страница пакета→ /design/conventions/lens-shell.md
pages/design/conventions/lens-shell.md
137 строк, 11.4 КБ. Как страница.
Этот текст ещё не переведён. Ниже английский оригинал.
- ---
- type: Page
- title: "The lens shell"
- description: "The shell contract of a component library: the components of the level shell (sidebar, side panel and its foldable sections, the page frame, the page layouts document, grid, catalog and canvas), their data-slot names, and the right-panel API through which a lens fills sections and lands its settings."
- icon: "🐚"
- ---
- # The lens shell
- The [Lens layout convention](layout.md) defines the interchangeable frame, its behavior and its JavaScript API.
- This page lists the existing slot names and the lens author API. The level `shell` in a component library provides
- the generic parts a layout uses.
- ## 1. The level `shell`
- `shell` is a level between `block` and `page`: `primitive` < `composite` < `block` < `shell` < `page`. A shell component lies at
- `/design/<lib>/components/shell/<id>/<id>.html` and `<id>.css` (React: the same id under the library's `sources:`), has the
- usual header and a template for every state and data state, and uses its own level or lower.
- ## 2. The components and their slots
- The root of each component carries `data-slot="<id>"` and the class `<id>`; each part carries `data-slot="<part>"` and the class
- `<part>`. State is said by attributes, never by extra classes: `data-state="open|closed"`, `data-active="true"`,
- `data-side="left|right"`, `data-layout="…"`, `aria-current="page"`, the `open` attribute of `<details>`.
- | id | what | parts |
- |---|---|---|
- | `shell` | the page frame provided by the layout package | `shell-sidebar`, `shell-left`, `shell-main`, `shell-right`, `shell-trigger` |
- | `sidebar` | the left sidebar, as in the desktop app: a head (the project's mark and name as a heading, a search icon button, a fold button), groups with a pages tree, icons and counts, a footer (shadcn `sidebar`) | `sidebar-header`, `sidebar-space`, `sidebar-space-mark`, `sidebar-space-name`, `sidebar-search-trigger`, `sidebar-search`, `sidebar-content`, `sidebar-group`, `sidebar-group-label`, `sidebar-menu`, `sidebar-menu-item`, `sidebar-menu-button`, `sidebar-menu-icon`, `sidebar-menu-label`, `sidebar-menu-badge`, `sidebar-menu-action`, `sidebar-menu-sub`, `sidebar-footer`, `sidebar-trigger` |
- | `panel` | a side panel: the right panel, or the optional left one with `data-side="left"` | `panel-header`, `panel-title`, `panel-close`, `panel-body`, `panel-footer` |
- | `panel-section` | a plain section of a panel that folds and unfolds: a `<details>` | `panel-section-trigger`, `panel-section-title`, `panel-section-meta`, `panel-section-content`, `panel-section-row`, `panel-section-label`, `panel-section-control` |
- | `collapsible` | the shadcn collapsible: a `<details>` with any content | `collapsible-trigger`, `collapsible-content` |
- | `scroll-area` | a region that scrolls with a thin, quiet bar (shadcn `scroll-area`) | `scroll-area-viewport` |
- | `sheet` | a panel that slides over the page on a narrow screen (shadcn `sheet`) | `sheet-overlay`, `sheet-content`, `sheet-header`, `sheet-title`, `sheet-description`, `sheet-close`, `sheet-footer` |
- | `layout-document` | a page form: one readable column | `layout-document-column` |
- | `layout-grid` | a page form: cards in a grid of bounded width (no card wider than its content needs) | `layout-grid-items` |
- | `layout-catalog` | a page form: a stage that takes the whole page, and a tree of the things on it (the tree stands in the right panel as a section of `tree-item` rows, or on the page's left) | `layout-catalog-tree`, `layout-catalog-stage` |
- | `layout-canvas` | a page form: a surface with pan, zoom and fit, and an optional minimap | `layout-canvas-viewport`, `layout-canvas-stage`, `layout-canvas-controls`, `layout-canvas-zoom`, `layout-canvas-minimap` |
- The frame slots:
- ```html
- <div data-slot="shell" class="shell" data-sidebar="open" data-left="closed" data-panel="open">
- <aside data-slot="shell-sidebar" class="shell-sidebar"><nav data-slot="sidebar" class="sidebar">…</nav></aside>
- <aside data-slot="shell-left" class="shell-left"><section data-slot="panel" class="panel" data-side="left">…</section></aside>
- <main data-slot="shell-main" class="shell-main">
- <div data-slot="layout-canvas" class="layout-canvas">…</div>
- <button data-slot="shell-trigger" class="shell-trigger" data-target="panel" aria-label="Show the panel">…</button>
- </main>
- <aside data-slot="shell-right" class="shell-right"><section data-slot="panel" class="panel" data-side="right">…</section></aside>
- <div data-slot="layout-card-host" class="layout-card-host" data-state="closed" hidden></div>
- </div>
- ```
- - `data-sidebar`, `data-left`, `data-panel` on the frame open and close the three regions (`open` | `closed`); a closed region
- takes no room. A region the page does not use is left out of the markup.
- - `shell-trigger` buttons (`data-target="sidebar|left|panel"`) lie in `shell-main` and show only while their region is closed.
- In the minimal layout a trigger is the small square button of the explore kit demo: 36 px, white, the even shadow with a 1 px ring, radius `--radius`
- + 2 px, one 18 px panel icon (`panel-left` for the sidebar and the left panel, `panel-right` for the right panel), a lift of
- 1 px on hover. The sidebar's and the left panel's button stand in the top-left corner, the right panel's in the top-right
- corner. There is no other folded form (no pill with the title and a chevron). `shell-main` does not scroll; its layout does.
- - In the minimal layout, under 900 px the sidebar and the panels stop taking room and open over the page like a `sheet`.
- - The sidebar keeps `data-state="collapsed"` for its narrow form (icons only).
- - The head of the sidebar: `sidebar-space` (a link home) holds `sidebar-space-mark` (30 px, the project's initial; the one raspberry
- surface) and `sidebar-space-name` (16 px, semibold, truncated); at its right two icon buttons, `sidebar-search-trigger` and
- `sidebar-trigger` (folds the sidebar). `aria-expanded="true"` on the search trigger shows `sidebar-search`, a field under the head;
- the page toggles it, focuses the field, and closes it again on Esc. There is no separate Search row.
- A section of the right panel:
- ```html
- <details data-slot="panel-section" class="panel-section" open>
- <summary data-slot="panel-section-trigger" class="panel-section-trigger">
- <span data-slot="panel-section-title" class="panel-section-title">Cards</span>
- <span data-slot="panel-section-meta" class="panel-section-meta">12</span>
- </summary>
- <div data-slot="panel-section-content" class="panel-section-content">
- <div data-slot="panel-section-row" class="panel-section-row">
- <label data-slot="panel-section-label" class="panel-section-label">Size</label>
- <div data-slot="panel-section-control" class="panel-section-control">…</div>
- </div>
- </div>
- </details>
- ```
- Folding is the browser's own `<details>`: an HTML library needs no script for it. The chevron is drawn by the CSS.
- ## 3. The look the slots must keep
- These are the design rules for the shared components and the minimal layout:
- - The page (`shell-main`) is `--background`. The sidebar is `--sidebar`, its text `--sidebar-foreground`, the selected and
- hovered rows `--sidebar-accent`. The panels are `--background` with one hairline (`--border` or `--sidebar-border`) towards
- the page. No shadow, tray or card around a section; sections are separated by spacing and at most one hairline.
- - No top header. A page that needs a title, a search or breadcrumbs puts them into the sidebar's header or the left panel.
- - Text never overflows: labels truncate with an ellipsis (the full text in `title`), rows grow to two lines at most. The
- options of a segmented choice (`panel-section-seg`) are never cut: the choice keeps the width its options need, the options
- wrap to a second line when they do not fit, and a settings row puts the choice under its label when both do not fit in one row.
- - **No sheet runs the full window height.** The sidebar, the left panel and the right panel are each **as tall as their
- content**, at most the window less the insets (12 px at the top and the bottom): a short sheet ends after its last item, and
- when the content is taller the scrolling part (`sidebar-content`, `panel-body`) scrolls inside the sheet while the head and the
- footer (`panel-footer`: Reset, Copy link) stay in place.
- - A sheet folds into its `shell-trigger` button: the sheet is hidden (`data-sidebar|left|panel="closed"`) and only the button stays
- in its corner. A page remembers the choice, folds a sheet on Esc inside it, and moves focus to the button (and back).
- - Layout CSS reads only contract names that a lens page never redefines: the surfaces and text (`--background`, `--foreground`,
- `--muted-foreground`, `--border`, `--ring`, `--primary`, `--primary-foreground`, `--popover`), the `--sidebar-*` names,
- `--font-sans`, `--font-mono`, `--radius`, `--shadow-*`, `--sb-ease`, `--sb-dur`, and `--secondary` for the track of a
- segmented choice. A component may give a `var()` fallback; `shtukbase-ui-html` gives none (SUI-R02), and on a lens page the
- kit supplies neutral values for these names when the project has no style.
- ## 4. The right-panel API (lens kit)
- The lens kit draws its frame with these slots (`Lens.page(cfg)`), and a lens fills it through `Lens.ui`:
- | call | does |
- |---|---|
- | `Lens.page({title, icon, description, layout, about, search})` | builds the frame; `layout` is `document`, `grid`, `catalog` or `canvas` (a template sets its own; `canvas` adds pan, zoom and fit through `Lens.zoom`) |
- | `ui.main` | the page: the root of the layout, where a lens appends its content |
- | `ui.section(title, ...nodes)` | adds a `panel-section` to the right panel and returns its content element; `body.setAnswer(text)` writes the `panel-section-meta`; a section folded by the reader stays folded (stored by title) |
- | `ui.settings({sections, presets, storageKey, target, onChange})` | lands settings in the right panel: one `panel-section` per settings section, rows of `panel-section-row`, a **Preset** select first when presets are given, **Reset** and **Copy link** in `panel-footer`; the call and the control kinds are those of `Explore.panel` (explore kit), values land on `target` as `data-<name>` and `--x-<name>`, in `localStorage` and in the link; returns the same handle as `Explore.panel` |
- | `ui.left(title, ...nodes)` | opens the optional left panel and adds a section there (a title, a search, breadcrumbs, a tree) |
- | `ui.sidebar` | the sidebar: by default the lenses of the project grouped by layer, the current one selected, and the search |
- | `ui.top` | kept for older lenses: the first, bare block of the right panel; what was put into the header lands there |
- | `ui.showBar()` / `ui.bar.append(...)` | the section **Overview** of the right panel, as before |
- The order of the right panel: the description of the lens (bare, no title), the lens's own sections in the order it adds them,
- the settings sections, **Appearance** (theme and style, folded), **About the lens** (folded), then the footer. The panel header
- holds the lens title once and the close button; the title is not repeated in the body.
- A page that is not a lens (the explore kit demo, a design page) uses the same markup directly, or `Explore.panel({container})`
- inside its own `panel-body`.
- ## 5. Where the kit finds the design
- At build the kit reads [Design](/design/design.md) for the style, libraries and layout. Library components draw
- the sidebar, panels, controls and page forms. The selected layout places these parts. Follow the
- [Lens layout convention](layout.md) to switch layouts or implement one.