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/README.md CHANGED
@@ -70,7 +70,7 @@ import SectionIntro from 'oneslash-design-system/components/sectionIntro';
70
70
 
71
71
  ## Design cases
72
72
 
73
- A case is one design situation with oneSlash's answer to it. A rule case has one answer, such as "an agent asks before a risky action". A design case has one to four options, each with a line on when to use it and a working example built only from this package. 2.29.0 has 149: sixteen rules and 133 design cases for auth pages, confirms and modals, states, chat and agent interfaces, settings and menus, shells and navigation, dashboards and billing, marketing and content pages, forms with dates and files, onboarding, history and charts, cookies, newsletters and plan comparison.
73
+ A case is one design situation with oneSlash's answer to it. A rule case has one answer, such as "an agent asks before a risky action". A design case has one to four options, each with a line on when to use it and a working example built only from this package. 2.30.0 has 149: sixteen rules and 133 design cases for auth pages, confirms and modals, states, chat and agent interfaces, settings and menus, shells and navigation, dashboards and billing, marketing and content pages, forms with dates and files, onboarding, history and charts, cookies, newsletters and plan comparison.
74
74
 
75
75
  - `oneslash-design-system/cases.json` lists every case with its rule text, options, Do and Don't lines, and the source of each example.
76
76
  - `oneslash-design-system/cases/<id>.md` is one case as text, and `oneslash-design-system/cases/<id>/<option>.jsx` is the example itself.
@@ -1,6 +1,7 @@
1
1
  'use client';
2
2
  import { useEffect, useRef, useState } from 'react';
3
3
  import Heading from '../../components/heading';
4
+ import Alert from '../../components/alert';
4
5
  import Paragraph from '../../components/paragraph';
5
6
  import FormField from '../../components/formField';
6
7
  import RadioGroup from '../../components/radioGroup';
