oneslash-design-system 2.22.0 → 2.23.1

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 (91) hide show
  1. package/README.md +1 -1
  2. package/dist/DESIGN.md +12 -1
  3. package/dist/cases/admin-inbox/split.jsx +22 -10
  4. package/dist/cases/admin-inbox.md +28 -23
  5. package/dist/cases/api-keys.md +1 -1
  6. package/dist/cases/breadcrumb/back-link.d.ts +1 -0
  7. package/dist/cases/breadcrumb/back-link.jsx +23 -0
  8. package/dist/cases/breadcrumb/trail.d.ts +1 -0
  9. package/dist/cases/breadcrumb/trail.jsx +28 -0
  10. package/dist/cases/breadcrumb.md +105 -0
  11. package/dist/cases/date-field/calendar.d.ts +1 -0
  12. package/dist/cases/date-field/calendar.jsx +80 -0
  13. package/dist/cases/date-field/typed.d.ts +1 -0
  14. package/dist/cases/date-field/typed.jsx +58 -0
  15. package/dist/cases/date-field.md +232 -0
  16. package/dist/cases/docs-component-page/reference.jsx +11 -1
  17. package/dist/cases/docs-component-page.md +19 -8
  18. package/dist/cases/file-upload/files.d.ts +1 -0
  19. package/dist/cases/file-upload/files.jsx +118 -0
  20. package/dist/cases/file-upload/picture.d.ts +1 -0
  21. package/dist/cases/file-upload/picture.jsx +50 -0
  22. package/dist/cases/file-upload.md +270 -0
  23. package/dist/cases/filter-menu.md +1 -1
  24. package/dist/cases/image-viewer/with-video.d.ts +1 -0
  25. package/dist/cases/image-viewer/with-video.jsx +42 -0
  26. package/dist/cases/image-viewer.md +72 -4
  27. package/dist/cases/master-detail/split.jsx +17 -10
  28. package/dist/cases/master-detail.md +26 -24
  29. package/dist/cases/message-reactions/picker.d.ts +1 -0
  30. package/dist/cases/message-reactions/picker.jsx +145 -0
  31. package/dist/cases/message-reactions/quick-pick.jsx +1 -1
  32. package/dist/cases/message-reactions.md +184 -3
  33. package/dist/cases/page-header.md +1 -1
  34. package/dist/cases/people-row/names.d.ts +1 -0
  35. package/dist/cases/people-row/names.jsx +20 -0
  36. package/dist/cases/people-row/stack.d.ts +1 -0
  37. package/dist/cases/people-row/stack.jsx +33 -0
  38. package/dist/cases/people-row.md +110 -0
  39. package/dist/cases/profile-form/form.jsx +21 -10
  40. package/dist/cases/profile-form.md +38 -9
  41. package/dist/cases.json +306 -25
  42. package/dist/components/avatarStack.d.ts +22 -0
  43. package/dist/components/avatarStack.jsx +32 -0
  44. package/dist/components/breadcrumb.d.ts +12 -0
  45. package/dist/components/breadcrumb.jsx +24 -0
  46. package/dist/components/calendar.d.ts +19 -0
  47. package/dist/components/calendar.jsx +126 -0
  48. package/dist/components/dateField.d.ts +35 -0
  49. package/dist/components/dateField.jsx +76 -0
  50. package/dist/components/dropZone.d.ts +53 -0
  51. package/dist/components/dropZone.jsx +136 -0
  52. package/dist/components/emojiPicker.d.ts +22 -0
  53. package/dist/components/emojiPicker.jsx +161 -0
  54. package/dist/components/itemList.d.ts +31 -0
  55. package/dist/components/itemList.jsx +81 -0
  56. package/dist/components/lightbox.d.ts +33 -9
  57. package/dist/components/lightbox.jsx +58 -27
  58. package/dist/components/menuItem.d.ts +1 -1
  59. package/dist/components/menuItem.jsx +3 -3
  60. package/dist/components/popover.jsx +7 -2
  61. package/dist/internal/date.d.ts +35 -0
  62. package/dist/internal/date.js +122 -0
  63. package/dist/internal/dropZone.d.ts +28 -0
  64. package/dist/internal/dropZone.js +42 -0
  65. package/dist/internal/emoji.d.ts +13 -0
  66. package/dist/internal/emoji.js +182 -0
  67. package/dist/internal/overlayStack.js +1 -1
  68. package/dist/internal/people.d.ts +1 -0
  69. package/dist/internal/people.js +12 -0
  70. package/dist/native-mapping.json +45 -3
  71. package/dist/stories/AvatarStack.stories.d.ts +7 -0
  72. package/dist/stories/AvatarStack.stories.jsx +46 -0
  73. package/dist/stories/Breadcrumb.stories.d.ts +7 -0
  74. package/dist/stories/Breadcrumb.stories.jsx +26 -0
  75. package/dist/stories/Calendar.stories.d.ts +6 -0
  76. package/dist/stories/Calendar.stories.jsx +15 -0
  77. package/dist/stories/Cases.generated.stories.d.ts +10 -0
  78. package/dist/stories/Cases.generated.stories.jsx +20 -0
  79. package/dist/stories/DateField.stories.d.ts +10 -0
  80. package/dist/stories/DateField.stories.jsx +132 -0
  81. package/dist/stories/DropZone.stories.d.ts +12 -0
  82. package/dist/stories/DropZone.stories.jsx +151 -0
  83. package/dist/stories/EmojiPicker.stories.d.ts +6 -0
  84. package/dist/stories/EmojiPicker.stories.jsx +92 -0
  85. package/dist/stories/ItemList.stories.d.ts +9 -0
  86. package/dist/stories/ItemList.stories.jsx +86 -0
  87. package/dist/stories/Lightbox.stories.d.ts +4 -0
  88. package/dist/stories/Lightbox.stories.jsx +44 -0
  89. package/dist/stories/Popover.stories.d.ts +1 -0
  90. package/dist/stories/Popover.stories.jsx +17 -0
  91. package/package.json +3 -2
