{"id":24015935,"url":"https://github.com/devritter/blazortoolkit","last_synced_at":"2026-05-17T05:33:31.589Z","repository":{"id":271156062,"uuid":"912541082","full_name":"devritter/BlazorToolkit","owner":"devritter","description":"useful components and utilities for Blazor developers","archived":false,"fork":false,"pushed_at":"2025-01-23T19:07:45.000Z","size":201,"stargazers_count":0,"open_issues_count":1,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-01-23T20:20:01.028Z","etag":null,"topics":["blazor","productivity","utility"],"latest_commit_sha":null,"homepage":"https://www.nuget.org/packages/BlazingDev.BlazorToolkit","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/devritter.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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,"publiccode":null,"codemeta":null}},"created_at":"2025-01-05T21:20:10.000Z","updated_at":"2025-01-23T19:07:49.000Z","dependencies_parsed_at":"2025-01-23T20:29:39.685Z","dependency_job_id":null,"html_url":"https://github.com/devritter/BlazorToolkit","commit_stats":null,"previous_names":["devritter/blazortoolkit"],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/devritter%2FBlazorToolkit","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/devritter%2FBlazorToolkit/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/devritter%2FBlazorToolkit/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/devritter%2FBlazorToolkit/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/devritter","download_url":"https://codeload.github.com/devritter/BlazorToolkit/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":240729844,"owners_count":19848234,"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":["blazor","productivity","utility"],"created_at":"2025-01-08T08:23:12.428Z","updated_at":"2026-05-17T05:33:31.577Z","avatar_url":"https://github.com/devritter.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"# BlazorToolkit\n\nUseful components and utilities for Blazor developers\n\n## BzDump\n\nBzDump is a powerful UI component that displays all properties of a given object using reflection — \nsimilar to what you see in a debugger's inspect variable view in Visual Studio. \\\nIt provides a structured and readable view of an object's state at runtime, making it an invaluable tool for diagnostics and troubleshooting. \\\nBy enabling object inspection without requiring an attached debugger, you can boost your productivity and get deeper insight into application behavior during live execution or in production-like environments.\n\n```xml\n\u003cBzDump Value=\"yourStateVariable\" /\u003e\n\u003cBzDump Value=\"CultureInfo.CurrentCulture\" /\u003e\n\u003cBzDump Value=\"resultFromRestApiCall\" /\u003e\n```\n\n## BzComponentBase\n\nYour new component base class with:\n\n* typed `Logger` instance\n* `IsInitialized` property to simplify your rendering logic for asynchronously initialized components!\n* `Disposer` object to register disposables at creation time!\n* `InvokeAsyncStateHasChanged()` method\n* Support for [Integrations](https://github.com/devritter/BlazorToolkit/blob/main/docs/integrations.md)\n\nand more to come!\n\n### Registration:\n\n**Per component:**\n\n```\n@inherits BlazingDev.BlazorToolkit.Components.BzComponentBase\n```\n\n**Globally:**\n\nLocate `_Imports.razor` and add the following line to set the base component for all `*.razor` files in the same\ndirectory and subdirectories:\n\n```\n@inherits BlazingDev.BlazorToolkit.Components.BzComponentBase\n```\n\n### Example\n\n```csharp\n@* IsInitialized from base class *@\n@if (IsInitialized)\n{\n    // render product and reviews\n}\nelse\n{\n    \u003cLoadingSpinner /\u003e   \n}\n\n@code {\n\n    IDisposable? _someDisposable = null;\n    ProductDto? _product = null;\n    List\u003cProductReviewDto\u003e? _reviews = null;\n    \n    protected override async Task OnInitializedAsync()\n    {\n        _someDisposable = GetSomeDisposable();\n        _product = await ProductService.GetProductAsync(5);\n        _reviews = await ProductService.GetProductReviewsAsync(5);\n        \n        // BzAsyncDisposer from base class\n        Disposer.Add(_someDisposable);\n        \n        var subscription = SubscriptionService.Subscribe(\"important-messages\", HandleImportantMessage);\n        // Logger from base class\n        Logger.LogInformation(\"Got subscription {SubscriptionId}\", subscription.Id);\n        Disposer.Add(subscription);\n        \n        SubscriptionService.ConnectionLost += HandleConnectionLost;\n        Disposer.Add(() =\u003e SubscriptionService.ConnectionLost -= HandleConnectionLost);\n        Disposer.Add(SayGoodbyeAsync);\n    }\n    \n    private void HandleConnectionLost(object sender, EventArgs e)\n    {\n        ShowReconnectOverlay = true;\n        // little simplified method from base class\n        InvokeAsyncStateHasChanged();\n    }\n\n}\n```\n\n## BzComponentTool\n\nProvides utility methods regarding components.\n\n### GetRoute\n\nWith the following methods you can retrieve a component's route (`@page \"/this-is-the-route\"`). \\\nUseful if you want to create links to other components and you don't want to have magic strings in your code.\n\n```csharp\n // returns the first defined route or null for non-routable components\nBzComponentTool.TryGetRoute\u003cPotentiallyRoutableComponent\u003e();\nBzComponentTool.TryGetRoute(typeof(PotentiallyRoutableComponent));\n// returns the first defined route or throws for non-routable components\nBzComponentTool.GetRoute\u003cSomePage\u003e();\nBzComponentTool.GetRoute(typeof(SomePage));\n// returns zero-to-many items\nBzComponentTool.TryGetRoutes\u003cPageWithMultipleRoutes\u003e();\nBzComponentTool.TryGetRoutes(typeof(PageWithMultipleRoutes));\n```\n\n### BzMenuItem\n\nUse the `BzMenuItemAttribute` to specify menu items at component level. \\\nFor extra laziness you can use the `BzComponentTool.GetAllMenuItemsFromAssembly(assembly)` method :)\n\n```csharp\n@page \"/about\"\n@attribute [BzMenuItem(Name = \"About\", Icon = \"people\", Sorting = 500)]\n```\n\n```csharp\nBzComponentTool.GetMenuItem\u003cAboutPage\u003e();    // requires ( @page OR [Route] ) AND [BzMenuItem]\nBzComponentTool.TryGetMenuItem\u003cAboutPage\u003e(); // returns null if anything required is missing\n\n// NavMenu.razor\n@foreach (var item in BzComponentTool.GetAllMenuItemsFromAssembly(GetType().Assembly))\n{\n    \u003cMyNavItem MenuItem=\"item\"/\u003e\n}\n```\n\n## BzTimerComponent\n\nA blazor component that wraps a Timer instance. \\\nAutomatically handles:\n\n* Creating the `Timer`\n* Calling `InvokeAsync()`\n* Calling `StateHasChanged()` when using the `OnElapsed` `EventCallback`\n* `OnElapsedAction` when you want to manually decide if any re-rendering is needed\n* `try-catch` of the elapsed handlers\n* disposing the timer when the component is unmounted\n\nAnd you can use `ShowControls` for testing purposes which let you override the `Enabled` and `Interval` setting!\n\n```xml\n\u003cBzTimerComponent Name=\"PriceRefreshTimer\" Interval=\"5000\" OnElapsed=\"HandleUpdatePriceTimerElapsed\" /\u003e\n```\n\n## BzCssClassBuilder\n\nA utility class to help creating CSS classes lists.\n\n* static `Create` methods to not use spaces (sometimes handy in razor files)\n* `Add(className)`, `Add(listOfClassNames)`, `AddIf(condition, className)`\n* `Remove(className)`, `RemoveIf(condition, className)`\n* automatically trimes classNames\n* ignores duplicates and no-content classNames\n* use `Build()` or `ToString()` to get your final string\n\n### Usage Example:\n\n```csharp\n@{\n    var cssClasses = BzCssClassBuilder.Create(\"my-button\")\n        .Add(\"button-primary\")\n        .AddIf(isOutline, \"button-outline\")\n        .Add(SomeSettings.AdditionalButtonClasses) // e.g. theme-specific\n        .Build()\n}\n\u003cbutton class=\"@cssClasses\"\u003e...\u003c/button\u003e\n```\n\n## BzCssStyleBuilder\n\nA utility class for building CSS styles conditionally and fluently.\n\n### Usage:\n\n```csharp\nvar style = new BzCssStyleBuilder()\n    .Add(\"color\", \"red\")\n    .Add(\"font-size\", UserFontSize, \"em\")\n    .AddIf(isBold, \"font-weight\", \"bold\")\n    .AddIf(concreteWidth, \"width\", CalculateWidthFunction, \"px\")\n    .Add(Style) // from component parameter\n    .Build();\n```\n\n## BzRenderMode\n\nPredefined render modes without prerender\n\n### Usage\n\n**per component, e.g. in `App.razor`:**\n\n```\n\u003cRoutes @rendermode=\"BzRenderMode.InteractiveServerNoPrerender\"/\u003e\n```\n\nIf you add the following line in `_Imports.razor`, you can omit the `BzRenderMode` prefix:\n\n```\n@using static BlazingDev.BlazorToolkit.Components.BzRenderMode\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdevritter%2Fblazortoolkit","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdevritter%2Fblazortoolkit","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdevritter%2Fblazortoolkit/lists"}