@bridgebrew/design-system 0.0.0-stage → 0.1.9
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 +21 -2
- package/browser.tsx +227 -0
- package/design-system.css +110 -0
- package/e2e.test.ts +253 -0
- package/highlight.ts +29 -0
- package/model.test.ts +69 -0
- package/package.json +72 -3
- package/stories/action.tsx +101 -0
- package/stories/data-display.tsx +371 -0
- package/stories/feedback.tsx +109 -0
- package/stories/foundations.tsx +157 -0
- package/stories/input.tsx +851 -0
- package/stories/interaction.tsx +76 -0
- package/stories/layout.tsx +510 -0
- package/stories/navigation.tsx +220 -0
- package/stories/overlay.tsx +293 -0
- package/stories/parts.tsx +201 -0
- package/stories.ts +149 -0
- package/tsconfig.json +20 -0
|
@@ -0,0 +1,851 @@
|
|
|
1
|
+
// Input: the form and detail-card controls, each with its variants, sizes, states and a working example.
|
|
2
|
+
import * as React from 'react';
|
|
3
|
+
import {
|
|
4
|
+
Avatar, Button, Checkbox, Combobox, DataMenuTrigger, EditableField, InlineFields, PickMenu, PickSelect, TagDot, TagList, TagMenu, TagPill,
|
|
5
|
+
type EditableFieldState, type PickOption, Field, FieldDescription, FieldError, FieldLabel, Icon, Input, Picker, Properties,
|
|
6
|
+
PromptField, PropertyRow, SegmentGroup, Select, SelectContent, SelectGroup, SelectItem, SelectLabel, SelectSeparator, SelectTrigger,
|
|
7
|
+
SelectValue, Slider, ColourPicker, StatusIcon, TagInput, Textarea, Toggle, useToast, type StatusIconStatus,
|
|
8
|
+
DropZone, type DropZoneHandle, ImageField, ToggleGroup,
|
|
9
|
+
} from '@bridge/ui';
|
|
10
|
+
import { Group, Sample, organizations, people, useFakeSearch } from './parts.tsx';
|
|
11
|
+
|
|
12
|
+
// ---------------------------------------------------------------------------------------------------------------
|
|
13
|
+
// Checkbox and Toggle
|
|
14
|
+
|
|
15
|
+
/** A control and its label on one row, wired by a Field. */
|
|
16
|
+
const Labelled = ({ label, disabled, children }: { label: string; disabled?: boolean; children: React.ReactNode }) => (
|
|
17
|
+
<Field disabled={disabled} className="ds-inline ds-field-row">
|
|
18
|
+
{children}
|
|
19
|
+
<FieldLabel>{label}</FieldLabel>
|
|
20
|
+
</Field>
|
|
21
|
+
);
|
|
22
|
+
|
|
23
|
+
const channels = ['Email', 'Slack', 'Push'] as const;
|
|
24
|
+
|
|
25
|
+
function CheckboxStory() {
|
|
26
|
+
const [on, setOn] = React.useState<ReadonlySet<string>>(new Set(['Email']));
|
|
27
|
+
const all = on.size === channels.length ? true : on.size === 0 ? false : 'indeterminate';
|
|
28
|
+
return (
|
|
29
|
+
<>
|
|
30
|
+
<Group title="States" code={`<Checkbox aria-label="Unchecked" />\n<Checkbox aria-label="Checked" defaultChecked />\n<Checkbox aria-label="Indeterminate" checked="indeterminate" />\n<Checkbox aria-label="Disabled" disabled /><Checkbox aria-label="Disabled, checked" disabled defaultChecked />`}>
|
|
31
|
+
<Sample title="unchecked"><Checkbox aria-label="Unchecked" /></Sample>
|
|
32
|
+
<Sample title="checked"><Checkbox aria-label="Checked" defaultChecked /></Sample>
|
|
33
|
+
<Sample title="indeterminate" description="Some, not all"><Checkbox aria-label="Indeterminate" checked="indeterminate" /></Sample>
|
|
34
|
+
<Sample title="disabled"><Checkbox aria-label="Disabled" disabled /><Checkbox aria-label="Disabled, checked" disabled defaultChecked /></Sample>
|
|
35
|
+
</Group>
|
|
36
|
+
<Group title="Examples" description="Select all: the parent shows a dash while some channels are on." layout="stack" code={`<div className="ds-checklist">\n <Labelled label="All channels">\n <Checkbox checked={all} onCheckedChange={(checked) => setOn(new Set(checked ? channels : []))} />\n </Labelled>\n <div className="ds-indent">\n {channels.map((channel) => (\n <Labelled key={channel} label={channel}>\n <Checkbox\n checked={on.has(channel)}\n onCheckedChange={(checked) => setOn((current) => {\n const next = new Set(current);\n if (checked) next.add(channel); else next.delete(channel);\n return next;\n })}\n />\n </Labelled>\n ))}\n </div>\n</div>`}>
|
|
37
|
+
<Sample title="notify me by" wide>
|
|
38
|
+
<div className="ds-checklist">
|
|
39
|
+
<Labelled label="All channels">
|
|
40
|
+
<Checkbox checked={all} onCheckedChange={(checked) => setOn(new Set(checked ? channels : []))} />
|
|
41
|
+
</Labelled>
|
|
42
|
+
<div className="ds-indent">
|
|
43
|
+
{channels.map((channel) => (
|
|
44
|
+
<Labelled key={channel} label={channel}>
|
|
45
|
+
<Checkbox
|
|
46
|
+
checked={on.has(channel)}
|
|
47
|
+
onCheckedChange={(checked) => setOn((current) => {
|
|
48
|
+
const next = new Set(current);
|
|
49
|
+
if (checked) next.add(channel); else next.delete(channel);
|
|
50
|
+
return next;
|
|
51
|
+
})}
|
|
52
|
+
/>
|
|
53
|
+
</Labelled>
|
|
54
|
+
))}
|
|
55
|
+
</div>
|
|
56
|
+
</div>
|
|
57
|
+
</Sample>
|
|
58
|
+
</Group>
|
|
59
|
+
</>
|
|
60
|
+
);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
function ToggleStory() {
|
|
64
|
+
const [settings, setSettings] = React.useState({ digest: true, mentions: true, sounds: false });
|
|
65
|
+
return (
|
|
66
|
+
<>
|
|
67
|
+
<Group title="States" code={`<Toggle aria-label="Off" />\n<Toggle aria-label="On" defaultChecked />\n<Toggle aria-label="Disabled" disabled /><Toggle aria-label="Disabled, on" disabled defaultChecked />`}>
|
|
68
|
+
<Sample title="off"><Toggle aria-label="Off" /></Sample>
|
|
69
|
+
<Sample title="on"><Toggle aria-label="On" defaultChecked /></Sample>
|
|
70
|
+
<Sample title="disabled"><Toggle aria-label="Disabled" disabled /><Toggle aria-label="Disabled, on" disabled defaultChecked /></Sample>
|
|
71
|
+
</Group>
|
|
72
|
+
<Group title="Examples" description="Settings that apply at once." layout="stack" code={`<div className="ds-checklist">\n {([['digest', 'Daily digest'], ['mentions', 'Mentions'], ['sounds', 'Sounds']] as const).map(([key, label]) => (\n <Labelled key={key} label={label}>\n <Toggle checked={settings[key]} onCheckedChange={(checked) => setSettings((current) => ({ ...current, [key]: checked }))} />\n </Labelled>\n ))}\n <Labelled label="Desktop badge (managed by your admin)" disabled><Toggle defaultChecked /></Labelled>\n</div>`}>
|
|
73
|
+
<Sample title="notifications" wide>
|
|
74
|
+
<div className="ds-checklist">
|
|
75
|
+
{([['digest', 'Daily digest'], ['mentions', 'Mentions'], ['sounds', 'Sounds']] as const).map(([key, label]) => (
|
|
76
|
+
<Labelled key={key} label={label}>
|
|
77
|
+
<Toggle checked={settings[key]} onCheckedChange={(checked) => setSettings((current) => ({ ...current, [key]: checked }))} />
|
|
78
|
+
</Labelled>
|
|
79
|
+
))}
|
|
80
|
+
<Labelled label="Desktop badge (managed by your admin)" disabled><Toggle defaultChecked /></Labelled>
|
|
81
|
+
</div>
|
|
82
|
+
</Sample>
|
|
83
|
+
</Group>
|
|
84
|
+
</>
|
|
85
|
+
);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
// ---------------------------------------------------------------------------------------------------------------
|
|
89
|
+
// Colour picker
|
|
90
|
+
|
|
91
|
+
/** A colour picker holding its own value, as Settings holds a look colour. */
|
|
92
|
+
function Colour(props: Omit<React.ComponentProps<typeof ColourPicker>, 'value' | 'onChange'> & { initial?: string }) {
|
|
93
|
+
const [value, setValue] = React.useState<string | undefined>(props.initial);
|
|
94
|
+
return <ColourPicker {...props} value={value} onChange={setValue} />;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
function ColourPickerStory() {
|
|
98
|
+
return (
|
|
99
|
+
<>
|
|
100
|
+
<Group title="States" layout="stack" code={`<Colour defaultColour="var(--paint-c1)" defaultName="Theme's first paint colour" />\n<Colour initial="var(--accent)" defaultColour="var(--accent)" defaultName="Theme's accent" />\n<Colour initial="oklch(62% 0.14 165)" />\n<Colour />\n<Colour initial="var(--accent)" disabled />`}>
|
|
101
|
+
<Sample title="default" description="Unset: the theme's colour it follows, its name read out" wide>
|
|
102
|
+
<Colour defaultColour="var(--paint-c1)" defaultName="Theme's first paint colour" />
|
|
103
|
+
</Sample>
|
|
104
|
+
<Sample title="a theme colour" description="Stored as its reference (var(--accent)): it follows the theme" wide>
|
|
105
|
+
<Colour initial="var(--accent)" defaultColour="var(--accent)" defaultName="Theme's accent" />
|
|
106
|
+
</Sample>
|
|
107
|
+
<Sample title="a colour of its own" description="From Custom, in the popover: read out as its value" wide>
|
|
108
|
+
<Colour initial="oklch(62% 0.14 165)" />
|
|
109
|
+
</Sample>
|
|
110
|
+
<Sample title="no default colour" description="The default crossed out: a value of Bridge's own" wide>
|
|
111
|
+
<Colour />
|
|
112
|
+
</Sample>
|
|
113
|
+
<Sample title="disabled" wide>
|
|
114
|
+
<Colour initial="var(--accent)" disabled />
|
|
115
|
+
</Sample>
|
|
116
|
+
</Group>
|
|
117
|
+
<Group title="Examples" description="Each mode's half drawn in that mode's theme, as Settings draws a colour by mode." layout="stack" code={`<Colour theme="t3-code-light" defaultColour="var(--paint-c1)" defaultName="Theme's first paint colour" />\n<Colour theme="t3-code-dark" defaultColour="var(--paint-c1)" defaultName="Theme's first paint colour" />`}>
|
|
118
|
+
<Sample title="light and dark" wide>
|
|
119
|
+
<Colour theme="t3-code-light" defaultColour="var(--paint-c1)" defaultName="Theme's first paint colour" />
|
|
120
|
+
<Colour theme="t3-code-dark" defaultColour="var(--paint-c1)" defaultName="Theme's first paint colour" />
|
|
121
|
+
</Sample>
|
|
122
|
+
</Group>
|
|
123
|
+
</>
|
|
124
|
+
);
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
// ---------------------------------------------------------------------------------------------------------------
|
|
128
|
+
// Slider
|
|
129
|
+
|
|
130
|
+
/** A slider with its value read out after it, as Settings draws one (`x-bridge-slider`). */
|
|
131
|
+
function ReadOut({ label, unit, ...props }: { label: string; unit: string } & React.ComponentProps<typeof Slider>) {
|
|
132
|
+
const [value, setValue] = React.useState(props.defaultValue as number);
|
|
133
|
+
return (
|
|
134
|
+
<div className="ds-control ds-inline">
|
|
135
|
+
<Slider aria-label={label} {...props} value={value} onValueChange={setValue} />
|
|
136
|
+
<output className="ds-readout">{value}{unit}</output>
|
|
137
|
+
</div>
|
|
138
|
+
);
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
function SliderStory() {
|
|
142
|
+
return (
|
|
143
|
+
<>
|
|
144
|
+
<Group title="States" layout="stack" code={`<div className="ds-control"><Slider aria-label="Default" defaultValue={40} /></div>\n<div className="ds-control"><Slider aria-label="Minimum" defaultValue={0} /></div>\n<div className="ds-control"><Slider aria-label="Maximum" defaultValue={100} /></div>\n<div className="ds-control"><Slider aria-label="Disabled" defaultValue={60} disabled /></div>\n<div className="ds-control-wide"><Slider aria-label="Wide" defaultValue={50} /></div>`}>
|
|
145
|
+
<Sample title="default" description="As wide as its container: here 280px" wide>
|
|
146
|
+
<div className="ds-control"><Slider aria-label="Default" defaultValue={40} /></div>
|
|
147
|
+
</Sample>
|
|
148
|
+
<Sample title="at the ends" wide>
|
|
149
|
+
<div className="ds-control"><Slider aria-label="Minimum" defaultValue={0} /></div>
|
|
150
|
+
<div className="ds-control"><Slider aria-label="Maximum" defaultValue={100} /></div>
|
|
151
|
+
</Sample>
|
|
152
|
+
<Sample title="disabled" wide>
|
|
153
|
+
<div className="ds-control"><Slider aria-label="Disabled" defaultValue={60} disabled /></div>
|
|
154
|
+
</Sample>
|
|
155
|
+
<Sample title="wide" description="420px" wide>
|
|
156
|
+
<div className="ds-control-wide"><Slider aria-label="Wide" defaultValue={50} /></div>
|
|
157
|
+
</Sample>
|
|
158
|
+
</Group>
|
|
159
|
+
<Group title="Examples" description="A setting's range, its value read out as it moves (Settings saves it once it rests)." layout="stack" code={`<ReadOut label="Window background opacity" unit=" %" defaultValue={85} min={30} max={100} />\n<ReadOut label="Blur behind the windows" unit=" px" defaultValue={16} min={0} max={40} />`}>
|
|
160
|
+
<Sample title="window background" wide>
|
|
161
|
+
<ReadOut label="Window background opacity" unit=" %" defaultValue={85} min={30} max={100} />
|
|
162
|
+
<ReadOut label="Blur behind the windows" unit=" px" defaultValue={16} min={0} max={40} />
|
|
163
|
+
</Sample>
|
|
164
|
+
</Group>
|
|
165
|
+
</>
|
|
166
|
+
);
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
// ---------------------------------------------------------------------------------------------------------------
|
|
170
|
+
// Text
|
|
171
|
+
|
|
172
|
+
function InputStory() {
|
|
173
|
+
const [title, setTitle] = React.useState('Quarterly planning');
|
|
174
|
+
const [city, setCity] = React.useState('Lyon');
|
|
175
|
+
return (
|
|
176
|
+
<>
|
|
177
|
+
<Group title="Variants" layout="stack" code={`<div className="ds-control"><Input variant="outline" placeholder="name@company.com" aria-label="Outline" /></div>\n<div className="ds-control"><Input variant="inline" value={city} onChange={(event) => setCity(event.currentTarget.value)} aria-label="City" /></div>\n<div className="ds-control-wide"><Input variant="inline-title" value={title} onChange={(event) => setTitle(event.currentTarget.value)} aria-label="Title" /></div>`}>
|
|
178
|
+
<Sample title="outline" description="Forms and settings; lg (32px) by default" wide>
|
|
179
|
+
<div className="ds-control"><Input variant="outline" placeholder="name@company.com" aria-label="Outline" /></div>
|
|
180
|
+
</Sample>
|
|
181
|
+
<Sample title="inline" description="A value edited in place on a detail card; borderless until hovered" wide>
|
|
182
|
+
<div className="ds-control"><Input variant="inline" value={city} onChange={(event) => setCity(event.currentTarget.value)} aria-label="City" /></div>
|
|
183
|
+
</Sample>
|
|
184
|
+
<Sample title="inline-title" description="A record's title, edited in place" wide>
|
|
185
|
+
<div className="ds-control-wide"><Input variant="inline-title" value={title} onChange={(event) => setTitle(event.currentTarget.value)} aria-label="Title" /></div>
|
|
186
|
+
</Sample>
|
|
187
|
+
</Group>
|
|
188
|
+
<Group title="Sizes" description="On the sm, md and lg heights." layout="grid" code={`{(['sm', 'default', 'lg'] as const).map((size) => (\n <Input variant="outline" size={size} placeholder={\`Size \${size}\`} aria-label={\`Size \${size}\`} />\n))}`}>
|
|
189
|
+
{(['sm', 'default', 'lg'] as const).map((size) => (
|
|
190
|
+
<Sample key={size} title={size}>
|
|
191
|
+
<Input variant="outline" size={size} placeholder={`Size ${size}`} aria-label={`Size ${size}`} />
|
|
192
|
+
</Sample>
|
|
193
|
+
))}
|
|
194
|
+
</Group>
|
|
195
|
+
<Group title="Adornments" layout="grid" code={`<Input variant="outline" size="default" type="search" placeholder="Search" aria-label="Search" icon={<Icon name="search" size={14} />} />\n<Input variant="outline" size="default" placeholder="Jump to…" aria-label="Jump to" shortcut="⌘K" />\n<Input variant="outline" size="default" type="search" placeholder="Search" aria-label="Search all" icon={<Icon name="search" size={14} />} shortcut="/" />`}>
|
|
196
|
+
<Sample title="icon"><Input variant="outline" size="default" type="search" placeholder="Search" aria-label="Search" icon={<Icon name="search" size={14} />} /></Sample>
|
|
197
|
+
<Sample title="shortcut"><Input variant="outline" size="default" placeholder="Jump to…" aria-label="Jump to" shortcut="⌘K" /></Sample>
|
|
198
|
+
<Sample title="icon and shortcut"><Input variant="outline" size="default" type="search" placeholder="Search" aria-label="Search all" icon={<Icon name="search" size={14} />} shortcut="/" /></Sample>
|
|
199
|
+
</Group>
|
|
200
|
+
<Group title="States" layout="grid" code={`<Input variant="outline" placeholder="Add a website" aria-label="Placeholder" />\n<Input variant="outline" defaultValue="northwind.example" aria-label="Filled" />\n<Input variant="outline" readOnly defaultValue="Created by Ada" aria-label="Read-only" />\n<Input variant="outline" disabled defaultValue="Locked" aria-label="Disabled" />\n<Field invalid>\n <Input variant="outline" defaultValue="hi@" aria-label="Invalid" />\n <FieldError>Enter a valid email</FieldError>\n</Field>\n<Field invalid>\n <Input variant="inline" defaultValue="+33 call me" aria-label="Phone" />\n <FieldError>Enter a phone number</FieldError>\n</Field>`}>
|
|
201
|
+
<Sample title="placeholder"><Input variant="outline" placeholder="Add a website" aria-label="Placeholder" /></Sample>
|
|
202
|
+
<Sample title="filled"><Input variant="outline" defaultValue="northwind.example" aria-label="Filled" /></Sample>
|
|
203
|
+
<Sample title="read-only"><Input variant="outline" readOnly defaultValue="Created by Ada" aria-label="Read-only" /></Sample>
|
|
204
|
+
<Sample title="disabled"><Input variant="outline" disabled defaultValue="Locked" aria-label="Disabled" /></Sample>
|
|
205
|
+
<Sample title="invalid" description="aria-invalid, in an invalid Field">
|
|
206
|
+
<Field invalid>
|
|
207
|
+
<Input variant="outline" defaultValue="hi@" aria-label="Invalid" />
|
|
208
|
+
<FieldError>Enter a valid email</FieldError>
|
|
209
|
+
</Field>
|
|
210
|
+
</Sample>
|
|
211
|
+
<Sample title="inline, invalid">
|
|
212
|
+
<Field invalid>
|
|
213
|
+
<Input variant="inline" defaultValue="+33 call me" aria-label="Phone" />
|
|
214
|
+
<FieldError>Enter a phone number</FieldError>
|
|
215
|
+
</Field>
|
|
216
|
+
</Sample>
|
|
217
|
+
</Group>
|
|
218
|
+
</>
|
|
219
|
+
);
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
function TextareaStory() {
|
|
223
|
+
const [notes, setNotes] = React.useState('Met at the Lyon offsite.\nFollow up after the pilot.');
|
|
224
|
+
return (
|
|
225
|
+
<>
|
|
226
|
+
<Group title="Variants" layout="grid" code={`<Textarea value={notes} onChange={(event) => setNotes(event.currentTarget.value)} aria-label="Notes" />\n<Textarea variant="outline" placeholder="Context, history, next steps…" aria-label="Outline notes" />`}>
|
|
227
|
+
<Sample title="default" description="Borderless, an inline description; grows as you type">
|
|
228
|
+
<Textarea value={notes} onChange={(event) => setNotes(event.currentTarget.value)} aria-label="Notes" />
|
|
229
|
+
</Sample>
|
|
230
|
+
<Sample title="outline" description="In forms, framed like an outline Input">
|
|
231
|
+
<Textarea variant="outline" placeholder="Context, history, next steps…" aria-label="Outline notes" />
|
|
232
|
+
</Sample>
|
|
233
|
+
</Group>
|
|
234
|
+
<Group title="States" layout="grid" code={`<Textarea variant="outline" readOnly defaultValue="Signed off by legal on 2 October." aria-label="Read-only notes" />\n<Textarea variant="outline" disabled defaultValue="Archived record" aria-label="Disabled notes" />\n<Field invalid>\n <Textarea variant="outline" defaultValue="Too short" aria-label="Invalid notes" />\n <FieldError>Write at least 20 characters</FieldError>\n</Field>`}>
|
|
235
|
+
<Sample title="read-only"><Textarea variant="outline" readOnly defaultValue="Signed off by legal on 2 October." aria-label="Read-only notes" /></Sample>
|
|
236
|
+
<Sample title="disabled"><Textarea variant="outline" disabled defaultValue="Archived record" aria-label="Disabled notes" /></Sample>
|
|
237
|
+
<Sample title="invalid">
|
|
238
|
+
<Field invalid>
|
|
239
|
+
<Textarea variant="outline" defaultValue="Too short" aria-label="Invalid notes" />
|
|
240
|
+
<FieldError>Write at least 20 characters</FieldError>
|
|
241
|
+
</Field>
|
|
242
|
+
</Sample>
|
|
243
|
+
</Group>
|
|
244
|
+
</>
|
|
245
|
+
);
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
function FieldStory() {
|
|
249
|
+
const { toast } = useToast();
|
|
250
|
+
const [email, setEmail] = React.useState('');
|
|
251
|
+
const [touched, setTouched] = React.useState(false);
|
|
252
|
+
const [role, setRole] = React.useState<string | null>(null);
|
|
253
|
+
const [tags, setTags] = React.useState<string[]>(['design']);
|
|
254
|
+
const emailError = !/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(email) ? (email === '' ? 'Enter an email' : 'Enter a valid email, e.g. ada@northwind.dev') : undefined;
|
|
255
|
+
const roleError = role === null ? 'Choose a role' : undefined;
|
|
256
|
+
return (
|
|
257
|
+
<>
|
|
258
|
+
<Group title="Parts" description="FieldLabel, the control, FieldDescription, FieldError, 4px apart." layout="grid" code={`<Field>\n <FieldLabel>Website</FieldLabel>\n <Input variant="outline" placeholder="northwind.example" />\n <FieldDescription>Shown on the organization's card</FieldDescription>\n</Field>\n<Field invalid>\n <FieldLabel>Email</FieldLabel>\n <Input variant="outline" defaultValue="ada@" />\n <FieldError>Enter a valid email</FieldError>\n</Field>\n<Field disabled invalid>\n <FieldLabel>Workspace</FieldLabel>\n <Input variant="outline" defaultValue="generic-test" />\n <FieldError>Hidden while disabled</FieldError>\n</Field>`}>
|
|
259
|
+
<Sample title="label and description">
|
|
260
|
+
<Field>
|
|
261
|
+
<FieldLabel>Website</FieldLabel>
|
|
262
|
+
<Input variant="outline" placeholder="northwind.example" />
|
|
263
|
+
<FieldDescription>Shown on the organization's card</FieldDescription>
|
|
264
|
+
</Field>
|
|
265
|
+
</Sample>
|
|
266
|
+
<Sample title="invalid" description="The control is marked aria-invalid">
|
|
267
|
+
<Field invalid>
|
|
268
|
+
<FieldLabel>Email</FieldLabel>
|
|
269
|
+
<Input variant="outline" defaultValue="ada@" />
|
|
270
|
+
<FieldError>Enter a valid email</FieldError>
|
|
271
|
+
</Field>
|
|
272
|
+
</Sample>
|
|
273
|
+
<Sample title="disabled" description="The error never shows on a disabled field">
|
|
274
|
+
<Field disabled invalid>
|
|
275
|
+
<FieldLabel>Workspace</FieldLabel>
|
|
276
|
+
<Input variant="outline" defaultValue="generic-test" />
|
|
277
|
+
<FieldError>Hidden while disabled</FieldError>
|
|
278
|
+
</Field>
|
|
279
|
+
</Sample>
|
|
280
|
+
</Group>
|
|
281
|
+
<Group title="Examples" description="An invite form: errors show once a field is left, all of them on submit." layout="fill" code={`<form\n className="ds-form"\n noValidate\n onSubmit={(event) => {\n event.preventDefault();\n setTouched(true);\n if (emailError || roleError) return;\n toast({ title: \`Invitation sent to \${email}\`, description: \`As \${role}\${tags.length ? \`, tagged \${tags.join(', ')}\` : ''}\`, variant: 'success' });\n setEmail(''); setRole(null); setTags([]); setTouched(false);\n }}\n>\n <Field invalid={touched && emailError !== undefined}>\n <FieldLabel>Email</FieldLabel>\n <Input variant="outline" type="email" placeholder="ada@northwind.dev" value={email} onChange={(event) => setEmail(event.currentTarget.value)} onBlur={() => setTouched(true)} />\n <FieldError>{emailError}</FieldError>\n </Field>\n <Field invalid={touched && roleError !== undefined}>\n <FieldLabel>Role</FieldLabel>\n <Select items={{ member: 'Member', admin: 'Admin', guest: 'Guest' }} value={role} onValueChange={(value) => setRole(value as string | null)}>\n <SelectTrigger><SelectValue placeholder="Choose a role" /></SelectTrigger>\n <SelectContent>\n <SelectItem value="member">Member</SelectItem>\n <SelectItem value="admin">Admin</SelectItem>\n <SelectItem value="guest">Guest</SelectItem>\n </SelectContent>\n </Select>\n <FieldError>{roleError}</FieldError>\n </Field>\n <Field>\n <FieldLabel>Teams</FieldLabel>\n <TagInput value={tags} onChange={setTags} placeholder={tags.length ? '' : 'Type a team, then Enter'} />\n <FieldDescription>Enter or a comma adds a team</FieldDescription>\n </Field>\n <div className="ds-actions">\n <Button variant="ghost" type="reset" onClick={() => { setEmail(''); setRole(null); setTags([]); setTouched(false); }}>Clear</Button>\n <Button variant="primary" type="submit">Send invitation</Button>\n </div>\n</form>`}>
|
|
282
|
+
<form
|
|
283
|
+
className="ds-form"
|
|
284
|
+
noValidate
|
|
285
|
+
onSubmit={(event) => {
|
|
286
|
+
event.preventDefault();
|
|
287
|
+
setTouched(true);
|
|
288
|
+
if (emailError || roleError) return;
|
|
289
|
+
toast({ title: `Invitation sent to ${email}`, description: `As ${role}${tags.length ? `, tagged ${tags.join(', ')}` : ''}`, variant: 'success' });
|
|
290
|
+
setEmail(''); setRole(null); setTags([]); setTouched(false);
|
|
291
|
+
}}
|
|
292
|
+
>
|
|
293
|
+
<Field invalid={touched && emailError !== undefined}>
|
|
294
|
+
<FieldLabel>Email</FieldLabel>
|
|
295
|
+
<Input variant="outline" type="email" placeholder="ada@northwind.dev" value={email} onChange={(event) => setEmail(event.currentTarget.value)} onBlur={() => setTouched(true)} />
|
|
296
|
+
<FieldError>{emailError}</FieldError>
|
|
297
|
+
</Field>
|
|
298
|
+
<Field invalid={touched && roleError !== undefined}>
|
|
299
|
+
<FieldLabel>Role</FieldLabel>
|
|
300
|
+
<Select items={{ member: 'Member', admin: 'Admin', guest: 'Guest' }} value={role} onValueChange={(value) => setRole(value as string | null)}>
|
|
301
|
+
<SelectTrigger><SelectValue placeholder="Choose a role" /></SelectTrigger>
|
|
302
|
+
<SelectContent>
|
|
303
|
+
<SelectItem value="member">Member</SelectItem>
|
|
304
|
+
<SelectItem value="admin">Admin</SelectItem>
|
|
305
|
+
<SelectItem value="guest">Guest</SelectItem>
|
|
306
|
+
</SelectContent>
|
|
307
|
+
</Select>
|
|
308
|
+
<FieldError>{roleError}</FieldError>
|
|
309
|
+
</Field>
|
|
310
|
+
<Field>
|
|
311
|
+
<FieldLabel>Teams</FieldLabel>
|
|
312
|
+
<TagInput value={tags} onChange={setTags} placeholder={tags.length ? '' : 'Type a team, then Enter'} />
|
|
313
|
+
<FieldDescription>Enter or a comma adds a team</FieldDescription>
|
|
314
|
+
</Field>
|
|
315
|
+
<div className="ds-actions">
|
|
316
|
+
<Button variant="ghost" type="reset" onClick={() => { setEmail(''); setRole(null); setTags([]); setTouched(false); }}>Clear</Button>
|
|
317
|
+
<Button variant="primary" type="submit">Send invitation</Button>
|
|
318
|
+
</div>
|
|
319
|
+
</form>
|
|
320
|
+
</Group>
|
|
321
|
+
</>
|
|
322
|
+
);
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
function TagInputStory() {
|
|
326
|
+
const [tags, setTags] = React.useState<string[]>(['VIP client', 'Lyon', 'Q4 pilot']);
|
|
327
|
+
return (
|
|
328
|
+
<>
|
|
329
|
+
<Group title="States" layout="grid" code={`<TagInput aria-label="Empty tags" value={[]} onChange={() => {}} placeholder="Type a tag, then Enter" />\n<TagInput aria-label="Disabled tags" value={['archived', 'read-only']} onChange={() => {}} disabled />\n<Field invalid>\n <TagInput aria-label="Invalid tags" value={['VIP', 'Q4!']} onChange={() => {}} />\n <FieldError>Tags are letters, digits and spaces</FieldError>\n</Field>`}>
|
|
330
|
+
<Sample title="empty" description="A placeholder until the first tag">
|
|
331
|
+
<TagInput aria-label="Empty tags" value={[]} onChange={() => {}} placeholder="Type a tag, then Enter" />
|
|
332
|
+
</Sample>
|
|
333
|
+
<Sample title="disabled"><TagInput aria-label="Disabled tags" value={['archived', 'read-only']} onChange={() => {}} disabled /></Sample>
|
|
334
|
+
<Sample title="invalid">
|
|
335
|
+
<Field invalid>
|
|
336
|
+
<TagInput aria-label="Invalid tags" value={['VIP', 'Q4!']} onChange={() => {}} />
|
|
337
|
+
<FieldError>Tags are letters, digits and spaces</FieldError>
|
|
338
|
+
</Field>
|
|
339
|
+
</Sample>
|
|
340
|
+
</Group>
|
|
341
|
+
<Group title="Examples" description="Enter, a comma or leaving adds; Backspace on an empty input removes the last; pasting “a,b,c” adds three." layout="stack" code={`<div className="ds-control-wide"><TagInput aria-label="Tags" value={tags} onChange={setTags} placeholder={tags.length ? '' : 'Type a tag, then Enter'} /></div>`}>
|
|
342
|
+
<Sample title="tags, with real state" description={`${tags.length} ${tags.length === 1 ? 'tag' : 'tags'}`} wide>
|
|
343
|
+
<div className="ds-control-wide"><TagInput aria-label="Tags" value={tags} onChange={setTags} placeholder={tags.length ? '' : 'Type a tag, then Enter'} /></div>
|
|
344
|
+
</Sample>
|
|
345
|
+
</Group>
|
|
346
|
+
</>
|
|
347
|
+
);
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
// ---------------------------------------------------------------------------------------------------------------
|
|
351
|
+
// Choices
|
|
352
|
+
|
|
353
|
+
const views = [{ value: 'list', label: 'List' }, { value: 'board', label: 'Board' }, { value: 'timeline', label: 'Timeline' }];
|
|
354
|
+
|
|
355
|
+
function SegmentGroupStory() {
|
|
356
|
+
const [view, setView] = React.useState('board');
|
|
357
|
+
const [range, setRange] = React.useState('week');
|
|
358
|
+
const [layout, setLayout] = React.useState('list');
|
|
359
|
+
return (
|
|
360
|
+
<>
|
|
361
|
+
<Group title="Variants" layout="stack" code={`<SegmentGroup aria-label="View" items={views} value={view} onValueChange={setView} />\n<div className="ds-control-wide">\n <SegmentGroup aria-label="Range" fullWidth items={[{ value: 'day', label: 'Day' }, { value: 'week', label: 'Week' }, { value: 'month', label: 'Month' }, { value: 'quarter', label: 'Quarter' }]} value={range} onValueChange={setRange} />\n</div>\n<SegmentGroup\n aria-label="Layout"\n items={[{ value: 'list', label: <Icon name="list" size={14} aria-label="List" /> }, { value: 'board', label: <Icon name="dashboard" size={14} /> }, { value: 'calendar', label: <Icon name="calendar" size={14} /> }]}\n value={layout}\n onValueChange={setLayout}\n/>`}>
|
|
362
|
+
<Sample title="inline" description="As wide as its labels" wide>
|
|
363
|
+
<SegmentGroup aria-label="View" items={views} value={view} onValueChange={setView} />
|
|
364
|
+
</Sample>
|
|
365
|
+
<Sample title="full width" description="fullWidth: the segments share the width" wide>
|
|
366
|
+
<div className="ds-control-wide">
|
|
367
|
+
<SegmentGroup aria-label="Range" fullWidth items={[{ value: 'day', label: 'Day' }, { value: 'week', label: 'Week' }, { value: 'month', label: 'Month' }, { value: 'quarter', label: 'Quarter' }]} value={range} onValueChange={setRange} />
|
|
368
|
+
</div>
|
|
369
|
+
</Sample>
|
|
370
|
+
<Sample title="icons" description="Labels can be any node; name the group" wide>
|
|
371
|
+
<SegmentGroup
|
|
372
|
+
aria-label="Layout"
|
|
373
|
+
items={[{ value: 'list', label: <Icon name="list" size={14} aria-label="List" /> }, { value: 'board', label: <Icon name="dashboard" size={14} /> }, { value: 'calendar', label: <Icon name="calendar" size={14} /> }]}
|
|
374
|
+
value={layout}
|
|
375
|
+
onValueChange={setLayout}
|
|
376
|
+
/>
|
|
377
|
+
</Sample>
|
|
378
|
+
</Group>
|
|
379
|
+
<Group title="States" description="← → move and pick; the indicator slides." layout="stack" code={`<Sample title="selected" description={\`View: \${views.find((each) => each.value === view)?.label}\`} wide>\n <SegmentGroup aria-label="View, again" items={views} value={view} onValueChange={setView} />`}>
|
|
380
|
+
<Sample title="selected" description={`View: ${views.find((each) => each.value === view)?.label}`} wide>
|
|
381
|
+
<SegmentGroup aria-label="View, again" items={views} value={view} onValueChange={setView} />
|
|
382
|
+
</Sample>
|
|
383
|
+
</Group>
|
|
384
|
+
</>
|
|
385
|
+
);
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
const fruits = { apple: 'Apple', banana: 'Banana', cherry: 'Cherry', grape: 'Grape', mango: 'Mango' };
|
|
389
|
+
|
|
390
|
+
function SelectStory() {
|
|
391
|
+
const [fruit, setFruit] = React.useState<string | null>('cherry');
|
|
392
|
+
const [tz, setTz] = React.useState<string | null>(null);
|
|
393
|
+
const zones = { paris: 'Paris (UTC+2)', london: 'London (UTC+1)', lisbon: 'Lisbon (UTC+1)', ny: 'New York (UTC−4)', sf: 'San Francisco (UTC−7)', tokyo: 'Tokyo (UTC+9)' };
|
|
394
|
+
return (
|
|
395
|
+
<>
|
|
396
|
+
<Group title="Sizes" description="The trigger is an outline Input; lg by default." layout="grid" code={`{(['sm', 'default', 'lg'] as const).map((size) => (\n <Select items={fruits} value={fruit} onValueChange={(value) => setFruit(value as string | null)}>\n <SelectTrigger size={size} aria-label={\`Fruit, \${size}\`}><SelectValue /></SelectTrigger>\n <SelectContent>{Object.entries(fruits).map(([value, label]) => <SelectItem key={value} value={value}>{label}</SelectItem>)}</SelectContent>\n </Select>\n))}`}>
|
|
397
|
+
{(['sm', 'default', 'lg'] as const).map((size) => (
|
|
398
|
+
<Sample key={size} title={size}>
|
|
399
|
+
<Select items={fruits} value={fruit} onValueChange={(value) => setFruit(value as string | null)}>
|
|
400
|
+
<SelectTrigger size={size} aria-label={`Fruit, ${size}`}><SelectValue /></SelectTrigger>
|
|
401
|
+
<SelectContent>{Object.entries(fruits).map(([value, label]) => <SelectItem key={value} value={value}>{label}</SelectItem>)}</SelectContent>
|
|
402
|
+
</Select>
|
|
403
|
+
</Sample>
|
|
404
|
+
))}
|
|
405
|
+
</Group>
|
|
406
|
+
<Group title="States" layout="grid" code={`<Select items={zones} value={tz} onValueChange={(value) => setTz(value as string | null)}>\n <SelectTrigger aria-label="Time zone"><SelectValue placeholder="Choose a time zone" /></SelectTrigger>\n <SelectContent>\n <SelectGroup>\n <SelectLabel>Europe</SelectLabel>\n {(['paris', 'london', 'lisbon'] as const).map((key) => <SelectItem key={key} value={key}>{zones[key]}</SelectItem>)}\n </SelectGroup>\n <SelectSeparator />\n <SelectGroup>\n <SelectLabel>Americas</SelectLabel>\n {(['ny', 'sf'] as const).map((key) => <SelectItem key={key} value={key}>{zones[key]}</SelectItem>)}\n </SelectGroup>\n <SelectSeparator />\n <SelectGroup>\n <SelectLabel>Asia</SelectLabel>\n <SelectItem value="tokyo" disabled>{zones.tokyo}</SelectItem>\n </SelectGroup>\n </SelectContent>\n</Select>\n<Select items={fruits} defaultValue="apple" disabled>\n <SelectTrigger aria-label="Disabled fruit"><SelectValue /></SelectTrigger>\n <SelectContent>{Object.entries(fruits).map(([value, label]) => <SelectItem key={value} value={value}>{label}</SelectItem>)}</SelectContent>\n</Select>\n<Field invalid>\n <Select items={fruits} value={null}>\n <SelectTrigger aria-label="Invalid fruit"><SelectValue placeholder="Pick a fruit" /></SelectTrigger>\n <SelectContent>{Object.entries(fruits).map(([value, label]) => <SelectItem key={value} value={value}>{label}</SelectItem>)}</SelectContent>\n </Select>\n <FieldError>Pick a fruit</FieldError>\n</Field>`}>
|
|
407
|
+
<Sample title="placeholder">
|
|
408
|
+
<Select items={zones} value={tz} onValueChange={(value) => setTz(value as string | null)}>
|
|
409
|
+
<SelectTrigger aria-label="Time zone"><SelectValue placeholder="Choose a time zone" /></SelectTrigger>
|
|
410
|
+
<SelectContent>
|
|
411
|
+
<SelectGroup>
|
|
412
|
+
<SelectLabel>Europe</SelectLabel>
|
|
413
|
+
{(['paris', 'london', 'lisbon'] as const).map((key) => <SelectItem key={key} value={key}>{zones[key]}</SelectItem>)}
|
|
414
|
+
</SelectGroup>
|
|
415
|
+
<SelectSeparator />
|
|
416
|
+
<SelectGroup>
|
|
417
|
+
<SelectLabel>Americas</SelectLabel>
|
|
418
|
+
{(['ny', 'sf'] as const).map((key) => <SelectItem key={key} value={key}>{zones[key]}</SelectItem>)}
|
|
419
|
+
</SelectGroup>
|
|
420
|
+
<SelectSeparator />
|
|
421
|
+
<SelectGroup>
|
|
422
|
+
<SelectLabel>Asia</SelectLabel>
|
|
423
|
+
<SelectItem value="tokyo" disabled>{zones.tokyo}</SelectItem>
|
|
424
|
+
</SelectGroup>
|
|
425
|
+
</SelectContent>
|
|
426
|
+
</Select>
|
|
427
|
+
</Sample>
|
|
428
|
+
<Sample title="disabled">
|
|
429
|
+
<Select items={fruits} defaultValue="apple" disabled>
|
|
430
|
+
<SelectTrigger aria-label="Disabled fruit"><SelectValue /></SelectTrigger>
|
|
431
|
+
<SelectContent>{Object.entries(fruits).map(([value, label]) => <SelectItem key={value} value={value}>{label}</SelectItem>)}</SelectContent>
|
|
432
|
+
</Select>
|
|
433
|
+
</Sample>
|
|
434
|
+
<Sample title="invalid">
|
|
435
|
+
<Field invalid>
|
|
436
|
+
<Select items={fruits} value={null}>
|
|
437
|
+
<SelectTrigger aria-label="Invalid fruit"><SelectValue placeholder="Pick a fruit" /></SelectTrigger>
|
|
438
|
+
<SelectContent>{Object.entries(fruits).map(([value, label]) => <SelectItem key={value} value={value}>{label}</SelectItem>)}</SelectContent>
|
|
439
|
+
</Select>
|
|
440
|
+
<FieldError>Pick a fruit</FieldError>
|
|
441
|
+
</Field>
|
|
442
|
+
</Sample>
|
|
443
|
+
</Group>
|
|
444
|
+
<Group title="Examples" description="Groups with labels, separators, a disabled item; aligned over the trigger (macOS style)." layout="grid" code={`<Select items={zones} value={tz} onValueChange={(value) => setTz(value as string | null)}>\n <SelectTrigger aria-label="Time zone, grouped"><SelectValue placeholder="Choose a time zone" /></SelectTrigger>\n <SelectContent>\n <SelectGroup><SelectLabel>Europe</SelectLabel>{(['paris', 'london', 'lisbon'] as const).map((key) => <SelectItem key={key} value={key}>{zones[key]}</SelectItem>)}</SelectGroup>\n <SelectSeparator />\n <SelectGroup><SelectLabel>Americas</SelectLabel>{(['ny', 'sf'] as const).map((key) => <SelectItem key={key} value={key}>{zones[key]}</SelectItem>)}</SelectGroup>\n </SelectContent>\n</Select>\n<Select items={fruits} value={fruit} onValueChange={(value) => setFruit(value as string | null)}>\n <SelectTrigger aria-label="Fruit, aligned"><SelectValue /></SelectTrigger>\n <SelectContent alignItemWithTrigger>{Object.entries(fruits).map(([value, label]) => <SelectItem key={value} value={value}>{label}</SelectItem>)}</SelectContent>\n</Select>`}>
|
|
445
|
+
<Sample title="grouped" description={tz ? `Picked: ${zones[tz as keyof typeof zones]}` : 'Nothing picked yet'}>
|
|
446
|
+
<Select items={zones} value={tz} onValueChange={(value) => setTz(value as string | null)}>
|
|
447
|
+
<SelectTrigger aria-label="Time zone, grouped"><SelectValue placeholder="Choose a time zone" /></SelectTrigger>
|
|
448
|
+
<SelectContent>
|
|
449
|
+
<SelectGroup><SelectLabel>Europe</SelectLabel>{(['paris', 'london', 'lisbon'] as const).map((key) => <SelectItem key={key} value={key}>{zones[key]}</SelectItem>)}</SelectGroup>
|
|
450
|
+
<SelectSeparator />
|
|
451
|
+
<SelectGroup><SelectLabel>Americas</SelectLabel>{(['ny', 'sf'] as const).map((key) => <SelectItem key={key} value={key}>{zones[key]}</SelectItem>)}</SelectGroup>
|
|
452
|
+
</SelectContent>
|
|
453
|
+
</Select>
|
|
454
|
+
</Sample>
|
|
455
|
+
<Sample title="aligned with the trigger" description="alignItemWithTrigger">
|
|
456
|
+
<Select items={fruits} value={fruit} onValueChange={(value) => setFruit(value as string | null)}>
|
|
457
|
+
<SelectTrigger aria-label="Fruit, aligned"><SelectValue /></SelectTrigger>
|
|
458
|
+
<SelectContent alignItemWithTrigger>{Object.entries(fruits).map(([value, label]) => <SelectItem key={value} value={value}>{label}</SelectItem>)}</SelectContent>
|
|
459
|
+
</Select>
|
|
460
|
+
</Sample>
|
|
461
|
+
</Group>
|
|
462
|
+
</>
|
|
463
|
+
);
|
|
464
|
+
}
|
|
465
|
+
|
|
466
|
+
// ---------------------------------------------------------------------------------------------------------------
|
|
467
|
+
// Combobox and Picker
|
|
468
|
+
|
|
469
|
+
const cities = [
|
|
470
|
+
'Amsterdam', 'Athens', 'Barcelona', 'Berlin', 'Bordeaux', 'Brussels', 'Budapest', 'Copenhagen', 'Dublin', 'Édimbourg',
|
|
471
|
+
'Florence', 'Genève', 'Hamburg', 'Helsinki', 'Lisbon', 'London', 'Lyon', 'Madrid', 'Marseille', 'Milan', 'Munich',
|
|
472
|
+
'Nantes', 'Oslo', 'Paris', 'Porto', 'Prague', 'Reykjavík', 'Rome', 'Stockholm', 'Toulouse', 'Vienna', 'Warsaw', 'Zürich',
|
|
473
|
+
];
|
|
474
|
+
const same = (text: string) => text;
|
|
475
|
+
|
|
476
|
+
function ComboboxStory() {
|
|
477
|
+
const [city, setCity] = React.useState<string | null>('Lyon');
|
|
478
|
+
const [org, setOrg] = React.useState<string | null>(null);
|
|
479
|
+
const server = useFakeSearch(organizations, same);
|
|
480
|
+
return (
|
|
481
|
+
<>
|
|
482
|
+
<Group title="Sizes" description="As SelectTrigger: lg in forms, sm in property rows." layout="grid" code={`{(['sm', 'default', 'lg'] as const).map((size) => (\n <Combobox aria-label={\`City, \${size}\`} size={size} items={cities} value={city} onValueChange={setCity} itemToString={same} itemToKey={same} />\n))}`}>
|
|
483
|
+
{(['sm', 'default', 'lg'] as const).map((size) => (
|
|
484
|
+
<Sample key={size} title={size}>
|
|
485
|
+
<Combobox aria-label={`City, ${size}`} size={size} items={cities} value={city} onValueChange={setCity} itemToString={same} itemToKey={same} />
|
|
486
|
+
</Sample>
|
|
487
|
+
))}
|
|
488
|
+
</Group>
|
|
489
|
+
<Group title="States" layout="grid" code={`<Combobox aria-label="City, empty" items={cities} value={null} onValueChange={() => {}} itemToString={same} itemToKey={same} placeholder="Search a city…" />\n<Combobox aria-label="City, read-only" readOnly items={cities} value="Paris" onValueChange={() => {}} itemToString={same} itemToKey={same} />\n<Combobox aria-label="City, disabled" disabled items={cities} value="Oslo" onValueChange={() => {}} itemToString={same} itemToKey={same} />\n<Field invalid>\n <Combobox aria-label="City, invalid" items={cities} value={null} onValueChange={() => {}} itemToString={same} itemToKey={same} placeholder="Search a city…" />\n <FieldError>Choose a city</FieldError>\n</Field>\n<Combobox aria-label="Nothing to offer" items={[] as string[]} value={null} onValueChange={() => {}} itemToString={same} itemToKey={same} placeholder="Search a city…" emptyText="No cities in this region" />\n<Combobox aria-label="Loading" loading items={[] as string[]} value={null} onValueChange={() => {}} itemToString={same} itemToKey={same} placeholder="Search a city…" />`}>
|
|
490
|
+
<Sample title="placeholder"><Combobox aria-label="City, empty" items={cities} value={null} onValueChange={() => {}} itemToString={same} itemToKey={same} placeholder="Search a city…" /></Sample>
|
|
491
|
+
<Sample title="read-only"><Combobox aria-label="City, read-only" readOnly items={cities} value="Paris" onValueChange={() => {}} itemToString={same} itemToKey={same} /></Sample>
|
|
492
|
+
<Sample title="disabled"><Combobox aria-label="City, disabled" disabled items={cities} value="Oslo" onValueChange={() => {}} itemToString={same} itemToKey={same} /></Sample>
|
|
493
|
+
<Sample title="invalid">
|
|
494
|
+
<Field invalid>
|
|
495
|
+
<Combobox aria-label="City, invalid" items={cities} value={null} onValueChange={() => {}} itemToString={same} itemToKey={same} placeholder="Search a city…" />
|
|
496
|
+
<FieldError>Choose a city</FieldError>
|
|
497
|
+
</Field>
|
|
498
|
+
</Sample>
|
|
499
|
+
<Sample title="empty" description="No match: “No results”, or emptyText">
|
|
500
|
+
<Combobox aria-label="Nothing to offer" items={[] as string[]} value={null} onValueChange={() => {}} itemToString={same} itemToKey={same} placeholder="Search a city…" emptyText="No cities in this region" />
|
|
501
|
+
</Sample>
|
|
502
|
+
<Sample title="loading" description="Loading… while nothing is shown">
|
|
503
|
+
<Combobox aria-label="Loading" loading items={[] as string[]} value={null} onValueChange={() => {}} itemToString={same} itemToKey={same} placeholder="Search a city…" />
|
|
504
|
+
</Sample>
|
|
505
|
+
</Group>
|
|
506
|
+
<Group title="Examples" description="In a form, with a label and a hint." layout="columns" code={`<Field>\n <FieldLabel>City</FieldLabel>\n <Combobox items={cities} value={city} onValueChange={setCity} itemToString={same} itemToKey={same} placeholder="Search a city…" />\n <FieldDescription>{\`A local list; contains, any case or accent (try “zur”). Picked: \${city ?? 'none'}\`}</FieldDescription>\n</Field>\n<Field>\n <FieldLabel>Organization</FieldLabel>\n <Combobox\n items={server.items}\n loading={server.loading}\n filter={null}\n onInputChange={server.ask}\n value={org}\n onValueChange={setOrg}\n itemToString={same}\n itemToKey={same}\n placeholder="Search organizations…"\n emptyText="No organization matches"\n />\n <FieldDescription>{\`Searched on a fake server, 400 ms (try “wi”). Picked: \${org ?? 'none'}\`}</FieldDescription>\n</Field>`}>
|
|
507
|
+
<Field>
|
|
508
|
+
<FieldLabel>City</FieldLabel>
|
|
509
|
+
<Combobox items={cities} value={city} onValueChange={setCity} itemToString={same} itemToKey={same} placeholder="Search a city…" />
|
|
510
|
+
<FieldDescription>{`A local list; contains, any case or accent (try “zur”). Picked: ${city ?? 'none'}`}</FieldDescription>
|
|
511
|
+
</Field>
|
|
512
|
+
<Field>
|
|
513
|
+
<FieldLabel>Organization</FieldLabel>
|
|
514
|
+
<Combobox
|
|
515
|
+
items={server.items}
|
|
516
|
+
loading={server.loading}
|
|
517
|
+
filter={null}
|
|
518
|
+
onInputChange={server.ask}
|
|
519
|
+
value={org}
|
|
520
|
+
onValueChange={setOrg}
|
|
521
|
+
itemToString={same}
|
|
522
|
+
itemToKey={same}
|
|
523
|
+
placeholder="Search organizations…"
|
|
524
|
+
emptyText="No organization matches"
|
|
525
|
+
/>
|
|
526
|
+
<FieldDescription>{`Searched on a fake server, 400 ms (try “wi”). Picked: ${org ?? 'none'}`}</FieldDescription>
|
|
527
|
+
</Field>
|
|
528
|
+
</Group>
|
|
529
|
+
</>
|
|
530
|
+
);
|
|
531
|
+
}
|
|
532
|
+
|
|
533
|
+
interface Status { id: StatusIconStatus; label: string }
|
|
534
|
+
const statuses: Status[] = [
|
|
535
|
+
{ id: 'backlog', label: 'Backlog' }, { id: 'todo', label: 'Todo' }, { id: 'in-progress', label: 'In progress' },
|
|
536
|
+
{ id: 'in-review', label: 'In review' }, { id: 'done', label: 'Done' }, { id: 'cancelled', label: 'Cancelled' },
|
|
537
|
+
];
|
|
538
|
+
const statusProps = { items: statuses, itemToString: (each: Status) => each.label, itemToKey: (each: Status) => each.id, itemIcon: (each: Status) => <StatusIcon status={each.id} /> };
|
|
539
|
+
const projects = ['Website', 'Mobile app', 'Billing', 'Design system'];
|
|
540
|
+
interface Person { name: string }
|
|
541
|
+
const nobody: Person = { name: '' };
|
|
542
|
+
const everyone: Person[] = [nobody, ...people.map((name) => ({ name }))];
|
|
543
|
+
const personProps = {
|
|
544
|
+
itemToString: (each: Person) => each.name || 'Unassigned',
|
|
545
|
+
itemToKey: (each: Person) => each.name || 'none',
|
|
546
|
+
itemIcon: (each: Person) => (each.name ? <Avatar name={each.name} size="sm" tint /> : <Icon name="users" size={14} />),
|
|
547
|
+
};
|
|
548
|
+
|
|
549
|
+
function PickerStory() {
|
|
550
|
+
const { toast } = useToast();
|
|
551
|
+
const [status, setStatus] = React.useState<Status>(statuses[1]!);
|
|
552
|
+
const [project, setProject] = React.useState<string | null>('Design system');
|
|
553
|
+
const [owner, setOwner] = React.useState<Person>({ name: 'Ada Lindqvist' });
|
|
554
|
+
const server = useFakeSearch(everyone, (each) => each.name || 'Unassigned');
|
|
555
|
+
const [saving, setSaving] = React.useState<Status>(statuses[2]!);
|
|
556
|
+
return (
|
|
557
|
+
<>
|
|
558
|
+
<Group title="Sizes" description="The trigger is a property Button." layout="grid" code={`{(['sm', 'default'] as const).map((size) => (\n <Picker aria-label={\`Status \${size}\`} size={size} {...statusProps} value={status} onValueChange={setStatus} />\n))}`}>
|
|
559
|
+
{(['sm', 'default'] as const).map((size) => (
|
|
560
|
+
<Sample key={size} title={size}>
|
|
561
|
+
<Picker aria-label={`Status ${size}`} size={size} {...statusProps} value={status} onValueChange={setStatus} />
|
|
562
|
+
</Sample>
|
|
563
|
+
))}
|
|
564
|
+
</Group>
|
|
565
|
+
<Group title="States" layout="grid" code={`<Picker aria-label="Project" items={projects} value={null} onValueChange={() => {}} itemToString={same} itemToKey={same} placeholder="No project" />\n<Picker aria-label="Status, read-only" readOnly {...statusProps} value={statuses[4]!} onValueChange={() => {}} />\n<Picker aria-label="Status, disabled" disabled {...statusProps} value={statuses[0]!} onValueChange={() => {}} />\n<Picker aria-label="Owner, loading" loading filter={null} items={[] as Person[]} {...personProps} value={null} onValueChange={() => {}} placeholder="Unassigned" />\n<Picker aria-label="Label" items={[] as string[]} value={null} onValueChange={() => {}} itemToString={same} itemToKey={same} placeholder="No label" emptyText="No labels yet" />`}>
|
|
566
|
+
<Sample title="placeholder" description="value null: “None”, muted">
|
|
567
|
+
<Picker aria-label="Project" items={projects} value={null} onValueChange={() => {}} itemToString={same} itemToKey={same} placeholder="No project" />
|
|
568
|
+
</Sample>
|
|
569
|
+
<Sample title="read-only" description="Shows, never opens">
|
|
570
|
+
<Picker aria-label="Status, read-only" readOnly {...statusProps} value={statuses[4]!} onValueChange={() => {}} />
|
|
571
|
+
</Sample>
|
|
572
|
+
<Sample title="disabled"><Picker aria-label="Status, disabled" disabled {...statusProps} value={statuses[0]!} onValueChange={() => {}} /></Sample>
|
|
573
|
+
<Sample title="loading" description="Open it: Loading…">
|
|
574
|
+
<Picker aria-label="Owner, loading" loading filter={null} items={[] as Person[]} {...personProps} value={null} onValueChange={() => {}} placeholder="Unassigned" />
|
|
575
|
+
</Sample>
|
|
576
|
+
<Sample title="empty" description="Open it: the empty text">
|
|
577
|
+
<Picker aria-label="Label" items={[] as string[]} value={null} onValueChange={() => {}} itemToString={same} itemToKey={same} placeholder="No label" emptyText="No labels yet" />
|
|
578
|
+
</Sample>
|
|
579
|
+
</Group>
|
|
580
|
+
<Group title="Examples" description="Open a pill, then type to search, ↑ ↓ and Enter, or press a digit." layout="grid" code={`<Picker aria-label="Status" {...statusProps} value={status} onValueChange={setStatus} searchPlaceholder="Change status…" />\n<Picker aria-label="Project, short" items={projects} value={project} onValueChange={setProject} itemToString={same} itemToKey={same} itemIcon={() => <Icon name="folder" size={14} />} placeholder="No project" />\n<Picker\n aria-label="Owner"\n {...personProps}\n items={server.items}\n loading={server.loading}\n filter={null}\n onInputChange={server.ask}\n value={owner}\n onValueChange={setOwner}\n searchPlaceholder="Assign to…"\n emptyText="Nobody matches"\n/>\n<Picker\n aria-label="Status, saved"\n {...statusProps}\n value={saving}\n onValueChange={(next) => new Promise<void>((done) => setTimeout(() => {\n setSaving(next);\n toast({ title: \`Status set to \${next.label}\`, variant: 'success' });\n done();\n }, 800))}\n/>`}>
|
|
581
|
+
<Sample title="status, by digit" description={`1–9 then 0 pick (try 3). Now: ${status.label}`}>
|
|
582
|
+
<Picker aria-label="Status" {...statusProps} value={status} onValueChange={setStatus} searchPlaceholder="Change status…" />
|
|
583
|
+
</Sample>
|
|
584
|
+
<Sample title="a short list" description="5 or fewer: no search row, the list takes the focus">
|
|
585
|
+
<Picker aria-label="Project, short" items={projects} value={project} onValueChange={setProject} itemToString={same} itemToKey={same} itemIcon={() => <Icon name="folder" size={14} />} placeholder="No project" />
|
|
586
|
+
</Sample>
|
|
587
|
+
<Sample title="searched on the server" description={'A fake server answers after 400 ms; try “ma”'}>
|
|
588
|
+
<Picker
|
|
589
|
+
aria-label="Owner"
|
|
590
|
+
{...personProps}
|
|
591
|
+
items={server.items}
|
|
592
|
+
loading={server.loading}
|
|
593
|
+
filter={null}
|
|
594
|
+
onInputChange={server.ask}
|
|
595
|
+
value={owner}
|
|
596
|
+
onValueChange={setOwner}
|
|
597
|
+
searchPlaceholder="Assign to…"
|
|
598
|
+
emptyText="Nobody matches"
|
|
599
|
+
/>
|
|
600
|
+
</Sample>
|
|
601
|
+
<Sample title="an async save" description="The pick shows while it saves (800 ms)">
|
|
602
|
+
<Picker
|
|
603
|
+
aria-label="Status, saved"
|
|
604
|
+
{...statusProps}
|
|
605
|
+
value={saving}
|
|
606
|
+
onValueChange={(next) => new Promise<void>((done) => setTimeout(() => {
|
|
607
|
+
setSaving(next);
|
|
608
|
+
toast({ title: `Status set to ${next.label}`, variant: 'success' });
|
|
609
|
+
done();
|
|
610
|
+
}, 800))}
|
|
611
|
+
/>
|
|
612
|
+
</Sample>
|
|
613
|
+
</Group>
|
|
614
|
+
<Group title="On a detail card" description="Pickers in property rows, as Linear's." layout="fill" code={`<Properties className="ds-control-wide">\n <PropertyRow label="Status"><Picker aria-label="Status, card" {...statusProps} value={status} onValueChange={setStatus} /></PropertyRow>\n <PropertyRow label="Owner"><Picker aria-label="Owner, card" {...personProps} items={server.items} loading={server.loading} filter={null} onInputChange={server.ask} value={owner} onValueChange={setOwner} searchPlaceholder="Assign to…" /></PropertyRow>\n <PropertyRow label="Project"><Picker aria-label="Project, card" items={projects} value={project} onValueChange={setProject} itemToString={same} itemToKey={same} itemIcon={() => <Icon name="folder" size={14} />} placeholder="No project" /></PropertyRow>\n</Properties>`}>
|
|
615
|
+
<Properties className="ds-control-wide">
|
|
616
|
+
<PropertyRow label="Status"><Picker aria-label="Status, card" {...statusProps} value={status} onValueChange={setStatus} /></PropertyRow>
|
|
617
|
+
<PropertyRow label="Owner"><Picker aria-label="Owner, card" {...personProps} items={server.items} loading={server.loading} filter={null} onInputChange={server.ask} value={owner} onValueChange={setOwner} searchPlaceholder="Assign to…" /></PropertyRow>
|
|
618
|
+
<PropertyRow label="Project"><Picker aria-label="Project, card" items={projects} value={project} onValueChange={setProject} itemToString={same} itemToKey={same} itemIcon={() => <Icon name="folder" size={14} />} placeholder="No project" /></PropertyRow>
|
|
619
|
+
</Properties>
|
|
620
|
+
</Group>
|
|
621
|
+
</>
|
|
622
|
+
);
|
|
623
|
+
}
|
|
624
|
+
|
|
625
|
+
function PromptFieldStory() {
|
|
626
|
+
const [draft, setDraft] = React.useState('');
|
|
627
|
+
const [sent, setSent] = React.useState<readonly string[]>([]);
|
|
628
|
+
const send = () => {
|
|
629
|
+
if (!draft.trim()) return;
|
|
630
|
+
setSent((before) => [...before, draft.trim()]);
|
|
631
|
+
setDraft('');
|
|
632
|
+
};
|
|
633
|
+
return (
|
|
634
|
+
<>
|
|
635
|
+
<Group title="Examples" description="Enter sends, Shift+Enter starts a new line; Send stays off while the field is blank." layout="stack" code={`<div className="ds-checklist">\n {sent.map((message, index) => <p key={index}>{message}</p>)}\n <PromptField value={draft} onValueChange={setDraft} onSubmit={send} placeholder="Ask anything…" aria-label="Message" />\n</div>`}>
|
|
636
|
+
<Sample title="a session's prompt" wide>
|
|
637
|
+
<div className="ds-checklist">
|
|
638
|
+
{sent.map((message, index) => <p key={index}>{message}</p>)}
|
|
639
|
+
<PromptField value={draft} onValueChange={setDraft} onSubmit={send} placeholder="Ask anything…" aria-label="Message" />
|
|
640
|
+
</div>
|
|
641
|
+
</Sample>
|
|
642
|
+
</Group>
|
|
643
|
+
<Group title="States" layout="grid" code={`<PromptField value="Summarize the last meeting" onValueChange={() => {}} onSubmit={() => {}} disabled aria-label="Disabled message" />`}>
|
|
644
|
+
<Sample title="disabled" description="While the agent answers">
|
|
645
|
+
<PromptField value="Summarize the last meeting" onValueChange={() => {}} onSubmit={() => {}} disabled aria-label="Disabled message" />
|
|
646
|
+
</Sample>
|
|
647
|
+
</Group>
|
|
648
|
+
</>
|
|
649
|
+
);
|
|
650
|
+
}
|
|
651
|
+
|
|
652
|
+
// ---------------------------------------------------------------------------------------------------------------
|
|
653
|
+
// Editable field
|
|
654
|
+
|
|
655
|
+
function EditableFieldStory() {
|
|
656
|
+
const [value, setValue] = React.useState('Ada Lindqvist');
|
|
657
|
+
const [state, setState] = React.useState<EditableFieldState>('idle');
|
|
658
|
+
const noop = () => {};
|
|
659
|
+
const frozen = (state: EditableFieldState, extra: Partial<React.ComponentProps<typeof EditableField>> = {}) => (
|
|
660
|
+
<EditableField aria-label={state} value="Ada Lindqvist" onChange={noop} state={state} {...extra} />
|
|
661
|
+
);
|
|
662
|
+
return (
|
|
663
|
+
<>
|
|
664
|
+
<Group title="States" description="The status sits at the right of the field." code={`{frozen('idle')}\n{frozen('saving')}\n{frozen('saved')}\n{frozen('failed', { error: 'The server did not answer' })}\n{frozen('conflict', { theirs: 'Ada Lovelace' })}\n{frozen('idle', { changedElsewhere: true })}\n<EditableField aria-label="Invalid" value="" placeholder="A name is needed" onChange={noop} invalid />`}>
|
|
665
|
+
<Sample title="idle">{frozen('idle')}</Sample>
|
|
666
|
+
<Sample title="saving">{frozen('saving')}</Sample>
|
|
667
|
+
<Sample title="saved" description="Fades after a moment">{frozen('saved')}</Sample>
|
|
668
|
+
<Sample title="failed" description="Retry, or discard">{frozen('failed', { error: 'The server did not answer' })}</Sample>
|
|
669
|
+
<Sample title="conflict" description="Keep mine, or take theirs">{frozen('conflict', { theirs: 'Ada Lovelace' })}</Sample>
|
|
670
|
+
<Sample title="changed elsewhere">{frozen('idle', { changedElsewhere: true })}</Sample>
|
|
671
|
+
<Sample title="invalid"><EditableField aria-label="Invalid" value="" placeholder="A name is needed" onChange={noop} invalid /></Sample>
|
|
672
|
+
</Group>
|
|
673
|
+
<Group title="Variants" code={`<EditableField aria-label="Property" value="ada@northwind.example" onChange={noop} />\n<EditableField aria-label="Title" variant="title" value="Ada Lindqvist" onChange={noop} />\n<EditableField aria-label="Subtitle" variant="subtitle" value="Head of design" onChange={noop} />\n<EditableField aria-label="Notes" multiline value={'Met at the fair.\\nSends news in June.'} onChange={noop} />`}>
|
|
674
|
+
<Sample title="property" description="The default"><EditableField aria-label="Property" value="ada@northwind.example" onChange={noop} /></Sample>
|
|
675
|
+
<Sample title="title"><EditableField aria-label="Title" variant="title" value="Ada Lindqvist" onChange={noop} /></Sample>
|
|
676
|
+
<Sample title="subtitle"><EditableField aria-label="Subtitle" variant="subtitle" value="Head of design" onChange={noop} /></Sample>
|
|
677
|
+
<Sample title="multiline" description="Cmd or Ctrl+Enter commits"><EditableField aria-label="Notes" multiline value={'Met at the fair.\nSends news in June.'} onChange={noop} /></Sample>
|
|
678
|
+
</Group>
|
|
679
|
+
<Group title="Fit" description="As wide as its text; the status follows it. InlineFields lays several on a line." code={`<InlineFields>\n <EditableField aria-label="First name" fit variant="title" value="Ada" onChange={noop} state="saved" />\n <EditableField aria-label="Last name" fit variant="title" value="Lindqvist" onChange={noop} />\n</InlineFields>`}>
|
|
680
|
+
<Sample title="fit" wide>
|
|
681
|
+
<InlineFields>
|
|
682
|
+
<EditableField aria-label="First name" fit variant="title" value="Ada" onChange={noop} state="saved" />
|
|
683
|
+
<EditableField aria-label="Last name" fit variant="title" value="Lindqvist" onChange={noop} />
|
|
684
|
+
</InlineFields>
|
|
685
|
+
</Sample>
|
|
686
|
+
</Group>
|
|
687
|
+
<Group title="Examples" description="Edit, then Enter or blur to commit; Esc reverts. The save takes a second." code={`<EditableField\n aria-label="Name"\n value={value}\n state={state}\n onChange={(text) => { setValue(text); setState('idle'); }}\n onCommit={() => { setState('saving'); setTimeout(() => setState('saved'), 800); }}\n onRevert={() => { setValue('Ada Lindqvist'); setState('idle'); }}\n/>`}>
|
|
688
|
+
<Sample title="working">
|
|
689
|
+
<EditableField
|
|
690
|
+
aria-label="Name"
|
|
691
|
+
value={value}
|
|
692
|
+
state={state}
|
|
693
|
+
onChange={(text) => { setValue(text); setState('idle'); }}
|
|
694
|
+
onCommit={() => { setState('saving'); setTimeout(() => setState('saved'), 800); }}
|
|
695
|
+
onRevert={() => { setValue('Ada Lindqvist'); setState('idle'); }}
|
|
696
|
+
/>
|
|
697
|
+
</Sample>
|
|
698
|
+
</Group>
|
|
699
|
+
</>
|
|
700
|
+
);
|
|
701
|
+
}
|
|
702
|
+
|
|
703
|
+
// ---------------------------------------------------------------------------------------------------------------
|
|
704
|
+
// Pick menu and tag menu
|
|
705
|
+
|
|
706
|
+
const pickBase: PickOption[] = [
|
|
707
|
+
{ key: 'none', label: 'No organization', none: true },
|
|
708
|
+
{ key: 'northwind', label: 'Northwind', note: 'northwind.example', icon: <Avatar name="Northwind" size="xs" tint /> },
|
|
709
|
+
{ key: 'windmill', label: 'Windmill Labs', note: 'windmill.example', icon: <Avatar name="Windmill Labs" size="xs" tint /> },
|
|
710
|
+
{ key: 'acme', label: 'Acme', note: 'acme.example', icon: <Avatar name="Acme" size="xs" tint /> },
|
|
711
|
+
{ key: 'tessera', label: 'Tessera', icon: <Avatar name="Tessera" size="xs" tint /> },
|
|
712
|
+
];
|
|
713
|
+
|
|
714
|
+
function PickMenuStory() {
|
|
715
|
+
const [anchor, setAnchor] = React.useState<HTMLButtonElement | null>(null);
|
|
716
|
+
const [open, setOpen] = React.useState(false);
|
|
717
|
+
const [picked, setPicked] = React.useState('northwind');
|
|
718
|
+
const [multiAnchor, setMultiAnchor] = React.useState<HTMLButtonElement | null>(null);
|
|
719
|
+
const [multiOpen, setMultiOpen] = React.useState(false);
|
|
720
|
+
const [many, setMany] = React.useState<ReadonlySet<string>>(new Set(['acme']));
|
|
721
|
+
const [options, setOptions] = React.useState(pickBase.filter((each) => !each.none));
|
|
722
|
+
const [kind, setKind] = React.useState('work');
|
|
723
|
+
return (
|
|
724
|
+
<>
|
|
725
|
+
<Group title="Variants" description="Type to filter, 1-9 (0 for none) to pick while nothing is typed, Enter and arrows, Esc to close." code={`<DataMenuTrigger ref={setAnchor} aria-haspopup="listbox" aria-expanded={open} onClick={() => setOpen(true)}>\n <Icon name="building-2" size={14} />{pickBase.find((each) => each.key === picked)?.label}\n</DataMenuTrigger>\n<PickMenu\n open={open} onOpenChange={setOpen} anchor={anchor} aria-label="Organization"\n options={pickBase.map((each) => ({ ...each, checked: each.key === picked }))}\n onPick={(option) => setPicked(option.key)}\n footer="Enter picks · Esc closes"\n/>\n<DataMenuTrigger ref={setMultiAnchor} aria-haspopup="listbox" aria-expanded={multiOpen} onClick={() => setMultiOpen(true)}>\n <Icon name="building-2" size={14} />{many.size} selected\n</DataMenuTrigger>\n<PickMenu\n multiple open={multiOpen} onOpenChange={setMultiOpen} anchor={multiAnchor} aria-label="Organizations"\n options={options.map((each) => ({ ...each, checked: many.has(each.key) }))}\n onPick={(option) => setMany((current) => { const next = new Set(current); if (!next.delete(option.key)) next.add(option.key); return next; })}\n onCreate={(text) => { const key = text.toLowerCase(); setOptions((current) => [...current, { key, label: text }]); setMany((current) => new Set(current).add(key)); }}\n placeholder="Find or add…"\n footer="Enter toggles · stays open · Esc closes"\n/>\n<PickSelect\n aria-label="Kind" value={kind} onChange={setKind}\n options={[{ key: 'work', label: 'Work' }, { key: 'home', label: 'Home' }, { key: 'other', label: 'Other' }]}\n/>\n<DataMenuTrigger empty><Icon name="plus" size={14} />Set organization</DataMenuTrigger>`}>
|
|
726
|
+
<Sample title="single" description="Opens on its checked option">
|
|
727
|
+
<DataMenuTrigger ref={setAnchor} aria-haspopup="listbox" aria-expanded={open} onClick={() => setOpen(true)}>
|
|
728
|
+
<Icon name="building-2" size={14} />{pickBase.find((each) => each.key === picked)?.label}
|
|
729
|
+
</DataMenuTrigger>
|
|
730
|
+
<PickMenu
|
|
731
|
+
open={open} onOpenChange={setOpen} anchor={anchor} aria-label="Organization"
|
|
732
|
+
options={pickBase.map((each) => ({ ...each, checked: each.key === picked }))}
|
|
733
|
+
onPick={(option) => setPicked(option.key)}
|
|
734
|
+
footer="Enter picks · Esc closes"
|
|
735
|
+
/>
|
|
736
|
+
</Sample>
|
|
737
|
+
<Sample title="multiple, with Create" description="Checkboxes; it stays open; a new text offers Create">
|
|
738
|
+
<DataMenuTrigger ref={setMultiAnchor} aria-haspopup="listbox" aria-expanded={multiOpen} onClick={() => setMultiOpen(true)}>
|
|
739
|
+
<Icon name="building-2" size={14} />{many.size} selected
|
|
740
|
+
</DataMenuTrigger>
|
|
741
|
+
<PickMenu
|
|
742
|
+
multiple open={multiOpen} onOpenChange={setMultiOpen} anchor={multiAnchor} aria-label="Organizations"
|
|
743
|
+
options={options.map((each) => ({ ...each, checked: many.has(each.key) }))}
|
|
744
|
+
onPick={(option) => setMany((current) => { const next = new Set(current); if (!next.delete(option.key)) next.add(option.key); return next; })}
|
|
745
|
+
onCreate={(text) => { const key = text.toLowerCase(); setOptions((current) => [...current, { key, label: text }]); setMany((current) => new Set(current).add(key)); }}
|
|
746
|
+
placeholder="Find or add…"
|
|
747
|
+
footer="Enter toggles · stays open · Esc closes"
|
|
748
|
+
/>
|
|
749
|
+
</Sample>
|
|
750
|
+
<Sample title="PickSelect" description="One value among a few, with its trigger">
|
|
751
|
+
<PickSelect
|
|
752
|
+
aria-label="Kind" value={kind} onChange={setKind}
|
|
753
|
+
options={[{ key: 'work', label: 'Work' }, { key: 'home', label: 'Home' }, { key: 'other', label: 'Other' }]}
|
|
754
|
+
/>
|
|
755
|
+
</Sample>
|
|
756
|
+
<Sample title="empty trigger"><DataMenuTrigger empty><Icon name="plus" size={14} />Set organization</DataMenuTrigger></Sample>
|
|
757
|
+
</Group>
|
|
758
|
+
</>
|
|
759
|
+
);
|
|
760
|
+
}
|
|
761
|
+
|
|
762
|
+
const knownTags = [{ value: 'client', count: 12 }, { value: 'lead', count: 7 }, { value: 'partner', count: 3 }];
|
|
763
|
+
|
|
764
|
+
function TagMenuStory() {
|
|
765
|
+
const [anchor, setAnchor] = React.useState<HTMLButtonElement | null>(null);
|
|
766
|
+
const [open, setOpen] = React.useState(false);
|
|
767
|
+
const [tags, setTags] = React.useState(['client']);
|
|
768
|
+
const toggle = (tag: string) => setTags((current) => (
|
|
769
|
+
current.some((each) => each.toLowerCase() === tag.toLowerCase())
|
|
770
|
+
? current.filter((each) => each.toLowerCase() !== tag.toLowerCase())
|
|
771
|
+
: [...current, tag]
|
|
772
|
+
));
|
|
773
|
+
return (
|
|
774
|
+
<Group title="Examples" description="The known tags with their counts, the record's checked; type a new one to Create it." code={`<TagList aria-label="Tags">\n {tags.map((tag) => <TagPill key={tag} name={tag} />)}\n <DataMenuTrigger ref={setAnchor} aria-label="Edit tags" aria-haspopup="listbox" aria-expanded={open} onClick={() => setOpen(true)}>\n <Icon name="plus" size={14} />\n </DataMenuTrigger>\n</TagList>\n<TagMenu open={open} onOpenChange={setOpen} anchor={anchor} value={tags} onToggle={toggle} load={async () => knownTags} />\n{knownTags.map((tag) => <TagDot key={tag.value} name={tag.value} />)}`}>
|
|
775
|
+
<Sample title="tags of a record">
|
|
776
|
+
<TagList aria-label="Tags">
|
|
777
|
+
{tags.map((tag) => <TagPill key={tag} name={tag} />)}
|
|
778
|
+
<DataMenuTrigger ref={setAnchor} aria-label="Edit tags" aria-haspopup="listbox" aria-expanded={open} onClick={() => setOpen(true)}>
|
|
779
|
+
<Icon name="plus" size={14} />
|
|
780
|
+
</DataMenuTrigger>
|
|
781
|
+
</TagList>
|
|
782
|
+
<TagMenu open={open} onOpenChange={setOpen} anchor={anchor} value={tags} onToggle={toggle} load={async () => knownTags} />
|
|
783
|
+
</Sample>
|
|
784
|
+
<Sample title="a tag's dot">{knownTags.map((tag) => <TagDot key={tag.value} name={tag.value} />)}</Sample>
|
|
785
|
+
</Group>
|
|
786
|
+
);
|
|
787
|
+
}
|
|
788
|
+
|
|
789
|
+
function DropZoneStory() {
|
|
790
|
+
const zone = React.useRef<DropZoneHandle>(null);
|
|
791
|
+
const [files, setFiles] = React.useState<string[]>([]);
|
|
792
|
+
const take = (picked: File[]) => setFiles(picked.map((file) => file.name));
|
|
793
|
+
return (
|
|
794
|
+
<>
|
|
795
|
+
<Group title="Examples" description="Drag files over the zone: an overlay says what a drop does. The button opens the system picker." layout="stack" code={`<DropZone ref={zone} accept="image/*" onFiles={take} className="rounded-default border border-dashed border-border p-3">\n <Button onClick={() => zone.current?.open()}>Choose images…</Button>\n <p className="text-xs text-muted">{files.length === 0 ? 'Or drop them here.' : files.join(', ')}</p>\n</DropZone>\n<DropZone disabled onFiles={take} className="rounded-default border border-dashed border-border p-3">\n <p className="text-xs text-muted">Uploads are off.</p>\n</DropZone>`}>
|
|
796
|
+
<Sample title="images, with a picker" wide>
|
|
797
|
+
<DropZone ref={zone} accept="image/*" onFiles={take} className="rounded-default border border-dashed border-border p-3">
|
|
798
|
+
<Button onClick={() => zone.current?.open()}>Choose images…</Button>
|
|
799
|
+
<p className="text-xs text-muted">{files.length === 0 ? 'Or drop them here.' : files.join(', ')}</p>
|
|
800
|
+
</DropZone>
|
|
801
|
+
</Sample>
|
|
802
|
+
<Sample title="disabled" description="Ignores drags and the picker" wide>
|
|
803
|
+
<DropZone disabled onFiles={take} className="rounded-default border border-dashed border-border p-3">
|
|
804
|
+
<p className="text-xs text-muted">Uploads are off.</p>
|
|
805
|
+
</DropZone>
|
|
806
|
+
</Sample>
|
|
807
|
+
</Group>
|
|
808
|
+
</>
|
|
809
|
+
);
|
|
810
|
+
}
|
|
811
|
+
|
|
812
|
+
function ToggleGroupStory() {
|
|
813
|
+
const [days, setDays] = React.useState<string[]>(['1', '3']);
|
|
814
|
+
const week = [['1', 'M', 'Monday'], ['2', 'T', 'Tuesday'], ['3', 'W', 'Wednesday'], ['4', 'T', 'Thursday'], ['5', 'F', 'Friday'], ['6', 'S', 'Saturday'], ['7', 'S', 'Sunday']]
|
|
815
|
+
.map(([value, label, title]) => ({ value: value!, label: label!, title }));
|
|
816
|
+
return (
|
|
817
|
+
<>
|
|
818
|
+
<Group title="Examples" description="Any number pressed at once; arrow keys move, Space toggles." code={`<ToggleGroup aria-label="Days" items={week} value={days} onValueChange={setDays} />`}>
|
|
819
|
+
<Sample title="weekdays" description={`${days.length} pressed`}>
|
|
820
|
+
<ToggleGroup aria-label="Days" items={week} value={days} onValueChange={setDays} />
|
|
821
|
+
</Sample>
|
|
822
|
+
</Group>
|
|
823
|
+
</>
|
|
824
|
+
);
|
|
825
|
+
}
|
|
826
|
+
|
|
827
|
+
function ImageFieldStory() {
|
|
828
|
+
const [image, setImage] = React.useState<{ name: string; size: number; url: string } | null>(null);
|
|
829
|
+
const upload = (file: File) => new Promise<{ name: string; size: number; url: string }>((resolve, reject) => {
|
|
830
|
+
const reader = new FileReader();
|
|
831
|
+
reader.onload = () => resolve({ name: file.name, size: file.size, url: String(reader.result) });
|
|
832
|
+
reader.onerror = () => reject(new Error('Could not read the image'));
|
|
833
|
+
reader.readAsDataURL(file);
|
|
834
|
+
});
|
|
835
|
+
return (
|
|
836
|
+
<Group title="Example" description="Choose or drop an image, then replace or remove it." layout="stack" code={`<div className="ds-control-wide">\n <ImageField label="Illustration" value={image} upload={upload} viewUrl={async (value) => value.url} onChange={setImage} />\n</div>`}>
|
|
837
|
+
<Sample title="article illustration" wide>
|
|
838
|
+
<div className="ds-control-wide">
|
|
839
|
+
<ImageField label="Illustration" value={image} upload={upload} viewUrl={async (value) => value.url} onChange={setImage} />
|
|
840
|
+
</div>
|
|
841
|
+
</Sample>
|
|
842
|
+
</Group>
|
|
843
|
+
);
|
|
844
|
+
}
|
|
845
|
+
|
|
846
|
+
export const input = { 'drop-zone': DropZoneStory, 'toggle-group': ToggleGroupStory,
|
|
847
|
+
'image-field': ImageFieldStory,
|
|
848
|
+
'editable-field': EditableFieldStory, 'pick-menu': PickMenuStory, 'tag-menu': TagMenuStory,
|
|
849
|
+
checkbox: CheckboxStory, combobox: ComboboxStory, field: FieldStory, input: InputStory, picker: PickerStory, 'prompt-field': PromptFieldStory,
|
|
850
|
+
'segment-group': SegmentGroupStory, select: SelectStory, slider: SliderStory, 'colour-picker': ColourPickerStory, 'tag-input': TagInputStory, textarea: TextareaStory, toggle: ToggleStory,
|
|
851
|
+
};
|