oneslash-design-system 2.22.0 → 2.23.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 +12 -1
- package/dist/cases/admin-inbox/split.jsx +22 -10
- package/dist/cases/admin-inbox.md +28 -23
- package/dist/cases/api-keys.md +1 -1
- package/dist/cases/breadcrumb/back-link.d.ts +1 -0
- package/dist/cases/breadcrumb/back-link.jsx +23 -0
- package/dist/cases/breadcrumb/trail.d.ts +1 -0
- package/dist/cases/breadcrumb/trail.jsx +28 -0
- package/dist/cases/breadcrumb.md +105 -0
- package/dist/cases/date-field/calendar.d.ts +1 -0
- package/dist/cases/date-field/calendar.jsx +80 -0
- package/dist/cases/date-field/typed.d.ts +1 -0
- package/dist/cases/date-field/typed.jsx +58 -0
- package/dist/cases/date-field.md +232 -0
- package/dist/cases/docs-component-page/reference.jsx +11 -1
- package/dist/cases/docs-component-page.md +19 -8
- package/dist/cases/file-upload/files.d.ts +1 -0
- package/dist/cases/file-upload/files.jsx +118 -0
- package/dist/cases/file-upload/picture.d.ts +1 -0
- package/dist/cases/file-upload/picture.jsx +50 -0
- package/dist/cases/file-upload.md +270 -0
- package/dist/cases/filter-menu.md +1 -1
- package/dist/cases/image-viewer/with-video.d.ts +1 -0
- package/dist/cases/image-viewer/with-video.jsx +42 -0
- package/dist/cases/image-viewer.md +72 -4
- package/dist/cases/master-detail/split.jsx +17 -10
- package/dist/cases/master-detail.md +26 -24
- package/dist/cases/message-reactions/picker.d.ts +1 -0
- package/dist/cases/message-reactions/picker.jsx +145 -0
- package/dist/cases/message-reactions/quick-pick.jsx +1 -1
- package/dist/cases/message-reactions.md +184 -3
- package/dist/cases/page-header.md +1 -1
- package/dist/cases/people-row/names.d.ts +1 -0
- package/dist/cases/people-row/names.jsx +20 -0
- package/dist/cases/people-row/stack.d.ts +1 -0
- package/dist/cases/people-row/stack.jsx +33 -0
- package/dist/cases/people-row.md +110 -0
- package/dist/cases/profile-form/form.jsx +21 -10
- package/dist/cases/profile-form.md +38 -9
- package/dist/cases.json +306 -25
- package/dist/components/avatarStack.d.ts +22 -0
- package/dist/components/avatarStack.jsx +32 -0
- package/dist/components/breadcrumb.d.ts +12 -0
- package/dist/components/breadcrumb.jsx +24 -0
- package/dist/components/calendar.d.ts +19 -0
- package/dist/components/calendar.jsx +126 -0
- package/dist/components/dateField.d.ts +35 -0
- package/dist/components/dateField.jsx +76 -0
- package/dist/components/dropZone.d.ts +53 -0
- package/dist/components/dropZone.jsx +136 -0
- package/dist/components/emojiPicker.d.ts +22 -0
- package/dist/components/emojiPicker.jsx +161 -0
- package/dist/components/itemList.d.ts +31 -0
- package/dist/components/itemList.jsx +81 -0
- package/dist/components/lightbox.d.ts +33 -9
- package/dist/components/lightbox.jsx +58 -27
- package/dist/components/menuItem.d.ts +1 -1
- package/dist/components/menuItem.jsx +3 -3
- package/dist/internal/date.d.ts +35 -0
- package/dist/internal/date.js +122 -0
- package/dist/internal/dropZone.d.ts +28 -0
- package/dist/internal/dropZone.js +42 -0
- package/dist/internal/emoji.d.ts +13 -0
- package/dist/internal/emoji.js +182 -0
- package/dist/internal/overlayStack.js +1 -1
- package/dist/internal/people.d.ts +1 -0
- package/dist/internal/people.js +12 -0
- package/dist/native-mapping.json +45 -3
- package/dist/stories/AvatarStack.stories.d.ts +7 -0
- package/dist/stories/AvatarStack.stories.jsx +46 -0
- package/dist/stories/Breadcrumb.stories.d.ts +7 -0
- package/dist/stories/Breadcrumb.stories.jsx +26 -0
- package/dist/stories/Calendar.stories.d.ts +6 -0
- package/dist/stories/Calendar.stories.jsx +15 -0
- package/dist/stories/Cases.generated.stories.d.ts +10 -0
- package/dist/stories/Cases.generated.stories.jsx +20 -0
- package/dist/stories/DateField.stories.d.ts +10 -0
- package/dist/stories/DateField.stories.jsx +132 -0
- package/dist/stories/DropZone.stories.d.ts +12 -0
- package/dist/stories/DropZone.stories.jsx +151 -0
- package/dist/stories/EmojiPicker.stories.d.ts +6 -0
- package/dist/stories/EmojiPicker.stories.jsx +92 -0
- package/dist/stories/ItemList.stories.d.ts +9 -0
- package/dist/stories/ItemList.stories.jsx +86 -0
- package/dist/stories/Lightbox.stories.d.ts +4 -0
- package/dist/stories/Lightbox.stories.jsx +44 -0
- package/package.json +3 -2
|
@@ -0,0 +1,270 @@
|
|
|
1
|
+
# File upload
|
|
2
|
+
|
|
3
|
+
A person adds a file from their device, such as a new profile picture or the receipts for a report.
|
|
4
|
+
|
|
5
|
+
## Do
|
|
6
|
+
|
|
7
|
+
- Use `DropZone`. A person can drop a file on it or choose one with its Button, so it works with a keyboard, a screen reader and touch.
|
|
8
|
+
- Use `size="compact"` around the picture for one picture, with `buttonLabel="Change Picture"`. Use the large zone with `multiple` and `maxFiles` for a list.
|
|
9
|
+
- Say what is allowed in `hint`, with the size from `formatBytes`: 'JPG, PNG or WebP, up to 5 MB'.
|
|
10
|
+
- Pass `accept` and `maxBytes`. The zone checks each file and reports the ones that do not pass, each with a reason.
|
|
11
|
+
- Turn each reason into words under the zone, through `FormField`, as the rule 'A form error shows next to the problem' says: 'Choose a JPG, PNG or WebP picture.' and 'Choose a picture under 5 MB.'
|
|
12
|
+
- Name the file when several are added at once: 'Hotel invoice.docx is not a PDF, PNG or JPG file.'
|
|
13
|
+
- Pass the `FormField`'s `aria-describedby` and `aria-invalid` to the zone, and the same error words as `status`, so the error is read with the control.
|
|
14
|
+
- Save a picture as soon as it is chosen, as the rule 'A setting saves in place, or with one Save Button' says. Show `loading` on 'Change Picture' while it saves, by passing `loading` to the zone, and nothing when it works.
|
|
15
|
+
- Show each file in a list as a `FileChip` with its type, its size and a remove button: 'Remove Hotel receipt.pdf'.
|
|
16
|
+
- Keep the list to the limit the hint names, across every choice: 'Add up to 5 files.'
|
|
17
|
+
- Save a list with one Save Button. It is disabled while nothing changed, shows `loading` while it saves, and reads 'Saved' for 2 seconds.
|
|
18
|
+
|
|
19
|
+
## Don't
|
|
20
|
+
|
|
21
|
+
- Do not make dropping the only way to add a file.
|
|
22
|
+
- Do not show a file error in a toast. Show it under the zone.
|
|
23
|
+
- Do not change the Button's label while it saves, such as to 'Saving…'.
|
|
24
|
+
- Do not write a size by hand. Use `formatBytes`, and check against the same number of bytes it shows.
|
|
25
|
+
- Do not refuse a file without saying why.
|
|
26
|
+
|
|
27
|
+
## Option: One picture beside its preview
|
|
28
|
+
|
|
29
|
+
Use when: One picture replaces the one shown, such as a profile picture.
|
|
30
|
+
|
|
31
|
+
Uses: `Center`, `DropZone`, `FormField`, `Heading`, `Stack`, `UserImage`, `formatBytes`
|
|
32
|
+
|
|
33
|
+
```tsx
|
|
34
|
+
'use client';
|
|
35
|
+
import { useEffect, useRef, useState } from 'react';
|
|
36
|
+
import Heading from 'oneslash-design-system/components/heading';
|
|
37
|
+
import FormField from 'oneslash-design-system/components/formField';
|
|
38
|
+
import DropZone, { type FileRejection } from 'oneslash-design-system/components/dropZone';
|
|
39
|
+
import UserImage from 'oneslash-design-system/components/userImage';
|
|
40
|
+
import { formatBytes } from 'oneslash-design-system/components/formatNumber';
|
|
41
|
+
import { Center, Stack } from 'oneslash-design-system/components/layout';
|
|
42
|
+
|
|
43
|
+
// A picture the person chose. A real app uploads the file and gets a URL back.
|
|
44
|
+
const chosenPicture =
|
|
45
|
+
"data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 64 64'%3E%3Crect width='64' height='64' fill='%232f6b4f'/%3E%3Ccircle cx='32' cy='25' r='11' fill='%23fff'/%3E%3Cpath d='M10 64c2-15 11-22 22-22s20 7 22 22z' fill='%23fff'/%3E%3C/svg%3E";
|
|
46
|
+
|
|
47
|
+
// 5 MB as formatBytes counts it (base 1024), so the words and the check agree
|
|
48
|
+
const maxBytes = 5 * 1024 * 1024;
|
|
49
|
+
|
|
50
|
+
// The zone reports a reason. The words are this page's, shown under the zone.
|
|
51
|
+
function say(rejections: FileRejection[]) {
|
|
52
|
+
const reason = rejections[0].reason;
|
|
53
|
+
if (reason === 'type') return 'Choose a JPG, PNG or WebP picture.';
|
|
54
|
+
if (reason === 'size') return `Choose a picture under ${formatBytes(maxBytes)}.`;
|
|
55
|
+
return 'Choose one picture.';
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export default function FileUploadPicture() {
|
|
59
|
+
const [picture, setPicture] = useState<string | undefined>(undefined);
|
|
60
|
+
const [saving, setSaving] = useState(false);
|
|
61
|
+
const [error, setError] = useState('');
|
|
62
|
+
const timer = useRef<ReturnType<typeof setTimeout>>();
|
|
63
|
+
|
|
64
|
+
// Stops the request if the example goes away before it ends.
|
|
65
|
+
useEffect(() => () => clearTimeout(timer.current), []);
|
|
66
|
+
|
|
67
|
+
// The picture is one control on its own, so it saves as soon as it is chosen. Nothing shows when it works.
|
|
68
|
+
// A real app crops the picture to a square in its own code or on the server.
|
|
69
|
+
function handleFiles() {
|
|
70
|
+
setError('');
|
|
71
|
+
setSaving(true);
|
|
72
|
+
// Stands in for the upload.
|
|
73
|
+
timer.current = setTimeout(() => {
|
|
74
|
+
setSaving(false);
|
|
75
|
+
setPicture(chosenPicture);
|
|
76
|
+
}, 900);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
return (
|
|
80
|
+
<Center width="form">
|
|
81
|
+
<Stack gap="large">
|
|
82
|
+
<Heading level={1} size="h5">Profile</Heading>
|
|
83
|
+
<FormField id="file-upload-picture" label="Picture" error={error}>
|
|
84
|
+
{(f) => (
|
|
85
|
+
<DropZone
|
|
86
|
+
id={f.id}
|
|
87
|
+
size="compact"
|
|
88
|
+
label="Drop a picture here"
|
|
89
|
+
buttonLabel="Change Picture"
|
|
90
|
+
hint={`JPG, PNG or WebP, up to ${formatBytes(maxBytes)}`}
|
|
91
|
+
accept={['image/jpeg', 'image/png', 'image/webp']}
|
|
92
|
+
maxBytes={maxBytes}
|
|
93
|
+
loading={saving}
|
|
94
|
+
aria-describedby={f['aria-describedby']}
|
|
95
|
+
aria-invalid={f['aria-invalid']}
|
|
96
|
+
status={error || undefined}
|
|
97
|
+
onFiles={handleFiles}
|
|
98
|
+
onReject={(rejections) => setError(say(rejections))}
|
|
99
|
+
>
|
|
100
|
+
<UserImage userHandle="Dana Lee" userImgUrl={picture} size={64} />
|
|
101
|
+
</DropZone>
|
|
102
|
+
)}
|
|
103
|
+
</FormField>
|
|
104
|
+
</Stack>
|
|
105
|
+
</Center>
|
|
106
|
+
);
|
|
107
|
+
}
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
## Option: Files that join a list
|
|
111
|
+
|
|
112
|
+
Use when: A few files are added to a list, such as attachments to a request.
|
|
113
|
+
|
|
114
|
+
Uses: `Button`, `Center`, `Cluster`, `DropZone`, `FileChip`, `Form`, `FormField`, `Heading`, `Paragraph`, `Stack`, `formatBytes`
|
|
115
|
+
|
|
116
|
+
```tsx
|
|
117
|
+
'use client';
|
|
118
|
+
import { useEffect, useRef, useState } from 'react';
|
|
119
|
+
import Heading from 'oneslash-design-system/components/heading';
|
|
120
|
+
import Paragraph from 'oneslash-design-system/components/paragraph';
|
|
121
|
+
import Form from 'oneslash-design-system/components/form';
|
|
122
|
+
import FormField from 'oneslash-design-system/components/formField';
|
|
123
|
+
import DropZone, { type FileRejection } from 'oneslash-design-system/components/dropZone';
|
|
124
|
+
import FileChip from 'oneslash-design-system/components/fileChip';
|
|
125
|
+
import Button from 'oneslash-design-system/components/button';
|
|
126
|
+
import { formatBytes } from 'oneslash-design-system/components/formatNumber';
|
|
127
|
+
import { Center, Cluster, Stack } from 'oneslash-design-system/components/layout';
|
|
128
|
+
|
|
129
|
+
type Chosen = { id: string; name: string; size: number };
|
|
130
|
+
|
|
131
|
+
const maxFiles = 5;
|
|
132
|
+
// 10 MB as formatBytes counts it (base 1024), so the words and the check agree
|
|
133
|
+
const maxBytes = 10 * 1024 * 1024;
|
|
134
|
+
|
|
135
|
+
// Two receipts saved earlier. A real app loads them with the request.
|
|
136
|
+
const savedFiles: Chosen[] = [
|
|
137
|
+
{ id: 'f1', name: 'Hotel receipt.pdf', size: 248_000 },
|
|
138
|
+
{ id: 'f2', name: 'Taxi receipt.png', size: 1_820_000 },
|
|
139
|
+
];
|
|
140
|
+
|
|
141
|
+
const kindOf = (name: string) => (name.split('.').pop() ?? '').toUpperCase();
|
|
142
|
+
|
|
143
|
+
// The zone reports reasons. The words are this page's, one line per file, shown under the zone,
|
|
144
|
+
// with the limit line when the same choice also had more files than the list has room for.
|
|
145
|
+
function say(rejections: FileRejection[], limit: string) {
|
|
146
|
+
return rejections
|
|
147
|
+
.map((r) =>
|
|
148
|
+
r.reason === 'type'
|
|
149
|
+
? `${r.name} is not a PDF, PNG or JPG file.`
|
|
150
|
+
: r.reason === 'size'
|
|
151
|
+
? `${r.name} is over ${formatBytes(maxBytes)}.`
|
|
152
|
+
: `Add up to ${maxFiles} files.`,
|
|
153
|
+
)
|
|
154
|
+
.concat(limit ? [limit] : [])
|
|
155
|
+
.filter((line, i, all) => all.indexOf(line) === i)
|
|
156
|
+
.join(' ');
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
export default function FileUploadFiles() {
|
|
160
|
+
const [files, setFiles] = useState<Chosen[]>(savedFiles);
|
|
161
|
+
const [saved, setSaved] = useState<Chosen[]>(savedFiles);
|
|
162
|
+
const [error, setError] = useState('');
|
|
163
|
+
const [saving, setSaving] = useState(false);
|
|
164
|
+
const [justSaved, setJustSaved] = useState(false);
|
|
165
|
+
const timers = useRef<ReturnType<typeof setTimeout>[]>([]);
|
|
166
|
+
const savedTimer = useRef<ReturnType<typeof setTimeout>>();
|
|
167
|
+
// Gives each chosen file its own id, so two files with one name are two rows.
|
|
168
|
+
const count = useRef(0);
|
|
169
|
+
// The limit line from the choice being handled. The zone calls onFiles, then onReject, for one choice,
|
|
170
|
+
// so onReject can keep it beside the reasons. It is cleared once that choice is done.
|
|
171
|
+
const limitLine = useRef('');
|
|
172
|
+
|
|
173
|
+
// Stops the request and the 'Saved' if the example goes away before they end.
|
|
174
|
+
useEffect(() => () => {
|
|
175
|
+
timers.current.forEach(clearTimeout);
|
|
176
|
+
clearTimeout(savedTimer.current);
|
|
177
|
+
}, []);
|
|
178
|
+
|
|
179
|
+
// The list holds five at most. The zone checks one choice; the page checks the list.
|
|
180
|
+
function handleFiles(chosen: File[]) {
|
|
181
|
+
const room = maxFiles - files.length;
|
|
182
|
+
const added = chosen.slice(0, Math.max(0, room)).map((file) => {
|
|
183
|
+
count.current += 1;
|
|
184
|
+
return { id: `new-${count.current}`, name: file.name, size: file.size };
|
|
185
|
+
});
|
|
186
|
+
setFiles((list) => [...list, ...added]);
|
|
187
|
+
limitLine.current = chosen.length > room ? `Add up to ${maxFiles} files.` : '';
|
|
188
|
+
Promise.resolve().then(() => { limitLine.current = ''; });
|
|
189
|
+
setError(limitLine.current);
|
|
190
|
+
setJustSaved(false);
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
function handleRemove(id: string) {
|
|
194
|
+
if (saving) return;
|
|
195
|
+
setFiles((list) => list.filter((f) => f.id !== id));
|
|
196
|
+
setError('');
|
|
197
|
+
setJustSaved(false);
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
// The list is a group with one Save Button: 'Saved' shows for 2 seconds, and the Button is disabled while nothing changed.
|
|
201
|
+
function handleSave() {
|
|
202
|
+
if (saving) return;
|
|
203
|
+
setSaving(true);
|
|
204
|
+
setError('');
|
|
205
|
+
// Stands in for the upload and the request to the server.
|
|
206
|
+
timers.current.push(setTimeout(() => {
|
|
207
|
+
setSaving(false);
|
|
208
|
+
setSaved(files);
|
|
209
|
+
setJustSaved(true);
|
|
210
|
+
clearTimeout(savedTimer.current);
|
|
211
|
+
savedTimer.current = setTimeout(() => setJustSaved(false), 2000);
|
|
212
|
+
}, 1200));
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
const changed = files.length !== saved.length || files.some((f, i) => f.id !== saved[i].id);
|
|
216
|
+
|
|
217
|
+
return (
|
|
218
|
+
<Center width="form">
|
|
219
|
+
<Stack gap="large">
|
|
220
|
+
<Stack gap="small">
|
|
221
|
+
<Heading level={1} size="h5">Expense report</Heading>
|
|
222
|
+
<Paragraph tone="secondary" size="body2" measure="none">Add the receipts for your trip on Nov 12, 2026.</Paragraph>
|
|
223
|
+
</Stack>
|
|
224
|
+
<Form aria-label="Receipts" gap="large" onSubmit={handleSave}>
|
|
225
|
+
<FormField id="file-upload-files" label="Receipts" error={error}>
|
|
226
|
+
{(f) => (
|
|
227
|
+
<DropZone
|
|
228
|
+
id={f.id}
|
|
229
|
+
label="Drop receipts here"
|
|
230
|
+
buttonLabel="Choose Files"
|
|
231
|
+
hint={`PDF, PNG or JPG, up to ${formatBytes(maxBytes)} each. Add up to ${maxFiles} files.`}
|
|
232
|
+
accept={['application/pdf', 'image/png', 'image/jpeg']}
|
|
233
|
+
maxBytes={maxBytes}
|
|
234
|
+
multiple
|
|
235
|
+
maxFiles={maxFiles}
|
|
236
|
+
disabled={saving}
|
|
237
|
+
aria-describedby={f['aria-describedby']}
|
|
238
|
+
aria-invalid={f['aria-invalid']}
|
|
239
|
+
status={error || undefined}
|
|
240
|
+
onFiles={handleFiles}
|
|
241
|
+
onReject={(rejections) => setError(say(rejections, limitLine.current))}
|
|
242
|
+
/>
|
|
243
|
+
)}
|
|
244
|
+
</FormField>
|
|
245
|
+
{files.length > 0 && (
|
|
246
|
+
<Stack gap="small" align="start">
|
|
247
|
+
{files.map((file) => (
|
|
248
|
+
<FileChip
|
|
249
|
+
key={file.id}
|
|
250
|
+
name={file.name}
|
|
251
|
+
kind={kindOf(file.name)}
|
|
252
|
+
meta={formatBytes(file.size)}
|
|
253
|
+
onRemove={() => handleRemove(file.id)}
|
|
254
|
+
/>
|
|
255
|
+
))}
|
|
256
|
+
</Stack>
|
|
257
|
+
)}
|
|
258
|
+
<Cluster>
|
|
259
|
+
<Button size="medium" type="primary" state={changed || saving ? 'enabled' : 'disabled'} label={justSaved ? 'Saved' : 'Save'} htmlType="submit" loading={saving} />
|
|
260
|
+
</Cluster>
|
|
261
|
+
</Form>
|
|
262
|
+
</Stack>
|
|
263
|
+
</Center>
|
|
264
|
+
);
|
|
265
|
+
}
|
|
266
|
+
```
|
|
267
|
+
|
|
268
|
+
## Native
|
|
269
|
+
|
|
270
|
+
On Apple use a `PhotosPicker` for a picture and `.fileImporter` for files, and take drops with `.dropDestination`. On Android use the photo picker and the system file picker.
|
|
@@ -20,7 +20,7 @@ A person narrows a list by one choice, such as a date range, or turns the filter
|
|
|
20
20
|
- Do not use a Tooltip as the only place that names the current filter.
|
|
21
21
|
- Do not mark the current choice with color only.
|
|
22
22
|
- Do not keep the menu open after a choice.
|
|
23
|
-
- Do not add a custom date range in a menu. ODS has no date picker
|
|
23
|
+
- Do not add a custom date range in a menu. ODS has no date range picker.
|
|
24
24
|
- Do not put a destructive item in a filter menu.
|
|
25
25
|
|
|
26
26
|
## Option: Presets
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default function ImageViewerWithVideo(): import("react").JSX.Element;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { useState } from 'react';
|
|
3
|
+
import PageShell from '../../components/pageShell';
|
|
4
|
+
import SectionIntro from '../../components/sectionIntro';
|
|
5
|
+
import Lightbox, { LightboxThumbnail } from '../../components/lightbox';
|
|
6
|
+
import { Grid, PageSection } from '../../components/layout';
|
|
7
|
+
// Two drawings stand in for the photos, and a short clip with its captions for the screen recording.
|
|
8
|
+
// A real page passes its own files.
|
|
9
|
+
var hillside = "data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 160 120'%3E%3Crect width='160' height='120' fill='%23dfe9f2'/%3E%3Ccircle cx='120' cy='32' r='14' fill='%23f2c46d'/%3E%3Cpath d='M0 90 50 60l40 22 30-18 40 24v32H0z' fill='%232f6b4f'/%3E%3C/svg%3E";
|
|
10
|
+
var desk = "data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 160 120'%3E%3Crect width='160' height='120' fill='%23efe6da'/%3E%3Crect x='30' y='30' width='100' height='60' rx='6' fill='%23333d47'/%3E%3Crect x='38' y='38' width='84' height='44' rx='2' fill='%2389b4d9'/%3E%3Crect x='20' y='92' width='120' height='6' rx='3' fill='%238a6d4b'/%3E%3C/svg%3E";
|
|
11
|
+
// The poster is the clip's first frame. It shows before the video plays, and as its thumbnail.
|
|
12
|
+
var clipPoster = "data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 320 240'%3E%3Crect width='320' height='240' fill='%23dfe9f2'/%3E%3Ccircle cx='240' cy='64' r='28' fill='%23f2c46d'/%3E%3Cpath d='M0 180 100 120l80 44 60-36 80 48v64H0z' fill='%232f6b4f'/%3E%3Ccircle cx='20' cy='200' r='14' fill='%23e08a5b'/%3E%3C/svg%3E";
|
|
13
|
+
var items = [
|
|
14
|
+
{ src: hillside, alt: 'A green hillside under a pale sky with the sun on the right', caption: 'The hill behind the new office.' },
|
|
15
|
+
{
|
|
16
|
+
kind: 'video',
|
|
17
|
+
src: '/media/hillside-ball.webm',
|
|
18
|
+
poster: clipPoster,
|
|
19
|
+
alt: 'A ball rolls along the foot of a green hillside',
|
|
20
|
+
caption: 'A short clip from the first walk.',
|
|
21
|
+
// Every video has a captions file. The viewer shows the captions by default.
|
|
22
|
+
captions: { src: '/media/hillside-ball.vtt', srclang: 'en', label: 'English' },
|
|
23
|
+
},
|
|
24
|
+
{ src: desk, alt: 'A laptop on a wooden desk, its screen blue', caption: 'A desk set up for the first day.' },
|
|
25
|
+
];
|
|
26
|
+
export default function ImageViewerWithVideo() {
|
|
27
|
+
var _a = useState(false), open = _a[0], setOpen = _a[1];
|
|
28
|
+
var _b = useState(0), index = _b[0], setIndex = _b[1];
|
|
29
|
+
return (<PageShell>
|
|
30
|
+
<PageSection gap="xlarge">
|
|
31
|
+
<SectionIntro id="image-viewer-with-video-intro" name="Pictures" statement="The office, and a walk on the hill."/>
|
|
32
|
+
{/* An image's thumbnail is named 'Open image: <alt>', the video's 'Play video: <alt>'. The video never starts by itself. */}
|
|
33
|
+
<Grid compact columns={3}>
|
|
34
|
+
{items.map(function (item, i) { return (<LightboxThumbnail key={item.alt} image={item} onOpen={function () {
|
|
35
|
+
setIndex(i);
|
|
36
|
+
setOpen(true);
|
|
37
|
+
}}/>); })}
|
|
38
|
+
</Grid>
|
|
39
|
+
</PageSection>
|
|
40
|
+
<Lightbox images={items} index={index} onIndexChange={setIndex} isOpen={open} onClose={function () { return setOpen(false); }} aria-label="Pictures"/>
|
|
41
|
+
</PageShell>);
|
|
42
|
+
}
|
|
@@ -8,11 +8,13 @@ A page shows images small, and a person wants to see one larger without leaving
|
|
|
8
8
|
- Render one `Lightbox` for the page with the list of images, the `index`, `onIndexChange`, `isOpen` and `onClose`. Give it an `aria-label` that names the set, such as "Pictures".
|
|
9
9
|
- Write alt text that says what the image shows, such as "A laptop on a wooden desk, its screen blue". It names the thumbnail and stands in for an image that fails to load.
|
|
10
10
|
- Add a `caption` when the image needs words. The viewer shows it under the image and uses it as its title.
|
|
11
|
-
- Pass two or more images to get the arrows: the viewer shows 'Previous image'
|
|
11
|
+
- Pass two or more images to get the arrows: the viewer shows 'Previous image' and 'Next image' ('Previous video' and 'Next video' when that item is a video) and '2 of 3' after the title. ArrowLeft, ArrowRight and a swipe step; the first and the last item stop there.
|
|
12
12
|
- Pass a single image in a list too, so the page keeps one way to open an image. The viewer then shows no arrows and no count.
|
|
13
13
|
- Let Escape, the backdrop and 'Close' close the viewer. Focus goes back to the thumbnail that opened it.
|
|
14
|
-
- Count on the viewer when an image fails to load: it shows 'This image could not be loaded.' with its alt text, and the arrows still work.
|
|
14
|
+
- Count on the viewer when an image or a video fails to load: it shows 'This image could not be loaded.' or 'This video could not be loaded.' with its alt text, and the arrows still work.
|
|
15
15
|
- Follow the case 'Attachments' for images that sit in a message.
|
|
16
|
+
- Give every video a captions file. The viewer shows the captions by default.
|
|
17
|
+
- Let the arrow keys seek a video while it has focus. The viewer steps with them from its buttons, and pauses a video when it steps away or closes.
|
|
16
18
|
|
|
17
19
|
## Don't
|
|
18
20
|
|
|
@@ -20,7 +22,8 @@ A page shows images small, and a person wants to see one larger without leaving
|
|
|
20
22
|
- Do not leave the alt text empty on a thumbnail, or write "image" or a file name.
|
|
21
23
|
- Do not build a full-screen layer with a portal of your own. `Lightbox` is a dialog with a focus trap and the focus return.
|
|
22
24
|
- Do not handle Escape or the arrow keys with a listener of your own. The viewer does.
|
|
23
|
-
- Do not use the viewer for
|
|
25
|
+
- Do not use the viewer for a page that has one image and nothing to see larger.
|
|
26
|
+
- Do not start a video by itself or loop it.
|
|
24
27
|
- Do not hide the arrows on a phone. A swipe is a second way to step, not the only one.
|
|
25
28
|
|
|
26
29
|
## Option: Several images opened from thumbnails
|
|
@@ -118,6 +121,71 @@ export default function ImageViewerSingle() {
|
|
|
118
121
|
}
|
|
119
122
|
```
|
|
120
123
|
|
|
124
|
+
## Option: Images and a video
|
|
125
|
+
|
|
126
|
+
Use when: A gallery that holds a short video, such as a clip from a walk or a screen recording.
|
|
127
|
+
|
|
128
|
+
Uses: `Grid`, `Lightbox`, `LightboxThumbnail`, `PageSection`, `PageShell`, `SectionIntro`
|
|
129
|
+
|
|
130
|
+
```tsx
|
|
131
|
+
'use client';
|
|
132
|
+
import { useState } from 'react';
|
|
133
|
+
import PageShell from 'oneslash-design-system/components/pageShell';
|
|
134
|
+
import SectionIntro from 'oneslash-design-system/components/sectionIntro';
|
|
135
|
+
import Lightbox, { LightboxThumbnail, type LightboxItem } from 'oneslash-design-system/components/lightbox';
|
|
136
|
+
import { Grid, PageSection } from 'oneslash-design-system/components/layout';
|
|
137
|
+
|
|
138
|
+
// Two drawings stand in for the photos, and a short clip with its captions for the screen recording.
|
|
139
|
+
// A real page passes its own files.
|
|
140
|
+
const hillside =
|
|
141
|
+
"data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 160 120'%3E%3Crect width='160' height='120' fill='%23dfe9f2'/%3E%3Ccircle cx='120' cy='32' r='14' fill='%23f2c46d'/%3E%3Cpath d='M0 90 50 60l40 22 30-18 40 24v32H0z' fill='%232f6b4f'/%3E%3C/svg%3E";
|
|
142
|
+
const desk =
|
|
143
|
+
"data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 160 120'%3E%3Crect width='160' height='120' fill='%23efe6da'/%3E%3Crect x='30' y='30' width='100' height='60' rx='6' fill='%23333d47'/%3E%3Crect x='38' y='38' width='84' height='44' rx='2' fill='%2389b4d9'/%3E%3Crect x='20' y='92' width='120' height='6' rx='3' fill='%238a6d4b'/%3E%3C/svg%3E";
|
|
144
|
+
// The poster is the clip's first frame. It shows before the video plays, and as its thumbnail.
|
|
145
|
+
const clipPoster =
|
|
146
|
+
"data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 320 240'%3E%3Crect width='320' height='240' fill='%23dfe9f2'/%3E%3Ccircle cx='240' cy='64' r='28' fill='%23f2c46d'/%3E%3Cpath d='M0 180 100 120l80 44 60-36 80 48v64H0z' fill='%232f6b4f'/%3E%3Ccircle cx='20' cy='200' r='14' fill='%23e08a5b'/%3E%3C/svg%3E";
|
|
147
|
+
|
|
148
|
+
const items: LightboxItem[] = [
|
|
149
|
+
{ src: hillside, alt: 'A green hillside under a pale sky with the sun on the right', caption: 'The hill behind the new office.' },
|
|
150
|
+
{
|
|
151
|
+
kind: 'video',
|
|
152
|
+
src: '/media/hillside-ball.webm',
|
|
153
|
+
poster: clipPoster,
|
|
154
|
+
alt: 'A ball rolls along the foot of a green hillside',
|
|
155
|
+
caption: 'A short clip from the first walk.',
|
|
156
|
+
// Every video has a captions file. The viewer shows the captions by default.
|
|
157
|
+
captions: { src: '/media/hillside-ball.vtt', srclang: 'en', label: 'English' },
|
|
158
|
+
},
|
|
159
|
+
{ src: desk, alt: 'A laptop on a wooden desk, its screen blue', caption: 'A desk set up for the first day.' },
|
|
160
|
+
];
|
|
161
|
+
|
|
162
|
+
export default function ImageViewerWithVideo() {
|
|
163
|
+
const [open, setOpen] = useState(false);
|
|
164
|
+
const [index, setIndex] = useState(0);
|
|
165
|
+
return (
|
|
166
|
+
<PageShell>
|
|
167
|
+
<PageSection gap="xlarge">
|
|
168
|
+
<SectionIntro id="image-viewer-with-video-intro" name="Pictures" statement="The office, and a walk on the hill." />
|
|
169
|
+
{/* An image's thumbnail is named 'Open image: <alt>', the video's 'Play video: <alt>'. The video never starts by itself. */}
|
|
170
|
+
<Grid compact columns={3}>
|
|
171
|
+
{items.map((item, i) => (
|
|
172
|
+
<LightboxThumbnail
|
|
173
|
+
key={item.alt}
|
|
174
|
+
image={item}
|
|
175
|
+
onOpen={() => {
|
|
176
|
+
setIndex(i);
|
|
177
|
+
setOpen(true);
|
|
178
|
+
}}
|
|
179
|
+
/>
|
|
180
|
+
))}
|
|
181
|
+
</Grid>
|
|
182
|
+
</PageSection>
|
|
183
|
+
<Lightbox images={items} index={index} onIndexChange={setIndex} isOpen={open} onClose={() => setOpen(false)} aria-label="Pictures" />
|
|
184
|
+
</PageShell>
|
|
185
|
+
);
|
|
186
|
+
}
|
|
187
|
+
```
|
|
188
|
+
|
|
121
189
|
## Native
|
|
122
190
|
|
|
123
|
-
On Apple use a `fullScreenCover` with a `TabView` in `page` style, and `accessibilityLabel` on each image. On Android use a full-screen dialog with a `HorizontalPager` and a content description on each image.
|
|
191
|
+
On Apple use a `fullScreenCover` with a `TabView` in `page` style, and `accessibilityLabel` on each image. On Android use a full-screen dialog with a `HorizontalPager` and a content description on each image. A video page uses the system player (`VideoPlayer`, or Media3 on Android) with its captions on, and does not start by itself.
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
import { useState } from 'react';
|
|
3
|
-
import
|
|
4
|
-
import MenuItem from '../../components/menuItem';
|
|
3
|
+
import ItemList from '../../components/itemList';
|
|
5
4
|
import { SettingsLayout } from '../../components/settingsSection';
|
|
6
5
|
import Heading from '../../components/heading';
|
|
7
6
|
import Paragraph from '../../components/paragraph';
|
|
@@ -20,15 +19,23 @@ export default function MasterDetailSplit() {
|
|
|
20
19
|
var _b = useState(messages[0].id), openId = _b[0], setOpenId = _b[1];
|
|
21
20
|
// On a phone the list is the screen until a message is chosen, and Back returns to it.
|
|
22
21
|
var _c = useState(false), showDetail = _c[0], setShowDetail = _c[1];
|
|
22
|
+
// A real app passes the router from its framework, such as Next's useRouter(), and reads the open message from its
|
|
23
|
+
// address, so it can be shared and reloaded. Here both set the open message.
|
|
24
|
+
var router = {
|
|
25
|
+
push: function (url) { var _a; return setOpenId((_a = url.split('/').pop()) !== null && _a !== void 0 ? _a : messages[0].id); },
|
|
26
|
+
replace: function (url) { var _a; return setOpenId((_a = url.split('/').pop()) !== null && _a !== void 0 ? _a : messages[0].id); },
|
|
27
|
+
};
|
|
23
28
|
var message = (_a = messages.find(function (m) { return m.id === openId; })) !== null && _a !== void 0 ? _a : messages[0];
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
29
|
+
// From md, Up and Down open the next message and focus follows. On a phone they move focus, and Enter opens.
|
|
30
|
+
var list = (<ItemList id="master-detail-split" aria-label="Messages" items={messages.map(function (m) { return ({ id: m.id, label: m.from, secondLabel: m.subject }); })} selectedId={message.id} onSelect={function (id, how) {
|
|
31
|
+
// A move with the arrows replaces the address, so Back leaves the list instead of stepping through every message.
|
|
32
|
+
// With `href` rows, the link itself pushes on a click, so call only `replace`, on a keyboard move.
|
|
33
|
+
if (how === 'keyboard')
|
|
34
|
+
router.replace("/inbox/".concat(id));
|
|
35
|
+
else
|
|
36
|
+
router.push("/inbox/".concat(id));
|
|
37
|
+
setShowDetail(true);
|
|
38
|
+
}}/>);
|
|
32
39
|
return (<PageShell>
|
|
33
40
|
<Stack gap="xlarge">
|
|
34
41
|
<Heading level={1} size="h5">Inbox</Heading>
|
|
@@ -5,8 +5,9 @@ A person opens an item from a list, such as a message or a report, and reads or
|
|
|
5
5
|
## Do
|
|
6
6
|
|
|
7
7
|
- Follow the rule 'On a phone, a sidebar opens as a drawer and a list opens its detail'.
|
|
8
|
-
- Use `SettingsLayout` with `navWidth="wide"` for
|
|
9
|
-
-
|
|
8
|
+
- Use `SettingsLayout` with `navWidth="wide"` and an `ItemList` for the list. From `md`, Up and Down open the next item; on a phone they move focus and Enter opens.
|
|
9
|
+
- Give the open item an address that can be shared and reloaded, and pass its id to `ItemList` as `selectedId`. That marks its row as the current one.
|
|
10
|
+
- Replace the address on a move with the arrows, so Back leaves the list instead of stepping through every item.
|
|
10
11
|
- Keep one item open at all times from `md` up, the first at the start.
|
|
11
12
|
- Name the row with the sender or the title, and put the subject or the summary in `secondLabel`.
|
|
12
13
|
- Show the list first on a phone, then the detail alone with a Back Button named for the list: 'Back to Inbox'. Pass it as `back` of `SettingsLayout`.
|
|
@@ -27,13 +28,12 @@ A person opens an item from a list, such as a message or a report, and reads or
|
|
|
27
28
|
|
|
28
29
|
Use when: The person works down the list, one item after another, such as an inbox.
|
|
29
30
|
|
|
30
|
-
Uses: `Button`, `Cluster`, `Heading`, `
|
|
31
|
+
Uses: `Button`, `Cluster`, `Heading`, `ItemList`, `PageShell`, `Paragraph`, `SettingsLayout`, `Stack`
|
|
31
32
|
|
|
32
33
|
```tsx
|
|
33
34
|
'use client';
|
|
34
35
|
import { useState } from 'react';
|
|
35
|
-
import
|
|
36
|
-
import MenuItem from 'oneslash-design-system/components/menuItem';
|
|
36
|
+
import ItemList from 'oneslash-design-system/components/itemList';
|
|
37
37
|
import { SettingsLayout } from 'oneslash-design-system/components/settingsSection';
|
|
38
38
|
import Heading from 'oneslash-design-system/components/heading';
|
|
39
39
|
import Paragraph from 'oneslash-design-system/components/paragraph';
|
|
@@ -56,28 +56,30 @@ export default function MasterDetailSplit() {
|
|
|
56
56
|
// On a phone the list is the screen until a message is chosen, and Back returns to it.
|
|
57
57
|
const [showDetail, setShowDetail] = useState(false);
|
|
58
58
|
|
|
59
|
+
// A real app passes the router from its framework, such as Next's useRouter(), and reads the open message from its
|
|
60
|
+
// address, so it can be shared and reloaded. Here both set the open message.
|
|
61
|
+
const router = {
|
|
62
|
+
push: (url: string) => setOpenId(url.split('/').pop() ?? messages[0].id),
|
|
63
|
+
replace: (url: string) => setOpenId(url.split('/').pop() ?? messages[0].id),
|
|
64
|
+
};
|
|
65
|
+
|
|
59
66
|
const message = messages.find((m) => m.id === openId) ?? messages[0];
|
|
60
67
|
|
|
68
|
+
// From md, Up and Down open the next message and focus follows. On a phone they move focus, and Enter opens.
|
|
61
69
|
const list = (
|
|
62
|
-
<
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
setOpenId(m.id);
|
|
76
|
-
setShowDetail(true);
|
|
77
|
-
}}
|
|
78
|
-
/>
|
|
79
|
-
))}
|
|
80
|
-
</Navigation>
|
|
70
|
+
<ItemList
|
|
71
|
+
id="master-detail-split"
|
|
72
|
+
aria-label="Messages"
|
|
73
|
+
items={messages.map((m) => ({ id: m.id, label: m.from, secondLabel: m.subject }))}
|
|
74
|
+
selectedId={message.id}
|
|
75
|
+
onSelect={(id, how) => {
|
|
76
|
+
// A move with the arrows replaces the address, so Back leaves the list instead of stepping through every message.
|
|
77
|
+
// With `href` rows, the link itself pushes on a click, so call only `replace`, on a keyboard move.
|
|
78
|
+
if (how === 'keyboard') router.replace(`/inbox/${id}`);
|
|
79
|
+
else router.push(`/inbox/${id}`);
|
|
80
|
+
setShowDetail(true);
|
|
81
|
+
}}
|
|
82
|
+
/>
|
|
81
83
|
);
|
|
82
84
|
|
|
83
85
|
return (
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default function MessageReactionsPicker(): import("react").JSX.Element;
|