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,552 @@
1
+ # Reply feedback
2
+
3
+ The agent has replied, and the person can say whether the reply helped.
4
+
5
+ **Not built yet:** Scindo on the web shows thumbs down only, with no thumbs up and no Copy, and the button goes away once pressed. Its thanks reads 'Noted, we'll improve.' Its reasons are Buttons, Skip is a cross, and Regenerate sits in the hover toolbar. Scindo's Apple app has no feedback buttons and no Regenerate.
6
+
7
+ ## Do
8
+
9
+ - Put a row of small `IconButton`s with Tooltips in the agent reply's `footer`: thumbs up, thumbs down, Copy, then Regenerate.
10
+ - Name them for the reply: 'Mark reply as helpful', 'Mark reply as not helpful', 'Copy reply' and 'Regenerate reply'.
11
+ - Add what tells the replies apart to the names when several replies are on screen, such as the question each one answers.
12
+ - Mark the pressed thumb with `state="selected"` and `aria-pressed`. Pressing it again clears it, and pressing the other thumb moves the mark.
13
+ - Show 'Thanks. This helps the agent improve.' after the buttons for 2 seconds. It is the only confirmation, since the result shows in place.
14
+ - Confirm in place, unlike the case 'Feedback form', which sends from a Modal and confirms with a toast.
15
+ - Announce the thanks politely: the app wraps it in a polite live region.
16
+ - Swap Copy's icon to `Check` for 2 seconds once the reply is copied.
17
+ - Show Regenerate on the latest reply only. It turns the row into the agent's progress row with 'Stop', as the case 'Agent at work' shows.
18
+ - Leave the old reply's time off the progress row while the new reply is written.
19
+ - Move focus to 'Stop' when Regenerate turns the row into a progress row.
20
+ - Keep the reply and its buttons when Regenerate fails. Show an inline error `Alert` above the buttons, as the rule 'A form error shows next to the problem' says.
21
+ - Keep the reply as it was when the person presses 'Stop', and say 'Stopped. Nothing was changed.' under it.
22
+ - Move focus back to Regenerate when the new reply is ready or the run has stopped.
23
+ - Show 'What was wrong?' after thumbs down, with four reason `Tag`s with `toggle={false}` and a tertiary small 'Skip' Button.
24
+ - Group the reasons under the question and name the group 'What was wrong?', so a screen reader hears them together.
25
+ - Close the reasons when the person picks one or presses 'Skip', show the thanks, and move focus back to thumbs down.
26
+ - Give the list that holds the rows `role="log"`.
27
+
28
+ ## Don't
29
+
30
+ - Do not show a toast for feedback. The thanks shows where the person pressed.
31
+ - Do not ask for a reason after thumbs up.
32
+ - Do not make the person pick a reason. 'Skip' closes the row.
33
+ - Do not show feedback buttons on a person's message.
34
+ - Do not show Regenerate on an older reply.
35
+
36
+ ## Option: Thumbs
37
+
38
+ Use when: The team wants a signal and will not read reasons.
39
+
40
+ Uses: `Button`, `Center`, `Cluster`, `Heading`, `IconButton`, `Message`, `Paragraph`, `Stack`, `StepList`, `Tag`, `TimeStamp`, `Tooltip`, `UserImage`
41
+
42
+ ```tsx
43
+ 'use client';
44
+ import { useEffect, useRef, useState } from 'react';
45
+ import { Bot } from 'lucide-react';
46
+ import Message from 'oneslash-design-system/components/message';
47
+ import UserImage from 'oneslash-design-system/components/userImage';
48
+ import Tag from 'oneslash-design-system/components/tag';
49
+ import TimeStamp from 'oneslash-design-system/components/timeStamp';
50
+ import Heading from 'oneslash-design-system/components/heading';
51
+ import Paragraph from 'oneslash-design-system/components/paragraph';
52
+ import Button from 'oneslash-design-system/components/button';
53
+ import IconButton from 'oneslash-design-system/components/iconButton';
54
+ import Tooltip from 'oneslash-design-system/components/tooltip';
55
+ import StepList, { type StepListStep } from 'oneslash-design-system/components/stepList';
56
+ import { Center, Cluster, Stack } from 'oneslash-design-system/components/layout';
57
+
58
+ const agentName = 'Acme Agent';
59
+
60
+ const request = { from: 'Dana Lee', at: new Date('2025-01-15T11:40:00Z'), text: 'What changed in the new plans?' };
61
+ const firstRepliedAt = new Date('2025-01-15T11:41:00Z');
62
+
63
+ // Each Regenerate writes the next version of the reply.
64
+ const replies = [
65
+ '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.',
66
+ 'Two things changed. Pro now costs $15 a month instead of $12, and the new Team plan costs $25 per seat.',
67
+ ];
68
+
69
+ // Each step in plain words: what the agent is doing now, and what it did once the step is done.
70
+ const plan = [
71
+ { doing: 'Reading the thread', done: 'Read the thread' },
72
+ { doing: 'Writing a new reply', done: 'Wrote a new reply' },
73
+ ];
74
+
75
+ type Thumb = 'up' | 'down' | null;
76
+ type Phase = 'reply' | 'running' | 'stopping';
77
+
78
+ function stepsUpTo(current: number): StepListStep[] {
79
+ return plan.slice(0, current + 1).map((s, i) => (i < current ? { label: s.done, status: 'done' } : { label: s.doing, status: 'running' }));
80
+ }
81
+
82
+ function secondsLine(seconds: number) {
83
+ return `Working for ${seconds} ${seconds === 1 ? 'second' : 'seconds'}`;
84
+ }
85
+
86
+ // The agent's marks, as the rule 'An agent says what it is' says. While a new reply is written there is
87
+ // no time to show: the old reply's time would be wrong for it.
88
+ function agentMeta(at?: Date) {
89
+ return (
90
+ <>
91
+ <Tag variant="contained" size="small" label="Agent" />
92
+ {at && <TimeStamp createdAt={at} dateFormat="absolute" data="time" />}
93
+ <Paragraph size="caption" tone="secondary" measure="none">Model name</Paragraph>
94
+ </>
95
+ );
96
+ }
97
+
98
+ export default function ReplyFeedbackThumbs() {
99
+ const [thumb, setThumb] = useState<Thumb>(null);
100
+ const [thanks, setThanks] = useState(false);
101
+ const [copied, setCopied] = useState(false);
102
+ const [version, setVersion] = useState(0);
103
+ // Each version of the reply has its own time: a regenerated reply shows when it was written.
104
+ const [repliedAt, setRepliedAt] = useState(firstRepliedAt);
105
+ const [phase, setPhase] = useState<Phase>('reply');
106
+ const [current, setCurrent] = useState(0);
107
+ const [seconds, setSeconds] = useState(0);
108
+ const [stopped, setStopped] = useState(false);
109
+ const thanksTimer = useRef<ReturnType<typeof setTimeout>>();
110
+ const copyTimer = useRef<ReturnType<typeof setTimeout>>();
111
+ const tick = useRef<ReturnType<typeof setInterval>>();
112
+ const step = useRef<ReturnType<typeof setTimeout>>();
113
+ const cancel = useRef<ReturnType<typeof setTimeout>>();
114
+ const regenerateButton = useRef<HTMLButtonElement | HTMLAnchorElement>(null);
115
+ const stopButton = useRef<HTMLButtonElement | HTMLAnchorElement>(null);
116
+ // Where focus goes after the next render, once the element it goes to is on screen.
117
+ const focusNext = useRef<() => void>();
118
+ // The clipboard answers later; by then the example may be gone.
119
+ const mounted = useRef(true);
120
+
121
+ // On unmount it stops every timer and the run.
122
+ useEffect(() => () => {
123
+ mounted.current = false;
124
+ clearTimeout(thanksTimer.current);
125
+ clearTimeout(copyTimer.current);
126
+ clearInterval(tick.current);
127
+ clearTimeout(step.current);
128
+ clearTimeout(cancel.current);
129
+ }, []);
130
+
131
+ useEffect(() => {
132
+ const move = focusNext.current;
133
+ focusNext.current = undefined;
134
+ move?.();
135
+ });
136
+
137
+ const reply = replies[version];
138
+
139
+ // Pressing a thumb marks it, pressing it again clears it, and the other thumb moves the mark.
140
+ // A real app sends the mark to the server; the thanks is the only confirmation.
141
+ function mark(next: 'up' | 'down') {
142
+ const value = thumb === next ? null : next;
143
+ setThumb(value);
144
+ clearTimeout(thanksTimer.current);
145
+ setThanks(value !== null);
146
+ if (value !== null) thanksTimer.current = setTimeout(() => setThanks(false), 2000);
147
+ }
148
+
149
+ function copy() {
150
+ navigator.clipboard?.writeText(reply).then(() => {
151
+ if (!mounted.current) return;
152
+ setCopied(true);
153
+ clearTimeout(copyTimer.current);
154
+ copyTimer.current = setTimeout(() => setCopied(false), 2000);
155
+ }, () => {});
156
+ }
157
+
158
+ function endRun() {
159
+ clearInterval(tick.current);
160
+ clearTimeout(step.current);
161
+ setPhase('reply');
162
+ // 'Stop' is gone and the buttons are back, so focus returns to Regenerate.
163
+ focusNext.current = () => regenerateButton.current?.focus();
164
+ }
165
+
166
+ // Stands in for the agent's run: one step every 1.5 seconds.
167
+ function advance(at: number) {
168
+ step.current = setTimeout(() => {
169
+ if (at === plan.length - 1) {
170
+ setVersion((v) => (v + 1) % replies.length);
171
+ setRepliedAt(new Date());
172
+ setThumb(null);
173
+ endRun();
174
+ return;
175
+ }
176
+ setCurrent(at + 1);
177
+ advance(at + 1);
178
+ }, 1500);
179
+ }
180
+
181
+ // The reply's row turns into the agent's progress row, as the case 'Agent at work' shows.
182
+ function regenerate() {
183
+ clearTimeout(thanksTimer.current);
184
+ setThanks(false);
185
+ setStopped(false);
186
+ setCurrent(0);
187
+ setSeconds(0);
188
+ setPhase('running');
189
+ tick.current = setInterval(() => setSeconds((s) => s + 1), 1000);
190
+ advance(0);
191
+ // Regenerate had focus and is gone; 'Stop' takes its place.
192
+ focusNext.current = () => stopButton.current?.focus();
193
+ }
194
+
195
+ // Stop asks the server to end the run. The reply stays as it was.
196
+ function stop() {
197
+ if (phase !== 'running') return;
198
+ clearTimeout(step.current);
199
+ setPhase('stopping');
200
+ // Stands in for the request to the server.
201
+ cancel.current = setTimeout(() => {
202
+ setStopped(true);
203
+ endRun();
204
+ }, 1200);
205
+ }
206
+
207
+ const working = phase !== 'reply';
208
+
209
+ return (
210
+ <Center width="page">
211
+ <Stack gap="large">
212
+ <Heading level={1} size="h5">Pricing</Heading>
213
+ {/* A real app gives the list that holds the rows role="log". */}
214
+ <Stack gap="small">
215
+ <Message
216
+ aria-label={request.from}
217
+ avatar={<UserImage userHandle={request.from} decorative />}
218
+ name={request.from}
219
+ meta={<TimeStamp createdAt={request.at} dateFormat="absolute" data="time" />}
220
+ >
221
+ <Paragraph measure="none">{request.text}</Paragraph>
222
+ </Message>
223
+ <Message
224
+ aria-label={`${agentName}, agent`}
225
+ avatar={<UserImage userHandle={agentName} icon={Bot} decorative />}
226
+ name={agentName}
227
+ meta={agentMeta(working ? undefined : repliedAt)}
228
+ footer={
229
+ working ? (
230
+ // The only Stop, on the row for the whole run. It shows loading while the run is stopping.
231
+ <Cluster>
232
+ <Button ref={stopButton} size="small" type="secondary" state="enabled" label="Stop" loading={phase === 'stopping'} onClickButton={stop} />
233
+ </Cluster>
234
+ ) : (
235
+ // One reply is on screen, so 'reply' is enough in the names. With several, each name says which reply.
236
+ <Cluster gap="small">
237
+ <Tooltip title="Mark as helpful">
238
+ <IconButton color="iconOnly" state={thumb === 'up' ? 'selected' : 'enabled'} size="small" iconName="ThumbsUp" ariaLabel="Mark reply as helpful" aria-pressed={thumb === 'up'} onClick={() => mark('up')} />
239
+ </Tooltip>
240
+ <Tooltip title="Mark as not helpful">
241
+ <IconButton color="iconOnly" state={thumb === 'down' ? 'selected' : 'enabled'} size="small" iconName="ThumbsDown" ariaLabel="Mark reply as not helpful" aria-pressed={thumb === 'down'} onClick={() => mark('down')} />
242
+ </Tooltip>
243
+ <Tooltip title={copied ? 'Copied' : 'Copy'}>
244
+ <IconButton color="iconOnly" state="enabled" size="small" iconName={copied ? 'Check' : 'Copy'} ariaLabel={copied ? 'Copied' : 'Copy reply'} onClick={copy} />
245
+ </Tooltip>
246
+ {/* Only on the latest reply. */}
247
+ <Tooltip title="Regenerate">
248
+ <IconButton ref={regenerateButton} color="iconOnly" state="enabled" size="small" iconName="RefreshCw" ariaLabel="Regenerate reply" onClick={regenerate} />
249
+ </Tooltip>
250
+ {/* A real app wraps the thanks in a polite live region. */}
251
+ {thanks && <Paragraph size="caption" tone="secondary" measure="none">Thanks. This helps the agent improve.</Paragraph>}
252
+ </Cluster>
253
+ )
254
+ }
255
+ >
256
+ {working ? (
257
+ // A real app wraps this part in a polite live region, since StepList has none.
258
+ <Stack gap="medium">
259
+ <Paragraph size="caption" tone="secondary" measure="none">{secondsLine(seconds)}</Paragraph>
260
+ <StepList aria-label="Acme Agent's steps" steps={stepsUpTo(current)} />
261
+ </Stack>
262
+ ) : (
263
+ <Stack gap="small">
264
+ <Paragraph measure="none">{reply}</Paragraph>
265
+ {stopped && <Paragraph size="caption" tone="secondary" measure="none">Stopped. Nothing was changed.</Paragraph>}
266
+ </Stack>
267
+ )}
268
+ </Message>
269
+ </Stack>
270
+ </Stack>
271
+ </Center>
272
+ );
273
+ }
274
+ ```
275
+
276
+ ## Option: With reason
277
+
278
+ Use when: Someone reads the reasons and acts on them.
279
+
280
+ Uses: `Button`, `Center`, `Cluster`, `Heading`, `IconButton`, `Message`, `Paragraph`, `Stack`, `StepList`, `Tag`, `TimeStamp`, `Tooltip`, `UserImage`
281
+
282
+ ```tsx
283
+ 'use client';
284
+ import { useEffect, useRef, useState } from 'react';
285
+ import { Bot } from 'lucide-react';
286
+ import Message from 'oneslash-design-system/components/message';
287
+ import UserImage from 'oneslash-design-system/components/userImage';
288
+ import Tag from 'oneslash-design-system/components/tag';
289
+ import TimeStamp from 'oneslash-design-system/components/timeStamp';
290
+ import Heading from 'oneslash-design-system/components/heading';
291
+ import Paragraph from 'oneslash-design-system/components/paragraph';
292
+ import Button from 'oneslash-design-system/components/button';
293
+ import IconButton from 'oneslash-design-system/components/iconButton';
294
+ import Tooltip from 'oneslash-design-system/components/tooltip';
295
+ import StepList, { type StepListStep } from 'oneslash-design-system/components/stepList';
296
+ import { Center, Cluster, Stack } from 'oneslash-design-system/components/layout';
297
+
298
+ const agentName = 'Acme Agent';
299
+
300
+ const request = { from: 'Dana Lee', at: new Date('2025-01-15T11:40:00Z'), text: 'What changed in the new plans?' };
301
+ const firstRepliedAt = new Date('2025-01-15T11:41:00Z');
302
+
303
+ // Each Regenerate writes the next version of the reply.
304
+ const replies = [
305
+ '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.',
306
+ 'Two things changed. Pro now costs $15 a month instead of $12, and the new Team plan costs $25 per seat.',
307
+ ];
308
+
309
+ // Each step in plain words: what the agent is doing now, and what it did once the step is done.
310
+ const plan = [
311
+ { doing: 'Reading the thread', done: 'Read the thread' },
312
+ { doing: 'Writing a new reply', done: 'Wrote a new reply' },
313
+ ];
314
+
315
+ type Thumb = 'up' | 'down' | null;
316
+
317
+ // A real app sends the reason with the mark, for the team to read.
318
+ const reasons = ['Inaccurate', 'Off topic', 'Too long', 'Other'];
319
+ type Phase = 'reply' | 'running' | 'stopping';
320
+
321
+ function stepsUpTo(current: number): StepListStep[] {
322
+ return plan.slice(0, current + 1).map((s, i) => (i < current ? { label: s.done, status: 'done' } : { label: s.doing, status: 'running' }));
323
+ }
324
+
325
+ function secondsLine(seconds: number) {
326
+ return `Working for ${seconds} ${seconds === 1 ? 'second' : 'seconds'}`;
327
+ }
328
+
329
+ // The agent's marks, as the rule 'An agent says what it is' says. While a new reply is written there is
330
+ // no time to show: the old reply's time would be wrong for it.
331
+ function agentMeta(at?: Date) {
332
+ return (
333
+ <>
334
+ <Tag variant="contained" size="small" label="Agent" />
335
+ {at && <TimeStamp createdAt={at} dateFormat="absolute" data="time" />}
336
+ <Paragraph size="caption" tone="secondary" measure="none">Model name</Paragraph>
337
+ </>
338
+ );
339
+ }
340
+
341
+ export default function ReplyFeedbackWithReason() {
342
+ // Opens just after the person pressed thumbs down, so the picture in the docs shows the reasons.
343
+ const [thumb, setThumb] = useState<Thumb>('down');
344
+ const [thanks, setThanks] = useState(false);
345
+ // The reason row, open after thumbs down until a reason or Skip is picked.
346
+ const [asking, setAsking] = useState(true);
347
+ const [copied, setCopied] = useState(false);
348
+ const [version, setVersion] = useState(0);
349
+ // Each version of the reply has its own time: a regenerated reply shows when it was written.
350
+ const [repliedAt, setRepliedAt] = useState(firstRepliedAt);
351
+ const [phase, setPhase] = useState<Phase>('reply');
352
+ const [current, setCurrent] = useState(0);
353
+ const [seconds, setSeconds] = useState(0);
354
+ const [stopped, setStopped] = useState(false);
355
+ const thanksTimer = useRef<ReturnType<typeof setTimeout>>();
356
+ const copyTimer = useRef<ReturnType<typeof setTimeout>>();
357
+ const tick = useRef<ReturnType<typeof setInterval>>();
358
+ const step = useRef<ReturnType<typeof setTimeout>>();
359
+ const cancel = useRef<ReturnType<typeof setTimeout>>();
360
+ const regenerateButton = useRef<HTMLButtonElement | HTMLAnchorElement>(null);
361
+ const stopButton = useRef<HTMLButtonElement | HTMLAnchorElement>(null);
362
+ const thumbsDownButton = useRef<HTMLButtonElement | HTMLAnchorElement>(null);
363
+ // Where focus goes after the next render, once the element it goes to is on screen.
364
+ const focusNext = useRef<() => void>();
365
+ // The clipboard answers later; by then the example may be gone.
366
+ const mounted = useRef(true);
367
+
368
+ // On unmount it stops every timer and the run.
369
+ useEffect(() => () => {
370
+ mounted.current = false;
371
+ clearTimeout(thanksTimer.current);
372
+ clearTimeout(copyTimer.current);
373
+ clearInterval(tick.current);
374
+ clearTimeout(step.current);
375
+ clearTimeout(cancel.current);
376
+ }, []);
377
+
378
+ useEffect(() => {
379
+ const move = focusNext.current;
380
+ focusNext.current = undefined;
381
+ move?.();
382
+ });
383
+
384
+ const reply = replies[version];
385
+
386
+ function showThanks() {
387
+ clearTimeout(thanksTimer.current);
388
+ setThanks(true);
389
+ thanksTimer.current = setTimeout(() => setThanks(false), 2000);
390
+ }
391
+
392
+ // Pressing a thumb marks it, pressing it again clears it, and the other thumb moves the mark.
393
+ // Thumbs down asks what was wrong; the thanks waits for the answer.
394
+ // A real app sends the mark to the server; the thanks is the only confirmation.
395
+ function mark(next: 'up' | 'down') {
396
+ const value = thumb === next ? null : next;
397
+ setThumb(value);
398
+ setAsking(value === 'down');
399
+ clearTimeout(thanksTimer.current);
400
+ setThanks(false);
401
+ if (value === 'up') showThanks();
402
+ }
403
+
404
+ // A reason or Skip closes the row. Focus was on a reason or Skip, so it goes back to thumbs down.
405
+ function finish() {
406
+ setAsking(false);
407
+ showThanks();
408
+ thumbsDownButton.current?.focus();
409
+ }
410
+
411
+ function copy() {
412
+ navigator.clipboard?.writeText(reply).then(() => {
413
+ if (!mounted.current) return;
414
+ setCopied(true);
415
+ clearTimeout(copyTimer.current);
416
+ copyTimer.current = setTimeout(() => setCopied(false), 2000);
417
+ }, () => {});
418
+ }
419
+
420
+ function endRun() {
421
+ clearInterval(tick.current);
422
+ clearTimeout(step.current);
423
+ setPhase('reply');
424
+ // 'Stop' is gone and the buttons are back, so focus returns to Regenerate.
425
+ focusNext.current = () => regenerateButton.current?.focus();
426
+ }
427
+
428
+ // Stands in for the agent's run: one step every 1.5 seconds.
429
+ function advance(at: number) {
430
+ step.current = setTimeout(() => {
431
+ if (at === plan.length - 1) {
432
+ setVersion((v) => (v + 1) % replies.length);
433
+ setRepliedAt(new Date());
434
+ setThumb(null);
435
+ endRun();
436
+ return;
437
+ }
438
+ setCurrent(at + 1);
439
+ advance(at + 1);
440
+ }, 1500);
441
+ }
442
+
443
+ // The reply's row turns into the agent's progress row, as the case 'Agent at work' shows.
444
+ function regenerate() {
445
+ clearTimeout(thanksTimer.current);
446
+ setThanks(false);
447
+ setAsking(false);
448
+ setStopped(false);
449
+ setCurrent(0);
450
+ setSeconds(0);
451
+ setPhase('running');
452
+ tick.current = setInterval(() => setSeconds((s) => s + 1), 1000);
453
+ advance(0);
454
+ // Regenerate had focus and is gone; 'Stop' takes its place.
455
+ focusNext.current = () => stopButton.current?.focus();
456
+ }
457
+
458
+ // Stop asks the server to end the run. The reply stays as it was.
459
+ function stop() {
460
+ if (phase !== 'running') return;
461
+ clearTimeout(step.current);
462
+ setPhase('stopping');
463
+ // Stands in for the request to the server.
464
+ cancel.current = setTimeout(() => {
465
+ setStopped(true);
466
+ endRun();
467
+ }, 1200);
468
+ }
469
+
470
+ const working = phase !== 'reply';
471
+
472
+ return (
473
+ <Center width="page">
474
+ <Stack gap="large">
475
+ <Heading level={1} size="h5">Pricing</Heading>
476
+ {/* A real app gives the list that holds the rows role="log". */}
477
+ <Stack gap="small">
478
+ <Message
479
+ aria-label={request.from}
480
+ avatar={<UserImage userHandle={request.from} decorative />}
481
+ name={request.from}
482
+ meta={<TimeStamp createdAt={request.at} dateFormat="absolute" data="time" />}
483
+ >
484
+ <Paragraph measure="none">{request.text}</Paragraph>
485
+ </Message>
486
+ <Message
487
+ aria-label={`${agentName}, agent`}
488
+ avatar={<UserImage userHandle={agentName} icon={Bot} decorative />}
489
+ name={agentName}
490
+ meta={agentMeta(working ? undefined : repliedAt)}
491
+ footer={
492
+ working ? (
493
+ // The only Stop, on the row for the whole run. It shows loading while the run is stopping.
494
+ <Cluster>
495
+ <Button ref={stopButton} size="small" type="secondary" state="enabled" label="Stop" loading={phase === 'stopping'} onClickButton={stop} />
496
+ </Cluster>
497
+ ) : (
498
+ // One reply is on screen, so 'reply' is enough in the names. With several, each name says which reply.
499
+ <Stack gap="small">
500
+ <Cluster gap="small">
501
+ <Tooltip title="Mark as helpful">
502
+ <IconButton color="iconOnly" state={thumb === 'up' ? 'selected' : 'enabled'} size="small" iconName="ThumbsUp" ariaLabel="Mark reply as helpful" aria-pressed={thumb === 'up'} onClick={() => mark('up')} />
503
+ </Tooltip>
504
+ <Tooltip title="Mark as not helpful">
505
+ <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={() => mark('down')} />
506
+ </Tooltip>
507
+ <Tooltip title={copied ? 'Copied' : 'Copy'}>
508
+ <IconButton color="iconOnly" state="enabled" size="small" iconName={copied ? 'Check' : 'Copy'} ariaLabel={copied ? 'Copied' : 'Copy reply'} onClick={copy} />
509
+ </Tooltip>
510
+ {/* Only on the latest reply. */}
511
+ <Tooltip title="Regenerate">
512
+ <IconButton ref={regenerateButton} color="iconOnly" state="enabled" size="small" iconName="RefreshCw" ariaLabel="Regenerate reply" onClick={regenerate} />
513
+ </Tooltip>
514
+ {/* A real app wraps the thanks in a polite live region. */}
515
+ {thanks && <Paragraph size="caption" tone="secondary" measure="none">Thanks. This helps the agent improve.</Paragraph>}
516
+ </Cluster>
517
+ {asking && (
518
+ <Cluster gap="small">
519
+ <Paragraph size="caption" tone="secondary" measure="none">What was wrong?</Paragraph>
520
+ {/* Each reason is an answer, not a filter, so it is not a toggle. A Cluster cannot be named:
521
+ a real app groups the reasons under the question, named 'What was wrong?'. */}
522
+ {reasons.map((r) => (
523
+ <Tag key={r} variant="contained" size="small" toggle={false} label={r} onClick={finish} />
524
+ ))}
525
+ <Button size="small" type="tertiary" state="enabled" label="Skip" onClickButton={finish} />
526
+ </Cluster>
527
+ )}
528
+ </Stack>
529
+ )
530
+ }
531
+ >
532
+ {working ? (
533
+ // A real app wraps this part in a polite live region, since StepList has none.
534
+ <Stack gap="medium">
535
+ <Paragraph size="caption" tone="secondary" measure="none">{secondsLine(seconds)}</Paragraph>
536
+ <StepList aria-label="Acme Agent's steps" steps={stepsUpTo(current)} />
537
+ </Stack>
538
+ ) : (
539
+ <Stack gap="small">
540
+ <Paragraph measure="none">{reply}</Paragraph>
541
+ {stopped && <Paragraph size="caption" tone="secondary" measure="none">Stopped. Nothing was changed.</Paragraph>}
542
+ </Stack>
543
+ )}
544
+ </Message>
545
+ </Stack>
546
+ </Stack>
547
+ </Center>
548
+ );
549
+ }
550
+ ```
551
+
552
+ Seen in: Scindo.
@@ -0,0 +1 @@
1
+ export default function ReplySourcesCards(): import("react").JSX.Element;
@@ -0,0 +1,83 @@
1
+ 'use client';
2
+ import { useState } from 'react';
3
+ import { BookOpen, Bot, MessageSquare, Plug } 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 SourceCard from '../../components/sourceCard';
12
+ import { Center, Cluster, Grid, Stack } from '../../components/layout';
13
+ var agentName = 'Acme Agent';
14
+ var request = { from: 'Dana Lee', at: new Date('2025-01-15T11:40:00Z'), text: 'What did we decide about the launch date?' };
15
+ var repliedAt = new Date('2025-01-15T11:41:00Z');
16
+ var reply = 'The launch moved to March 3. Ben asked for two more weeks of testing, and the team agreed in #launch on Jan 12.';
17
+ var kinds = {
18
+ chat: { label: 'Chat', icon: MessageSquare },
19
+ kb: { label: 'Knowledge base', icon: BookOpen },
20
+ };
21
+ var sources = [
22
+ { kind: 'chat', title: 'Launch date', where: '#launch · Jan 12', href: '/chat/launch/m-1042' },
23
+ { kind: 'kb', title: 'Launch plan 2025', where: 'Acme Design', href: '/docs/launch-plan-2025' },
24
+ { kind: 'chat', title: 'Testing schedule', where: '#qa · Jan 10', href: '/chat/qa/m-0981' },
25
+ { kind: 'kb', title: 'Release checklist', where: 'Acme Design', href: '/docs/release-checklist' },
26
+ { kind: 'chat', title: 'Budget for the launch', where: 'Private channel you are not in' },
27
+ { kind: 'kb', title: 'Press kit guide', where: 'Acme Marketing', href: '/docs/press-kit-guide' },
28
+ { kind: 'chat', title: 'Beta feedback', where: '#beta · Jan 8', href: '/chat/beta/m-0917' },
29
+ { kind: 'kb', title: 'Pricing for the new plans', where: 'Acme Design', href: '/docs/pricing' },
30
+ { kind: 'chat', title: 'Launch day roles', where: '#launch · Jan 14', href: '/chat/launch/m-1107' },
31
+ { kind: 'kb', title: 'Support playbook', where: 'Acme Support', href: '/docs/support-playbook' },
32
+ ];
33
+ var visible = 6;
34
+ // 'From Chat · Knowledge base': each kind once, in the order it first appears.
35
+ function kindsTag(list) {
36
+ var labels = [];
37
+ list.forEach(function (s) {
38
+ if (!labels.includes(kinds[s.kind].label))
39
+ labels.push(kinds[s.kind].label);
40
+ });
41
+ return "From ".concat(labels.join(' · '));
42
+ }
43
+ // The agent's marks, as the rule 'An agent says what it is' says.
44
+ function agentMeta(at) {
45
+ return (<>
46
+ <Tag variant="contained" size="small" label="Agent"/>
47
+ <TimeStamp createdAt={at} dateFormat="absolute" data="time"/>
48
+ <Paragraph size="caption" tone="secondary" measure="none">Model name</Paragraph>
49
+ </>);
50
+ }
51
+ export default function ReplySourcesCards() {
52
+ var _a = useState(false), expanded = _a[0], setExpanded = _a[1];
53
+ var shown = expanded ? sources : sources.slice(0, visible);
54
+ var more = sources.length - visible;
55
+ return (<Center width="page">
56
+ <Stack gap="large">
57
+ <Heading level={1} size="h5">Launch plan</Heading>
58
+ {/* A real app gives the list that holds the rows role="log". */}
59
+ <Stack gap="small">
60
+ <Message aria-label={request.from} avatar={<UserImage userHandle={request.from} decorative/>} name={request.from} meta={<TimeStamp createdAt={request.at} dateFormat="absolute" data="time"/>}>
61
+ <Paragraph measure="none">{request.text}</Paragraph>
62
+ </Message>
63
+ <Message aria-label={"".concat(agentName, ", agent")} avatar={<UserImage userHandle={agentName} icon={Bot} decorative/>} name={agentName} meta={agentMeta(repliedAt)}
64
+ // A reply that used no sources has no footer at all.
65
+ footer={<Stack gap="medium">
66
+ <Cluster>
67
+ <Tag variant="contained" size="small" color="success" icon={Plug} label={kindsTag(sources)}/>
68
+ </Cluster>
69
+ <Grid columns={2} gap="medium">
70
+ {shown.map(function (s) { return (
71
+ // A source in the product is a path; one on another site is an https:// URL and opens in a new tab.
72
+ <SourceCard key={"".concat(s.kind, ":").concat(s.title)} icon={kinds[s.kind].icon} title={s.title} meta={"".concat(kinds[s.kind].label, " \u00B7 ").concat(s.where)} href={s.href}/>); })}
73
+ </Grid>
74
+ {more > 0 && (<Cluster>
75
+ <Button size="small" type="textOnly" state="enabled" label={expanded ? 'Show Fewer' : "Show ".concat(more, " More")} aria-expanded={expanded} onClickButton={function () { return setExpanded(function (e) { return !e; }); }}/>
76
+ </Cluster>)}
77
+ </Stack>}>
78
+ <Paragraph measure="none">{reply}</Paragraph>
79
+ </Message>
80
+ </Stack>
81
+ </Stack>
82
+ </Center>);
83
+ }
@@ -0,0 +1 @@
1
+ export default function ReplySourcesTagOnly(): import("react").JSX.Element;