Skip to content

fix: consumer-configurable sidebar package selector - #14

Merged
Shewart merged 4 commits into
mainfrom
fix/consumer-package-selector
Jul 24, 2026
Merged

fix: consumer-configurable sidebar package selector#14
Shewart merged 4 commits into
mainfrom
fix/consumer-package-selector

Conversation

@Shewart

@Shewart Shewart commented Jul 24, 2026

Copy link
Copy Markdown
Contributor

Summary

Fixes the first entry in docs/SHELLUI_DOGFOOD_FIXES.md — the hardcoded ShellDocs-only package list in the sidebar's package selector.

The bug

PackageSelector.razor shipped a static readonly List<Package> hardcoded to ShellDocs' own five packages (ShellDocs, ShellDocs.Markdown, ShellDocs.Core, ShellDocs.CLI, ShellDocs.Components). Every consumer's sidebar surfaced that list — a ShellUI docs site rendered ShellDocs' package names, a MudBlazor site would have too. There was no consumer-config path, and the selector always rendered even for consumers with a single package family (dropdown of one).

Discovered during the first render of shellui-docs while scaffolding it via ShellDocs.

The fix

New public API on ShellDocsOptions

public record DocsPackage(string Id, string Title, string Description, string RootUrl, string? IconPath = null);

public List<DocsPackage> Packages { get; }
public ShellDocsOptions AddPackage(string id, string title, string description, string rootUrl, string? iconPath = null);

Consumers declare their family in Program.cs:

builder.Services.AddShellDocs(o =>
{
    o.AddPackage("shellui",             "ShellUI",             "The component library.",  "/docs/introduction");
    o.AddPackage("shellui.components",  "ShellUI.Components",  "Widgets and primitives.", "/docs/components");
    o.AddPackage("shellui.cli",         "ShellUI.CLI",         "`shellui add`, config.",  "/docs/cli");
});

PackageSelector.razor behavior changes

  • Injects ShellDocsOptions; reads Options.Packages at render time; hardcoded ShellDocs list deleted.
  • Early-returns rendering nothing at all when Options.Packages.Count <= 1. A consumer with zero or one packages sees no selector — no dropdown-of-one noise.
  • Selected-package resolution now does longest-prefix matching on the current URL against each package's RootUrl. Previously used a fuzzy substring match that wrongly picked ShellDocs for /docs/components/callout when it should have picked ShellDocs.Components.
  • Default box glyph used when a package's AddPackage(...) call omits an iconPath — same 24×24 stroke contract as consumer-supplied paths.

Preview app migration

examples/ShellDocs.Preview/Program.cs now calls AddPackage(...) for its five packages. Proves the consumer flow end-to-end and keeps the preview app's selector rendering identically to before.

Test plan

  • dotnet build shelldocs.slnx — clean, 0 warnings, 0 errors
  • dotnet test shelldocs.slnx121 / 121 passing (+2 new in PackageRegistrationTests)
  • Preview app smoke:
    • /docs/introduction → selector shows ShellDocs (correct)
    • /docs/markdownShellDocs.Markdown (correct)
    • /docs/components/calloutShellDocs.Components (previously would have wrongly selected ShellDocs under the old substring match)
  • Empty-packages case (verified via unit test): new ShellDocsOptions().Packages is empty by default; PackageSelector early-return path renders no markup

Files touched

  • src/ShellDocs.Components/ShellDocsOptions.cs — new DocsPackage public record, Packages list, AddPackage fluent
  • src/ShellDocs.Components/Chrome/PackageSelector.razor — rewritten; drops hardcoded list, injects options, early-returns, longest-prefix match
  • examples/ShellDocs.Preview/Program.cs — migrated to AddPackage(...)
  • docs/SHELLUI_DOGFOOD_FIXES.md — entry moved from Open to Fixed
  • tests/ShellDocs.Tests/PackageRegistrationTests.cs (new, 2 tests)

Shewart added 4 commits July 24, 2026 18:45
…ation links to enhance navigation and usability
…r dynamic package management and improve icon handling
@Shewart
Shewart merged commit 18330cf into main Jul 24, 2026
1 check passed
@Shewart
Shewart deleted the fix/consumer-package-selector branch July 25, 2026 00:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant