oneslash-design-system 2.16.0 → 2.17.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 (151) hide show
  1. package/README.md +1 -1
  2. package/dist/DESIGN.md +26 -3
  3. package/dist/cases/accept-invite/signed-in.jsx +1 -1
  4. package/dist/cases/accept-invite/signed-out.jsx +1 -1
  5. package/dist/cases/accept-invite.md +2 -2
  6. package/dist/cases/agent-options/cards.d.ts +1 -0
  7. package/dist/cases/agent-options/cards.jsx +91 -0
  8. package/dist/cases/agent-options.md +168 -0
  9. package/dist/cases/agent-pending-reply/steps.d.ts +1 -0
  10. package/dist/cases/agent-pending-reply/steps.jsx +149 -0
  11. package/dist/cases/agent-pending-reply/streaming.d.ts +1 -0
  12. package/dist/cases/agent-pending-reply/streaming.jsx +146 -0
  13. package/dist/cases/agent-pending-reply.md +432 -0
  14. package/dist/cases/agent-plan-proposal/changes.d.ts +1 -0
  15. package/dist/cases/agent-plan-proposal/changes.jsx +224 -0
  16. package/dist/cases/agent-plan-proposal/steps.d.ts +1 -0
  17. package/dist/cases/agent-plan-proposal/steps.jsx +211 -0
  18. package/dist/cases/agent-plan-proposal.md +656 -0
  19. package/dist/cases/agent-question/choices.d.ts +1 -0
  20. package/dist/cases/agent-question/choices.jsx +132 -0
  21. package/dist/cases/agent-question/free-text.d.ts +1 -0
  22. package/dist/cases/agent-question/free-text.jsx +81 -0
  23. package/dist/cases/agent-question.md +338 -0
  24. package/dist/cases/agent-shows-sources.md +2 -2
  25. package/dist/cases/artifact-card/card.d.ts +1 -0
  26. package/dist/cases/artifact-card/card.jsx +45 -0
  27. package/dist/cases/artifact-card.md +103 -0
  28. package/dist/cases/composer-limit/notice-with-action.d.ts +1 -0
  29. package/dist/cases/composer-limit/notice-with-action.jsx +87 -0
  30. package/dist/cases/composer-limit/notice.d.ts +1 -0
  31. package/dist/cases/composer-limit/notice.jsx +84 -0
  32. package/dist/cases/composer-limit.md +286 -0
  33. package/dist/cases/conversation-starters/chips.d.ts +1 -0
  34. package/dist/cases/conversation-starters/chips.jsx +69 -0
  35. package/dist/cases/conversation-starters/none.d.ts +1 -0
  36. package/dist/cases/conversation-starters/none.jsx +45 -0
  37. package/dist/cases/conversation-starters.md +208 -0
  38. package/dist/cases/mention-list/in-composer.d.ts +1 -0
  39. package/dist/cases/mention-list/in-composer.jsx +169 -0
  40. package/dist/cases/mention-list.md +252 -0
  41. package/dist/cases/message-actions/hover-toolbar.d.ts +1 -0
  42. package/dist/cases/message-actions/hover-toolbar.jsx +229 -0
  43. package/dist/cases/message-actions/menu.d.ts +1 -0
  44. package/dist/cases/message-actions/menu.jsx +258 -0
  45. package/dist/cases/message-actions.md +651 -0
  46. package/dist/cases/message-attachments/in-composer.d.ts +1 -0
  47. package/dist/cases/message-attachments/in-composer.jsx +134 -0
  48. package/dist/cases/message-attachments/in-message.d.ts +1 -0
  49. package/dist/cases/message-attachments/in-message.jsx +46 -0
  50. package/dist/cases/message-attachments.md +310 -0
  51. package/dist/cases/message-composer/plain.d.ts +1 -0
  52. package/dist/cases/message-composer/plain.jsx +57 -0
  53. package/dist/cases/message-composer/with-tools.d.ts +1 -0
  54. package/dist/cases/message-composer/with-tools.jsx +182 -0
  55. package/dist/cases/message-composer.md +356 -0
  56. package/dist/cases/message-edit/in-place.d.ts +1 -0
  57. package/dist/cases/message-edit/in-place.jsx +99 -0
  58. package/dist/cases/message-edit.md +179 -0
  59. package/dist/cases/message-reactions/chips.d.ts +1 -0
  60. package/dist/cases/message-reactions/chips.jsx +118 -0
  61. package/dist/cases/message-reactions/quick-pick.d.ts +1 -0
  62. package/dist/cases/message-reactions/quick-pick.jsx +155 -0
  63. package/dist/cases/message-reactions.md +371 -0
  64. package/dist/cases/message-row/grouped.d.ts +1 -0
  65. package/dist/cases/message-row/grouped.jsx +56 -0
  66. package/dist/cases/message-row/person-and-agent.d.ts +1 -0
  67. package/dist/cases/message-row/person-and-agent.jsx +41 -0
  68. package/dist/cases/message-row.md +189 -0
  69. package/dist/cases/reply-feedback/thumbs.d.ts +1 -0
  70. package/dist/cases/reply-feedback/thumbs.jsx +191 -0
  71. package/dist/cases/reply-feedback/with-reason.d.ts +1 -0
  72. package/dist/cases/reply-feedback/with-reason.jsx +221 -0
  73. package/dist/cases/reply-feedback.md +552 -0
  74. package/dist/cases/reply-sources/cards.d.ts +1 -0
  75. package/dist/cases/reply-sources/cards.jsx +83 -0
  76. package/dist/cases/reply-sources/tag-only.d.ts +1 -0
  77. package/dist/cases/reply-sources/tag-only.jsx +45 -0
  78. package/dist/cases/reply-sources.md +247 -0
  79. package/dist/cases/slash-command-list/in-composer.d.ts +1 -0
  80. package/dist/cases/slash-command-list/in-composer.jsx +162 -0
  81. package/dist/cases/slash-command-list.md +247 -0
  82. package/dist/cases/success-feedback.md +1 -1
  83. package/dist/cases/typing-and-status/line.d.ts +1 -0
  84. package/dist/cases/typing-and-status/line.jsx +50 -0
  85. package/dist/cases/typing-and-status.md +96 -0
  86. package/dist/cases.json +1276 -14
  87. package/dist/components/button.d.ts +3 -2
  88. package/dist/components/button.jsx +9 -7
  89. package/dist/components/composer.d.ts +74 -0
  90. package/dist/components/composer.jsx +122 -0
  91. package/dist/components/fileChip.d.ts +33 -0
  92. package/dist/components/fileChip.jsx +61 -0
  93. package/dist/components/iconButton.d.ts +3 -3
  94. package/dist/components/iconButton.jsx +9 -7
  95. package/dist/components/layout.d.ts +7 -1
  96. package/dist/components/layout.jsx +5 -2
  97. package/dist/components/menu.d.ts +21 -0
  98. package/dist/components/menu.jsx +27 -3
  99. package/dist/components/menuItem.d.ts +9 -1
  100. package/dist/components/menuItem.jsx +5 -4
  101. package/dist/components/message.d.ts +28 -0
  102. package/dist/components/message.jsx +25 -0
  103. package/dist/components/paragraph.d.ts +3 -1
  104. package/dist/components/paragraph.jsx +2 -2
  105. package/dist/components/popover.d.ts +7 -1
  106. package/dist/components/popover.jsx +35 -9
  107. package/dist/components/radioGroup.d.ts +8 -1
  108. package/dist/components/radioGroup.jsx +19 -8
  109. package/dist/components/sourceCard.d.ts +23 -0
  110. package/dist/components/sourceCard.jsx +56 -0
  111. package/dist/components/stepList.d.ts +17 -0
  112. package/dist/components/stepList.jsx +79 -0
  113. package/dist/components/tag.d.ts +9 -1
  114. package/dist/components/tag.jsx +6 -4
  115. package/dist/components/textarea.jsx +3 -18
  116. package/dist/components/userImage.d.ts +9 -1
  117. package/dist/components/userImage.jsx +10 -3
  118. package/dist/internal/autoGrow.d.ts +11 -0
  119. package/dist/internal/autoGrow.js +28 -0
  120. package/dist/internal/composer.d.ts +16 -0
  121. package/dist/internal/composer.js +18 -0
  122. package/dist/internal/menu.d.ts +6 -0
  123. package/dist/internal/menu.js +31 -0
  124. package/dist/native-mapping.json +32 -1
  125. package/dist/stories/Button.stories.d.ts +1 -0
  126. package/dist/stories/Button.stories.jsx +17 -1
  127. package/dist/stories/Cases.generated.stories.d.ts +30 -0
  128. package/dist/stories/Cases.generated.stories.jsx +60 -0
  129. package/dist/stories/Composer.stories.d.ts +23 -0
  130. package/dist/stories/Composer.stories.jsx +121 -0
  131. package/dist/stories/FileChip.stories.d.ts +7 -0
  132. package/dist/stories/FileChip.stories.jsx +35 -0
  133. package/dist/stories/IconButton.stories.d.ts +1 -0
  134. package/dist/stories/IconButton.stories.jsx +18 -1
  135. package/dist/stories/Menu.stories.d.ts +4 -0
  136. package/dist/stories/Menu.stories.jsx +46 -1
  137. package/dist/stories/MenuItem.stories.d.ts +1 -0
  138. package/dist/stories/MenuItem.stories.jsx +8 -0
  139. package/dist/stories/Message.stories.d.ts +10 -0
  140. package/dist/stories/Message.stories.jsx +77 -0
  141. package/dist/stories/PageComponents.stories.d.ts +1 -0
  142. package/dist/stories/PageComponents.stories.jsx +21 -0
  143. package/dist/stories/RadioGroup.stories.d.ts +2 -0
  144. package/dist/stories/RadioGroup.stories.jsx +40 -1
  145. package/dist/stories/SourceCard.stories.d.ts +8 -0
  146. package/dist/stories/SourceCard.stories.jsx +33 -0
  147. package/dist/stories/StepList.stories.d.ts +8 -0
  148. package/dist/stories/StepList.stories.jsx +35 -0
  149. package/dist/stories/UserImage.stories.d.ts +2 -0
  150. package/dist/stories/UserImage.stories.jsx +19 -0
  151. package/package.json +4 -3
