package page→ /design/conventions/layout.md
pages/design/conventions/layout.md
72 lines, 5.3 KB. As a page.
- ---
- type: Convention
- title: "Lens layout"
- description: "The regions, slots, behavior and browser API of a replaceable layout package."
- icon: "🪟"
- ---
- # Lens layout
- A layout package follows `design/conventions/layout`. Choose its id in `layout:` on [Design](/design/design.md).
- ## 1. What it covers
- A layout places the left sidebar, right settings panel, page, canvas and optional left panel. It also provides a host for
- cards opened from a lens. The same lens content can run in different layouts.
- ## 2. Gives
- The package publishes `/design/<id>/layout.css` and `/design/<id>/layout.js`. The script assigns a layout object to
- `window.Layout`. The lens build bundles the chosen assets. Component sync publishes their paths in the design data. The kit provides a built-in layout when the choice is empty or
- its assets are missing.
- | Region | Required slots and state |
- |---|---|
- | Frame | `shell` with `data-sidebar`, `data-left` and `data-panel` set to `open` or `closed`. |
- | Left sidebar | `shell-sidebar` contains `sidebar`. Its head has `sidebar-header`, `sidebar-space`, `sidebar-space-mark`, `sidebar-space-name`, `sidebar-search-trigger`, `sidebar-search` and `sidebar-trigger`. |
- | Right and optional left panels | `shell-right` and `shell-left` contain `panel` with `data-side="right"` or `"left"`. Keep `panel-header`, `panel-title`, `panel-close`, `panel-body` and the right `panel-footer`. |
- | Settings | Keep the native `panel-section` details, `panel-section-trigger`, `panel-section-title`, `panel-section-meta`, `panel-section-content`, `panel-section-row`, `panel-section-label` and `panel-section-control`. |
- | Page and canvas | `shell-main` hosts the page, including existing `layout-document`, `layout-grid`, `layout-catalog` and `layout-canvas` slots and their parts. |
- | Folded sheets | `shell-trigger` with `data-target="sidebar|left|panel"` reopens its sheet. The sheet wrapper has `data-state="open|closed"`. Keep the sidebar's legacy `expanded|collapsed` variants and the existing open and closed frame attributes. |
- | Cards | `layout-card-host` accepts `data-mode="side|center|peek"` and `data-state="open|closed"`. A side card opens beside the page, a center card centers over it, and a peek opens near the triggering click. |
- Keep the legacy classes alongside the `data-slot` names. The remaining component parts and the lens author API are listed
- in [The lens shell](lens-shell.md).
- A layout makes each sheet foldable, restores the saved state and honors `?sidebar=closed&panel=closed` (also `left=`).
- Esc inside a sheet folds it and focus follows the fold or reveal. The sidebar search has an expanded state and focuses the
- field on reveal. Esc inside it closes search first. Settings remain in the right panel, with their sections and footer.
- | JavaScript API | Contract |
- |---|---|
- | `Layout.mount(root, {sidebar, panel, page, slot, icon, state})` | Attach a frame to `root`. Preserve the supplied DOM nodes. Return the controller below. `slot(tag, name, attrs, ...children)` builds legacy slots, `icon(name)` gives a panel icon and `state.get(key, fallback)` / `state.set(key, value)` handle URL overrides and storage. |
- | `parts.connect({shell, body, cardHost, sidebar, panel, insertLeft})` | Optional kit helper. Pass the two sheet wrappers and a function that inserts and returns the left wrapper. It wires the standard fold buttons, sidebar search, state and focus, and returns the controller. |
- | `frame.shell`, `frame.body`, `frame.cardHost` | The shell, the `shell-main` element, and the card host. The kit exposes the controller as `Lens.ui.layout`. |
- | `frame.panel()` | Return the supplied right panel. |
- | `frame.open(region, on, focus?)` | Set the state of `sidebar`, `left` or `panel`; move focus when requested. |
- | `frame.mountLeft(panel)` | Add the optional left panel and its reveal button. Restore its saved state. |
- | `frame.openCard(el, {mode, anchor})` | Reserved for LAY-2. Present `el` in `side`, `center` or `peek` mode. `anchor` is the triggering element or a pointer position `{clientX, clientY}`. Return a handle with `close()`. |
- ## 3. Expects
- Use the design tokens and the chosen library's generic `sidebar`, `panel`, `panel-section`, `collapsible`, `sheet`
- and `scroll-area` parts. The kit supplies sidebar links, search input, panel content and the page. The lens continues
- to own its content, settings and canvas controls.
- ## 4. Free to choose
- Choose the placement, sizing, insets and responsive arrangement. Sheets can float or dock. Keep the slots, state, focus,
- search, settings and canvas behavior in either arrangement.
- ## 5. Make an alternative
- 1. Create a package with `follows: [design/conventions/layout]` and publish its CSS and JS at the paths above.
- 2. Implement the frame API with the same slots. Read the contract tokens and use the library parts.
- 3. Install it and set `layout:` on Design to its id. A layout package may adopt itself on install when the field is empty.
- 4. Run `shtuk run design-components sync` and `shtuk run lenses build`. Check the same lenses before and after the switch.
- ## 6. Health
- Test the slots and public API on both the default layout and an alternate layout. Check the page, canvas, panel sections,
- sidebar search, folded buttons, remembered state, URL overrides and Esc. Verify the catalog, style, icons and package map
- in light and dark, with long labels and a viewport short enough to require scrolling.