oneslash-design-system 2.29.0 → 2.30.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (40) hide show
  1. package/README.md +1 -1
  2. package/dist/cases/agent-permissions/levels.jsx +3 -1
  3. package/dist/cases/agent-permissions/per-tool.jsx +5 -3
  4. package/dist/cases/agent-permissions.md +10 -5
  5. package/dist/cases/bulk-actions/list.jsx +2 -5
  6. package/dist/cases/bulk-actions/paged-table.jsx +3 -6
  7. package/dist/cases/bulk-actions.md +8 -14
  8. package/dist/cases/product-demo/scripted.d.ts +1 -3
  9. package/dist/cases/product-demo/scripted.jsx +14 -10
  10. package/dist/cases/product-demo.md +15 -10
  11. package/dist/cases.json +10 -7
  12. package/dist/components/checkBox.d.ts +3 -2
  13. package/dist/components/checkBox.jsx +18 -7
  14. package/dist/components/diff.d.ts +4 -1
  15. package/dist/components/diff.jsx +8 -1
  16. package/dist/components/segmentedControl.d.ts +3 -1
  17. package/dist/components/segmentedControl.jsx +8 -6
  18. package/dist/components/slidingIndicator.d.ts +5 -2
  19. package/dist/components/slidingIndicator.jsx +9 -3
  20. package/dist/components/tableContainer.d.ts +1 -1
  21. package/dist/components/tableContainer.jsx +2 -2
  22. package/dist/components/timeStamp.d.ts +3 -1
  23. package/dist/components/timeStamp.jsx +4 -2
  24. package/dist/components/useReducedMotion.d.ts +6 -0
  25. package/dist/components/useReducedMotion.js +19 -0
  26. package/dist/index.d.ts +1 -0
  27. package/dist/index.js +1 -0
  28. package/dist/stories/Checkbox.stories.d.ts +1 -0
  29. package/dist/stories/Checkbox.stories.jsx +21 -1
  30. package/dist/stories/Diff.stories.d.ts +1 -0
  31. package/dist/stories/Diff.stories.jsx +5 -0
  32. package/dist/stories/SegmentedControl.stories.d.ts +1 -0
  33. package/dist/stories/SegmentedControl.stories.jsx +6 -0
  34. package/dist/stories/Table.stories.d.ts +1 -0
  35. package/dist/stories/Table.stories.jsx +25 -0
  36. package/dist/stories/TimeStamp.stories.d.ts +1 -0
  37. package/dist/stories/TimeStamp.stories.jsx +13 -0
  38. package/package.json +5 -1
  39. package/dist/stories/ProductDemo.probe.stories.d.ts +0 -6
  40. package/dist/stories/ProductDemo.probe.stories.jsx +0 -12
package/dist/cases.json CHANGED
@@ -756,8 +756,9 @@
756
756
  "id": "levels",
757
757
  "title": "One level",
758
758
  "useWhen": "One setting for how much the agent does without asking is enough.",
