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.
- package/README.md +1 -1
- package/dist/DESIGN.md +26 -3
- package/dist/cases/accept-invite/signed-in.jsx +1 -1
- package/dist/cases/accept-invite/signed-out.jsx +1 -1
- package/dist/cases/accept-invite.md +2 -2
- package/dist/cases/agent-options/cards.d.ts +1 -0
- package/dist/cases/agent-options/cards.jsx +91 -0
- package/dist/cases/agent-options.md +168 -0
- package/dist/cases/agent-pending-reply/steps.d.ts +1 -0
- package/dist/cases/agent-pending-reply/steps.jsx +149 -0
- package/dist/cases/agent-pending-reply/streaming.d.ts +1 -0
- package/dist/cases/agent-pending-reply/streaming.jsx +146 -0
- package/dist/cases/agent-pending-reply.md +432 -0
- package/dist/cases/agent-plan-proposal/changes.d.ts +1 -0
- package/dist/cases/agent-plan-proposal/changes.jsx +224 -0
- package/dist/cases/agent-plan-proposal/steps.d.ts +1 -0
- package/dist/cases/agent-plan-proposal/steps.jsx +211 -0
- package/dist/cases/agent-plan-proposal.md +656 -0
- package/dist/cases/agent-question/choices.d.ts +1 -0
- package/dist/cases/agent-question/choices.jsx +132 -0
- package/dist/cases/agent-question/free-text.d.ts +1 -0
- package/dist/cases/agent-question/free-text.jsx +81 -0
- package/dist/cases/agent-question.md +338 -0
- package/dist/cases/agent-shows-sources.md +2 -2
- package/dist/cases/artifact-card/card.d.ts +1 -0
- package/dist/cases/artifact-card/card.jsx +45 -0
- package/dist/cases/artifact-card.md +103 -0
- package/dist/cases/composer-limit/notice-with-action.d.ts +1 -0
- package/dist/cases/composer-limit/notice-with-action.jsx +87 -0
- package/dist/cases/composer-limit/notice.d.ts +1 -0
- package/dist/cases/composer-limit/notice.jsx +84 -0
- package/dist/cases/composer-limit.md +286 -0
- package/dist/cases/conversation-starters/chips.d.ts +1 -0
- package/dist/cases/conversation-starters/chips.jsx +69 -0
- package/dist/cases/conversation-starters/none.d.ts +1 -0
- package/dist/cases/conversation-starters/none.jsx +45 -0
- package/dist/cases/conversation-starters.md +208 -0
- package/dist/cases/mention-list/in-composer.d.ts +1 -0
- package/dist/cases/mention-list/in-composer.jsx +169 -0
- package/dist/cases/mention-list.md +252 -0
- package/dist/cases/message-actions/hover-toolbar.d.ts +1 -0
- package/dist/cases/message-actions/hover-toolbar.jsx +229 -0
- package/dist/cases/message-actions/menu.d.ts +1 -0
- package/dist/cases/message-actions/menu.jsx +258 -0
- package/dist/cases/message-actions.md +651 -0
- package/dist/cases/message-attachments/in-composer.d.ts +1 -0
- package/dist/cases/message-attachments/in-composer.jsx +134 -0
- package/dist/cases/message-attachments/in-message.d.ts +1 -0
- package/dist/cases/message-attachments/in-message.jsx +46 -0
- package/dist/cases/message-attachments.md +310 -0
- package/dist/cases/message-composer/plain.d.ts +1 -0
- package/dist/cases/message-composer/plain.jsx +57 -0
- package/dist/cases/message-composer/with-tools.d.ts +1 -0
- package/dist/cases/message-composer/with-tools.jsx +182 -0
- package/dist/cases/message-composer.md +356 -0
- package/dist/cases/message-edit/in-place.d.ts +1 -0
- package/dist/cases/message-edit/in-place.jsx +99 -0
- package/dist/cases/message-edit.md +179 -0
- package/dist/cases/message-reactions/chips.d.ts +1 -0
- package/dist/cases/message-reactions/chips.jsx +118 -0
- package/dist/cases/message-reactions/quick-pick.d.ts +1 -0
- package/dist/cases/message-reactions/quick-pick.jsx +155 -0
- package/dist/cases/message-reactions.md +371 -0
- package/dist/cases/message-row/grouped.d.ts +1 -0
- package/dist/cases/message-row/grouped.jsx +56 -0
- package/dist/cases/message-row/person-and-agent.d.ts +1 -0
- package/dist/cases/message-row/person-and-agent.jsx +41 -0
- package/dist/cases/message-row.md +189 -0
- package/dist/cases/reply-feedback/thumbs.d.ts +1 -0
- package/dist/cases/reply-feedback/thumbs.jsx +191 -0
- package/dist/cases/reply-feedback/with-reason.d.ts +1 -0
- package/dist/cases/reply-feedback/with-reason.jsx +221 -0
- package/dist/cases/reply-feedback.md +552 -0
- package/dist/cases/reply-sources/cards.d.ts +1 -0
- package/dist/cases/reply-sources/cards.jsx +83 -0
- package/dist/cases/reply-sources/tag-only.d.ts +1 -0
- package/dist/cases/reply-sources/tag-only.jsx +45 -0
- package/dist/cases/reply-sources.md +247 -0
- package/dist/cases/slash-command-list/in-composer.d.ts +1 -0
- package/dist/cases/slash-command-list/in-composer.jsx +162 -0
- package/dist/cases/slash-command-list.md +247 -0
- package/dist/cases/success-feedback.md +1 -1
- package/dist/cases/typing-and-status/line.d.ts +1 -0
- package/dist/cases/typing-and-status/line.jsx +50 -0
- package/dist/cases/typing-and-status.md +96 -0
- package/dist/cases.json +1276 -14
- package/dist/components/button.d.ts +3 -2
- package/dist/components/button.jsx +9 -7
- package/dist/components/composer.d.ts +74 -0
- package/dist/components/composer.jsx +122 -0
- package/dist/components/fileChip.d.ts +33 -0
- package/dist/components/fileChip.jsx +61 -0
- package/dist/components/iconButton.d.ts +3 -3
- package/dist/components/iconButton.jsx +9 -7
- package/dist/components/layout.d.ts +7 -1
- package/dist/components/layout.jsx +5 -2
- package/dist/components/menu.d.ts +21 -0
- package/dist/components/menu.jsx +27 -3
- package/dist/components/menuItem.d.ts +9 -1
- package/dist/components/menuItem.jsx +5 -4
- package/dist/components/message.d.ts +28 -0
- package/dist/components/message.jsx +25 -0
- package/dist/components/paragraph.d.ts +3 -1
- package/dist/components/paragraph.jsx +2 -2
- package/dist/components/popover.d.ts +7 -1
- package/dist/components/popover.jsx +35 -9
- package/dist/components/radioGroup.d.ts +8 -1
- package/dist/components/radioGroup.jsx +19 -8
- package/dist/components/sourceCard.d.ts +23 -0
- package/dist/components/sourceCard.jsx +56 -0
- package/dist/components/stepList.d.ts +17 -0
- package/dist/components/stepList.jsx +79 -0
- package/dist/components/tag.d.ts +9 -1
- package/dist/components/tag.jsx +6 -4
- package/dist/components/textarea.jsx +3 -18
- package/dist/components/userImage.d.ts +9 -1
- package/dist/components/userImage.jsx +10 -3
- package/dist/internal/autoGrow.d.ts +11 -0
- package/dist/internal/autoGrow.js +28 -0
- package/dist/internal/composer.d.ts +16 -0
- package/dist/internal/composer.js +18 -0
- package/dist/internal/menu.d.ts +6 -0
- package/dist/internal/menu.js +31 -0
- package/dist/native-mapping.json +32 -1
- package/dist/stories/Button.stories.d.ts +1 -0
- package/dist/stories/Button.stories.jsx +17 -1
- package/dist/stories/Cases.generated.stories.d.ts +30 -0
- package/dist/stories/Cases.generated.stories.jsx +60 -0
- package/dist/stories/Composer.stories.d.ts +23 -0
- package/dist/stories/Composer.stories.jsx +121 -0
- package/dist/stories/FileChip.stories.d.ts +7 -0
- package/dist/stories/FileChip.stories.jsx +35 -0
- package/dist/stories/IconButton.stories.d.ts +1 -0
- package/dist/stories/IconButton.stories.jsx +18 -1
- package/dist/stories/Menu.stories.d.ts +4 -0
- package/dist/stories/Menu.stories.jsx +46 -1
- package/dist/stories/MenuItem.stories.d.ts +1 -0
- package/dist/stories/MenuItem.stories.jsx +8 -0
- package/dist/stories/Message.stories.d.ts +10 -0
- package/dist/stories/Message.stories.jsx +77 -0
- package/dist/stories/PageComponents.stories.d.ts +1 -0
- package/dist/stories/PageComponents.stories.jsx +21 -0
- package/dist/stories/RadioGroup.stories.d.ts +2 -0
- package/dist/stories/RadioGroup.stories.jsx +40 -1
- package/dist/stories/SourceCard.stories.d.ts +8 -0
- package/dist/stories/SourceCard.stories.jsx +33 -0
- package/dist/stories/StepList.stories.d.ts +8 -0
- package/dist/stories/StepList.stories.jsx +35 -0
- package/dist/stories/UserImage.stories.d.ts +2 -0
- package/dist/stories/UserImage.stories.jsx +19 -0
- package/package.json +4 -3
|
@@ -0,0 +1,247 @@
|
|
|
1
|
+
# Command list
|
|
2
|
+
|
|
3
|
+
A person types / at the start of the message box to run a command.
|
|
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 command is highlighted. Both Scindo apps run a command with no argument as soon as it is picked.
|
|
6
|
+
|
|
7
|
+
## Do
|
|
8
|
+
|
|
9
|
+
- Open the list when the text starts with /. A bare / opens it, each letter after it narrows it, and a space closes it.
|
|
10
|
+
- Show at most 8 commands. 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 command with one line on what it does, and the argument it takes, such as '[topic]'. A menu row has no code font yet, so the command is plain text.
|
|
13
|
+
- Keep focus in the message box while the list is open, so the person keeps typing.
|
|
14
|
+
- Use the same keys as the case 'Mention list': the arrows move, Enter or Tab picks, Escape closes.
|
|
15
|
+
- Leave Enter and the arrow keys to an input method while it is still composing, such as for Korean or Japanese.
|
|
16
|
+
- Close the list when the caret moves out of the command being typed, and when focus leaves the message box.
|
|
17
|
+
- Check the word at the caret again on Enter or Tab, and pick only if a command still matches. Shift+Tab picks nothing.
|
|
18
|
+
- Put the command and a space in place of the '/word' before the caret, and keep the text after it.
|
|
19
|
+
- Put the caret after that space, so the person can type the argument.
|
|
20
|
+
- Run the command when the person sends it. Every command works this way, even one that takes no argument.
|
|
21
|
+
- Close the list when no command matches.
|
|
22
|
+
|
|
23
|
+
## Don't
|
|
24
|
+
|
|
25
|
+
- Do not move focus into the list. The person keeps typing in the field.
|
|
26
|
+
- Do not run a command on the Enter that picks it.
|
|
27
|
+
- Do not show an empty list.
|
|
28
|
+
- Do not open the list for a / in the middle of the text.
|
|
29
|
+
|
|
30
|
+
## Example: List in the composer
|
|
31
|
+
|
|
32
|
+
Uses: `Center`, `Composer`, `Heading`, `Menu`, `MenuItem`, `Message`, `Paragraph`, `Stack`, `TimeStamp`, `UserImage`
|
|
33
|
+
|
|
34
|
+
```tsx
|
|
35
|
+
'use client';
|
|
36
|
+
import { useEffect, useRef, useState, type KeyboardEvent, type SyntheticEvent } from 'react';
|
|
37
|
+
import Message from 'oneslash-design-system/components/message';
|
|
38
|
+
import UserImage from 'oneslash-design-system/components/userImage';
|
|
39
|
+
import TimeStamp from 'oneslash-design-system/components/timeStamp';
|
|
40
|
+
import Heading from 'oneslash-design-system/components/heading';
|
|
41
|
+
import Paragraph from 'oneslash-design-system/components/paragraph';
|
|
42
|
+
import Composer from 'oneslash-design-system/components/composer';
|
|
43
|
+
import Menu from 'oneslash-design-system/components/menu';
|
|
44
|
+
import MenuItem from 'oneslash-design-system/components/menuItem';
|
|
45
|
+
import { Center, Stack } from 'oneslash-design-system/components/layout';
|
|
46
|
+
|
|
47
|
+
// A real app reads this from the session.
|
|
48
|
+
const me = 'Dana Lee';
|
|
49
|
+
|
|
50
|
+
type Command = { name: string; does: string; argument?: string };
|
|
51
|
+
const commands: Command[] = [
|
|
52
|
+
{ name: 'plan', does: 'Ask the agent for a plan before it acts' },
|
|
53
|
+
{ name: 'summarize', does: 'Sum up this thread', argument: '[topic]' },
|
|
54
|
+
{ name: 'remind', does: 'Set a reminder for this thread', argument: '[time]' },
|
|
55
|
+
{ name: 'status', does: 'Show what the agent is working on' },
|
|
56
|
+
];
|
|
57
|
+
|
|
58
|
+
const listId = 'slash-command-list-commands';
|
|
59
|
+
// The list shows at most this many commands; typing more letters narrows it.
|
|
60
|
+
const MAX_MATCHES = 8;
|
|
61
|
+
const optionId = (c: Command) => `slash-command-list-option-${c.name}`;
|
|
62
|
+
|
|
63
|
+
type Row = { id: string; from: string; at: Date; text: string; command?: boolean };
|
|
64
|
+
|
|
65
|
+
const firstThread: Row[] = [
|
|
66
|
+
{ id: 'm1', from: 'Ben Carter', at: new Date('2025-01-15T11:40:00Z'), text: 'The pricing page is live.' },
|
|
67
|
+
{ id: 'm2', from: 'Omar Reyes', at: new Date('2025-01-15T11:42:00Z'), text: 'I missed the morning. What did we decide?' },
|
|
68
|
+
];
|
|
69
|
+
|
|
70
|
+
// Opens with a / typed, so the list shows every command.
|
|
71
|
+
const firstText = '/';
|
|
72
|
+
|
|
73
|
+
// The word after a / at the start of the text before the caret, or null once there is a space or no /.
|
|
74
|
+
function commandQuery(before: string) {
|
|
75
|
+
const match = before.match(/^\/(\S*)$/);
|
|
76
|
+
return match ? match[1] : null;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
// The query for where the caret is now.
|
|
80
|
+
function queryAtCaret(field: HTMLTextAreaElement) {
|
|
81
|
+
return commandQuery(field.value.slice(0, field.selectionStart ?? field.value.length));
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
const matches = (query: string) => commands.filter((c) => c.name.startsWith(query.toLowerCase())).slice(0, MAX_MATCHES);
|
|
85
|
+
|
|
86
|
+
export default function SlashCommandListInComposer() {
|
|
87
|
+
const [thread, setThread] = useState(firstThread);
|
|
88
|
+
const [text, setText] = useState(firstText);
|
|
89
|
+
const [query, setQuery] = useState<string | null>(commandQuery(firstText));
|
|
90
|
+
const [active, setActive] = useState(0);
|
|
91
|
+
// Where the caret goes after a pick; the effect below puts it there once the new text is in the field.
|
|
92
|
+
const [caret, setCaret] = useState<number | null>(null);
|
|
93
|
+
const field = useRef<HTMLTextAreaElement>(null);
|
|
94
|
+
|
|
95
|
+
const results = query === null ? [] : matches(query);
|
|
96
|
+
// No match: the list closes.
|
|
97
|
+
const open = results.length > 0;
|
|
98
|
+
|
|
99
|
+
// The field opens with the caret at the end, after the /.
|
|
100
|
+
useEffect(() => {
|
|
101
|
+
const end = field.current?.value.length ?? 0;
|
|
102
|
+
field.current?.setSelectionRange(end, end);
|
|
103
|
+
}, []);
|
|
104
|
+
|
|
105
|
+
useEffect(() => {
|
|
106
|
+
if (caret === null || !field.current) return;
|
|
107
|
+
field.current.focus();
|
|
108
|
+
field.current.setSelectionRange(caret, caret);
|
|
109
|
+
setCaret(null);
|
|
110
|
+
}, [caret]);
|
|
111
|
+
|
|
112
|
+
function change(value: string) {
|
|
113
|
+
setText(value);
|
|
114
|
+
const at = field.current?.selectionStart ?? value.length;
|
|
115
|
+
setQuery(commandQuery(value.slice(0, at)));
|
|
116
|
+
setActive(0);
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
// The caret moved (an arrow key, a click, Home or End): the list follows the word at the caret, and
|
|
120
|
+
// closes when the caret leaves it.
|
|
121
|
+
function caretMoved(e: SyntheticEvent<HTMLTextAreaElement>) {
|
|
122
|
+
const next = queryAtCaret(e.currentTarget);
|
|
123
|
+
if (next === query) return;
|
|
124
|
+
setQuery(next);
|
|
125
|
+
setActive(0);
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
// Puts '/name ' in place of the '/word' before the caret and keeps the text after it. The caret goes
|
|
129
|
+
// after the space, so the person can type the argument. Nothing runs yet.
|
|
130
|
+
function pick(c: Command) {
|
|
131
|
+
const at = field.current?.selectionStart ?? text.length;
|
|
132
|
+
const insert = `/${c.name} `;
|
|
133
|
+
// One space between the command and what follows, not two.
|
|
134
|
+
const after = text.slice(at).replace(/^ /, '');
|
|
135
|
+
setText(insert + after);
|
|
136
|
+
setQuery(null);
|
|
137
|
+
setCaret(insert.length);
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
// While the list is open it takes the arrows, Enter, Tab and Escape, so Enter picks instead of sending.
|
|
141
|
+
function keyDown(e: KeyboardEvent<HTMLTextAreaElement>) {
|
|
142
|
+
// An input method (Korean, Japanese, Chinese) uses Enter and the arrows while it composes: leave them to it.
|
|
143
|
+
if (e.nativeEvent.isComposing || e.keyCode === 229) return;
|
|
144
|
+
if (!open) return;
|
|
145
|
+
if (e.key === 'ArrowDown') {
|
|
146
|
+
e.preventDefault();
|
|
147
|
+
setActive((i) => Math.min(i + 1, results.length - 1));
|
|
148
|
+
} else if (e.key === 'ArrowUp') {
|
|
149
|
+
e.preventDefault();
|
|
150
|
+
setActive((i) => Math.max(i - 1, 0));
|
|
151
|
+
} else if (e.key === 'Enter' || (e.key === 'Tab' && !e.shiftKey)) {
|
|
152
|
+
// Check the word at the caret again before taking the key. If nothing matches now, the list
|
|
153
|
+
// closes and the key does what it always does: Enter sends, Tab moves on. Shift+Tab is never a pick.
|
|
154
|
+
const now = queryAtCaret(e.currentTarget);
|
|
155
|
+
const found = now === null ? [] : matches(now);
|
|
156
|
+
if (found.length === 0) {
|
|
157
|
+
setQuery(null);
|
|
158
|
+
return;
|
|
159
|
+
}
|
|
160
|
+
e.preventDefault();
|
|
161
|
+
pick(found[now === query ? Math.min(active, found.length - 1) : 0]);
|
|
162
|
+
} else if (e.key === 'Escape') {
|
|
163
|
+
e.preventDefault();
|
|
164
|
+
e.stopPropagation();
|
|
165
|
+
setQuery(null);
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
// A real app runs the command here. This one shows it in the thread.
|
|
170
|
+
function send() {
|
|
171
|
+
const value = text.trim();
|
|
172
|
+
setThread((rows) => [...rows, { id: `m${rows.length + 1}`, from: me, at: new Date(), text: value, command: value.startsWith('/') }]);
|
|
173
|
+
setText('');
|
|
174
|
+
setQuery(null);
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
return (
|
|
178
|
+
<Center width="page">
|
|
179
|
+
<Stack gap="large">
|
|
180
|
+
<Heading level={1} size="h5">Launch plan</Heading>
|
|
181
|
+
{/* A real app gives the list that holds the rows role="log". */}
|
|
182
|
+
<Stack gap="small">
|
|
183
|
+
{thread.map((m) => (
|
|
184
|
+
<Message
|
|
185
|
+
key={m.id}
|
|
186
|
+
aria-label={m.from}
|
|
187
|
+
avatar={<UserImage userHandle={m.from} decorative />}
|
|
188
|
+
name={m.from}
|
|
189
|
+
meta={<TimeStamp createdAt={m.at} dateFormat="absolute" data="time" />}
|
|
190
|
+
>
|
|
191
|
+
<Paragraph measure="none" mono={m.command}>{m.text}</Paragraph>
|
|
192
|
+
</Message>
|
|
193
|
+
))}
|
|
194
|
+
</Stack>
|
|
195
|
+
<Composer
|
|
196
|
+
ref={field}
|
|
197
|
+
id="slash-command-list-message"
|
|
198
|
+
aria-label="Message"
|
|
199
|
+
placeholder="Message the team, or type / for commands"
|
|
200
|
+
value={text}
|
|
201
|
+
onChange={change}
|
|
202
|
+
onSubmit={send}
|
|
203
|
+
onKeyDown={keyDown}
|
|
204
|
+
onSelect={caretMoved}
|
|
205
|
+
// A press on a row keeps focus in the field, so this runs only when focus leaves for good.
|
|
206
|
+
onBlur={() => setQuery(null)}
|
|
207
|
+
// Focus stays in the field; the field points at the list and at the highlighted row.
|
|
208
|
+
role="combobox"
|
|
209
|
+
aria-autocomplete="list"
|
|
210
|
+
aria-expanded={open}
|
|
211
|
+
aria-controls={open ? listId : undefined}
|
|
212
|
+
aria-activedescendant={open ? optionId(results[active]) : undefined}
|
|
213
|
+
above={
|
|
214
|
+
open ? (
|
|
215
|
+
<Menu role="listbox" id={listId} aria-label="Commands" width={400}>
|
|
216
|
+
{results.map((c, i) => (
|
|
217
|
+
<MenuItem
|
|
218
|
+
key={c.name}
|
|
219
|
+
id={optionId(c)}
|
|
220
|
+
role="option"
|
|
221
|
+
tabIndex={-1}
|
|
222
|
+
isActive={i === active}
|
|
223
|
+
aria-selected={i === active}
|
|
224
|
+
size="small"
|
|
225
|
+
iconName="SquareSlash"
|
|
226
|
+
// MenuItem has no mono label, so the command is plain text.
|
|
227
|
+
label={`/${c.name}`}
|
|
228
|
+
secondLabel={c.does}
|
|
229
|
+
tag={c.argument ? { label: c.argument, variant: 'textOnly' } : undefined}
|
|
230
|
+
onClick={() => pick(c)}
|
|
231
|
+
/>
|
|
232
|
+
))}
|
|
233
|
+
</Menu>
|
|
234
|
+
) : undefined
|
|
235
|
+
}
|
|
236
|
+
/>
|
|
237
|
+
</Stack>
|
|
238
|
+
</Center>
|
|
239
|
+
);
|
|
240
|
+
}
|
|
241
|
+
```
|
|
242
|
+
|
|
243
|
+
## Native
|
|
244
|
+
|
|
245
|
+
On Apple the list shows above the field with the command, what it does and, when it takes an argument, its usage. Escape closes the list on a Mac.
|
|
246
|
+
|
|
247
|
+
Seen in: Scindo.
|
|
@@ -4,7 +4,7 @@ Something the person did has worked.
|
|
|
4
4
|
|
|
5
5
|
## Answer
|
|
6
6
|
|
|
7
|
-
The feedback depends on where the result shows. A Button that is `loading` keeps its label, and the spinner shows that it is working. Only success changes a label, and there are three success labels: 'Saved', 'Copied' and 'Sent', each for 2 seconds. When a form saves in place, its Button is `loading`, then reads 'Saved' for 2 seconds, then its own label again. There is no toast. Sometimes the result is somewhere else or gone. Something was deleted, sent, moved or duplicated somewhere else, or a long job has finished. Then call `toast({ type: 'success', message: '…' })` with one short sentence in the past tense, in sentence case. It closes after 5 seconds. When something is copied to the clipboard, a Button reads 'Copied' for 2 seconds, and an IconButton swaps its icon to `Check` for 2 seconds. When a Button sends an email again, it reads 'Sent' for 2 seconds. The message names the thing and does not say 'successfully'.
|
|
7
|
+
The feedback depends on where the result shows. A Button that is `loading` keeps its label, and the spinner shows that it is working. Only success changes a label, and there are three success labels: 'Saved', 'Copied' and 'Sent', each for 2 seconds. When a form saves in place, its Button is `loading`, then reads 'Saved' for 2 seconds, then its own label again. There is no toast. Sometimes the result is somewhere else or gone. Something was deleted, sent, moved or duplicated somewhere else, or a long job has finished. Then call `toast({ type: 'success', message: '…' })` with one short sentence in the past tense, in sentence case. It closes after 5 seconds. When something is copied to the clipboard, a Button reads 'Copied' for 2 seconds, and an IconButton swaps its icon to `Check` for 2 seconds. When Copy is a menu item, the menu closes, so a toast says 'Message copied.' instead. When a Button sends an email again, it reads 'Sent' for 2 seconds. The message names the thing and does not say 'successfully'.
|
|
8
8
|
|
|
9
9
|
**Not built yet:** Scindo on the web has no toast. It shows success in five ways: a 'Saved' Button label, a green caption, an inline Alert, a thank-you that replaces a dialog and a 'Copied' label. The timed ones clear after 1.5, 2, 3 or 4 seconds. Commentify shows toasts through `Alert`, one at a time, and many of them say 'successfully'.
|
|
10
10
|
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default function TypingAndStatusLine(): import("react").JSX.Element;
|
|
@@ -0,0 +1,50 @@
|
|
|
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 { Center, Stack } from '../../components/layout';
|
|
19
|
+
// A real app reads this from the session.
|
|
20
|
+
var me = 'Dana Lee';
|
|
21
|
+
var firstThread = [
|
|
22
|
+
{ id: 'm1', from: 'Omar Reyes', at: new Date('2025-01-15T11:38:00Z'), text: 'Is the launch email going out today?' },
|
|
23
|
+
{ id: 'm2', from: me, at: new Date('2025-01-15T11:40:00Z'), text: 'Ben has the final copy. Ben, can you confirm?' },
|
|
24
|
+
];
|
|
25
|
+
export default function TypingAndStatusLine() {
|
|
26
|
+
var _a = useState(firstThread), thread = _a[0], setThread = _a[1];
|
|
27
|
+
var _b = useState(''), text = _b[0], setText = _b[1];
|
|
28
|
+
function send() {
|
|
29
|
+
// A real app sends the message to the server here and shows it at once.
|
|
30
|
+
setThread(function (rows) { return __spreadArray(__spreadArray([], rows, true), [{ id: "m".concat(rows.length + 1), from: me, at: new Date(), text: text.trim() }], false); });
|
|
31
|
+
setText('');
|
|
32
|
+
}
|
|
33
|
+
return (<Center width="page">
|
|
34
|
+
<Stack gap="large">
|
|
35
|
+
<Heading level={1} size="h5">Launch plan</Heading>
|
|
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
|
+
<Stack gap="small">
|
|
43
|
+
{/* One person typing. Two: 'Ben and Omar are typing…'. Three or more: 'Ben and 2 others are typing…'.
|
|
44
|
+
A real app removes the line a few seconds after the last keystroke. It is not a live region. */}
|
|
45
|
+
<Paragraph size="caption" tone="secondary" measure="none">Ben is typing…</Paragraph>
|
|
46
|
+
<Composer id="typing-and-status-message" aria-label="Message" placeholder="Message the team" value={text} onChange={setText} onSubmit={send}/>
|
|
47
|
+
</Stack>
|
|
48
|
+
</Stack>
|
|
49
|
+
</Center>);
|
|
50
|
+
}
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
# Typing line
|
|
2
|
+
|
|
3
|
+
Other people in the thread are writing a message that has not arrived yet.
|
|
4
|
+
|
|
5
|
+
**Not built yet:** Scindo on the web names people by their full name and ends the line with three dots.
|
|
6
|
+
|
|
7
|
+
## Do
|
|
8
|
+
|
|
9
|
+
- Show one line just above the Composer, in small secondary text: `<Paragraph size="caption" tone="secondary">`.
|
|
10
|
+
- Name one person by first name: 'Ben is typing…'.
|
|
11
|
+
- Name two people: 'Ben and Omar are typing…'.
|
|
12
|
+
- Name the first person and count the rest when three or more type: 'Ben and 2 others are typing…'.
|
|
13
|
+
- End the line with an ellipsis, one character.
|
|
14
|
+
- Remove the line a few seconds after the last keystroke, or when the message arrives.
|
|
15
|
+
- Leave out the person who is reading.
|
|
16
|
+
- Show an agent at work with its progress row, not as typing. The case 'Agent at work' has the pattern.
|
|
17
|
+
- Keep the line out of a live region. It changes too often to read aloud.
|
|
18
|
+
|
|
19
|
+
## Don't
|
|
20
|
+
|
|
21
|
+
- Do not say an agent is typing.
|
|
22
|
+
- Do not list every name when three or more people type.
|
|
23
|
+
|
|
24
|
+
## Example: Line above the composer
|
|
25
|
+
|
|
26
|
+
Uses: `Center`, `Composer`, `Heading`, `Message`, `Paragraph`, `Stack`, `TimeStamp`, `UserImage`
|
|
27
|
+
|
|
28
|
+
```tsx
|
|
29
|
+
'use client';
|
|
30
|
+
import { useState } from 'react';
|
|
31
|
+
import Message from 'oneslash-design-system/components/message';
|
|
32
|
+
import UserImage from 'oneslash-design-system/components/userImage';
|
|
33
|
+
import TimeStamp from 'oneslash-design-system/components/timeStamp';
|
|
34
|
+
import Heading from 'oneslash-design-system/components/heading';
|
|
35
|
+
import Paragraph from 'oneslash-design-system/components/paragraph';
|
|
36
|
+
import Composer from 'oneslash-design-system/components/composer';
|
|
37
|
+
import { Center, Stack } from 'oneslash-design-system/components/layout';
|
|
38
|
+
|
|
39
|
+
// A real app reads this from the session.
|
|
40
|
+
const me = 'Dana Lee';
|
|
41
|
+
|
|
42
|
+
type Row = { id: string; from: string; at: Date; text: string };
|
|
43
|
+
|
|
44
|
+
const firstThread: Row[] = [
|
|
45
|
+
{ id: 'm1', from: 'Omar Reyes', at: new Date('2025-01-15T11:38:00Z'), text: 'Is the launch email going out today?' },
|
|
46
|
+
{ id: 'm2', from: me, at: new Date('2025-01-15T11:40:00Z'), text: 'Ben has the final copy. Ben, can you confirm?' },
|
|
47
|
+
];
|
|
48
|
+
|
|
49
|
+
export default function TypingAndStatusLine() {
|
|
50
|
+
const [thread, setThread] = useState(firstThread);
|
|
51
|
+
const [text, setText] = useState('');
|
|
52
|
+
|
|
53
|
+
function send() {
|
|
54
|
+
// A real app sends the message to the server here and shows it at once.
|
|
55
|
+
setThread((rows) => [...rows, { id: `m${rows.length + 1}`, from: me, at: new Date(), text: text.trim() }]);
|
|
56
|
+
setText('');
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
return (
|
|
60
|
+
<Center width="page">
|
|
61
|
+
<Stack gap="large">
|
|
62
|
+
<Heading level={1} size="h5">Launch plan</Heading>
|
|
63
|
+
{/* A real app gives the list that holds the rows role="log". */}
|
|
64
|
+
<Stack gap="small">
|
|
65
|
+
{thread.map((m) => (
|
|
66
|
+
<Message
|
|
67
|
+
key={m.id}
|
|
68
|
+
aria-label={m.from}
|
|
69
|
+
avatar={<UserImage userHandle={m.from} decorative />}
|
|
70
|
+
name={m.from}
|
|
71
|
+
meta={<TimeStamp createdAt={m.at} dateFormat="absolute" data="time" />}
|
|
72
|
+
>
|
|
73
|
+
<Paragraph measure="none">{m.text}</Paragraph>
|
|
74
|
+
</Message>
|
|
75
|
+
))}
|
|
76
|
+
</Stack>
|
|
77
|
+
<Stack gap="small">
|
|
78
|
+
{/* One person typing. Two: 'Ben and Omar are typing…'. Three or more: 'Ben and 2 others are typing…'.
|
|
79
|
+
A real app removes the line a few seconds after the last keystroke. It is not a live region. */}
|
|
80
|
+
<Paragraph size="caption" tone="secondary" measure="none">Ben is typing…</Paragraph>
|
|
81
|
+
<Composer
|
|
82
|
+
id="typing-and-status-message"
|
|
83
|
+
aria-label="Message"
|
|
84
|
+
placeholder="Message the team"
|
|
85
|
+
value={text}
|
|
86
|
+
onChange={setText}
|
|
87
|
+
onSubmit={send}
|
|
88
|
+
/>
|
|
89
|
+
</Stack>
|
|
90
|
+
</Stack>
|
|
91
|
+
</Center>
|
|
92
|
+
);
|
|
93
|
+
}
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
Seen in: Scindo.
|