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,45 @@
1
+ 'use client';
2
+ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
3
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
4
+ if (ar || !(i in from)) {
5
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
6
+ ar[i] = from[i];
7
+ }
8
+ }
9
+ return to.concat(ar || Array.prototype.slice.call(from));
10
+ };
11
+ import { useState } from 'react';
12
+ import Message from '../../components/message';
13
+ import UserImage from '../../components/userImage';
14
+ import TimeStamp from '../../components/timeStamp';
15
+ import Heading from '../../components/heading';
16
+ import Paragraph from '../../components/paragraph';
17
+ import Composer from '../../components/composer';
18
+ import EmptyBox from '../../components/emptyBox';
19
+ import { Center, Stack } from '../../components/layout';
20
+ // A real app reads this from the session.
21
+ var me = 'Dana Lee';
22
+ export default function ConversationStartersNone() {
23
+ var _a = useState([]), thread = _a[0], setThread = _a[1];
24
+ var _b = useState(''), text = _b[0], setText = _b[1];
25
+ function send() {
26
+ // A real app sends the message to the server here and shows it at once.
27
+ setThread(function (rows) { return __spreadArray(__spreadArray([], rows, true), [{ id: "m".concat(rows.length + 1), from: me, at: new Date(), text: text.trim() }], false); });
28
+ setText('');
29
+ }
30
+ return (<Center width="page">
31
+ <Stack gap="large">
32
+ <Heading level={1} size="h5">Launch plan</Heading>
33
+ {thread.length === 0 ? (
34
+ // A thread between people: no starters, and secondText says what to do.
35
+ <EmptyBox size="large" icon="MessageCircle" text="No messages yet" secondText="Send the first message to the team in Launch plan."/>) : (
36
+ // A real app gives the list that holds the rows role="log".
37
+ <Stack gap="small">
38
+ {thread.map(function (m) { return (<Message key={m.id} aria-label={m.from} avatar={<UserImage userHandle={m.from} decorative/>} name={m.from} meta={<TimeStamp createdAt={m.at} dateFormat="absolute" data="time"/>}>
39
+ <Paragraph measure="none">{m.text}</Paragraph>
40
+ </Message>); })}
41
+ </Stack>)}
42
+ <Composer id="conversation-starters-none-message" aria-label="Message" placeholder="Message the team" value={text} onChange={setText} onSubmit={send}/>
43
+ </Stack>
44
+ </Center>);
45
+ }
@@ -0,0 +1,208 @@
1
+ # Conversation starters
2
+
3
+ A thread has no messages yet, and the person may not know what to write first.
4
+
5
+ **Not built yet:** Scindo on the web shows its starters as `Tag`s under the `EmptyBox`, not as its `action`. It shows them in threads between people too, and puts '@Agent' before the text.
6
+
7
+ ## Do
8
+
9
+ - Show the empty thread as the rule 'An empty list says what will fill it' says. Use `EmptyBox` with `size="large"`, the `text` 'No messages yet', and a `secondText` that says what to do.
10
+ - Pass the starters as the `action`: a `Cluster` of three or four clickable `Tag`s, each a short thing to ask in the person's words.
11
+ - Pass `toggle={false}` to each starter `Tag`, so it is a plain button and not a toggle.
12
+ - Use `Tag`, not Button: a starter is a phrase the person might say, and a Button label is in Title Case.
13
+ - Fill the Composer with the starter and focus it, with the caret at the end. Do not send it: the person reads it and can change it first.
14
+ - Say who reads the message in the placeholder: 'Message Acme Agent'.
15
+ - Hide the starters once the thread has a message.
16
+ - Write the starters for the place: in a task, ask about the plan; in a channel, ask about what the team discussed.
17
+
18
+ ## Don't
19
+
20
+ - Do not send a starter on a click.
21
+ - Do not show starters in a thread between people. Say what to do in `secondText` instead.
22
+ - Do not offer more than four starters.
23
+ - Do not write starters in the system's words, such as 'Run summary'.
24
+
25
+ ## Option: Things to ask
26
+
27
+ Use when: A conversation with the agent: three or four things to ask it.
28
+
29
+ Uses: `Center`, `Cluster`, `Composer`, `EmptyBox`, `Heading`, `Message`, `Paragraph`, `Stack`, `Tag`, `TimeStamp`, `UserImage`
30
+
31
+ ```tsx
32
+ 'use client';
33
+ import { useEffect, useRef, useState } from 'react';
34
+ import Message from 'oneslash-design-system/components/message';
35
+ import UserImage from 'oneslash-design-system/components/userImage';
36
+ import TimeStamp from 'oneslash-design-system/components/timeStamp';
37
+ import Heading from 'oneslash-design-system/components/heading';
38
+ import Paragraph from 'oneslash-design-system/components/paragraph';
39
+ import Composer from 'oneslash-design-system/components/composer';
40
+ import EmptyBox from 'oneslash-design-system/components/emptyBox';
41
+ import Tag from 'oneslash-design-system/components/tag';
42
+ import { Center, Cluster, Stack } from 'oneslash-design-system/components/layout';
43
+
44
+ // A real app reads this from the session.
45
+ const me = 'Dana Lee';
46
+ const agentName = 'Acme Agent';
47
+
48
+ // Things to ask, in the person's words.
49
+ const starters = [
50
+ 'Summarize the launch plan',
51
+ 'Draft the launch email',
52
+ 'List what is still open',
53
+ 'Check the pricing page for mistakes',
54
+ ];
55
+
56
+ type Row = { id: string; from: string; at: Date; text: string };
57
+
58
+ export default function ConversationStartersChips() {
59
+ const [thread, setThread] = useState<Row[]>([]);
60
+ const [text, setText] = useState('');
61
+ // Set when a starter fills the field; the effect below focuses it with the caret at the end.
62
+ const [filled, setFilled] = useState(0);
63
+ const field = useRef<HTMLTextAreaElement>(null);
64
+
65
+ useEffect(() => {
66
+ if (!filled || !field.current) return;
67
+ const end = field.current.value.length;
68
+ field.current.focus();
69
+ field.current.setSelectionRange(end, end);
70
+ }, [filled]);
71
+
72
+ // Fills the field and does not send: the person can change it first.
73
+ function fillWith(starter: string) {
74
+ setText(starter);
75
+ setFilled((n) => n + 1);
76
+ }
77
+
78
+ function send() {
79
+ // A real app sends the message to the agent here and shows it at once.
80
+ setThread((rows) => [...rows, { id: `m${rows.length + 1}`, from: me, at: new Date(), text: text.trim() }]);
81
+ setText('');
82
+ }
83
+
84
+ return (
85
+ <Center width="page">
86
+ <Stack gap="large">
87
+ <Heading level={1} size="h5">{`Ask ${agentName}`}</Heading>
88
+ {thread.length === 0 ? (
89
+ <EmptyBox
90
+ size="large"
91
+ icon="MessageCircle"
92
+ text="No messages yet"
93
+ secondText={`Ask ${agentName} about the launch, or start with one of these.`}
94
+ action={
95
+ <Cluster gap="small">
96
+ {starters.map((s) => (
97
+ <Tag key={s} variant="contained" size="small" label={s} toggle={false} onClick={() => fillWith(s)} />
98
+ ))}
99
+ </Cluster>
100
+ }
101
+ />
102
+ ) : (
103
+ // A real app gives the list that holds the rows role="log".
104
+ <Stack gap="small">
105
+ {thread.map((m) => (
106
+ <Message
107
+ key={m.id}
108
+ aria-label={m.from}
109
+ avatar={<UserImage userHandle={m.from} decorative />}
110
+ name={m.from}
111
+ meta={<TimeStamp createdAt={m.at} dateFormat="absolute" data="time" />}
112
+ >
113
+ <Paragraph measure="none">{m.text}</Paragraph>
114
+ </Message>
115
+ ))}
116
+ </Stack>
117
+ )}
118
+ <Composer
119
+ ref={field}
120
+ id="conversation-starters-chips-message"
121
+ aria-label="Message"
122
+ placeholder={`Message ${agentName}`}
123
+ value={text}
124
+ onChange={setText}
125
+ onSubmit={send}
126
+ />
127
+ </Stack>
128
+ </Center>
129
+ );
130
+ }
131
+ ```
132
+
133
+ ## Option: No starters
134
+
135
+ Use when: A thread between people, where the agent is not the one asked.
136
+
137
+ Uses: `Center`, `Composer`, `EmptyBox`, `Heading`, `Message`, `Paragraph`, `Stack`, `TimeStamp`, `UserImage`
138
+
139
+ ```tsx
140
+ 'use client';
141
+ import { useState } from 'react';
142
+ import Message from 'oneslash-design-system/components/message';
143
+ import UserImage from 'oneslash-design-system/components/userImage';
144
+ import TimeStamp from 'oneslash-design-system/components/timeStamp';
145
+ import Heading from 'oneslash-design-system/components/heading';
146
+ import Paragraph from 'oneslash-design-system/components/paragraph';
147
+ import Composer from 'oneslash-design-system/components/composer';
148
+ import EmptyBox from 'oneslash-design-system/components/emptyBox';
149
+ import { Center, Stack } from 'oneslash-design-system/components/layout';
150
+
151
+ // A real app reads this from the session.
152
+ const me = 'Dana Lee';
153
+
154
+ type Row = { id: string; from: string; at: Date; text: string };
155
+
156
+ export default function ConversationStartersNone() {
157
+ const [thread, setThread] = useState<Row[]>([]);
158
+ const [text, setText] = useState('');
159
+
160
+ function send() {
161
+ // A real app sends the message to the server here and shows it at once.
162
+ setThread((rows) => [...rows, { id: `m${rows.length + 1}`, from: me, at: new Date(), text: text.trim() }]);
163
+ setText('');
164
+ }
165
+
166
+ return (
167
+ <Center width="page">
168
+ <Stack gap="large">
169
+ <Heading level={1} size="h5">Launch plan</Heading>
170
+ {thread.length === 0 ? (
171
+ // A thread between people: no starters, and secondText says what to do.
172
+ <EmptyBox
173
+ size="large"
174
+ icon="MessageCircle"
175
+ text="No messages yet"
176
+ secondText="Send the first message to the team in Launch plan."
177
+ />
178
+ ) : (
179
+ // A real app gives the list that holds the rows role="log".
180
+ <Stack gap="small">
181
+ {thread.map((m) => (
182
+ <Message
183
+ key={m.id}
184
+ aria-label={m.from}
185
+ avatar={<UserImage userHandle={m.from} decorative />}
186
+ name={m.from}
187
+ meta={<TimeStamp createdAt={m.at} dateFormat="absolute" data="time" />}
188
+ >
189
+ <Paragraph measure="none">{m.text}</Paragraph>
190
+ </Message>
191
+ ))}
192
+ </Stack>
193
+ )}
194
+ <Composer
195
+ id="conversation-starters-none-message"
196
+ aria-label="Message"
197
+ placeholder="Message the team"
198
+ value={text}
199
+ onChange={setText}
200
+ onSubmit={send}
201
+ />
202
+ </Stack>
203
+ </Center>
204
+ );
205
+ }
206
+ ```
207
+
208
+ Seen in: Scindo.
@@ -0,0 +1 @@
1
+ export default function MentionListInComposer(): import("react").JSX.Element;
@@ -0,0 +1,169 @@
1
+ 'use client';
2
+ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
3
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
4
+ if (ar || !(i in from)) {
5
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
6
+ ar[i] = from[i];
7
+ }
8
+ }
9
+ return to.concat(ar || Array.prototype.slice.call(from));
10
+ };
11
+ import { useEffect, useRef, useState } from 'react';
12
+ import { Bot } from 'lucide-react';
13
+ import Message from '../../components/message';
14
+ import UserImage from '../../components/userImage';
15
+ import TimeStamp from '../../components/timeStamp';
16
+ import Heading from '../../components/heading';
17
+ import Paragraph from '../../components/paragraph';
18
+ import Composer from '../../components/composer';
19
+ import Menu from '../../components/menu';
20
+ import MenuItem from '../../components/menuItem';
21
+ import { Center, Stack } from '../../components/layout';
22
+ // A real app reads these from the session and the workspace.
23
+ var me = 'Dana Lee';
24
+ // The agent comes first.
25
+ var members = [
26
+ { id: 'acme-agent', name: 'Acme Agent', agent: true },
27
+ { id: 'ben-carter', name: 'Ben Carter' },
28
+ { id: 'dana-lee', name: 'Dana Lee' },
29
+ { id: 'omar-reyes', name: 'Omar Reyes' },
30
+ ];
31
+ var listId = 'mention-list-suggestions';
32
+ // The list shows at most this many names; typing more letters narrows it.
33
+ var MAX_MATCHES = 8;
34
+ var optionId = function (m) { return "mention-list-option-".concat(m.id); };
35
+ var firstThread = [
36
+ { id: 'm1', from: 'Ben Carter', at: new Date('2025-01-15T11:40:00Z'), text: 'The pricing page is live.' },
37
+ { id: 'm2', from: 'Omar Reyes', at: new Date('2025-01-15T11:42:00Z'), text: 'Who checks the links before we announce it?' },
38
+ ];
39
+ // Opens with the person part-way through a mention, so the list shows.
40
+ var firstText = 'Can you check the links, @';
41
+ // The word after the @ that ends the text before the caret, or null when there is none. The @ starts
42
+ // the text or follows a space, so an email address such as dana@example.com opens nothing.
43
+ function mentionQuery(before) {
44
+ var match = before.match(/(?:^|\s)@(\w*)$/);
45
+ return match ? match[1] : null;
46
+ }
47
+ // The query for where the caret is now.
48
+ function queryAtCaret(field) {
49
+ var _a;
50
+ return mentionQuery(field.value.slice(0, (_a = field.selectionStart) !== null && _a !== void 0 ? _a : field.value.length));
51
+ }
52
+ // Names with a word that starts with what was typed, at most 8. The person typing is left out.
53
+ function matches(query) {
54
+ var q = query.toLowerCase();
55
+ return members.filter(function (m) { return m.name !== me && m.name.toLowerCase().split(' ').some(function (w) { return w.startsWith(q); }); }).slice(0, MAX_MATCHES);
56
+ }
57
+ export default function MentionListInComposer() {
58
+ var _a = useState(firstThread), thread = _a[0], setThread = _a[1];
59
+ var _b = useState(firstText), text = _b[0], setText = _b[1];
60
+ var _c = useState(mentionQuery(firstText)), query = _c[0], setQuery = _c[1];
61
+ var _d = useState(0), active = _d[0], setActive = _d[1];
62
+ // Where the caret goes after a pick; the effect below puts it there once the new text is in the field.
63
+ var _e = useState(null), caret = _e[0], setCaret = _e[1];
64
+ var field = useRef(null);
65
+ var results = query === null ? [] : matches(query);
66
+ // No match: the list closes.
67
+ var open = results.length > 0;
68
+ // The field opens with the caret at the end, after the @.
69
+ useEffect(function () {
70
+ var _a, _b, _c;
71
+ var end = (_b = (_a = field.current) === null || _a === void 0 ? void 0 : _a.value.length) !== null && _b !== void 0 ? _b : 0;
72
+ (_c = field.current) === null || _c === void 0 ? void 0 : _c.setSelectionRange(end, end);
73
+ }, []);
74
+ useEffect(function () {
75
+ if (caret === null || !field.current)
76
+ return;
77
+ field.current.focus();
78
+ field.current.setSelectionRange(caret, caret);
79
+ setCaret(null);
80
+ }, [caret]);
81
+ function change(value) {
82
+ var _a, _b;
83
+ setText(value);
84
+ var at = (_b = (_a = field.current) === null || _a === void 0 ? void 0 : _a.selectionStart) !== null && _b !== void 0 ? _b : value.length;
85
+ setQuery(mentionQuery(value.slice(0, at)));
86
+ setActive(0);
87
+ }
88
+ // The caret moved (an arrow key, a click, Home or End): the list follows the word at the caret, and
89
+ // closes when the caret leaves it.
90
+ function caretMoved(e) {
91
+ var next = queryAtCaret(e.currentTarget);
92
+ if (next === query)
93
+ return;
94
+ setQuery(next);
95
+ setActive(0);
96
+ }
97
+ // Puts '@Name ' in place of the @ and the word typed so far, and the caret after the space.
98
+ function pick(m) {
99
+ var _a, _b;
100
+ var at = (_b = (_a = field.current) === null || _a === void 0 ? void 0 : _a.selectionStart) !== null && _b !== void 0 ? _b : text.length;
101
+ var before = text.slice(0, at);
102
+ var start = before.lastIndexOf('@');
103
+ if (start < 0)
104
+ return;
105
+ var inserted = "@".concat(m.name, " ");
106
+ setText(before.slice(0, start) + inserted + text.slice(at));
107
+ setQuery(null);
108
+ setCaret(start + inserted.length);
109
+ }
110
+ // While the list is open it takes the arrows, Enter, Tab and Escape, so Enter picks instead of sending.
111
+ function keyDown(e) {
112
+ // An input method (Korean, Japanese, Chinese) uses Enter and the arrows while it composes: leave them to it.
113
+ if (e.nativeEvent.isComposing || e.keyCode === 229)
114
+ return;
115
+ if (!open)
116
+ return;
117
+ if (e.key === 'ArrowDown') {
118
+ e.preventDefault();
119
+ setActive(function (i) { return Math.min(i + 1, results.length - 1); });
120
+ }
121
+ else if (e.key === 'ArrowUp') {
122
+ e.preventDefault();
123
+ setActive(function (i) { return Math.max(i - 1, 0); });
124
+ }
125
+ else if (e.key === 'Enter' || (e.key === 'Tab' && !e.shiftKey)) {
126
+ // Check the word at the caret again before taking the key. If nothing matches now, the list
127
+ // closes and the key does what it always does: Enter sends, Tab moves on. Shift+Tab is never a pick.
128
+ var now = queryAtCaret(e.currentTarget);
129
+ var found = now === null ? [] : matches(now);
130
+ if (found.length === 0) {
131
+ setQuery(null);
132
+ return;
133
+ }
134
+ e.preventDefault();
135
+ pick(found[now === query ? Math.min(active, found.length - 1) : 0]);
136
+ }
137
+ else if (e.key === 'Escape') {
138
+ e.preventDefault();
139
+ e.stopPropagation();
140
+ setQuery(null);
141
+ }
142
+ }
143
+ function send() {
144
+ // A real app sends the message to the server here and shows it at once.
145
+ setThread(function (rows) { return __spreadArray(__spreadArray([], rows, true), [{ id: "m".concat(rows.length + 1), from: me, at: new Date(), text: text.trim() }], false); });
146
+ setText('');
147
+ setQuery(null);
148
+ }
149
+ return (<Center width="page">
150
+ <Stack gap="large">
151
+ <Heading level={1} size="h5">Launch plan</Heading>
152
+ {/* A real app gives the list that holds the rows role="log". */}
153
+ <Stack gap="small">
154
+ {thread.map(function (m) { return (<Message key={m.id} aria-label={m.from} avatar={<UserImage userHandle={m.from} decorative/>} name={m.from} meta={<TimeStamp createdAt={m.at} dateFormat="absolute" data="time"/>}>
155
+ <Paragraph measure="none">{m.text}</Paragraph>
156
+ </Message>); })}
157
+ </Stack>
158
+ <Composer ref={field} id="mention-list-message" aria-label="Message" placeholder="Message the team" value={text} onChange={change} onSubmit={send} onKeyDown={keyDown} onSelect={caretMoved}
159
+ // A press on a row keeps focus in the field, so this runs only when focus leaves for good.
160
+ onBlur={function () { return setQuery(null); }}
161
+ // Focus stays in the field; the field points at the list and at the highlighted row.
162
+ role="combobox" aria-autocomplete="list" aria-expanded={open} aria-controls={open ? listId : undefined} aria-activedescendant={open ? optionId(results[active]) : undefined} above={open ? (<Menu role="listbox" id={listId} aria-label="People and agents" width={280}>
163
+ {results.map(function (m, i) { return (<MenuItem key={m.id} id={optionId(m)} role="option" tabIndex={-1} isActive={i === active} aria-selected={i === active} size="small"
164
+ // A person may have no picture, so the avatar goes in icon: UserImage shows the initial.
165
+ icon={m.agent ? <UserImage userHandle={m.name} icon={Bot} size={20} decorative/> : <UserImage userHandle={m.name} size={20} decorative/>} label={m.name} tag={m.agent ? { label: 'Agent' } : undefined} onClick={function () { return pick(m); }}/>); })}
166
+ </Menu>) : undefined}/>
167
+ </Stack>
168
+ </Center>);
169
+ }
@@ -0,0 +1,252 @@
1
+ # Mention list
2
+
3
+ A person types @ in the message box to name someone, or the agent.
4
+
5
+ **Not built yet:** Scindo on the web builds its list from buttons, so a screen reader in the field does not hear which name is highlighted. It shows no 'Agent' tag on the agent's row.
6
+
7
+ ## Do
8
+
9
+ - Open the list when the person types @ at the start of the text or after a space. A bare @ opens it, and each letter after it narrows it.
10
+ - Show at most 8 names. Typing more letters finds the rest.
11
+ - Build it as a combobox. The text area gets `role="combobox"`, `aria-expanded`, `aria-controls` and `aria-activedescendant`, and the list in `above` is a `Menu role="listbox"` of `MenuItem role="option"` rows with `isActive` and `aria-selected`.
12
+ - Show each person's avatar and name. A person with no picture shows their initial, and the avatar is not read aloud, since the name is.
13
+ - Put the agent first, with its icon avatar and an 'Agent' tag, as the rule 'An agent says what it is' says.
14
+ - Keep focus in the message box while the list is open, so the person keeps typing.
15
+ - Move the highlight with the arrow keys. Enter or Tab picks the highlighted name, and Escape closes the list.
16
+ - Leave Enter and the arrow keys to an input method while it is still composing, such as for Korean or Japanese.
17
+ - Close the list when the caret moves out of the name being typed, and when focus leaves the message box.
18
+ - Check the word at the caret again on Enter or Tab, and pick only if a name still matches. Shift+Tab picks nothing.
19
+ - Put the name in at the caret with a space after it, and put the caret after the space.
20
+ - Close the list when no name matches.
21
+ - Leave out the person who is typing.
22
+
23
+ ## Don't
24
+
25
+ - Do not move focus into the list. The person keeps typing in the field.
26
+ - Do not send the message on the Enter that picks a name.
27
+ - Do not show an empty list.
28
+ - Do not open the list for an @ inside a word, such as in an email address.
29
+ - Do not show the agent with a photo or an initial.
30
+
31
+ ## Example: List in the composer
32
+
33
+ Uses: `Center`, `Composer`, `Heading`, `Menu`, `MenuItem`, `Message`, `Paragraph`, `Stack`, `TimeStamp`, `UserImage`
34
+
35
+ ```tsx
36
+ 'use client';
37
+ import { useEffect, useRef, useState, type KeyboardEvent, type SyntheticEvent } from 'react';
38
+ import { Bot } from 'lucide-react';
39
+ import Message from 'oneslash-design-system/components/message';
40
+ import UserImage from 'oneslash-design-system/components/userImage';
41
+ import TimeStamp from 'oneslash-design-system/components/timeStamp';
42
+ import Heading from 'oneslash-design-system/components/heading';
43
+ import Paragraph from 'oneslash-design-system/components/paragraph';
44
+ import Composer from 'oneslash-design-system/components/composer';
45
+ import Menu from 'oneslash-design-system/components/menu';
46
+ import MenuItem from 'oneslash-design-system/components/menuItem';
47
+ import { Center, Stack } from 'oneslash-design-system/components/layout';
48
+
49
+ // A real app reads these from the session and the workspace.
50
+ const me = 'Dana Lee';
51
+ type Member = { id: string; name: string; agent?: boolean };
52
+ // The agent comes first.
53
+ const members: Member[] = [
54
+ { id: 'acme-agent', name: 'Acme Agent', agent: true },
55
+ { id: 'ben-carter', name: 'Ben Carter' },
56
+ { id: 'dana-lee', name: 'Dana Lee' },
57
+ { id: 'omar-reyes', name: 'Omar Reyes' },
58
+ ];
59
+
60
+ const listId = 'mention-list-suggestions';
61
+ // The list shows at most this many names; typing more letters narrows it.
62
+ const MAX_MATCHES = 8;
63
+ const optionId = (m: Member) => `mention-list-option-${m.id}`;
64
+
65
+ type Row = { id: string; from: string; at: Date; text: string };
66
+
67
+ const firstThread: Row[] = [
68
+ { id: 'm1', from: 'Ben Carter', at: new Date('2025-01-15T11:40:00Z'), text: 'The pricing page is live.' },
69
+ { id: 'm2', from: 'Omar Reyes', at: new Date('2025-01-15T11:42:00Z'), text: 'Who checks the links before we announce it?' },
70
+ ];
71
+
72
+ // Opens with the person part-way through a mention, so the list shows.
73
+ const firstText = 'Can you check the links, @';
74
+
75
+ // The word after the @ that ends the text before the caret, or null when there is none. The @ starts
76
+ // the text or follows a space, so an email address such as dana@example.com opens nothing.
77
+ function mentionQuery(before: string) {
78
+ const match = before.match(/(?:^|\s)@(\w*)$/);
79
+ return match ? match[1] : null;
80
+ }
81
+
82
+ // The query for where the caret is now.
83
+ function queryAtCaret(field: HTMLTextAreaElement) {
84
+ return mentionQuery(field.value.slice(0, field.selectionStart ?? field.value.length));
85
+ }
86
+
87
+ // Names with a word that starts with what was typed, at most 8. The person typing is left out.
88
+ function matches(query: string) {
89
+ const q = query.toLowerCase();
90
+ return members.filter((m) => m.name !== me && m.name.toLowerCase().split(' ').some((w) => w.startsWith(q))).slice(0, MAX_MATCHES);
91
+ }
92
+
93
+ export default function MentionListInComposer() {
94
+ const [thread, setThread] = useState(firstThread);
95
+ const [text, setText] = useState(firstText);
96
+ const [query, setQuery] = useState<string | null>(mentionQuery(firstText));
97
+ const [active, setActive] = useState(0);
98
+ // Where the caret goes after a pick; the effect below puts it there once the new text is in the field.
99
+ const [caret, setCaret] = useState<number | null>(null);
100
+ const field = useRef<HTMLTextAreaElement>(null);
101
+
102
+ const results = query === null ? [] : matches(query);
103
+ // No match: the list closes.
104
+ const open = results.length > 0;
105
+
106
+ // The field opens with the caret at the end, after the @.
107
+ useEffect(() => {
108
+ const end = field.current?.value.length ?? 0;
109
+ field.current?.setSelectionRange(end, end);
110
+ }, []);
111
+
112
+ useEffect(() => {
113
+ if (caret === null || !field.current) return;
114
+ field.current.focus();
115
+ field.current.setSelectionRange(caret, caret);
116
+ setCaret(null);
117
+ }, [caret]);
118
+
119
+ function change(value: string) {
120
+ setText(value);
121
+ const at = field.current?.selectionStart ?? value.length;
122
+ setQuery(mentionQuery(value.slice(0, at)));
123
+ setActive(0);
124
+ }
125
+
126
+ // The caret moved (an arrow key, a click, Home or End): the list follows the word at the caret, and
127
+ // closes when the caret leaves it.
128
+ function caretMoved(e: SyntheticEvent<HTMLTextAreaElement>) {
129
+ const next = queryAtCaret(e.currentTarget);
130
+ if (next === query) return;
131
+ setQuery(next);
132
+ setActive(0);
133
+ }
134
+
135
+ // Puts '@Name ' in place of the @ and the word typed so far, and the caret after the space.
136
+ function pick(m: Member) {
137
+ const at = field.current?.selectionStart ?? text.length;
138
+ const before = text.slice(0, at);
139
+ const start = before.lastIndexOf('@');
140
+ if (start < 0) return;
141
+ const inserted = `@${m.name} `;
142
+ setText(before.slice(0, start) + inserted + text.slice(at));
143
+ setQuery(null);
144
+ setCaret(start + inserted.length);
145
+ }
146
+
147
+ // While the list is open it takes the arrows, Enter, Tab and Escape, so Enter picks instead of sending.
148
+ function keyDown(e: KeyboardEvent<HTMLTextAreaElement>) {
149
+ // An input method (Korean, Japanese, Chinese) uses Enter and the arrows while it composes: leave them to it.
150
+ if (e.nativeEvent.isComposing || e.keyCode === 229) return;
151
+ if (!open) return;
152
+ if (e.key === 'ArrowDown') {
153
+ e.preventDefault();
154
+ setActive((i) => Math.min(i + 1, results.length - 1));
155
+ } else if (e.key === 'ArrowUp') {
156
+ e.preventDefault();
157
+ setActive((i) => Math.max(i - 1, 0));
158
+ } else if (e.key === 'Enter' || (e.key === 'Tab' && !e.shiftKey)) {
159
+ // Check the word at the caret again before taking the key. If nothing matches now, the list
160
+ // closes and the key does what it always does: Enter sends, Tab moves on. Shift+Tab is never a pick.
161
+ const now = queryAtCaret(e.currentTarget);
162
+ const found = now === null ? [] : matches(now);
163
+ if (found.length === 0) {
164
+ setQuery(null);
165
+ return;
166
+ }
167
+ e.preventDefault();
168
+ pick(found[now === query ? Math.min(active, found.length - 1) : 0]);
169
+ } else if (e.key === 'Escape') {
170
+ e.preventDefault();
171
+ e.stopPropagation();
172
+ setQuery(null);
173
+ }
174
+ }
175
+
176
+ function send() {
177
+ // A real app sends the message to the server here and shows it at once.
178
+ setThread((rows) => [...rows, { id: `m${rows.length + 1}`, from: me, at: new Date(), text: text.trim() }]);
179
+ setText('');
180
+ setQuery(null);
181
+ }
182
+
183
+ return (
184
+ <Center width="page">
185
+ <Stack gap="large">
186
+ <Heading level={1} size="h5">Launch plan</Heading>
187
+ {/* A real app gives the list that holds the rows role="log". */}
188
+ <Stack gap="small">
189
+ {thread.map((m) => (
190
+ <Message
191
+ key={m.id}
192
+ aria-label={m.from}
193
+ avatar={<UserImage userHandle={m.from} decorative />}
194
+ name={m.from}
195
+ meta={<TimeStamp createdAt={m.at} dateFormat="absolute" data="time" />}
196
+ >
197
+ <Paragraph measure="none">{m.text}</Paragraph>
198
+ </Message>
199
+ ))}
200
+ </Stack>
201
+ <Composer
202
+ ref={field}
203
+ id="mention-list-message"
204
+ aria-label="Message"
205
+ placeholder="Message the team"
206
+ value={text}
207
+ onChange={change}
208
+ onSubmit={send}
209
+ onKeyDown={keyDown}
210
+ onSelect={caretMoved}
211
+ // A press on a row keeps focus in the field, so this runs only when focus leaves for good.
212
+ onBlur={() => setQuery(null)}
213
+ // Focus stays in the field; the field points at the list and at the highlighted row.
214
+ role="combobox"
215
+ aria-autocomplete="list"
216
+ aria-expanded={open}
217
+ aria-controls={open ? listId : undefined}
218
+ aria-activedescendant={open ? optionId(results[active]) : undefined}
219
+ above={
220
+ open ? (
221
+ <Menu role="listbox" id={listId} aria-label="People and agents" width={280}>
222
+ {results.map((m, i) => (
223
+ <MenuItem
224
+ key={m.id}
225
+ id={optionId(m)}
226
+ role="option"
227
+ tabIndex={-1}
228
+ isActive={i === active}
229
+ aria-selected={i === active}
230
+ size="small"
231
+ // A person may have no picture, so the avatar goes in icon: UserImage shows the initial.
232
+ icon={m.agent ? <UserImage userHandle={m.name} icon={Bot} size={20} decorative /> : <UserImage userHandle={m.name} size={20} decorative />}
233
+ label={m.name}
234
+ tag={m.agent ? { label: 'Agent' } : undefined}
235
+ onClick={() => pick(m)}
236
+ />
237
+ ))}
238
+ </Menu>
239
+ ) : undefined
240
+ }
241
+ />
242
+ </Stack>
243
+ </Center>
244
+ );
245
+ }
246
+ ```
247
+
248
+ ## Native
249
+
250
+ On Apple the list shows above the field, the agent with a sparkles icon and people with a person icon. A name is picked with a click or a tap.
251
+
252
+ Seen in: Scindo.