Skip to content
Dashboard DashboardGroup

DashboardGroup

The root of a dashboard: a sidebar and resizable panels in a row, with their sizes and collapsed state remembered under a storage key.

On this page

Examples

A complete dashboard

Sidebar, navbar, toolbar, panels and search. Ctrl+K opens the search; the sidebar and the panel sizes are remembered under the StorageKey.

Sidebar

Acme
Ada Lovelace

Inbox

  • Welcome to Acme
  • Your invoice is ready
  • Design review notes
  • Weekly summary
  • Password changed

Message

Press Ctrl+K, or use the search button, to jump to a page or run a command.

Last command: none

Compose message
Sign out
Razor
@* A complete dashboard in a frame of fixed height, so it does not replace the layout of the site. In an app the group
   fills the page: give it the whole viewport. As="div": the docs page already has a main landmark.
   The group-data-[state=collapsed]/sidebar variants keep labels for screen readers while the sidebar shows icons only. *@
<div class="h-[30rem] w-full overflow-hidden rounded-xl border border-(--klyroo-border)" data-testid="dashboard">
    <KlyDashboardGroup StorageKey="playground-dashboard">
        <KlyDashboardSidebar As="KlyElement.Div" Resizable data-testid="dashboard-sidebar">
            <Header>
                <span class="font-semibold text-(--klyroo-text-highlighted)">Acme</span>
            </Header>
            <ChildContent>
                <KlyDashboardSearchButton data-testid="dashboard-search-button" />
                <KlyNavigationMenu Items="_items" Orientation="KlyOrientation.Vertical" AriaLabel="Workspace" Ui="_navUi" />
            </ChildContent>
            <Footer>
                <span class="inline-flex size-8 shrink-0 items-center justify-center rounded-full bg-(--klyroo-bg-elevated) text-xs font-medium" aria-hidden="true">AL</span>
                <span class="min-w-0 truncate text-sm group-data-[state=collapsed]/sidebar:sr-only">Ada Lovelace</span>
            </Footer>
        </KlyDashboardSidebar>

        <KlyDashboardPanel Resizable Size="35" MinSize="20" MaxSize="60" ResizeLabel="Resize inbox" data-testid="dashboard-inbox">
            <Header>
                <KlyDashboardNavbar Title="Inbox">
                    <Leading><KlyDashboardSidebarCollapse data-testid="dashboard-collapse" /></Leading>
                </KlyDashboardNavbar>
                <KlyDashboardToolbar>
                    <Left>
                        <KlyButton Label="All" Size="KlySize.Sm" Variant="ButtonVariant.Soft" Color="KlyColor.Neutral" />
                        <KlyButton Label="Unread" Size="KlySize.Sm" Variant="ButtonVariant.Ghost" Color="KlyColor.Neutral" />
                    </Left>
                </KlyDashboardToolbar>
            </Header>
            <Body>
                <ul class="flex flex-col gap-3 text-sm">
                    @foreach (var subject in _subjects)
                    {
                        <li class="truncate text-(--klyroo-text)">@subject</li>
                    }
                </ul>
            </Body>
        </KlyDashboardPanel>

        <KlyDashboardPanel data-testid="dashboard-detail">
            <Header>
                <KlyDashboardNavbar Title="Message" Toggle="false">
                    <Right>
                        <KlyButton Label="Reply" Size="KlySize.Sm" Variant="ButtonVariant.Outline" Color="KlyColor.Neutral" />
                    </Right>
                </KlyDashboardNavbar>
            </Header>
            <Body>
                <p class="text-sm text-(--klyroo-text-muted)">
                    Press Ctrl+K, or use the search button, to jump to a page or run a command.
                </p>
                <p class="text-sm text-(--klyroo-text-muted)" data-testid="dashboard-last">Last command: @(_last ?? "none")</p>
            </Body>
        </KlyDashboardPanel>

        <KlyDashboardSearch Groups="_groups" OnSelect="item => _last = item.Label" />
    </KlyDashboardGroup>
</div>

@code {
    private string? _last;

    private static readonly NavigationMenuUi _navUi = new() { Label = "group-data-[state=collapsed]/sidebar:sr-only" };

    private static readonly string[] _subjects = ["Welcome to Acme", "Your invoice is ready", "Design review notes", "Weekly summary", "Password changed"];

    private static readonly KlyNavigationItem[] _items =
    [
        new("Home") { Href = "/", Exact = true, Icon = KlyIcons.Named("home", "size-5") },
        new("Inbox") { Href = "/components/dashboard-group", Icon = KlyIcons.Named("inbox", "size-5") },
        new("Calendar") { Href = "/components/header", Icon = KlyIcons.Named("calendar", "size-5") },
        new("Settings") { Href = "/docs/theming", Icon = KlyIcons.Named("user", "size-5") },
    ];

    private static readonly KlyCommandGroup[] _groups =
    [
        new("Go to",
        [
            new() { Label = "Inbox", Href = "?view=inbox", Keywords = "mail messages" },
            new() { Label = "Settings", Href = "?view=settings", Keywords = "preferences account" },
        ]),
        new("Actions",
        [
            new() { Label = "Compose message", Keywords = "new write" },
            new() { Label = "Sign out", Keywords = "logout" },
        ]),
    ];
}

