AI-native design editor. Open-source Figma alternative.
feat(storybook): follow the active tab and lay out content parts (#1011)
Danila Poyarkove8adf384de7a
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 7cd8dcf23..4a5c3705d 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -48,7 +48,7 @@- Print the installed version of OpenPencil's MCP server and Harness companion with `openpencil-mcp-http --version`, `openpencil-mcp --version`, and `openpencil-harness --version`. The desktop app asks it to check that they match the app on every platform, including npm `.cmd` shims on Windows and version managers such as Volta and mise.- Add a Controls page to the `/demo` document: a switch, checkbox, slider, tabs, text field, and a button with hover, pressed, focus, and disabled states, written as Reka-named design JSX, and a settings card made of their instances to try in preview.- Make main components behave like real controls and try them in preview. The Behaviour section turns a component or component set into a Button, Text field, Textarea, Number field, Toggle, Switch, Checkbox, Radio, Radio group, Toggle group, Slider, Progress, Tabs, Collapsible, or Accordion, after Reka UI's primitives: its values bind to the component's variant, boolean, and text properties, a slider or number field keeps its own number range, its parts are its slots (a group's items slot holds its radios, toggles, or collapsibles), and a variant property can draw its default, hover, pressed, focus, and disabled states. Rows are named for the control, and an empty row creates what it needs: a text layer and text property, Off and On variants, a slot in every variant, or a variant for each interaction state, turning a lone component into a component set when it needs variants. View > Preview (⌥⌘↩) runs each top-level layer holding controls as live Reka UI components over the canvas, drawn by the component's variants: real inputs with the browser's caret, selection, and paste, keyboard focus and navigation, and layout that grows as collapsibles open, all without changing the document, its history, or what collaborators see; Esc or the pill returns to editing.-- Build controls from scripts, tools, and design JSX. Scripts run by `eval`, `openpencil eval`, and app automation get an `openpencil` global next to `figma`, in the Figma API's style: `openpencil.setBehaviour(set, { kind: 'switch', values: { value: 'State' }, parts: { thumb: 'Thumb' }, states: 'Interaction' })` or `.bindValue()` and `.bindPart()` by property and slot names, `getBehaviour`, `behaviourKinds`, and `createSlot`. MCP and AI chat get `set_behaviour`, `get_behaviour`, and `create_slot`. Design JSX writes controls with Reka UI's element names, such as `<Switch.Root modelValue="State">` with `<Switch.Thumb>`, `<TextField.Input>`, and `<Tabs.List>`, in JSX strings or in TSX through the typed `Switch`, `Slider`, `Tabs`, and other namespaces `@open-pencil/design-jsx` exports, and exports components with behaviours the same way.+- Build controls from scripts, tools, and design JSX. Scripts run by `eval`, `openpencil eval`, and app automation get an `openpencil` global next to `figma`, in the Figma API's style: `openpencil.setBehaviour(set, { kind: 'switch', values: { value: 'State' }, parts: { thumb: 'Thumb' }, states: 'Interaction' })` or `.bindValue()` and `.bindPart()` by property and slot names, `getBehaviour`, `behaviourKinds`, and `createSlot`. MCP and AI chat get `set_behaviour`, `get_behaviour`, and `create_slot`. Design JSX writes controls with Reka UI's element names, such as `<Switch.Root modelValue="State">` with `<Switch.Thumb>`, `<TextField.Input>`, and `<Tabs.List>`, in JSX strings or in TSX through the typed `Switch`, `Slider`, `Tabs`, and other namespaces `@open-pencil/design-jsx` exports, and exports components with behaviours the same way. A part holding layers with no layout of its own, such as a `Tabs.Content` panel, stacks them in a column that hugs them.- Open a `.fig`, `.pen`, or other supported document by dragging it onto the window, where it opens in a new tab as File → Open does. Images and SVG files dropped on the canvas are still placed, and other files report that they can't be opened instead of being ignored.- Pass an ID generator to `new SceneGraph()` from `@open-pencil/scene-graph` to choose the IDs of the nodes, variables, collections, and modes the graph creates, including modes added later with `createMode`; generated IDs skip any node, variable, collection, or mode ID already in the graph, and an exhausted generator throws instead of hanging. `createComponentPropertyId` gives new component properties the `prop:` IDs the editor, plugin API, and design JSX share.- Diagnose failures from Settings → Diagnostics. Uncaught errors, unhandled rejections, component errors, failed AI chats, and AI tool calls that broke inside OpenPencil are recorded with their message and stack, and other failed tool calls as warnings. Messages and stacks are scrubbed of URL queries and credentials, API keys and tokens, email addresses, and home folder names, and provider errors keep no message. Each event has a specific label, such as *Tool: render · 162 ms* or *Error: TypeError*, expands to its details, and can be filtered by level and category and paged; copied diagnostics include the app version and browser.@@ -76,7 +76,7 @@- Swap the component behind an instance with `instance.swapComponent(component)` in the plugin API, as in Figma.- Detach an instance from its component with `detachInstance()` in the plugin API, as in Figma, from scripts run through `eval`.- Run scripts written for Figma's dynamic-page mode that call `figma.getNodeByIdAsync()` or `getMainComponentAsync()`; both resolve to the same nodes as their synchronous forms.-- Export components to Storybook with `openpencil export -f storybook`: one CSF3 story file per component set or component for React, Vue, or HTML, with a story and `select` controls per variant (a component with a behaviour gets boolean `checked`, `pressed`, `open`, and `disabled` controls instead, and each interaction state stays a story; with `--framework vue` or `--framework react`, a Button, Switch, Checkbox, Toggle, Collapsible, Tabs, Radio group, Toggle group, or Accordion becomes a Reka UI or Radix UI component whose variants are compiled into state styles and whose text properties are string props with a text control, tabs and groups choosing a value named after each tab's or item's label, and groups writing an item component they use once per item; inside it, an instance of another generated component uses that component, operable from the value the design draws, and an icon is an `@iconify/vue` or `@iconify/react` component; with stories whose play function operates it), a design image per variant, and an `openpencil://` link that opens the variant in OpenPencil. `--watch` re-exports on every save and removes stories of deleted components, and `--beside` writes each document's stories next to it, for many documents at once (#727).+- Export components to Storybook with `openpencil export -f storybook`: one CSF3 story file per component set or component for React, Vue, or HTML, with a story and `select` controls per variant (a component with a behaviour gets boolean `checked`, `pressed`, `open`, and `disabled` controls instead, and each interaction state stays a story; with `--framework vue` or `--framework react`, a Button, Switch, Checkbox, Toggle, Collapsible, Tabs, Radio group, Toggle group, or Accordion becomes a Reka UI or Radix UI component whose variants are compiled into state styles and whose text properties are string props with a text control, tabs and groups choosing a value named after each tab's or item's label, each tab's trigger drawn with the chosen tab's look while it is active, and groups writing an item component they use once per item; inside it, an instance of another generated component uses that component, operable from the value the design draws, and an icon is an `@iconify/vue` or `@iconify/react` component; with stories whose play function operates it), a design image per variant, and an `openpencil://` link that opens the variant in OpenPencil. `--watch` re-exports on every save and removes stories of deleted components, and `--beside` writes each document's stories next to it, for many documents at once (#727).- Export HTML and Tailwind JSX from the app's export options and through the IO registry, and export Tailwind JSX from the CLI with `-f tailwind-jsx` (`-f jsx --style tailwind` still works). HTML export of a single layer now includes the layer itself, as other formats do. Vector shapes, booleans, stars, and polygons export as inline SVG with their fills, gradients, strokes, and shadows, in HTML, Tailwind JSX, and Storybook stories.- Choose PPTX in the Export panel's format list, alongside PNG, JPG, WEBP, SVG, and PDF.- Let AI and MCP agents verify and replay their edits with diff tools: `diff_visual` returns a pixel diff of two rendered nodes with the changed region, and `diff_apply` applies a `diff_create` or `diff_show` patch, including moved, added, and removed children, only when every node still matches it. The built-in AI chat enables `diff_create`, `diff_jsx`, and `diff_visual` by default.@@ -134,6 +134,7 @@### Fixed+- Choose an instance's variant by its variant property in design JSX, such as `<Instance component="Button" State="Pressed" />`, without a warning that the property is unsupported.- Keep memory flat while the AI chat or an MCP client edits a document (#587). Each edit kept two copies of its whole page in the undo history, about 10 MB a call on a 400-layer page, until the 200-step history limit, so long sessions grew until the app ran out of memory; an edit now keeps only the layers it changed, and undoing it leaves the other layers as they are.- Keep the new-tab button and the active tab in view when many documents are open. Tabs shrink before the tab bar scrolls, the clipped side fades with a chevron that scrolls to hidden tabs, and the new-tab button is a compact button beside the last tab instead of scrolling away with the tabs.- Show when the browser menubar has more menus than fit in the left panel. The clipped side fades out and a chevron scrolls to the hidden menus; before, Arrange and Text could be cut off with no sign the bar scrolls.diff --git a/packages/core/tests/design-jsx/behaviours.test.ts b/packages/core/tests/design-jsx/behaviours.test.tsindex b0accf094..d3b7efd48 100644--- a/packages/core/tests/design-jsx/behaviours.test.ts+++ b/packages/core/tests/design-jsx/behaviours.test.ts@@ -105,6 +105,65 @@ describe('Reka UI elements in design JSX', () => {const behaviour = readBehaviour(root)expect(behaviour && missingBindings(graph, root, behaviour)).toEqual([])})++ test('a part with content and no layout of its own hugs it in a column', async () => {+ const { graph, root } = await render(`+ <Collapsible.Root name="Question" w={360} flex="col">+ <Collapsible.Trigger flex="row" gap={8}><Text>Can I cancel?</Text></Collapsible.Trigger>+ <Collapsible.Content><Text>Yes, any time from your account.</Text></Collapsible.Content>+ </Collapsible.Root>+ `)+ const [, content] = graph.getChildren(root.id)+ const [text] = graph.getChildren(content?.id ?? '')+ expect(content?.layoutMode).toBe('VERTICAL')+ expect(content?.width).toBe(text?.width)+ expect(content?.height).toBe(text?.height)++ // One sized under any name keeps its own size and no layout.+ const { graph: sizedGraph, root: sized } = await render(`+ <Collapsible.Root name="Question" w={360} flex="col">+ <Collapsible.Trigger flex="row"><Text>Can I cancel?</Text></Collapsible.Trigger>+ <Collapsible.Content width={200} height={40}><Text>Yes.</Text></Collapsible.Content>+ </Collapsible.Root>+ `)+ const [, sizedContent] = sizedGraph.getChildren(sized.id)+ expect([sizedContent?.layoutMode, sizedContent?.width, sizedContent?.height]).toEqual([+ 'NONE',+ 200,+ 40+ ])++ // A part drawn as a shape keeps the size it is given.+ const { graph: switchGraph, root: switchRoot } = await render(`+ <Switch.Root name="Switch" w={44} h={24}><Switch.Thumb w={20} h={20} /></Switch.Root>+ `)+ const [thumb] = switchGraph.getChildren(switchRoot.id)+ expect([thumb?.layoutMode, thumb?.width, thumb?.height]).toEqual(['NONE', 20, 20])+ })++ test('an item chooses its variant by the set’s variant property, which is no unknown prop', async () => {+ const graph = new SceneGraph()+ const [radio] = await renderJSX(+ graph,+ `<RadioGroup.Item name="Radio" modelValue="Checked">+ <Component name="Checked=Off" w={20} h={20} />+ <Component name="Checked=On" w={20} h={20} />+ </RadioGroup.Item>`+ )+ const [group] = await renderJSX(+ graph,+ `<RadioGroup.Root name="Plan">+ <RadioGroup.Item of="${radio.id}" />+ <RadioGroup.Item of="${radio.id}" Checked="On" Tone="Loud" />+ </RadioGroup.Root>`+ )+ const [items] = graph.getChildren(group.id)+ const chosen = graph+ .getChildren(items?.id ?? '')+ .map((item) => graph.getNode(item.componentId ?? '')?.name)+ expect(chosen).toEqual(['Checked=Off', 'Checked=On'])+ expect(group.warnings).toEqual(['Unsupported prop "Tone" on <RadioGroup.Item> is ignored.'])+ })})describe('Reka UI elements in JSX export', () => {diff --git a/packages/design-jsx/src/behaviours/render.ts b/packages/design-jsx/src/behaviours/render.tsindex de914611a..45c31c86d 100644--- a/packages/design-jsx/src/behaviours/render.ts+++ b/packages/design-jsx/src/behaviours/render.ts@@ -1,5 +1,6 @@import type { NodeType, SceneGraph, SceneNode } from '@open-pencil/scene-graph'+import { designJSXProp } from '../schema'import type { TreeNode } from '../tree'import {BEHAVIOUR_PROPS,@@ -47,6 +48,20 @@ function named(tree: TreeNode, fallback: string): TreeNode {: tree}+/** The props that give a frame a layout or size of its own, under any of their names. */+const LAYOUT_PROPS = ['flex', 'display', 'w', 'h']++/**+ * A part that holds content, such as a panel or a trigger, with no layout of its own stacks+ * its children in a column that hugs them, rather than pinning them in a fixed box.+ */+function laidOut(tree: TreeNode): TreeNode {+ const content = tree.children.some((child) => typeof child !== 'string')+ if (!content || LAYOUT_PROPS.some((prop) => designJSXProp(tree.props, prop) !== undefined))+ return tree+ return { ...tree, props: { ...tree.props, flex: 'col' } }+}+/*** Render a Reka UI element: a root as a main component (or a component set, when it has* variants) that behaves as its control, a part as the slot that draws it, and an input as the@@ -89,13 +104,13 @@ export async function renderRekaNode(}case 'part': {if (!scope) throw new Error(`<${tree.type}> must be inside its Root`)- const frame = hooks.create('FRAME', named(tree, partName), parentId)+ const frame = hooks.create('FRAME', laidOut(named(tree, partName)), parentId)await renderChildren(hooks.render, tree.children, frame.id, scope)bindPart(graph, scope, frame, role.part)return frame}case 'repeat': {- const frame = hooks.create('FRAME', named(tree, partName), parentId)+ const frame = hooks.create('FRAME', laidOut(named(tree, partName)), parentId)await renderChildren(hooks.render, tree.children, frame.id, scope)// Only the first tab's panel shows as designed; preview shows the others as chosen.const siblings = graph.getChildren(parentId)@@ -120,7 +135,7 @@ export async function renderRekaNode(return text}case 'frame': {- const frame = hooks.create('FRAME', named(tree, partName), parentId)+ const frame = hooks.create('FRAME', laidOut(named(tree, partName)), parentId)await renderChildren(hooks.render, tree.children, frame.id, scope)return frame}diff --git a/packages/design-jsx/src/reference/authoring.md b/packages/design-jsx/src/reference/authoring.mdindex 1472b9da1..a26d8ea17 100644--- a/packages/design-jsx/src/reference/authoring.md+++ b/packages/design-jsx/src/reference/authoring.md@@ -43,7 +43,7 @@ This reference describes scene creation, not React DOM output. Use the `render`- A main component can behave as a Reka UI control in preview and code. Write it with Reka's names: `Switch.Root` is the component (a component set when its children are `Component` variants), and each Reka part is the slot that draws it, such as `Switch.Thumb`, `Slider.Track`, `Slider.Range`, `Slider.Thumb`, `Tabs.List`, `Collapsible.Trigger`, or `NumberField.Increment`. Parts in different variants share one slot.- The root names the properties that hold its values: `modelValue` (`open` on `Collapsible.Root`), `disabled`, and, for text fields, `filled`, as a variant or boolean property name, or `{ property, on, off }` when the variant values are not named like On and Off. `states` names the variant property that draws default, hover, pressed, focus, and disabled; a slider, progress bar, or number field takes `min`, `max`, `step`, and `defaultValue`.-- `TextField.Input`, `Textarea.Input`, and `NumberField.Input` are the text layers whose text becomes the field's text property. `Tabs.Trigger` goes in `Tabs.List`; `Tabs.Content` panels may sit directly under `Tabs.Root`, the first showing.+- `TextField.Input`, `Textarea.Input`, and `NumberField.Input` are the text layers whose text becomes the field's text property. `Tabs.Trigger` goes in `Tabs.List`; `Tabs.Content` panels may sit directly under `Tabs.Root`, the first showing. A part with children and no `flex`, `display`, `w`, or `h` of its own stacks them in a column that hugs them.- A group's item component is written on its own (`RadioGroup.Item`, `ToggleGroup.Item`, `Accordion.Item` with its `Accordion.Trigger` and `Accordion.Content`); the group's root then lists items as `<RadioGroup.Item of={radioId} />`.```tsxdiff --git a/packages/design-jsx/src/render.ts b/packages/design-jsx/src/render.tsindex a81014ca0..2c00415a4 100644--- a/packages/design-jsx/src/render.ts+++ b/packages/design-jsx/src/render.ts@@ -6,7 +6,7 @@ import type { SceneGraph } from '@open-pencil/scene-graph'import { REKA_ELEMENTS } from './behaviours'import { designJSXHelpers } from './helpers'import * as React from './mini-react'-import { renderRoots, renderTree, type RenderResult } from './renderer'+import { renderRoots, renderTree, variantPropNames, type RenderResult } from './renderer'import { DESIGN_JSX_SUPPORTED_PROPERTIES } from './schema'import type { DesignJSXServices } from './services'import { isTreeNode, resolveToTree, type TreeNode } from './tree'@@ -32,18 +32,24 @@ function stripHTMLComments(jsxString: string): string {return jsxString.replace(/<!--[\s\S]*?-->/g, '')}-function unsupportedPropWarnings(tree: TreeNode): string[] {+function unsupportedPropWarnings(graph: SceneGraph, tree: TreeNode): string[] {const warnings: string[] = []- collectUnsupportedPropWarnings(tree, warnings)+ collectUnsupportedPropWarnings(graph, tree, warnings)return warnings}const SVG_ROOT_PROPS = new Set([...SUPPORTED_PROPS, 'viewBox', 'body'])-function collectUnsupportedPropWarnings(tree: TreeNode, warnings: string[]): void {+function collectUnsupportedPropWarnings(+ graph: SceneGraph,+ tree: TreeNode,+ warnings: string[]+): void {const supportedProps = tree.type === 'svg' ? SVG_ROOT_PROPS : SUPPORTED_PROPS+ // An instance chooses its variant by the set's variant properties, such as `State="On"`.+ const variants = variantPropNames(graph, tree.props)for (const key of Object.keys(tree.props)) {- if (!supportedProps.has(key)) {+ if (!supportedProps.has(key) && !variants.includes(key)) {warnings.push(`Unsupported prop "${key}" on <${tree.type}> is ignored.`)}}@@ -52,7 +58,7 @@ function collectUnsupportedPropWarnings(tree: TreeNode, warnings: string[]): voiif (tree.type === 'svg') returnfor (const child of tree.children) {- if (isTreeNode(child)) collectUnsupportedPropWarnings(child, warnings)+ if (isTreeNode(child)) collectUnsupportedPropWarnings(graph, child, warnings)}}@@ -128,10 +134,10 @@ async function renderJSX<Artwork>(throw new Error('JSX must return a Figma element (Frame, Text, etc)')}- // A helper called in a loop reports each ignored option once.- const warnings = uniq([...unsupportedPropWarnings(tree), ...helperWarnings])-const results = await renderRoots(services, graph, tree, options)+ // After rendering, so an instance's component set drawn in the same JSX names its variants.+ // A helper called in a loop reports each ignored option once.+ const warnings = uniq([...unsupportedPropWarnings(graph, tree), ...helperWarnings])if (warnings.length > 0) results[0].warnings = warningsreturn results}diff --git a/packages/design-jsx/src/renderer.ts b/packages/design-jsx/src/renderer.tsindex e462bdf1b..b167c5801 100644--- a/packages/design-jsx/src/renderer.ts+++ b/packages/design-jsx/src/renderer.ts@@ -378,27 +378,40 @@ function findVariantInSet()}-function resolveComponent(- graph: SceneGraph,- props: Record<string, unknown>-): SceneNode | undefined {+/** The component or component set an element names by id or name. */+function namedComponent(graph: SceneGraph, props: Record<string, unknown>): SceneNode | undefined {const ref = props.component ?? props.componentId ?? props.ofif (typeof ref !== 'string') return undefinedconst byId = graph.getNode(ref)- if (byId?.type === 'COMPONENT') return byId- if (byId?.type === 'COMPONENT_SET') return findVariantInSet(graph, byId, props)+ if (byId?.type === 'COMPONENT' || byId?.type === 'COMPONENT_SET') return byIdconst byName = findComponentByName(graph, ref)if (byName) return byNamefor (const node of graph.getAllNodes()) {- if (node.type === 'COMPONENT_SET' && node.name === ref)- return findVariantInSet(graph, node, props)+ if (node.type === 'COMPONENT_SET' && node.name === ref) return node}return undefined}+function resolveComponent(+ graph: SceneGraph,+ props: Record<string, unknown>+): SceneNode | undefined {+ const named = namedComponent(graph, props)+ return named?.type === 'COMPONENT_SET' ? findVariantInSet(graph, named, props) : named+}++/** The variant properties an element chooses its component's variant by, such as `State`. */+export function variantPropNames(graph: SceneGraph, props: Record<string, unknown>): string[] {+ const named = namedComponent(graph, props)+ if (named?.type !== 'COMPONENT_SET') return []+ return named.componentPropertyDefinitions+ .filter((definition) => definition.type === 'VARIANT')+ .map((definition) => definition.name)+}+async function renderInstanceNode(graph: SceneGraph,tree: TreeNode,diff --git a/packages/docs/programmable/cli/exporting.md b/packages/docs/programmable/cli/exporting.mdindex c19b4dbb6..d74f11c9e 100644--- a/packages/docs/programmable/cli/exporting.md+++ b/packages/docs/programmable/cli/exporting.md@@ -164,7 +164,7 @@ Stories render the component as HTML with inline styles, like `-f html`, so theyWith `--framework vue` or `--framework react`, a component set or component whose behaviour is a Button, Switch, Checkbox, Toggle, Collapsible, Tabs, Radio group, Toggle group, or Accordion becomes a real component instead: `<Name>.vue` built on Reka UI, or `<Name>.tsx` with a `<Name>.module.css` built on Radix UI's `radix-ui` package. Its variants are compiled into a stylesheet keyed on the states Reka and Radix set (`data-state`, `data-disabled`, hover, and focus), and every other variant property is a prop the component sets as a `data-*` attribute. In Vue its value is a `v-model` such as `checked` or `open`; in React the component takes the Radix root's props, such as `checked`, `defaultChecked`, and `onCheckedChange`. Its text properties are string props, defaulting to the design's words, which the layers bound to them draw, with a text control in its stories.-Tabs take the open tab as `value` (`v-model:value`, or `defaultValue` and `onValueChange` in React), named by each trigger's words as a slug, such as `account` or `password`, and starting on the first; each trigger and its panel are Reka's or Radix's `Tabs` parts around the design's layers, and the stories get a `select` control and a story per tab. A Radio group, Toggle group, or Accordion writes two components: the group, which chooses one item the same way, starting on the item the design draws on, and `<Group>Item` from its items' component set, built as the group's item primitive (`RadioGroupItem`, `ToggleGroupItem`, or `AccordionItem` with its trigger in a header) and taking the `value` it stands for. The group uses it once per item in its items slot, with each item's value, named by its label property or else its words, and its text values. A Radio is only generated as a group's item; a Toggle or Collapsible used on its own still becomes its own component.+Tabs take the open tab as `value` (`v-model:value`, or `defaultValue` and `onValueChange` in React), named by each trigger's words as a slug, such as `account` or `password`, and starting on the first; each trigger and its panel are Reka's or Radix's `Tabs` parts around the design's layers, every trigger drawn like the design's other triggers and taking the first trigger's look while its tab is active, and the stories get a `select` control and a story per tab. A Radio group, Toggle group, or Accordion writes two components: the group, which chooses one item the same way, starting on the item the design draws on, and `<Group>Item` from its items' component set, built as the group's item primitive (`RadioGroupItem`, `ToggleGroupItem`, or `AccordionItem` with its trigger in a header) and taking the `value` it stands for. The group uses it once per item in its items slot, with each item's value, named by its label property or else its words, and its text values. A Radio is only generated as a group's item; a Toggle or Collapsible used on its own still becomes its own component.Inside a generated component, an instance of another component generated in the same export uses that component rather than drawing its layers: `<Switch>` imported from `./Switch.vue` or `./Switch`, set to the variant, text, and `disabled` values the instance shows. A control the design draws on, such as a checked switch, starts on and stays operable: a local `ref` bound with `v-model` in Vue, `defaultChecked` in React. The parent only places it, so the control keeps its own look and state styles. Instances of components not exported, or exported only as static stories, are drawn as before. An icon placed from a set, unless its paths were edited, is Iconify's component, `<Icon icon="lucide:bell">` from `@iconify/vue` or `@iconify/react`, which loads the icon when shown.diff --git a/packages/docs/reference/design-authoring.md b/packages/docs/reference/design-authoring.mdindex 06f681a05..7d2737972 100644--- a/packages/docs/reference/design-authoring.md+++ b/packages/docs/reference/design-authoring.md@@ -45,7 +45,7 @@ This reference describes scene creation, not React DOM output. Use the `render`- A main component can behave as a Reka UI control in preview and code. Write it with Reka's names: `Switch.Root` is the component (a component set when its children are `Component` variants), and each Reka part is the slot that draws it, such as `Switch.Thumb`, `Slider.Track`, `Slider.Range`, `Slider.Thumb`, `Tabs.List`, `Collapsible.Trigger`, or `NumberField.Increment`. Parts in different variants share one slot.- The root names the properties that hold its values: `modelValue` (`open` on `Collapsible.Root`), `disabled`, and, for text fields, `filled`, as a variant or boolean property name, or `{ property, on, off }` when the variant values are not named like On and Off. `states` names the variant property that draws default, hover, pressed, focus, and disabled; a slider, progress bar, or number field takes `min`, `max`, `step`, and `defaultValue`.-- `TextField.Input`, `Textarea.Input`, and `NumberField.Input` are the text layers whose text becomes the field's text property. `Tabs.Trigger` goes in `Tabs.List`; `Tabs.Content` panels may sit directly under `Tabs.Root`, the first showing.+- `TextField.Input`, `Textarea.Input`, and `NumberField.Input` are the text layers whose text becomes the field's text property. `Tabs.Trigger` goes in `Tabs.List`; `Tabs.Content` panels may sit directly under `Tabs.Root`, the first showing. A part with children and no `flex`, `display`, `w`, or `h` of its own stacks them in a column that hugs them.- A group's item component is written on its own (`RadioGroup.Item`, `ToggleGroup.Item`, `Accordion.Item` with its `Accordion.Trigger` and `Accordion.Content`); the group's root then lists items as `<RadioGroup.Item of={radioId} />`.```tsxdiff --git a/packages/dom-css/src/behaviours/states/css.ts b/packages/dom-css/src/behaviours/states/css.tsindex 58ad69614..c20ea92db 100644--- a/packages/dom-css/src/behaviours/states/css.ts+++ b/packages/dom-css/src/behaviours/states/css.ts@@ -58,9 +58,11 @@ export async function stateStylesToCSS(styles: StateStyles): Promise<StateStylesrules.push({ order: 0, selector: `.${rootClass}${own}`, style: element.base })for (const rule of element.rules) {const when = rule.conditions.map(conditionSelector).join('')+ const on = rule.on && classes.get(rule.on)+ const tested = on ? ` .${on}${when}${rule.on === element ? '' : own}` : `${when}${own}`rules.push({order: rule.conditions.length,- selector: `.${rootClass}${when}${own}`,+ selector: `.${rootClass}${tested}`,style: rule.style})}diff --git a/packages/dom-css/src/behaviours/states/model.ts b/packages/dom-css/src/behaviours/states/model.tsindex 7a399bfa1..8d03de019 100644--- a/packages/dom-css/src/behaviours/states/model.ts+++ b/packages/dom-css/src/behaviours/states/model.ts@@ -16,7 +16,7 @@ import {import type { StateCondition, StateElement, StateRule, StateStyles } from './types'/** Declarations `drawn` sets differently from `base`, with `unset` for ones it drops. */-function difference(+export function difference(base: DesignStyleDeclaration,drawn: DesignStyleDeclaration): DesignStyleDeclaration {diff --git a/packages/dom-css/src/behaviours/states/tailwind.ts b/packages/dom-css/src/behaviours/states/tailwind.tsindex 81302f919..043e7a475 100644--- a/packages/dom-css/src/behaviours/states/tailwind.ts+++ b/packages/dom-css/src/behaviours/states/tailwind.ts@@ -3,7 +3,7 @@ import type { DesignDocument, DesignNode, DesignStyleDeclaration } from '#dom-csimport { twirl } from 'twirlwind'import { cssName, propAttribute } from './names'-import type { StateCondition, StateNode, StateStyles } from './types'+import type { StateCondition, StateElement, StateNode, StateStyles } from './types'export interface StateTailwindOptions {/** Custom properties declared in `@theme`; a `var()` naming one becomes its utility. */@@ -41,21 +41,41 @@ function utilities(style: DesignStyleDeclaration, options: StateTailwindOptions): []}+/** What each element's utilities are written against. */+interface Groups {+ /** The control's root group. */+ root: string+ /** A named group for each layer other than the root whose state a rule tests. */+ anchors: Map<StateElement, string>+}++/** The group a rule's conditions test from `node`, or null when they test `node` itself. */+function testedGroup(+ node: StateElement,+ on: StateElement | undefined,+ groups: Groups,+ isRoot: boolean+): string | null {+ if (on) return on === node ? null : (groups.anchors.get(on) ?? null)+ return isRoot ? null : groups.root+}+function designNode(node: StateNode,- group: string,+ groups: Groups,isRoot: boolean,options: StateTailwindOptions): DesignNode {if (node.type === 'text') return node+ const anchor = groups.anchors.get(node)const classes = [...(node.attrs.class ? splitWhitespace(node.attrs.class) : []),- ...(isRoot ? [`group/${group}`] : []),+ ...(isRoot ? [`group/${groups.root}`] : []),+ ...(anchor ? [`group/${anchor}`] : []),...utilities(node.base, options),...node.rules.flatMap((rule) => {- const prefix = rule.conditions- .map((condition) => variant(condition, isRoot ? null : group))- .join('')+ const group = testedGroup(node, rule.on, groups, isRoot)+ const prefix = rule.conditions.map((condition) => variant(condition, group)).join('')return utilities(rule.style, options).map((utility) => `${prefix}${utility}`)})]@@ -63,8 +83,21 @@ function designNode(type: 'element',tagName: node.tagName,attrs: { ...node.attrs, class: classes.join(' ') },- children: node.children.map((child) => designNode(child, group, false, options))+ children: node.children.map((child) => designNode(child, groups, false, options))+ }+}++/** The layers rules test other than the root, each named after the root's group. */+function anchorGroups(root: StateElement, group: string): Map<StateElement, string> {+ const anchors = new Map<StateElement, string>()+ const visit = (node: StateNode) => {+ if (node.type === 'text') return+ for (const rule of node.rules)+ if (rule.on && !anchors.has(rule.on)) anchors.set(rule.on, `${group}-${anchors.size + 1}`)+ for (const child of node.children) visit(child)}+ visit(root)+ return anchors}/**@@ -76,6 +109,7 @@ export function stateStylesToTailwind(styles: StateStyles,options: StateTailwindOptions = {}): DesignDocument {- const group = cssName(styles.name, 'component')- return { type: 'document', children: [designNode(styles.root, group, true, options)] }+ const root = cssName(styles.name, 'component')+ const groups = { root, anchors: anchorGroups(styles.root, root) }+ return { type: 'document', children: [designNode(styles.root, groups, true, options)] }}diff --git a/packages/dom-css/src/behaviours/states/types.ts b/packages/dom-css/src/behaviours/states/types.tsindex 8ceec4c02..6b7b9c146 100644--- a/packages/dom-css/src/behaviours/states/types.ts+++ b/packages/dom-css/src/behaviours/states/types.ts@@ -14,6 +14,11 @@ export type StateCondition =/** What a variant changes on a layer, and the conditions that show that variant. */export interface StateRule {conditions: StateCondition[]+ /**+ * The layer the conditions test when it is not the control's root, such as a tab trigger+ * that Reka and Radix mark active itself: the layer the rule styles, or one around it.+ */+ on?: StateElementstyle: DesignStyleDeclaration}diff --git a/packages/dom-css/src/export/components/model.ts b/packages/dom-css/src/export/components/model.tsindex b64011f00..b591301d5 100644--- a/packages/dom-css/src/export/components/model.ts+++ b/packages/dom-css/src/export/components/model.ts@@ -35,7 +35,7 @@ import {type IconReference,type UsedLayer} from './references'-import { tabParts, type ChoiceModel, type RepeatedPart } from './repeats'+import { activeTriggers, tabParts, type ChoiceModel, type RepeatedPart } from './repeats'/** Kinds generated as components so far; the rest keep static stories. */export const GENERATED_KINDS = [@@ -413,6 +413,7 @@ export function componentModel(const parts = behaviourParts(graph, set, behaviour, styles.root)const tabs = behaviour.kind === 'tabs' ? tabParts(parts) : nullconst repeated = tabs?.repeated ?? new Map<StateElement, RepeatedPart>()+ activeTriggers(repeated)resetButtons(kind, parts, repeated)// A group's items first, so its item component is used for them rather than a standalone one.diff --git a/packages/dom-css/src/export/components/references.ts b/packages/dom-css/src/export/components/references.tsindex ab64f454b..c2a2d4519 100644--- a/packages/dom-css/src/export/components/references.ts+++ b/packages/dom-css/src/export/components/references.ts@@ -49,9 +49,12 @@ export interface IconReference {const PLACEMENT =/^(position|inset|left|top|right|bottom|(min-|max-)?(width|height)|margin(-.+)?|flex(-.+)?|align-self|justify-self|order|grid-(area|column|row)(-.+)?|transform(-origin)?|rotate|translate|scale|z-index)$/+/** Whether a declaration places a layer rather than drawing it. */+export const isPlacement = (property: string) => PLACEMENT.test(property)+export function placementOnly(element: StateElement): void {const placement = (style: DesignStyleDeclaration): DesignStyleDeclaration =>- Object.fromEntries(Object.entries(style).filter(([property]) => PLACEMENT.test(property)))+ Object.fromEntries(Object.entries(style).filter(([property]) => isPlacement(property)))element.base = placement(element.base)element.rules = element.rules.map((rule) => ({ ...rule, style: placement(rule.style) }))diff --git a/packages/dom-css/src/export/components/repeats.ts b/packages/dom-css/src/export/components/repeats.tsindex 2d10aed6c..5d586b589 100644--- a/packages/dom-css/src/export/components/repeats.ts+++ b/packages/dom-css/src/export/components/repeats.ts@@ -1,7 +1,11 @@+import { difference } from '#dom-css/behaviours/states/model'import type { StateElement, StateNode } from '#dom-css/behaviours/states/types'+import type { DesignStyleDeclaration } from '#dom-css/types'+import { isEmptyObject } from 'es-toolkit/predicate'import { kebabCase } from 'es-toolkit/string'import { claimName } from '../storybook/names'+import { isPlacement } from './references'/** A layer drawn once per value, such as a tab's trigger or its panel, and the value it is. */export interface RepeatedPart {@@ -57,3 +61,68 @@ export function tabParts(parts: ReadonlyMap<StateElement, string>): {const first = values.at(0)return { repeated, choice: first === undefined ? null : { options: values, default: first } }}++/** How `drawn` looks different from `base`, leaving out where each is placed. */+function lookChange(+ base: DesignStyleDeclaration,+ drawn: DesignStyleDeclaration+): DesignStyleDeclaration {+ const changed = Object.entries(difference(base, drawn))+ return Object.fromEntries(changed.filter(([property]) => !isPlacement(property)))+}++/** `base` with `change` applied, where `unset` drops a declaration. */+function applied(+ base: DesignStyleDeclaration,+ change: DesignStyleDeclaration+): DesignStyleDeclaration {+ return Object.fromEntries([+ ...Object.entries(base).filter(([property]) => change[property] !== 'unset'),+ ...Object.entries(change).filter(([, value]) => value !== 'unset')+ ])+}++/** The layer of `into` where `from` has `child`: the same name, and the same one of that name. */+function counterpart(+ child: StateElement,+ from: StateElement,+ into: StateElement+): StateElement | undefined {+ const named = (element: StateElement) =>+ elementsOf(element).filter((item) => item.name === child.name)+ return named(into).at(named(from).indexOf(child))+}++/**+ * Tabs draw the first trigger chosen and the others not. Every trigger rests with the look of+ * the others and takes the first one's, layer by layer, while Reka or Radix marks it active;+ * each keeps its own place. A layer is matched across triggers by name, and one without a+ * counterpart keeps its own styles.+ */+export function activeTriggers(repeated: ReadonlyMap<StateElement, RepeatedPart>): void {+ const triggers = [...repeated].filter(([, item]) => item.part === 'trigger').map(([el]) => el)+ const first = triggers.at(0)+ const second = triggers.at(1)+ if (!first || !second) return+ // The two looks as drawn, before the first trigger rests with the others' look.+ const [active, inactive] = structuredClone([first, second])+ for (const trigger of triggers) {+ const visit = (layer: StateElement, drawn: StateElement, other: StateElement) => {+ if (trigger === first) layer.base = applied(layer.base, lookChange(drawn.base, other.base))+ // From the layer's own rest, so a trigger drawn apart still takes the chosen look.+ const look = lookChange(layer.base, drawn.base)+ if (!isEmptyObject(look))+ layer.rules.push({+ conditions: [{ type: 'state', value: 'active' }],+ on: trigger,+ style: look+ })+ for (const child of elementsOf(layer)) {+ const drawnChild = counterpart(child, layer, drawn)+ const otherChild = counterpart(child, layer, other)+ if (drawnChild && otherChild) visit(child, drawnChild, otherChild)+ }+ }+ visit(trigger, active, inactive)+ }+}diff --git a/packages/dom-css/tests/behaviours/states.test.ts b/packages/dom-css/tests/behaviours/states.test.tsindex 76c155aad..6c4f1a0c2 100644--- a/packages/dom-css/tests/behaviours/states.test.ts+++ b/packages/dom-css/tests/behaviours/states.test.ts@@ -1,5 +1,6 @@import { describe, expect, test } from 'bun:test'+import { cssRules } from '#dom-css-tests/helpers'import {stateStyles,stateStylesToCSS,@@ -9,11 +10,17 @@ import {} from '#dom-css/behaviours/states/index'import { compileTailwindCSS } from '#dom-css/import/tailwind'import type { DesignElement, DesignNode } from '#dom-css/types'-import { parse, type CSSStyleRuleLike } from '@acemir/cssom'import { emptyBehaviour } from '@open-pencil/scene-graph'-import { buttonSet, checkboxSet, componentSet, switchSet, toggleSet } from './fixtures'+import {+ buttonSet,+ checkboxSet,+ componentSet,+ switchSet,+ tabsComponent,+ toggleSet+} from './fixtures'function styles(fixture: ReturnType<typeof switchSet>): StateStyles {const result = stateStyles(fixture.graph, fixture.set)@@ -29,24 +36,6 @@ function child(element: StateElement, key: string): StateElement {return found}-/** Every style rule of a stylesheet, by selector, including ones inside media queries. */-function cssRules(css: string): Map<string, Record<string, string>> {- const rules = new Map<string, Record<string, string>>()- const visit = (list: ArrayLike<unknown>) => {- for (const item of Array.from(list)) {- const rule = item as CSSStyleRuleLike & { cssRules?: ArrayLike<unknown> }- if (rule.cssRules) visit(rule.cssRules)- if (!rule.selectorText) continue- const style: Record<string, string> = {}- for (const property of Array.from({ length: rule.style.length }, (_, i) => rule.style[i]))- if (property) style[property] = rule.style.getPropertyValue(property)- rules.set(rule.selectorText, style)- }- }- visit(parse(css).cssRules)- return rules-}-/*** Tailwind's compiled rules as selector and declarations. Its escaped class selectors are* beyond the CSSOM parser, so innermost `selector { … }` blocks are read directly, which also@@ -59,6 +48,25 @@ function compiledRules(css: string): [string, string][] {])}+/**+ * Tabs whose first trigger, and the label in it, change while that trigger is active, the+ * state Reka and Radix set on the trigger rather than the root.+ */+function anchoredTabs() {+ const root = styles(tabsComponent())+ const trigger = { opacity: '0.5' }+ const label = { color: '#fff' }+ const triggerElement = child(child(root.root, 'List'), 'List/Trigger#0')+ const labelElement = child(+ triggerElement,+ triggerElement.children.find((item) => item.type === 'element')?.key ?? ''+ )+ const active = [{ type: 'state' as const, value: 'active' }]+ triggerElement.rules.push({ conditions: active, on: triggerElement, style: trigger })+ labelElement.rules.push({ conditions: active, on: triggerElement, style: label })+ return { root, trigger, label }+}+function elements(node: DesignNode, into: DesignElement[] = []): DesignElement[] {if (node.type !== 'element') return intointo.push(node)@@ -168,9 +176,36 @@ describe('state stylesheet', () => {const rules = cssRules((await stateStylesToCSS(styles(buttonSet()))).css)expect(rules.get('.button[data-size="Large"]')).toEqual({ width: '160px' })})+ test('tests the state of the layer a rule names, for that layer and the ones inside it', async () => {+ const { root, trigger, label } = anchoredTabs()+ const rules = cssRules((await stateStylesToCSS(root)).css)+ expect(rules.get('.settings .settings__trigger[data-state="active"]')).toEqual(trigger)+ expect(rules.get('.settings .settings__trigger[data-state="active"] .settings__label')).toEqual(+ label+ )+ })})describe('state Tailwind', () => {+ test('names a group for the layer a rule tests, which the layers inside it test', async () => {+ const document = stateStylesToTailwind(anchoredTabs().root)+ const [, , trigger, label] = elements(document.children[0] ?? { type: 'text', text: '' })+ const triggerClasses = trigger?.attrs.class.split(' ') ?? []+ const labelClasses = label?.attrs.class.split(' ') ?? []+ expect(triggerClasses).toContain('group/settings-1')+ expect(triggerClasses).toContain('data-[state=active]:opacity-50')+ expect(labelClasses).toContain('group-data-[state=active]/settings-1:text-[#fff]')++ const rules = compiledRules(await compileTailwindCSS([...triggerClasses, ...labelClasses]))+ expect(+ rules.some(+ ([selector, body]) =>+ body.startsWith('color:') &&+ selector.endsWith(':is(:where(.group\\/settings-1)[data-state="active"] *)')+ )+ ).toBe(true)+ })+test('writes state variants that Tailwind compiles to the same selectors', async () => {const document = stateStylesToTailwind(styles(switchSet()))const [root, thumb] = elements(document.children[0] ?? { type: 'text', text: '' })diff --git a/packages/dom-css/tests/export/components/react.test.ts b/packages/dom-css/tests/export/components/react.test.tsindex 4297b8e16..5d1fec289 100644--- a/packages/dom-css/tests/export/components/react.test.ts+++ b/packages/dom-css/tests/export/components/react.test.ts@@ -14,6 +14,7 @@ import {tabsComponent,toggleGroupComponent} from '#dom-css-tests/behaviours/fixtures'+import { cssRules } from '#dom-css-tests/helpers'import { exportStorybook } from '#dom-css/index'import { createElement, type ComponentType } from 'react'import { renderToStaticMarkup } from 'react-dom/server'@@ -141,6 +142,24 @@ describe('generated React components', () => {expect(second).not.toContain('Account settings')})+ test('every tab trigger rests unchosen and takes the chosen look while active, in its place', async () => {+ const { files } = await generate(tabsComponent())+ const rules = cssRules(+ String(files.find((file) => file.path === 'Settings.module.css')?.content)+ )+ const [first, second] = ['.settings .settings__trigger', '.settings .settings__trigger-2'].map(+ (selector) => ({+ rest: rules.get(selector),+ active: rules.get(`${selector}[data-state="active"]`)+ })+ )+ // The design draws the first tab chosen; at rest it looks like the others, where it is drawn.+ expect(first?.rest?.['background-color']).toBe(second?.rest?.['background-color'])+ expect([first?.rest?.left, second?.rest?.left]).toEqual(['0px', '90px'])+ expect(first?.active).toEqual({ 'background-color': '#4F45E6' })+ expect(second?.active).toEqual(first?.active)+ })+test('a radio group writes an item component and chooses among its labelled items', async () => {const { files, component } = await generate(radioGroupComponent())expect(files.map((file) => file.path)).toContain('PlanItem.tsx')diff --git a/packages/dom-css/tests/export/components/repeats.test.ts b/packages/dom-css/tests/export/components/repeats.test.tsnew file mode 100644index 000000000..98a8cae1e--- /dev/null+++ b/packages/dom-css/tests/export/components/repeats.test.ts@@ -0,0 +1,66 @@+import { describe, expect, test } from 'bun:test'++import type { StateElement } from '#dom-css/behaviours/states/types'+import { activeTriggers, type RepeatedPart } from '#dom-css/export/components/repeats'+import type { DesignStyleDeclaration } from '#dom-css/types'++function layer(+ name: string,+ base: DesignStyleDeclaration,+ children: StateElement[] = []+): StateElement {+ return { type: 'element', key: name, name, tagName: 'div', attrs: {}, base, rules: [], children }+}++/** A trigger with an icon and a label in `order`. */+function trigger(+ background: string,+ [icon, label, weight]: [string, string, string],+ order: 'icon first' | 'label first'+) {+ const layers = [+ layer('Icon', { color: icon }),+ layer('Label', { color: label, 'font-weight': weight })+ ]+ return layer(+ 'Trigger',+ { 'background-color': background },+ order === 'icon first' ? layers : layers.reverse()+ )+}++function triggers(...elements: StateElement[]): Map<StateElement, RepeatedPart> {+ return new Map(+ elements.map((element, index) => [element, { part: 'trigger', value: String(index) }])+ )+}++const active = (element: StateElement | undefined, on: StateElement) =>+ element?.rules.find((rule) => rule.on === on && rule.conditions.at(0)?.type === 'state')?.style++const child = (element: StateElement, name: string) =>+ element.children.find(+ (item): item is StateElement => item.type === 'element' && item.name === name+ )++describe('tab triggers', () => {+ test('take the first trigger’s look while active, from their own rest and layer by name', () => {+ const chosen = trigger('#111', ['#999', '#fff', '400'], 'icon first')+ const plain = trigger('#eee', ['#555', '#333', '400'], 'icon first')+ // Drawn apart from the others, in bold with its layers in another order.+ const apart = trigger('#eee', ['#555', '#333', '700'], 'label first')+ activeTriggers(triggers(chosen, plain, apart))++ expect(chosen.base).toEqual({ 'background-color': '#eee' })+ expect(child(chosen, 'Label')?.base).toEqual({ color: '#333', 'font-weight': '400' })+ for (const each of [chosen, plain]) {+ expect(active(each, each)).toEqual({ 'background-color': '#111' })+ expect(active(child(each, 'Icon'), each)).toEqual({ color: '#999' })+ expect(active(child(each, 'Label'), each)).toEqual({ color: '#fff' })+ }+ expect(active(child(apart, 'Icon'), apart)).toEqual({ color: '#999' })+ expect(active(child(apart, 'Label'), apart)).toEqual({ color: '#fff', 'font-weight': '400' })+ // At rest it keeps its own look.+ expect(child(apart, 'Label')?.base).toEqual({ color: '#333', 'font-weight': '700' })+ })+})diff --git a/packages/dom-css/tests/helpers.ts b/packages/dom-css/tests/helpers.tsindex 11a0ccf28..1d10ede97 100644--- a/packages/dom-css/tests/helpers.ts+++ b/packages/dom-css/tests/helpers.ts@@ -1,3 +1,5 @@+import { parse, type CSSStyleRuleLike } from '@acemir/cssom'+import { colorToCSS } from '@open-pencil/scene-graph/color'import type { DesignDocument } from '../src/index'@@ -144,3 +146,21 @@ export const tailwindInputClasses = ['text-sm','text-slate-900'] as const++/** Every style rule of a stylesheet, by selector, including ones inside media queries. */+export function cssRules(css: string): Map<string, Record<string, string>> {+ const rules = new Map<string, Record<string, string>>()+ const visit = (list: ArrayLike<unknown>) => {+ for (const item of Array.from(list)) {+ const rule = item as CSSStyleRuleLike & { cssRules?: ArrayLike<unknown> }+ if (rule.cssRules) visit(rule.cssRules)+ if (!rule.selectorText) continue+ const style: Record<string, string> = {}+ for (const property of Array.from({ length: rule.style.length }, (_, i) => rule.style[i]))+ if (property) style[property] = rule.style.getPropertyValue(property)+ rules.set(rule.selectorText, style)+ }+ }+ visit(parse(css).cssRules)+ return rules+}diff --git a/skills/open-pencil/references/design-authoring.md b/skills/open-pencil/references/design-authoring.mdindex 06f681a05..7d2737972 100644--- a/skills/open-pencil/references/design-authoring.md+++ b/skills/open-pencil/references/design-authoring.md@@ -45,7 +45,7 @@ This reference describes scene creation, not React DOM output. Use the `render`- A main component can behave as a Reka UI control in preview and code. Write it with Reka's names: `Switch.Root` is the component (a component set when its children are `Component` variants), and each Reka part is the slot that draws it, such as `Switch.Thumb`, `Slider.Track`, `Slider.Range`, `Slider.Thumb`, `Tabs.List`, `Collapsible.Trigger`, or `NumberField.Increment`. Parts in different variants share one slot.- The root names the properties that hold its values: `modelValue` (`open` on `Collapsible.Root`), `disabled`, and, for text fields, `filled`, as a variant or boolean property name, or `{ property, on, off }` when the variant values are not named like On and Off. `states` names the variant property that draws default, hover, pressed, focus, and disabled; a slider, progress bar, or number field takes `min`, `max`, `step`, and `defaultValue`.-- `TextField.Input`, `Textarea.Input`, and `NumberField.Input` are the text layers whose text becomes the field's text property. `Tabs.Trigger` goes in `Tabs.List`; `Tabs.Content` panels may sit directly under `Tabs.Root`, the first showing.+- `TextField.Input`, `Textarea.Input`, and `NumberField.Input` are the text layers whose text becomes the field's text property. `Tabs.Trigger` goes in `Tabs.List`; `Tabs.Content` panels may sit directly under `Tabs.Root`, the first showing. A part with children and no `flex`, `display`, `w`, or `h` of its own stacks them in a column that hugs them.- A group's item component is written on its own (`RadioGroup.Item`, `ToggleGroup.Item`, `Accordion.Item` with its `Accordion.Trigger` and `Accordion.Content`); the group's root then lists items as `<RadioGroup.Item of={radioId} />`.```tsx