DashboardCard
The base of every block (KlyDashboardCard): a card with a title, an optional menu (View as table, Download CSV, Expand), a footer and a phase drawn from the state of its Source. Use it for a block of your own. Without a Source it shows its content, or its empty state, at once.
Examples
Phases of a block
Idle and Loading draw a skeleton (Skeleton picks its shape), Error draws the message of the source with a Retry button that refreshes it, IsEmpty draws the empty state with EmptyTitle and EmptyDescription once the source is ready, and Ready draws the content. Freshness adds an Updated footer built from UpdatedAt. A card outside a page does not subscribe to its source, so the example calls StateHasChanged on the Changed event of the resource.
Loading
Source never loaded
Failed
Press Retry to load again
This data could not be loaded
The orders service is not reachable.
Empty
No orders
Try another period.
Content
12 orders this week.
@implements IDisposable
<KlyDashboardGrid Columns="2">
<KlyDashboardCard Title="Loading" Subtitle="Source never loaded" Source="_idle" Span="1" Skeleton="DashboardSkeletonKind.Bars">
<p class="m-0 text-sm">Not shown while the source is idle or loading.</p>
</KlyDashboardCard>
<KlyDashboardCard Title="Failed" Subtitle="Press Retry to load again" Source="_failed" Span="1">
<p class="m-0 text-sm">Loaded after a retry: @_failed.Data orders.</p>
</KlyDashboardCard>
<KlyDashboardCard Title="Empty" Source="_ready" Span="1" IsEmpty="true"
EmptyTitle="No orders" EmptyDescription="Try another period.">
<p class="m-0 text-sm">Not shown, the block is empty.</p>
</KlyDashboardCard>
<KlyDashboardCard Title="Content" Source="_ready" Span="1" Freshness="true">
<p class="m-0 text-sm">@_ready.Data orders this week.</p>
</KlyDashboardCard>
</KlyDashboardGrid>
@code {
// A resource without a loader is a plain holder, and one with a loader that was never run stays Idle.
private readonly DashboardResource<int> _idle = new("idle");
private readonly DashboardResource<int> _failed = new("failed", _ => Task.FromResult(5));
private readonly DashboardResource<int> _ready = new("ready");
protected override void OnInitialized()
{
_failed.SetError("The orders service is not reachable.");
_ready.SetData(12);
// A card outside a page does not subscribe to its source: re-render when it changes.
_failed.Changed += OnChanged;
}
private void OnChanged() => InvokeAsync(StateHasChanged);
public void Dispose() => _failed.Changed -= OnChanged;
}Your own content, table and CSV
The card cannot read your markup, so Tabulate returns the DashboardDataTable behind View as table and Download CSV. With OnCsvExported the card starts no download and hands you the CSV text (it starts with a byte order mark and ends every line with CRLF), which is also the way to save the file where a web view cannot download. The expand button opens the block in a modal dialog, here turned off with Expandable. Statically rendered the buttons do nothing.
Orders by region
Your own markup in a card
- EMEA: 140 orders
- Americas: 120 orders
- APAC: 66 orders
@using System.Globalization
<div class="flex w-full flex-col gap-3">
<KlyDashboardGrid>
<KlyDashboardCard Title="Orders by region" Subtitle="Your own markup in a card" Source="_orders" Span="12" Menu="true" Expandable="false"
IsEmpty="@(_orders.Data is not { Count: > 0 })" Tabulate="BuildTable" OnCsvExported="OnCsv">
<ul class="m-0 flex list-none flex-col gap-1 p-0 text-sm">
@foreach (var order in _orders.Data ?? [])
{
<li>@order.Region: @order.Orders orders</li>
}
</ul>
</KlyDashboardCard>
</KlyDashboardGrid>
@if (_csv is not null)
{
<pre class="m-0 text-xs">@_csv</pre>
}
</div>
@code {
private sealed record RegionOrders(string Region, int Orders);
private string? _csv;
private readonly DashboardResource<IReadOnlyList<RegionOrders>> _orders = new(
"orders", _ => Task.FromResult<IReadOnlyList<RegionOrders>>([new("EMEA", 140), new("Americas", 120), new("APAC", 66)]));
protected override Task OnInitializedAsync() => _orders.RefreshAsync();
// The card cannot read the content of your markup, so Tabulate gives the table behind the View as table and Download CSV buttons.
private DashboardDataTable BuildTable() => new(
[new("region", "Region"), new("orders", "Orders", Numeric: true)],
(_orders.Data ?? []).Select(r => (IReadOnlyDictionary<string, string?>)new Dictionary<string, string?>
{
["region"] = r.Region,
["orders"] = r.Orders.ToString(CultureInfo.InvariantCulture),
}).ToList());
// With a handler the card starts no download and hands the CSV text over.
private void OnCsv(string csv) => _csv = csv;
}API
KlyDashboardCard
The frame shared by every block: header with title and menu, loading skeleton, error with a retry button, empty state, content, chips for active filters and a footer. Use it directly to build a custom block.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
Card |
bool |
true |
Whether the block draws its own surface (border, background and shadow; only the background in a panels grid). Defaults to true . |
Class |
string |
Classes added to the root element, merged last so they win over the theme. | |
EmptyDescription |
string |
A line of text under the title of the empty state. | |
EmptyTitle |
string |
The title of the empty state. Defaults to the NoData text of the locale ( No data for this period in English). | |
Expandable |
bool |
true |
Shows the Expand button in the menu, which opens the content of the card in a modal dialog ( KlyModal of Klyroo.UI: the page behind is inert, the focus stays in the dialog, Escape, the close button and a click on the backdrop close it, and the focus returns to the Expand button). Defaults to true . |
Filters |
IReadOnlyList |
Filters whose non-default selection is shown as removable chips under the header. | |
Freshness |
bool? |
Shows an Updated footer built from Source.UpdatedAt . When null , the value of the enclosing KlyDashboardGrid.Freshness applies, or false outside a grid. | |
IsEmpty |
bool |
false |
Shows the empty state instead of the content once the source is ready. |
Menu |
bool? |
Shows the View as table, Download CSV and Expand buttons in the header once the content is displayed. Download CSV saves the block's table as a CSV file named after the title. When null , the value of the enclosing KlyDashboardGrid.Menu applies, or false outside a grid. | |
Skeleton |
Dashboard |
Dashboard |
The shape of the loading skeleton. Stat , Bars , Lines , Paired and Stack have their own shape, the other kinds render three lines. Values: Rows, Stat, Stats, Gauge, Details, Bars, Paired, Funnel, Stack, Table, Feed, Lines, Donut. |
Source |
IDashboardSource |
The resource whose state drives the block: a skeleton while it loads, an error message with a retry button, then the content. The block does not read Data from it, so pass the data through the other parameters. Without a source the content renders immediately. The card activates a Deferred source on its first render, and on every render calls ActivateAsync on a disabled source, which loads it once its enabled predicate returns true . | |
Span |
int |
12 |
Width of the block in columns of the grid, clamped between 1 and the Columns of the enclosing KlyDashboardGrid (12 outside a grid). Defaults to 12. |
Subtitle |
string |
A secondary line under the title. | |
Tabulate |
Func |
Returns the content of the block as a table. It enables the View as table and Download CSV buttons. | |
Title |
string |
The heading of the block. | |
ViewAsTable |
bool |
true |
Shows the View as table button in the menu. It needs Tabulate . Defaults to true . |
Events
| Name | Type | Description |
|---|---|---|
OnCsvExported |
EventCallback |
Receives the CSV text when the user clicks Download CSV, instead of the browser download the card starts by default. Use it to save the file yourself, for example in a .NET MAUI app where the web view cannot download. Name the file with String) . |
Slots
| Name | Type | Description |
|---|---|---|
Footer |
RenderFragment |
Content placed in the footer, before the freshness text. |
HeaderRight |
RenderFragment |
Content placed in the header, before the menu buttons. |
ChildContent |
RenderFragment |
The content of the block, rendered once the source is ready and not empty. |