@@ -0,0 +1,232 @@
1
+ # Date field
2
+
3
+ A person gives one day, such as when a token expires or their date of birth.
4
+
5
+ ## Do
6
+
7
+ - Use `DateField`. The person types the date as MM/DD/YYYY, such as '11/16/2026', or picks it from the calendar.
8
+ - Store the value as an ISO day, such as '2026-11-16'. Write it in text as 'Nov 16, 2026'.
9
+ - Pass `min` or `max` as an ISO day when only some days can be chosen. Days outside them cannot be picked in the calendar.
10
+ - Let the field say why a date cannot be used: 'Choose Nov 16, 2026 or later.' for a day before `min`, and 'Choose Dec 31, 2026 or earlier.' for a day after `max`.
11
+ - Let the field say how to fix a date that is not real, such as '02/30/2026': 'Enter a real date as MM/DD/YYYY.' A two-digit year says 'Enter the year in four digits, like 2026.'
12
+ - Name the format in the helper text, and say what an empty field means: 'MM/DD/YYYY. Leave empty for no end date.'
13
+ - Pass `calendar={false}` for a date years away, such as a date of birth. Paging a calendar back 30 years takes too long.
14
+ - Read the second argument of `onChange`: `''` with `error: null` is an empty field, and `''` with an error is a date typed wrong. Do not submit while `error` is set. The field already shows why under itself.
15
+ - Treat an empty optional date as no date, such as no end date for a token.
16
+ - Show a problem from the form, such as a required date left empty, through `errorText`, as the rule 'A form error shows next to the problem' says: 'Enter your date of birth as MM/DD/YYYY.'
17
+ - Save a date in a group of fields with one Save Button, as the rule 'A setting saves in place, or with one Save Button' says.
18
+ - Put an expiry date in the create Modal of the case 'API keys', under 'Name'. The example shows the fields on a page to keep it short.
19
+
20
+ ## Don't
21
+
22
+ - Do not ask for a date in three `Select`s for the month, the day and the year.
23
+ - Do not make the calendar the only way in. A person who knows the date types it.
24
+ - Do not use the browser's own date input. It looks different in each browser and cannot follow the theme.
25
+ - Do not show the stored ISO day to the person. Show '11/16/2026' in the field and 'Nov 16, 2026' in text.
26
+ - Do not build a date range from two `DateField`s in a filter. Use the presets of the case 'Filter menu'.
27
+
28
+ ## Option: Typed or picked from a calendar
29
+
30
+ Use when: The date is near today and the person picks it, such as when a token expires.
31
+
32
+ Uses: `Button`, `Center`, `Cluster`, `CopyField`, `DateField`, `Form`, `FormField`, `Heading`, `Paragraph`, `Stack`, `TextField`
33
+
34
+ ```tsx
35
+ 'use client';
36
+ import { useEffect, useRef, useState } from 'react';
37
+ import Heading from 'oneslash-design-system/components/heading';
38
+ import Paragraph from 'oneslash-design-system/components/paragraph';
39
+ import Form from 'oneslash-design-system/components/form';
40
+ import FormField from 'oneslash-design-system/components/formField';
41
+ import TextField from 'oneslash-design-system/components/textField';
42
+ import DateField from 'oneslash-design-system/components/dateField';
43
+ import CopyField from 'oneslash-design-system/components/copyField';
44
+ import Button from 'oneslash-design-system/components/button';
45
+ import { Center, Cluster, Stack } from 'oneslash-design-system/components/layout';
46
+
47
+ // In an app, these fields sit in the 'Create Key' Modal of the case 'API keys'.
48
+ // "Today" in this example. A real app passes its own today as `min`, as 'YYYY-MM-DD'.
49
+ const today = '2026-11-16';
50
+ // The token the server made. A real app gets it once, in the reply to the create request.
51
+ const madeToken = 'acme_tok_9Rk2vQ7mXa4LwT8cZp1Hd6Ns';
52
+
53
+ const months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
54
+ // '2026-12-16' as 'Dec 16, 2026', for the line under the new token
55
+ function formatDay(day: string) {
56
+ const [year, month, date] = day.split('-').map(Number);
57
+ return `${months[month - 1]} ${date}, ${year}`;
58
+ }
59
+
60
+ export default function DateFieldCalendar() {
61
+ const [name, setName] = useState('');
62
+ const [nameError, setNameError] = useState('');
63
+ // The day as 'YYYY-MM-DD', or '' for no end date
64
+ const [expires, setExpires] = useState('');
65
+ // The field's own message for a date typed wrong. While it is set, the token is not created.
66
+ const [expiresError, setExpiresError] = useState<string | null>(null);
67
+ const [creating, setCreating] = useState(false);
68
+ const [made, setMade] = useState<{ name: string; expires: string } | null>(null);
69
+ const timer = useRef<ReturnType<typeof setTimeout>>();
70
+
71
+ // Stops the request if the example goes away before it ends.
72
+ useEffect(() => () => clearTimeout(timer.current), []);
73
+
74
+ function handleCreate() {
75
+ if (creating) return;
76
+ setNameError(name.trim() ? '' : 'Enter a name for the token.');
77
+ // A date typed wrong shows its message under the field. An empty date means no end date.
78
+ if (!name.trim() || expiresError) return;
79
+ setCreating(true);
80
+ // Stands in for the request to the server.
81
+ timer.current = setTimeout(() => {
82
+ setCreating(false);
83
+ setMade({ name: name.trim(), expires });
84
+ }, 1200);
85
+ }
86
+
87
+ function handleDone() {
88
+ setMade(null);
89
+ setName('');
90
+ setExpires('');
91
+ setExpiresError(null);
92
+ }
93
+
94
+ return (
95
+ <Center width="form">
96
+ <Stack gap="large">
97
+ <Stack gap="small">
98
+ <Heading level={1} size="h5">New access token</Heading>
99
+ <Paragraph tone="secondary" size="body2" measure="none">A token lets a script use Acme as you until the day it expires.</Paragraph>
100
+ </Stack>
101
+ {made ? (
102
+ <Stack gap="large">
103
+ <CopyField id="date-field-token" label={made.name} value={madeToken} mono reveal="once" />
104
+ <Paragraph size="body2" measure="none">{made.expires ? `Expires ${formatDay(made.expires)}.` : 'Never expires.'}</Paragraph>
105
+ <Cluster>
106
+ <Button size="medium" type="primary" state="enabled" label="Done" onClickButton={handleDone} />
107
+ </Cluster>
108
+ </Stack>
109
+ ) : (
110
+ <Form aria-label="New access token" gap="large" onSubmit={handleCreate}>
111
+ <FormField id="date-field-name" label="Name" help="Say what will use it, such as Deploy script." error={nameError}>
112
+ {(f) => (
113
+ <TextField
114
+ id={f.id}
115
+ aria-describedby={f['aria-describedby']}
116
+ aria-invalid={f['aria-invalid']}
117
+ value={name}
118
+ disabled={creating}
119
+ autoComplete="off"
120
+ onChange={(e) => { setName(e.target.value); setNameError(''); }}
121
+ />
122
+ )}
123
+ </FormField>
124
+ {/* Typed as MM/DD/YYYY or picked from the calendar. A day before today says 'Choose Nov 16, 2026 or later.'
125
+ The second argument of onChange tells an empty field (no error) from a date typed wrong. */}
126
+ <DateField
127
+ id="date-field-expires"
128
+ label="Expires on"
129
+ value={expires}
130
+ onChange={(day, detail) => { setExpires(day); setExpiresError(detail.error); }}
131
+ min={today}
132
+ disabled={creating}
133
+ helperText="MM/DD/YYYY. Leave empty for no end date."
134
+ />
135
+ <Cluster>
136
+ <Button size="medium" type="primary" state="enabled" label="Create Token" htmlType="submit" loading={creating} />
137
+ </Cluster>
138
+ </Form>
139
+ )}
140
+ </Stack>
141
+ </Center>
142
+ );
143
+ }
144
+ ```
145
+
146
+ ## Option: Typed only
147
+
148
+ Use when: The date is far from today and the person knows it, such as a date of birth.
149
+
150
+ Uses: `Button`, `Center`, `Cluster`, `DateField`, `Form`, `Heading`, `Stack`
151
+
152
+ ```tsx
153
+ 'use client';
154
+ import { useEffect, useRef, useState } from 'react';
155
+ import Heading from 'oneslash-design-system/components/heading';
156
+ import Form from 'oneslash-design-system/components/form';
157
+ import DateField from 'oneslash-design-system/components/dateField';
158
+ import Button from 'oneslash-design-system/components/button';
159
+ import { Center, Cluster, Stack } from 'oneslash-design-system/components/layout';
160
+
161
+ // "Today" in this example. A real app passes its own today as `max`, as 'YYYY-MM-DD'.
162
+ const today = '2026-11-16';
163
+
164
+ export default function DateFieldTyped() {
165
+ // The day as 'YYYY-MM-DD'
166
+ const [saved, setSaved] = useState('1990-04-12');
167
+ const [birth, setBirth] = useState('1990-04-12');
168
+ // The field's own message for a date typed wrong or after today. While it is set, nothing is saved.
169
+ const [birthError, setBirthError] = useState<string | null>(null);
170
+ // The form's message for an empty field
171
+ const [error, setError] = useState('');
172
+ const [saving, setSaving] = useState(false);
173
+ const [justSaved, setJustSaved] = useState(false);
174
+ const timers = useRef<ReturnType<typeof setTimeout>[]>([]);
175
+ const savedTimer = useRef<ReturnType<typeof setTimeout>>();
176
+
177
+ // Stops the request and the 'Saved' if the example goes away before they end.
178
+ useEffect(() => () => {
179
+ timers.current.forEach(clearTimeout);
180
+ clearTimeout(savedTimer.current);
181
+ }, []);
182
+
183
+ function handleSave() {
184
+ if (saving || birthError) return;
185
+ if (!birth) {
186
+ setError('Enter your date of birth as MM/DD/YYYY.');
187
+ return;
188
+ }
189
+ setError('');
190
+ setSaving(true);
191
+ // Stands in for the request to the server.
192
+ timers.current.push(setTimeout(() => {
193
+ setSaving(false);
194
+ setSaved(birth);
195
+ setJustSaved(true);
196
+ clearTimeout(savedTimer.current);
197
+ savedTimer.current = setTimeout(() => setJustSaved(false), 2000);
198
+ }, 1200));
199
+ }
200
+
201
+ const changed = birth !== saved;
202
+
203
+ return (
204
+ <Center width="form">
205
+ <Stack gap="large">
206
+ <Heading level={1} size="h5">Personal details</Heading>
207
+ <Form aria-label="Personal details" gap="large" onSubmit={handleSave}>
208
+ {/* Typed only: a date of birth is years away, where paging a calendar would take too long */}
209
+ <DateField
210
+ id="date-field-birth"
211
+ label="Date of birth"
212
+ value={birth}
213
+ onChange={(day, detail) => { setBirth(day); setBirthError(detail.error); setJustSaved(false); setError(''); }}
214
+ max={today}
215
+ required
216
+ calendar={false}
217
+ disabled={saving}
218
+ errorText={error || undefined}
219
+ />
220
+ <Cluster>
221
+ <Button size="medium" type="primary" state={changed || saving ? 'enabled' : 'disabled'} label={justSaved ? 'Saved' : 'Save'} htmlType="submit" loading={saving} />
222
+ </Cluster>
223
+ </Form>
224
+ </Stack>
225
+ </Center>
226
+ );
227
+ }
228
+ ```
229
+
230
+ ## Native
231
+
232
+ On Apple use a `DatePicker` with `.compact` style and a `ClosedRange` for the days that can be chosen; use `.wheel` for a date of birth. On Android use the Material date picker with text input on.
@@ -2,6 +2,7 @@
2
2
  import { useState } from 'react';
