@sybilion/uilib 1.4.20 → 1.4.21

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.
@@ -0,0 +1,590 @@
1
+ import { useState } from 'react';
2
+
3
+ import { Button } from '#uilib/components/ui/Button';
4
+ import { ButtonGroup } from '#uilib/components/ui/ButtonGroup';
5
+ import { Checkbox } from '#uilib/components/ui/Checkbox';
6
+ import { DropZone } from '#uilib/components/ui/DropZone/DropZone';
7
+ import { Input } from '#uilib/components/ui/Input';
8
+ import { Label } from '#uilib/components/ui/Label';
9
+ import { LabelWithId } from '#uilib/components/ui/LabelWithId';
10
+ import { LabeledInput } from '#uilib/components/ui/LabeledInput/LabeledInput';
11
+ import { MobileAdaptiveSelector } from '#uilib/components/ui/MobileAdaptiveSelector';
12
+ import { NumberControl } from '#uilib/components/ui/NumberControl';
13
+ import { PageContentSection } from '#uilib/components/ui/Page';
14
+ import { RegionSelector } from '#uilib/components/ui/RegionCoords';
15
+ import { Renamer } from '#uilib/components/ui/Renamer';
16
+ import {
17
+ Select,
18
+ SelectContent,
19
+ SelectItem,
20
+ SelectTrigger,
21
+ SelectValue,
22
+ } from '#uilib/components/ui/Select';
23
+ import { Slider } from '#uilib/components/ui/Slider';
24
+ import { Switch } from '#uilib/components/ui/Switch';
25
+ import { TimeRangeControls } from '#uilib/components/ui/TimeRangeControls';
26
+ import { ToggleGroup, ToggleGroupItem } from '#uilib/components/ui/ToggleGroup';
27
+
28
+ import { AppPageHeader } from '../components/AppPageHeader/AppPageHeader';
29
+ import { DocsHeaderActions } from '../docsHeaderActions';
30
+
31
+ const FRUIT_OPTIONS = [
32
+ { value: 'apple', label: 'Apple' },
33
+ { value: 'orange', label: 'Orange' },
34
+ { value: 'banana', label: 'Banana' },
35
+ ] as const;
36
+
37
+ const ROLE_OPTIONS = [
38
+ { value: 'viewer', label: 'Viewer' },
39
+ { value: 'editor', label: 'Editor' },
40
+ { value: 'admin', label: 'Admin' },
41
+ ] as const;
42
+
43
+ const MOBILE_SELECTOR_ITEMS = [
44
+ { value: 'a', label: 'Alpha' },
45
+ { value: 'b', label: 'Beta' },
46
+ { value: 'c', label: 'Gamma' },
47
+ ] as const;
48
+
49
+ const REGION_COORDS = {
50
+ NYC: { longitude: -74.006, latitude: 40.7128 },
51
+ London: { longitude: -0.1276, latitude: 51.5074 },
52
+ } as const;
53
+
54
+ const SLIDER_WIDTH = 280;
55
+ const FIELD_WIDTH = 280;
56
+
57
+ const stateLabelStyle: React.CSSProperties = {
58
+ marginBottom: '0.5rem',
59
+ fontSize: 13,
60
+ fontWeight: 600,
61
+ color: 'var(--muted-foreground)',
62
+ textTransform: 'uppercase',
63
+ letterSpacing: '0.04em',
64
+ };
65
+
66
+ const twoColumnStyle: React.CSSProperties = {
67
+ display: 'grid',
68
+ gridTemplateColumns: 'repeat(auto-fit, minmax(240px, 1fr))',
69
+ gap: '1.5rem',
70
+ };
71
+
72
+ const panelStyle: React.CSSProperties = {
73
+ display: 'flex',
74
+ flexDirection: 'column',
75
+ gap: '0.75rem',
76
+ padding: 'var(--p-3)',
77
+ borderRadius: 'var(--radius-3)',
78
+ };
79
+
80
+ function DemoSelect({
81
+ disabled = false,
82
+ defaultValue,
83
+ placeholder = 'Pick fruit',
84
+ }: {
85
+ disabled?: boolean;
86
+ defaultValue?: string;
87
+ placeholder?: string;
88
+ }) {
89
+ return (
90
+ <Select defaultValue={defaultValue}>
91
+ <SelectTrigger disabled={disabled} style={{ width: FIELD_WIDTH }}>
92
+ <SelectValue placeholder={placeholder} />
93
+ </SelectTrigger>
94
+ <SelectContent>
95
+ {FRUIT_OPTIONS.map(o => (
96
+ <SelectItem key={o.value} value={o.value}>
97
+ {o.label}
98
+ </SelectItem>
99
+ ))}
100
+ </SelectContent>
101
+ </Select>
102
+ );
103
+ }
104
+
105
+ export default function FormsOverviewPage() {
106
+ const [sliderValue, setSliderValue] = useState([40]);
107
+ const [toggleValue, setToggleValue] = useState('day');
108
+ const [numberValue, setNumberValue] = useState(2);
109
+ const [labeledValue, setLabeledValue] = useState('Sybilion');
110
+ const [period, setPeriod] = useState('week');
111
+ const [composedName, setComposedName] = useState('Alex Morgan');
112
+ const [composedEmail, setComposedEmail] = useState('alex@example.com');
113
+ const [composedRole, setComposedRole] = useState('editor');
114
+ const [composedNotifications, setComposedNotifications] = useState(true);
115
+ const [composedTerms, setComposedTerms] = useState(false);
116
+ const [dropZoneName, setDropZoneName] = useState<string | null>(null);
117
+ const [mobileSelectorValue, setMobileSelectorValue] = useState('a');
118
+ const [regionPick, setRegionPick] = useState<string | null>(null);
119
+ const [renamerValue, setRenamerValue] = useState('Dataset name');
120
+ const [timeRange, setTimeRange] = useState('1y');
121
+
122
+ return (
123
+ <>
124
+ <AppPageHeader
125
+ breadcrumbs={[{ label: 'Overview' }]}
126
+ title="Overview"
127
+ subheader="Composition of form inputs and actions."
128
+ actions={<DocsHeaderActions />}
129
+ />
130
+ <PageContentSection
131
+ style={{ display: 'flex', flexDirection: 'column', gap: '2.5rem' }}
132
+ >
133
+ <section>
134
+ <h3 style={{ marginBottom: '1rem' }}>Text input</h3>
135
+ <div style={twoColumnStyle}>
136
+ <div style={panelStyle}>
137
+ <p style={stateLabelStyle}>Default</p>
138
+ <Input placeholder="Enter text" style={{ width: FIELD_WIDTH }} />
139
+ <Input
140
+ type="textarea"
141
+ placeholder="Enter description"
142
+ rows={3}
143
+ style={{ width: FIELD_WIDTH }}
144
+ />
145
+ </div>
146
+ <div style={panelStyle}>
147
+ <p style={stateLabelStyle}>Disabled</p>
148
+ <Input
149
+ disabled
150
+ placeholder="Enter text"
151
+ style={{ width: FIELD_WIDTH }}
152
+ />
153
+ <Input
154
+ type="textarea"
155
+ disabled
156
+ placeholder="Enter description"
157
+ rows={3}
158
+ style={{ width: FIELD_WIDTH }}
159
+ />
160
+ </div>
161
+ </div>
162
+ </section>
163
+
164
+ <section>
165
+ <h3 style={{ marginBottom: '1rem' }}>Label</h3>
166
+ <div style={panelStyle}>
167
+ <Label htmlFor="forms-label-demo">Example label</Label>
168
+ </div>
169
+ </section>
170
+
171
+ <section>
172
+ <h3 style={{ marginBottom: '1rem' }}>LabelWithId</h3>
173
+ <div style={panelStyle}>
174
+ <LabelWithId id={42} label="Analysis label" />
175
+ </div>
176
+ </section>
177
+
178
+ <section>
179
+ <h3 style={{ marginBottom: '1rem' }}>LabeledInput</h3>
180
+ <div style={twoColumnStyle}>
181
+ <div style={panelStyle}>
182
+ <p style={stateLabelStyle}>Default</p>
183
+ <LabeledInput
184
+ id="forms-labeled-default"
185
+ name="labeled-default"
186
+ label="Account name"
187
+ value={labeledValue}
188
+ onChange={e => setLabeledValue(e.target.value)}
189
+ placeholder="Value"
190
+ />
191
+ </div>
192
+ <div style={panelStyle}>
193
+ <p style={stateLabelStyle}>Disabled</p>
194
+ <LabeledInput
195
+ id="forms-labeled-disabled"
196
+ name="labeled-disabled"
197
+ label="Account name"
198
+ value="Sybilion"
199
+ onChange={() => {}}
200
+ placeholder="Value"
201
+ disabled
202
+ />
203
+ </div>
204
+ </div>
205
+ </section>
206
+
207
+ <section>
208
+ <h3 style={{ marginBottom: '1rem' }}>Checkbox</h3>
209
+ <div style={twoColumnStyle}>
210
+ <div style={panelStyle}>
211
+ <p style={stateLabelStyle}>Default</p>
212
+ <div
213
+ style={{ display: 'flex', alignItems: 'center', gap: '0.5rem' }}
214
+ >
215
+ <Checkbox id="forms-cb-default" defaultChecked />
216
+ <Label htmlFor="forms-cb-default">Accept terms</Label>
217
+ </div>
218
+ <div
219
+ style={{ display: 'flex', alignItems: 'center', gap: '0.5rem' }}
220
+ >
221
+ <Checkbox id="forms-cb-unchecked" />
222
+ <Label htmlFor="forms-cb-unchecked">Subscribe to updates</Label>
223
+ </div>
224
+ </div>
225
+ <div style={panelStyle}>
226
+ <p style={stateLabelStyle}>Disabled</p>
227
+ <div
228
+ style={{ display: 'flex', alignItems: 'center', gap: '0.5rem' }}
229
+ >
230
+ <Checkbox id="forms-cb-dis-on" checked disabled />
231
+ <Label htmlFor="forms-cb-dis-on">Accept terms</Label>
232
+ </div>
233
+ <div
234
+ style={{ display: 'flex', alignItems: 'center', gap: '0.5rem' }}
235
+ >
236
+ <Checkbox id="forms-cb-dis-off" disabled />
237
+ <Label htmlFor="forms-cb-dis-off">Subscribe to updates</Label>
238
+ </div>
239
+ </div>
240
+ </div>
241
+ </section>
242
+
243
+ <section>
244
+ <h3 style={{ marginBottom: '1rem' }}>Switch</h3>
245
+ <div style={twoColumnStyle}>
246
+ <div style={panelStyle}>
247
+ <p style={stateLabelStyle}>Default</p>
248
+ <div
249
+ style={{ display: 'flex', alignItems: 'center', gap: '0.5rem' }}
250
+ >
251
+ <Switch id="forms-sw-default" defaultChecked />
252
+ <Label htmlFor="forms-sw-default">Enable notifications</Label>
253
+ </div>
254
+ </div>
255
+ <div style={panelStyle}>
256
+ <p style={stateLabelStyle}>Disabled</p>
257
+ <div
258
+ style={{ display: 'flex', alignItems: 'center', gap: '0.5rem' }}
259
+ >
260
+ <Switch id="forms-sw-dis-on" checked disabled />
261
+ <Label htmlFor="forms-sw-dis-on">Enable notifications</Label>
262
+ </div>
263
+ <div
264
+ style={{ display: 'flex', alignItems: 'center', gap: '0.5rem' }}
265
+ >
266
+ <Switch id="forms-sw-dis-off" disabled />
267
+ <Label htmlFor="forms-sw-dis-off">Enable notifications</Label>
268
+ </div>
269
+ </div>
270
+ </div>
271
+ </section>
272
+
273
+ <section>
274
+ <h3 style={{ marginBottom: '1rem' }}>Select</h3>
275
+ <div style={twoColumnStyle}>
276
+ <div style={panelStyle}>
277
+ <p style={stateLabelStyle}>Default</p>
278
+ <DemoSelect defaultValue="apple" />
279
+ <DemoSelect placeholder="Pick fruit" />
280
+ </div>
281
+ <div style={panelStyle}>
282
+ <p style={stateLabelStyle}>Disabled</p>
283
+ <DemoSelect defaultValue="orange" disabled />
284
+ </div>
285
+ </div>
286
+ </section>
287
+
288
+ <section>
289
+ <h3 style={{ marginBottom: '1rem' }}>Slider</h3>
290
+ <div style={twoColumnStyle}>
291
+ <div style={panelStyle}>
292
+ <p style={stateLabelStyle}>Default</p>
293
+ <Slider
294
+ value={sliderValue}
295
+ onValueChange={setSliderValue}
296
+ max={100}
297
+ step={1}
298
+ style={{ width: SLIDER_WIDTH }}
299
+ />
300
+ <p style={{ fontSize: 14, color: 'var(--muted-foreground)' }}>
301
+ Value: {sliderValue[0]}
302
+ </p>
303
+ </div>
304
+ <div style={panelStyle}>
305
+ <p style={stateLabelStyle}>Disabled</p>
306
+ <Slider
307
+ defaultValue={[60]}
308
+ max={100}
309
+ step={1}
310
+ disabled
311
+ style={{ width: SLIDER_WIDTH }}
312
+ />
313
+ </div>
314
+ </div>
315
+ </section>
316
+
317
+ <section>
318
+ <h3 style={{ marginBottom: '1rem' }}>ToggleGroup</h3>
319
+ <div style={twoColumnStyle}>
320
+ <div style={panelStyle}>
321
+ <p style={stateLabelStyle}>Default</p>
322
+ <ToggleGroup
323
+ type="single"
324
+ value={toggleValue}
325
+ onValueChange={val => {
326
+ if (val) setToggleValue(val);
327
+ }}
328
+ >
329
+ <ToggleGroupItem value="day">Day</ToggleGroupItem>
330
+ <ToggleGroupItem value="week">Week</ToggleGroupItem>
331
+ <ToggleGroupItem value="month">Month</ToggleGroupItem>
332
+ </ToggleGroup>
333
+ </div>
334
+ <div style={panelStyle}>
335
+ <p style={stateLabelStyle}>Disabled</p>
336
+ <ToggleGroup type="single" value="week" disabled>
337
+ <ToggleGroupItem value="day">Day</ToggleGroupItem>
338
+ <ToggleGroupItem value="week">Week</ToggleGroupItem>
339
+ <ToggleGroupItem value="month">Month</ToggleGroupItem>
340
+ </ToggleGroup>
341
+ </div>
342
+ </div>
343
+ </section>
344
+
345
+ <section>
346
+ <h3 style={{ marginBottom: '1rem' }}>NumberControl</h3>
347
+ <div style={panelStyle}>
348
+ <NumberControl
349
+ value={numberValue}
350
+ onChange={setNumberValue}
351
+ min={0}
352
+ max={10}
353
+ step={1}
354
+ />
355
+ </div>
356
+ </section>
357
+
358
+ <section>
359
+ <h3 style={{ marginBottom: '1rem' }}>Button</h3>
360
+ <div style={panelStyle}>
361
+ <div
362
+ style={{
363
+ display: 'flex',
364
+ flexWrap: 'wrap',
365
+ gap: '0.75rem',
366
+ alignItems: 'center',
367
+ }}
368
+ >
369
+ <Button type="button">Primary</Button>
370
+ <Button type="button" variant="secondary">
371
+ Secondary
372
+ </Button>
373
+ <Button type="button" variant="outline">
374
+ Outline
375
+ </Button>
376
+ <Button type="button" variant="ghost">
377
+ Ghost
378
+ </Button>
379
+ <Button type="button" variant="link">
380
+ Link
381
+ </Button>
382
+ </div>
383
+ <div
384
+ style={{
385
+ display: 'flex',
386
+ flexWrap: 'wrap',
387
+ gap: '0.75rem',
388
+ alignItems: 'center',
389
+ }}
390
+ >
391
+ <Button type="button" disabled>
392
+ Disabled
393
+ </Button>
394
+ <Button type="button" variant="outline" disabled>
395
+ Disabled outline
396
+ </Button>
397
+ </div>
398
+ </div>
399
+ </section>
400
+
401
+ <section>
402
+ <h3 style={{ marginBottom: '1rem' }}>ButtonGroup</h3>
403
+ <div style={panelStyle}>
404
+ <ButtonGroup>
405
+ {['day', 'week', 'month'].map(item => (
406
+ <Button
407
+ key={item}
408
+ type="button"
409
+ variant={item === period ? 'default' : 'outline'}
410
+ onClick={() => setPeriod(item)}
411
+ >
412
+ {item}
413
+ </Button>
414
+ ))}
415
+ </ButtonGroup>
416
+ </div>
417
+ </section>
418
+
419
+ <section>
420
+ <h3 style={{ marginBottom: '1rem' }}>DropZone</h3>
421
+ <div style={{ ...panelStyle, maxWidth: 420 }}>
422
+ <DropZone
423
+ accept=".csv,.txt"
424
+ label="Drop a .csv or .txt file here"
425
+ onFile={file => setDropZoneName(file.name)}
426
+ />
427
+ {dropZoneName ? (
428
+ <p style={{ margin: 0, fontSize: 14 }}>
429
+ Selected: {dropZoneName}
430
+ </p>
431
+ ) : null}
432
+ </div>
433
+ </section>
434
+
435
+ <section>
436
+ <h3 style={{ marginBottom: '1rem' }}>MobileAdaptiveSelector</h3>
437
+ <div style={panelStyle}>
438
+ <MobileAdaptiveSelector
439
+ value={mobileSelectorValue}
440
+ onChange={setMobileSelectorValue}
441
+ items={[...MOBILE_SELECTOR_ITEMS]}
442
+ isDropdown={false}
443
+ />
444
+ </div>
445
+ </section>
446
+
447
+ <section>
448
+ <h3 style={{ marginBottom: '1rem' }}>RegionCoords</h3>
449
+ <div style={panelStyle}>
450
+ <RegionSelector
451
+ regions={REGION_COORDS}
452
+ onSelect={(name, coords) => {
453
+ setRegionPick(
454
+ `${name}: ${coords.latitude.toFixed(2)}, ${coords.longitude.toFixed(2)}`,
455
+ );
456
+ }}
457
+ >
458
+ <span style={{ marginRight: 8 }}>Map region</span>
459
+ </RegionSelector>
460
+ {regionPick ? (
461
+ <p style={{ margin: 0, fontSize: 14 }}>{regionPick}</p>
462
+ ) : null}
463
+ </div>
464
+ </section>
465
+
466
+ <section>
467
+ <h3 style={{ marginBottom: '1rem' }}>Renamer</h3>
468
+ <div style={panelStyle}>
469
+ <Renamer value={renamerValue} onChange={setRenamerValue} size="md">
470
+ {renamerValue}
471
+ </Renamer>
472
+ </div>
473
+ </section>
474
+
475
+ <section>
476
+ <h3 style={{ marginBottom: '1rem' }}>TimeRangeControls</h3>
477
+ <div style={panelStyle}>
478
+ <TimeRangeControls
479
+ timeRange={timeRange}
480
+ onTimeRangeChange={setTimeRange}
481
+ loading={false}
482
+ />
483
+ </div>
484
+ </section>
485
+
486
+ {/* Form (react-hook-form integration) excluded — see FormPage */}
487
+
488
+ <section>
489
+ <h3 style={{ marginBottom: '1rem' }}>Composed form</h3>
490
+ <p
491
+ style={{
492
+ marginBottom: '1rem',
493
+ color: 'var(--muted-foreground)',
494
+ maxWidth: 560,
495
+ }}
496
+ >
497
+ Realistic layout combining several controls — visual composition
498
+ only, no form library.
499
+ </p>
500
+ <form
501
+ style={{
502
+ ...panelStyle,
503
+ maxWidth: 480,
504
+ gap: '1.25rem',
505
+ }}
506
+ onSubmit={e => e.preventDefault()}
507
+ >
508
+ <LabeledInput
509
+ id="forms-composed-name"
510
+ name="name"
511
+ label="Full name"
512
+ value={composedName}
513
+ onChange={e => setComposedName(e.target.value)}
514
+ placeholder="Enter your name"
515
+ />
516
+ <LabeledInput
517
+ id="forms-composed-email"
518
+ name="email"
519
+ type="email"
520
+ label="Email"
521
+ value={composedEmail}
522
+ onChange={e => setComposedEmail(e.target.value)}
523
+ placeholder="you@company.com"
524
+ />
525
+ <div
526
+ style={{
527
+ display: 'flex',
528
+ flexDirection: 'column',
529
+ gap: '0.5rem',
530
+ }}
531
+ >
532
+ <Label htmlFor="forms-composed-role">Role</Label>
533
+ <Select value={composedRole} onValueChange={setComposedRole}>
534
+ <SelectTrigger
535
+ id="forms-composed-role"
536
+ style={{ width: '100%' }}
537
+ >
538
+ <SelectValue placeholder="Select role" />
539
+ </SelectTrigger>
540
+ <SelectContent>
541
+ {ROLE_OPTIONS.map(o => (
542
+ <SelectItem key={o.value} value={o.value}>
543
+ {o.label}
544
+ </SelectItem>
545
+ ))}
546
+ </SelectContent>
547
+ </Select>
548
+ </div>
549
+ <div
550
+ style={{ display: 'flex', alignItems: 'center', gap: '0.5rem' }}
551
+ >
552
+ <Switch
553
+ id="forms-composed-notifications"
554
+ checked={composedNotifications}
555
+ onCheckedChange={setComposedNotifications}
556
+ />
557
+ <Label htmlFor="forms-composed-notifications">
558
+ Email me about product updates
559
+ </Label>
560
+ </div>
561
+ <div
562
+ style={{ display: 'flex', alignItems: 'center', gap: '0.5rem' }}
563
+ >
564
+ <Checkbox
565
+ id="forms-composed-terms"
566
+ checked={composedTerms}
567
+ onCheckedChange={v => setComposedTerms(v === true)}
568
+ />
569
+ <Label htmlFor="forms-composed-terms">
570
+ I agree to the terms of service
571
+ </Label>
572
+ </div>
573
+ <div
574
+ style={{
575
+ display: 'flex',
576
+ gap: '0.75rem',
577
+ paddingTop: '0.5rem',
578
+ }}
579
+ >
580
+ <Button type="submit">Save profile</Button>
581
+ <Button type="button" variant="outline">
582
+ Cancel
583
+ </Button>
584
+ </div>
585
+ </form>
586
+ </section>
587
+ </PageContentSection>
588
+ </>
589
+ );
590
+ }