{"id":13807603,"url":"https://github.com/wihrl/RazorStyle","last_synced_at":"2025-05-14T00:31:47.498Z","repository":{"id":206948314,"uuid":"702933806","full_name":"wihrl/RazorStyle","owner":"wihrl","description":"A library to allow CSS inside .razor components without duplication","archived":false,"fork":false,"pushed_at":"2024-03-04T12:17:48.000Z","size":212,"stargazers_count":7,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2024-11-18T23:53:27.352Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/wihrl.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null}},"created_at":"2023-10-10T09:33:01.000Z","updated_at":"2024-10-20T16:50:32.000Z","dependencies_parsed_at":null,"dependency_job_id":"78bb8220-1964-41af-bbd3-57c7c6b7f97c","html_url":"https://github.com/wihrl/RazorStyle","commit_stats":null,"previous_names":["wihrl/razorstyle"],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wihrl%2FRazorStyle","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wihrl%2FRazorStyle/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wihrl%2FRazorStyle/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wihrl%2FRazorStyle/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/wihrl","download_url":"https://codeload.github.com/wihrl/RazorStyle/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254046351,"owners_count":22005575,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-04T01:01:27.452Z","updated_at":"2025-05-14T00:31:42.306Z","avatar_url":"https://github.com/wihrl.png","language":"C#","funding_links":[],"categories":["Libraries \u0026 Extensions"],"sub_categories":["2D/3D Rendering engines"],"readme":"# RazorStyle\n\nA library to allow adding CSS locally inside .razor components without duplication.\n\n![Nuget](https://img.shields.io/nuget/v/wihrl.RazorStyle)\n![Nuget](https://img.shields.io/nuget/dt/wihrl.RazorStyle)\n\n### Why?\n\nWhile using `\u003cstyle\u003e ... \u003c/style\u003e` within Blazor components works fine, each instance of the component creates a new\nstyle tag.\nThis results in unnecessary junk in the DOM as well as potential styling conflicts.\n\nUsing CSS isolation (`.razor.css`) fixes these issues, but having styles in a separate file sucks.\n\n### Usage\n\n1. Add `@using RazorStyle` to your `_Imports.cs`. (This is necessary for IDE support)\n\n2. Add the `StyleRoot` component to any singleton component, for example `App.razor`. The root component creates a\n   single `\u003cstyle\u003e` tag to be\n   shared between all instances of `\u003cRazorStyle.Style\u003e`.\n\n```csharp\n// App.razor\n\n// ...\n\n\u003cStyleRoot /\u003e\n    \n\u003cRouter AppAssembly=\"@typeof(App).Assembly\"\u003e\n    // ...\n\u003c/Router\u003e\n    \n@code {\nprotected override void OnInitialized()\n    {\n        base.OnInitialized();\n\n#if DEBUG\n        // Enable hot reload for debugging only (performance impact)\n        StyleRoot.EnableHotReload = true;\n#endif\n    }\n}\n\n// ...\n```\n\n3. Use `\u003cStyle\u003e` instead of `\u003cstyle\u003e` in your components.\n\n```csharp\n// SomeComponent.razor\n\n\u003ch1 class=\"title\"\u003eFoo\u003c/h1\u003e\n\n\u003cStyle\u003e\n.title {\n    // ...\n}\n\u003c/Style\u003e\n````\n\n**BEWARE:** This library does not handle CSS isolation! Make sure to use\nunique class names / selectors to avoid conflicts between components.\n\n### Triggered animations\n\nAdding a `_triggered_` prefix to `@keyframes` blocks will duplicate it with a different name.\nThis can be used in combination with `AnimationTrigger` to replay an animation programatically without relying on JS.\n\n```csharp\n// SomeAnimatedComponent.razor\n\n@code {\n\n    readonly AnimationTrigger _titleAnimation = new(\"fly-in\");\n\n    void Trigger()\n    {\n        _titleAnimation.Trigger();\n        StateHasChanged();\n    }\n\n}\n\n\u003cbutton @onclick=\"Trigger\"\u003eTrigger\u003c/button\u003e\n\n\u003ch1 class=\"title\" style=\"@_titleAnimation\"\u003eHome\u003c/h1\u003e\n\n\u003cStyle\u003e\n    .title {\n        // ! do NOT include the animation name ! \n        animation: 1s linear;\n        // ...\n    }\n\n    @@keyframes _triggered_fly-in {\n        // ...\n    } \n\u003c/Style\u003e\n````","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwihrl%2FRazorStyle","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwihrl%2FRazorStyle","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwihrl%2FRazorStyle/lists"}