@@ -37,8 +38,9 @@ export default function AgentPermissionsLevels(_a) {
37
38
  <Stack gap="small">
38
39
  <Heading level={1} size="h5">Agent</Heading>
39
40
  <Paragraph tone="secondary" size="body2" measure="none">How Acme Agent works for everyone in this workspace.</Paragraph>
40
- {!canChange && <Paragraph tone="secondary" size="body2" measure="none">Only admins can change these settings. Your admin is Dana Lee.</Paragraph>}
41
41
  </Stack>
42
+ {/* One line at the top says why nothing can be changed, and who can. */}
43
+ {!canChange && <Alert type="info" variant="inline" message="Only admins can change these settings. Your admin is Dana Lee." autoDismiss={false}/>}
42
44
  <SettingsSection title="What Acme Agent does alone" description="Your choice saves as soon as you make it.">
43
45
  <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.">
44
46
  {function (f) { return (<RadioGroup id={f.id} aria-describedby={f['aria-describedby']} aria-label="Level" options={levels} selectedValue={level} disabled={!canChange || saving} onChange={choose}/>); }}
@@ -13,6 +13,7 @@ var __assign = (this && this.__assign) || function () {
13
13
  import { useEffect, useRef, useState } from 'react';
14
14
  import Toaster, { toast, dismissToast } from '../../components/toaster';
15
15
  import Heading from '../../components/heading';
16
+ import Alert from '../../components/alert';
16
17
  import Paragraph from '../../components/paragraph';
17
18
  import SegmentedControl from '../../components/segmentedControl';
18
19
  import SettingsSection from '../../components/settingsSection';
@@ -77,7 +78,7 @@ export default function AgentPermissionsPerTool(_a) {
77
78
  timers.current.push(setTimeout(callback, ms));
78
79
  }
79
80
  // Each row's choice stands alone, so it saves as soon as it is made, and shows nothing when it works.
80
- // SegmentedControl cannot be disabled, so a press on a row that is still saving does nothing.
81
+ // A press on a row that is still saving does nothing. The row stays enabled, so focus stays on it.
81
82
  function choose(tool, next) {
82
83
  if (!canChange || savingTool === tool.id || next === settings[tool.id])
83
84
  return;
@@ -124,8 +125,9 @@ export default function AgentPermissionsPerTool(_a) {
124
125
  <Stack gap="small">
125
126
  <Heading level={1} size="h5">Agent tools</Heading>
126
127
  <Paragraph tone="secondary" size="body2" measure="none">What Acme Agent may do in this workspace, for everyone.</Paragraph>
127
- {!canChange && <Paragraph tone="secondary" size="body2" measure="none">Only admins can change these settings. Your admin is Dana Lee.</Paragraph>}
128
128
  </Stack>
129
+ {/* One line at the top says why nothing can be changed, and who can. */}
130
+ {!canChange && <Alert type="info" variant="inline" message="Only admins can change these settings. Your admin is Dana Lee." autoDismiss={false}/>}
129
131
 
130
132
  <SettingsSection title="Tools" description="Each choice saves as soon as you make it. Ask means Acme Agent asks before each use.">
131
133
  <TableContainer>
@@ -145,7 +147,7 @@ export default function AgentPermissionsPerTool(_a) {
145
147
  </Stack>
146
148
  </TableCell>
147
149
  <TableCell width="184px">
148
- <SegmentedControl size="small" aria-label={t.name} options={t.risky ? riskyOptions : allOptions} value={settings[t.id]} onChange={function (next) { return choose(t, next); }}/>
150
+ <SegmentedControl size="small" aria-label={t.name} options={t.risky ? riskyOptions : allOptions} value={settings[t.id]} disabled={!canChange} onChange={function (next) { return choose(t, next); }}/>
149
151
  </TableCell>
150
152
  </TableRow>);
151
153
  })}
@@ -32,12 +32,13 @@ For: an app, an agent
32
32
 
33
33
  Use when: One setting for how much the agent does without asking is enough.
34
34
 
35
- Uses: `Center`, `FormField`, `Heading`, `Paragraph`, `RadioGroup`, `SettingsSection`, `Stack`
35
+ Uses: `Alert`, `Center`, `FormField`, `Heading`, `Paragraph`, `RadioGroup`, `SettingsSection`, `Stack`
36
36
 
37
37
  ```tsx
38
38
  'use client';
39
39
  import { useEffect, useRef, useState } from 'react';
40
40
  import Heading from 'oneslash-design-system/components/heading';
41
+ import Alert from 'oneslash-design-system/components/alert';
41
42
  import Paragraph from 'oneslash-design-system/components/paragraph';
42
43
  import FormField from 'oneslash-design-system/components/formField';
43
44
  import RadioGroup from 'oneslash-design-system/components/radioGroup';
@@ -78,8 +79,9 @@ export default function AgentPermissionsLevels({ canChange = true }: { canChange
78
79
  <Stack gap="small">
79
80
  <Heading level={1} size="h5">Agent</Heading>
80
81
  <Paragraph tone="secondary" size="body2" measure="none">How Acme Agent works for everyone in this workspace.</Paragraph>
81
- {!canChange && <Paragraph tone="secondary" size="body2" measure="none">Only admins can change these settings. Your admin is Dana Lee.</Paragraph>}
82
82
  </Stack>
83
+ {/* One line at the top says why nothing can be changed, and who can. */}
84
+ {!canChange && <Alert type="info" variant="inline" message="Only admins can change these settings. Your admin is Dana Lee." autoDismiss={false} />}
83
85
  <SettingsSection title="What Acme Agent does alone" description="Your choice saves as soon as you make it.">
84
86
  <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.">
85
87
  {(f) => (
@@ -105,13 +107,14 @@ export default function AgentPermissionsLevels({ canChange = true }: { canChange
105
107
 
106
108
  Use when: An admin sets each tool or action on its own.
107
109
 
108
- Uses: `Button`, `Center`, `Cluster`, `EmptyBox`, `Heading`, `Paragraph`, `SegmentedControl`, `SettingsSection`, `Stack`, `TableCell`, `TableContainer`, `TableHeader`, `TableHeaderCell`, `TableRow`, `Toaster`, `dismissToast`, `toast`
110
+ Uses: `Alert`, `Button`, `Center`, `Cluster`, `EmptyBox`, `Heading`, `Paragraph`, `SegmentedControl`, `SettingsSection`, `Stack`, `TableCell`, `TableContainer`, `TableHeader`, `TableHeaderCell`, `TableRow`, `Toaster`, `dismissToast`, `toast`
109
111
 
110
112
  ```tsx
111
113
  'use client';
112
114
  import { useEffect, useRef, useState } from 'react';
113
115
  import Toaster, { toast, dismissToast } from 'oneslash-design-system/components/toaster';
114
116
  import Heading from 'oneslash-design-system/components/heading';
117
+ import Alert from 'oneslash-design-system/components/alert';
115
118
  import Paragraph from 'oneslash-design-system/components/paragraph';
116
119
  import SegmentedControl from 'oneslash-design-system/components/segmentedControl';
117
120
  import SettingsSection from 'oneslash-design-system/components/settingsSection';
@@ -190,7 +193,7 @@ export default function AgentPermissionsPerTool({ canChange = true }: { canChang
190
193
  }
191
194
 
192
195
  // Each row's choice stands alone, so it saves as soon as it is made, and shows nothing when it works.
193
- // SegmentedControl cannot be disabled, so a press on a row that is still saving does nothing.
196
+ // A press on a row that is still saving does nothing. The row stays enabled, so focus stays on it.
194
197
  function choose(tool: Tool, next: string) {
195
198
  if (!canChange || savingTool === tool.id || next === settings[tool.id]) return;
196
199
  setSettings((current) => ({ ...current, [tool.id]: next as Setting }));
@@ -235,8 +238,9 @@ export default function AgentPermissionsPerTool({ canChange = true }: { canChang
235
238
  <Stack gap="small">
236
239
  <Heading level={1} size="h5">Agent tools</Heading>
237
240
  <Paragraph tone="secondary" size="body2" measure="none">What Acme Agent may do in this workspace, for everyone.</Paragraph>
238
- {!canChange && <Paragraph tone="secondary" size="body2" measure="none">Only admins can change these settings. Your admin is Dana Lee.</Paragraph>}
239
241
  </Stack>
242
+ {/* One line at the top says why nothing can be changed, and who can. */}
243
+ {!canChange && <Alert type="info" variant="inline" message="Only admins can change these settings. Your admin is Dana Lee." autoDismiss={false} />}
240
244
 
241
245
  <SettingsSection title="Tools" description="Each choice saves as soon as you make it. Ask means Acme Agent asks before each use.">
242
246
  <TableContainer>
@@ -260,6 +264,7 @@ export default function AgentPermissionsPerTool({ canChange = true }: { canChang
260
264
  aria-label={t.name}
261
265
  options={t.risky ? riskyOptions : allOptions}
262
266
  value={settings[t.id]}
267
+ disabled={!canChange}
263
268
  onChange={(next) => choose(t, next)}
264
269
  />
265
270
  </TableCell>
@@ -76,7 +76,6 @@ export default function BulkActionsList() {
76
76
  var _g = useState(false), deleting = _g[0], setDeleting = _g[1];
77
77
  var timer = useRef();
78
78
  var toastIds = useRef([]);
79
- // Holds the header Checkbox. Checkbox takes no ref, so focus goes to the box inside this line.
80
79
  var headerBox = useRef(null);
81
80
  // With no task left there is no header Checkbox, so focus goes to Add Task.
82
81
  var addTask = useRef(null);
@@ -93,7 +92,7 @@ export default function BulkActionsList() {
93
92
  focusNext.current = undefined;
94
93
  move === null || move === void 0 ? void 0 : move();
95
94
  });
96
- var headerCheckbox = function () { var _a, _b; return (_b = (_a = headerBox.current) === null || _a === void 0 ? void 0 : _a.querySelector('input')) !== null && _b !== void 0 ? _b : addTask.current; };
95
+ var headerCheckbox = function () { var _a; return (_a = headerBox.current) !== null && _a !== void 0 ? _a : addTask.current; };
97
96
  var pickedTasks = tasks.filter(function (t) { return picked.includes(t.id); });
98
97
  var count = pickedTasks.length;
99
98
  var all = tasks.length > 0 && count === tasks.length;
@@ -165,9 +164,7 @@ export default function BulkActionsList() {
165
164
  <TableHeader>
166
165
  <TableRow>
167
166
  <TableHeaderCell width="48px">
168
- <Paragraph ref={headerBox} measure="none">
169
- <Checkbox aria-label="Select all tasks" checked={all} indeterminate={count > 0 && !all} onChange={toggleAll}/>
170
- </Paragraph>
167
+ <Checkbox ref={headerBox} aria-label="Select all tasks" checked={all} indeterminate={count > 0 && !all} onChange={toggleAll}/>
171
168
  </TableHeaderCell>
172
169
  <TableHeaderCell>Task</TableHeaderCell>
173
170
  <TableHeaderCell width="140px">Assignee</TableHeaderCell>
@@ -85,7 +85,6 @@ export default function BulkActionsPagedTable() {
85
85
  var clearButton = useRef(null);
86
86
  // With no invoice left there is no header Checkbox, so focus goes to the empty state's Button.
87
87
  var createButton = useRef(null);
88
- // Holds the header Checkbox. Checkbox takes no ref, so focus goes to the box inside this line.
89
88
  var headerBox = useRef(null);
90
89
  // Where focus goes after the next render, once the element it goes to is on screen.
91
90
  var focusNext = useRef();
@@ -100,7 +99,7 @@ export default function BulkActionsPagedTable() {
100
99
  focusNext.current = undefined;
101
100
  move === null || move === void 0 ? void 0 : move();
102
101
  });
103
- var headerCheckbox = function () { var _a, _b; return (_b = (_a = headerBox.current) === null || _a === void 0 ? void 0 : _a.querySelector('input')) !== null && _b !== void 0 ? _b : createButton.current; };
102
+ var headerCheckbox = function () { var _a; return (_a = headerBox.current) !== null && _a !== void 0 ? _a : createButton.current; };
104
103
  var pageCount = Math.ceil(invoices.length / PAGE_SIZE);
105
104
  var rows = invoices.slice((page - 1) * PAGE_SIZE, page * PAGE_SIZE);
106
105
  var pickedInvoices = invoices.filter(function (inv) { return picked.includes(inv.id); });
@@ -175,7 +174,7 @@ export default function BulkActionsPagedTable() {
175
174
  <Paragraph id="bulk-actions-paged-table-count" role="status" size="body2" measure="none">
176
175
  {count > 0 ? "".concat(formatCount(count), " selected") : ''}
177
176
  </Paragraph>
178
- {count > 0 && !everyRow && (<Button size="small" type="textOnly" state="enabled" label={"Select All ".concat(formatCount(invoices.length))} onClickButton={pickEveryRow}/>)}
177
+ {count > 0 && !everyRow && (<Button size="small" type="tertiary" state="enabled" label={"Select All ".concat(formatCount(invoices.length))} onClickButton={pickEveryRow}/>)}
179
178
  </Cluster>
180
179
  {count > 0 ? (<Cluster gap="small">
181
180
  <Button size="small" type="secondary" state="enabled" label="Export" onClickButton={function () { return toastIds.current.push(toast({ type: 'success', message: "Export of ".concat(plural(count), " sent to dana@acme.example.") })); }}/>
@@ -198,9 +197,7 @@ export default function BulkActionsPagedTable() {
198
197
  <TableHeader>
199
198
  <TableRow>
200
199
  <TableHeaderCell width="48px">
201
- <Paragraph ref={headerBox} measure="none">
202
- <Checkbox aria-label="Select all invoices on this page" checked={wholePage} indeterminate={onPage > 0 && !wholePage} onChange={togglePage}/>
203
- </Paragraph>
200
+ <Checkbox ref={headerBox} aria-label="Select all invoices on this page" checked={wholePage} indeterminate={onPage > 0 && !wholePage} onChange={togglePage}/>
204
201
  </TableHeaderCell>
205
202
  <TableHeaderCell width="110px">Invoice</TableHeaderCell>
206
203
  <TableHeaderCell>Customer</TableHeaderCell>
@@ -13,7 +13,7 @@ For: an app
13
13
  - Give the count `role="status"` and keep it on the page, so a screen reader hears each new count once.
14
14
  - Name the More menu for the rows it acts on: 'More actions for 3 tasks'. Follow the case 'More menu'.
15
15
  - Follow the case 'Data table page' for a table over many pages. The header Checkbox picks the rows of the page shown.
16
- - 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'.
16
+ - 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'.
17
17
  - Keep the picked rows when the person changes page, sorts or comes back.
18
18
  - Confirm a delete in a small Modal, as the case 'Delete confirm' does, titled with the count: 'Delete 3 Invoices'.
19
19
  - Move focus to the header Checkbox after 'Clear Selection' and after a delete, because the bar and its Buttons are gone.
@@ -98,8 +98,7 @@ export default function BulkActionsList() {
98
98
  const [deleting, setDeleting] = useState(false);
99
99
  const timer = useRef<ReturnType<typeof setTimeout>>();
100
100
  const toastIds = useRef<string[]>([]);
101
- // Holds the header Checkbox. Checkbox takes no ref, so focus goes to the box inside this line.
102
- const headerBox = useRef<HTMLParagraphElement>(null);
101
+ const headerBox = useRef<HTMLInputElement>(null);
103
102
  // With no task left there is no header Checkbox, so focus goes to Add Task.
104
103
  const addTask = useRef<HTMLButtonElement | HTMLAnchorElement | null>(null);
105
104
  // Where focus goes after the next render, once the element it goes to is on screen.
@@ -118,7 +117,7 @@ export default function BulkActionsList() {
118
117
  move?.();
119
118
  });
120
119
 
121
- const headerCheckbox = () => headerBox.current?.querySelector('input') ?? addTask.current;
120
+ const headerCheckbox = () => headerBox.current ?? addTask.current;
122
121
  const pickedTasks = tasks.filter((t) => picked.includes(t.id));
123
122
  const count = pickedTasks.length;
124
123
  const all = tasks.length > 0 && count === tasks.length;
@@ -213,9 +212,7 @@ export default function BulkActionsList() {
213
212
  <TableHeader>
214
213
  <TableRow>
215
214
  <TableHeaderCell width="48px">
216
- <Paragraph ref={headerBox} measure="none">
217
- <Checkbox aria-label="Select all tasks" checked={all} indeterminate={count > 0 && !all} onChange={toggleAll} />
218
- </Paragraph>
215
+ <Checkbox ref={headerBox} aria-label="Select all tasks" checked={all} indeterminate={count > 0 && !all} onChange={toggleAll} />
219
216
  </TableHeaderCell>
220
217
  <TableHeaderCell>Task</TableHeaderCell>
221
218
  <TableHeaderCell width="140px">Assignee</TableHeaderCell>
@@ -347,8 +344,7 @@ export default function BulkActionsPagedTable() {
347
344
  const clearButton = useRef<Focusable>(null);
348
345
  // With no invoice left there is no header Checkbox, so focus goes to the empty state's Button.
349
346
  const createButton = useRef<Focusable>(null);
350
- // Holds the header Checkbox. Checkbox takes no ref, so focus goes to the box inside this line.
351
- const headerBox = useRef<HTMLParagraphElement>(null);
347
+ const headerBox = useRef<HTMLInputElement>(null);
352
348
  // Where focus goes after the next render, once the element it goes to is on screen.
353
349
  const focusNext = useRef<() => void>();
354
350
 
@@ -365,7 +361,7 @@ export default function BulkActionsPagedTable() {
365
361
  move?.();
366
362
  });
367
363
 
368
- const headerCheckbox = () => headerBox.current?.querySelector('input') ?? createButton.current;
364
+ const headerCheckbox = () => headerBox.current ?? createButton.current;
369
365
  const pageCount = Math.ceil(invoices.length / PAGE_SIZE);
370
366
  const rows = invoices.slice((page - 1) * PAGE_SIZE, page * PAGE_SIZE);
371
367
  const pickedInvoices = invoices.filter((inv) => picked.includes(inv.id));
@@ -449,7 +445,7 @@ export default function BulkActionsPagedTable() {
449
445
  {count > 0 ? `${formatCount(count)} selected` : ''}
450
446
  </Paragraph>
451
447
  {count > 0 && !everyRow && (
452
- <Button size="small" type="textOnly" state="enabled" label={`Select All ${formatCount(invoices.length)}`} onClickButton={pickEveryRow} />
448
+ <Button size="small" type="tertiary" state="enabled" label={`Select All ${formatCount(invoices.length)}`} onClickButton={pickEveryRow} />
453
449
  )}
454
450
  </Cluster>
455
451
  {count > 0 ? (
@@ -493,9 +489,7 @@ export default function BulkActionsPagedTable() {
493
489
  <TableHeader>
494
490
  <TableRow>
495
491
  <TableHeaderCell width="48px">
496
- <Paragraph ref={headerBox} measure="none">
497
- <Checkbox aria-label="Select all invoices on this page" checked={wholePage} indeterminate={onPage > 0 && !wholePage} onChange={togglePage} />
498
- </Paragraph>
492
+ <Checkbox ref={headerBox} aria-label="Select all invoices on this page" checked={wholePage} indeterminate={onPage > 0 && !wholePage} onChange={togglePage} />
499
493
  </TableHeaderCell>
500
494
  <TableHeaderCell width="110px">Invoice</TableHeaderCell>
501
495
  <TableHeaderCell>Customer</TableHeaderCell>
@@ -1,3 +1 @@
1
- export default function ProductDemoScripted({ autoPlay }?: {
2
- autoPlay?: boolean;
3
- }): import("react").JSX.Element;
1
+ export default function ProductDemoScripted(): import("react").JSX.Element;
@@ -13,6 +13,7 @@ import Button from '../../components/button';
13
13
  import SegmentedControl from '../../components/segmentedControl';
14
14
  import StepList from '../../components/stepList';
15
15
  import SourceCard from '../../components/sourceCard';
16
+ import useReducedMotion from '../../components/useReducedMotion';
16
17
  import { Cluster, Grid, PageSection, Stack } from '../../components/layout';
17
18
  var agentName = 'Acme Agent';
18
19
  // A made-up thread. Every label in it is one the app has: the agent's marks, its steps and its source cards.
@@ -34,22 +35,25 @@ function agentMeta(at) {
34
35
  <Paragraph size="caption" tone="secondary" measure="none">Model name</Paragraph>
35
36
  </>);
36
37
  }
37
- // `autoPlay` starts the scenes when the page opens. A real site passes it only when the visitor has not asked for
38
- // reduced motion, from `matchMedia('(prefers-reduced-motion: reduce)')`. Left out, the demo waits for the visitor.
39
- export default function ProductDemoScripted(_a) {
40
- var _b = _a === void 0 ? {} : _a, _c = _b.autoPlay, autoPlay = _c === void 0 ? false : _c;
41
- var _d = useState(autoPlay ? 'ask' : 'answer'), scene = _d[0], setScene = _d[1];
42
- var _e = useState(!autoPlay), paused = _e[0], setPaused = _e[1];
38
+ export default function ProductDemoScripted() {
39
+ // The scenes start when the page opens, unless the visitor asks for reduced motion. Then the demo waits for
40
+ // 'Play' and shows the answer. Once the visitor plays, pauses or picks a scene, their choice stands.
41
+ var reducedMotion = useReducedMotion();
42
+ var _a = useState(null), chosenPaused = _a[0], setChosenPaused = _a[1];
43
+ var _b = useState(null), chosenScene = _b[0], setChosenScene = _b[1];
44
+ var paused = chosenPaused !== null && chosenPaused !== void 0 ? chosenPaused : reducedMotion;
45
+ var scene = chosenScene !== null && chosenScene !== void 0 ? chosenScene : (paused ? 'answer' : 'ask');
46
+ var setPaused = setChosenPaused;
43
47
  var timer = useRef();
44
48
  // Moves to the next scene while the demo plays, and stops when it is paused or leaves the page.
45
49
  useEffect(function () {
46
50
  if (paused)
47
51
  return undefined;
48
52
  timer.current = setInterval(function () {
49
- setScene(function (s) { return scenes[(scenes.findIndex(function (x) { return x.value === s; }) + 1) % scenes.length].value; });
53
+ setChosenScene(scenes[(scenes.findIndex(function (x) { return x.value === scene; }) + 1) % scenes.length].value);
50
54
  }, sceneTime);
51
55
  return function () { return clearInterval(timer.current); };
52
- }, [paused]);
56
+ }, [paused, scene]);
53
57
  var at = scenes.findIndex(function (x) { return x.value === scene; });
54
58
  return (<PageShell>
55
59
  <PageSection gap="xxlarge">
@@ -61,10 +65,10 @@ export default function ProductDemoScripted(_a) {
61
65
  says what pressing it does, so focus stays on it when the label changes. Picking a scene pauses too. */}
62
66
  <Cluster justify="between">
63
67
  <Cluster gap="xlarge">
64
- <Button size="small" type="secondary" state="enabled" label={paused ? 'Play' : 'Pause'} onClickButton={function () { return setPaused(function (p) { return !p; }); }}/>
68
+ <Button size="small" type="secondary" state="enabled" label={paused ? 'Play' : 'Pause'} onClickButton={function () { return setPaused(!paused); }}/>
65
69
  <SegmentedControl size="small" width="fit" aria-label="Scene" options={scenes} value={scene} onChange={function (value) {
66
70
  setPaused(true);
67
- setScene(value);
71
+ setChosenScene(value);
68
72
  }}/>
69
73
  </Cluster>
70
74
  <Tag variant="textOnly" size="small" label="Example"/>
@@ -69,7 +69,7 @@ export default function ProductDemoStill() {
69
69
 
70
70
  Use when: The product is about a flow, such as asking an agent and getting an answer.
71
71
 
72
- Uses: `Button`, `Cluster`, `Grid`, `Message`, `PageSection`, `PageShell`, `Paragraph`, `SectionIntro`, `SegmentedControl`, `SourceCard`, `Stack`, `StepList`, `Surface`, `Tag`, `TimeStamp`, `UserImage`
72
+ Uses: `Button`, `Cluster`, `Grid`, `Message`, `PageSection`, `PageShell`, `Paragraph`, `SectionIntro`, `SegmentedControl`, `SourceCard`, `Stack`, `StepList`, `Surface`, `Tag`, `TimeStamp`, `UserImage`, `useReducedMotion`
73
73
 
74
74
  ```tsx
75
75
  'use client';
@@ -87,6 +87,7 @@ import Button from 'oneslash-design-system/components/button';
87
87
  import SegmentedControl from 'oneslash-design-system/components/segmentedControl';
88
88
  import StepList from 'oneslash-design-system/components/stepList';
89
89
  import SourceCard from 'oneslash-design-system/components/sourceCard';
90
+ import useReducedMotion from 'oneslash-design-system/components/useReducedMotion';
90
91
  import { Cluster, Grid, PageSection, Stack } from 'oneslash-design-system/components/layout';
91
92
 
92
93
  const agentName = 'Acme Agent';
@@ -116,21 +117,25 @@ function agentMeta(at: Date) {
116
117
  );
117
118
  }
118
119
 
119
- // `autoPlay` starts the scenes when the page opens. A real site passes it only when the visitor has not asked for
120
- // reduced motion, from `matchMedia('(prefers-reduced-motion: reduce)')`. Left out, the demo waits for the visitor.
121
- export default function ProductDemoScripted({ autoPlay = false }: { autoPlay?: boolean } = {}) {
122
- const [scene, setScene] = useState(autoPlay ? 'ask' : 'answer');
123
- const [paused, setPaused] = useState(!autoPlay);
120
+ export default function ProductDemoScripted() {
121
+ // The scenes start when the page opens, unless the visitor asks for reduced motion. Then the demo waits for
122
+ // 'Play' and shows the answer. Once the visitor plays, pauses or picks a scene, their choice stands.
123
+ const reducedMotion = useReducedMotion();
124
+ const [chosenPaused, setChosenPaused] = useState<boolean | null>(null);
125
+ const [chosenScene, setChosenScene] = useState<string | null>(null);
126
+ const paused = chosenPaused ?? reducedMotion;
127
+ const scene = chosenScene ?? (paused ? 'answer' : 'ask');
128
+ const setPaused = setChosenPaused;
124
129
  const timer = useRef<ReturnType<typeof setInterval>>();
125
130
 
126
131
  // Moves to the next scene while the demo plays, and stops when it is paused or leaves the page.
127
132
  useEffect(() => {
128
133
  if (paused) return undefined;
129
134
  timer.current = setInterval(() => {
130
- setScene((s) => scenes[(scenes.findIndex((x) => x.value === s) + 1) % scenes.length].value);
135
+ setChosenScene(scenes[(scenes.findIndex((x) => x.value === scene) + 1) % scenes.length].value);
131
136
  }, sceneTime);
132
137
  return () => clearInterval(timer.current);
133
- }, [paused]);
138
+ }, [paused, scene]);
134
139
 
135
140
  const at = scenes.findIndex((x) => x.value === scene);
136
141
 
@@ -150,7 +155,7 @@ export default function ProductDemoScripted({ autoPlay = false }: { autoPlay?: b
150
155
  type="secondary"
151
156
  state="enabled"
152
157
  label={paused ? 'Play' : 'Pause'}
153
- onClickButton={() => setPaused((p) => !p)}
158
+ onClickButton={() => setPaused(!paused)}
154
159
  />
155
160
  <SegmentedControl
156
161
  size="small"
@@ -160,7 +165,7 @@ export default function ProductDemoScripted({ autoPlay = false }: { autoPlay?: b
160
165
  value={scene}
161
166
  onChange={(value) => {
162
167
  setPaused(true);
163
- setScene(value);
168
+ setChosenScene(value);
164
169
  }}
165
170
  />
166
171
  </Cluster>