@@ -0,0 +1,191 @@
1
+ 'use client';
2
+ import { useEffect, useRef, useState } from 'react';
3
+ import { Bot } from 'lucide-react';
4
+ import Message from '../../components/message';
5
+ import UserImage from '../../components/userImage';
6
+ import Tag from '../../components/tag';
7
+ import TimeStamp from '../../components/timeStamp';
8
+ import Heading from '../../components/heading';
9
+ import Paragraph from '../../components/paragraph';
10
+ import Button from '../../components/button';
11
+ import IconButton from '../../components/iconButton';
12
+ import Tooltip from '../../components/tooltip';
13
+ import StepList from '../../components/stepList';
14
+ import { Center, Cluster, Stack } from '../../components/layout';
15
+ var agentName = 'Acme Agent';
16
+ var request = { from: 'Dana Lee', at: new Date('2025-01-15T11:40:00Z'), text: 'What changed in the new plans?' };
17
+ var firstRepliedAt = new Date('2025-01-15T11:41:00Z');
18
+ // Each Regenerate writes the next version of the reply.
19
+ var replies = [
20
+ 'Pro goes from $12 to $15 a month. There is a new Team plan at $25 per seat, and the Free plan stays the same.',
21
+ 'Two things changed. Pro now costs $15 a month instead of $12, and the new Team plan costs $25 per seat.',
22
+ ];
23
+ // Each step in plain words: what the agent is doing now, and what it did once the step is done.
24
+ var plan = [
25
+ { doing: 'Reading the thread', done: 'Read the thread' },
26
+ { doing: 'Writing a new reply', done: 'Wrote a new reply' },
27
+ ];
28
+ function stepsUpTo(current) {
29
+ return plan.slice(0, current + 1).map(function (s, i) { return (i < current ? { label: s.done, status: 'done' } : { label: s.doing, status: 'running' }); });
30
+ }
31
+ function secondsLine(seconds) {
32
+ return "Working for ".concat(seconds, " ").concat(seconds === 1 ? 'second' : 'seconds');
33
+ }
34
+ // The agent's marks, as the rule 'An agent says what it is' says. While a new reply is written there is
35
+ // no time to show: the old reply's time would be wrong for it.
36
+ function agentMeta(at) {
37
+ return (<>
38
+ <Tag variant="contained" size="small" label="Agent"/>
39
+ {at && <TimeStamp createdAt={at} dateFormat="absolute" data="time"/>}
40
+ <Paragraph size="caption" tone="secondary" measure="none">Model name</Paragraph>
41
+ </>);
42
+ }
43
+ export default function ReplyFeedbackThumbs() {
44
+ var _a = useState(null), thumb = _a[0], setThumb = _a[1];
45
+ var _b = useState(false), thanks = _b[0], setThanks = _b[1];
46
+ var _c = useState(false), copied = _c[0], setCopied = _c[1];
47
+ var _d = useState(0), version = _d[0], setVersion = _d[1];
48
+ // Each version of the reply has its own time: a regenerated reply shows when it was written.
49
+ var _e = useState(firstRepliedAt), repliedAt = _e[0], setRepliedAt = _e[1];
50
+ var _f = useState('reply'), phase = _f[0], setPhase = _f[1];
51
+ var _g = useState(0), current = _g[0], setCurrent = _g[1];
52
+ var _h = useState(0), seconds = _h[0], setSeconds = _h[1];
53
+ var _j = useState(false), stopped = _j[0], setStopped = _j[1];
54
+ var thanksTimer = useRef();
55
+ var copyTimer = useRef();
56
+ var tick = useRef();
57
+ var step = useRef();
58
+ var cancel = useRef();
59
+ var regenerateButton = useRef(null);
60
+ var stopButton = useRef(null);
61
+ // Where focus goes after the next render, once the element it goes to is on screen.
62
+ var focusNext = useRef();
63
+ // The clipboard answers later; by then the example may be gone.
64
+ var mounted = useRef(true);
65
+ // On unmount it stops every timer and the run.
66
+ useEffect(function () { return function () {
67
+ mounted.current = false;
68
+ clearTimeout(thanksTimer.current);
69
+ clearTimeout(copyTimer.current);
70
+ clearInterval(tick.current);
71
+ clearTimeout(step.current);
72
+ clearTimeout(cancel.current);
73
+ }; }, []);
74
+ useEffect(function () {
75
+ var move = focusNext.current;
76
+ focusNext.current = undefined;
77
+ move === null || move === void 0 ? void 0 : move();
78
+ });
79
+ var reply = replies[version];
80
+ // Pressing a thumb marks it, pressing it again clears it, and the other thumb moves the mark.
81
+ // A real app sends the mark to the server; the thanks is the only confirmation.
82
+ function mark(next) {
83
+ var value = thumb === next ? null : next;
84
+ setThumb(value);
85
+ clearTimeout(thanksTimer.current);
86
+ setThanks(value !== null);
87
+ if (value !== null)
88
+ thanksTimer.current = setTimeout(function () { return setThanks(false); }, 2000);
89
+ }
90
+ function copy() {
91
+ var _a;
92
+ (_a = navigator.clipboard) === null || _a === void 0 ? void 0 : _a.writeText(reply).then(function () {
93
+ if (!mounted.current)
94
+ return;
95
+ setCopied(true);
96
+ clearTimeout(copyTimer.current);
97
+ copyTimer.current = setTimeout(function () { return setCopied(false); }, 2000);
98
+ }, function () { });
99
+ }
100
+ function endRun() {
101
+ clearInterval(tick.current);
102
+ clearTimeout(step.current);
103
+ setPhase('reply');
104
+ // 'Stop' is gone and the buttons are back, so focus returns to Regenerate.
105
+ focusNext.current = function () { var _a; return (_a = regenerateButton.current) === null || _a === void 0 ? void 0 : _a.focus(); };
106
+ }
107
+ // Stands in for the agent's run: one step every 1.5 seconds.
108
+ function advance(at) {
109
+ step.current = setTimeout(function () {
110
+ if (at === plan.length - 1) {
111
+ setVersion(function (v) { return (v + 1) % replies.length; });
112
+ setRepliedAt(new Date());
113
+ setThumb(null);
114
+ endRun();
115
+ return;
116
+ }
117
+ setCurrent(at + 1);
118
+ advance(at + 1);
119
+ }, 1500);
120
+ }
121
+ // The reply's row turns into the agent's progress row, as the case 'Agent at work' shows.
122
+ function regenerate() {
123
+ clearTimeout(thanksTimer.current);
124
+ setThanks(false);
125
+ setStopped(false);
126
+ setCurrent(0);
127
+ setSeconds(0);
128
+ setPhase('running');
129
+ tick.current = setInterval(function () { return setSeconds(function (s) { return s + 1; }); }, 1000);
130
+ advance(0);
131
+ // Regenerate had focus and is gone; 'Stop' takes its place.
132
+ focusNext.current = function () { var _a; return (_a = stopButton.current) === null || _a === void 0 ? void 0 : _a.focus(); };
133
+ }
134
+ // Stop asks the server to end the run. The reply stays as it was.
135
+ function stop() {
136
+ if (phase !== 'running')
137
+ return;
138
+ clearTimeout(step.current);
139
+ setPhase('stopping');
140
+ // Stands in for the request to the server.
141
+ cancel.current = setTimeout(function () {
142
+ setStopped(true);
143
+ endRun();
144
+ }, 1200);
145
+ }
146
+ var working = phase !== 'reply';
147
+ return (<Center width="page">
148
+ <Stack gap="large">
149
+ <Heading level={1} size="h5">Pricing</Heading>
150
+ {/* A real app gives the list that holds the rows role="log". */}
151
+ <Stack gap="small">
152
+ <Message aria-label={request.from} avatar={<UserImage userHandle={request.from} decorative/>} name={request.from} meta={<TimeStamp createdAt={request.at} dateFormat="absolute" data="time"/>}>
153
+ <Paragraph measure="none">{request.text}</Paragraph>
154
+ </Message>
155
+ <Message aria-label={"".concat(agentName, ", agent")} avatar={<UserImage userHandle={agentName} icon={Bot} decorative/>} name={agentName} meta={agentMeta(working ? undefined : repliedAt)} footer={working ? (
156
+ // The only Stop, on the row for the whole run. It shows loading while the run is stopping.
157
+ <Cluster>
158
+ <Button ref={stopButton} size="small" type="secondary" state="enabled" label="Stop" loading={phase === 'stopping'} onClickButton={stop}/>
159
+ </Cluster>) : (
160
+ // One reply is on screen, so 'reply' is enough in the names. With several, each name says which reply.
161
+ <Cluster gap="small">
162
+ <Tooltip title="Mark as helpful">
163
+ <IconButton color="iconOnly" state={thumb === 'up' ? 'selected' : 'enabled'} size="small" iconName="ThumbsUp" ariaLabel="Mark reply as helpful" aria-pressed={thumb === 'up'} onClick={function () { return mark('up'); }}/>
164
+ </Tooltip>
165
+ <Tooltip title="Mark as not helpful">
166
+ <IconButton color="iconOnly" state={thumb === 'down' ? 'selected' : 'enabled'} size="small" iconName="ThumbsDown" ariaLabel="Mark reply as not helpful" aria-pressed={thumb === 'down'} onClick={function () { return mark('down'); }}/>
167
+ </Tooltip>
168
+ <Tooltip title={copied ? 'Copied' : 'Copy'}>
169
+ <IconButton color="iconOnly" state="enabled" size="small" iconName={copied ? 'Check' : 'Copy'} ariaLabel={copied ? 'Copied' : 'Copy reply'} onClick={copy}/>
170
+ </Tooltip>
171
+ {/* Only on the latest reply. */}
172
+ <Tooltip title="Regenerate">
173
+ <IconButton ref={regenerateButton} color="iconOnly" state="enabled" size="small" iconName="RefreshCw" ariaLabel="Regenerate reply" onClick={regenerate}/>
174
+ </Tooltip>
175
+ {/* A real app wraps the thanks in a polite live region. */}
176
+ {thanks && <Paragraph size="caption" tone="secondary" measure="none">Thanks. This helps the agent improve.</Paragraph>}
177
+ </Cluster>)}>
178
+ {working ? (
179
+ // A real app wraps this part in a polite live region, since StepList has none.
180
+ <Stack gap="medium">
181
+ <Paragraph size="caption" tone="secondary" measure="none">{secondsLine(seconds)}</Paragraph>
182
+ <StepList aria-label="Acme Agent's steps" steps={stepsUpTo(current)}/>
183
+ </Stack>) : (<Stack gap="small">
184
+ <Paragraph measure="none">{reply}</Paragraph>
185
+ {stopped && <Paragraph size="caption" tone="secondary" measure="none">Stopped. Nothing was changed.</Paragraph>}
186
+ </Stack>)}
187
+ </Message>
188
+ </Stack>
189
+ </Stack>
190
+ </Center>);
191
+ }
@@ -0,0 +1 @@
1
+ export default function ReplyFeedbackWithReason(): import("react").JSX.Element;
@@ -0,0 +1,221 @@
1
+ 'use client';
2
+ import { useEffect, useRef, useState } from 'react';
3
+ import { Bot } from 'lucide-react';
4
+ import Message from '../../components/message';
5
+ import UserImage from '../../components/userImage';
6
+ import Tag from '../../components/tag';
7
+ import TimeStamp from '../../components/timeStamp';
8
+ import Heading from '../../components/heading';
9
+ import Paragraph from '../../components/paragraph';
10
+ import Button from '../../components/button';
11
+ import IconButton from '../../components/iconButton';
12
+ import Tooltip from '../../components/tooltip';
13
+ import StepList from '../../components/stepList';
14
+ import { Center, Cluster, Stack } from '../../components/layout';
15
+ var agentName = 'Acme Agent';
16
+ var request = { from: 'Dana Lee', at: new Date('2025-01-15T11:40:00Z'), text: 'What changed in the new plans?' };
17
+ var firstRepliedAt = new Date('2025-01-15T11:41:00Z');
18
+ // Each Regenerate writes the next version of the reply.
19
+ var replies = [
20
+ 'Pro goes from $12 to $15 a month. There is a new Team plan at $25 per seat, and the Free plan stays the same.',
21
+ 'Two things changed. Pro now costs $15 a month instead of $12, and the new Team plan costs $25 per seat.',
22
+ ];
23
+ // Each step in plain words: what the agent is doing now, and what it did once the step is done.
24
+ var plan = [
25
+ { doing: 'Reading the thread', done: 'Read the thread' },
26
+ { doing: 'Writing a new reply', done: 'Wrote a new reply' },
27
+ ];
28
+ // A real app sends the reason with the mark, for the team to read.
29
+ var reasons = ['Inaccurate', 'Off topic', 'Too long', 'Other'];
30
+ function stepsUpTo(current) {
31
+ return plan.slice(0, current + 1).map(function (s, i) { return (i < current ? { label: s.done, status: 'done' } : { label: s.doing, status: 'running' }); });
32
+ }
33
+ function secondsLine(seconds) {
34
+ return "Working for ".concat(seconds, " ").concat(seconds === 1 ? 'second' : 'seconds');
35
+ }
36
+ // The agent's marks, as the rule 'An agent says what it is' says. While a new reply is written there is
37
+ // no time to show: the old reply's time would be wrong for it.
38
+ function agentMeta(at) {
39
+ return (<>
40
+ <Tag variant="contained" size="small" label="Agent"/>
41
+ {at && <TimeStamp createdAt={at} dateFormat="absolute" data="time"/>}
42
+ <Paragraph size="caption" tone="secondary" measure="none">Model name</Paragraph>
43
+ </>);
44
+ }
45
+ export default function ReplyFeedbackWithReason() {
46
+ // Opens just after the person pressed thumbs down, so the picture in the docs shows the reasons.
47
+ var _a = useState('down'), thumb = _a[0], setThumb = _a[1];
48
+ var _b = useState(false), thanks = _b[0], setThanks = _b[1];
49
+ // The reason row, open after thumbs down until a reason or Skip is picked.
50
+ var _c = useState(true), asking = _c[0], setAsking = _c[1];
51
+ var _d = useState(false), copied = _d[0], setCopied = _d[1];
52
+ var _e = useState(0), version = _e[0], setVersion = _e[1];
53
+ // Each version of the reply has its own time: a regenerated reply shows when it was written.
54
+ var _f = useState(firstRepliedAt), repliedAt = _f[0], setRepliedAt = _f[1];
55
+ var _g = useState('reply'), phase = _g[0], setPhase = _g[1];
56
+ var _h = useState(0), current = _h[0], setCurrent = _h[1];
57
+ var _j = useState(0), seconds = _j[0], setSeconds = _j[1];
58
+ var _k = useState(false), stopped = _k[0], setStopped = _k[1];
59
+ var thanksTimer = useRef();
60
+ var copyTimer = useRef();
61
+ var tick = useRef();
62
+ var step = useRef();
63
+ var cancel = useRef();
64
+ var regenerateButton = useRef(null);
65
+ var stopButton = useRef(null);
66
+ var thumbsDownButton = useRef(null);
67
+ // Where focus goes after the next render, once the element it goes to is on screen.
68
+ var focusNext = useRef();
69
+ // The clipboard answers later; by then the example may be gone.
70
+ var mounted = useRef(true);
71
+ // On unmount it stops every timer and the run.
72
+ useEffect(function () { return function () {
73
+ mounted.current = false;
74
+ clearTimeout(thanksTimer.current);
75
+ clearTimeout(copyTimer.current);
76
+ clearInterval(tick.current);
77
+ clearTimeout(step.current);
78
+ clearTimeout(cancel.current);
79
+ }; }, []);
80
+ useEffect(function () {
81
+ var move = focusNext.current;
82
+ focusNext.current = undefined;
83
+ move === null || move === void 0 ? void 0 : move();
84
+ });
85
+ var reply = replies[version];
86
+ function showThanks() {
87
+ clearTimeout(thanksTimer.current);
88
+ setThanks(true);
89
+ thanksTimer.current = setTimeout(function () { return setThanks(false); }, 2000);
90
+ }
91
+ // Pressing a thumb marks it, pressing it again clears it, and the other thumb moves the mark.
92
+ // Thumbs down asks what was wrong; the thanks waits for the answer.
93
+ // A real app sends the mark to the server; the thanks is the only confirmation.
94
+ function mark(next) {
95
+ var value = thumb === next ? null : next;
96
+ setThumb(value);
97
+ setAsking(value === 'down');
98
+ clearTimeout(thanksTimer.current);
99
+ setThanks(false);
100
+ if (value === 'up')
101
+ showThanks();
102
+ }
103
+ // A reason or Skip closes the row. Focus was on a reason or Skip, so it goes back to thumbs down.
104
+ function finish() {
105
+ var _a;
106
+ setAsking(false);
107
+ showThanks();
108
+ (_a = thumbsDownButton.current) === null || _a === void 0 ? void 0 : _a.focus();
109
+ }
110
+ function copy() {
111
+ var _a;
112
+ (_a = navigator.clipboard) === null || _a === void 0 ? void 0 : _a.writeText(reply).then(function () {
113
+ if (!mounted.current)
114
+ return;
115
+ setCopied(true);
116
+ clearTimeout(copyTimer.current);
117
+ copyTimer.current = setTimeout(function () { return setCopied(false); }, 2000);
118
+ }, function () { });
119
+ }
120
+ function endRun() {
121
+ clearInterval(tick.current);
122
+ clearTimeout(step.current);
123
+ setPhase('reply');
124
+ // 'Stop' is gone and the buttons are back, so focus returns to Regenerate.
125
+ focusNext.current = function () { var _a; return (_a = regenerateButton.current) === null || _a === void 0 ? void 0 : _a.focus(); };
126
+ }
127
+ // Stands in for the agent's run: one step every 1.5 seconds.
128
+ function advance(at) {
129
+ step.current = setTimeout(function () {
130
+ if (at === plan.length - 1) {
131
+ setVersion(function (v) { return (v + 1) % replies.length; });
132
+ setRepliedAt(new Date());
133
+ setThumb(null);
134
+ endRun();
135
+ return;
136
+ }
137
+ setCurrent(at + 1);
138
+ advance(at + 1);
139
+ }, 1500);
140
+ }
141
+ // The reply's row turns into the agent's progress row, as the case 'Agent at work' shows.
142
+ function regenerate() {
143
+ clearTimeout(thanksTimer.current);
144
+ setThanks(false);
145
+ setAsking(false);
146
+ setStopped(false);
147
+ setCurrent(0);
148
+ setSeconds(0);
149
+ setPhase('running');
150
+ tick.current = setInterval(function () { return setSeconds(function (s) { return s + 1; }); }, 1000);
151
+ advance(0);
152
+ // Regenerate had focus and is gone; 'Stop' takes its place.
153
+ focusNext.current = function () { var _a; return (_a = stopButton.current) === null || _a === void 0 ? void 0 : _a.focus(); };
154
+ }
155
+ // Stop asks the server to end the run. The reply stays as it was.
156
+ function stop() {
157
+ if (phase !== 'running')
158
+ return;
159
+ clearTimeout(step.current);
160
+ setPhase('stopping');
161
+ // Stands in for the request to the server.
162
+ cancel.current = setTimeout(function () {
163
+ setStopped(true);
164
+ endRun();
165
+ }, 1200);
166
+ }
167
+ var working = phase !== 'reply';
168
+ return (<Center width="page">
169
+ <Stack gap="large">
170
+ <Heading level={1} size="h5">Pricing</Heading>
171
+ {/* A real app gives the list that holds the rows role="log". */}
172
+ <Stack gap="small">
173
+ <Message aria-label={request.from} avatar={<UserImage userHandle={request.from} decorative/>} name={request.from} meta={<TimeStamp createdAt={request.at} dateFormat="absolute" data="time"/>}>
174
+ <Paragraph measure="none">{request.text}</Paragraph>
175
+ </Message>
176
+ <Message aria-label={"".concat(agentName, ", agent")} avatar={<UserImage userHandle={agentName} icon={Bot} decorative/>} name={agentName} meta={agentMeta(working ? undefined : repliedAt)} footer={working ? (
177
+ // The only Stop, on the row for the whole run. It shows loading while the run is stopping.
178
+ <Cluster>
179
+ <Button ref={stopButton} size="small" type="secondary" state="enabled" label="Stop" loading={phase === 'stopping'} onClickButton={stop}/>
180
+ </Cluster>) : (
181
+ // One reply is on screen, so 'reply' is enough in the names. With several, each name says which reply.
182
+ <Stack gap="small">
183
+ <Cluster gap="small">
184
+ <Tooltip title="Mark as helpful">
185
+ <IconButton color="iconOnly" state={thumb === 'up' ? 'selected' : 'enabled'} size="small" iconName="ThumbsUp" ariaLabel="Mark reply as helpful" aria-pressed={thumb === 'up'} onClick={function () { return mark('up'); }}/>
186
+ </Tooltip>
187
+ <Tooltip title="Mark as not helpful">
188
+ <IconButton ref={thumbsDownButton} color="iconOnly" state={thumb === 'down' ? 'selected' : 'enabled'} size="small" iconName="ThumbsDown" ariaLabel="Mark reply as not helpful" aria-pressed={thumb === 'down'} onClick={function () { return mark('down'); }}/>
189
+ </Tooltip>
190
+ <Tooltip title={copied ? 'Copied' : 'Copy'}>
191
+ <IconButton color="iconOnly" state="enabled" size="small" iconName={copied ? 'Check' : 'Copy'} ariaLabel={copied ? 'Copied' : 'Copy reply'} onClick={copy}/>
192
+ </Tooltip>
193
+ {/* Only on the latest reply. */}
194
+ <Tooltip title="Regenerate">
195
+ <IconButton ref={regenerateButton} color="iconOnly" state="enabled" size="small" iconName="RefreshCw" ariaLabel="Regenerate reply" onClick={regenerate}/>
196
+ </Tooltip>
197
+ {/* A real app wraps the thanks in a polite live region. */}
198
+ {thanks && <Paragraph size="caption" tone="secondary" measure="none">Thanks. This helps the agent improve.</Paragraph>}
199
+ </Cluster>
200
+ {asking && (<Cluster gap="small">
201
+ <Paragraph size="caption" tone="secondary" measure="none">What was wrong?</Paragraph>
202
+ {/* Each reason is an answer, not a filter, so it is not a toggle. A Cluster cannot be named:
203
+ a real app groups the reasons under the question, named 'What was wrong?'. */}
204
+ {reasons.map(function (r) { return (<Tag key={r} variant="contained" size="small" toggle={false} label={r} onClick={finish}/>); })}
205
+ <Button size="small" type="tertiary" state="enabled" label="Skip" onClickButton={finish}/>
206
+ </Cluster>)}
207
+ </Stack>)}>
208
+ {working ? (
209
+ // A real app wraps this part in a polite live region, since StepList has none.
210
+ <Stack gap="medium">
211
+ <Paragraph size="caption" tone="secondary" measure="none">{secondsLine(seconds)}</Paragraph>
212
+ <StepList aria-label="Acme Agent's steps" steps={stepsUpTo(current)}/>
213
+ </Stack>) : (<Stack gap="small">
214
+ <Paragraph measure="none">{reply}</Paragraph>
215
+ {stopped && <Paragraph size="caption" tone="secondary" measure="none">Stopped. Nothing was changed.</Paragraph>}
216
+ </Stack>)}
217
+ </Message>
218
+ </Stack>
219
+ </Stack>
220
+ </Center>);
221
+ }