Bound state

@bind-Sizes and @bind-Collapsed report to .NET; your state wins over the stored one.

Sidebar

Acme

List

Detail

Sizes: 40,60

Collapsed: false

Razor
<div class="flex flex-col gap-3">
    <div class="h-72 w-full overflow-hidden rounded-xl border border-(--klyroo-border)" data-testid="dashboard-bound">
        <KlyDashboardGroup StorageKey="playground-dashboard-bound" @bind-Sizes="_sizes">
            <KlyDashboardSidebar As="KlyElement.Div" @bind-Collapsed="_collapsed" data-testid="dashboard-bound-sidebar">
                <Header><span class="font-semibold text-(--klyroo-text-highlighted)">Acme</span></Header>
                <ChildContent>
                    <KlyNavigationMenu Items="_items" Orientation="KlyOrientation.Vertical" AriaLabel="Workspace, bound" Ui="_navUi" />
                </ChildContent>
            </KlyDashboardSidebar>
            <KlyDashboardPanel Resizable Size="40" MinSize="15" MaxSize="85" ResizeLabel="Resize list">
                <Header>
                    <KlyDashboardNavbar Title="List">
                        <Leading><KlyDashboardSidebarCollapse data-testid="dashboard-bound-collapse" /></Leading>
                    </KlyDashboardNavbar>
                </Header>
            </KlyDashboardPanel>
            <KlyDashboardPanel>
                <Header><KlyDashboardNavbar Title="Detail" Toggle="false" /></Header>
            </KlyDashboardPanel>
        </KlyDashboardGroup>
    </div>
    <div class="flex flex-wrap items-center gap-3 text-sm text-(--klyroo-text-muted)">
        <p data-testid="dashboard-bound-sizes">Sizes: @string.Join(",", _sizes.Select(s => Math.Round(s)))</p>
        <p data-testid="dashboard-bound-collapsed">Collapsed: @(_collapsed ? "true" : "false")</p>
        <KlyButton Label="Set 25 / 75" Size="KlySize.Sm" Variant="ButtonVariant.Outline" Color="KlyColor.Neutral" OnClick="() => _sizes = [25, 75]" data-testid="dashboard-bound-set" />
    </div>
</div>

@code {
    private IReadOnlyList<double> _sizes = [40, 60];
    private bool _collapsed;

    private static readonly NavigationMenuUi _navUi = new() { Label = "group-data-[state=collapsed]/sidebar:sr-only" };

    private static readonly KlyNavigationItem[] _items =
    [
        new("Home") { Href = "/", Exact = true, Icon = KlyIcons.Named("home", "size-5") },
        new("Inbox") { Href = "/components/dashboard-group", Icon = KlyIcons.Named("inbox", "size-5") },
    ];
}

API

KlyDashboardGroup

Root of a dashboard layout: a sidebar and resizable panels, with the panel sizes remembered in the browser.

Parameters

Name Type Description
Class string Classes added to the root element, merged last so they win over the theme.
Sizes (@bind-Sizes) IReadOnlyList<Double> Sizes of the panels in percent, one per panel in document order. Bind it to follow resizing from .NET; unbound, resizing stays in the browser. Bound sizes are not restored from storage: your state wins.
StorageKey string Key under which the dashboard remembers its state (sidebar in cookies, panel sizes in localStorage): the collapsed state and the width of its sidebar (cookies "klyroo-sidebar-" followed by the key, see KlySidebar.Id and KlyPathScope.SidebarCookieName for an app below a path base) and the sizes of its panels ("klyroo:dashboard:" key ":panels"). Without a key nothing is remembered. Use a different key for each dashboard of the app.
Ui DashboardGroupUi Per-instance class overrides of the slots of the dashboard group, see DashboardGroupUi . They are merged after the theme and the Class parameter wins on the root slot.

Slots

Name Type Description
ChildContent RenderFragment The sidebar, the panels and anything else of the dashboard, laid out in a row.

Ui slots

Ui takes a DashboardGroupUi with one class string per slot, merged after the theme.

Slot Styles
Root Classes merged into the root slot of KlyDashboardGroup , after the theme and the app configuration.