feat: support host-supplied named theme presets#42
Open
nmiddelmann2106 wants to merge 1 commit intoMudBlazor:mainfrom
Open
feat: support host-supplied named theme presets#42nmiddelmann2106 wants to merge 1 commit intoMudBlazor:mainfrom
nmiddelmann2106 wants to merge 1 commit intoMudBlazor:mainfrom
Conversation
Replaces the long-standing "Not Implemented" preset stub with a working dropdown driven by themes the host application provides. - Add optional `Name` to `ThemeManagerTheme` so the existing wrapper can carry a display name. Default null preserves all existing usage. - Add `[Parameter] IEnumerable<ThemeManagerTheme>? Presets` and `[Parameter] EventCallback<ThemeManagerTheme> PresetSelected` on `MudThemeManager`. When `Presets` is null the original disabled stub renders unchanged (backward compatible). - Refactor theme initialisation into `SyncWithTheme()` and run it from both `OnInitialized` and `OnParametersSet`, with a reference guard. This lets the host swap the active theme via the existing `Theme` parameter (e.g. on preset selection) and have the manager re-sync its internal palette caches. Without this, switching the active theme after first render would leave subsequent edits applied to the previous theme. The library remains storage-agnostic: presets are passed in by the host, persistence stays the host application concern.
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



Summary
Replaces the long-standing "Not Implemented" preset stub in the
ThemeManager drawer with a working dropdown driven by themes the host
application provides. The library stays storage-agnostic — it just
renders what it is given and emits a selection event.
Motivation
Issue #31 names "Add presets" as a planned improvement. There are at
least two natural shapes this can take: built-in catalog presets
(library-shipped) and host-supplied presets (loaded from app state, a
DB, JSON files, etc.). This PR addresses the second shape with a
small, additive API. It is intentionally unopinionated about
persistence: the host fills the list, the library renders and reports
selection.
Changes
ThemeManagerTheme.cs: add optionalstring? Name. Existing usageis unaffected; only consumers that opt into presets need to set it.
MudThemeManager.razor.cs: add two parametersIEnumerable<ThemeManagerTheme>? PresetsEventCallback<ThemeManagerTheme> PresetSelectedMudThemeManager.razor: whenPresetsisnullthe existingdisabled "Not Implemented" stub still renders unchanged. When
provided, a working
MudSelectlists the names and emits theselection event.
OnInitializedinto asmall
SyncWithTheme()method called from bothOnInitializedandOnParametersSet, guarded by a reference check onTheme. Withoutthis, swapping the active
Themevia the existing parameter (whichis the natural way to react to a preset selection) would leave the
manager's internal palette caches pointing at the previous theme,
so subsequent edits would mutate the wrong instance.
Backward compatibility
Presetsisnullthe rendered drawer is byte-identical tobefore (same disabled
MudSelect, same "Not Implemented" item).NameonThemeManagerThemeis nullable and unused by the libraryunless the consumer opts in.
Usage
Test plan
dotnet buildclean (0 errors).Presetsshows the unchanged"Not Implemented" stub.
Presetsshows names and switching emitsPresetSelected.Themeafter first render correctlyre-syncs internal caches (subsequent color edits target the
newly-active theme).
Notes
independent. Either can land in any order.
Built-in catalog presets and import/export from JSON are separate
concerns and can compose naturally with this API.