MudBlazor.Extensions

repository·main·Indexed 43 days ago

https://github.com/fgilde/mudblazor.extensions

A library that extends the MudBlazor component library with additional components and enhanced functionality for dialogs and data editing. Key features include MudExObjectEdit for automatic object editing, MudExUploadEdit for advanced file uploads, MudExFileDisplay for file previews, and extended dialog options for resizable, draggable, and animated dialogs.

Tokens
59.3K
Snippets
227
Records
288
Agent score
55%

What's inside MudBlazor.Extensions

  1. Overview of Playzor Packages

    main

    Playzor is a suite of packages designed for code playgrounds and editors, providing compiler capabilities, Blazor components, and server-side support. The ecosystem is split into several specialized packages:

    PackageTFMContent
    Playzor.Blazornet8/9/10<PlayzorPlayground> (iframe-Embed) and the <playzor-playground> Web-Component
    Playzor.Corenet10Compiler, CodeFiles, NuGet resolution, IPlayzorApi, IPlayzorSnippetStore
    Playzor.Blazor.Editornet10<PlayzorEditor> including Monaco, Panels, and Assets
    Playzor.UserComponentsnet10Stub-Assembly for previews
    Playzor.Servernet10MapPlayzorApi(): NuGet-Proxy and optional snippet endpoints

    Note on Dependencies: Playzor.Core depends on MudBlazor.Extensions to provide ambient references for MudBlazor and MudEx to the user's code.

  2. Overview of dockview layout manager

    main
    dockview is a zero-dependency layout manager designed to support complex UI arrangements including tabs, groups, grids, and split-views. It is compatible with React, Vue, and Vanilla TypeScript. It provides advanced features like serialization/deserialization for layout persistence, drag-and-drop docking for tabs and groups, popout windows, and floating groups. The library is themeable, supports Shadow DOMs, and offers an extensive API for full layout management.
  3. Overview of MudBlazor.Extensions Utilities

    main

    MudBlazor.Extensions provides several utility categories to simplify common Blazor development tasks:

    Styling Utilities

    • Color Utilities: Color manipulation, conversion, and generation.
    • CSS Builder: Dynamic CSS class building with conditional logic.
    • Style Builder: Dynamic inline style building.
    • Size Utilities: Size calculations, conversions, and parsing.

    Helper Utilities

    • MudExJsonHelper: JSON serialization and manipulation.
    • MudExFonts: Font management and loading.
    • MudExThemeHelper: Theme creation and manipulation.
    • BrowserFileExt: File handling extensions.
    • EnumHelper: Enum utility methods.
    • ComponentHelper: Component reflection and creation.
    • LocalizationStringHelper: Localization support.
  4. Overview of MudBlazor.Extensions Components

    main

    MudBlazor.Extensions provides a suite of components designed to extend the standard MudBlazor library. Components are organized into several functional categories:

    • Data Editing: MudExObjectEdit (auto-generated UI with validation) and MudExStructuredDataEditor (JSON/XML/YAML editing).
    • File Management: MudExFileDisplay (file previews) and MudExUploadEdit (advanced uploads with cloud integration).
    • Navigation: MudExTreeView (enhanced tree view) and MudExTreeViewBreadcrumb.
    • Pickers: MudExColorPicker, MudExIconPicker, MudExFontSelect, and MudExEnumSelect.
    • Layout: MudExGrid (drag-drop/sorting), MudExDockLayout (resizable panels), and MudExSplitPanel.
    • Display & Media: MudExImageViewer, MudExCodeView (syntax highlighting), MudExMarkdown, and MudExGravatarCard.
    • Form & Input: MudExTextField, MudExSelect, MudExChipSelect, and MudExHtmlEdit.
    • Utility: MudExAppLoader and MudExSvg.
  5. Use MudExObjectEdit for automatic UI generation

    main

    MudExObjectEdit is a component that automatically generates user interfaces for editing objects. It uses your model's properties and metadata (like DataAnnotations) to build forms, supporting automatic validation via DataAnnotations or FluentValidation. It supports grouping via tabs, accordions, or dock panels, and allows for highly customized layouts and conditional rendering.

    <!-- Basic usage with MudExObjectEditForm -->
    <MudExObjectEditForm OnValidSubmit="@OnSubmit" Value="@MyModel" />
    
    @code {
        private MyModel MyModel = new MyModel();
    
        private void OnSubmit()
        {
            // Handle valid submission
            Console.WriteLine($"Name: {MyModel.Name}");
        }
    }
  6. Use MudExCssBuilder to build CSS classes dynamically

    main

    The MudExCssBuilder class is a utility for dynamically constructing CSS class strings. It is thread-safe (using concurrent dictionaries) and implements IAsyncDisposable to clean up any disposable objects stored during the building process.

    Key features include:

    • Conditional Class Addition: Add classes based on boolean conditions or predicates (Func<bool>).
    • Style Integration: Extract classes from style objects or style strings asynchronously.
    • Fluent API: Use factory methods like From to initialize the builder.
    • Attribute Support: Add classes directly from an IReadOnlyDictionary<string, object> of attributes.
    // Example conceptual usage
    var builder = MudExCssBuilder.Default;
    builder.AddClass("my-base-class");
    builder.AddClass("conditional-class", someCondition);
    string finalClass = builder.Build();
  7. Test structure and categories

    main

    The MudBlazor.Extensions.Tests project organizes tests into two distinct categories:

    • UITests: Located in the UITests folder. These focus on end-to-end user interface behaviors using Playwright.
    • UnitTests: Located in the UnitTests folder. These focus on testing individual functional units of the code.

    Both categories utilize xUnit as the underlying testing framework.

  8. Understand the documentation structure

    main

    The documentation is organized into several functional areas within the docs/ directory:

    • index.md: Homepage
    • getting-started/: Installation and setup guides
    • components/: Documentation for specific components
    • extensions/: Documentation for extension methods
    • utilities/: Documentation for utility classes
    • services/: Documentation for services
    • api/: Full API reference
    • about/: License and contributing information
    • stylesheets/: Custom CSS files
    • javascripts/: Custom JavaScript files

    Configuration is managed via the mkdocs.yml file in the root.

  9. Understand the Branding Model

    main

    The system uses a BrandingService to resolve visual identity based on the request hostname. This allows a single codebase to serve different 'brands' (e.g., mudex.org vs playzor.net).

    Resolution Logic:

    • The service maps window.location.hostname to a specific Brand record.
    • If the hostname is unknown or localhost, the brand can be overridden using the ?brand= query parameter.

    Brand Properties: A Brand record includes Name, LogoUrl, PrimaryColor, CanonicalHost, DefaultCulture, DefaultPackages, and a MudTheme (containing both Light and Dark palettes). This affects the landing page, toolbars, embed footers, and default templates used in the playground.

  10. Implement a custom file display component

    main

    To support a custom file format, implement the IMudExFileDisplay interface. This allows you to define which MIME types your component handles and how they should be rendered.

    1. Create a class inheriting from ComponentBase and implementing IMudExFileDisplay.
    2. Implement CanHandleFile(string fileName, string contentType) to return true for your target type.
    3. Implement Render() to return a RenderFragment containing your custom logic.
    4. Register the component in your dependency injection container (e.g., builder.Services.AddScoped<IMudExFileDisplay, MyCustomFileDisplay>();).
    public class MyCustomFileDisplay : ComponentBase, IMudExFileDisplay
    {
        public bool CanHandleFile(string fileName, string contentType)
        {
            return contentType == "application/x-custom";
        }
    
        public RenderFragment Render()
        {
            return builder =>
            {
                // Your custom rendering logic
            };
        }
    }