diff --git a/.changeset/sheet-side-drawer.md b/.changeset/sheet-side-drawer.md new file mode 100644 index 00000000..33cd510f --- /dev/null +++ b/.changeset/sheet-side-drawer.md @@ -0,0 +1,7 @@ +--- +"@codeui/solid": minor +"@codeui/styles": minor +"@codeui/inkstone": minor +--- + +Sheet: left and right sheets float 8px in from the edges and become a bottom sheet at 768px and below, where `draggable` shows the grip. A `mount` other than `document.body` makes the sheet and its scrim cover that element. The sheet slides with transitions (in 260ms on the new `--cui-motion-ease-drawer`, out 200ms), stays mounted through its exit, reverses when reopened mid-exit, and no longer leaves the page unclickable while it closes. A modal sheet without an overlay no longer blocks clicks on the page. diff --git a/.claude/skills/verify-codeui/features/overlays.md b/.claude/skills/verify-codeui/features/overlays.md index b0ac0a51..41d2b547 100644 --- a/.claude/skills/verify-codeui/features/overlays.md +++ b/.claude/skills/verify-codeui/features/overlays.md @@ -1,6 +1,6 @@ # Overlays -Dialog and Popover open from a trigger, move focus inside, trap Tab while modal, close on Escape or the close button, and return focus to the trigger. Both render the same in dark and light themes. Sheet and CommandMenu arrive in later PRs; add them here when their stories land. +Dialog and Popover open from a trigger, move focus inside, trap Tab while modal, close on Escape or the close button, and return focus to the trigger. Both render the same in dark and light themes. Sheet follows the same focus rules; CommandMenu arrives in a later PR. ## Sub-features @@ -21,6 +21,9 @@ Dialog and Popover open from a trigger, move focus inside, trap Tab while modal, - `hovercard-touch` opens the card on a touch tap without following the link, places it on the right of the trigger by default, keeps the floating surface (dialog fill, shadow with the dark inset ring, radius 16, max width 320), closes on an outside press, and opens at once on a mouse click. Journey: `journeys/hovercard-touch.mjs` on `designsystem-hovercard--hover-card-story`. - `hovercard-edge` flips the card to the left when there is no room on the right. Journey: `journeys/hovercard-edge.mjs` on `designsystem-hovercard--edge-placement`. - `hovercard-list` renders `HoverCardList`: one 28px line per entry, 16px indent per depth, truncated titles, named state icons, capped at 24rem with its own scroll. Journey: `journeys/hovercard-list.mjs` on `designsystem-hovercard--task-list`. +- `sheet-side` a right sheet mounted in a content island: floats 8px in from the island's top, right and bottom; the scrim covers only the island; Enter opens it with `data-motion="none"` and focus inside; Escape and a scrim click close it and return focus to the opener; at 390×844 it becomes a full-width bottom sheet with the grip. Journey: `journeys/sheet-drawer.mjs` on `designsystem-sheet--drawer`. +- `sheet-swap` choosing another row, or Edit, swaps the open sheet's content: same element, `data-expanded` never removed. Journeys: `journeys/sheet-drawer.mjs` (Edit, modal) and `journeys/sheet-swap.mjs` on `designsystem-sheet--drawer-nonmodal` (row clicks). +- `sheet-motion` the slide itself. drive.mjs disables motion, so `node scripts/sheet-motion.mjs designsystem-sheet--sides "Open (right)" [reduce]` samples the content and scrim with motion on: pointer enter 260ms transform on the drawer curve, exit 200ms ease-out and still mounted at 150ms, reopen mid-exit reverses, keyboard `data-motion="none"`, reduced motion opacity only. - `popover-parts` composes `@codeui/solid/popover/parts` parts with title, description, arrow and close button. ## How to get to it (user POV) diff --git a/.claude/skills/verify-codeui/journeys/sheet-drawer.mjs b/.claude/skills/verify-codeui/journeys/sheet-drawer.mjs new file mode 100644 index 00000000..410fe4da --- /dev/null +++ b/.claude/skills/verify-codeui/journeys/sheet-drawer.mjs @@ -0,0 +1,121 @@ +// Drives designsystem-sheet--drawer (modal) like a keyboard user. +export default async ({ page, step, check, focus, axe }) => { + const dialog = () => page.getByRole("dialog"); + const tabTo = async name => { + for (let i = 0; i < 30; i++) { + await page.keyboard.press("Tab"); + if ((await focus()).name?.startsWith(name)) return; + } + throw new Error(`Tab never reached ${name}`); + }; + const boxes = () => + page.evaluate(() => { + const r = el => el && el.getBoundingClientRect().toJSON(); + return { + main: r(document.querySelector("main")), + sheet: r(document.querySelector('[data-cui="sheet-content"]')), + overlay: r(document.querySelector('[data-cui="sheet-overlay"]')), + handleShown: (() => { + const h = document.querySelector('[data-cui="sheet-handle"]'); + return !!h && getComputedStyle(h).display !== "none"; + })(), + }; + }); + + await step("closed", async () => {}); + await check("closed: no dialog", async () => ({ pass: (await dialog().count()) === 0 })); + + await step("open New automation with Enter", async () => { + await tabTo("New automation"); + await page.keyboard.press("Enter"); + await dialog().waitFor(); + await page.waitForFunction(() => document.activeElement?.closest('[role="dialog"]')); + }); + await check("open: named New automation, focus inside", async () => { + const f = await focus(); + const name = await dialog().getAttribute("aria-labelledby").then(id => page.locator(`#${id}`).textContent()); + return { pass: f.inDialog && name === "New automation", name, focus: f }; + }); + await check("open: keyboard open does not move", async () => ({ + pass: (await dialog().getAttribute("data-motion")) === "none", + })); + await check("open: floats inside the island, inset 8px, scrim covers only the island", async () => { + const { main, sheet, overlay } = await boxes(); + const pass = + Math.round(main.right - sheet.right) === 8 && + Math.round(sheet.top - main.top) === 8 && + Math.round(main.bottom - sheet.bottom) === 8 && + Math.round(overlay.left) === Math.round(main.left) && + Math.round(overlay.width) === Math.round(main.width); + return { pass, main, sheet, overlay }; + }); + await axe("open-new"); + + await step("Escape closes", async () => { + await page.keyboard.press("Escape"); + await dialog().waitFor({ state: "detached" }); + }); + await page.waitForFunction(() => document.activeElement?.textContent === "New automation"); + await check("closed: focus back on New automation", async () => { + const f = await focus(); + return { pass: f.name === "New automation", focus: f }; + }); + + await step("open a row with Enter", async () => { + await tabTo("Morning digest"); + await page.keyboard.press("Enter"); + await dialog().waitFor(); + await page.evaluate(() => (window.__sheet = document.querySelector('[data-cui="sheet-content"]'))); + }); + await check("detail: title is the row", async () => ({ + pass: (await page.locator('[data-cui="sheet-title"]').textContent()) === "Morning digest", + })); + await axe("detail"); + + await step("Edit swaps the content in place", async () => { + await tabTo("Edit"); + await page.keyboard.press("Enter"); + await page.locator('[data-cui="sheet-title"]', { hasText: "Edit automation" }).waitFor(); + }); + await check("swap: same sheet element, still open, no remount", async () => { + const same = await page.evaluate( + () => window.__sheet === document.querySelector('[data-cui="sheet-content"]') && window.__sheet.hasAttribute("data-expanded"), + ); + return { pass: same }; + }); + await axe("form"); + + await step("scrim click closes", async () => { + const { main } = await boxes(); + await page.mouse.click(main.left + 40, main.top + 200); + await dialog().waitFor({ state: "detached" }); + }); + await page.waitForFunction(() => document.activeElement?.hasAttribute("data-row"), null, { timeout: 3000 }).catch(() => {}); + await check("scrim: closed and focus back on the row", async () => { + const f = await focus(); + return { pass: (await dialog().count()) === 0 && f.name?.startsWith("Morning digest"), focus: f }; + }); + + await step("phone: open becomes a bottom sheet", async () => { + await page.setViewportSize({ width: 390, height: 844 }); + await page.locator("body").press("Escape"); + await tabTo("New automation"); + await page.keyboard.press("Enter"); + await dialog().waitFor(); + }); + await check("phone: full width of the island, on its bottom edge, grip shown", async () => { + const { main, sheet, handleShown } = await boxes(); + const pass = + Math.round(sheet.left) === Math.round(main.left) && + Math.round(sheet.right) === Math.round(main.right) && + Math.round(sheet.bottom) === Math.round(main.bottom) && + sheet.top > main.top && + handleShown; + return { pass, main, sheet, handleShown }; + }); + await axe("phone"); + await step("phone: Escape closes", async () => { + await page.keyboard.press("Escape"); + await dialog().waitFor({ state: "detached" }); + }); +}; diff --git a/.claude/skills/verify-codeui/journeys/sheet-swap.mjs b/.claude/skills/verify-codeui/journeys/sheet-swap.mjs new file mode 100644 index 00000000..896dff9f --- /dev/null +++ b/.claude/skills/verify-codeui/journeys/sheet-swap.mjs @@ -0,0 +1,35 @@ +// designsystem-sheet--drawernonmodal: clicking another row swaps the open sheet. +export default async ({ page, step, check, focus, axe }) => { + const title = () => page.locator('[data-cui="sheet-title"]').textContent(); + await step("click Morning digest", async () => { + await page.getByRole("button", { name: /^Morning digest/ }).click(); + await page.getByRole("dialog").waitFor(); + await page.evaluate(() => { + const sheet = document.querySelector('[data-cui="sheet-content"]'); + window.__sheet = sheet; + window.__lostExpanded = false; + new MutationObserver(() => { + if (!sheet.hasAttribute("data-expanded")) window.__lostExpanded = true; + }).observe(sheet, { attributes: true, attributeFilter: ["data-expanded"] }); + }); + }); + await check("detail open", async () => ({ pass: (await title()) === "Morning digest" })); + await step("click Issue triage while open", async () => { + await page.getByRole("button", { name: /^Issue triage/ }).click(); + await page.locator('[data-cui="sheet-title"]', { hasText: "Issue triage" }).waitFor(); + }); + await check("swap: same element, never closed", async () => { + const r = await page.evaluate(() => ({ + same: window.__sheet === document.querySelector('[data-cui="sheet-content"]'), + lost: window.__lostExpanded, + current: document.querySelector('[aria-current="true"]')?.textContent, + })); + return { pass: r.same && !r.lost && r.current?.startsWith("Issue triage"), ...r }; + }); + await axe("swapped"); + await step("Escape closes", async () => { + await page.getByRole("dialog").focus(); + await page.keyboard.press("Escape"); + await page.getByRole("dialog").waitFor({ state: "detached" }); + }); +}; diff --git a/.claude/skills/verify-codeui/scripts/sheet-motion.mjs b/.claude/skills/verify-codeui/scripts/sheet-motion.mjs new file mode 100644 index 00000000..e5a112bc --- /dev/null +++ b/.claude/skills/verify-codeui/scripts/sheet-motion.mjs @@ -0,0 +1,73 @@ +// Records what a Sheet animates with motion on (drive.mjs turns motion off). +// usage: node .claude/skills/verify-codeui/scripts/sheet-motion.mjs [reduce] +import { launch } from "../../../../tools/baseline/browser.mjs"; + +const [base, story, buttonName, reduce] = process.argv.slice(2); +const browser = await launch(); +const context = await browser.newContext({ + viewport: { width: 1280, height: 900 }, + reducedMotion: reduce ? "reduce" : "no-preference", +}); +const page = await context.newPage(); +await page.goto(`${base}/iframe.html?id=${story}&viewMode=story`, { waitUntil: "networkidle" }); + +const snapshot = () => + page.evaluate(() => { + const pick = sel => { + const el = document.querySelector(sel); + if (!el) return null; + return { + motion: el.getAttribute("data-motion"), + anims: el.getAnimations().map(a => { + const t = a.effect.getTiming(); + return { + type: a.constructor.name, + name: a.animationName ?? a.transitionProperty, + duration: t.duration, + easing: t.easing === "linear" ? getComputedStyle(el).transitionTimingFunction || getComputedStyle(el).animationTimingFunction : t.easing, + }; + }), + transform: getComputedStyle(el).transform, + opacity: getComputedStyle(el).opacity, + }; + }; + return { content: pick('[data-cui="sheet-content"]'), overlay: pick('[data-cui="sheet-overlay"]') }; + }); + +const result = {}; +// Pointer open +await page.getByRole("button", { name: buttonName }).click(); +await page.waitForTimeout(30); +result.pointerOpen = await snapshot(); +await page.waitForTimeout(600); +// Pointer close via the close button +await page.locator('[data-cui="sheet-close-button"]').click(); +await page.waitForTimeout(30); +result.pointerClose30ms = await snapshot(); +await page.waitForTimeout(120); +result.pointerClose150ms = await snapshot(); +await page.waitForTimeout(450); +result.after600ms = await snapshot(); +// Interrupt: close, then reopen 80ms into the exit +await page.getByRole("button", { name: buttonName }).click(); +await page.waitForTimeout(600); +await page.locator('[data-cui="sheet-close-button"]').click(); +await page.waitForTimeout(80); +result.interruptMidExit = await snapshot(); +await page.getByRole("button", { name: buttonName }).click({ force: true }); +await page.waitForTimeout(20); +result.interruptReopened20ms = await snapshot(); +await page.waitForTimeout(600); +result.interruptSettled = await snapshot(); +await page.keyboard.press("Escape"); +await page.waitForTimeout(600); +// Keyboard open +await page.getByRole("button", { name: buttonName }).focus(); +await page.keyboard.press("Enter"); +await page.waitForTimeout(30); +result.keyboardOpen = await snapshot(); +await page.keyboard.press("Escape"); +await page.waitForTimeout(30); +result.keyboardClose30ms = await snapshot(); +console.log(JSON.stringify(result, null, 1)); +await browser.close(); diff --git a/apps/docs/content/docs/(kit)/components/sheet.mdx b/apps/docs/content/docs/(kit)/components/sheet.mdx index ff9a45c4..a6a32529 100644 --- a/apps/docs/content/docs/(kit)/components/sheet.mdx +++ b/apps/docs/content/docs/(kit)/components/sheet.mdx @@ -38,7 +38,13 @@ Use [Dialog](/docs/components/dialog) for a blocking decision. Use [Popover](/do -`side` accepts `left`, `right`, and `bottom`. Bottom is the default. +`side` accepts `left`, `right`, and `bottom`. Bottom is the default. A left or right sheet floats 8px in from the top, bottom and its edge, with every corner rounded, and is 24rem wide (set `--cui-sheet-width` on the content to change it). At 768px and below it becomes a bottom sheet. + +### In a container + +Pass `mount` an element other than `document.body`, and the sheet and its scrim cover that element instead of the viewport. Give the element `position: relative`. CodeLoom mounts its side sheet in the content island, so the sidebar stays uncovered and usable. + +Change what the sheet shows while it stays open, and it swaps in place with no close and reopen. For a nonmodal sheet beside a list, keep a click on another row from dismissing it: call `event.preventDefault()` in `contentProps.onInteractOutside` when the target is a row. @@ -46,11 +52,11 @@ Modal sheets render a scrim and trap focus. `modal={false}` removes the scrim an -`draggable` adds a handle only to a bottom sheet. The placement union rejects draggable left and right sheets. +`draggable` adds a handle to a bottom sheet. A left or right sheet renders the handle only while it is a bottom sheet, at 768px and below. -`motion="auto"` slides on pointer open and close. Keyboard actions do not animate. Reduced motion replaces the slide with a fade. `motion="none"` disables presence animation. +`motion="auto"` slides on pointer open and close: in over 260ms on the drawer curve, out over 200ms ease-out. The slide is a CSS transition, so reopening a sheet mid-exit turns it around from where it is. Keyboard actions do not animate. Reduced motion replaces the slide with a fade. `motion="none"` disables presence animation. A downward drag tracks the handle 1:1. Dragging above the open position applies rubber band resistance. A downward flick above 0.5 px/ms or a drag beyond 35% of the sheet height dismisses it. Short drags and `pointercancel` settle back open. A new grab can interrupt the settle. Reduced motion skips the settle animation. @@ -58,7 +64,7 @@ Drag events belong to `Handle`, not `Body`. Scrollable body content scrolls with ## States -The live demo controls `open` with `onOpenChange`. Parts also support `defaultOpen` for uncontrolled state. Closed content unmounts after its exit animation unless Kobalte force mounting is enabled. +The live demo controls `open` with `onOpenChange`. Parts also support `defaultOpen` for uncontrolled state. Closed content stays mounted until its exit transition ends, then unmounts unless `forceMount` is set. During the exit the sheet is inert and the page under it takes clicks. ## Ready API @@ -132,7 +138,7 @@ Kobalte Dialog.Overlay with scrim styles. Include it only for a modal sheet. ### `Portal` -Kobalte Dialog.Portal. `mount` selects the browser destination. It renders no wrapper. +Kobalte Dialog.Portal. `mount` selects the browser destination. It renders no wrapper. With a `mount` other than `document.body`, the overlay and the content get `data-contained` and cover that element. diff --git a/apps/docs/content/docs/(kit)/foundations/tokens.mdx b/apps/docs/content/docs/(kit)/foundations/tokens.mdx index cca5a079..59ec56f3 100644 --- a/apps/docs/content/docs/(kit)/foundations/tokens.mdx +++ b/apps/docs/content/docs/(kit)/foundations/tokens.mdx @@ -3,7 +3,7 @@ title: "Tokens" description: "The --cui-* custom properties every kit style reads." --- -Every color, radius, space, size, shadow and motion value in the kit is a `--cui-*` CSS custom property. Kit components read only these properties, so changing one changes every component that uses it. The kit defines 142 of them. +Every color, radius, space, size, shadow and motion value in the kit is a `--cui-*` CSS custom property. Kit components read only these properties, so changing one changes every component that uses it. The kit defines 143 of them. @@ -296,5 +296,6 @@ The kit does not load a font file. Without Inter, the stack falls back to the sy | `motion.duration.slow` | `--cui-motion-duration-slow` | `260ms` | | `motion.duration.rise` | `--cui-motion-duration-rise` | `400ms` | | `motion.ease.out` | `--cui-motion-ease-out` | `cubic-bezier(0.23, 1, 0.32, 1)` | +| `motion.ease.drawer` | `--cui-motion-ease-drawer` | `cubic-bezier(0.32, 0.72, 0, 1)` | [Motion](/docs/foundations/motion) explains when to use each duration. diff --git a/apps/docs/content/docs/css/components/sheet.mdx b/apps/docs/content/docs/css/components/sheet.mdx index 64aee564..98199bd0 100644 --- a/apps/docs/content/docs/css/components/sheet.mdx +++ b/apps/docs/content/docs/css/components/sheet.mdx @@ -32,6 +32,7 @@ The overlay and the content are siblings. Put the overlay first. | `data-side` on the content | `bottom`, `left`, `right` | `bottom` | | `data-expanded` on the overlay and the content | Presence | Off | | `data-motion` on the overlay and the content | `none` | None | +| `data-contained` on the overlay and the content | Presence | Off | ## Variants @@ -41,14 +42,18 @@ The overlay and the content are siblings. Put the overlay first. -`data-side="left"` and `data-side="right"` pin the sheet to that edge at full height. It is 24rem wide, and at least 40px narrower than the viewport. The corners on the open edge are rounded. +`data-side="left"` and `data-side="right"` float the sheet 8px in from the top, bottom and that edge, with every corner rounded. It is 24rem wide, or `--cui-sheet-width`, and never wider than the area less the insets. At 768px and below it is a bottom sheet. + +### Contained + +`data-contained` on the overlay and the content positions them `absolute` instead of `fixed`, so they cover their nearest positioned ancestor instead of the viewport. A bottom sheet spans the width and stops 40px below the top of the viewport. Omitting `data-side` renders a bottom sheet. ### Handle -Put a `button.cui-sheet-handle` first in a bottom sheet. It is a 40px tall hit area with a 40×4 bar. Give it an accessible name, because it has no text. +Put a `button.cui-sheet-handle` first in a bottom sheet. It is a 40px tall hit area with a 40×4 bar. Give it an accessible name, because it has no text. Above 768px a left or right sheet hides its handle; render it there only at 768px and below, or focus may land on a hidden button. The handle has `touch-action: none`, so a script can track a drag on it while the body still scrolls. ### Non-modal @@ -61,12 +66,12 @@ Leave out the overlay and the page behind stays visible and usable. Set `aria-mo ### Open -`data-expanded` on the content slides it in from its side over the panel duration. `data-expanded` on the overlay fades the scrim in. -Without `data-expanded`, both play their exit animation and stay hidden: the content off screen and the scrim transparent. Set it on an open sheet even without a script. +`data-expanded` on the content slides it in from its side, over 260ms on `--cui-motion-ease-drawer`. `data-expanded` on the overlay fades the scrim in. Both are transitions that start from `@starting-style`, so adding `data-expanded` again mid-exit turns them around. +Without `data-expanded`, both transition out over 200ms ease-out and stay hidden: the content off screen and the scrim transparent. Set it on an open sheet even without a script. ### Closing -Remove `data-expanded` from both while they are still in the page. The content slides out and the overlay fades. Remove the markup when the animation ends. +Remove `data-expanded` from both while they are still in the page. The content slides out and the overlay fades. Remove the markup on the content's `transitionend`. ### No motion diff --git a/apps/docs/content/docs/design/motion.mdx b/apps/docs/content/docs/design/motion.mdx index 4abc7973..78e7acf7 100644 --- a/apps/docs/content/docs/design/motion.mdx +++ b/apps/docs/content/docs/design/motion.mdx @@ -34,7 +34,7 @@ Naming the movements gives designers, developers and agents a shared vocabulary. | **Collapse to origin** | Closing something that lives on elsewhere | Shrinks into where it can be found again, 200ms | | **Rise** | Corner card, toast | From the edge 400ms; leaves in 200ms | | **Reveal** | A surface growing in place | `clip-path`, 260ms | -| **Slide** | Phone sheet | Up from below, 280ms drawer curve; follows the finger when dragged | +| **Slide** | Phone sheet, side sheet | From its edge in 260ms on the drawer curve; out in 200ms ease-out; turns around if reopened mid-exit; follows the finger when dragged | | **Ring** | Selection ring | From `scale(0.92)` with a fade, 200ms | ### The best example: collapse to origin @@ -85,4 +85,4 @@ The kit's own components are slower and softer than the app that uses them. | Dialog: Pop as keyframes, in 200ms from `scale(0.96)`, out 120ms toward `scale(0.98)`, scrim fades, no motion from the keyboard | Pop, as a reversible transition | | Segmented indicator: 160ms ease-out on click, instant from the keyboard | 200ms ease-out, or no animation in working panels | -Two curves are also missing from the tokens: `--cui-motion-ease-in-out` and `--cui-motion-ease-drawer`. +One curve is still missing from the tokens: `--cui-motion-ease-in-out`. The drawer curve is `--cui-motion-ease-drawer`, and the kit sheet slides on it. diff --git a/apps/docs/content/docs/design/patterns.mdx b/apps/docs/content/docs/design/patterns.mdx index 670686e7..b7b82185 100644 --- a/apps/docs/content/docs/design/patterns.mdx +++ b/apps/docs/content/docs/design/patterns.mdx @@ -55,7 +55,7 @@ The preview is a schematic drawn in the option's own colours, not a miniature of | Popover | Pick a value for one row | None | | Menu | Choose an action | None | | Command menu | Find anything by name | None | -| Sheet | A panel on a phone | None | +| Sheet | A panel on a phone; a side sheet for a record's details or form | Scrim when modal | | Dialog | Settings, or a decision that blocks | Scrim | A picker opens over the panel that holds it, anchored to its row. It does not push the rows below it down, and it does not dim the page. The user is choosing a value for the content, so the content must stay visible. diff --git a/docs/kit-2026/design/k5-token-map.json b/docs/kit-2026/design/k5-token-map.json index 3874240b..a4989dd3 100644 --- a/docs/kit-2026/design/k5-token-map.json +++ b/docs/kit-2026/design/k5-token-map.json @@ -1136,6 +1136,14 @@ "dark": "cubic-bezier(0.23, 1, 0.32, 1)", "light": "cubic-bezier(0.23, 1, 0.32, 1)", "source": "measured preview and DESIGN.md; threads rule" + }, + { + "group": "motion", + "token": "motion.ease.drawer", + "css": "--cui-motion-ease-drawer", + "dark": "cubic-bezier(0.32, 0.72, 0, 1)", + "light": "cubic-bezier(0.32, 0.72, 0, 1)", + "source": "DESIGN.md §7.3 Slide (sheet and side sheet enter); iOS drawer curve" } ], "mappings": { diff --git a/docs/kit-2026/design/k5-tokens.md b/docs/kit-2026/design/k5-tokens.md index 9a694fe0..491b0eef 100644 --- a/docs/kit-2026/design/k5-tokens.md +++ b/docs/kit-2026/design/k5-tokens.md @@ -196,6 +196,7 @@ Token paths refer to the proposed exported `tokens` object. The CSS name is stab | `motion.duration.slow` | `--cui-motion-duration-slow` | `260ms` | `260ms` | measured preview fast/normal/panel; DESIGN.md 260ms ceiling for usual transitions | | `motion.duration.rise` | `--cui-motion-duration-rise` | `400ms` | `400ms` | DESIGN.md §7.3 Rise (toast, corner card); measured preview toast 350ms and Nudge 400ms | | `motion.ease.out` | `--cui-motion-ease-out` | `cubic-bezier(0.23, 1, 0.32, 1)` | `cubic-bezier(0.23, 1, 0.32, 1)` | measured preview and DESIGN.md; threads rule | +| `motion.ease.drawer` | `--cui-motion-ease-drawer` | `cubic-bezier(0.32, 0.72, 0, 1)` | `cubic-bezier(0.32, 0.72, 0, 1)` | DESIGN.md §7.3 Slide (sheet and side sheet enter); iOS drawer curve | ## Public CSS and vanilla-extract coexistence diff --git a/packages/docs-demos/src/props/sheet.ts b/packages/docs-demos/src/props/sheet.ts index c41dc1e7..4036e146 100644 --- a/packages/docs-demos/src/props/sheet.ts +++ b/packages/docs-demos/src/props/sheet.ts @@ -43,12 +43,12 @@ export const notes = { SheetHandleInherited: { disabled: { default: "false", description: "Disables the handle." } }, SheetTriggerInherited: { disabled: { default: "false", description: "Disables the trigger." } }, Sheet: { - "side": { default: '"bottom"', description: 'Viewport edge for the content.' }, - "draggable": { default: 'false', description: 'Adds the dismiss handle to a bottom sheet.' }, + "side": { default: '"bottom"', description: 'Edge for the content. Left and right float inset, and become a bottom sheet at 768px and below.' }, + "draggable": { default: 'false', description: 'Adds the dismiss handle to a bottom sheet, and to a side sheet while it is one.' }, "title": { description: 'Accessible sheet heading.' }, "description": { description: 'Description linked to the sheet.' }, "footer": { description: 'Actions rendered below the body.' }, - "mount": { default: 'document.body', description: 'Portal destination in the browser.' }, + "mount": { default: 'document.body', description: 'Portal destination in the browser. Any other element is covered instead of the viewport.' }, "showCloseButton": { default: 'true', description: 'Includes the close button in the header.' }, "closeLabel": { default: '"close"', description: 'Accessible name for the close button and handle.' }, "class": { description: 'Class merged after the kit styles.' }, diff --git a/packages/inkstone/src/cui.css.ts b/packages/inkstone/src/cui.css.ts index b5caeaeb..43f571bc 100644 --- a/packages/inkstone/src/cui.css.ts +++ b/packages/inkstone/src/cui.css.ts @@ -192,7 +192,8 @@ const values = { "rise": "var(--cui-motion-duration-rise)" }, "ease": { - "out": "var(--cui-motion-ease-out)" + "out": "var(--cui-motion-ease-out)", + "drawer": "var(--cui-motion-ease-drawer)" } } } as const; diff --git a/packages/inkstone/src/theme-values.ts b/packages/inkstone/src/theme-values.ts index 82b8b1a7..2d957cf9 100644 --- a/packages/inkstone/src/theme-values.ts +++ b/packages/inkstone/src/theme-values.ts @@ -314,7 +314,8 @@ export const themeValues = { "rise": "400ms" }, "ease": { - "out": "cubic-bezier(0.23, 1, 0.32, 1)" + "out": "cubic-bezier(0.23, 1, 0.32, 1)", + "drawer": "cubic-bezier(0.32, 0.72, 0, 1)" } } } as const; diff --git a/packages/inkstone/tokens/foundation.tokens.json b/packages/inkstone/tokens/foundation.tokens.json index 08f5b26a..f3951a43 100644 --- a/packages/inkstone/tokens/foundation.tokens.json +++ b/packages/inkstone/tokens/foundation.tokens.json @@ -802,6 +802,15 @@ 0.32, 1 ] + }, + "drawer": { + "$type": "cubicBezier", + "$value": [ + 0.32, + 0.72, + 0, + 1 + ] } } }, diff --git a/packages/kit/DESIGN.md b/packages/kit/DESIGN.md index 462c6ab7..39d834b6 100644 --- a/packages/kit/DESIGN.md +++ b/packages/kit/DESIGN.md @@ -250,7 +250,7 @@ If you cannot name the purpose (feedback, origin, state change, avoiding a jump, | ------------------------------ | ---------------------------------- | --------------------------------------- | | `--cui-motion-ease-out` | `cubic-bezier(0.23, 1, 0.32, 1)` | Enter, respond, default | | `--cui-motion-ease-in-out` | `cubic-bezier(0.77, 0, 0.175, 1)` (proposed) | Something moving across the screen | -| `--cui-motion-ease-drawer` | `cubic-bezier(0.32, 0.72, 0, 1)` (proposed) | Sheets and drawers | +| `--cui-motion-ease-drawer` | `cubic-bezier(0.32, 0.72, 0, 1)` | Sheets and drawers entering | | `--cui-motion-duration-fast` | 120ms | Press, switch, colour, exit | | `--cui-motion-duration-normal` | 160ms | Tooltip, small popover | | `--cui-motion-duration-panel` | 200ms | Accordion, popover, content change | @@ -269,7 +269,7 @@ If you cannot name the purpose (feedback, origin, state change, avoiding a jump, | **Collapse to origin** | Closing something that lives on elsewhere | Scale and move into where it can be found again, 200ms ease-out (What's new → nudge) | | **Rise** | Corner card, toast | From the edge, 400ms (`--cui-motion-duration-rise`); leave 200ms. The kit uses its ease-out | | **Reveal** | A surface growing in place | `clip-path`, 260ms ease-out | -| **Slide** | Phone sheet | `translateY(100%)` → 0, 280ms drawer curve; out 150–200ms; tracks the finger 1:1 when dragged | +| **Slide** | Sheet: phone sheet, side sheet | From its edge to 0, 260ms (`slow`) drawer curve; out 200ms (`panel`) ease-out; reverses if reopened mid-exit; tracks the finger 1:1 when dragged; reduced motion fades in place | | **Ring** | Selection ring | `scale(0.92)` → 1 with fade, 200ms | Rules for every movement: @@ -292,6 +292,8 @@ Rules for every movement: The kit's popover, hover card, menu, list popovers and tooltip follow Pop, and its toast follows Rise. Pop uses CSS keyframes. The kit keeps each closing surface mounted until its exit finishes. The rest of the kit's motion is slower than these rules today: buttons press in 200ms `ease`, and the focus ring transitions with `ease-in`. **Proposed:** move them to Press and a 120ms colour change. +The kit sheet follows Slide with transitions, and its scrim fades with it. It stays mounted until its exit ends, and the page under it takes clicks during that exit. Opened or closed from the keyboard, it does not move. + The kit dialog follows Pop with keyframes: in from `scale(0.96)` over 200ms, out toward `scale(0.98)` over 120ms, and its scrim fades with it. Opened or closed from the keyboard, it does not move. Moving it to transitions is still proposed. ## 8. Layout @@ -360,10 +362,11 @@ No border; field fill, radius 12, padding 12; a 68px preview well (radius 8) ove | Popover | Pick a value for one row | None | Moves in, returns to the trigger | | Menu | Choose an action | None | Moves in, returns to the trigger | | Command menu | Find anything by name | None | Trapped, returns on close | -| Sheet | A panel on a phone | None | Trapped | +| Sheet | A panel on a phone; a side sheet for a record's details or form | Scrim when modal | Trapped when modal, returns on close | | Dialog | Settings, or a decision that blocks | Scrim | Trapped, returns on close | - A picker opens anchored to its row, over the panel that holds it: 360px, radius 16, padding 16. +- A side sheet floats 8px in from the top, bottom and its edge of the area it covers, with all corners rounded. Mount it in the content island so it and its scrim cover the island, not the sidebar. Choosing another record while it is open swaps its content in place. At 768px and below it becomes a bottom sheet with the grip. - A dialog is for settings and for blocking decisions, not for confirming something undoable. - A tooltip is one line that names one thing. A description, or more than one fact, goes in a hover card beside its trigger, on the right unless there is no room, wrapped at about 20rem. It opens on click too, so touch works. Never use the `title` attribute. Everything in a hover card is reachable another way. Use the kit `HoverCard`: `right-start` by default, a click or tap opens it at once, Pop motion, and the floating surface. Moving to the next trigger while a card is open moves that card: it slides to the new trigger and resizes to the new content in 200ms ease-out, with no second pop. From the keyboard it swaps in place. Hover cards share one card per page; a `HoverCardGroup` gives a set of triggers their own. A text trigger has a dotted underline in the hint tone that takes the text colour on hover and while open. diff --git a/packages/kit/api/kit.api.md b/packages/kit/api/kit.api.md index 4e204e78..8992740e 100644 --- a/packages/kit/api/kit.api.md +++ b/packages/kit/api/kit.api.md @@ -216,6 +216,7 @@ declare const values: { }; readonly ease: { readonly out: "var(--cui-motion-ease-out)"; + readonly drawer: "var(--cui-motion-ease-drawer)"; }; }; }; @@ -562,6 +563,7 @@ export declare const themeValues: { }; readonly ease: { readonly out: "cubic-bezier(0.23, 1, 0.32, 1)"; + readonly drawer: "cubic-bezier(0.32, 0.72, 0, 1)"; }; }; }; @@ -4786,15 +4788,17 @@ export declare function createSettingsRowProps(props: Accessor & { @@ -4802,7 +4806,10 @@ type SheetOptions = Omit & { title?: JSX.Element; description?: JSX.Element; footer?: JSX.Element; - /** Node the sheet is portaled into. Defaults to `document.body`. */ + /** + * Node the sheet is portaled into. Defaults to `document.body`. Any other node + * is covered instead of the viewport; give it `position: relative`. + */ mount?: HTMLElement; /** Shows the close button in the header. Defaults to true. */ showCloseButton?: boolean; @@ -6144,7 +6151,15 @@ export { sheetParts, type SheetPart, type SheetClasses, type SheetSide, type She export type RootProps = KDialogRootProps & { motion?: SheetMotion; }; +/** + * Kobalte unmounts a closed dialog at once, so the root holds the sheet open + * until its exit transition ends. Opening it again mid-exit reverses the slide. + */ export declare function Root(props: RootProps): JSX.Element; +/** + * With `mount`, the sheet covers that element instead of the viewport. Give the + * element `position: relative` (or any containing block) and a size. + */ export declare function Portal(props: KDialogPortalProps): JSX.Element; export declare function Trigger(props: PolymorphicProps>): JSX.Element; export declare function Overlay(props: PolymorphicProps>): JSX.Element; diff --git a/packages/kit/src/components/Sheet/Sheet.tsx b/packages/kit/src/components/Sheet/Sheet.tsx index 8e9f9b2c..27fa5a3f 100644 --- a/packages/kit/src/components/Sheet/Sheet.tsx +++ b/packages/kit/src/components/Sheet/Sheet.tsx @@ -1,19 +1,22 @@ import { pickProps } from "../../utils/pick-props"; import type { DialogContentProps as KDialogContentProps } from "@kobalte/core/dialog"; -import { Show, omit } from "solid-js"; -import { type JSX } from "@solidjs/web"; +import { createSignal, onCleanup, Show, omit } from "solid-js"; +import { isServer, type JSX } from "@solidjs/web"; import * as S from "../../parts/sheet"; import { mergeClasses } from "../../utils/css"; -/** Only a bottom sheet can be dragged to dismiss. */ -export type SheetPlacement = - | { - /** Edge the sheet is attached to. Defaults to `bottom`. */ - side?: "bottom"; - /** Shows a handle that closes the sheet on a tap or a downward drag. Defaults to false. */ - draggable?: boolean; - } - | { side: "left" | "right"; draggable?: false }; +export type SheetPlacement = { + /** + * Edge the sheet is attached to. Defaults to `bottom`. A `left` or `right` + * sheet floats inset from the edges, and becomes a bottom sheet at 768px and below. + */ + side?: S.SheetSide; + /** + * Shows a handle that closes the sheet on a tap or a downward drag. A side + * sheet shows it only while it is a bottom sheet. Defaults to false. + */ + draggable?: boolean; +}; export type SheetProps = SheetPlacement & SheetOptions; @@ -22,7 +25,10 @@ type SheetOptions = Omit & { title?: JSX.Element; description?: JSX.Element; footer?: JSX.Element; - /** Node the sheet is portaled into. Defaults to `document.body`. */ + /** + * Node the sheet is portaled into. Defaults to `document.body`. Any other node + * is covered instead of the viewport; give it `position: relative`. + */ mount?: HTMLElement; /** Shows the close button in the header. Defaults to true. */ showCloseButton?: boolean; @@ -44,6 +50,17 @@ type SheetOptions = Omit & { >; }; +/** True at 768px and below, where a side sheet becomes a bottom sheet. */ +function createPhoneLayout() { + if (isServer || typeof window.matchMedia !== "function") return () => false; + const query = window.matchMedia("(max-width: 768px)"); + const [phone, setPhone] = createSignal(query.matches); + const onChange = () => setPhone(query.matches); + query.addEventListener("change", onChange); + onCleanup(() => query.removeEventListener("change", onChange)); + return phone; +} + /** * A dialog attached to an edge of the viewport. Modal by default, with a * scrim. A nonmodal sheet has no scrim and leaves the page usable. @@ -52,6 +69,9 @@ export function Sheet(props: SheetProps) { const local = pickProps(props, "children", "title", "description", "footer", "side", "draggable", "mount", "showCloseButton", "closeLabel", "class", "classes", "aria-label", "contentProps"); const root = omit(props, "children", "title", "description", "footer", "side", "draggable", "mount", "showCloseButton", "closeLabel", "class", "classes", "aria-label", "contentProps"); const showCloseButton = () => local.showCloseButton !== false; + const phone = createPhoneLayout(); + // A hidden grip would be the first tabbable, and focus could not move in. + const showHandle = () => local.draggable && ((local.side ?? "bottom") === "bottom" || phone()); return ( @@ -64,7 +84,7 @@ export function Sheet(props: SheetProps) { aria-label={local["aria-label"]} class={mergeClasses(local.class, local.classes?.content)} > - + void; /** Closes without the exit slide, for a sheet a drag already moved off screen. */ closeInPlace: () => void; + /** Registers the content, so the root keeps it mounted through its exit. */ + setExitTarget: (target: { element: HTMLElement; applyMotion: () => boolean } | undefined) => void; }; const SheetContext = createContext(null); -function MotionScope(props: { motion?: SheetMotion; children?: JSX.Element }) { +/** True inside a Portal mounted somewhere other than `document.body`. */ +const ContainedContext = createContext(false); + +/** The exit is a transition on the content's transform or opacity. */ +const isSheetExit = (animation: Animation) => + animation instanceof CSSTransition && + (animation.transitionProperty === "transform" || animation.transitionProperty === "opacity"); + +function MotionScope(props: { + motion?: SheetMotion; + setExitTarget: SheetContextValue["setExitTarget"]; + children?: JSX.Element; +}) { const dialog = useDialogContext(); const [overlay, setOverlay] = createSignal(); let inPlace = false; @@ -54,7 +69,7 @@ function MotionScope(props: { motion?: SheetMotion; children?: JSX.Element }) { dialog.close(); }; return ( - + {props.children} ); @@ -67,20 +82,39 @@ const motionAttribute = () => { export type RootProps = KDialogRootProps & { motion?: SheetMotion }; +/** + * Kobalte unmounts a closed dialog at once, so the root holds the sheet open + * until its exit transition ends. Opening it again mid-exit reverses the slide. + */ export function Root(props: RootProps) { const local = props; - const others = omit(props, "motion", "children"); + const others = omit(props, "motion", "children", "forceMount", "onOpenChange"); + const exit = createPopMotion(props, isSheetExit); onSettled(trackInput); return ( - - {local.children} + + + {local.children} + ); } +/** + * With `mount`, the sheet covers that element instead of the viewport. Give the + * element `position: relative` (or any containing block) and a size. + */ export function Portal(props: KDialogPortalProps) { const context = useDialogContext(); - return ; + const others = omit(props, "children"); + const contained = () => props.mount !== undefined && props.mount !== document.body; + return ( + + + {props.children} + + + ); } export function Trigger( @@ -104,12 +138,17 @@ export function Overlay( const others = omit(local, "class", "ref"); const motion = motionAttribute(); const context = useContext(SheetContext); + const dialog = useDialogContext(); + const contained = useContext(ContainedContext); onCleanup(() => context?.setOverlay(undefined)); return ( context?.setOverlay(element)]} data-cui={sheetParts.overlay} data-motion={motion()} + data-contained={contained ? "" : undefined} + // A closing scrim lets clicks through to the page. + inert={!dialog.isOpen() || undefined} class={mergeClasses(sheetStyles.overlay(), local.class)} {...others} /> @@ -128,15 +167,26 @@ export type ContentProps = KDialogContentProps export function Content(props: PolymorphicProps>) { const allProps = props as PolymorphicProps<"div", ContentProps>; const local = pickProps(allProps, "class", "side"); - const others = omit(allProps, "class", "side", "onOpenAutoFocus", "onCloseAutoFocus", "onInteractOutside", "onFocusOutside", "onPointerDownOutside"); + const others = omit(allProps, "class", "side", "ref", "onOpenAutoFocus", "onCloseAutoFocus", "onInteractOutside", "onFocusOutside", "onPointerDownOutside"); const { layer, props: focus } = createDialogFocus(allProps); const motion = motionAttribute(); + const context = useContext(SheetContext); + const contained = useContext(ContainedContext); return ( + context?.setExitTarget({ element, applyMotion: () => untrack(context.moves) }), + ]} data-cui={sheetParts.content} data-side={local.side ?? "bottom"} data-motion={motion()} + data-contained={contained ? "" : undefined} + // The scrim catches outside clicks. Kobalte's body lock would outlive the + // close and swallow clicks for the whole exit. + disableOutsidePointerEvents={false} class={mergeClasses(styles.content(), local.class)} {...focus} {...others} diff --git a/packages/kit/src/utils/pop-motion.ts b/packages/kit/src/utils/pop-motion.ts index d374dba6..dbe3315f 100644 --- a/packages/kit/src/utils/pop-motion.ts +++ b/packages/kit/src/utils/pop-motion.ts @@ -17,8 +17,18 @@ type MotionTarget = { export const PopMotionContext = createContext<((target: MotionTarget) => void) | null>(null); const popExit = /^cui-motion-(pop|fade)-out$/; -/** Hold Kobalte's portalled content through its CSS exit. Alpha.5 unmounts at once. */ -export function createPopMotion(props: OverlayProps) { +/** The Pop exit keyframes. */ +const isPopExit = (animation: Animation) => + animation instanceof CSSAnimation && popExit.test(animation.animationName); + +/** + * Hold Kobalte's portalled content through its CSS exit. Alpha.5 unmounts at once. + * `isExit` picks the animations that make up the exit; it defaults to Pop's keyframes. + */ +export function createPopMotion( + props: OverlayProps, + isExit: (animation: Animation) => boolean = isPopExit, +) { const [requested, setRequested] = createSignal(untrack(() => props.defaultOpen ?? false)); const [target, setTarget] = createSignal(); const [animate, setAnimate] = createSignal(false); @@ -56,21 +66,23 @@ export function createPopMotion(props: OverlayProps { if (listeners.signal.aborted) return; - const exits = element.getAnimations().filter(animation => - animation instanceof CSSAnimation && popExit.test(animation.animationName), - ); + // A finished exit that fills forwards still shows up in getAnimations(). + const running = () => + element.getAnimations().filter(animation => animation.playState !== "finished" && isExit(animation)); + const exits = running(); if (!exits.length) { finish(); return; } - const onExit = (event: AnimationEvent) => { - if (event.target === element && popExit.test(event.animationName)) { + const onExit = (event: Event) => { + if (event.target === element && !running().length) { clearTimeout(timeout); timeout = setTimeout(finish, 0); } }; - element.addEventListener("animationend", onExit, { signal: listeners.signal }); - element.addEventListener("animationcancel", onExit, { signal: listeners.signal }); + for (const type of ["animationend", "animationcancel", "transitionend", "transitioncancel"]) { + element.addEventListener(type, onExit, { signal: listeners.signal }); + } // The finished promises settle before CSS events. Use them as a fallback // if the page intercepts an event or the animation is replaced. void Promise.allSettled(exits.map(animation => animation.finished)).then(() => { diff --git a/packages/kit/test/sheet-drag.test.tsx b/packages/kit/test/sheet-drag.test.tsx index 8749ce7c..38981156 100644 --- a/packages/kit/test/sheet-drag.test.tsx +++ b/packages/kit/test/sheet-drag.test.tsx @@ -142,20 +142,16 @@ describe("Sheet drag to dismiss", () => { await expectFocus(opener); }); - it("shows the handle only on a draggable bottom sheet", () => { + it("shows the handle only on a draggable sheet", () => { render(() => ( <> )); - expect(screen.getByRole("dialog", { name: "Plain" })).not.toContainElement( - document.querySelector(`[data-cui="${S.sheetParts.handle}"]`), - ); - expect(screen.getByRole("dialog", { name: "Docked" })).toContainElement( - document.querySelector(`[data-cui="${S.sheetParts.handle}"]`), - ); - // @ts-expect-error a side sheet cannot be dragged - void (() => ); + const handle = (name: string) => + screen.getByRole("dialog", { name }).querySelector(`[data-cui="${S.sheetParts.handle}"]`); + expect(handle("Plain")).toBeNull(); + expect(handle("Docked")).not.toBeNull(); }); }); diff --git a/packages/kit/test/sheet-side.test.tsx b/packages/kit/test/sheet-side.test.tsx new file mode 100644 index 00000000..32eb685a --- /dev/null +++ b/packages/kit/test/sheet-side.test.tsx @@ -0,0 +1,50 @@ +import { cleanup, fireEvent, render, screen } from "@solidjs/testing-library"; +import { createSignal } from "solid-js"; +import { page } from "vitest/browser"; +import { Sheet } from "../src/components/Sheet/Sheet"; +import * as S from "../src/parts/sheet"; +import { expectFocusWithin } from "./helpers"; + +afterEach(cleanup); + +function renderSideSheet() { + render(() => { + const [open, setOpen] = createSignal(false); + return ( + <> + + + + + + ); + }); + const opener = screen.getByRole("button", { name: "Open" }); + opener.focus(); + fireEvent.click(opener); + return screen.getByRole("dialog"); +} + +const handle = (sheet: HTMLElement) => sheet.querySelector(`[data-cui="${S.sheetParts.handle}"]`); + +describe("Side sheet", () => { + it("floats inset on a desktop, without a grip, and takes focus", async () => { + await page.viewport(1280, 900); + const sheet = renderSideSheet(); + await expectFocusWithin(sheet); + expect(handle(sheet)).toBeNull(); + const box = sheet.getBoundingClientRect(); + expect(Math.round(window.innerWidth - box.right)).toBe(8); + expect(Math.round(box.top)).toBe(8); + }); + + it("becomes a bottom sheet with a grip on a phone", async () => { + await page.viewport(390, 844); + const sheet = renderSideSheet(); + await expectFocusWithin(sheet); + expect(handle(sheet)).not.toBeNull(); + const box = sheet.getBoundingClientRect(); + expect(Math.round(box.width)).toBe(window.innerWidth); + expect(Math.round(box.bottom)).toBe(window.innerHeight); + }); +}); diff --git a/packages/kit/test/sheet.test.tsx b/packages/kit/test/sheet.test.tsx index 905822ba..b1651024 100644 --- a/packages/kit/test/sheet.test.tsx +++ b/packages/kit/test/sheet.test.tsx @@ -107,6 +107,43 @@ describe("Sheet", () => { host.remove(); }); + it("covers a mount node other than the body instead of the viewport", () => { + const host = document.createElement("section"); + host.style.position = "relative"; + document.body.append(host); + render(() => ); + const sheet = screen.getByRole("dialog"); + const overlay = host.querySelector(`[data-cui="${S.sheetParts.overlay}"]`)!; + expect(getComputedStyle(sheet).position).toBe("absolute"); + expect(getComputedStyle(overlay).position).toBe("absolute"); + host.remove(); + }); + + it("stays until its exit ends, keeps the page clickable meanwhile, and turns around when reopened", async () => { + const opener = renderOpener({ side: "right" }); + fireEvent.pointerDown(opener); + fireEvent.click(opener); + const sheet = screen.getByRole("dialog"); + await new Promise(resolve => setTimeout(resolve, 400)); + + const close = screen.getByRole("button", { name: "close" }); + fireEvent.pointerDown(close); + fireEvent.click(close); + await tick(); + expect(sheet).toBeInTheDocument(); + expect(sheet).not.toHaveAttribute("data-expanded"); + expect(document.body.style.pointerEvents).not.toBe("none"); + + fireEvent.pointerDown(opener); + fireEvent.click(opener); + await tick(); + expect(screen.getByRole("dialog")).toBe(sheet); + expect(sheet).toHaveAttribute("data-expanded"); + + press("Escape"); + await expectSheetDismissed(sheet); + }); + it("moves focus in, keeps it inside while modal, and returns it to the opener", async () => { const opener = renderOpener(); fireEvent.click(opener); diff --git a/packages/storybook/src/stories/Sheet.stories.tsx b/packages/storybook/src/stories/Sheet.stories.tsx index df45ad9b..2dac8251 100644 --- a/packages/storybook/src/stories/Sheet.stories.tsx +++ b/packages/storybook/src/stories/Sheet.stories.tsx @@ -1,6 +1,6 @@ import type { Meta, StoryObj } from "storybook-solidjs-vite"; -import { Button, Sheet, TextField } from "@codeui/solid"; +import { Button, Sheet, TextArea, TextField } from "@codeui/solid"; import * as S from "@codeui/solid/sheet/parts"; import { createSignal, For, Show } from "solid-js"; import { DocsItemsContainer } from "./components/Section.jsx"; @@ -137,7 +137,7 @@ export const DockedParts: Story = { @@ -152,3 +152,144 @@ export const DockedParts: Story = { ); }, }; + +type Automation = { id: string; name: string; schedule: string; prompt: string }; + +const automations: Automation[] = [ + { id: "digest", name: "Morning digest", schedule: "Weekdays at 09:00", prompt: "Summarise yesterday's merged pull requests." }, + { id: "triage", name: "Issue triage", schedule: "Every hour", prompt: "Label new issues and ask for missing steps." }, + { id: "deps", name: "Dependency check", schedule: "Mondays at 08:00", prompt: "List outdated packages with a breaking change." }, +]; + +/** + * A right sheet mounted in the content island, as on CodeLoom's Automations + * page. It covers the island, not the sidebar. Choosing another row, or Edit, + * swaps what the open sheet shows without closing it. At 768px and below it + * becomes a bottom sheet with a grip. + */ +function AutomationsDrawer(props: { modal: boolean }) { + const [island, setIsland] = createSignal(); + const [open, setOpen] = createSignal(false); + const [view, setView] = createSignal<{ kind: "detail" | "form"; automation?: Automation }>({ kind: "form" }); + const show = (next: { kind: "detail" | "form"; automation?: Automation }) => { + setView(next); + setOpen(true); + }; + return ( +
+ + +
+
+

Automations

+ +
+
    + + {automation => ( +
  • + +
  • + )} +
    +
+ + {mount => ( + { + if ((event.target as Element | null)?.closest?.("[data-row]")) event.preventDefault(); + }, + }} + footer={ + <> + + setOpen(false)}> + Save + + } + > + + + + } + > + +
Schedule
+
{view().automation?.schedule}
+
Prompt
+
{view().automation?.prompt}
+ + } + > +
+ + +