3
3
  import PageShell from '../../components/pageShell';
4
4
  import PageHeader from '../../components/pageHeader';
5
+ import Breadcrumb from '../../components/breadcrumb';
5
6
  import SectionIntro from '../../components/sectionIntro';
6
7
  import OnThisPage from '../../components/onThisPage';
7
8
  import Surface from '../../components/surface';
@@ -25,6 +26,12 @@ var sections = [
25
26
  { id: 'docs-component-page-use', label: 'When to use it' },
26
27
  ];
27
28
  var code = "<Tag\n variant=\"contained\"\n size=\"medium\"\n color=\"success\"\n label=\"Paid\"\n/>";
29
+ // The page's place, from the top level down. The last level is this page, so it is not a link.
30
+ var trail = [
31
+ { label: 'Docs', href: '/docs' },
32
+ { label: 'Components', href: '/docs/components' },
33
+ { label: 'Tag' },
34
+ ];
28
35
  // Prop, Type, Default, Description
29
36
  var props = [
30
37
  { name: 'variant', type: "'contained' | 'textOnly' | 'dot'", initial: 'None, required', text: 'How it is drawn: a filled pill, text only, or a dot before the text.' },
@@ -36,7 +43,10 @@ export default function DocsComponentPageReference() {
36
43
  var _a = useState('example'), view = _a[0], setView = _a[1];
37
44
  return (<PageShell aside={<OnThisPage items={sections}/>}>
38
45
  <Stack gap="giant">
39
- <PageHeader level={1} eyebrow="Components" title="Tag" lede="A short label that says what state something is in, such as Paid or Draft."/>
46
+ <Stack gap="large">
47
+ <Breadcrumb items={trail}/>
48
+ <PageHeader level={1} title="Tag" lede="A short label that says what state something is in, such as Paid or Draft."/>
49
+ </Stack>
40
50
  <PageSection gap="xlarge">
41
51
  <SectionIntro id="docs-component-page-example" name="Example"/>
42
52
  <Stack gap="large">
@@ -4,7 +4,8 @@ A person opens the page of one part of a design system or a code library to see
4
4
 
5
5
  ## Do
6
6
 
7
- - Use `PageHeader` with `level={1}`: the part's name is the one level 1 heading, with an `eyebrow` for its group and a `lede` of one sentence that says what it is for.
7
+ - Use `PageHeader` with `level={1}`: the part's name is the one level 1 heading, with a `lede` of one sentence that says what it is for.
8
+ - Put a `Breadcrumb` above the title, as the case 'Breadcrumb' says. It names the part's group, so leave out the `eyebrow`.
8
9
  - Show the part live first, in a `Surface` with `align="center"`, so a person sees it before reading about it.
9
10
  - Put the code of that same example in a `CodeBlock` with a `label` such as 'Tag example', so the Copy Button and the scroll region have a name.
10
11
  - Switch between the example and its code with `TabsContainer`, `Tab` and `TabPanel`: give each `Tab` an `id` and `controls`, and keep both panels in the page.
@@ -23,13 +24,14 @@ A person opens the page of one part of a design system or a code library to see
23
24
 
24
25
  ## Example: A page that documents one part
25
26
 
26
- Uses: `CodeBlock`, `Grid`, `Heading`, `List`, `OnThisPage`, `PageHeader`, `PageSection`, `PageShell`, `SectionIntro`, `Stack`, `Surface`, `Tab`, `TabPanel`, `TableCell`, `TableContainer`, `TableHeader`, `TableHeaderCell`, `TableRow`, `TabsContainer`, `Tag`
27
+ Uses: `Breadcrumb`, `CodeBlock`, `Grid`, `Heading`, `List`, `OnThisPage`, `PageHeader`, `PageSection`, `PageShell`, `SectionIntro`, `Stack`, `Surface`, `Tab`, `TabPanel`, `TableCell`, `TableContainer`, `TableHeader`, `TableHeaderCell`, `TableRow`, `TabsContainer`, `Tag`
27
28
 
28
29
  ```tsx
29
30
  'use client';
30
31
  import { useState } from 'react';
31
32
  import PageShell from 'oneslash-design-system/components/pageShell';
32
33
  import PageHeader from 'oneslash-design-system/components/pageHeader';
34
+ import Breadcrumb from 'oneslash-design-system/components/breadcrumb';
33
35
  import SectionIntro from 'oneslash-design-system/components/sectionIntro';
34
36
  import OnThisPage from 'oneslash-design-system/components/onThisPage';
35
37
  import Surface from 'oneslash-design-system/components/surface';
@@ -61,6 +63,13 @@ const code = `<Tag
61
63
  label="Paid"
62
64
  />`;
63
65
 
66
+ // The page's place, from the top level down. The last level is this page, so it is not a link.
67
+ const trail = [
68
+ { label: 'Docs', href: '/docs' },
69
+ { label: 'Components', href: '/docs/components' },
70
+ { label: 'Tag' },
71
+ ];
72
+
64
73
  // Prop, Type, Default, Description
65
74
  const props = [
66
75
  { name: 'variant', type: "'contained' | 'textOnly' | 'dot'", initial: 'None, required', text: 'How it is drawn: a filled pill, text only, or a dot before the text.' },
@@ -74,12 +83,14 @@ export default function DocsComponentPageReference() {
74
83
  return (
75
84
  <PageShell aside={<OnThisPage items={sections} />}>
76
85
  <Stack gap="giant">
77
- <PageHeader
78
- level={1}
79
- eyebrow="Components"
80
- title="Tag"
81
- lede="A short label that says what state something is in, such as Paid or Draft."
82
- />
86
+ <Stack gap="large">
87
+ <Breadcrumb items={trail} />
88
+ <PageHeader
89
+ level={1}
90
+ title="Tag"
91
+ lede="A short label that says what state something is in, such as Paid or Draft."
92
+ />
93
+ </Stack>
83
94
  <PageSection gap="xlarge">
84
95
  <SectionIntro id="docs-component-page-example" name="Example" />
85
96
  <Stack gap="large">
@@ -0,0 +1 @@
1
+ export default function FileUploadFiles(): import("react").JSX.Element;
@@ -0,0 +1,118 @@
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 Heading from '../../components/heading';
13
+ import Paragraph from '../../components/paragraph';
14
+ import Form from '../../components/form';
15
+ import FormField from '../../components/formField';
16
+ import DropZone from '../../components/dropZone';
17
+ import FileChip from '../../components/fileChip';
18
+ import Button from '../../components/button';
19
+ import { formatBytes } from '../../components/formatNumber';
20
+ import { Center, Cluster, Stack } from '../../components/layout';
21
+ var maxFiles = 5;
22
+ // 10 MB as formatBytes counts it (base 1024), so the words and the check agree
23
+ var maxBytes = 10 * 1024 * 1024;
24
+ // Two receipts saved earlier. A real app loads them with the request.
25
+ var savedFiles = [
26
+ { id: 'f1', name: 'Hotel receipt.pdf', size: 248000 },
27
+ { id: 'f2', name: 'Taxi receipt.png', size: 1820000 },
28
+ ];
29
+ var kindOf = function (name) { var _a; return ((_a = name.split('.').pop()) !== null && _a !== void 0 ? _a : '').toUpperCase(); };
30
+ // The zone reports reasons. The words are this page's, one line per file, shown under the zone,
31
+ // with the limit line when the same choice also had more files than the list has room for.
32
+ function say(rejections, limit) {
33
+ return rejections
34
+ .map(function (r) {
35
+ return r.reason === 'type'
36
+ ? "".concat(r.name, " is not a PDF, PNG or JPG file.")
37
+ : r.reason === 'size'
38
+ ? "".concat(r.name, " is over ").concat(formatBytes(maxBytes), ".")
39
+ : "Add up to ".concat(maxFiles, " files.");
40
+ })
41
+ .concat(limit ? [limit] : [])
42
+ .filter(function (line, i, all) { return all.indexOf(line) === i; })
43
+ .join(' ');
44
+ }
45
+ export default function FileUploadFiles() {
46
+ var _a = useState(savedFiles), files = _a[0], setFiles = _a[1];
47
+ var _b = useState(savedFiles), saved = _b[0], setSaved = _b[1];
48
+ var _c = useState(''), error = _c[0], setError = _c[1];
49
+ var _d = useState(false), saving = _d[0], setSaving = _d[1];
50
+ var _e = useState(false), justSaved = _e[0], setJustSaved = _e[1];
51
+ var timers = useRef([]);
52
+ var savedTimer = useRef();
53
+ // Gives each chosen file its own id, so two files with one name are two rows.
54
+ var count = useRef(0);
55
+ // The limit line from the choice being handled. The zone calls onFiles, then onReject, for one choice,
56
+ // so onReject can keep it beside the reasons. It is cleared once that choice is done.
57
+ var limitLine = useRef('');
58
+ // Stops the request and the 'Saved' if the example goes away before they end.
59
+ useEffect(function () { return function () {
60
+ timers.current.forEach(clearTimeout);
61
+ clearTimeout(savedTimer.current);
62
+ }; }, []);
63
+ // The list holds five at most. The zone checks one choice; the page checks the list.
64
+ function handleFiles(chosen) {
65
+ var room = maxFiles - files.length;
66
+ var added = chosen.slice(0, Math.max(0, room)).map(function (file) {
67
+ count.current += 1;
68
+ return { id: "new-".concat(count.current), name: file.name, size: file.size };
69
+ });
70
+ setFiles(function (list) { return __spreadArray(__spreadArray([], list, true), added, true); });
71
+ limitLine.current = chosen.length > room ? "Add up to ".concat(maxFiles, " files.") : '';
72
+ Promise.resolve().then(function () { limitLine.current = ''; });
73
+ setError(limitLine.current);
74
+ setJustSaved(false);
75
+ }
76
+ function handleRemove(id) {
77
+ if (saving)
78
+ return;
79
+ setFiles(function (list) { return list.filter(function (f) { return f.id !== id; }); });
80
+ setError('');
81
+ setJustSaved(false);
82
+ }
83
+ // The list is a group with one Save Button: 'Saved' shows for 2 seconds, and the Button is disabled while nothing changed.
84
+ function handleSave() {
85
+ if (saving)
86
+ return;
87
+ setSaving(true);
88
+ setError('');
89
+ // Stands in for the upload and the request to the server.
90
+ timers.current.push(setTimeout(function () {
91
+ setSaving(false);
92
+ setSaved(files);
93
+ setJustSaved(true);
94
+ clearTimeout(savedTimer.current);
95
+ savedTimer.current = setTimeout(function () { return setJustSaved(false); }, 2000);
96
+ }, 1200));
97
+ }
98
+ var changed = files.length !== saved.length || files.some(function (f, i) { return f.id !== saved[i].id; });
99
+ return (<Center width="form">
100
+ <Stack gap="large">
101
+ <Stack gap="small">
102
+ <Heading level={1} size="h5">Expense report</Heading>
103
+ <Paragraph tone="secondary" size="body2" measure="none">Add the receipts for your trip on Nov 12, 2026.</Paragraph>
104
+ </Stack>
105
+ <Form aria-label="Receipts" gap="large" onSubmit={handleSave}>
106
+ <FormField id="file-upload-files" label="Receipts" error={error}>
107
+ {function (f) { return (<DropZone id={f.id} label="Drop receipts here" buttonLabel="Choose Files" hint={"PDF, PNG or JPG, up to ".concat(formatBytes(maxBytes), " each. Add up to ").concat(maxFiles, " files.")} accept={['application/pdf', 'image/png', 'image/jpeg']} maxBytes={maxBytes} multiple maxFiles={maxFiles} disabled={saving} aria-describedby={f['aria-describedby']} aria-invalid={f['aria-invalid']} status={error || undefined} onFiles={handleFiles} onReject={function (rejections) { return setError(say(rejections, limitLine.current)); }}/>); }}
108
+ </FormField>
109
+ {files.length > 0 && (<Stack gap="small" align="start">
110
+ {files.map(function (file) { return (<FileChip key={file.id} name={file.name} kind={kindOf(file.name)} meta={formatBytes(file.size)} onRemove={function () { return handleRemove(file.id); }}/>); })}
111
+ </Stack>)}
112
+ <Cluster>
113
+ <Button size="medium" type="primary" state={changed || saving ? 'enabled' : 'disabled'} label={justSaved ? 'Saved' : 'Save'} htmlType="submit" loading={saving}/>
114
+ </Cluster>
115
+ </Form>
116
+ </Stack>
117
+ </Center>);
118
+ }
@@ -0,0 +1 @@
1
+ export default function FileUploadPicture(): import("react").JSX.Element;
@@ -0,0 +1,50 @@
1
+ 'use client';
2
+ import { useEffect, useRef, useState } from 'react';
3
+ import Heading from '../../components/heading';
4
+ import FormField from '../../components/formField';
5
+ import DropZone from '../../components/dropZone';
6
+ import UserImage from '../../components/userImage';
7
+ import { formatBytes } from '../../components/formatNumber';
8
+ import { Center, Stack } from '../../components/layout';
9
+ // A picture the person chose. A real app uploads the file and gets a URL back.
10
+ var chosenPicture = "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";
11
+ // 5 MB as formatBytes counts it (base 1024), so the words and the check agree
12
+ var maxBytes = 5 * 1024 * 1024;
13
+ // The zone reports a reason. The words are this page's, shown under the zone.
14
+ function say(rejections) {
15
+ var reason = rejections[0].reason;
16
+ if (reason === 'type')
17
+ return 'Choose a JPG, PNG or WebP picture.';
18
+ if (reason === 'size')
19
+ return "Choose a picture under ".concat(formatBytes(maxBytes), ".");
20
+ return 'Choose one picture.';
21
+ }
22
+ export default function FileUploadPicture() {
23
+ var _a = useState(undefined), picture = _a[0], setPicture = _a[1];
24
+ var _b = useState(false), saving = _b[0], setSaving = _b[1];
25
+ var _c = useState(''), error = _c[0], setError = _c[1];
26
+ var timer = useRef();
27
+ // Stops the request if the example goes away before it ends.
28
+ useEffect(function () { return function () { return clearTimeout(timer.current); }; }, []);
29
+ // The picture is one control on its own, so it saves as soon as it is chosen. Nothing shows when it works.
30
+ // A real app crops the picture to a square in its own code or on the server.
31
+ function handleFiles() {
32
+ setError('');
33
+ setSaving(true);
34
+ // Stands in for the upload.
35
+ timer.current = setTimeout(function () {
36
+ setSaving(false);
37
+ setPicture(chosenPicture);
38
+ }, 900);
39
+ }
40
+ return (<Center width="form">
41
+ <Stack gap="large">
42
+ <Heading level={1} size="h5">Profile</Heading>
43
+ <FormField id="file-upload-picture" label="Picture" error={error}>
44
+ {function (f) { return (<DropZone id={f.id} size="compact" label="Drop a picture here" buttonLabel="Change Picture" hint={"JPG, PNG or WebP, up to ".concat(formatBytes(maxBytes))} accept={['image/jpeg', 'image/png', 'image/webp']} maxBytes={maxBytes} loading={saving} aria-describedby={f['aria-describedby']} aria-invalid={f['aria-invalid']} status={error || undefined} onFiles={handleFiles} onReject={function (rejections) { return setError(say(rejections)); }}>
45
+ <UserImage userHandle="Dana Lee" userImgUrl={picture} size={64}/>
46
+ </DropZone>); }}
47
+ </FormField>
48
+ </Stack>
49
+ </Center>);
50
+ }