ShtukbaseStandard
página del paquete→ /design/conventions/layout.md

pages/design/conventions/layout.md

72 líneas, 5.3 KB. Como página.

Este texto aún no está traducido. Debajo está el original en inglés.

  1. ---
  2. type: Convention
  3. title: "Lens layout"
  4. description: "The regions, slots, behavior and browser API of a replaceable layout package."
  5. icon: "🪟"
  6. ---
  7. # Lens layout
  8. A layout package follows `design/conventions/layout`. Choose its id in `layout:` on [Design](/design/design.md).
  9. ## 1. What it covers
  10. A layout places the left sidebar, right settings panel, page, canvas and optional left panel. It also provides a host for
  11. cards opened from a lens. The same lens content can run in different layouts.
  12. ## 2. Gives
  13. The package publishes `/design/<id>/layout.css` and `/design/<id>/layout.js`. The script assigns a layout object to
  14. `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
  15. its assets are missing.
  16. | Region | Required slots and state |
  17. |---|---|
  18. | Frame | `shell` with `data-sidebar`, `data-left` and `data-panel` set to `open` or `closed`. |
  19. | 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`. |
  20. | 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`. |
  21. | 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`. |
  22. | Page and canvas | `shell-main` hosts the page, including existing `layout-document`, `layout-grid`, `layout-catalog` and `layout-canvas` slots and their parts. |
  23. | 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. |
  24. | 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. |
  25. Keep the legacy classes alongside the `data-slot` names. The remaining component parts and the lens author API are listed
  26. in [The lens shell](lens-shell.md).
  27. A layout makes each sheet foldable, restores the saved state and honors `?sidebar=closed&panel=closed` (also `left=`).
  28. Esc inside a sheet folds it and focus follows the fold or reveal. The sidebar search has an expanded state and focuses the
  29. field on reveal. Esc inside it closes search first. Settings remain in the right panel, with their sections and footer.
  30. | JavaScript API | Contract |
  31. |---|---|
  32. | `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. |
  33. | `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. |
  34. | `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`. |
  35. | `frame.panel()` | Return the supplied right panel. |
  36. | `frame.open(region, on, focus?)` | Set the state of `sidebar`, `left` or `panel`; move focus when requested. |
  37. | `frame.mountLeft(panel)` | Add the optional left panel and its reveal button. Restore its saved state. |
  38. | `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()`. |
  39. ## 3. Expects
  40. Use the design tokens and the chosen library's generic `sidebar`, `panel`, `panel-section`, `collapsible`, `sheet`
  41. and `scroll-area` parts. The kit supplies sidebar links, search input, panel content and the page. The lens continues
  42. to own its content, settings and canvas controls.
  43. ## 4. Free to choose
  44. Choose the placement, sizing, insets and responsive arrangement. Sheets can float or dock. Keep the slots, state, focus,
  45. search, settings and canvas behavior in either arrangement.
  46. ## 5. Make an alternative
  47. 1. Create a package with `follows: [design/conventions/layout]` and publish its CSS and JS at the paths above.
  48. 2. Implement the frame API with the same slots. Read the contract tokens and use the library parts.
  49. 3. Install it and set `layout:` on Design to its id. A layout package may adopt itself on install when the field is empty.
  50. 4. Run `shtuk run design-components sync` and `shtuk run lenses build`. Check the same lenses before and after the switch.
  51. ## 6. Health
  52. Test the slots and public API on both the default layout and an alternate layout. Check the page, canvas, panel sections,
  53. sidebar search, folded buttons, remembered state, URL overrides and Esc. Verify the catalog, style, icons and package map
  54. in light and dark, with long labels and a viewport short enough to require scrolling.