Layout and containers
Grid, stacks, tabs, guard, placeholder and the page layouts that hold every other component.
Overview
Layout components hold other components. They come in two kinds.
| What you want to change | Use |
|---|---|
| The frame around a page: dashboard, settings, or no navigation | A page layout (DefaultLayout, SettingsLayout, EmptyLayout). |
| The arrangement of blocks inside the page | A container builder (Grid, stacks, or tabs). |
See the settings-page screenshot for the frame and the container previews for the blocks inside it. The reference below gives their exact contracts.
Containers are builders: Grid, GridRow, HStack, VStack, Spacer, Tab, Guard and Placeholder return a ComponentBuilder, and you nest components inside them with .child(id, component). They are assigned to a static field of a page class like any other component.
Page layouts are not builders: DefaultLayout, FormPageLayout, SettingsLayout and EmptyLayout return a plain ComponentInfo and are passed as the third argument of PageController, or as the layout option of a page or category (the default of everything declared under it), to say how the page's chrome is drawn.
CustomComponent sits outside both: it names a Vue component from the frontend registry and gives you a builder for it, which is the escape hatch when the vocabulary on this page is not enough.
import { Grid, GridRow } from "@antelopejs/interface-dms/base/grid";
import { HStack, Spacer, VStack } from "@antelopejs/interface-dms/base/stack";
import { Tab } from "@antelopejs/interface-dms/base/tab";
import { Guard } from "@antelopejs/interface-dms/base/guard";
import { DefaultLayout, EmptyLayout, FormPageLayout, SettingsLayout } from "@antelopejs/interface-dms/base/layouts";
import { Placeholder } from "@antelopejs/interface-dms/base/placeholder";
import { CustomComponent } from "@antelopejs/interface-dms/base/custom";
Grid, GridRow, HStack, VStack, Spacer, Tab, Guard, Placeholder, DefaultLayout, FormPageLayout, SettingsLayout and EmptyLayout are also exported from the base barrel. CustomComponent is only exported from @antelopejs/interface-dms/base/custom.
Grid
Grid is a container whose direct children are GridRows. The number of columns follows the widest row.
import { Grid, GridRow } from "@antelopejs/interface-dms/base/grid";
import { KpiCard } from "@antelopejs/interface-dms/base";
static kpis = Grid({ gap: "1rem" }).child(
"kpiRow",
GridRow()
.child("proposed", KpiCard({ title: "Proposed", fetchUrl: "/metrics/proposed" }))
.child("approved", KpiCard({ title: "Approved", fetchUrl: "/metrics/approved" }))
.child("denied", KpiCard({ title: "Denied", fetchUrl: "/metrics/denied" })),
);
GridOptions:
| Option | Type | Description |
|---|---|---|
gap | string | Gap between rows and columns, as a CSS length. Defaults to "1rem". |
minColumnWidth | string | Width below which a column is dropped rather than squeezed. Defaults to "240px". |
GridRow() takes no options. Its children are laid out horizontally within the row.
.child() accepts a third argument of extra metadata, which is carried verbatim onto the serialized child alongside its id. That is how a child declares that it spans more than one column:
GridRow().child("chart", chartCard, { colSpan: 2 }).child("list", topListCard);
Stacks
HStack and VStack arrange their children along one axis; Spacer fills the leftover space between them.
import { HStack, Spacer } from "@antelopejs/interface-dms/base/stack";
static toolbar = HStack({ alignment: "center", distribution: "space-between", spacing: "16px" })
.child("title", titleComponent)
.child("gap", Spacer())
.child("actions", actionsComponent);
StackAlignment is "start" | "center" | "end" | "stretch" and StackDistribution is "start" | "center" | "end" | "space-between" | "space-around" | "space-evenly".
HStackOptions
| Option | Type | Description |
|---|---|---|
alignment | StackAlignment | Vertical alignment of children. Defaults to "center". |
distribution | StackDistribution | Horizontal distribution of children. Defaults to "start". |
spacing | string | Space between children, as a CSS length. Defaults to "8px". |
wrap | boolean | Wrap children onto the next line when the row runs out of space. Defaults to false. |
grow | number | Share of the parent stack's free space this stack takes, against its siblings. Unset, a stack nested in an HStack shares the row equally with its sibling stacks, or keeps its content width when the row has a Spacer. |
VStackOptions
| Option | Type | Description |
|---|---|---|
alignment | StackAlignment | Horizontal alignment of children. Defaults to "center". |
distribution | StackDistribution | Vertical distribution of children. Defaults to "start". |
spacing | string | Space between children, as a CSS length. Defaults to "8px". |
grow | number | Share of the parent stack's free space this stack takes, against its siblings. Unset, a stack nested in an HStack shares the row equally with its sibling stacks, or keeps its content width when the row has a Spacer. |
SpacerOptions
| Option | Type | Description |
|---|---|---|
minSize | string | Minimum size, as a CSS length. No minimum by default. |
maxSize | string | Maximum size, as a CSS length. No maximum by default. |
grow | number | Flex grow factor. Defaults to 1. |
The three builders apply their defaults into the options they carry, so a Spacer() with no arguments still ships { grow: 1 }.
Tabs
Tab declares a tab bar. Each TabItem names a slot, and the component that belongs in a tab is attached as a child with that slot.
import { Tab, TabVariant } from "@antelopejs/interface-dms/base/tab";
import { Color, Size } from "@antelopejs/interface-dms/base/types";
static tabs = Tab({
items: [
{ label: "Overview", slot: "overview", icon: "i-ph-gauge" },
{ label: "Members", slot: "members", icon: "i-ph-users", badge: 12 },
],
variant: TabVariant.pill,
color: Color.primary,
size: Size.medium,
persistState: true,
stateKey: "tenant-tabs",
})
.child("overview", overviewComponent, { slot: "overview" })
.child("members", membersTable, { slot: "members" });
TabProps
TabProps extends BaseComponentProps.
| Option | Type | Description |
|---|---|---|
items | TabItem[] | The tabs. Required. |
color | Color | Colour of the active tab. |
size | Size | Control size. |
variant | TabVariant | TabVariant.pill or TabVariant.link. |
orientation | AxeOrientation | Direction of the tab bar. |
fit | boolean | A horizontal pill list as wide as its tabs instead of the full width; a link list already sizes its tabs to their labels. Defaults to false. |
unmountOnHide | boolean | Discard a tab's content when it is not active. |
persistState | boolean | Keep the active tab in the URL by its slot (?<stateKey>=<slot>); an index (?tab=2) is still read. |
stateKey | string | Key the state is stored under. |
TabItem
| Field | Type | Description |
|---|---|---|
label | string | Tab label. Required. |
slot | string | Slot name the tab's content is attached to. Required. |
icon | string | Leading icon. |
badge | BlockText | number | BadgeProps | Badge on the tab; a $ key, a ComposedText and a BadgeProps label are translated. |
disabled | boolean | Make the tab unselectable. |
shortcut | string | Keyboard shortcut. |
avatar | { src?: string; alt?: string; size?: Size } | Leading avatar. |
BadgeProps is { label?: string | number; color?: string; variant?: "solid" | "outline" | "soft" | "subtle"; size?: Size }. Note that its variant union is its own, narrower than ButtonVariant.
TabEvents.TAB_CHANGE is "DmsComponent.Tab.Change".
Guard
Guard is a container that renders its children unchanged unless a route says there is nothing for them; then it renders one EmptyState, its fallback, in their place. Several children stack with the spacing the page puts between its blocks.
import { Guard } from "@antelopejs/interface-dms/base/guard";
static statistics = Guard({
fetchUrl: "/api/routes/activity?route={{query.route}}", // { calls: 0 }
periodScope: "api",
field: "calls",
fallback: {
title: "$api.routes.statistics.idle_title",
actions: [{ label: "$api.routes.test", to: "/modules/api/routes?tab=tester" }],
},
}).child("charts", statisticsGrid);
GuardOptions:
| Option | Type | Description |
|---|---|---|
fetchUrl | string | The route read. It takes the {{params.X}} / {{query.X}} tokens of a block's fetchUrl; nothing is requested while one has no value. |
fetchUrlMethod | HttpMethod | Method of the request. |
periodScope | string | Id of the PeriodSelector the route is read with, again on each change. |
realtimeTopic | string | string[] | Topics whose events make the guard read the route again. |
when | GuardCondition | "empty" (the default): the value at field is absent, null, false, 0, "" or []. "notFound": the route answers 404. |
field | string | Dot path of the value "empty" checks; the whole answer without it. |
fallback | GuardFallback | An EmptyState's options without watchActions, all optional. The title defaults to "Nothing to show yet", or "Not found" for "notFound", in the reader's language; for "notFound" the description defaults to the 404 body's message, as for a block. |
An emptyState object in the answer, or in the body of the 404, is laid over fallback. The children show while the route loads, after any failure other than the condition, and whenever the value is set. The guide is Layout & containers.
Placeholder
Placeholder renders a labelled box. It exists so a layout can be assembled and reviewed before the real components are written. It takes PlaceholderOptions:
import { Placeholder } from "@antelopejs/interface-dms/base/placeholder";
static preview = Placeholder({ label: "Chart goes here", height: "200px" });
| Option | Type | Description |
|---|---|---|
label | string | Text shown in the box. |
height | string | CSS height. Defaults to "120px". |
width | string | CSS width. Auto by default. |
CustomComponent
CustomComponent(componentName) returns a bare ComponentBuilder for a frontend component resolved by name. Nothing else in the base domain is involved: the options you pass with .options() are handed to that component as-is, and the component itself comes from a frontend module registered with AddFrontendModule.
import { CustomComponent } from "@antelopejs/interface-dms/base/custom";
static changes = CustomComponent("DmsAssistantChangesView").meta({
name: "Changes",
icon: "i-ph-git-diff",
});
Since the return value is an ordinary builder, .options(), .child(), .meta(), .watch(), .onCreated() and .onFilter() all apply, and the component can hold base components as children.
CustomComponent is also how a table view's formContainer.pages.*.customPage option is used: you register your own page carrying a custom component at the slug the table view would otherwise generate. Declare that slug as the entry's urlSlug, which is taken relative to the page as it stands. See Tables.
Next steps
- Page layouts: The layouts a page renders in, its header actions, and pages that fill the panel.