ui/AppShell.svelte

Sidebar-and-main app shell. Provisions sidebar_state_context (creating a fresh SidebarState if sidebar_state is not supplied) so descendants can read sidebar visibility and toggle it. Optionally binds a global keyboard shortcut and renders a built-in toggle button (or a custom one via the toggle_button snippet) while the sidebar is enabled. Requires the SvelteKit runtime — it closes the overlay from afterNavigate.

Two modes, split by the state's narrow_query. Outside it the sidebar sits beside the content, padded by --sidebar_offset, following show_sidebar_wide. Inside it the sidebar starts closed and opens as an overlay over a scrim, following show_sidebar_narrow; the content is inert while it's open, and navigation, Escape, a scrim click, or widening out of narrow mode closes it. Escape never prevents the default, so the browser's close requests stay intact; it does nothing while a modal (:modal) is open, when a window keydown listener registered before the overlay opened swallows it (a contextmenu, say), or when a visible Popover's document listener already handled it.

The open overlay is a modal dialog: the sidebar takes role="dialog", aria-modal, tabindex="-1", and sidebar_label as its name, and focus moves into it, to its first control that takes focus, else to the sidebar itself — the content went inert and dropped it. The attributes key on the open overlay, which reads the viewport — that's what keeps the wide sidebar from ever being a dialog — and the server render matches hydration because the overlay always starts closed, as with the content's inert. aria-modal lets assistive tech hide everything outside the sidebar, the built-in toggle included, so a sidebar whose screen-reader users need a close control beyond Escape and navigation renders its own.

Closing with Escape, the keyboard shortcut, or a scrim click returns focus to what opened the overlay, or else to the first element whose aria-controls names the sidebar's id and that takes it — when focus was inside the sidebar or had fallen to the body. The id is the state's sidebar_id when set, so a toggle outside the shell can carry aria-controls too; Safari doesn't focus a clicked button, so without it a mouse-opened overlay has no opener to return to.

The shell's rules sit in two cascade layers nested under fuz_app. fuz_app.app_shell_base, in the scoped style, holds the base and state rules, which apply in both modes; fuz_app.app_shell_narrow overrides some of them from a style element in svelte:head carrying media={narrow_query}, so the server render paints the right mode before hydration and the markup's classes never depend on the viewport. The narrow layer is ordered after the base layer, so it wins whatever the selectors' specificity or the sheets' order. Its rules are global — they match every .app-shell on the page — so shells mounted at the same time must share a narrow_query. Pages served under a strict CSP need style-src-elem 'unsafe-inline' or the hash of that constant style.

Public class hooks: .app-shell (root, with state classes .wide-open / .narrow-open), .app-shell-content, .app-shell-sidebar, .app-shell-scrim, .app-shell-toggle, .app-shell-toggle-glyph. Any unlayered rule beats both layers at any specificity, so overrides need no specificity games; to layer them instead, order fuz_app first (@layer fuz_app, overrides;) in a sheet that loads before the shell. The same rule means an unlayered reset overrides the shell too — the fuz_css reset zeroes padding, margin, and border on every element — so the layers set none of those. The one they need, the content's wide offset, goes through --sidebar_offset: the layers set it on .app-shell-content (--sidebar_width while the wide sidebar is open, else 0px), and one unlayered rule at (0,0,1) reads it into the content's padding-left. Descendants of the content can read it too. Override the offset by setting --sidebar_offset on .app-shell-content or with a padding-left rule there; a padding shorthand there overrides it as well. Like any unlayered override, these apply in both modes, open or closed; to change only the wide open offset, target .app-shell.wide-open > .app-shell-content inside the narrow query's negation — the state classes don't track the viewport, so .wide-open stays set in narrow mode too. CSS variables: --sidebar_bg, --sidebar_z_index (default 200 in both modes; the toggle sits one above), --sidebar_scrim_bg, --sidebar_width (set from the sidebar_width prop; always the configured width, not the offset), and --sidebar_offset.

view source

Declarations
#

AppShell
#

ui/AppShell.svelte view source

accepts children

import AppShell from '@fuzdev/fuz_app/ui/AppShell.svelte';

children

type Snippet<[]>

sidebar

type Snippet<[]>

sidebar_width?

Sidebar width in pixels when shown; in narrow mode capped at 85vw.

type number
optional default 180

sidebar_label?

Accessible name for the sidebar while it's the narrow-mode overlay, announced as a modal dialog.

type string
optional default 'sidebar'

sidebar_state?

Optional pre-built SidebarState for sharing visibility across shells.

optional

keyboard_shortcut?

Single-key shortcut that toggles the sidebar (e.g. 'b') while it's enabled and no modal is open — the persistent sidebar in wide mode, the overlay in narrow mode. false disables.

type string | false
optional default false

show_toggle?

Whether to render the built-in (or custom) toggle button. It renders only while the sidebar is enabled either way.

type boolean
optional default true

toggle_button?

Custom toggle-button renderer; receives the title, visibility, toggle callback, and the sidebar element's id. Give the button class="app-shell-toggle" so it stacks above the sidebar and scrim (it renders as a direct child of the root) — the z-index applies only to a positioned button, so position it (e.g. position: fixed) — and aria-controls={sidebar_id} so closing can return focus to it. show_sidebar is viewport-dependent: the server renders it as in wide mode, so rendering it as visible content changes on hydration at narrow widths — attributes are repaired, but key visible content on CSS or the viewport-free fields instead.

type Snippet<[{ title: string; show_sidebar: boolean; toggle: () => void; sidebar_id: string; }]>
optional
snippet parameters
arg0 { title: string; show_sidebar: boolean; toggle: () => void; sidebar_id: string; }

class?

type ClassValue | null
optional

CSS custom properties

--sidebar_bg
fallback var(--shade_05)
--sidebar_z_index
fallback 200
--sidebar_scrim_bg
fallback var(--darken_40)

external types

SvelteHTMLElements['div']

Depends on
#