759
- "source": "'use client';\nimport { useEffect, useRef, useState } from 'react';\nimport Heading from 'oneslash-design-system/components/heading';\nimport Paragraph from 'oneslash-design-system/components/paragraph';\nimport FormField from 'oneslash-design-system/components/formField';\nimport RadioGroup from 'oneslash-design-system/components/radioGroup';\nimport SettingsSection from 'oneslash-design-system/components/settingsSection';\nimport { Center, Stack } from 'oneslash-design-system/components/layout';\n\n// Three levels, each named for what the agent does at it, with an example. No level lets it do a risky action alone.\nconst levels = [\n { value: 'suggest', label: 'Only suggest changes', secondLabel: 'It drafts a fix and proposes it in the thread. It changes nothing itself.' },\n { value: 'ask-every', label: 'Ask before every change', secondLabel: 'It asks before every change, even to its own drafts.' },\n { value: 'ask-risky', label: 'Ask before risky changes', secondLabel: 'It drafts and checks alone. Every change to shared work, such as a page edit, a pull request or a deploy, waits for a yes.' },\n];\n\n// A real app reads `canChange` from the person's role. Only an admin can change how the agent works.\n// The example shows an admin's view. A real app passes `canChange` from the person's role.\nexport default function AgentPermissionsLevels({ canChange = true }: { canChange?: boolean } = {}) {\n const [level, setLevel] = useState('ask-every');\n const [saving, setSaving] = useState(false);\n const timer = useRef<ReturnType<typeof setTimeout>>();\n\n // Stops the request if the example goes away before it ends.\n useEffect(() => () => clearTimeout(timer.current), []);\n\n // The choice stands alone, so it saves as soon as it is made. Nothing shows when it works.\n // While the request runs the group is disabled. A real app puts the old level back if the save fails,\n // and says why in the FormField's error line: 'Could not save. Try again.'\n function choose(next: string) {\n if (saving || next === level) return;\n setLevel(next);\n setSaving(true);\n // Stands in for the request to the server.\n timer.current = setTimeout(() => setSaving(false), 900);\n }\n\n return (\n <Center width=\"page\">\n <Stack gap=\"xlarge\">\n <Stack gap=\"small\">\n <Heading level={1} size=\"h5\">Agent</Heading>\n <Paragraph tone=\"secondary\" size=\"body2\" measure=\"none\">How Acme Agent works for everyone in this workspace.</Paragraph>\n {!canChange && <Paragraph tone=\"secondary\" size=\"body2\" measure=\"none\">Only admins can change these settings. Your admin is Dana Lee.</Paragraph>}\n </Stack>\n <SettingsSection title=\"What Acme Agent does alone\" description=\"Your choice saves as soon as you make it.\">\n <FormField id=\"agent-permissions-levels-level\" label=\"Level\" help=\"Risky changes are any change to shared work, such as a page edit or a pull request, and messages to people outside Acme, deploys and deletes. They wait for a yes at every level.\">\n {(f) => (\n <RadioGroup\n id={f.id}\n aria-describedby={f['aria-describedby']}\n aria-label=\"Level\"\n options={levels}\n selectedValue={level}\n disabled={!canChange || saving}\n onChange={choose}\n />\n )}\n </FormField>\n </SettingsSection>\n </Stack>\n </Center>\n );\n}\n",
759
+ "source": "'use client';\nimport { useEffect, useRef, useState } from 'react';\nimport Heading from 'oneslash-design-system/components/heading';\nimport Alert from 'oneslash-design-system/components/alert';\nimport Paragraph from 'oneslash-design-system/components/paragraph';\nimport FormField from 'oneslash-design-system/components/formField';\nimport RadioGroup from 'oneslash-design-system/components/radioGroup';\nimport SettingsSection from 'oneslash-design-system/components/settingsSection';\nimport { Center, Stack } from 'oneslash-design-system/components/layout';\n\n// Three levels, each named for what the agent does at it, with an example. No level lets it do a risky action alone.\nconst levels = [\n { value: 'suggest', label: 'Only suggest changes', secondLabel: 'It drafts a fix and proposes it in the thread. It changes nothing itself.' },\n { value: 'ask-every', label: 'Ask before every change', secondLabel: 'It asks before every change, even to its own drafts.' },\n { value: 'ask-risky', label: 'Ask before risky changes', secondLabel: 'It drafts and checks alone. Every change to shared work, such as a page edit, a pull request or a deploy, waits for a yes.' },\n];\n\n// A real app reads `canChange` from the person's role. Only an admin can change how the agent works.\n// The example shows an admin's view. A real app passes `canChange` from the person's role.\nexport default function AgentPermissionsLevels({ canChange = true }: { canChange?: boolean } = {}) {\n const [level, setLevel] = useState('ask-every');\n const [saving, setSaving] = useState(false);\n const timer = useRef<ReturnType<typeof setTimeout>>();\n\n // Stops the request if the example goes away before it ends.\n useEffect(() => () => clearTimeout(timer.current), []);\n\n // The choice stands alone, so it saves as soon as it is made. Nothing shows when it works.\n // While the request runs the group is disabled. A real app puts the old level back if the save fails,\n // and says why in the FormField's error line: 'Could not save. Try again.'\n function choose(next: string) {\n if (saving || next === level) return;\n setLevel(next);\n setSaving(true);\n // Stands in for the request to the server.\n timer.current = setTimeout(() => setSaving(false), 900);\n }\n\n return (\n <Center width=\"page\">\n <Stack gap=\"xlarge\">\n <Stack gap=\"small\">\n <Heading level={1} size=\"h5\">Agent</Heading>\n <Paragraph tone=\"secondary\" size=\"body2\" measure=\"none\">How Acme Agent works for everyone in this workspace.</Paragraph>\n </Stack>\n {/* One line at the top says why nothing can be changed, and who can. */}\n {!canChange && <Alert type=\"info\" variant=\"inline\" message=\"Only admins can change these settings. Your admin is Dana Lee.\" autoDismiss={false} />}\n <SettingsSection title=\"What Acme Agent does alone\" description=\"Your choice saves as soon as you make it.\">\n <FormField id=\"agent-permissions-levels-level\" label=\"Level\" help=\"Risky changes are any change to shared work, such as a page edit or a pull request, and messages to people outside Acme, deploys and deletes. They wait for a yes at every level.\">\n {(f) => (\n <RadioGroup\n id={f.id}\n aria-describedby={f['aria-describedby']}\n aria-label=\"Level\"\n options={levels}\n selectedValue={level}\n disabled={!canChange || saving}\n onChange={choose}\n />\n )}\n </FormField>\n </SettingsSection>\n </Stack>\n </Center>\n );\n}\n",
760
760
  "uses": [
761
+ "Alert",
761
762
  "Center",
762
763
  "FormField",
763
764
  "Heading",
@@ -771,8 +772,9 @@
771
772
  "id": "per-tool",
772
773
  "title": "Each tool",
773
774
  "useWhen": "An admin sets each tool or action on its own.",
774
- "source": "'use client';\nimport { useEffect, useRef, useState } from 'react';\nimport Toaster, { toast, dismissToast } from 'oneslash-design-system/components/toaster';\nimport Heading from 'oneslash-design-system/components/heading';\nimport Paragraph from 'oneslash-design-system/components/paragraph';\nimport SegmentedControl from 'oneslash-design-system/components/segmentedControl';\nimport SettingsSection from 'oneslash-design-system/components/settingsSection';\nimport TableContainer from 'oneslash-design-system/components/tableContainer';\nimport TableHeader from 'oneslash-design-system/components/tableHeader';\nimport TableHeaderCell from 'oneslash-design-system/components/tableHeaderCell';\nimport TableRow from 'oneslash-design-system/components/tableRow';\nimport TableCell from 'oneslash-design-system/components/tableCell';\nimport EmptyBox from 'oneslash-design-system/components/emptyBox';\nimport Button from 'oneslash-design-system/components/button';\nimport { Center, Cluster, Stack } from 'oneslash-design-system/components/layout';\n\ntype Focusable = HTMLButtonElement | HTMLAnchorElement | null;\ntype Setting = 'allow' | 'ask' | 'never';\n\ntype Tool = { id: string; name: string; does: string; risky?: string };\n\nconst tools: Tool[] = [\n { id: 'read', name: 'Read pages and files', does: 'Reads the workspace to answer and to plan.' },\n { id: 'post', name: 'Post in threads', does: 'Posts replies and updates in Acme threads.' },\n { id: 'edit', name: 'Edit pages', does: 'Changes the text of a page.', risky: 'Risky: it changes shared work, so it cannot be set to Allow.' },\n { id: 'pull', name: 'Open pull requests', does: 'Proposes code changes for review.', risky: 'Risky: it changes shared work, so it cannot be set to Allow.' },\n { id: 'deploy', name: 'Deploy to production', does: 'Puts a change live.', risky: 'Risky: it changes what customers see, so it cannot be set to Allow.' },\n { id: 'delete', name: 'Delete files', does: 'Removes files from the workspace.', risky: 'Risky: a deleted file cannot be brought back, so it cannot be set to Allow.' },\n];\n\nconst allOptions = [\n { value: 'allow', label: 'Allow' },\n { value: 'ask', label: 'Ask' },\n { value: 'never', label: 'Never' },\n];\n// A risky tool offers no 'Allow'.\nconst riskyOptions = allOptions.filter((o) => o.value !== 'allow');\n\ntype Client = { id: string; name: string; connected: string };\n\nconst firstClients: Client[] = [\n { id: 'cli', name: 'Acme CLI', connected: 'Connected by Ben Carter on Oct 3, 2026' },\n { id: 'slack', name: 'Acme for Slack', connected: 'Connected by Dana Lee on Aug 19, 2026' },\n { id: 'reports', name: 'Reporting script', connected: 'Connected by Omar Reyes on Nov 2, 2026' },\n];\n\n// A real app reads `canChange` from the person's role. Only an admin can change the tools.\n// The example shows an admin's view. A real app passes `canChange` from the person's role.\nexport default function AgentPermissionsPerTool({ canChange = true }: { canChange?: boolean } = {}) {\n const [settings, setSettings] = useState<Record<string, Setting>>({ read: 'allow', post: 'allow', edit: 'ask', pull: 'ask', deploy: 'ask', delete: 'never' });\n const [savingTool, setSavingTool] = useState<string | null>(null);\n const [clients, setClients] = useState(firstClients);\n const [confirming, setConfirming] = useState<string | null>(null);\n const [revoking, setRevoking] = useState<string | null>(null);\n const timers = useRef<ReturnType<typeof setTimeout>[]>([]);\n const toastIds = useRef<string[]>([]);\n const cancelRevoke = useRef<Focusable>(null);\n const guideButton = useRef<Focusable>(null);\n // Each row's Revoke button by client id, so focus can move to one when the button that had it is gone.\n const revokeButtons = useRef<Record<string, Focusable>>({});\n // Where focus goes after the next render, once the element it goes to is on screen.\n const focusNext = useRef<() => void>();\n\n // On unmount it stops every request and closes every toast it opened.\n useEffect(() => () => {\n timers.current.forEach(clearTimeout);\n toastIds.current.forEach((id) => dismissToast(id));\n toastIds.current = [];\n }, []);\n\n useEffect(() => {\n const move = focusNext.current;\n focusNext.current = undefined;\n move?.();\n });\n\n // Stands in for the request to the server.\n function later(callback: () => void, ms: number) {\n timers.current.push(setTimeout(callback, ms));\n }\n\n // Each row's choice stands alone, so it saves as soon as it is made, and shows nothing when it works.\n // SegmentedControl cannot be disabled, so a press on a row that is still saving does nothing.\n function choose(tool: Tool, next: string) {\n if (!canChange || savingTool === tool.id || next === settings[tool.id]) return;\n setSettings((current) => ({ ...current, [tool.id]: next as Setting }));\n setSavingTool(tool.id);\n later(() => setSavingTool((id) => (id === tool.id ? null : id)), 900);\n }\n\n // The confirm opens in the row, with focus on 'Cancel'.\n function askToRevoke(c: Client) {\n setConfirming(c.id);\n focusNext.current = () => cancelRevoke.current?.focus();\n }\n\n // 'Cancel' goes away with the confirm, so focus goes back to the row's Revoke button.\n function keepClient(c: Client) {\n if (revoking) return;\n setConfirming(null);\n focusNext.current = () => revokeButtons.current[c.id]?.focus();\n }\n\n function revoke(c: Client) {\n if (revoking) return;\n const at = clients.findIndex((x) => x.id === c.id);\n const neighbor = clients[at + 1] ?? clients[at - 1];\n setRevoking(c.id);\n later(() => {\n setRevoking(null);\n setConfirming(null);\n setClients((list) => list.filter((x) => x.id !== c.id));\n // The row is gone: focus goes to the next row's Revoke, or the one before it when it was the last.\n // With no client left, it goes to the guide Button in the empty list.\n focusNext.current = () => (neighbor ? revokeButtons.current[neighbor.id] : guideButton.current)?.focus();\n toastIds.current.push(toast({ type: 'success', message: `${c.name} revoked.` }));\n }, 1200);\n }\n\n return (\n <Center width=\"page\">\n {/* A real app mounts one Toaster near its root. */}\n <Toaster />\n <Stack gap=\"xlarge\">\n <Stack gap=\"small\">\n <Heading level={1} size=\"h5\">Agent tools</Heading>\n <Paragraph tone=\"secondary\" size=\"body2\" measure=\"none\">What Acme Agent may do in this workspace, for everyone.</Paragraph>\n {!canChange && <Paragraph tone=\"secondary\" size=\"body2\" measure=\"none\">Only admins can change these settings. Your admin is Dana Lee.</Paragraph>}\n </Stack>\n\n <SettingsSection title=\"Tools\" description=\"Each choice saves as soon as you make it. Ask means Acme Agent asks before each use.\">\n <TableContainer>\n <TableHeader>\n <TableRow>\n <TableHeaderCell>Tool</TableHeaderCell>\n <TableHeaderCell width=\"184px\">Setting</TableHeaderCell>\n </TableRow>\n </TableHeader>\n {tools.map((t) => (\n <TableRow key={t.id}>\n <TableCell>\n <Stack gap=\"small\">\n {t.name}\n <Paragraph size=\"body2\" tone=\"secondary\" measure=\"none\">{t.risky ?? t.does}</Paragraph>\n </Stack>\n </TableCell>\n <TableCell width=\"184px\">\n <SegmentedControl\n size=\"small\"\n aria-label={t.name}\n options={t.risky ? riskyOptions : allOptions}\n value={settings[t.id]}\n onChange={(next) => choose(t, next)}\n />\n </TableCell>\n </TableRow>\n ))}\n </TableContainer>\n </SettingsSection>\n\n <SettingsSection title=\"Connected apps\" description=\"Apps that use Acme Agent from outside Acme. They can use the tools above.\">\n {clients.length > 0 ? (\n <TableContainer>\n {clients.map((c) => (\n <TableRow key={c.id}>\n <TableCell>\n <Stack gap=\"small\">\n {c.name}\n <Paragraph size=\"body2\" tone=\"secondary\" measure=\"none\">{confirming === c.id ? `Revoke ${c.name}? It stops working until someone connects it again.` : c.connected}</Paragraph>\n </Stack>\n </TableCell>\n {/* A fixed last column keeps every row's Buttons in one place, so they do not jump when they change. */}\n <TableCell width=\"168px\" align=\"right\">\n {confirming === c.id ? (\n <Cluster gap=\"small\" justify=\"end\">\n <Button ref={cancelRevoke} size=\"small\" type=\"tertiary\" state={revoking ? 'disabled' : 'enabled'} label=\"Cancel\" aria-label={`Cancel revoking ${c.name}`} onClickButton={() => keepClient(c)} />\n <Button size=\"small\" type=\"primary\" color=\"danger\" state=\"enabled\" label=\"Revoke\" aria-label={`Revoke ${c.name}`} loading={revoking === c.id} onClickButton={() => revoke(c)} />\n </Cluster>\n ) : (\n canChange && (\n <Cluster justify=\"end\">\n <Button ref={(el) => { revokeButtons.current[c.id] = el; }} size=\"small\" type=\"tertiary\" state={revoking ? 'disabled' : 'enabled'} label=\"Revoke\" aria-label={`Revoke ${c.name}`} onClickButton={() => askToRevoke(c)} />\n </Cluster>\n )\n )}\n </TableCell>\n </TableRow>\n ))}\n </TableContainer>\n ) : (\n <EmptyBox\n size=\"small\"\n icon=\"Plug\"\n text=\"No connected apps\"\n secondText=\"Apps you connect to Acme Agent appear here.\"\n action={<Button ref={guideButton} size=\"small\" type=\"secondary\" state=\"enabled\" label=\"Read the Setup Guide\" href=\"/docs/agent/clients\" />}\n />\n )}\n </SettingsSection>\n </Stack>\n </Center>\n );\n}\n",
775
+ "source": "'use client';\nimport { useEffect, useRef, useState } from 'react';\nimport Toaster, { toast, dismissToast } from 'oneslash-design-system/components/toaster';\nimport Heading from 'oneslash-design-system/components/heading';\nimport Alert from 'oneslash-design-system/components/alert';\nimport Paragraph from 'oneslash-design-system/components/paragraph';\nimport SegmentedControl from 'oneslash-design-system/components/segmentedControl';\nimport SettingsSection from 'oneslash-design-system/components/settingsSection';\nimport TableContainer from 'oneslash-design-system/components/tableContainer';\nimport TableHeader from 'oneslash-design-system/components/tableHeader';\nimport TableHeaderCell from 'oneslash-design-system/components/tableHeaderCell';\nimport TableRow from 'oneslash-design-system/components/tableRow';\nimport TableCell from 'oneslash-design-system/components/tableCell';\nimport EmptyBox from 'oneslash-design-system/components/emptyBox';\nimport Button from 'oneslash-design-system/components/button';\nimport { Center, Cluster, Stack } from 'oneslash-design-system/components/layout';\n\ntype Focusable = HTMLButtonElement | HTMLAnchorElement | null;\ntype Setting = 'allow' | 'ask' | 'never';\n\ntype Tool = { id: string; name: string; does: string; risky?: string };\n\nconst tools: Tool[] = [\n { id: 'read', name: 'Read pages and files', does: 'Reads the workspace to answer and to plan.' },\n { id: 'post', name: 'Post in threads', does: 'Posts replies and updates in Acme threads.' },\n { id: 'edit', name: 'Edit pages', does: 'Changes the text of a page.', risky: 'Risky: it changes shared work, so it cannot be set to Allow.' },\n { id: 'pull', name: 'Open pull requests', does: 'Proposes code changes for review.', risky: 'Risky: it changes shared work, so it cannot be set to Allow.' },\n { id: 'deploy', name: 'Deploy to production', does: 'Puts a change live.', risky: 'Risky: it changes what customers see, so it cannot be set to Allow.' },\n { id: 'delete', name: 'Delete files', does: 'Removes files from the workspace.', risky: 'Risky: a deleted file cannot be brought back, so it cannot be set to Allow.' },\n];\n\nconst allOptions = [\n { value: 'allow', label: 'Allow' },\n { value: 'ask', label: 'Ask' },\n { value: 'never', label: 'Never' },\n];\n// A risky tool offers no 'Allow'.\nconst riskyOptions = allOptions.filter((o) => o.value !== 'allow');\n\ntype Client = { id: string; name: string; connected: string };\n\nconst firstClients: Client[] = [\n { id: 'cli', name: 'Acme CLI', connected: 'Connected by Ben Carter on Oct 3, 2026' },\n { id: 'slack', name: 'Acme for Slack', connected: 'Connected by Dana Lee on Aug 19, 2026' },\n { id: 'reports', name: 'Reporting script', connected: 'Connected by Omar Reyes on Nov 2, 2026' },\n];\n\n// A real app reads `canChange` from the person's role. Only an admin can change the tools.\n// The example shows an admin's view. A real app passes `canChange` from the person's role.\nexport default function AgentPermissionsPerTool({ canChange = true }: { canChange?: boolean } = {}) {\n const [settings, setSettings] = useState<Record<string, Setting>>({ read: 'allow', post: 'allow', edit: 'ask', pull: 'ask', deploy: 'ask', delete: 'never' });\n const [savingTool, setSavingTool] = useState<string | null>(null);\n const [clients, setClients] = useState(firstClients);\n const [confirming, setConfirming] = useState<string | null>(null);\n const [revoking, setRevoking] = useState<string | null>(null);\n const timers = useRef<ReturnType<typeof setTimeout>[]>([]);\n const toastIds = useRef<string[]>([]);\n const cancelRevoke = useRef<Focusable>(null);\n const guideButton = useRef<Focusable>(null);\n // Each row's Revoke button by client id, so focus can move to one when the button that had it is gone.\n const revokeButtons = useRef<Record<string, Focusable>>({});\n // Where focus goes after the next render, once the element it goes to is on screen.\n const focusNext = useRef<() => void>();\n\n // On unmount it stops every request and closes every toast it opened.\n useEffect(() => () => {\n timers.current.forEach(clearTimeout);\n toastIds.current.forEach((id) => dismissToast(id));\n toastIds.current = [];\n }, []);\n\n useEffect(() => {\n const move = focusNext.current;\n focusNext.current = undefined;\n move?.();\n });\n\n // Stands in for the request to the server.\n function later(callback: () => void, ms: number) {\n timers.current.push(setTimeout(callback, ms));\n }\n\n // Each row's choice stands alone, so it saves as soon as it is made, and shows nothing when it works.\n // A press on a row that is still saving does nothing. The row stays enabled, so focus stays on it.\n function choose(tool: Tool, next: string) {\n if (!canChange || savingTool === tool.id || next === settings[tool.id]) return;\n setSettings((current) => ({ ...current, [tool.id]: next as Setting }));\n setSavingTool(tool.id);\n later(() => setSavingTool((id) => (id === tool.id ? null : id)), 900);\n }\n\n // The confirm opens in the row, with focus on 'Cancel'.\n function askToRevoke(c: Client) {\n setConfirming(c.id);\n focusNext.current = () => cancelRevoke.current?.focus();\n }\n\n // 'Cancel' goes away with the confirm, so focus goes back to the row's Revoke button.\n function keepClient(c: Client) {\n if (revoking) return;\n setConfirming(null);\n focusNext.current = () => revokeButtons.current[c.id]?.focus();\n }\n\n function revoke(c: Client) {\n if (revoking) return;\n const at = clients.findIndex((x) => x.id === c.id);\n const neighbor = clients[at + 1] ?? clients[at - 1];\n setRevoking(c.id);\n later(() => {\n setRevoking(null);\n setConfirming(null);\n setClients((list) => list.filter((x) => x.id !== c.id));\n // The row is gone: focus goes to the next row's Revoke, or the one before it when it was the last.\n // With no client left, it goes to the guide Button in the empty list.\n focusNext.current = () => (neighbor ? revokeButtons.current[neighbor.id] : guideButton.current)?.focus();\n toastIds.current.push(toast({ type: 'success', message: `${c.name} revoked.` }));\n }, 1200);\n }\n\n return (\n <Center width=\"page\">\n {/* A real app mounts one Toaster near its root. */}\n <Toaster />\n <Stack gap=\"xlarge\">\n <Stack gap=\"small\">\n <Heading level={1} size=\"h5\">Agent tools</Heading>\n <Paragraph tone=\"secondary\" size=\"body2\" measure=\"none\">What Acme Agent may do in this workspace, for everyone.</Paragraph>\n </Stack>\n {/* One line at the top says why nothing can be changed, and who can. */}\n {!canChange && <Alert type=\"info\" variant=\"inline\" message=\"Only admins can change these settings. Your admin is Dana Lee.\" autoDismiss={false} />}\n\n <SettingsSection title=\"Tools\" description=\"Each choice saves as soon as you make it. Ask means Acme Agent asks before each use.\">\n <TableContainer>\n <TableHeader>\n <TableRow>\n <TableHeaderCell>Tool</TableHeaderCell>\n <TableHeaderCell width=\"184px\">Setting</TableHeaderCell>\n </TableRow>\n </TableHeader>\n {tools.map((t) => (\n <TableRow key={t.id}>\n <TableCell>\n <Stack gap=\"small\">\n {t.name}\n <Paragraph size=\"body2\" tone=\"secondary\" measure=\"none\">{t.risky ?? t.does}</Paragraph>\n </Stack>\n </TableCell>\n <TableCell width=\"184px\">\n <SegmentedControl\n size=\"small\"\n aria-label={t.name}\n options={t.risky ? riskyOptions : allOptions}\n value={settings[t.id]}\n disabled={!canChange}\n onChange={(next) => choose(t, next)}\n />\n </TableCell>\n </TableRow>\n ))}\n </TableContainer>\n </SettingsSection>\n\n <SettingsSection title=\"Connected apps\" description=\"Apps that use Acme Agent from outside Acme. They can use the tools above.\">\n {clients.length > 0 ? (\n <TableContainer>\n {clients.map((c) => (\n <TableRow key={c.id}>\n <TableCell>\n <Stack gap=\"small\">\n {c.name}\n <Paragraph size=\"body2\" tone=\"secondary\" measure=\"none\">{confirming === c.id ? `Revoke ${c.name}? It stops working until someone connects it again.` : c.connected}</Paragraph>\n </Stack>\n </TableCell>\n {/* A fixed last column keeps every row's Buttons in one place, so they do not jump when they change. */}\n <TableCell width=\"168px\" align=\"right\">\n {confirming === c.id ? (\n <Cluster gap=\"small\" justify=\"end\">\n <Button ref={cancelRevoke} size=\"small\" type=\"tertiary\" state={revoking ? 'disabled' : 'enabled'} label=\"Cancel\" aria-label={`Cancel revoking ${c.name}`} onClickButton={() => keepClient(c)} />\n <Button size=\"small\" type=\"primary\" color=\"danger\" state=\"enabled\" label=\"Revoke\" aria-label={`Revoke ${c.name}`} loading={revoking === c.id} onClickButton={() => revoke(c)} />\n </Cluster>\n ) : (\n canChange && (\n <Cluster justify=\"end\">\n <Button ref={(el) => { revokeButtons.current[c.id] = el; }} size=\"small\" type=\"tertiary\" state={revoking ? 'disabled' : 'enabled'} label=\"Revoke\" aria-label={`Revoke ${c.name}`} onClickButton={() => askToRevoke(c)} />\n </Cluster>\n )\n )}\n </TableCell>\n </TableRow>\n ))}\n </TableContainer>\n ) : (\n <EmptyBox\n size=\"small\"\n icon=\"Plug\"\n text=\"No connected apps\"\n secondText=\"Apps you connect to Acme Agent appear here.\"\n action={<Button ref={guideButton} size=\"small\" type=\"secondary\" state=\"enabled\" label=\"Read the Setup Guide\" href=\"/docs/agent/clients\" />}\n />\n )}\n </SettingsSection>\n </Stack>\n </Center>\n );\n}\n",
775
776
  "uses": [
777
+ "Alert",
776
778
  "Button",
777
779
  "Center",
778
780
  "Cluster",
@@ -1873,7 +1875,7 @@
1873
1875
  "Give the count `role=\"status\"` and keep it on the page, so a screen reader hears each new count once.",
1874
1876
  "Name the More menu for the rows it acts on: 'More actions for 3 tasks'. Follow the case 'More menu'.",
1875
1877
  "Follow the case 'Data table page' for a table over many pages. The header Checkbox picks the rows of the page shown.",
1876
- "Offer 'Select All 240' as a text Button in the bar of a paged table, until every row is picked. Focus then goes to 'Clear Selection'.",
1878
+ "Offer 'Select All 240' as a tertiary Button in the bar of a paged table, until every row is picked. Focus then goes to 'Clear Selection'.",
1877
1879
  "Keep the picked rows when the person changes page, sorts or comes back.",
1878
1880
  "Confirm a delete in a small Modal, as the case 'Delete confirm' does, titled with the count: 'Delete 3 Invoices'.",
1879
1881
  "Move focus to the header Checkbox after 'Clear Selection' and after a delete, because the bar and its Buttons are gone.",
@@ -1894,7 +1896,7 @@
1894
1896
  "id": "list",
1895
1897
  "title": "Ticks on one page",
1896
1898
  "useWhen": "A list whose rows all fit on one page, such as the tasks of a project.",
1897
- "source": "'use client';\nimport { useEffect, useRef, useState } from 'react';\nimport Toaster, { toast, dismissToast } from 'oneslash-design-system/components/toaster';\nimport Heading from 'oneslash-design-system/components/heading';\nimport Paragraph from 'oneslash-design-system/components/paragraph';\nimport Checkbox from 'oneslash-design-system/components/checkBox';\nimport Button from 'oneslash-design-system/components/button';\nimport IconButton from 'oneslash-design-system/components/iconButton';\nimport Tooltip from 'oneslash-design-system/components/tooltip';\nimport Popover from 'oneslash-design-system/components/popover';\nimport Menu from 'oneslash-design-system/components/menu';\nimport MenuItem from 'oneslash-design-system/components/menuItem';\nimport Modal from 'oneslash-design-system/components/modal';\nimport Tag from 'oneslash-design-system/components/tag';\nimport EmptyBox from 'oneslash-design-system/components/emptyBox';\nimport TableContainer from 'oneslash-design-system/components/tableContainer';\nimport TableHeader from 'oneslash-design-system/components/tableHeader';\nimport TableHeaderCell from 'oneslash-design-system/components/tableHeaderCell';\nimport TableRow from 'oneslash-design-system/components/tableRow';\nimport TableCell from 'oneslash-design-system/components/tableCell';\nimport { Center, Cluster, Stack } from 'oneslash-design-system/components/layout';\n\ntype Task = { id: string; title: string; assignee: string | null; done: boolean };\n\n// A real app reads this from the session.\nconst me = 'Dana Lee';\n\n// A real app reads these from the server. They all fit on one page.\nconst firstTasks: Task[] = [\n { id: 't1', title: 'Write the launch email', assignee: 'Ben Carter', done: false },\n { id: 't2', title: 'Update the pricing page', assignee: 'Dana Lee', done: false },\n { id: 't3', title: 'Check the plan table on a phone', assignee: 'Omar Reyes', done: false },\n { id: 't4', title: 'Send the press kit', assignee: 'Mia Park', done: true },\n { id: 't5', title: 'Book the launch call', assignee: null, done: false },\n { id: 't6', title: 'Review the help article', assignee: 'Ben Carter', done: false },\n { id: 't7', title: 'Record the demo video', assignee: 'Omar Reyes', done: false },\n { id: 't8', title: 'Translate the FAQ', assignee: null, done: false },\n];\n\nconst plural = (n: number) => `${n} ${n === 1 ? 'task' : 'tasks'}`;\n\n// Names up to three tasks, then counts the rest: 'A', 'B' and 2 more tasks.\nfunction nameTasks(list: Task[]) {\n const names = list.slice(0, 3).map((t) => `'${t.title}'`);\n const rest = list.length - names.length;\n if (rest > 0) return `${names.join(', ')} and ${rest} more ${rest === 1 ? 'task' : 'tasks'}`;\n if (names.length <= 1) return names[0] ?? '';\n return `${names.slice(0, -1).join(', ')} and ${names[names.length - 1]}`;\n}\n\nexport default function BulkActionsList() {\n const [tasks, setTasks] = useState(firstTasks);\n // Opens with three tasks picked, so the bar shows.\n const [picked, setPicked] = useState<string[]>(['t1', 't3', 't5']);\n const [menuAnchor, setMenuAnchor] = useState<HTMLElement | null>(null);\n const [menuOpen, setMenuOpen] = useState(false);\n // The tasks the confirm names. They stay set while the Modal fades out.\n const [toDelete, setToDelete] = useState<Task[]>([]);\n const [confirming, setConfirming] = useState(false);\n const [deleting, setDeleting] = useState(false);\n const timer = useRef<ReturnType<typeof setTimeout>>();\n const toastIds = useRef<string[]>([]);\n // Holds the header Checkbox. Checkbox takes no ref, so focus goes to the box inside this line.\n const headerBox = useRef<HTMLParagraphElement>(null);\n // With no task left there is no header Checkbox, so focus goes to Add Task.\n const addTask = useRef<HTMLButtonElement | HTMLAnchorElement | null>(null);\n // Where focus goes after the next render, once the element it goes to is on screen.\n const focusNext = useRef<() => void>();\n\n // On unmount it stops the request and closes every toast it opened.\n useEffect(() => () => {\n clearTimeout(timer.current);\n toastIds.current.forEach((id) => dismissToast(id));\n toastIds.current = [];\n }, []);\n\n useEffect(() => {\n const move = focusNext.current;\n focusNext.current = undefined;\n move?.();\n });\n\n const headerCheckbox = () => headerBox.current?.querySelector('input') ?? addTask.current;\n const pickedTasks = tasks.filter((t) => picked.includes(t.id));\n const count = pickedTasks.length;\n const all = tasks.length > 0 && count === tasks.length;\n\n function toggle(id: string, on: boolean) {\n setPicked((list) => (on ? [...list, id] : list.filter((x) => x !== id)));\n }\n\n // Mixed or empty: pick every task. All picked: pick none.\n function toggleAll(on: boolean) {\n setPicked(on ? tasks.map((t) => t.id) : []);\n }\n\n // The bar and its Buttons go, so focus goes to the header Checkbox.\n function clearSelection() {\n setPicked([]);\n focusNext.current = () => headerCheckbox()?.focus();\n }\n\n function update(change: (t: Task) => Task, message: string) {\n setTasks((list) => list.map((t) => (picked.includes(t.id) ? change(t) : t)));\n toastIds.current.push(toast({ type: 'success', message }));\n }\n\n function choose(action: () => void) {\n setMenuOpen(false);\n action();\n }\n\n // Escape, a click outside and Cancel all close it, except while the request runs.\n function closeConfirm() {\n if (deleting) return;\n setConfirming(false);\n }\n\n function deletePicked() {\n if (deleting) return;\n const ids = toDelete.map((t) => t.id);\n setDeleting(true);\n // Stands in for the request to the server.\n timer.current = setTimeout(() => {\n setDeleting(false);\n setTasks((list) => list.filter((t) => !ids.includes(t.id)));\n setPicked([]);\n setConfirming(false);\n toastIds.current.push(toast({ type: 'success', message: `${plural(ids.length)} deleted.` }));\n }, 1200);\n }\n\n return (\n <Center width=\"page\">\n {/* A real app mounts one Toaster near its root. */}\n <Toaster />\n <Stack gap=\"large\">\n <Heading level={1} size=\"h5\">Launch tasks</Heading>\n {/* The toolbar. While any task is picked, the bar takes its place. */}\n <Cluster justify=\"between\">\n {/* On the page from the start, so each new count is heard once. */}\n <Paragraph id=\"bulk-actions-list-count\" role=\"status\" size=\"body2\" measure=\"none\">\n {count > 0 ? `${count} selected` : plural(tasks.length)}\n </Paragraph>\n {count > 0 ? (\n <Cluster gap=\"small\">\n <Button size=\"small\" type=\"secondary\" state=\"enabled\" label=\"Mark Done\" onClickButton={() => update((t) => ({ ...t, done: true }), `${plural(count)} marked done.`)} />\n <Button size=\"small\" type=\"secondary\" color=\"danger\" state=\"enabled\" label=\"Delete\" onClickButton={() => { setToDelete(pickedTasks); setConfirming(true); }} />\n <Tooltip title=\"More\">\n <IconButton\n color=\"iconOnly\"\n state={menuOpen ? 'selected' : 'enabled'}\n size=\"small\"\n iconName=\"Ellipsis\"\n ariaLabel={`More actions for ${plural(count)}`}\n aria-haspopup=\"menu\"\n aria-expanded={menuOpen}\n onClick={(e: { currentTarget: HTMLElement }) => {\n setMenuAnchor(e.currentTarget);\n setMenuOpen((o) => !o);\n }}\n />\n </Tooltip>\n <Button size=\"small\" type=\"tertiary\" state=\"enabled\" label=\"Clear Selection\" onClickButton={clearSelection} />\n </Cluster>\n ) : (\n <Button ref={addTask} size=\"small\" type=\"secondary\" state=\"enabled\" label=\"Add Task\" decoIcon=\"Plus\" onClickButton={() => console.info('Open the new task form')} />\n )}\n </Cluster>\n\n {tasks.length === 0 ? (\n <EmptyBox size=\"large\" text=\"No tasks\" secondText=\"Tasks you add to this project appear here.\" />\n ) : (\n <TableContainer aria-label=\"Launch tasks\" minWidth=\"520px\">\n <TableHeader>\n <TableRow>\n <TableHeaderCell width=\"48px\">\n <Paragraph ref={headerBox} measure=\"none\">\n <Checkbox aria-label=\"Select all tasks\" checked={all} indeterminate={count > 0 && !all} onChange={toggleAll} />\n </Paragraph>\n </TableHeaderCell>\n <TableHeaderCell>Task</TableHeaderCell>\n <TableHeaderCell width=\"140px\">Assignee</TableHeaderCell>\n <TableHeaderCell width=\"80px\">Status</TableHeaderCell>\n </TableRow>\n </TableHeader>\n {tasks.map((t) => (\n <TableRow key={t.id}>\n <TableCell width=\"48px\">\n <Checkbox aria-label={`Select ${t.title}`} checked={picked.includes(t.id)} onChange={(on) => toggle(t.id, on)} />\n </TableCell>\n <TableCell>{t.title}</TableCell>\n <TableCell width=\"140px\">{t.assignee ?? 'No one'}</TableCell>\n <TableCell width=\"80px\">\n <Tag variant=\"textOnly\" size=\"small\" label={t.done ? 'Done' : 'Open'} />\n </TableCell>\n </TableRow>\n ))}\n </TableContainer>\n )}\n </Stack>\n\n <Popover open={menuOpen} anchorEl={menuAnchor} onClose={() => setMenuOpen(false)} returnFocus>\n <Menu navigable aria-label={`Actions for ${plural(count)}`} width={200}>\n <MenuItem size=\"small\" iconName=\"UserCheck\" label=\"Assign to Me\" onClick={() => choose(() => update((t) => ({ ...t, assignee: me }), `${plural(count)} assigned to you.`))} />\n <MenuItem size=\"small\" iconName=\"UserX\" label=\"Unassign\" onClick={() => choose(() => update((t) => ({ ...t, assignee: null }), `${plural(count)} unassigned.`))} />\n </Menu>\n </Popover>\n\n {/* After a delete the bar is gone, so the Modal gives focus to the header Checkbox. Cancel gives it back to Delete. */}\n <Modal\n isOpen={confirming}\n size=\"small\"\n title={`Delete ${toDelete.length} ${toDelete.length === 1 ? 'Task' : 'Tasks'}`}\n onClose={closeConfirm}\n returnFocus={headerCheckbox}\n actions={\n <>\n <Button size=\"small\" type=\"tertiary\" state={deleting ? 'disabled' : 'enabled'} label=\"Cancel\" onClickButton={closeConfirm} />\n <Button size=\"small\" type=\"primary\" color=\"danger\" state=\"enabled\" label=\"Delete\" loading={deleting} onClickButton={deletePicked} />\n </>\n }\n >\n <Paragraph measure=\"none\">{`This deletes ${nameTasks(toDelete)}.`}</Paragraph>\n <Paragraph tone=\"secondary\" size=\"body2\" measure=\"none\">Their comments and files go too.</Paragraph>\n </Modal>\n </Center>\n );\n}\n",
1899
+ "source": "'use client';\nimport { useEffect, useRef, useState } from 'react';\nimport Toaster, { toast, dismissToast } from 'oneslash-design-system/components/toaster';\nimport Heading from 'oneslash-design-system/components/heading';\nimport Paragraph from 'oneslash-design-system/components/paragraph';\nimport Checkbox from 'oneslash-design-system/components/checkBox';\nimport Button from 'oneslash-design-system/components/button';\nimport IconButton from 'oneslash-design-system/components/iconButton';\nimport Tooltip from 'oneslash-design-system/components/tooltip';\nimport Popover from 'oneslash-design-system/components/popover';\nimport Menu from 'oneslash-design-system/components/menu';\nimport MenuItem from 'oneslash-design-system/components/menuItem';\nimport Modal from 'oneslash-design-system/components/modal';\nimport Tag from 'oneslash-design-system/components/tag';\nimport EmptyBox from 'oneslash-design-system/components/emptyBox';\nimport TableContainer from 'oneslash-design-system/components/tableContainer';\nimport TableHeader from 'oneslash-design-system/components/tableHeader';\nimport TableHeaderCell from 'oneslash-design-system/components/tableHeaderCell';\nimport TableRow from 'oneslash-design-system/components/tableRow';\nimport TableCell from 'oneslash-design-system/components/tableCell';\nimport { Center, Cluster, Stack } from 'oneslash-design-system/components/layout';\n\ntype Task = { id: string; title: string; assignee: string | null; done: boolean };\n\n// A real app reads this from the session.\nconst me = 'Dana Lee';\n\n// A real app reads these from the server. They all fit on one page.\nconst firstTasks: Task[] = [\n { id: 't1', title: 'Write the launch email', assignee: 'Ben Carter', done: false },\n { id: 't2', title: 'Update the pricing page', assignee: 'Dana Lee', done: false },\n { id: 't3', title: 'Check the plan table on a phone', assignee: 'Omar Reyes', done: false },\n { id: 't4', title: 'Send the press kit', assignee: 'Mia Park', done: true },\n { id: 't5', title: 'Book the launch call', assignee: null, done: false },\n { id: 't6', title: 'Review the help article', assignee: 'Ben Carter', done: false },\n { id: 't7', title: 'Record the demo video', assignee: 'Omar Reyes', done: false },\n { id: 't8', title: 'Translate the FAQ', assignee: null, done: false },\n];\n\nconst plural = (n: number) => `${n} ${n === 1 ? 'task' : 'tasks'}`;\n\n// Names up to three tasks, then counts the rest: 'A', 'B' and 2 more tasks.\nfunction nameTasks(list: Task[]) {\n const names = list.slice(0, 3).map((t) => `'${t.title}'`);\n const rest = list.length - names.length;\n if (rest > 0) return `${names.join(', ')} and ${rest} more ${rest === 1 ? 'task' : 'tasks'}`;\n if (names.length <= 1) return names[0] ?? '';\n return `${names.slice(0, -1).join(', ')} and ${names[names.length - 1]}`;\n}\n\nexport default function BulkActionsList() {\n const [tasks, setTasks] = useState(firstTasks);\n // Opens with three tasks picked, so the bar shows.\n const [picked, setPicked] = useState<string[]>(['t1', 't3', 't5']);\n const [menuAnchor, setMenuAnchor] = useState<HTMLElement | null>(null);\n const [menuOpen, setMenuOpen] = useState(false);\n // The tasks the confirm names. They stay set while the Modal fades out.\n const [toDelete, setToDelete] = useState<Task[]>([]);\n const [confirming, setConfirming] = useState(false);\n const [deleting, setDeleting] = useState(false);\n const timer = useRef<ReturnType<typeof setTimeout>>();\n const toastIds = useRef<string[]>([]);\n const headerBox = useRef<HTMLInputElement>(null);\n // With no task left there is no header Checkbox, so focus goes to Add Task.\n const addTask = useRef<HTMLButtonElement | HTMLAnchorElement | null>(null);\n // Where focus goes after the next render, once the element it goes to is on screen.\n const focusNext = useRef<() => void>();\n\n // On unmount it stops the request and closes every toast it opened.\n useEffect(() => () => {\n clearTimeout(timer.current);\n toastIds.current.forEach((id) => dismissToast(id));\n toastIds.current = [];\n }, []);\n\n useEffect(() => {\n const move = focusNext.current;\n focusNext.current = undefined;\n move?.();\n });\n\n const headerCheckbox = () => headerBox.current ?? addTask.current;\n const pickedTasks = tasks.filter((t) => picked.includes(t.id));\n const count = pickedTasks.length;\n const all = tasks.length > 0 && count === tasks.length;\n\n function toggle(id: string, on: boolean) {\n setPicked((list) => (on ? [...list, id] : list.filter((x) => x !== id)));\n }\n\n // Mixed or empty: pick every task. All picked: pick none.\n function toggleAll(on: boolean) {\n setPicked(on ? tasks.map((t) => t.id) : []);\n }\n\n // The bar and its Buttons go, so focus goes to the header Checkbox.\n function clearSelection() {\n setPicked([]);\n focusNext.current = () => headerCheckbox()?.focus();\n }\n\n function update(change: (t: Task) => Task, message: string) {\n setTasks((list) => list.map((t) => (picked.includes(t.id) ? change(t) : t)));\n toastIds.current.push(toast({ type: 'success', message }));\n }\n\n function choose(action: () => void) {\n setMenuOpen(false);\n action();\n }\n\n // Escape, a click outside and Cancel all close it, except while the request runs.\n function closeConfirm() {\n if (deleting) return;\n setConfirming(false);\n }\n\n function deletePicked() {\n if (deleting) return;\n const ids = toDelete.map((t) => t.id);\n setDeleting(true);\n // Stands in for the request to the server.\n timer.current = setTimeout(() => {\n setDeleting(false);\n setTasks((list) => list.filter((t) => !ids.includes(t.id)));\n setPicked([]);\n setConfirming(false);\n toastIds.current.push(toast({ type: 'success', message: `${plural(ids.length)} deleted.` }));\n }, 1200);\n }\n\n return (\n <Center width=\"page\">\n {/* A real app mounts one Toaster near its root. */}\n <Toaster />\n <Stack gap=\"large\">\n <Heading level={1} size=\"h5\">Launch tasks</Heading>\n {/* The toolbar. While any task is picked, the bar takes its place. */}\n <Cluster justify=\"between\">\n {/* On the page from the start, so each new count is heard once. */}\n <Paragraph id=\"bulk-actions-list-count\" role=\"status\" size=\"body2\" measure=\"none\">\n {count > 0 ? `${count} selected` : plural(tasks.length)}\n </Paragraph>\n {count > 0 ? (\n <Cluster gap=\"small\">\n <Button size=\"small\" type=\"secondary\" state=\"enabled\" label=\"Mark Done\" onClickButton={() => update((t) => ({ ...t, done: true }), `${plural(count)} marked done.`)} />\n <Button size=\"small\" type=\"secondary\" color=\"danger\" state=\"enabled\" label=\"Delete\" onClickButton={() => { setToDelete(pickedTasks); setConfirming(true); }} />\n <Tooltip title=\"More\">\n <IconButton\n color=\"iconOnly\"\n state={menuOpen ? 'selected' : 'enabled'}\n size=\"small\"\n iconName=\"Ellipsis\"\n ariaLabel={`More actions for ${plural(count)}`}\n aria-haspopup=\"menu\"\n aria-expanded={menuOpen}\n onClick={(e: { currentTarget: HTMLElement }) => {\n setMenuAnchor(e.currentTarget);\n setMenuOpen((o) => !o);\n }}\n />\n </Tooltip>\n <Button size=\"small\" type=\"tertiary\" state=\"enabled\" label=\"Clear Selection\" onClickButton={clearSelection} />\n </Cluster>\n ) : (\n <Button ref={addTask} size=\"small\" type=\"secondary\" state=\"enabled\" label=\"Add Task\" decoIcon=\"Plus\" onClickButton={() => console.info('Open the new task form')} />\n )}\n </Cluster>\n\n {tasks.length === 0 ? (\n <EmptyBox size=\"large\" text=\"No tasks\" secondText=\"Tasks you add to this project appear here.\" />\n ) : (\n <TableContainer aria-label=\"Launch tasks\" minWidth=\"520px\">\n <TableHeader>\n <TableRow>\n <TableHeaderCell width=\"48px\">\n <Checkbox ref={headerBox} aria-label=\"Select all tasks\" checked={all} indeterminate={count > 0 && !all} onChange={toggleAll} />\n </TableHeaderCell>\n <TableHeaderCell>Task</TableHeaderCell>\n <TableHeaderCell width=\"140px\">Assignee</TableHeaderCell>\n <TableHeaderCell width=\"80px\">Status</TableHeaderCell>\n </TableRow>\n </TableHeader>\n {tasks.map((t) => (\n <TableRow key={t.id}>\n <TableCell width=\"48px\">\n <Checkbox aria-label={`Select ${t.title}`} checked={picked.includes(t.id)} onChange={(on) => toggle(t.id, on)} />\n </TableCell>\n <TableCell>{t.title}</TableCell>\n <TableCell width=\"140px\">{t.assignee ?? 'No one'}</TableCell>\n <TableCell width=\"80px\">\n <Tag variant=\"textOnly\" size=\"small\" label={t.done ? 'Done' : 'Open'} />\n </TableCell>\n </TableRow>\n ))}\n </TableContainer>\n )}\n </Stack>\n\n <Popover open={menuOpen} anchorEl={menuAnchor} onClose={() => setMenuOpen(false)} returnFocus>\n <Menu navigable aria-label={`Actions for ${plural(count)}`} width={200}>\n <MenuItem size=\"small\" iconName=\"UserCheck\" label=\"Assign to Me\" onClick={() => choose(() => update((t) => ({ ...t, assignee: me }), `${plural(count)} assigned to you.`))} />\n <MenuItem size=\"small\" iconName=\"UserX\" label=\"Unassign\" onClick={() => choose(() => update((t) => ({ ...t, assignee: null }), `${plural(count)} unassigned.`))} />\n </Menu>\n </Popover>\n\n {/* After a delete the bar is gone, so the Modal gives focus to the header Checkbox. Cancel gives it back to Delete. */}\n <Modal\n isOpen={confirming}\n size=\"small\"\n title={`Delete ${toDelete.length} ${toDelete.length === 1 ? 'Task' : 'Tasks'}`}\n onClose={closeConfirm}\n returnFocus={headerCheckbox}\n actions={\n <>\n <Button size=\"small\" type=\"tertiary\" state={deleting ? 'disabled' : 'enabled'} label=\"Cancel\" onClickButton={closeConfirm} />\n <Button size=\"small\" type=\"primary\" color=\"danger\" state=\"enabled\" label=\"Delete\" loading={deleting} onClickButton={deletePicked} />\n </>\n }\n >\n <Paragraph measure=\"none\">{`This deletes ${nameTasks(toDelete)}.`}</Paragraph>\n <Paragraph tone=\"secondary\" size=\"body2\" measure=\"none\">Their comments and files go too.</Paragraph>\n </Modal>\n </Center>\n );\n}\n",
1898
1900
  "uses": [
1899
1901
  "Button",
1900
1902
  "Center",
@@ -1925,7 +1927,7 @@
1925
1927
  "id": "paged-table",
1926
1928
  "title": "Ticks across pages",
1927
1929
  "useWhen": "A table over many pages, where the person may want every row, not only the ones they see.",
1928
- "source": "'use client';\nimport { useEffect, useRef, useState } from 'react';\nimport Toaster, { toast, dismissToast } from 'oneslash-design-system/components/toaster';\nimport TitleBar from 'oneslash-design-system/components/titleBar';\nimport Paragraph from 'oneslash-design-system/components/paragraph';\nimport Checkbox from 'oneslash-design-system/components/checkBox';\nimport Button from 'oneslash-design-system/components/button';\nimport IconButton from 'oneslash-design-system/components/iconButton';\nimport Tooltip from 'oneslash-design-system/components/tooltip';\nimport Popover from 'oneslash-design-system/components/popover';\nimport Menu from 'oneslash-design-system/components/menu';\nimport MenuItem from 'oneslash-design-system/components/menuItem';\nimport Modal from 'oneslash-design-system/components/modal';\nimport Tag from 'oneslash-design-system/components/tag';\nimport Surface from 'oneslash-design-system/components/surface';\nimport EmptyBox from 'oneslash-design-system/components/emptyBox';\nimport Pagination from 'oneslash-design-system/components/pagination';\nimport TableContainer from 'oneslash-design-system/components/tableContainer';\nimport TableHeader from 'oneslash-design-system/components/tableHeader';\nimport TableHeaderCell from 'oneslash-design-system/components/tableHeaderCell';\nimport TableRow from 'oneslash-design-system/components/tableRow';\nimport TableCell from 'oneslash-design-system/components/tableCell';\nimport { formatCount, formatMoney } from 'oneslash-design-system/components/formatNumber';\nimport { Center, Cluster, Stack } from 'oneslash-design-system/components/layout';\n\ntype Focusable = HTMLButtonElement | HTMLAnchorElement | null;\ntype Status = 'Paid' | 'Past due';\ntype Invoice = { id: string; number: string; customer: string; date: string; cents: number; status: Status };\n\nconst customers = ['Willow Bakery', 'Harbor Studio', 'Lumen Labs', 'Pine and Co', 'Cedar Works', 'Bright Dental', 'Maple Design', 'Atlas Freight'];\nconst monthNames = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];\n\n// A real app asks the server for one page. This makes the 240 invoices the server would hold, newest first.\nconst firstInvoices: Invoice[] = Array.from({ length: 240 }, (_, i) => {\n const day = new Date(Date.UTC(2026, 10, 16 - i));\n return {\n id: `inv-${i}`,\n number: `INV-${1290 - i}`,\n customer: customers[(i * 5 + 1) % customers.length],\n date: `${monthNames[day.getUTCMonth()]} ${day.getUTCDate()}, ${day.getUTCFullYear()}`,\n cents: 2400 + ((i * 5303) % 40000),\n status: i % 11 === 4 ? 'Past due' : 'Paid',\n };\n});\n\nconst PAGE_SIZE = 25;\nconst plural = (n: number) => `${formatCount(n)} ${n === 1 ? 'invoice' : 'invoices'}`;\n\n// Names up to three invoices, then counts the rest: INV-1290, INV-1289 and 23 more.\nfunction nameInvoices(list: Invoice[]) {\n const names = list.slice(0, 3).map((inv) => inv.number);\n const rest = list.length - names.length;\n if (rest > 0) return `${plural(list.length)}: ${names.join(', ')} and ${formatCount(rest)} more`;\n if (names.length <= 1) return names[0] ?? '';\n return `${names.slice(0, -1).join(', ')} and ${names[names.length - 1]}`;\n}\n\nexport default function BulkActionsPagedTable() {\n const [invoices, setInvoices] = useState(firstInvoices);\n const [page, setPage] = useState(1);\n // The picked invoices by id, on any page. Opens with three picked, so the bar shows.\n const [picked, setPicked] = useState<string[]>(['inv-0', 'inv-1', 'inv-3']);\n const [menuAnchor, setMenuAnchor] = useState<HTMLElement | null>(null);\n const [menuOpen, setMenuOpen] = useState(false);\n // The invoices the confirm names. They stay set while the Modal fades out.\n const [toDelete, setToDelete] = useState<Invoice[]>([]);\n const [confirming, setConfirming] = useState(false);\n const [deleting, setDeleting] = useState(false);\n const timer = useRef<ReturnType<typeof setTimeout>>();\n const toastIds = useRef<string[]>([]);\n const clearButton = useRef<Focusable>(null);\n // With no invoice left there is no header Checkbox, so focus goes to the empty state's Button.\n const createButton = useRef<Focusable>(null);\n // Holds the header Checkbox. Checkbox takes no ref, so focus goes to the box inside this line.\n const headerBox = useRef<HTMLParagraphElement>(null);\n // Where focus goes after the next render, once the element it goes to is on screen.\n const focusNext = useRef<() => void>();\n\n // On unmount it stops the request and closes every toast it opened.\n useEffect(() => () => {\n clearTimeout(timer.current);\n toastIds.current.forEach((id) => dismissToast(id));\n toastIds.current = [];\n }, []);\n\n useEffect(() => {\n const move = focusNext.current;\n focusNext.current = undefined;\n move?.();\n });\n\n const headerCheckbox = () => headerBox.current?.querySelector('input') ?? createButton.current;\n const pageCount = Math.ceil(invoices.length / PAGE_SIZE);\n const rows = invoices.slice((page - 1) * PAGE_SIZE, page * PAGE_SIZE);\n const pickedInvoices = invoices.filter((inv) => picked.includes(inv.id));\n const count = pickedInvoices.length;\n const everyRow = count > 0 && count === invoices.length;\n // The header Checkbox speaks for the page shown.\n const onPage = rows.filter((inv) => picked.includes(inv.id)).length;\n const wholePage = rows.length > 0 && onPage === rows.length;\n\n function toggle(id: string, on: boolean) {\n setPicked((list) => (on ? [...list, id] : list.filter((x) => x !== id)));\n }\n\n // Mixed or empty: pick every row on this page. All picked: unpick them. Rows on other pages stay as they are.\n function togglePage(on: boolean) {\n const ids = rows.map((inv) => inv.id);\n setPicked((list) => (on ? [...list.filter((x) => !ids.includes(x)), ...ids] : list.filter((x) => !ids.includes(x))));\n }\n\n // 'Select All 240' goes away once every row is picked, so focus goes to 'Clear Selection'.\n function pickEveryRow() {\n setPicked(invoices.map((inv) => inv.id));\n focusNext.current = () => clearButton.current?.focus();\n }\n\n // The bar and its Buttons go, so focus goes to the header Checkbox.\n function clearSelection() {\n setPicked([]);\n focusNext.current = () => headerCheckbox()?.focus();\n }\n\n function choose(action: () => void) {\n setMenuOpen(false);\n action();\n }\n\n function markPaid() {\n setInvoices((list) => list.map((inv) => (picked.includes(inv.id) ? { ...inv, status: 'Paid' } : inv)));\n toastIds.current.push(toast({ type: 'success', message: `${plural(count)} marked as paid.` }));\n }\n\n // Escape, a click outside and Cancel all close it, except while the request runs.\n function closeConfirm() {\n if (deleting) return;\n setConfirming(false);\n }\n\n function deletePicked() {\n if (deleting) return;\n const ids = toDelete.map((inv) => inv.id);\n setDeleting(true);\n // Stands in for the request to the server.\n timer.current = setTimeout(() => {\n setDeleting(false);\n const left = invoices.filter((inv) => !ids.includes(inv.id));\n setInvoices(left);\n // Fewer pages may be left: stay on this page if it still exists, or go to the last one.\n setPage((p) => Math.min(p, Math.max(1, Math.ceil(left.length / PAGE_SIZE))));\n setPicked([]);\n setConfirming(false);\n toastIds.current.push(toast({ type: 'success', message: `${plural(ids.length)} deleted.` }));\n }, 1200);\n }\n\n return (\n <Center width=\"page\">\n {/* A real app mounts one Toaster near its root. */}\n <Toaster />\n <Stack gap=\"large\">\n {/* The case 'Data table page' adds search, a filter and sorting here. */}\n <Stack gap=\"small\">\n <TitleBar title=\"Invoices\" id=\"bulk-actions-paged-table-top\" />\n <Paragraph tone=\"secondary\" size=\"body2\" measure=\"none\">{plural(invoices.length)}</Paragraph>\n </Stack>\n\n {/* The toolbar. While any invoice is picked, the bar takes its place. */}\n <Cluster justify=\"between\">\n <Cluster gap=\"small\">\n {/* On the page from the start, so each new count is heard once. */}\n <Paragraph id=\"bulk-actions-paged-table-count\" role=\"status\" size=\"body2\" measure=\"none\">\n {count > 0 ? `${formatCount(count)} selected` : ''}\n </Paragraph>\n {count > 0 && !everyRow && (\n <Button size=\"small\" type=\"textOnly\" state=\"enabled\" label={`Select All ${formatCount(invoices.length)}`} onClickButton={pickEveryRow} />\n )}\n </Cluster>\n {count > 0 ? (\n <Cluster gap=\"small\">\n <Button size=\"small\" type=\"secondary\" state=\"enabled\" label=\"Export\" onClickButton={() => toastIds.current.push(toast({ type: 'success', message: `Export of ${plural(count)} sent to dana@acme.example.` }))} />\n <Button size=\"small\" type=\"secondary\" color=\"danger\" state=\"enabled\" label=\"Delete\" onClickButton={() => { setToDelete(pickedInvoices); setConfirming(true); }} />\n <Tooltip title=\"More\">\n <IconButton\n color=\"iconOnly\"\n state={menuOpen ? 'selected' : 'enabled'}\n size=\"small\"\n iconName=\"Ellipsis\"\n ariaLabel={`More actions for ${plural(count)}`}\n aria-haspopup=\"menu\"\n aria-expanded={menuOpen}\n onClick={(e: { currentTarget: HTMLElement }) => {\n setMenuAnchor(e.currentTarget);\n setMenuOpen((o) => !o);\n }}\n />\n </Tooltip>\n <Button ref={clearButton} size=\"small\" type=\"tertiary\" state=\"enabled\" label=\"Clear Selection\" onClickButton={clearSelection} />\n </Cluster>\n ) : invoices.length === 0 ? null : (\n <Button size=\"small\" type=\"secondary\" state=\"enabled\" label=\"Export All\" onClickButton={() => toastIds.current.push(toast({ type: 'success', message: `Export of ${plural(invoices.length)} sent to dana@acme.example.` }))} />\n )}\n </Cluster>\n\n {invoices.length === 0 ? (\n // The case 'Empty list' takes the table's place.\n <Surface minHeight=\"tall\" align=\"center\">\n <EmptyBox\n size=\"large\"\n text=\"No invoices yet\"\n secondText=\"Your next invoice appears here after the next payment.\"\n action={<Button ref={createButton} size=\"medium\" type=\"primary\" state=\"enabled\" label=\"Create Invoice\" onClickButton={() => console.info('Open the new invoice form')} />}\n />\n </Surface>\n ) : (\n <TableContainer aria-label=\"Invoices\" minWidth=\"640px\">\n <TableHeader>\n <TableRow>\n <TableHeaderCell width=\"48px\">\n <Paragraph ref={headerBox} measure=\"none\">\n <Checkbox aria-label=\"Select all invoices on this page\" checked={wholePage} indeterminate={onPage > 0 && !wholePage} onChange={togglePage} />\n </Paragraph>\n </TableHeaderCell>\n <TableHeaderCell width=\"110px\">Invoice</TableHeaderCell>\n <TableHeaderCell>Customer</TableHeaderCell>\n <TableHeaderCell width=\"130px\">Date</TableHeaderCell>\n <TableHeaderCell width=\"120px\" align=\"right\">Amount</TableHeaderCell>\n <TableHeaderCell width=\"100px\">Status</TableHeaderCell>\n </TableRow>\n </TableHeader>\n {rows.map((inv) => (\n <TableRow key={inv.id}>\n <TableCell width=\"48px\">\n <Checkbox aria-label={`Select ${inv.number}`} checked={picked.includes(inv.id)} onChange={(on) => toggle(inv.id, on)} />\n </TableCell>\n <TableCell width=\"110px\">{inv.number}</TableCell>\n <TableCell>{inv.customer}</TableCell>\n <TableCell width=\"130px\">{inv.date}</TableCell>\n <TableCell width=\"120px\" align=\"right\">{formatMoney(inv.cents / 100)}</TableCell>\n <TableCell width=\"100px\">\n {inv.status === 'Past due' ? <Tag variant=\"dot\" size=\"small\" color=\"error\" label={inv.status} /> : <Tag variant=\"textOnly\" size=\"small\" label={inv.status} />}\n </TableCell>\n </TableRow>\n ))}\n </TableContainer>\n )}\n\n {/* Changing page keeps the picked invoices. A real app also passes `getHref`, so each page has an address. */}\n <Pagination aria-label=\"Invoice pages\" page={page} pageCount={pageCount} onPageChange={setPage} scrollTargetId=\"bulk-actions-paged-table-top\" />\n </Stack>\n\n <Popover open={menuOpen} anchorEl={menuAnchor} onClose={() => setMenuOpen(false)} returnFocus>\n <Menu navigable aria-label={`Actions for ${plural(count)}`} width={200}>\n <MenuItem size=\"small\" iconName=\"Mail\" label=\"Send Receipts\" onClick={() => choose(() => toastIds.current.push(toast({ type: 'success', message: `Receipts for ${plural(count)} sent.` })))} />\n <MenuItem size=\"small\" iconName=\"Check\" label=\"Mark as Paid\" onClick={() => choose(markPaid)} />\n </Menu>\n </Popover>\n\n {/* After a delete the bar is gone, so the Modal gives focus to the header Checkbox. Cancel gives it back to Delete. */}\n <Modal\n isOpen={confirming}\n size=\"small\"\n title={`Delete ${formatCount(toDelete.length)} ${toDelete.length === 1 ? 'Invoice' : 'Invoices'}`}\n onClose={closeConfirm}\n returnFocus={headerCheckbox}\n actions={\n <>\n <Button size=\"small\" type=\"tertiary\" state={deleting ? 'disabled' : 'enabled'} label=\"Cancel\" onClickButton={closeConfirm} />\n <Button size=\"small\" type=\"primary\" color=\"danger\" state=\"enabled\" label=\"Delete\" loading={deleting} onClickButton={deletePicked} />\n </>\n }\n >\n <Paragraph measure=\"none\">{`This deletes ${nameInvoices(toDelete)}.`}</Paragraph>\n <Paragraph tone=\"secondary\" size=\"body2\" measure=\"none\">Payments made on them stay in Payments.</Paragraph>\n </Modal>\n </Center>\n );\n}\n",
1930
+ "source": "'use client';\nimport { useEffect, useRef, useState } from 'react';\nimport Toaster, { toast, dismissToast } from 'oneslash-design-system/components/toaster';\nimport TitleBar from 'oneslash-design-system/components/titleBar';\nimport Paragraph from 'oneslash-design-system/components/paragraph';\nimport Checkbox from 'oneslash-design-system/components/checkBox';\nimport Button from 'oneslash-design-system/components/button';\nimport IconButton from 'oneslash-design-system/components/iconButton';\nimport Tooltip from 'oneslash-design-system/components/tooltip';\nimport Popover from 'oneslash-design-system/components/popover';\nimport Menu from 'oneslash-design-system/components/menu';\nimport MenuItem from 'oneslash-design-system/components/menuItem';\nimport Modal from 'oneslash-design-system/components/modal';\nimport Tag from 'oneslash-design-system/components/tag';\nimport Surface from 'oneslash-design-system/components/surface';\nimport EmptyBox from 'oneslash-design-system/components/emptyBox';\nimport Pagination from 'oneslash-design-system/components/pagination';\nimport TableContainer from 'oneslash-design-system/components/tableContainer';\nimport TableHeader from 'oneslash-design-system/components/tableHeader';\nimport TableHeaderCell from 'oneslash-design-system/components/tableHeaderCell';\nimport TableRow from 'oneslash-design-system/components/tableRow';\nimport TableCell from 'oneslash-design-system/components/tableCell';\nimport { formatCount, formatMoney } from 'oneslash-design-system/components/formatNumber';\nimport { Center, Cluster, Stack } from 'oneslash-design-system/components/layout';\n\ntype Focusable = HTMLButtonElement | HTMLAnchorElement | null;\ntype Status = 'Paid' | 'Past due';\ntype Invoice = { id: string; number: string; customer: string; date: string; cents: number; status: Status };\n\nconst customers = ['Willow Bakery', 'Harbor Studio', 'Lumen Labs', 'Pine and Co', 'Cedar Works', 'Bright Dental', 'Maple Design', 'Atlas Freight'];\nconst monthNames = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];\n\n// A real app asks the server for one page. This makes the 240 invoices the server would hold, newest first.\nconst firstInvoices: Invoice[] = Array.from({ length: 240 }, (_, i) => {\n const day = new Date(Date.UTC(2026, 10, 16 - i));\n return {\n id: `inv-${i}`,\n number: `INV-${1290 - i}`,\n customer: customers[(i * 5 + 1) % customers.length],\n date: `${monthNames[day.getUTCMonth()]} ${day.getUTCDate()}, ${day.getUTCFullYear()}`,\n cents: 2400 + ((i * 5303) % 40000),\n status: i % 11 === 4 ? 'Past due' : 'Paid',\n };\n});\n\nconst PAGE_SIZE = 25;\nconst plural = (n: number) => `${formatCount(n)} ${n === 1 ? 'invoice' : 'invoices'}`;\n\n// Names up to three invoices, then counts the rest: INV-1290, INV-1289 and 23 more.\nfunction nameInvoices(list: Invoice[]) {\n const names = list.slice(0, 3).map((inv) => inv.number);\n const rest = list.length - names.length;\n if (rest > 0) return `${plural(list.length)}: ${names.join(', ')} and ${formatCount(rest)} more`;\n if (names.length <= 1) return names[0] ?? '';\n return `${names.slice(0, -1).join(', ')} and ${names[names.length - 1]}`;\n}\n\nexport default function BulkActionsPagedTable() {\n const [invoices, setInvoices] = useState(firstInvoices);\n const [page, setPage] = useState(1);\n // The picked invoices by id, on any page. Opens with three picked, so the bar shows.\n const [picked, setPicked] = useState<string[]>(['inv-0', 'inv-1', 'inv-3']);\n const [menuAnchor, setMenuAnchor] = useState<HTMLElement | null>(null);\n const [menuOpen, setMenuOpen] = useState(false);\n // The invoices the confirm names. They stay set while the Modal fades out.\n const [toDelete, setToDelete] = useState<Invoice[]>([]);\n const [confirming, setConfirming] = useState(false);\n const [deleting, setDeleting] = useState(false);\n const timer = useRef<ReturnType<typeof setTimeout>>();\n const toastIds = useRef<string[]>([]);\n const clearButton = useRef<Focusable>(null);\n // With no invoice left there is no header Checkbox, so focus goes to the empty state's Button.\n const createButton = useRef<Focusable>(null);\n const headerBox = useRef<HTMLInputElement>(null);\n // Where focus goes after the next render, once the element it goes to is on screen.\n const focusNext = useRef<() => void>();\n\n // On unmount it stops the request and closes every toast it opened.\n useEffect(() => () => {\n clearTimeout(timer.current);\n toastIds.current.forEach((id) => dismissToast(id));\n toastIds.current = [];\n }, []);\n\n useEffect(() => {\n const move = focusNext.current;\n focusNext.current = undefined;\n move?.();\n });\n\n const headerCheckbox = () => headerBox.current ?? createButton.current;\n const pageCount = Math.ceil(invoices.length / PAGE_SIZE);\n const rows = invoices.slice((page - 1) * PAGE_SIZE, page * PAGE_SIZE);\n const pickedInvoices = invoices.filter((inv) => picked.includes(inv.id));\n const count = pickedInvoices.length;\n const everyRow = count > 0 && count === invoices.length;\n // The header Checkbox speaks for the page shown.\n const onPage = rows.filter((inv) => picked.includes(inv.id)).length;\n const wholePage = rows.length > 0 && onPage === rows.length;\n\n function toggle(id: string, on: boolean) {\n setPicked((list) => (on ? [...list, id] : list.filter((x) => x !== id)));\n }\n\n // Mixed or empty: pick every row on this page. All picked: unpick them. Rows on other pages stay as they are.\n function togglePage(on: boolean) {\n const ids = rows.map((inv) => inv.id);\n setPicked((list) => (on ? [...list.filter((x) => !ids.includes(x)), ...ids] : list.filter((x) => !ids.includes(x))));\n }\n\n // 'Select All 240' goes away once every row is picked, so focus goes to 'Clear Selection'.\n function pickEveryRow() {\n setPicked(invoices.map((inv) => inv.id));\n focusNext.current = () => clearButton.current?.focus();\n }\n\n // The bar and its Buttons go, so focus goes to the header Checkbox.\n function clearSelection() {\n setPicked([]);\n focusNext.current = () => headerCheckbox()?.focus();\n }\n\n function choose(action: () => void) {\n setMenuOpen(false);\n action();\n }\n\n function markPaid() {\n setInvoices((list) => list.map((inv) => (picked.includes(inv.id) ? { ...inv, status: 'Paid' } : inv)));\n toastIds.current.push(toast({ type: 'success', message: `${plural(count)} marked as paid.` }));\n }\n\n // Escape, a click outside and Cancel all close it, except while the request runs.\n function closeConfirm() {\n if (deleting) return;\n setConfirming(false);\n }\n\n function deletePicked() {\n if (deleting) return;\n const ids = toDelete.map((inv) => inv.id);\n setDeleting(true);\n // Stands in for the request to the server.\n timer.current = setTimeout(() => {\n setDeleting(false);\n const left = invoices.filter((inv) => !ids.includes(inv.id));\n setInvoices(left);\n // Fewer pages may be left: stay on this page if it still exists, or go to the last one.\n setPage((p) => Math.min(p, Math.max(1, Math.ceil(left.length / PAGE_SIZE))));\n setPicked([]);\n setConfirming(false);\n toastIds.current.push(toast({ type: 'success', message: `${plural(ids.length)} deleted.` }));\n }, 1200);\n }\n\n return (\n <Center width=\"page\">\n {/* A real app mounts one Toaster near its root. */}\n <Toaster />\n <Stack gap=\"large\">\n {/* The case 'Data table page' adds search, a filter and sorting here. */}\n <Stack gap=\"small\">\n <TitleBar title=\"Invoices\" id=\"bulk-actions-paged-table-top\" />\n <Paragraph tone=\"secondary\" size=\"body2\" measure=\"none\">{plural(invoices.length)}</Paragraph>\n </Stack>\n\n {/* The toolbar. While any invoice is picked, the bar takes its place. */}\n <Cluster justify=\"between\">\n <Cluster gap=\"small\">\n {/* On the page from the start, so each new count is heard once. */}\n <Paragraph id=\"bulk-actions-paged-table-count\" role=\"status\" size=\"body2\" measure=\"none\">\n {count > 0 ? `${formatCount(count)} selected` : ''}\n </Paragraph>\n {count > 0 && !everyRow && (\n <Button size=\"small\" type=\"tertiary\" state=\"enabled\" label={`Select All ${formatCount(invoices.length)}`} onClickButton={pickEveryRow} />\n )}\n </Cluster>\n {count > 0 ? (\n <Cluster gap=\"small\">\n <Button size=\"small\" type=\"secondary\" state=\"enabled\" label=\"Export\" onClickButton={() => toastIds.current.push(toast({ type: 'success', message: `Export of ${plural(count)} sent to dana@acme.example.` }))} />\n <Button size=\"small\" type=\"secondary\" color=\"danger\" state=\"enabled\" label=\"Delete\" onClickButton={() => { setToDelete(pickedInvoices); setConfirming(true); }} />\n <Tooltip title=\"More\">\n <IconButton\n color=\"iconOnly\"\n state={menuOpen ? 'selected' : 'enabled'}\n size=\"small\"\n iconName=\"Ellipsis\"\n ariaLabel={`More actions for ${plural(count)}`}\n aria-haspopup=\"menu\"\n aria-expanded={menuOpen}\n onClick={(e: { currentTarget: HTMLElement }) => {\n setMenuAnchor(e.currentTarget);\n setMenuOpen((o) => !o);\n }}\n />\n </Tooltip>\n <Button ref={clearButton} size=\"small\" type=\"tertiary\" state=\"enabled\" label=\"Clear Selection\" onClickButton={clearSelection} />\n </Cluster>\n ) : invoices.length === 0 ? null : (\n <Button size=\"small\" type=\"secondary\" state=\"enabled\" label=\"Export All\" onClickButton={() => toastIds.current.push(toast({ type: 'success', message: `Export of ${plural(invoices.length)} sent to dana@acme.example.` }))} />\n )}\n </Cluster>\n\n {invoices.length === 0 ? (\n // The case 'Empty list' takes the table's place.\n <Surface minHeight=\"tall\" align=\"center\">\n <EmptyBox\n size=\"large\"\n text=\"No invoices yet\"\n secondText=\"Your next invoice appears here after the next payment.\"\n action={<Button ref={createButton} size=\"medium\" type=\"primary\" state=\"enabled\" label=\"Create Invoice\" onClickButton={() => console.info('Open the new invoice form')} />}\n />\n </Surface>\n ) : (\n <TableContainer aria-label=\"Invoices\" minWidth=\"640px\">\n <TableHeader>\n <TableRow>\n <TableHeaderCell width=\"48px\">\n <Checkbox ref={headerBox} aria-label=\"Select all invoices on this page\" checked={wholePage} indeterminate={onPage > 0 && !wholePage} onChange={togglePage} />\n </TableHeaderCell>\n <TableHeaderCell width=\"110px\">Invoice</TableHeaderCell>\n <TableHeaderCell>Customer</TableHeaderCell>\n <TableHeaderCell width=\"130px\">Date</TableHeaderCell>\n <TableHeaderCell width=\"120px\" align=\"right\">Amount</TableHeaderCell>\n <TableHeaderCell width=\"100px\">Status</TableHeaderCell>\n </TableRow>\n </TableHeader>\n {rows.map((inv) => (\n <TableRow key={inv.id}>\n <TableCell width=\"48px\">\n <Checkbox aria-label={`Select ${inv.number}`} checked={picked.includes(inv.id)} onChange={(on) => toggle(inv.id, on)} />\n </TableCell>\n <TableCell width=\"110px\">{inv.number}</TableCell>\n <TableCell>{inv.customer}</TableCell>\n <TableCell width=\"130px\">{inv.date}</TableCell>\n <TableCell width=\"120px\" align=\"right\">{formatMoney(inv.cents / 100)}</TableCell>\n <TableCell width=\"100px\">\n {inv.status === 'Past due' ? <Tag variant=\"dot\" size=\"small\" color=\"error\" label={inv.status} /> : <Tag variant=\"textOnly\" size=\"small\" label={inv.status} />}\n </TableCell>\n </TableRow>\n ))}\n </TableContainer>\n )}\n\n {/* Changing page keeps the picked invoices. A real app also passes `getHref`, so each page has an address. */}\n <Pagination aria-label=\"Invoice pages\" page={page} pageCount={pageCount} onPageChange={setPage} scrollTargetId=\"bulk-actions-paged-table-top\" />\n </Stack>\n\n <Popover open={menuOpen} anchorEl={menuAnchor} onClose={() => setMenuOpen(false)} returnFocus>\n <Menu navigable aria-label={`Actions for ${plural(count)}`} width={200}>\n <MenuItem size=\"small\" iconName=\"Mail\" label=\"Send Receipts\" onClick={() => choose(() => toastIds.current.push(toast({ type: 'success', message: `Receipts for ${plural(count)} sent.` })))} />\n <MenuItem size=\"small\" iconName=\"Check\" label=\"Mark as Paid\" onClick={() => choose(markPaid)} />\n </Menu>\n </Popover>\n\n {/* After a delete the bar is gone, so the Modal gives focus to the header Checkbox. Cancel gives it back to Delete. */}\n <Modal\n isOpen={confirming}\n size=\"small\"\n title={`Delete ${formatCount(toDelete.length)} ${toDelete.length === 1 ? 'Invoice' : 'Invoices'}`}\n onClose={closeConfirm}\n returnFocus={headerCheckbox}\n actions={\n <>\n <Button size=\"small\" type=\"tertiary\" state={deleting ? 'disabled' : 'enabled'} label=\"Cancel\" onClickButton={closeConfirm} />\n <Button size=\"small\" type=\"primary\" color=\"danger\" state=\"enabled\" label=\"Delete\" loading={deleting} onClickButton={deletePicked} />\n </>\n }\n >\n <Paragraph measure=\"none\">{`This deletes ${nameInvoices(toDelete)}.`}</Paragraph>\n <Paragraph tone=\"secondary\" size=\"body2\" measure=\"none\">Payments made on them stay in Payments.</Paragraph>\n </Modal>\n </Center>\n );\n}\n",
1929
1931
  "uses": [
1930
1932
  "Button",
1931
1933
  "Center",
@@ -7298,7 +7300,7 @@
7298
7300
  "id": "scripted",
7299
7301
  "title": "Scripted scenes",
7300
7302
  "useWhen": "The product is about a flow, such as asking an agent and getting an answer.",
7301
- "source": "'use client';\nimport { useEffect, useRef, useState } from 'react';\nimport { BookOpen, Bot, MessageSquare } from 'lucide-react';\nimport PageShell from 'oneslash-design-system/components/pageShell';\nimport SectionIntro from 'oneslash-design-system/components/sectionIntro';\nimport Surface from 'oneslash-design-system/components/surface';\nimport Message from 'oneslash-design-system/components/message';\nimport UserImage from 'oneslash-design-system/components/userImage';\nimport Tag from 'oneslash-design-system/components/tag';\nimport TimeStamp from 'oneslash-design-system/components/timeStamp';\nimport Paragraph from 'oneslash-design-system/components/paragraph';\nimport Button from 'oneslash-design-system/components/button';\nimport SegmentedControl from 'oneslash-design-system/components/segmentedControl';\nimport StepList from 'oneslash-design-system/components/stepList';\nimport SourceCard from 'oneslash-design-system/components/sourceCard';\nimport { Cluster, Grid, PageSection, Stack } from 'oneslash-design-system/components/layout';\n\nconst agentName = 'Acme Agent';\n\n// A made-up thread. Every label in it is one the app has: the agent's marks, its steps and its source cards.\nconst request = { from: 'Dana Lee', at: new Date('2026-11-16T14:30:00Z'), text: 'When does the new pricing page go live?' };\nconst repliedAt = new Date('2026-11-16T14:31:00Z');\nconst reply = 'The new pricing page goes live on Nov 20, 2026. Ben moved it two days to finish the plan table.';\n\nconst scenes = [\n { value: 'ask', label: 'Ask' },\n { value: 'work', label: 'Work' },\n { value: 'answer', label: 'Answer' },\n];\n\n// Long enough to read each scene.\nconst sceneTime = 6000;\n\n// The agent's marks, as the rule 'An agent says what it is' says.\nfunction agentMeta(at: Date) {\n return (\n <>\n <Tag variant=\"contained\" size=\"small\" label=\"Agent\" />\n <TimeStamp createdAt={at} dateFormat=\"absolute\" data=\"time\" />\n <Paragraph size=\"caption\" tone=\"secondary\" measure=\"none\">Model name</Paragraph>\n </>\n );\n}\n\n// `autoPlay` starts the scenes when the page opens. A real site passes it only when the visitor has not asked for\n// reduced motion, from `matchMedia('(prefers-reduced-motion: reduce)')`. Left out, the demo waits for the visitor.\nexport default function ProductDemoScripted({ autoPlay = false }: { autoPlay?: boolean } = {}) {\n const [scene, setScene] = useState(autoPlay ? 'ask' : 'answer');\n const [paused, setPaused] = useState(!autoPlay);\n const timer = useRef<ReturnType<typeof setInterval>>();\n\n // Moves to the next scene while the demo plays, and stops when it is paused or leaves the page.\n useEffect(() => {\n if (paused) return undefined;\n timer.current = setInterval(() => {\n setScene((s) => scenes[(scenes.findIndex((x) => x.value === s) + 1) % scenes.length].value);\n }, sceneTime);\n return () => clearInterval(timer.current);\n }, [paused]);\n\n const at = scenes.findIndex((x) => x.value === scene);\n\n return (\n <PageShell>\n <PageSection gap=\"xxlarge\">\n <SectionIntro id=\"product-demo-scripted\" name=\"Ask the agent in the thread\" statement=\"Acme Agent reads the thread and the docs, then answers with its sources.\" />\n {/* No live region: a screen reader is not read each scene as it changes. */}\n <Surface padding=\"medium\">\n <Stack gap=\"large\">\n {/* Play or Pause comes first, so a keyboard reaches it before anything moves. It is one Button whose label\n says what pressing it does, so focus stays on it when the label changes. Picking a scene pauses too. */}\n <Cluster justify=\"between\">\n <Cluster gap=\"xlarge\">\n <Button\n size=\"small\"\n type=\"secondary\"\n state=\"enabled\"\n label={paused ? 'Play' : 'Pause'}\n onClickButton={() => setPaused((p) => !p)}\n />\n <SegmentedControl\n size=\"small\"\n width=\"fit\"\n aria-label=\"Scene\"\n options={scenes}\n value={scene}\n onChange={(value) => {\n setPaused(true);\n setScene(value);\n }}\n />\n </Cluster>\n <Tag variant=\"textOnly\" size=\"small\" label=\"Example\" />\n </Cluster>\n <Stack gap=\"small\">\n <Message\n aria-label={request.from}\n avatar={<UserImage userHandle={request.from} decorative />}\n name={request.from}\n meta={<TimeStamp createdAt={request.at} dateFormat=\"absolute\" data=\"time\" />}\n >\n <Paragraph measure=\"none\">{request.text}</Paragraph>\n </Message>\n {at >= 1 && (\n <Message\n aria-label={`${agentName}, agent`}\n avatar={<UserImage userHandle={agentName} icon={Bot} decorative />}\n name={agentName}\n meta={agentMeta(repliedAt)}\n footer={\n at === 2 ? (\n // Plain cards: a demo on the site opens nothing.\n <Grid columns={2} gap=\"medium\">\n <SourceCard icon={BookOpen} title=\"Launch plan\" meta=\"Docs · Nov 14, 2026\" />\n <SourceCard icon={MessageSquare} title=\"Pricing page date\" meta=\"#launch · Nov 15, 2026\" />\n </Grid>\n ) : undefined\n }\n >\n {at === 2 ? (\n <Paragraph measure=\"none\">{reply}</Paragraph>\n ) : (\n <Stack gap=\"medium\">\n <Paragraph size=\"caption\" tone=\"secondary\" measure=\"none\">Working for 4 seconds</Paragraph>\n <StepList\n aria-label=\"Acme Agent's steps\"\n steps={[\n { label: 'Read the thread in #launch', status: 'done' },\n { label: 'Read the launch plan', status: 'running' },\n ]}\n />\n </Stack>\n )}\n </Message>\n )}\n </Stack>\n </Stack>\n </Surface>\n </PageSection>\n </PageShell>\n );\n}\n",
7303
+ "source": "'use client';\nimport { useEffect, useRef, useState } from 'react';\nimport { BookOpen, Bot, MessageSquare } from 'lucide-react';\nimport PageShell from 'oneslash-design-system/components/pageShell';\nimport SectionIntro from 'oneslash-design-system/components/sectionIntro';\nimport Surface from 'oneslash-design-system/components/surface';\nimport Message from 'oneslash-design-system/components/message';\nimport UserImage from 'oneslash-design-system/components/userImage';\nimport Tag from 'oneslash-design-system/components/tag';\nimport TimeStamp from 'oneslash-design-system/components/timeStamp';\nimport Paragraph from 'oneslash-design-system/components/paragraph';\nimport Button from 'oneslash-design-system/components/button';\nimport SegmentedControl from 'oneslash-design-system/components/segmentedControl';\nimport StepList from 'oneslash-design-system/components/stepList';\nimport SourceCard from 'oneslash-design-system/components/sourceCard';\nimport useReducedMotion from 'oneslash-design-system/components/useReducedMotion';\nimport { Cluster, Grid, PageSection, Stack } from 'oneslash-design-system/components/layout';\n\nconst agentName = 'Acme Agent';\n\n// A made-up thread. Every label in it is one the app has: the agent's marks, its steps and its source cards.\nconst request = { from: 'Dana Lee', at: new Date('2026-11-16T14:30:00Z'), text: 'When does the new pricing page go live?' };\nconst repliedAt = new Date('2026-11-16T14:31:00Z');\nconst reply = 'The new pricing page goes live on Nov 20, 2026. Ben moved it two days to finish the plan table.';\n\nconst scenes = [\n { value: 'ask', label: 'Ask' },\n { value: 'work', label: 'Work' },\n { value: 'answer', label: 'Answer' },\n];\n\n// Long enough to read each scene.\nconst sceneTime = 6000;\n\n// The agent's marks, as the rule 'An agent says what it is' says.\nfunction agentMeta(at: Date) {\n return (\n <>\n <Tag variant=\"contained\" size=\"small\" label=\"Agent\" />\n <TimeStamp createdAt={at} dateFormat=\"absolute\" data=\"time\" />\n <Paragraph size=\"caption\" tone=\"secondary\" measure=\"none\">Model name</Paragraph>\n </>\n );\n}\n\nexport default function ProductDemoScripted() {\n // The scenes start when the page opens, unless the visitor asks for reduced motion. Then the demo waits for\n // 'Play' and shows the answer. Once the visitor plays, pauses or picks a scene, their choice stands.\n const reducedMotion = useReducedMotion();\n const [chosenPaused, setChosenPaused] = useState<boolean | null>(null);\n const [chosenScene, setChosenScene] = useState<string | null>(null);\n const paused = chosenPaused ?? reducedMotion;\n const scene = chosenScene ?? (paused ? 'answer' : 'ask');\n const setPaused = setChosenPaused;\n const timer = useRef<ReturnType<typeof setInterval>>();\n\n // Moves to the next scene while the demo plays, and stops when it is paused or leaves the page.\n useEffect(() => {\n if (paused) return undefined;\n timer.current = setInterval(() => {\n setChosenScene(scenes[(scenes.findIndex((x) => x.value === scene) + 1) % scenes.length].value);\n }, sceneTime);\n return () => clearInterval(timer.current);\n }, [paused, scene]);\n\n const at = scenes.findIndex((x) => x.value === scene);\n\n return (\n <PageShell>\n <PageSection gap=\"xxlarge\">\n <SectionIntro id=\"product-demo-scripted\" name=\"Ask the agent in the thread\" statement=\"Acme Agent reads the thread and the docs, then answers with its sources.\" />\n {/* No live region: a screen reader is not read each scene as it changes. */}\n <Surface padding=\"medium\">\n <Stack gap=\"large\">\n {/* Play or Pause comes first, so a keyboard reaches it before anything moves. It is one Button whose label\n says what pressing it does, so focus stays on it when the label changes. Picking a scene pauses too. */}\n <Cluster justify=\"between\">\n <Cluster gap=\"xlarge\">\n <Button\n size=\"small\"\n type=\"secondary\"\n state=\"enabled\"\n label={paused ? 'Play' : 'Pause'}\n onClickButton={() => setPaused(!paused)}\n />\n <SegmentedControl\n size=\"small\"\n width=\"fit\"\n aria-label=\"Scene\"\n options={scenes}\n value={scene}\n onChange={(value) => {\n setPaused(true);\n setChosenScene(value);\n }}\n />\n </Cluster>\n <Tag variant=\"textOnly\" size=\"small\" label=\"Example\" />\n </Cluster>\n <Stack gap=\"small\">\n <Message\n aria-label={request.from}\n avatar={<UserImage userHandle={request.from} decorative />}\n name={request.from}\n meta={<TimeStamp createdAt={request.at} dateFormat=\"absolute\" data=\"time\" />}\n >\n <Paragraph measure=\"none\">{request.text}</Paragraph>\n </Message>\n {at >= 1 && (\n <Message\n aria-label={`${agentName}, agent`}\n avatar={<UserImage userHandle={agentName} icon={Bot} decorative />}\n name={agentName}\n meta={agentMeta(repliedAt)}\n footer={\n at === 2 ? (\n // Plain cards: a demo on the site opens nothing.\n <Grid columns={2} gap=\"medium\">\n <SourceCard icon={BookOpen} title=\"Launch plan\" meta=\"Docs · Nov 14, 2026\" />\n <SourceCard icon={MessageSquare} title=\"Pricing page date\" meta=\"#launch · Nov 15, 2026\" />\n </Grid>\n ) : undefined\n }\n >\n {at === 2 ? (\n <Paragraph measure=\"none\">{reply}</Paragraph>\n ) : (\n <Stack gap=\"medium\">\n <Paragraph size=\"caption\" tone=\"secondary\" measure=\"none\">Working for 4 seconds</Paragraph>\n <StepList\n aria-label=\"Acme Agent's steps\"\n steps={[\n { label: 'Read the thread in #launch', status: 'done' },\n { label: 'Read the launch plan', status: 'running' },\n ]}\n />\n </Stack>\n )}\n </Message>\n )}\n </Stack>\n </Stack>\n </Surface>\n </PageSection>\n </PageShell>\n );\n}\n",
7302
7304
  "uses": [
7303
7305
  "Button",
7304
7306
  "Cluster",
@@ -7315,7 +7317,8 @@
7315
7317
  "Surface",
7316
7318
  "Tag",
7317
7319
  "TimeStamp",
7318
- "UserImage"
7320
+ "UserImage",
7321
+ "useReducedMotion"
7319
7322
  ]
7320
7323
  }
7321
7324
  ]
@@ -14,5 +14,6 @@ interface CheckboxProps {
14
14
  /** Mixed state, e.g. the header checkbox of a partly selected list. Shows a dash. A press calls `onChange(true)` and stays mixed until the parent sets `checked`. Does nothing while `checked` */
15
15
  indeterminate?: boolean;
16
16
  }
17
- export default function Checkbox({ label, secondLabel, checked, onChange, disabled, id, 'aria-describedby': ariaDescribedBy, 'aria-label': ariaLabel, indeterminate, }: CheckboxProps): React.JSX.Element;
18
- export {};
17
+ /** The ref reaches the `<input>`, so a page can move focus to it */
18
+ declare const Checkbox: React.ForwardRefExoticComponent<CheckboxProps & React.RefAttributes<HTMLInputElement>>;
19
+ export default Checkbox;
@@ -1,16 +1,20 @@
1
1
  'use client';
2
- import React, { useEffect, useRef, useState } from 'react';
2
+ import React, { forwardRef, useEffect, useRef, useState } from 'react';
3
3
  import { popTransition, stateTransition } from './sharedStyles';
4
- export default function Checkbox(_a) {
4
+ /** The ref reaches the `<input>`, so a page can move focus to it */
5
+ var Checkbox = forwardRef(function Checkbox(_a, ref) {
5
6
  var label = _a.label, secondLabel = _a.secondLabel, _b = _a.checked, checked = _b === void 0 ? false : _b, onChange = _a.onChange, _c = _a.disabled, disabled = _c === void 0 ? false : _c, id = _a.id, ariaDescribedBy = _a["aria-describedby"], ariaLabel = _a["aria-label"], _d = _a.indeterminate, indeterminate = _d === void 0 ? false : _d;
6
7
  var _e = useState(checked), isChecked = _e[0], setIsChecked = _e[1];
7
8
  var inputRef = useRef(null);
8
9
  var isMixed = indeterminate && !isChecked;
9
10
  var filled = isChecked || isMixed;
10
- // Follow the parent when it changes `checked` (e.g. resetting a form)
11
- useEffect(function () {
11
+ // Follow the parent when it changes `checked` (e.g. resetting a form). Done while rendering, not in an
12
+ // effect, so the box never paints the old value first
13
+ var _f = useState(checked), lastChecked = _f[0], setLastChecked = _f[1];
14
+ if (checked !== lastChecked) {
15
+ setLastChecked(checked);
12
16
  setIsChecked(checked);
13
- }, [checked]);
17
+ }
14
18
  // The DOM property is what browsers expose to assistive tech as mixed
15
19
  useEffect(function () {
16
20
  if (inputRef.current)
@@ -30,7 +34,13 @@ export default function Checkbox(_a) {
30
34
  };
31
35
  return (<label className={"group relative flex items-start ".concat(disabled ? 'cursor-not-allowed' : 'cursor-pointer')}>
32
36
  {/* Native input keeps keyboard focus, Space to toggle and screen-reader semantics */}
33
- <input type="checkbox" ref={inputRef} id={id} aria-describedby={ariaDescribedBy} aria-label={ariaLabel} data-indeterminate={isMixed ? 'true' : undefined} className="peer sr-only" checked={isChecked} disabled={disabled} onChange={handleChange}/>
37
+ <input type="checkbox" ref={function (el) {
38
+ inputRef.current = el;
39
+ if (typeof ref === 'function')
40
+ ref(el);
41
+ else if (ref)
42
+ ref.current = el;
43
+ }} id={id} aria-describedby={ariaDescribedBy} aria-label={ariaLabel} data-indeterminate={isMixed ? 'true' : undefined} className="peer sr-only" checked={isChecked} disabled={disabled} onChange={handleChange}/>
34
44
  <span className={"relative flex flex-shrink-0 items-center justify-center w-6 h-6 rounded-full ".concat(stateTransition, "\n peer-focus-visible:outline peer-focus-visible:outline-2 peer-focus-visible:outline-offset-0 peer-focus-visible:outline-fg-primary\n ").concat(disabled ? '' : 'group-hover:bg-action-selected')}>
35
45
  {/* Checkbox */}
36
46
  <span className={"relative w-4 h-4 border-2 rounded ".concat(stateTransition, " ").concat(disabled
@@ -59,4 +69,5 @@ export default function Checkbox(_a) {
59
69
  </span>)}
60
70
  </span>)}
61
71
  </label>);
62
- }
72
+ });
73
+ export default Checkbox;
@@ -18,12 +18,15 @@ interface DiffProps {
18
18
  emptyText?: string;
19
19
  /** Wrap long lines instead of scrolling them sideways. Default false. */
20
20
  wrap?: boolean;
21
+ /** Draw each line's number in the old text and in the new text, before its mark. Default false. */
22
+ lineNumbers?: boolean;
21
23
  }
22
24
  /**
23
25
  * The lines a change adds and removes, in a figure: a visible label, then a table in a named region. An added
24
26
  * line has a quiet success fill and a removed line a quiet error fill, and each also has a `+` or `-` mark and
25
27
  * hidden text 'Added: ' or 'Removed: ', so color is never the only sign. A long line scrolls inside the region,
26
28
  * a Tab stop a keyboard can scroll; the page never does. When nothing changed it shows `emptyText` instead.
29
+ * `lineNumbers` adds the old and the new line number to each row, for eyes only.
27
30
  */
28
- export default function Diff({ id, label, lines, maxRows, emptyText, wrap }: DiffProps): React.JSX.Element;
31
+ export default function Diff({ id, label, lines, maxRows, emptyText, wrap, lineNumbers }: DiffProps): React.JSX.Element;
29
32
  export { Diff };
@@ -3,15 +3,18 @@ import { focusRing } from './sharedStyles';
3
3
  export { diffLines } from '../internal/diff';
4
4
  var rowFill = { added: 'bg-success-alertBg', removed: 'bg-error-alertBg', same: '' };
5
5
  var mark = { added: '+', removed: '-', same: '' };
6
+ // As wide as four digits, so the columns line up down the diff
7
+ var numberCell = 'w-[5ch] min-w-[5ch] select-none pl-2 text-right align-top tabular-nums text-fg-secondary';
6
8
  var hidden = { added: 'Added: ', removed: 'Removed: ', same: '' };
7
9
  /**
8
10
  * The lines a change adds and removes, in a figure: a visible label, then a table in a named region. An added
9
11
  * line has a quiet success fill and a removed line a quiet error fill, and each also has a `+` or `-` mark and
10
12
  * hidden text 'Added: ' or 'Removed: ', so color is never the only sign. A long line scrolls inside the region,
11
13
  * a Tab stop a keyboard can scroll; the page never does. When nothing changed it shows `emptyText` instead.
14
+ * `lineNumbers` adds the old and the new line number to each row, for eyes only.
12
15
  */
13
16
  export default function Diff(_a) {
14
- var id = _a.id, label = _a.label, lines = _a.lines, maxRows = _a.maxRows, _b = _a.emptyText, emptyText = _b === void 0 ? 'No changes' : _b, _c = _a.wrap, wrap = _c === void 0 ? false : _c;
17
+ var id = _a.id, label = _a.label, lines = _a.lines, maxRows = _a.maxRows, _b = _a.emptyText, emptyText = _b === void 0 ? 'No changes' : _b, _c = _a.wrap, wrap = _c === void 0 ? false : _c, _d = _a.lineNumbers, lineNumbers = _d === void 0 ? false : _d;
15
18
  var changed = lines.some(function (line) { return line.kind !== 'same'; });
16
19
  return (<figure className="m-0 grid w-full min-w-0 max-w-full gap-y-1">
17
20
  <figcaption className="min-w-0 break-words text-caption text-fg-secondary">{label}</figcaption>
@@ -21,6 +24,10 @@ export default function Diff(_a) {
21
24
  <table className={"border-collapse ".concat(wrap ? 'w-full table-fixed' : 'w-max min-w-full')}>
22
25
  <tbody>
23
26
  {lines.map(function (line, i) { return (<tr key={i} className={rowFill[line.kind]}>
27
+ {lineNumbers && (<>
28
+ <td aria-hidden="true" className={numberCell}>{line.oldNumber}</td>
29
+ <td aria-hidden="true" className={numberCell}>{line.newNumber}</td>
30
+ </>)}
24
31
  <td aria-hidden="true" className="w-6 select-none px-2 text-center align-top">{mark[line.kind]}</td>
25
32
  <td className={"pr-medium align-top ".concat(wrap ? 'whitespace-pre-wrap break-words' : 'whitespace-pre')}>
26
33
  {line.kind !== 'same' && <span className="sr-only">{hidden[line.kind]}</span>}
@@ -12,11 +12,13 @@ interface SegmentedControlProps {
12
12
  size?: 'medium' | 'small' | 'tiny';
13
13
  /** `fill` takes the width of its container. `fit` is as wide as its options, for a control that sits beside a heading. */
14
14
  width?: 'fill' | 'fit';
15
+ /** Shows the value and takes no press and no focus, e.g. a setting only an admin can change. Say why beside it. */
16
+ disabled?: boolean;
15
17
  }
16
18
  /**
17
19
  * A row of options that sets one value on the same page, with the look of `TabsContainer fill`.
18
20
  * Use tabs to switch panels and this to change a value. Arrow keys move and select; only the
19
21
  * selected option is in the tab order.
20
22
  */
21
- export default function SegmentedControl({ options, value, onChange, 'aria-label': ariaLabel, size, width, }: SegmentedControlProps): React.JSX.Element;
23
+ export default function SegmentedControl({ options, value, onChange, 'aria-label': ariaLabel, size, width, disabled, }: SegmentedControlProps): React.JSX.Element;
22
24
  export { SegmentedControl };
@@ -1,14 +1,14 @@
1
1
  'use client';
2
2
  import React, { useRef } from 'react';
3
- import { SlidingPill, segmentIdleClasses, segmentItemClasses, segmentSelectedClasses, segmentSizes, segmentTrackClasses, segmentTrackStyle, useSlidingIndicator, } from './slidingIndicator';
3
+ import { SlidingPill, segmentDisabledIdleClasses, segmentDisabledSelectedClasses, segmentIdleClasses, segmentItemClasses, segmentSelectedClasses, segmentSizes, segmentTrackClasses, segmentTrackStyle, useSlidingIndicator, } from './slidingIndicator';
4
4
  /**
5
5
  * A row of options that sets one value on the same page, with the look of `TabsContainer fill`.
6
6
  * Use tabs to switch panels and this to change a value. Arrow keys move and select; only the
7
7
  * selected option is in the tab order.
8
8
  */
9
9
  export default function SegmentedControl(_a) {
10
- var options = _a.options, value = _a.value, onChange = _a.onChange, ariaLabel = _a["aria-label"], _b = _a.size, size = _b === void 0 ? 'medium' : _b, _c = _a.width, width = _c === void 0 ? 'fill' : _c;
11
- var _d = useSlidingIndicator(options), containerRef = _d.containerRef, indicator = _d.indicator;
10
+ var options = _a.options, value = _a.value, onChange = _a.onChange, ariaLabel = _a["aria-label"], _b = _a.size, size = _b === void 0 ? 'medium' : _b, _c = _a.width, width = _c === void 0 ? 'fill' : _c, _d = _a.disabled, disabled = _d === void 0 ? false : _d;
11
+ var _e = useSlidingIndicator(options), containerRef = _e.containerRef, indicator = _e.indicator;
12
12
  var refs = useRef([]);
13
13
  var sizeClasses = segmentSizes[size];
14
14
  var selectedIndex = options.findIndex(function (o) { return o.value === value; });
@@ -37,13 +37,15 @@ export default function SegmentedControl(_a) {
37
37
  e.preventDefault();
38
38
  move(next);
39
39
  };
40
- return (<div ref={containerRef} role="radiogroup" aria-label={ariaLabel} onKeyDown={handleKeyDown} className={segmentTrackClasses(width === 'fill', options.length > 0)} style={segmentTrackStyle}>
41
- <SlidingPill indicator={indicator}/>
40
+ return (<div ref={containerRef} role="radiogroup" aria-label={ariaLabel} aria-disabled={disabled || undefined} onKeyDown={handleKeyDown} className={segmentTrackClasses(width === 'fill', options.length > 0)} style={segmentTrackStyle}>
41
+ <SlidingPill indicator={indicator} disabled={disabled}/>
42
42
  {options.map(function (option, i) {
43
43
  var selected = i === selectedIndex;
44
44
  return (<button key={option.value} ref={function (el) {
45
45
  refs.current[i] = el;
46
- }} type="button" role="radio" aria-checked={selected} tabIndex={i === tabStop ? 0 : -1} data-tab-selected={selected} onClick={function () { return onChange(option.value); }} className={segmentItemClasses(width === 'fill', sizeClasses.tab, selected ? segmentSelectedClasses : segmentIdleClasses)}>
46
+ }} type="button" role="radio" aria-checked={selected} tabIndex={i === tabStop ? 0 : -1} disabled={disabled || undefined} data-tab-selected={selected} onClick={function () { return onChange(option.value); }} className={segmentItemClasses(width === 'fill', sizeClasses.tab, disabled
47
+ ? (selected ? segmentDisabledSelectedClasses : segmentDisabledIdleClasses)
48
+ : (selected ? segmentSelectedClasses : segmentIdleClasses), disabled)}>
47
49
  <div className={"flex flex-col text-center ".concat(sizeClasses.label)}>
48
50
  <span className="whitespace-nowrap">{option.label}</span>
49
51
  </div>
@@ -10,7 +10,7 @@ type IndicatorRect = {
10
10
  export declare function segmentTrackClasses(fill: boolean, filled: boolean): string;
11
11
  export declare const segmentTrackStyle: React.CSSProperties;
12
12
  /** The classes every item has, selected or not */
13
- export declare function segmentItemClasses(fill: boolean, sizeClass: string, selectedClasses: string): string;
13
+ export declare function segmentItemClasses(fill: boolean, sizeClass: string, selectedClasses: string, disabled?: boolean): string;
14
14
  /** Item text and icon sizes. Items use `data-tab-selected="true"` on the selected one. */
15
15
  export declare const segmentSizes: {
16
16
  medium: {
@@ -34,6 +34,8 @@ export declare const segmentSizes: {
34
34
  };
35
35
  export declare const segmentSelectedClasses = "text-primary-contrast";
36
36
  export declare const segmentIdleClasses = "text-fg-primary hover:bg-background-accent200";
37
+ export declare const segmentDisabledSelectedClasses = "text-fg-contrast";
38
+ export declare const segmentDisabledIdleClasses = "text-fg-disabled";
37
39
  /**
38
40
  * Places a pill behind the item marked `data-tab-selected="true"` inside the container, keeps it
39
41
  * there as items resize, and scrolls a newly selected item into view. Pass the container's `ref`
@@ -44,7 +46,8 @@ export declare function useSlidingIndicator(children: unknown): {
44
46
  indicator: IndicatorRect | null;
45
47
  };
46
48
  /** The pill itself. Render it first inside the track. */
47
- export declare function SlidingPill({ indicator }: {
49
+ export declare function SlidingPill({ indicator, disabled }: {
48
50
  indicator: IndicatorRect | null;
51
+ disabled?: boolean;
49
52
  }): React.JSX.Element | null;
50
53
  export {};
@@ -15,7 +15,11 @@ export var segmentTrackStyle = {
15
15
  msOverflowStyle: 'none',
16
16
  };
17
17
  /** The classes every item has, selected or not */
18
- export function segmentItemClasses(fill, sizeClass, selectedClasses) {
18
+ export function segmentItemClasses(fill, sizeClass, selectedClasses, disabled) {
19
+ if (disabled === void 0) { disabled = false; }
20
+ if (disabled) {
21
+ return "\n relative flex items-center space-x-1 rounded-control cursor-not-allowed ".concat(fill ? 'flex-1 justify-center' : 'justify-start', "\n ").concat(sizeClass, "\n ").concat(selectedClasses, "\n ");
22
+ }
19
23
  return "\n relative flex items-center space-x-1 rounded-control cursor-pointer ".concat(fill ? 'flex-1 justify-center' : 'justify-start', " ").concat(stateTransition, " ").concat(pressFeedbackAny, " ").concat(focusRing, "\n ").concat(sizeClass, "\n ").concat(selectedClasses, "\n ");
20
24
  }
21
25
  /** Item text and icon sizes. Items use `data-tab-selected="true"` on the selected one. */
@@ -26,6 +30,8 @@ export var segmentSizes = {
26
30
  };
27
31
  export var segmentSelectedClasses = 'text-primary-contrast';
28
32
  export var segmentIdleClasses = 'text-fg-primary hover:bg-background-accent200';
33
+ export var segmentDisabledSelectedClasses = 'text-fg-contrast';
34
+ export var segmentDisabledIdleClasses = 'text-fg-disabled';
29
35
  /**
30
36
  * Places a pill behind the item marked `data-tab-selected="true"` inside the container, keeps it
31
37
  * there as items resize, and scrolls a newly selected item into view. Pass the container's `ref`
@@ -89,10 +95,10 @@ export function useSlidingIndicator(children) {
89
95
  }
90
96
  /** The pill itself. Render it first inside the track. */
91
97
  export function SlidingPill(_a) {
92
- var indicator = _a.indicator;
98
+ var indicator = _a.indicator, _b = _a.disabled, disabled = _b === void 0 ? false : _b;
93
99
  if (!indicator)
94
100
  return null;
95
- return (<span aria-hidden className={"absolute rounded-control pointer-events-none bg-primary-dark\n ".concat(indicator.animate ? 'transition-[transform,width,height] duration-[var(--os-duration-slide)] ease-emphasized motion-reduce:transition-none' : '')} style={{
101
+ return (<span aria-hidden className={"absolute rounded-control pointer-events-none ".concat(disabled ? 'bg-fg-disabled' : 'bg-primary-dark', "\n ").concat(indicator.animate ? 'transition-[transform,width,height] duration-[var(--os-duration-slide)] ease-emphasized motion-reduce:transition-none' : '')} style={{
96
102
  top: 0,
97
103
  left: 0,
98
104
  transform: "translate(".concat(indicator.x, "px, ").concat(indicator.y, "px)"),
@@ -1,7 +1,7 @@
1
1
  import React from 'react';
2
2
  interface TableContainerProps {
3
3
  children: React.ReactNode;
4
- /** Names the table. Name it when it can overflow; a named table is a Tab stop. With a name the table sits in a scrollable `role="region"` of the same name that a keyboard can focus and scroll, for a table wider than a phone. */
4
+ /** Names the table. Name it when it can overflow; a named table is a Tab stop. With a name the table sits in a scrollable `role="region"` of the same name that a keyboard can focus and scroll, for a table wider than a phone. The scroll box is `relative`, so hidden text inside it (a `Link` with `announceNewTab`) scrolls with the table and never widens the page. */
5
5
  'aria-label'?: string;
6
6
  /** With `aria-label`: the width the table keeps, e.g. '640px', so its columns do not squeeze and the region scrolls sideways. Ignored without a name. */
7
7
  minWidth?: string;
@@ -4,13 +4,13 @@ import { focusRing } from './sharedStyles';
4
4
  export default function TableContainer(_a) {
5
5
  var children = _a.children, ariaLabel = _a["aria-label"], minWidth = _a.minWidth;
6
6
  if (ariaLabel) {
7
- return (<div role="region" aria-label={ariaLabel} tabIndex={0} className={"w-full overflow-x-auto bg-background-default rounded-control ".concat(focusRing)}>
7
+ return (<div role="region" aria-label={ariaLabel} tabIndex={0} className={"relative w-full overflow-x-auto bg-background-default rounded-control ".concat(focusRing)}>
8
8
  <div role="table" aria-label={ariaLabel} className="w-full bg-background-default" style={minWidth ? { minWidth: minWidth } : undefined}>
9
9
  {children}
10
10
  </div>
11
11
  </div>);
12
12
  }
13
- return (<div role="table" className="w-full overflow-x-auto bg-background-default">
13
+ return (<div role="table" className="relative w-full overflow-x-auto bg-background-default">
14
14
  {children}
15
15
  </div>);
16
16
  }
@@ -5,6 +5,8 @@ interface TimeStampProps {
5
5
  textSize?: 'small' | 'medium' | 'large';
6
6
  textColor?: 'secondary' | 'primary';
7
7
  data?: 'date-and-time' | 'date' | 'time';
8
+ /** With `absolute`: `'24'` prints 14:40 and `'12'` prints 2:40 PM. Default `'24'`. */
9
+ hourCycle?: '24' | '12';
8
10
  }
9
- export default function TimeStamp({ createdAt, dateFormat, textSize, textColor, data, }: TimeStampProps): React.JSX.Element;
11
+ export default function TimeStamp({ createdAt, dateFormat, textSize, textColor, data, hourCycle, }: TimeStampProps): React.JSX.Element;
10
12
  export {};