TileLayout
Since 0.1.0-alpha.24A grid of tiles, each placed at a column and row and spanning some of each, such as the panels of a dashboard. The server draws the layout as it is, with no script, and cells can stay empty.
A dashboard
For a dashboard people rearrange and keep, put a Tile for each panel in a TileLayout; one that never changes is a Grid of Cards. Col and Row place it, from 1, and ColSpan and RowSpan size it. Columns and RowHeight set the grid.
Static
Preview
- Revenue
- $84,320
- Orders
- 1,284
- Average order
- $65.67
- Returns
- 2.1%
Revenue by channel
- Online store
- Marketplaces
- Wholesale
| Month | Online store | Marketplaces | Wholesale |
|---|---|---|---|
| Jun | $151K | $60K | $47K |
| Jul | $149K | $63K | $45K |
| Aug | $157K | $66K | $48K |
| Sep | $162K | $68K | $52K |
| Oct | $171K | $72K | $55K |
| Nov | $178K | $75K | $57K |
Top products
Stoneware mug
214 sold
Linen throw
168 sold
Oak serving board
131 sold
Beeswax candle
97 sold
Wool blanket
84 sold
Ceramic planter
72 sold
Code
@* A store's week at a glance: four figures across the top, revenue and best sellers under them. *@
<TileLayout Columns="new() { Base = 1, Md = 6, Lg = 12 }" RowHeight="Length.Rem(7)" aria-label="Store dashboard">
<Tile Id="revenue" Col="1" Row="1" ColSpan="3">
<Stat Label="Revenue" Value="$84,320" Change="9.4%" Trend="StatTrend.Up" Description="vs last week" />
</Tile>
<Tile Id="orders" Col="4" Row="1" ColSpan="3">
<Stat Label="Orders" Value="1,284" Change="6.1%" Trend="StatTrend.Up" Description="vs last week" />
</Tile>
<Tile Id="average" Col="7" Row="1" ColSpan="3">
<Stat Label="Average order" Value="$65.67" Change="3.0%" Trend="StatTrend.Up" Description="vs last week" />
</Tile>
<Tile Id="returns" Col="10" Row="1" ColSpan="3">
<Stat Label="Returns" Value="2.1%" Change="0.4 pts" Trend="StatTrend.Down" ChangeStatus="Status.Success" Description="vs last week" />
</Tile>
<Tile Id="channels" Title="Revenue by channel" TitleId="tiles-channels-title" Icon="Lucide.ChartColumn" Col="1" Row="2" ColSpan="8" RowSpan="3">
<HeaderEnd>
<ChartDownload />
</HeaderEnd>
<ChildContent>
<Chart Items="_channels" Argument="m => m.Month" TitledBy="tiles-channels-title" Stacking="ChartStacking.Normal">
<ChartValueAxis Format="$#,##0,K" />
<ChartBarSeries Value="m => m.Online" Name="Online store" />
<ChartBarSeries Value="m => m.Marketplace" Name="Marketplaces" />
<ChartBarSeries Value="m => m.Wholesale" Name="Wholesale" />
</Chart>
</ChildContent>
</Tile>
<Tile Id="products" Title="Top products" Icon="Lucide.Package" Col="9" Row="2" ColSpan="4" RowSpan="3">
<Stack Gap="3">
foreach (var product in _top)
{
<Row Gap="3" Align="Align.Center">
<Avatar Name="product.Name" Size="AvatarSize.Sm" Decorative />
<TextBlock Size="TextSize.Sm" Grow>product.Name</TextBlock>
<TextBlock Size="TextSize.Sm" Weight="FontWeight.Medium" TabularNums>product.Sold sold</TextBlock>
</Row>
}
</Stack>
</Tile>
</TileLayout>
{
private record ChannelMonth(string Month, decimal Online, decimal Marketplace, decimal Wholesale);
private readonly ChannelMonth[] _channels =
[
new("Jun", 151_000, 60_000, 47_000), new("Jul", 149_000, 63_000, 45_000), new("Aug", 157_000, 66_000, 48_000),
new("Sep", 162_000, 68_000, 52_000), new("Oct", 171_000, 72_000, 55_000), new("Nov", 178_000, 75_000, 57_000),
];
private record Product(string Name, int Sold);
private readonly Product[] _top =
[
new("Stoneware mug", 214), new("Linen throw", 168), new("Oak serving board", 131), new("Beeswax candle", 97), new("Wool blanket", 84), new("Ceramic planter", 72),
];
}Add this example to a page with the izzy CLI:
izzy add component TileLayout --at <file>:<line>A tile's Title and Icon make its header, and HeaderEnd puts buttons or a figure at its end. Header replaces the title with your own content. Flush runs the content to the tile's edges, for Tabs or a DataGrid.
A Chart that is a tile's only content, with no Height, fills the tile. Name it by the tile's title: set the tile's TitleId and the chart's TitledBy. Put its buttons in HeaderEnd: ChartDownload, ChartResetZoom, ChartZoom and ChartPause act on the tile's chart.
A tile without Col and Row takes the first free cells, row by row, in the order written. Cells no tile covers stay empty.
Columns can change by breakpoint. Places and spans are for the widest count; at fewer columns, spans shrink in proportion and the tiles wrap in reading order, by row and then by column. At one column they stack.
Rearranging the tiles
Set Editable to let people move and resize the tiles. Dragging a tile moves it a cell at a time, and dragging its corner grip resizes it. Most dashboards turn editing on with an Edit layout button, and off with Save or Cancel.
Static
Preview
Code
@* A support lead arranging the team dashboard. Edit layout turns on editing; Save layout keeps the
new layout and Cancel drops it. On a static page the buttons post the form (the layout travels
in it), and with JavaScript off so does each move from a tile's menu. *@
<Stack Grow>
<Form Model="this" FormName="tile-layout-edit" OnValidSubmit="Submitted">
<Stack Gap="3">
<Row Gap="2" Align="Align.Center" Wrap>
<TextBlock Weight="FontWeight.Medium" Grow>Support dashboard</TextBlock>
if (_editing)
{
Action("cancel", "Cancel", ButtonVariant.Outline, null)
Action("save", "Save layout", ButtonVariant.Solid, Lucide.Check, focus: _focus)
if (!RendererInfo.IsInteractive)
{
<input type="hidden" name="editing" value="1" />
}
}
else
{
Action("edit", "Edit layout", ButtonVariant.Outline, Lucide.LayoutDashboard, focus: _focus)
}
</Row>
<TileLayout Columns="new() { Base = 1, Md = 6 }" Rows="3" RowHeight="Length.Rem(7)" aria-label="Support dashboard"
Editable="_editing" ShowGrid="_editing" Name="layout" Post="(_editing ? Posted : null)" @bind-State="_layout">
<Tile Id="open" Label="Open tickets" Col="1" Row="1" ColSpan="2" MinColSpan="2">
<Stat Label="Open tickets" Value="42" Change="5" Trend="StatTrend.Down" ChangeStatus="Status.Success" Description="since Monday" />
</Tile>
<Tile Id="response" Label="First response" Col="3" Row="1" ColSpan="2" MinColSpan="2">
<Stat Label="First response" Value="38 min" Change="6 min" Trend="StatTrend.Down" ChangeStatus="Status.Success" Description="vs last week" />
</Tile>
<Tile Id="satisfaction" Label="Satisfaction" Col="1" Row="2" ColSpan="2" MinColSpan="2">
<Stat Label="Satisfaction" Value="94%" Change="1 pt" Trend="StatTrend.Up" Description="last 30 days" />
</Tile>
</TileLayout>
if (_saved is not null && !_editing)
{
<TextBlock Size="TextSize.Sm" Color="Color.Muted">Saved: _saved</TextBlock>
}
</Stack>
</Form>
</Stack>
{
[SupplyParameterFromForm(FormName = "tile-layout-edit", Name = "layout")]
private TileLayoutPost? Posted { get; set; }
// Which button posted (static pages); null for a move from a tile's menu.
[SupplyParameterFromForm(FormName = "tile-layout-edit", Name = "do")]
private string? Do { get; set; }
// Set while editing, so a move from a tile's menu (JavaScript off) stays in edit mode.
[SupplyParameterFromForm(FormName = "tile-layout-edit", Name = "editing")]
private string? EditingPosted { get; set; }
// The layout shown (and, while editing, being changed), and the one saved.
private TileLayoutState? _layout;
private TileLayoutState? _saved;
private bool _editing;
// A static page comes back after a button posted: focus goes to the button now in its place.
private bool _focus;
protected override void OnInitialized()
{
_saved = Load();
_layout = _saved;
_editing = EditingPosted == "1";
}
// A static page: the button that posted, or a move from a tile's menu (stays in edit mode).
private void Submitted()
{
_focus = Do is not null;
if (Do is not null)
{
Act(Do);
}
}
private void Act(string what)
{
switch (what)
{
case "edit":
_editing = true;
return;
case "save":
// Static: the layout came in the post. Interactive: @bind-State kept it.
// An app saves it per user, as a TileLayoutState string.
_saved = RendererInfo.IsInteractive ? _layout : Posted?.State ?? _saved;
break;
}
_layout = _saved;
_editing = false;
}
// Edit layout only from the Md breakpoint up, where the tiles can be arranged.
private RenderFragment Action(string what, string text, ButtonVariant variant, IconData? icon, bool focus = false) => __builder =>
{
var accent = variant == ButtonVariant.Solid ? Accent.Primary : Accent.Neutral;
var from = what == "edit" ? Breakpoint.Md : (Breakpoint?)null;
if (RendererInfo.IsInteractive)
{
<Button Variant="variant" Accent="accent" StartIcon="icon" VisibleFrom="from" OnClick="() => Act(what)">@text</Button>
}
else
{
<Button Variant="variant" Accent="accent" StartIcon="icon" VisibleFrom="from" Submit Name="do" Value="@what"
autofocus="@focus" data-ib-autofocus="@(focus ? "" : null)">@text</Button>
}
};
}Static: Tiles move in place, and the form posts the layout when it's submitted.
A tile in the way takes the moved tile's old cells when it fits there, so two tiles of a size swap. Otherwise it moves down, and the tiles below it move with it. Tiles stay where they're dropped, so cells can stay empty; set Compact to have every tile rise into the space above it after each move.
Collision changes what a move onto a tile does: Block stops the tile at its last free spot, and Overlap lets it cover the other. A move that would leave the grid or break a tile's MinColSpan, MaxColSpan, MinRowSpan or MaxRowSpan is disabled.
ShowGrid outlines every cell while editing, and Rows keeps the empty rows. Editing works at the widest column count; with fewer columns the handles hide.
Each tile's handle opens a menu of the same moves. Each tile needs an Id, and a Title or Label to name its handle.
A saved layout
To show a layout someone arranged, pass it as State. It places and sizes each tile by its Id, over the tile's own values.
Static
Preview
- Open tickets
- 42
- First response
- 38 min
- Satisfaction
- 94%
Code
@* A support lead's own arrangement of the team dashboard, read back from where it was saved. *@
<TileLayout Columns="new() { Base = 1, Md = 6 }" RowHeight="Length.Rem(7)" State="_saved" aria-label="Support dashboard">
<Tile Id="open" Col="1" Row="1" ColSpan="2">
<Stat Label="Open tickets" Value="42" Change="5" Trend="StatTrend.Down" ChangeStatus="Status.Success" Description="since Monday" />
</Tile>
<Tile Id="response" Col="3" Row="1" ColSpan="2">
<Stat Label="First response" Value="38 min" Change="6 min" Trend="StatTrend.Down" ChangeStatus="Status.Success" Description="vs last week" />
</Tile>
<Tile Id="satisfaction" Col="5" Row="1" ColSpan="2">
<Stat Label="Satisfaction" Value="94%" Change="1 pt" Trend="StatTrend.Up" Description="last 30 days" />
</Tile>
</TileLayout>
{
// Saved with _saved.ToString() in a cookie or the user's profile; here, read from the text.
private readonly TileLayoutState? _saved = TileLayoutState.Parse("satisfaction:1,1,3,1;open:4,1,3,1;response:1,2,6,1");
}ToString writes a TileLayoutState as a short string, for a cookie or a database column, and TileLayoutState.Parse reads it back.
Tiles the state doesn't name keep their own place, and entries for tiles that aren't there are ignored.
A dashboard each person arranges
To let people arrange a dashboard and keep it, turn Editable and ShowGrid on from an Edit layout button, and save State when they press Done. Cancel puts the saved layout back, and Reset layout goes back to the default.
Preview
Code
@* A store's overview that each person arranges. Edit layout turns on editing: tiles drag and
resize, and their handles' menus move them. Done saves the layout, Cancel drops the changes and
Reset layout goes back to the default. On a static page the buttons post the form (the layout
travels in it); on an interactive one they act in place. *@
Microsoft.AspNetCore.Http
<AppShell Variant="ShellVariant.Canvas">
<AppHeader>
<AppBrand Icon="Lucide.Store" Label="Northwind" />
<Box Grow />
<Avatar Name="Maya Patel" Size="AvatarSize.Sm" />
</AppHeader>
<AppMain>
<Form Model="this" FormName="store-tiles" OnValidSubmit="Submitted">
<Stack Gap="5" Padding="new() { Base = 4, Md = 6 }">
<Row Gap="3" Align="Align.Center" Wrap>
<Stack Gap="1" Grow>
<Heading Level="1" Size="TextSize.Xl2">Store overview</Heading>
<TextBlock Size="TextSize.Sm" Color="Color.Muted">(_editing ? "Drag a tile to move it, or its corner to resize it." : "This week, against last week.")</TextBlock>
</Stack>
if (_editing)
{
Action("reset", "Reset layout", ButtonVariant.Ghost, null)
Action("cancel", "Cancel", ButtonVariant.Outline, null)
Action("done", "Done", ButtonVariant.Solid, Lucide.Check, focus: _focus)
if (!RendererInfo.IsInteractive)
{
<input type="hidden" name="editing" value="1" />
}
}
else
{
Action("edit", "Edit layout", ButtonVariant.Outline, Lucide.LayoutDashboard, focus: _focus)
}
</Row>
<TileLayout Columns="new() { Base = 1, Md = 6, Lg = 12 }" RowHeight="Length.Rem(7)" aria-label="Store overview"
Editable="_editing" ShowGrid="_editing" Name="tiles" Post="(_editing ? Posted : null)" @bind-State="_layout">
<Tile Id="revenue" Label="Revenue" Col="1" Row="1" ColSpan="3" MinColSpan="2">
<Stat Label="Revenue" Value="$84,320" Change="9.4%" Trend="StatTrend.Up" Description="vs last week" />
</Tile>
<Tile Id="orders" Label="Orders" Col="4" Row="1" ColSpan="3" MinColSpan="2">
<Stat Label="Orders" Value="1,284" Change="6.1%" Trend="StatTrend.Up" Description="vs last week" />
</Tile>
<Tile Id="average" Label="Average order" Col="7" Row="1" ColSpan="3" MinColSpan="2">
<Stat Label="Average order" Value="$65.67" Change="3.0%" Trend="StatTrend.Up" Description="vs last week" />
</Tile>
<Tile Id="returns" Label="Returns" Col="10" Row="1" ColSpan="3" MinColSpan="2">
<Stat Label="Returns" Value="2.1%" Change="0.4 pts" Trend="StatTrend.Down" ChangeStatus="Status.Success" Description="vs last week" />
</Tile>
<Tile Id="channels" Title="Revenue by channel" TitleId="store-channels-title" TitleLevel="2" Col="1" Row="2" ColSpan="8" RowSpan="3" MinColSpan="4" MinRowSpan="2">
<HeaderEnd>
<ChartDownload />
</HeaderEnd>
<ChildContent>
<Chart Items="_channels" Argument="m => m.Month" TitledBy="store-channels-title" Stacking="ChartStacking.Normal">
<ChartValueAxis Format="$#,##0,K" />
<ChartBarSeries Value="m => m.Online" Name="Online store" />
<ChartBarSeries Value="m => m.Marketplace" Name="Marketplaces" />
<ChartBarSeries Value="m => m.Wholesale" Name="Wholesale" />
</Chart>
</ChildContent>
</Tile>
<Tile Id="products" Title="Top products" TitleLevel="2" Col="9" Row="2" ColSpan="4" RowSpan="3" MinColSpan="3" MinRowSpan="2">
<Stack Gap="3">
foreach (var product in _top)
{
<Row Gap="3" Align="Align.Center">
<Avatar Name="product.Name" Size="AvatarSize.Sm" Decorative />
<TextBlock Size="TextSize.Sm" Grow>product.Name</TextBlock>
<TextBlock Size="TextSize.Sm" Weight="FontWeight.Medium" TabularNums>product.Sold sold</TextBlock>
</Row>
}
</Stack>
</Tile>
<Tile Id="visitors" Title="Visitors" TitleId="store-visitors-title" TitleLevel="2" Col="1" Row="5" ColSpan="4" RowSpan="2" MinColSpan="3" MinRowSpan="2">
<HeaderEnd>
<TextBlock Size="TextSize.Xl2" Weight="FontWeight.Light" TabularNums>12.4K</TextBlock>
</HeaderEnd>
<ChildContent>
<Chart Items="_visitors" Argument="d => d.Day" TitledBy="store-visitors-title">
<ChartLineSeries Value="d => d.Count" Name="Visitors" />
</Chart>
</ChildContent>
</Tile>
<Tile Id="recent" Title="Recent orders" TitleLevel="2" Col="5" Row="5" ColSpan="8" RowSpan="2" MinColSpan="4" MinRowSpan="2">
<Stack Gap="2">
foreach (var order in _recent)
{
<Row Gap="3" Align="Align.Center">
<TextBlock Size="TextSize.Sm" TabularNums Color="Color.Muted">#order.Number</TextBlock>
<TextBlock Size="TextSize.Sm" Grow>order.Customer</TextBlock>
<Badge Status="order.Status" Variant="BadgeVariant.Soft">order.State</Badge>
<TextBlock Size="TextSize.Sm" Weight="FontWeight.Medium" TabularNums>order.Total.ToString("C")</TextBlock>
</Row>
}
</Stack>
</Tile>
</TileLayout>
</Stack>
</Form>
</AppMain>
</AppShell>
{
[SupplyParameterFromForm(FormName = "store-tiles", Name = "tiles")]
private TileLayoutPost? Posted { get; set; }
// Which button posted (static pages); null for a move from a tile's menu.
[SupplyParameterFromForm(FormName = "store-tiles", Name = "do")]
private string? Do { get; set; }
// Set while editing, so a move from a tile's menu (JavaScript off) stays in edit mode.
[SupplyParameterFromForm(FormName = "store-tiles", Name = "editing")]
private string? EditingPosted { get; set; }
// The layout shown (and, while editing on an interactive page, being changed), and the one saved.
private TileLayoutState? _layout;
private TileLayoutState? _saved;
private bool _editing;
// A static page comes back after Edit layout, Done, Cancel or Reset layout: focus goes to the
// button that's now in the same place (Done, or Edit layout), not to the first in the row.
private bool _focus;
protected override void OnInitialized()
{
_saved = Load();
_layout = _saved;
_editing = EditingPosted == "1";
}
// A static page: the button that posted, or a move from a tile's menu (stays in edit mode).
private void Submitted()
{
_focus = Do is not null;
switch (Do)
{
case "edit":
_editing = true;
break;
case "done":
Act("done");
break;
case "cancel" or "reset":
Act(Do);
break;
}
}
private void Act(string what)
{
switch (what)
{
case "edit":
_editing = true;
return;
case "done":
// Static: the layout came in the post. Interactive: @bind-State kept it.
_saved = RendererInfo.IsInteractive ? _layout : Posted?.State ?? _saved;
Save(_saved);
break;
case "reset":
_saved = null;
Save(null);
break;
}
_layout = _saved;
_editing = false;
}
// Edit layout only from 1024px up, where tiles can be arranged (the layout's widest columns).
private RenderFragment Action(string what, string text, ButtonVariant variant, IconData? icon, bool focus = false) => __builder =>
{
var from = what == "edit" ? Breakpoint.Lg : (Breakpoint?)null;
if (RendererInfo.IsInteractive)
{
<Button Variant="variant" Accent="@(variant == ButtonVariant.Solid ? Accent.Primary : Accent.Neutral)" StartIcon="icon" VisibleFrom="from" OnClick="() => Act(what)">@text</Button>
}
else
{
<Button Variant="variant" Accent="@(variant == ButtonVariant.Solid ? Accent.Primary : Accent.Neutral)" StartIcon="icon" VisibleFrom="from" Submit Name="do" Value="@what"
autofocus="@focus" data-ib-autofocus="@(focus ? "" : null)">@text</Button>
}
};
}On static pages the buttons post the form, with the layout in it, and with JavaScript off each move posts it too. This example keeps the layout in a cookie; an app would save it with the user.
Details
A Tile with both Col and Row goes there; one without them takes the first free cells, row by row, in the order written. State, a TileLayoutState saved for this person, overrides each tile's place and size by its Id; tiles it doesn't name keep their own. Spans are kept inside the columns (and Rows, when set). Each tile is as tall as the rows it spans, and its content scrolls inside it when longer.
Columns can change by breakpoint. Places and spans are for the widest count; at each narrower one, spans shrink in proportion (8 of 12 is 4 of 6) and the tiles wrap in reading order, by row and then by column, with no empty cells. At 1 column they stack. Unless Base is set, the tiles stack below the first breakpoint given.
Editable lets people rearrange the tiles at the widest column count. With script, dragging a tile moves it (from anywhere but its controls) and dragging its corner grip resizes it, a cell at a time. A tile in the way swaps into the moved tile's old cells when it fits there, else it moves down. Tiles stay where they're dropped; with Compact, every tile then rises to fill the space above it. Collision Block stops a tile at its last free spot instead, and Overlap lets tiles cover each other. Each tile's handle opens a menu of the same moves, which with JavaScript off post the form.
Parts
Written inside TileLayout. The API page lists their parameters.
Tile: one tile of aTileLayout: a header with an icon, title and actions, over its content.
Mode support
| Feature | Static | Interactive |
|---|---|---|
| Everything | Yes | Yes |
Static: static server-side rendering, with no circuit and no WebAssembly. Interactive: Server, WebAssembly or Auto.
Accessibility
- The layout is a list and each tile an item, named by its title, so screen readers say how many tiles there are and which one they're in.
- A tile's Title is a heading (TitleLevel, 3 by default), so screen readers can jump from tile to tile.
- Screen readers and the Tab key follow the order the tiles are written in, not where they're drawn. Write them in reading order (by row, then by column), or sort the tiles you render from a list by their saved place.
- In an editable layout, each tile's handle is a button named "Move" and the tile's name, whose menu moves and resizes it; nothing needs dragging. Each move is announced: "Moved Revenue to column 3, row 1", "Resized Revenue to 6 by 2 cells".
Keyboard navigation
| Press this key | To do this |
|---|---|
| Alt+Left or Alt+Right or Alt+Up or Alt+Down | On a tile's handle, move the tile a cell (Left and Right reversed on right-to-left pages) |
| Alt+Shift+Right or Alt+Shift+Left | On a tile's handle, make it a column wider or narrower |
| Alt+Shift+Down or Alt+Shift+Up | On a tile's handle, make it a row taller or shorter |
| Escape | While dragging, put the tile back |
Parameters
| Prop | Type | Default |
|---|---|---|
ChildContentThe Tiles. | RenderFragment? | |
ColumnsHow many columns, all the same width, per breakpoint. | Responsive<int> | 1 md:12 |
RowsHow many rows at the widest column count, up to 200. | int | 0 |
RowHeightThe height of a row. | Length | 8rem |
GapSpace between tiles, in spacing steps (0 to 16). | int | 4 |
@bind-StateThe layout saved for this person: each tile's place and size by its Id. | TileLayoutState? | |
EditableLets the user move and resize the tiles: each gets a handle whose menu moves it a cell at a time and makes it wider, narrower, taller or shorter. | bool | false |
ShowGridWhile Editable, outlines every cell, so the user sees where tiles can go. | bool | false |
CollisionWhat a move onto another tile does. | TileCollision | TileCollision.Push |
CompactWith TileCollision.Push, every tile rises as far as it can after each move, closing the gaps above it. | bool | false |
NameOn a static page, the name an editable layout posts under: {Name}.Tiles (the layout shown) and {Name}.Move (a move from a tile's menu), bound as a TileLayoutPost. | string? | |
PostOn a static page, what the layout posted, bound under its Name: it shows the posted layout with the posted move made, over State. | TileLayoutPost? |
Plus 17 item props and 4 common props.
Full APISee also
- Grid: lays out its children in columns set by breakpoint, by minimum width or by template.
- Card: groups media, a header, body sections, actions and a footer in a box.
- Stat: shows a figure with its trend, read as words.