oneslash-design-system 2.22.0 → 2.23.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (88) 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/internal/date.d.ts +35 -0
  61. package/dist/internal/date.js +122 -0
  62. package/dist/internal/dropZone.d.ts +28 -0
  63. package/dist/internal/dropZone.js +42 -0
  64. package/dist/internal/emoji.d.ts +13 -0
  65. package/dist/internal/emoji.js +182 -0
  66. package/dist/internal/overlayStack.js +1 -1
  67. package/dist/internal/people.d.ts +1 -0
  68. package/dist/internal/people.js +12 -0
  69. package/dist/native-mapping.json +45 -3
  70. package/dist/stories/AvatarStack.stories.d.ts +7 -0
  71. package/dist/stories/AvatarStack.stories.jsx +46 -0
  72. package/dist/stories/Breadcrumb.stories.d.ts +7 -0
  73. package/dist/stories/Breadcrumb.stories.jsx +26 -0
  74. package/dist/stories/Calendar.stories.d.ts +6 -0
  75. package/dist/stories/Calendar.stories.jsx +15 -0
  76. package/dist/stories/Cases.generated.stories.d.ts +10 -0
  77. package/dist/stories/Cases.generated.stories.jsx +20 -0
  78. package/dist/stories/DateField.stories.d.ts +10 -0
  79. package/dist/stories/DateField.stories.jsx +132 -0
  80. package/dist/stories/DropZone.stories.d.ts +12 -0
  81. package/dist/stories/DropZone.stories.jsx +151 -0
  82. package/dist/stories/EmojiPicker.stories.d.ts +6 -0
  83. package/dist/stories/EmojiPicker.stories.jsx +92 -0
  84. package/dist/stories/ItemList.stories.d.ts +9 -0
  85. package/dist/stories/ItemList.stories.jsx +86 -0
  86. package/dist/stories/Lightbox.stories.d.ts +4 -0
  87. package/dist/stories/Lightbox.stories.jsx +44 -0
  88. package/package.json +3 -2
