MainOptions
Defined in: components/main.ts:13
Options for main.
Type Parameters
Section titled “Type Parameters”R = Routes
Properties
Section titled “Properties”attrs?
Section titled “attrs?”
optionalattrs?:string
Defined in: components/main.ts:15
Aberdeen attr/style string applied to the outermost shell element.
title?
Section titled “title?”
optionaltitle?:Slot
Defined in: components/main.ts:22
The app’s name, shown in the top bar in the brand’s own styling, with the breadcrumb stack of open panels on the line beneath it (in routed mode). In routed mode it is a link to the app’s MainOptions.home, as the MainOptions.logo is.
subtitle?
Section titled “subtitle?”
optionalsubtitle?:Slot
Defined in: components/main.ts:36
A tagline for the app, on the line under its name.
In routed mode that line is the breadcrumb stack’s, and the tagline only gets it while the stack would be saying nothing the screen doesn’t already: exactly one panel open, that panel being one a nav item leads to (so the sidebar has it highlighted), and the sidebar actually on screen. Open a panel on top of it, or narrow the shell until the nav is behind the ☰, and the stack takes the line back — it is then the only thing naming the screen. Pass no subtitle and the stack simply always has it.
Outside routed mode nothing competes for the line, so it always shows.
optionallogo?:Slot
Defined in: components/main.ts:45
The brand mark: the bar’s leading slot while the nav is a sidebar.
A narrow shell displaces it with the ☰ that opens the collapsed nav. The app never branches on which: it hands over a logo and the shell works out whether there is room for it. In routed mode it is a link to the app’s MainOptions.home, as the app’s name is.
optionalhome?:string
Defined in: components/main.ts:56
The app’s home: where the name and the MainOptions.logo in the
top bar link, as every logo on the web does. Defaults to "/"; set it
when your home screen lives elsewhere. It’s an ordinary link, so the
usual rules apply: a home that is already open in the stack — its first
panel, usually — is returned to, closing nothing, and one that isn’t is
opened the way a nav item would be. Pass null to link neither — for a
title or logo slot holding interactive content of its own, which
can’t sit inside a link. Routed mode only.
optionalmenu?:Slot
Defined in: components/main.ts:68
The app’s own chrome, at the trailing end of the top bar: an account button, a global search box, a settings menu. It may grow into the bar’s free space (so a search box is at home here); the title truncates before it gives any of it back.
In routed mode a narrow shell hands this slot to the current panel’s Panel.actions whenever it has any — on a phone the screen’s own verbs win the space — and keeps the app’s menu for the screens that declare none.
content?
Section titled “content?”
optionalcontent?:Slot
Defined in: components/main.ts:73
The scrollable panel content. A string is rendered as rich text. Mutually exclusive with MainOptions.routes.
routes?
Section titled “routes?”
optionalroutes?:R
Defined in: components/main.ts:141
Paths mapped to the functions that draw them, which hands navigation over to the shell. Each route draws one screen of your app, called a panel, and as many columns as fit are shown at a time: one at a time on a phone, several side by side on a wider screen. Mutually exclusive with MainOptions.content.
A segment wrapped in brackets is a param: [name] matches one segment as
a string, [name=integer] matches one segment as a number, and a trailing
[...name] matches the rest of the path as one raw (still percent-encoded)
string, so it has to come last and needs at least one segment to match.
The first key that matches wins, a segment a param refuses falls through
to a later route (or to MainOptions.notFound), and each handler’s
$panel.params is typed from its own key.
integer accepts only spellings that survive a round trip back to the
same URL, so /tasks/0042 is not a second path for /tasks/42. Ids that
aren’t safe integers, such as snowflakes, want a plain [id].
Navigating is just links: the shell handles the clicks itself, so do not
also call Aberdeen’s interceptLinks(). A link opens its target on top of
the panel it sits in, closing everything after that panel first. The
data-panel attribute keeps less of that context instead: replace
drops the link’s own panel too, putting the target in its place (history
entry included — a redirect), and
open drops it all, giving the target its own stack, the way a nav item
does. A plain link to something already open goes back to it rather than
opening it twice, closing whatever was stacked on top — pinned panels
excepted (see Panel.pinned), and panels holding unsaved work,
which park instead; a replace or open applies its usual shape, the
open panel moving into it alive. From code, use pushPanel and
friends: navigating with aberdeen/route’s own go() works too — a panel with
Panel.unsaved work still survives it — but builds the whole stack
from the path. A navigation guard the app registered with
route.setGuard (an auth redirect, say) keeps working: the shell
registers none of its own.
A panel declares its chrome; the shell places it. A panel says what it is called (Panel.title — unset, its first line of text stands in) and what it can do (Panel.actions); everything else in a column is the panel’s own content, boxes included. The shell writes the stack of open panels as breadcrumbs in the top bar — click one to go back to it — and places each panel’s actions where the room is: on its own column while several fit, in the bar once the shell is narrow and the current panel is the screen. Nothing in an app measures the viewport to lay its screens out twice.
Only one routed shell can be mounted at a time (a second one throws) —
the URL is global, so two of them would fight over it. Nothing else is:
the PanelStack belongs to its shell, which hands it back, and
each handler gets its own $panel rather than there being one global
“current panel”, since several panels are alive at once. It’s that
argument that carries the per-route typing of params.
Example
Section titled “Example”S.main({ title: "Trackle", nav: { items: [{ label: "Projects", href: "/projects" }] }, routes: { "/projects": ($panel) => { $panel.title = "Projects"; drawProjects(); }, "/projects/[id]": ($panel) => drawProject($panel.params.id), // typed string }, notFound: ($panel) => S.box({ header: "Not found", content: $panel.path }),});notFound?
Section titled “notFound?”
optionalnotFound?:RouteHandler<{ }>
Defined in: components/main.ts:147
Draws the panel for a path none of the routes match. There are no params
to go with it, so $panel.params is empty; the path itself is in
$panel.path.
ancestors?
Section titled “ancestors?”
optionalancestors?:AncestorTable<NoInfer<R>>
Defined in: components/main.ts:189
What to open beneath a path that arrives cold — a shared link, a bookmark, a push notification, a nav item — with no stack of its own to restore. Keyed by path template exactly like MainOptions.routes, so each entry gets that key’s params, matched and typed, rather than taking the path apart a second time.
Without this, the stack is derived from the path: every prefix that has a
route becomes a column, so /projects/7/tasks/42 opens three deep. That
only works for URLs that spell their own context out. A flat one —
/thread/[id], where a notification lands — has no prefix to walk, so it
opens as a single column with nothing under it and nothing to close back
to. This is where you say what that context is:
S.main({ routes: { "/mailbox/[id]": drawMailbox, "/thread/[id=integer]": drawThread, }, ancestors: { "/thread/[id=integer]": ({ id }) => [`/mailbox/${mailboxOf(id)}`], // id: number },});Return the paths shallowest first; the path itself goes on top. Return nothing to leave a path to the prefix derivation, which is also what an unlisted one gets — so you only list the routes whose URL doesn’t say where it belongs. Paths you have no route for are skipped, as they are there.
This is asked for every origin-less navigation, so a nav item and a fresh tab still land on the same columns; a link inside a panel builds on that panel instead and never asks. It’s consulted while the navigation is still being worked out — before any route handler runs — so it has to answer without drawing anything. From code, PanelStack.openPanelStack takes the same list directly.
columns?
Section titled “columns?”
optionalcolumns?:"auto"|"single"
Defined in: components/main.ts:203
How many panels are shown at a time. "auto" (the default) shows as
many columns, side by side, as comfortably fit, ending at the current
panel; "single" shows only the current panel, however wide the screen
— one screen at a time at every size, each still at its asked width
(the nav sidebar still sits beside it). Only the display
differs: the stack, the breadcrumbs, the URL, Escape and the back
button behave identically in both. Routed mode only.
Live: pass a proxied options object (or make this field a getter) and a change is adopted in place — one layout pass, every panel keeping its state.
alignment?
Section titled “alignment?”
optionalalignment?:PanelAlignment
Defined in: components/main.ts:216
Where the open columns sit when they don’t fill the content area — on a
wide screen with a single small panel open, say. "center" (the default)
splits the leftover room between both sides, "left" and "right" put it
all on one side, and "spaced" shares it out evenly over the gutters
beside and between the columns. Columns crowded out on the left take
precedence: while there are any, the run hugs the left edge whatever this
says. Routed mode only.
Live, like MainOptions.columns: a change is adopted in one layout pass, every panel keeping its state.
linkNavigation?
Section titled “linkNavigation?”
optionallinkNavigation?:"push"|"replace"|"open"
Defined in: components/main.ts:230
What a link without a data-panel attribute does — the per-link
attribute always wins. The three keep less and less of the link’s own
context: "push" (the default) builds on the panel the link sits in,
"replace" swaps that panel out (history entry included), and "open" ignores it and gives the
target its own stack, the way a nav item does. So with "open" every
click replaces the content as a whole — which, with flat routes, is the
conventional sidebar-and-content app: one pane, swapped on every click,
the crumb line simply naming it. Routed mode only.
Live, like MainOptions.columns: change it and the next click uses the new default.
footer?
Section titled “footer?”
optionalfooter?:Slot
Defined in: components/main.ts:232
Footer content, pinned below the scroll area.
maxWidth?
Section titled “maxWidth?”
optionalmaxWidth?:string
Defined in: components/main.ts:250
Max width for the shell’s content, e.g. "80rem". The header and footer
backgrounds still span the full shell width, but their contents — and the
sidebar + separator + content trio (or just the content when there’s no
sidebar) — cap to this width and centre horizontally. When unset, everything
fills the available width. Either way the content shares the panel surface —
it is not boxed.
In routed mode this is what the columns divide up (see Panel.maxWidth), which is the reason to set it on a very wide screen: left uncapped, a stack of small panels will happily march right across a 4K display.
Live, like MainOptions.columns: pass a proxied options object (or make this field a getter) and a change is adopted in one layout pass, every open panel keeping its state.
contentAttrs?
Section titled “contentAttrs?”
optionalcontentAttrs?:string
Defined in: components/main.ts:252
Aberdeen attr/style string applied to the content area.
topbarAttrs?
Section titled “topbarAttrs?”
optionaltopbarAttrs?:string
Defined in: components/main.ts:254
Aberdeen attr/style string applied to the top bar.
optionalnav?:MenuOptions
Defined in: components/main.ts:266
Navigation menu, rendered as a sidebar beside the content. The sidebar collapses to a ☰ in the top bar when the shell is narrow, and there it opens the nav as a full panel sliding in from the left, not as a dropdown.
items may be a reactive array: the shell reads it inside the sidebar’s own
scope, so an item arriving or leaving redraws the sidebar and nothing else.
The content beside it — in routed mode, the whole stack — is left
alone. button customizes the ☰; dropdownAttrs does nothing here, since
a collapsed nav is a panel rather than a dropdown.
navPosition?
Section titled “navPosition?”
optionalnavPosition?:"left"|"right"
Defined in: components/main.ts:276
Which side the nav sidebar sits on. Defaults to "left".
Either way it collapses to a ☰ in the top bar once the shell width drops to 640 px or below — the one threshold everything else keys off too, which is why there is no “always a button” mode: it would make “narrow” and “the nav is collapsed” two different things, and every rule about where a panel’s chrome goes assumes they are one.
navWidth?
Section titled “navWidth?”
optionalnavWidth?:number
Defined in: components/main.ts:283
How wide the nav sidebar column is, in pixels — its hairline included. Defaults to 200. Whatever it takes comes off the content area beside it.
Live, like MainOptions.maxWidth.
navResizable?
Section titled “navResizable?”
optionalnavResizable?:boolean
Defined in: components/main.ts:292
Lets the user resize the nav sidebar by dragging the hairline between it
and the content area, or with the arrow keys once it has focus. Defaults
to false.
A dragged width stands until MainOptions.navWidth changes, and stays between 120 px and half the shell.
navAttrs?
Section titled “navAttrs?”
optionalnavAttrs?:string
Defined in: components/main.ts:294
Aberdeen attr/style string applied to the sidebar nav panel.
navPageAttrs?
Section titled “navPageAttrs?”
optionalnavPageAttrs?:string
Defined in: components/main.ts:296
Aberdeen attr/style string applied to the narrow-screen full-page nav.