@@ -0,0 +1,22 @@
1
+ import React from 'react';
2
+ interface Person {
3
+ name: string;
4
+ imageUrl?: string;
5
+ }
6
+ interface AvatarStackProps {
7
+ people: Person[];
8
+ /** The most circles shown, the '+N' one included. Default 4. */
9
+ max?: number;
10
+ /** Face diameter in pixels. Default 24. */
11
+ size?: number;
12
+ /** The spoken name of the group. Defaults to the names, e.g. 'Dana Lee, Ben Carter and 4 others'. */
13
+ 'aria-label'?: string;
14
+ /** Makes the stack one button. The caller anchors a Popover on `event.currentTarget` to list everyone. */
15
+ onClick?: React.MouseEventHandler<HTMLButtonElement>;
16
+ /** With `onClick`: what the button opens, such as `'dialog'` for a Popover */
17
+ 'aria-haspopup'?: 'dialog' | 'menu' | 'listbox' | 'true';
18
+ /** With `onClick`: whether what it opens is open now */
19
+ 'aria-expanded'?: boolean;
20
+ }
21
+ export default function AvatarStack({ people, max, size, 'aria-label': ariaLabel, onClick, 'aria-haspopup': ariaHasPopup, 'aria-expanded': ariaExpanded, }: AvatarStackProps): React.JSX.Element | null;
22
+ export {};
@@ -0,0 +1,32 @@
1
+ 'use client';
2
+ import React from 'react';
3
+ import UserImage from './userImage';
4
+ import { focusRing } from './sharedStyles';
5
+ import { peopleLabel } from '../internal/people';
6
+ var ring = 'rounded-full border-2 border-background-default';
7
+ // Overlapping faces for the people on a thing. Past `max` the last circle counts the rest.
8
+ export default function AvatarStack(_a) {
9
+ var people = _a.people, _b = _a.max, max = _b === void 0 ? 4 : _b, _c = _a.size, size = _c === void 0 ? 24 : _c, ariaLabel = _a["aria-label"], onClick = _a.onClick, ariaHasPopup = _a["aria-haspopup"], ariaExpanded = _a["aria-expanded"];
10
+ if (people.length === 0)
11
+ return null;
12
+ var over = people.length > max;
13
+ var shown = over ? people.slice(0, Math.max(0, max - 1)) : people;
14
+ var label = ariaLabel !== null && ariaLabel !== void 0 ? ariaLabel : peopleLabel(people.map(function (p) { return p.name; }));
15
+ var overlap = function (i) { return (i > 0 ? ' -ml-2' : ''); };
16
+ var faces = (<>
17
+ {shown.map(function (p, i) { return (<span key={i} className={"inline-flex shrink-0 ".concat(ring).concat(overlap(i))}>
18
+ <UserImage userHandle={p.name} userImgUrl={p.imageUrl} size={size} decorative/>
19
+ </span>); })}
20
+ {over && (<span aria-hidden="true" style={{ width: size + 4, height: size + 4 }} className={"inline-flex shrink-0 items-center justify-center bg-background-accent200 text-fg-primary text-caption ".concat(ring).concat(overlap(shown.length))}>
21
+ +{people.length - shown.length}
22
+ </span>)}
23
+ </>);
24
+ if (onClick) {
25
+ return (<button type="button" aria-label={label} aria-haspopup={ariaHasPopup} aria-expanded={ariaExpanded} onClick={onClick} className={"inline-flex cursor-pointer items-center rounded-full ".concat(focusRing)}>
26
+ {faces}
27
+ </button>);
28
+ }
29
+ return (<span role="img" aria-label={label} className="inline-flex items-center">
30
+ {faces}
31
+ </span>);
32
+ }
@@ -0,0 +1,12 @@
1
+ import React from 'react';
2
+ interface BreadcrumbItem {
3
+ label: string;
4
+ href?: string;
5
+ }
6
+ interface BreadcrumbProps {
7
+ /** The trail from the top to the current page. The last item is the current page and is not a link. */
8
+ items: BreadcrumbItem[];
9
+ 'aria-label'?: string;
10
+ }
11
+ export default function Breadcrumb({ items, 'aria-label': ariaLabel }: BreadcrumbProps): React.JSX.Element | null;
12
+ export {};
@@ -0,0 +1,24 @@
1
+ import React from 'react';
2
+ import { ChevronRight } from 'lucide-react';
3
+ import Link from './link';
4
+ import Icon from './icon';
5
+ // Where a page sits: a linked trail with the current page last. It wraps on a narrow screen and never
6
+ // scrolls sideways. Fewer than two items shows nothing.
7
+ export default function Breadcrumb(_a) {
8
+ var items = _a.items, _b = _a["aria-label"], ariaLabel = _b === void 0 ? 'Breadcrumb' : _b;
9
+ if (items.length < 2)
10
+ return null;
11
+ var last = items.length - 1;
12
+ return (<nav aria-label={ariaLabel}>
13
+ <ol className="flex flex-wrap items-center gap-x-1 gap-y-1 text-body2">
14
+ {items.map(function (item, i) { return (<li key={i} className="flex min-w-0 items-center gap-1">
15
+ {i === last || !item.href ? (<span {...(i === last && { 'aria-current': 'page' })} className={"break-words min-w-0 ".concat(i === last ? 'text-fg-primary' : 'text-fg-secondary')}>
16
+ {item.label}
17
+ </span>) : (<Link href={item.href} size="body2" className="break-words">
18
+ {item.label}
19
+ </Link>)}
20
+ {i < last && <Icon icon={ChevronRight} size="small" color="secondary" className="shrink-0"/>}
21
+ </li>); })}
22
+ </ol>
23
+ </nav>);
24
+ }
@@ -0,0 +1,19 @@
1
+ import React from 'react';
2
+ interface CalendarProps {
3
+ /** Prefix for the ids: a day's button is `<id>-<YYYY-MM-DD>`, the month heading `<id>-heading`. */
4
+ id: string;
5
+ /** The chosen day as `'YYYY-MM-DD'`, or `''` for none. */
6
+ value: string;
7
+ /** Called with the picked day (`'YYYY-MM-DD'`) on a click, Enter or Space. A day outside `min` and `max` is never picked. */
8
+ onChange: (value: string) => void;
9
+ /** The first day that can be picked, `'YYYY-MM-DD'`. */
10
+ min?: string;
11
+ /** The last day that can be picked, `'YYYY-MM-DD'`. */
12
+ max?: string;
13
+ /** Names the calendar, e.g. the field it fills. */
14
+ 'aria-label': string;
15
+ /** Focus the day that holds the tab stop when the calendar mounts, as in a Popover that has just opened. */
16
+ autoFocus?: boolean;
17
+ }
18
+ export default function Calendar({ id, value, onChange, min, max, 'aria-label': ariaLabel, autoFocus }: CalendarProps): React.JSX.Element;
19
+ export {};
@@ -0,0 +1,126 @@
1
+ 'use client';
2
+ import React, { useEffect, useRef, useState } from 'react';
3
+ import { ChevronLeft, ChevronRight } from 'lucide-react';
4
+ import IconButton from './iconButton';
5
+ import { focusRing, stateTransition } from './sharedStyles';
6
+ import { addDays, addMonths, compare, formatLong, inRange, monthGrid, monthLabel, todayIso, weekday } from '../internal/date';
7
+ var WEEKDAYS = [
8
+ ['Su', 'Sunday'], ['Mo', 'Monday'], ['Tu', 'Tuesday'], ['We', 'Wednesday'], ['Th', 'Thursday'], ['Fr', 'Friday'], ['Sa', 'Saturday'],
9
+ ];
10
+ // The day the tab stop starts on: the chosen day, else today, else the first day that can be picked
11
+ function startDay(value, min, max) {
12
+ if (value)
13
+ return value;
14
+ var today = todayIso();
15
+ if (min && compare(today, min) < 0)
16
+ return min;
17
+ if (max && compare(today, max) > 0)
18
+ return max;
19
+ return today;
20
+ }
21
+ // One month of days in a grid. The arrows move a day or a week, Home and End go to the start and end of the
22
+ // week, PageUp and PageDown a month (with Shift, a year). Weeks start on Sunday.
23
+ export default function Calendar(_a) {
24
+ var id = _a.id, value = _a.value, onChange = _a.onChange, min = _a.min, max = _a.max, ariaLabel = _a["aria-label"], _b = _a.autoFocus, autoFocus = _b === void 0 ? false : _b;
25
+ var _c = useState(function () { return startDay(value, min, max); }), active = _c[0], setActive = _c[1];
26
+ var moved = useRef(autoFocus);
27
+ var today = todayIso();
28
+ // A new value from outside moves the tab stop to it
29
+ useEffect(function () {
30
+ if (value)
31
+ setActive(value);
32
+ }, [value]);
33
+ // After a key moves the tab stop, focus follows it
34
+ useEffect(function () {
35
+ var _a;
36
+ if (!moved.current)
37
+ return;
38
+ moved.current = false;
39
+ // The Popover may not be positioned yet on the first focus, so the page must not scroll to it
40
+ (_a = document.getElementById("".concat(id, "-").concat(active))) === null || _a === void 0 ? void 0 : _a.focus({ preventScroll: true });
41
+ }, [active, id]);
42
+ var onKeyDown = function (e) {
43
+ if (!(e.target instanceof HTMLButtonElement) || e.altKey || e.ctrlKey || e.metaKey)
44
+ return;
45
+ var day = weekday(active);
46
+ var next = {
47
+ ArrowLeft: function () { return addDays(active, -1); },
48
+ ArrowRight: function () { return addDays(active, 1); },
49
+ ArrowUp: function () { return addDays(active, -7); },
50
+ ArrowDown: function () { return addDays(active, 7); },
51
+ Home: function () { return addDays(active, -day); },
52
+ End: function () { return addDays(active, 6 - day); },
53
+ PageUp: function () { return addMonths(active, e.shiftKey ? -12 : -1); },
54
+ PageDown: function () { return addMonths(active, e.shiftKey ? 12 : 1); },
55
+ }[e.key];
56
+ if (!next)
57
+ return;
58
+ e.preventDefault();
59
+ moved.current = true;
60
+ setActive(next());
61
+ };
62
+ var pick = function (day) {
63
+ setActive(day);
64
+ if (inRange(day, min, max))
65
+ onChange(day);
66
+ };
67
+ // Tab and Shift+Tab move between the month buttons and the day, so a Popover around the calendar does not
68
+ // close first. Tab from the day and Shift+Tab from 'Previous month' keep their normal behaviour.
69
+ var onTab = function (e) {
70
+ var _a;
71
+ if (e.key !== 'Tab' || e.altKey || e.ctrlKey || e.metaKey)
72
+ return;
73
+ var order = [
74
+ document.getElementById("".concat(id, "-prev")),
75
+ document.getElementById("".concat(id, "-next")),
76
+ document.getElementById("".concat(id, "-").concat(active)),
77
+ ];
78
+ var index = order.indexOf(e.target);
79
+ if (index < 0)
80
+ return;
81
+ var to = e.shiftKey ? index - 1 : index + 1;
82
+ if (to < 0 || to > 2)
83
+ return;
84
+ e.preventDefault();
85
+ e.stopPropagation();
86
+ (_a = order[to]) === null || _a === void 0 ? void 0 : _a.focus();
87
+ };
88
+ var headingId = "".concat(id, "-heading");
89
+ return (<div id={id} role="group" aria-label={ariaLabel} className="flex flex-col gap-small w-fit" onKeyDown={onTab}>
90
+ <div className="flex items-center justify-between">
91
+ <IconButton color="iconOnly" state="enabled" size="medium" icon={ChevronLeft} id={"".concat(id, "-prev")} ariaLabel="Previous month" onClick={function () { return setActive(addMonths(active, -1)); }}/>
92
+ <div id={headingId} aria-live="polite" className="text-subtitle2 text-fg-primary">{monthLabel(active)}</div>
93
+ <IconButton color="iconOnly" state="enabled" size="medium" icon={ChevronRight} id={"".concat(id, "-next")} ariaLabel="Next month" onClick={function () { return setActive(addMonths(active, 1)); }}/>
94
+ </div>
95
+ <table role="grid" aria-labelledby={headingId} className="border-collapse" onKeyDown={onKeyDown}>
96
+ <thead>
97
+ <tr>
98
+ {WEEKDAYS.map(function (_a) {
99
+ var short = _a[0], long = _a[1];
100
+ return (<th key={short} scope="col" abbr={long} className="w-10 h-8 text-caption font-normal text-fg-primary">{short}</th>);
101
+ })}
102
+ </tr>
103
+ </thead>
104
+ <tbody>
105
+ {monthGrid(active).map(function (week, w) { return (<tr key={w}>
106
+ {week.map(function (day, d) {
107
+ if (!day)
108
+ return <td key={d} role="gridcell" className="p-0"/>;
109
+ var selected = day === value;
110
+ var allowed = inRange(day, min, max);
111
+ var color = selected
112
+ ? 'bg-primary-dark text-primary-contrast cursor-pointer'
113
+ : allowed
114
+ ? 'text-fg-primary hover:bg-background-accent200 cursor-pointer'
115
+ : 'text-fg-disabled cursor-not-allowed';
116
+ return (<td key={d} role="gridcell" aria-selected={selected} className="p-0">
117
+ <button type="button" id={"".concat(id, "-").concat(day)} tabIndex={day === active ? 0 : -1} aria-label={formatLong(day)} aria-current={day === today ? 'date' : undefined} aria-disabled={allowed ? undefined : true} className={"w-10 h-10 flex items-center justify-center rounded-control text-body2 ".concat(day === today ? 'border border-fg-primary' : '', " ").concat(color, " ").concat(stateTransition, " ").concat(focusRing)} onClick={function () { return pick(day); }}>
118
+ {Number(day.slice(8))}
119
+ </button>
120
+ </td>);
121
+ })}
122
+ </tr>); })}
123
+ </tbody>
124
+ </table>
125
+ </div>);
126
+ }
@@ -0,0 +1,35 @@
1
+ import React from 'react';
2
+ /** What `onChange` says besides the day: the text in the field, and why it is not a date, or `null` */
3
+ export interface DateFieldChange {
4
+ text: string;
5
+ error: string | null;
6
+ }
7
+ interface DateFieldProps {
8
+ id: string;
9
+ label?: string;
10
+ /** The day as `'YYYY-MM-DD'`, or `''` for none. */
11
+ value: string;
12
+ /**
13
+ * Called with `'YYYY-MM-DD'` when a good date is typed (on blur or Enter) or picked, and with `''` when the typed text
14
+ * is empty or not a date that can be chosen. The second argument tells the two apart: `error` is `null` for an empty
15
+ * field and for a good date, and the field's own message ('Enter a real date as MM/DD/YYYY.') for a date typed wrong
16
+ * or out of range. A form blocks its submit while `error` is set.
17
+ */
18
+ onChange: (value: string, detail: DateFieldChange) => void;
19
+ /** The first day that can be chosen, `'YYYY-MM-DD'`. */
20
+ min?: string;
21
+ /** The last day that can be chosen, `'YYYY-MM-DD'`. */
22
+ max?: string;
23
+ required?: boolean;
24
+ disabled?: boolean;
25
+ /** The caption under the field. Defaults to 'MM/DD/YYYY'. */
26
+ helperText?: string;
27
+ /** An error from the form, such as a required field left empty. While set it replaces the field's own messages. */
28
+ errorText?: string;
29
+ /** Show the 'Choose date' button that opens a Calendar. Turn it off for a date far away, such as a date of birth. */
30
+ calendar?: boolean;
31
+ /** Id of the element that describes the field. Read after the field's own helper or error text. */
32
+ 'aria-describedby'?: string;
33
+ }
34
+ export default function DateField({ id, label, value, onChange, min, max, required, disabled, helperText, errorText, calendar, 'aria-describedby': ariaDescribedBy, }: DateFieldProps): React.JSX.Element;
35
+ export {};
@@ -0,0 +1,76 @@
1
+ 'use client';
2
+ import React, { useEffect, useRef, useState } from 'react';
3
+ import { CalendarDays } from 'lucide-react';
4
+ import TextField from './textField';
5
+ import IconButton from './iconButton';
6
+ import Popover from './popover';
7
+ import Calendar from './calendar';
8
+ import { Cluster } from './layout';
9
+ import { formatLong, readTyped, toTyped } from '../internal/date';
10
+ var labelClass = 'mb-1 text-body2 text-fg-secondary';
11
+ // A date typed as MM/DD/YYYY, or picked from a Calendar in a Popover. The text stays as typed until the
12
+ // field loses focus or Enter is pressed; then it is read, and a date that is not real or not in range says why.
13
+ export default function DateField(_a) {
14
+ var id = _a.id, label = _a.label, value = _a.value, onChange = _a.onChange, min = _a.min, max = _a.max, _b = _a.required, required = _b === void 0 ? false : _b, _c = _a.disabled, disabled = _c === void 0 ? false : _c, _d = _a.helperText, helperText = _d === void 0 ? 'MM/DD/YYYY' : _d, errorText = _a.errorText, _e = _a.calendar, calendar = _e === void 0 ? true : _e, ariaDescribedBy = _a["aria-describedby"];
15
+ var _f = useState(value ? toTyped(value) : ''), text = _f[0], setText = _f[1];
16
+ var _g = useState(''), ownError = _g[0], setOwnError = _g[1];
17
+ var _h = useState(false), open = _h[0], setOpen = _h[1];
18
+ var _j = useState(null), button = _j[0], setButton = _j[1];
19
+ // The last value this field reported, so a value from outside can be told apart from our own
20
+ var reported = useRef(value);
21
+ useEffect(function () {
22
+ if (value === reported.current)
23
+ return;
24
+ reported.current = value;
25
+ setText(value ? toTyped(value) : '');
26
+ setOwnError('');
27
+ }, [value]);
28
+ var report = function (next, detail) {
29
+ reported.current = next;
30
+ onChange(next, detail);
31
+ };
32
+ var commit = function () {
33
+ var _a;
34
+ var read = readTyped(text, min, max);
35
+ setOwnError((_a = read.error) !== null && _a !== void 0 ? _a : '');
36
+ if (read.value)
37
+ setText(read.text);
38
+ report(read.value, { text: read.text, error: read.error });
39
+ };
40
+ var pick = function (day) {
41
+ setText(toTyped(day));
42
+ setOwnError('');
43
+ report(day, { text: toTyped(day), error: null });
44
+ setOpen(false);
45
+ button === null || button === void 0 ? void 0 : button.focus();
46
+ };
47
+ var shownError = errorText || ownError;
48
+ var errorId = "".concat(id, "-error");
49
+ var helperId = "".concat(id, "-helper");
50
+ // With the calendar button, the helper or error line is drawn under the whole row, not under the input. It then has
51
+ // the row's width, so a helper that fits on one line where the error does keeps the Buttons below from moving.
52
+ var ownDescription = shownError ? errorId : helperText ? helperId : undefined;
53
+ var field = calendar ? (<TextField id={id} value={text} onChange={function (e) { return setText(e.target.value); }} onBlur={commit} onKeyDown={function (e) { if (e.key === 'Enter')
54
+ commit(); }} required={required} disabled={disabled} autoComplete="off" aria-invalid={!!shownError} aria-describedby={[ownDescription, ariaDescribedBy].filter(Boolean).join(' ') || undefined}/>) : (<TextField id={id} label={label} value={text} onChange={function (e) { return setText(e.target.value); }} onBlur={commit} onKeyDown={function (e) { if (e.key === 'Enter')
55
+ commit(); }} required={required} disabled={disabled} error={!!shownError} errorText={shownError} helperText={helperText} autoComplete="off" aria-describedby={ariaDescribedBy}/>);
56
+ if (!calendar)
57
+ return field;
58
+ return (<div className="flex flex-col w-full">
59
+ {label && (<label htmlFor={id} className={labelClass}>
60
+ {label}{required && <span className="text-error-text ml-0.5">*</span>}
61
+ </label>)}
62
+ {/* The button lines up with the input (both 40px); the helper or error text sits under the whole row */}
63
+ <Cluster gap="small" align="start">
64
+ <div className="flex-1 min-w-0">{field}</div>
65
+ <IconButton ref={setButton} id={"".concat(id, "-choose")} color="iconOnly" state={disabled ? 'disabled' : 'enabled'} size="large" icon={CalendarDays} ariaLabel={value ? "Choose date, ".concat(formatLong(value)) : 'Choose date'} aria-haspopup="dialog" aria-expanded={open} onClick={function () { return setOpen(function (o) { return !o; }); }}/>
66
+ </Cluster>
67
+ {shownError ? (<p id={errorId} className="mt-1 text-error-text text-body2">
68
+ {shownError}
69
+ </p>) : (helperText && (<p id={helperId} className="mt-1 text-fg-secondary text-body2">
70
+ {helperText}
71
+ </p>))}
72
+ <Popover id={"".concat(id, "-popover")} anchorEl={button} open={open} onClose={function () { return setOpen(false); }} returnFocus>
73
+ <Calendar id={"".concat(id, "-calendar")} value={value} min={min} max={max} aria-label={label || 'Choose date'} autoFocus onChange={pick}/>
74
+ </Popover>
75
+ </div>);
76
+ }
@@ -0,0 +1,53 @@
1
+ import React, { type ReactNode } from 'react';
2
+ import { type FileRejection } from '../internal/dropZone';
3
+ export type { FileRejection };
4
+ interface DropZoneProps {
5
+ /** Prefix for the ids: the group is `<id>`, the file input `<id>-input`, the label `<id>-label`, the hint `<id>-hint`. */
6
+ id: string;
7
+ /** Names the group, and is the large zone's first line ('Drop a picture here'). In `compact` it is read by screen readers only. */
8
+ label: string;
9
+ /** The Button that opens the file chooser. Default 'Choose File'. */
10
+ buttonLabel?: string;
11
+ /** What is allowed, in words ('JPG, PNG or WebP, up to 5 MB'). Also describes the Button. */
12
+ hint?: string;
13
+ /** MIME types ('image/png'), wildcards ('image/*') or extensions ('.pdf') */
14
+ accept?: string[];
15
+ /** The largest file, in bytes */
16
+ maxBytes?: number;
17
+ /** Default `false`: one file at a time */
18
+ multiple?: boolean;
19
+ /** With `multiple`: the most files in one choice */
20
+ maxFiles?: number;
21
+ /** Ignores drops and disables the Button */
22
+ disabled?: boolean;
23
+ /**
24
+ * While the caller saves what was chosen: the Button shows `loading` (it keeps its label and focus and is announced
25
+ * busy) and ignores presses, and a drop is taken from the page and ignored. Unlike `disabled`, focus stays on the Button.
26
+ */
27
+ loading?: boolean;
28
+ /** `large` is a dashed box with an icon; `compact` is a row for `children` (such as a picture), the Button and the hint. Default `large`. */
29
+ size?: 'large' | 'compact';
30
+ /** The files that passed, from a drop or from the file chooser */
31
+ onFiles: (files: File[]) => void;
32
+ /**
33
+ * The files that did not pass, each with a reason: `type`, `size` or `count`. The zone shows no error itself:
34
+ * turn the reasons into words and show them under the zone, for instance through `FormField`.
35
+ */
36
+ onReject?: (rejections: FileRejection[]) => void;
37
+ /** In `compact`: shown before the Button, such as a `UserImage` */
38
+ children?: ReactNode;
39
+ /**
40
+ * The id of the caller's error or help text (from `FormField`'s `aria-describedby`). It describes the group and the
41
+ * Button, so the error is read with the control.
42
+ */
43
+ 'aria-describedby'?: string;
44
+ /** `true` while the caller shows an error (from `FormField`'s `aria-invalid`) */
45
+ 'aria-invalid'?: boolean;
46
+ /**
47
+ * What a screen reader hears after a drop or a choice, in a polite live line that is never drawn. Left out, the zone
48
+ * says what it added ('dana.png added', '2 files added') or that files were not added. Pass the caller's own error
49
+ * words so a rejection is announced as the caller wrote it; pass them again as the error changes.
50
+ */
51
+ status?: string;
52
+ }
53
+ export default function DropZone({ id, label, buttonLabel, hint, accept, maxBytes, multiple, maxFiles, disabled, loading, size, onFiles, onReject, children, 'aria-describedby': describedBy, 'aria-invalid': invalid, status, }: DropZoneProps): React.JSX.Element;
@@ -0,0 +1,136 @@
1
+ 'use client';
2
+ import React, { useEffect, useRef, useState } from 'react';
3
+ import { Upload } from 'lucide-react';
4
+ import Button from './button';
5
+ import { checkFiles } from '../internal/dropZone';
6
+ var hasFiles = function (e) { var _a, _b; return Array.from((_b = (_a = e.dataTransfer) === null || _a === void 0 ? void 0 : _a.types) !== null && _b !== void 0 ? _b : []).includes('Files'); };
7
+ // A place to drop files, and a Button that opens the file chooser for everyone who does not drag (keyboard,
8
+ // touch, screen reader). The drop checks each file against `accept`, `maxBytes` and the count, then reports
9
+ // the good ones through `onFiles` and the bad ones, with a reason, through `onReject`. A drag over the page
10
+ // outside the zone does nothing. The highlight clears on drag leave, on drop and when the drag is cancelled.
11
+ export default function DropZone(_a) {
12
+ var id = _a.id, label = _a.label, _b = _a.buttonLabel, buttonLabel = _b === void 0 ? 'Choose File' : _b, hint = _a.hint, accept = _a.accept, maxBytes = _a.maxBytes, _c = _a.multiple, multiple = _c === void 0 ? false : _c, maxFiles = _a.maxFiles, _d = _a.disabled, disabled = _d === void 0 ? false : _d, _e = _a.loading, loading = _e === void 0 ? false : _e, _f = _a.size, size = _f === void 0 ? 'large' : _f, onFiles = _a.onFiles, onReject = _a.onReject, children = _a.children, describedBy = _a["aria-describedby"], invalid = _a["aria-invalid"], status = _a.status;
13
+ var inputRef = useRef(null);
14
+ // Entering a child fires dragenter before the parent's dragleave, so count them to keep the state steady
15
+ var depth = useRef(0);
16
+ var _g = useState(false), dragging = _g[0], setDragging = _g[1];
17
+ var _h = useState(''), said = _h[0], setSaid = _h[1];
18
+ var labelId = "".concat(id, "-label");
19
+ var hintId = "".concat(id, "-hint");
20
+ var stop = function () {
21
+ depth.current = 0;
22
+ setDragging(false);
23
+ };
24
+ // A drag cancelled with Escape, or dropped somewhere else, may not reach the zone: clear on the page's events
25
+ useEffect(function () {
26
+ if (!dragging)
27
+ return;
28
+ var onKey = function (e) {
29
+ if (e.key === 'Escape')
30
+ stop();
31
+ };
32
+ window.addEventListener('drop', stop);
33
+ window.addEventListener('dragend', stop);
34
+ window.addEventListener('keydown', onKey);
35
+ return function () {
36
+ window.removeEventListener('drop', stop);
37
+ window.removeEventListener('dragend', stop);
38
+ window.removeEventListener('keydown', onKey);
39
+ };
40
+ }, [dragging]);
41
+ useEffect(function () {
42
+ if (disabled || loading)
43
+ stop();
44
+ }, [disabled, loading]);
45
+ var handle = function (list) {
46
+ if (list.length === 0)
47
+ return;
48
+ var _a = checkFiles(list, { accept: accept, maxBytes: maxBytes, multiple: multiple, maxFiles: maxFiles }), accepted = _a.accepted, rejected = _a.rejected;
49
+ if (accepted.length > 0) {
50
+ setSaid(accepted.length === 1 ? "".concat(list[accepted[0]].name, " added") : "".concat(accepted.length, " files added"));
51
+ }
52
+ else {
53
+ setSaid(rejected.length === 1 ? 'File not added' : "".concat(rejected.length, " files not added"));
54
+ }
55
+ if (accepted.length > 0)
56
+ onFiles(accepted.map(function (i) { return list[i]; }));
57
+ if (rejected.length > 0)
58
+ onReject === null || onReject === void 0 ? void 0 : onReject(rejected);
59
+ };
60
+ var onDragEnter = function (e) {
61
+ if (disabled || !hasFiles(e))
62
+ return;
63
+ e.preventDefault();
64
+ if (loading)
65
+ return;
66
+ depth.current += 1;
67
+ setDragging(true);
68
+ };
69
+ var onDragOver = function (e) {
70
+ if (disabled || !hasFiles(e))
71
+ return;
72
+ e.preventDefault();
73
+ };
74
+ var onDragLeave = function (e) {
75
+ if (disabled || !hasFiles(e))
76
+ return;
77
+ depth.current = Math.max(0, depth.current - 1);
78
+ if (depth.current === 0)
79
+ setDragging(false);
80
+ };
81
+ var onDrop = function (e) {
82
+ if (disabled || !hasFiles(e))
83
+ return;
84
+ // Taken from the page while loading, so the browser does not open the file, then ignored
85
+ e.preventDefault();
86
+ stop();
87
+ if (loading)
88
+ return;
89
+ handle(Array.from(e.dataTransfer.files));
90
+ };
91
+ var dropProps = { onDragEnter: onDragEnter, onDragOver: onDragOver, onDragLeave: onDragLeave, onDrop: onDrop };
92
+ var button = (<Button size="small" type="secondary" state={disabled ? 'disabled' : 'enabled'} loading={loading} label={buttonLabel} aria-describedby={[hint ? hintId : '', describedBy !== null && describedBy !== void 0 ? describedBy : ''].filter(Boolean).join(' ') || undefined} onClickButton={function () { var _a; return (_a = inputRef.current) === null || _a === void 0 ? void 0 : _a.click(); }}/>);
93
+ var input = (<input ref={inputRef} id={"".concat(id, "-input")} type="file" className="hidden" tabIndex={-1} aria-hidden="true" accept={accept && accept.length > 0 ? accept.join(',') : undefined} multiple={multiple} disabled={disabled} onChange={function (e) {
94
+ var _a;
95
+ var list = Array.from((_a = e.target.files) !== null && _a !== void 0 ? _a : []);
96
+ // Reset, so choosing the same file again fires again
97
+ e.target.value = '';
98
+ handle(list);
99
+ }}/>);
100
+ // The drag border is the primary text color: the accent is 1.6:1 on the default and clay light pages
101
+ var live = (<span role="status" aria-live="polite" className="sr-only">
102
+ {status !== null && status !== void 0 ? status : said}
103
+ </span>);
104
+ var border = dragging ? 'border-fg-primary' : size === 'compact' ? 'border-transparent' : 'border-misc-divider';
105
+ if (size === 'compact') {
106
+ return (<div id={id} role="group" aria-labelledby={labelId} aria-describedby={describedBy} aria-invalid={invalid} className={"flex flex-row flex-wrap items-center gap-3 rounded-control border-2 border-dashed p-2 ".concat(border)} {...dropProps}>
107
+ {children}
108
+ {button}
109
+ <div className="flex flex-col">
110
+ <span id={labelId} className={dragging ? 'text-body2 text-fg-primary' : 'sr-only'}>
111
+ {dragging ? 'Drop to upload' : label}
112
+ </span>
113
+ {hint && (<span id={hintId} className="text-body2 text-fg-secondary">
114
+ {hint}
115
+ </span>)}
116
+ </div>
117
+ {input}
118
+ {live}
119
+ </div>);
120
+ }
121
+ return (<div id={id} role="group" aria-labelledby={labelId} aria-describedby={describedBy} aria-invalid={invalid} className={"flex flex-col items-center gap-2 rounded-control border-2 border-dashed px-4 py-6 text-center ".concat(border)} {...dropProps}>
122
+ <Upload aria-hidden="true" className="h-6 w-6 text-fg-secondary"/>
123
+ <span id={labelId} className="text-subtitle1 text-fg-primary">
124
+ {dragging ? 'Drop to upload' : label}
125
+ </span>
126
+ <span aria-hidden="true" className="text-body2 text-fg-secondary">
127
+ or
128
+ </span>
129
+ {button}
130
+ {hint && (<span id={hintId} className="text-body2 text-fg-secondary">
131
+ {hint}
132
+ </span>)}
133
+ {input}
134
+ {live}
135
+ </div>);
136
+ }
@@ -0,0 +1,22 @@
1
+ import React from 'react';
2
+ import { emojiGroups, quickEmoji, type EmojiEntry, type EmojiGroup } from '../internal/emoji';
3
+ export type { EmojiEntry, EmojiGroup };
4
+ export { emojiGroups, quickEmoji };
5
+ interface EmojiPickerProps {
6
+ /** Prefix for the ids: the search field is `<id>-search`, the status line `<id>-status`, a group's heading `<id>-group-<group id>`. */
7
+ id: string;
8
+ /** Called with the emoji on a click, Enter or Space. Inside a `<Popover returnFocus>`, close the Popover here. */
9
+ onPick: (emoji: EmojiEntry) => void;
10
+ /**
11
+ * The emoji (`char`) the person has already used, shown pressed. Given (even `[]`), every emoji is a toggle
12
+ * button with `aria-pressed`, as for reactions; left out, they are plain buttons, as for inserting text.
13
+ */
14
+ selected?: string[];
15
+ /** The groups to show. Defaults to the 96 built-in emoji in six groups. */
16
+ groups?: EmojiGroup[];
17
+ /** The row shown first as 'Frequently used'. Defaults to the six quick emoji; `[]` hides it. */
18
+ frequent?: EmojiEntry[];
19
+ /** Names the picker. */
20
+ 'aria-label'?: string;
21
+ }
22
+ export default function EmojiPicker({ id, onPick, selected, groups, frequent, 'aria-label': ariaLabel, }: EmojiPickerProps): React.JSX.Element;