oneslash-design-system 2.22.0 → 2.23.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/DESIGN.md +12 -1
- package/dist/cases/admin-inbox/split.jsx +22 -10
- package/dist/cases/admin-inbox.md +28 -23
- package/dist/cases/api-keys.md +1 -1
- package/dist/cases/breadcrumb/back-link.d.ts +1 -0
- package/dist/cases/breadcrumb/back-link.jsx +23 -0
- package/dist/cases/breadcrumb/trail.d.ts +1 -0
- package/dist/cases/breadcrumb/trail.jsx +28 -0
- package/dist/cases/breadcrumb.md +105 -0
- package/dist/cases/date-field/calendar.d.ts +1 -0
- package/dist/cases/date-field/calendar.jsx +80 -0
- package/dist/cases/date-field/typed.d.ts +1 -0
- package/dist/cases/date-field/typed.jsx +58 -0
- package/dist/cases/date-field.md +232 -0
- package/dist/cases/docs-component-page/reference.jsx +11 -1
- package/dist/cases/docs-component-page.md +19 -8
- package/dist/cases/file-upload/files.d.ts +1 -0
- package/dist/cases/file-upload/files.jsx +118 -0
- package/dist/cases/file-upload/picture.d.ts +1 -0
- package/dist/cases/file-upload/picture.jsx +50 -0
- package/dist/cases/file-upload.md +270 -0
- package/dist/cases/filter-menu.md +1 -1
- package/dist/cases/image-viewer/with-video.d.ts +1 -0
- package/dist/cases/image-viewer/with-video.jsx +42 -0
- package/dist/cases/image-viewer.md +72 -4
- package/dist/cases/master-detail/split.jsx +17 -10
- package/dist/cases/master-detail.md +26 -24
- package/dist/cases/message-reactions/picker.d.ts +1 -0
- package/dist/cases/message-reactions/picker.jsx +145 -0
- package/dist/cases/message-reactions/quick-pick.jsx +1 -1
- package/dist/cases/message-reactions.md +184 -3
- package/dist/cases/page-header.md +1 -1
- package/dist/cases/people-row/names.d.ts +1 -0
- package/dist/cases/people-row/names.jsx +20 -0
- package/dist/cases/people-row/stack.d.ts +1 -0
- package/dist/cases/people-row/stack.jsx +33 -0
- package/dist/cases/people-row.md +110 -0
- package/dist/cases/profile-form/form.jsx +21 -10
- package/dist/cases/profile-form.md +38 -9
- package/dist/cases.json +306 -25
- package/dist/components/avatarStack.d.ts +22 -0
- package/dist/components/avatarStack.jsx +32 -0
- package/dist/components/breadcrumb.d.ts +12 -0
- package/dist/components/breadcrumb.jsx +24 -0
- package/dist/components/calendar.d.ts +19 -0
- package/dist/components/calendar.jsx +126 -0
- package/dist/components/dateField.d.ts +35 -0
- package/dist/components/dateField.jsx +76 -0
- package/dist/components/dropZone.d.ts +53 -0
- package/dist/components/dropZone.jsx +136 -0
- package/dist/components/emojiPicker.d.ts +22 -0
- package/dist/components/emojiPicker.jsx +161 -0
- package/dist/components/itemList.d.ts +31 -0
- package/dist/components/itemList.jsx +81 -0
- package/dist/components/lightbox.d.ts +33 -9
- package/dist/components/lightbox.jsx +58 -27
- package/dist/components/menuItem.d.ts +1 -1
- package/dist/components/menuItem.jsx +3 -3
- package/dist/internal/date.d.ts +35 -0
- package/dist/internal/date.js +122 -0
- package/dist/internal/dropZone.d.ts +28 -0
- package/dist/internal/dropZone.js +42 -0
- package/dist/internal/emoji.d.ts +13 -0
- package/dist/internal/emoji.js +182 -0
- package/dist/internal/overlayStack.js +1 -1
- package/dist/internal/people.d.ts +1 -0
- package/dist/internal/people.js +12 -0
- package/dist/native-mapping.json +45 -3
- package/dist/stories/AvatarStack.stories.d.ts +7 -0
- package/dist/stories/AvatarStack.stories.jsx +46 -0
- package/dist/stories/Breadcrumb.stories.d.ts +7 -0
- package/dist/stories/Breadcrumb.stories.jsx +26 -0
- package/dist/stories/Calendar.stories.d.ts +6 -0
- package/dist/stories/Calendar.stories.jsx +15 -0
- package/dist/stories/Cases.generated.stories.d.ts +10 -0
- package/dist/stories/Cases.generated.stories.jsx +20 -0
- package/dist/stories/DateField.stories.d.ts +10 -0
- package/dist/stories/DateField.stories.jsx +132 -0
- package/dist/stories/DropZone.stories.d.ts +12 -0
- package/dist/stories/DropZone.stories.jsx +151 -0
- package/dist/stories/EmojiPicker.stories.d.ts +6 -0
- package/dist/stories/EmojiPicker.stories.jsx +92 -0
- package/dist/stories/ItemList.stories.d.ts +9 -0
- package/dist/stories/ItemList.stories.jsx +86 -0
- package/dist/stories/Lightbox.stories.d.ts +4 -0
- package/dist/stories/Lightbox.stories.jsx +44 -0
- package/package.json +3 -2
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
3
|
+
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
4
|
+
if (ar || !(i in from)) {
|
|
5
|
+
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
6
|
+
ar[i] = from[i];
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
return to.concat(ar || Array.prototype.slice.call(from));
|
|
10
|
+
};
|
|
11
|
+
import React, { useEffect, useMemo, useRef, useState } from 'react';
|
|
12
|
+
import TextField from './textField';
|
|
13
|
+
import { focusRing, stateTransition } from './sharedStyles';
|
|
14
|
+
import { emojiGroups, quickEmoji, searchEmoji } from '../internal/emoji';
|
|
15
|
+
export { emojiGroups, quickEmoji };
|
|
16
|
+
var COLUMNS = 8;
|
|
17
|
+
// Where an arrow key moves from cell `index`, given each section's size. Left and Right step one cell in
|
|
18
|
+
// reading order; Up and Down step a row in the same column, into the next or previous section at its edge,
|
|
19
|
+
// and to the last emoji of a short row. 'field' is the search field, above the first row.
|
|
20
|
+
function move(sizes, index, key) {
|
|
21
|
+
var total = sizes.reduce(function (a, b) { return a + b; }, 0);
|
|
22
|
+
var starts = sizes.map(function (_, s) { return sizes.slice(0, s).reduce(function (a, b) { return a + b; }, 0); });
|
|
23
|
+
var s = 0;
|
|
24
|
+
while (index >= starts[s] + sizes[s])
|
|
25
|
+
s++;
|
|
26
|
+
var i = index - starts[s];
|
|
27
|
+
var col = i % COLUMNS;
|
|
28
|
+
if (key === 'ArrowLeft')
|
|
29
|
+
return Math.max(index - 1, 0);
|
|
30
|
+
if (key === 'ArrowRight')
|
|
31
|
+
return Math.min(index + 1, total - 1);
|
|
32
|
+
if (key === 'Home')
|
|
33
|
+
return 0;
|
|
34
|
+
if (key === 'End')
|
|
35
|
+
return total - 1;
|
|
36
|
+
if (key === 'ArrowDown') {
|
|
37
|
+
if (Math.floor(i / COLUMNS) < Math.floor((sizes[s] - 1) / COLUMNS))
|
|
38
|
+
return starts[s] + Math.min(i + COLUMNS, sizes[s] - 1);
|
|
39
|
+
if (s + 1 < sizes.length)
|
|
40
|
+
return starts[s + 1] + Math.min(col, sizes[s + 1] - 1);
|
|
41
|
+
return index;
|
|
42
|
+
}
|
|
43
|
+
// ArrowUp
|
|
44
|
+
if (i >= COLUMNS)
|
|
45
|
+
return index - COLUMNS;
|
|
46
|
+
if (s === 0)
|
|
47
|
+
return 'field';
|
|
48
|
+
var lastRow = Math.floor((sizes[s - 1] - 1) / COLUMNS) * COLUMNS;
|
|
49
|
+
return starts[s - 1] + Math.min(lastRow + col, sizes[s - 1] - 1);
|
|
50
|
+
}
|
|
51
|
+
// A search field over a grid of emoji in groups, eight to a row. ArrowDown from the field enters the grid;
|
|
52
|
+
// in the grid the arrows move in two directions, Home and End go to the first and last emoji, and Enter or
|
|
53
|
+
// Space picks. The field and one emoji are the only tab stops: Tab from the field and Shift+Tab from the grid
|
|
54
|
+
// move between them and stay inside a `returnFocus` Popover. Escape is left to the Popover around it.
|
|
55
|
+
export default function EmojiPicker(_a) {
|
|
56
|
+
var id = _a.id, onPick = _a.onPick, selected = _a.selected, _b = _a.groups, groups = _b === void 0 ? emojiGroups : _b, _c = _a.frequent, frequent = _c === void 0 ? quickEmoji : _c, _d = _a["aria-label"], ariaLabel = _d === void 0 ? 'Emoji' : _d;
|
|
57
|
+
var _e = useState(''), query = _e[0], setQuery = _e[1];
|
|
58
|
+
var _f = useState(0), active = _f[0], setActive = _f[1];
|
|
59
|
+
var scroller = useRef(null);
|
|
60
|
+
var searchId = "".concat(id, "-search");
|
|
61
|
+
// Focus the field when the picker opens. The Popover may not be positioned yet, so the page must not scroll.
|
|
62
|
+
useEffect(function () {
|
|
63
|
+
var _a;
|
|
64
|
+
(_a = document.getElementById(searchId)) === null || _a === void 0 ? void 0 : _a.focus({ preventScroll: true });
|
|
65
|
+
}, [searchId]);
|
|
66
|
+
var count = useMemo(function () { return searchEmoji(groups, '').length; }, [groups]);
|
|
67
|
+
var searching = query.trim() !== '';
|
|
68
|
+
var results = searching ? searchEmoji(groups, query) : [];
|
|
69
|
+
var sections = (searching
|
|
70
|
+
? [{ id: 'results', label: 'Results', emojis: results }]
|
|
71
|
+
: __spreadArray([{ id: 'frequent', label: 'Frequently used', emojis: frequent }], groups, true)).filter(function (s) { return s.emojis.length > 0; });
|
|
72
|
+
var sizes = sections.map(function (s) { return s.emojis.length; });
|
|
73
|
+
var total = sizes.reduce(function (a, b) { return a + b; }, 0);
|
|
74
|
+
var stop = Math.min(active, Math.max(total - 1, 0));
|
|
75
|
+
var status = searching
|
|
76
|
+
? results.length > 0 ? "".concat(results.length, " emoji") : "No emoji match \"".concat(query.trim(), "\"")
|
|
77
|
+
: "".concat(count, " emoji");
|
|
78
|
+
// Focus a cell without scrolling the page, then scroll only the grid so the cell (and, in a first row,
|
|
79
|
+
// its group's heading) shows
|
|
80
|
+
var focusCell = function (index) {
|
|
81
|
+
setActive(index);
|
|
82
|
+
var box = scroller.current;
|
|
83
|
+
var cell = box === null || box === void 0 ? void 0 : box.querySelectorAll('button')[index];
|
|
84
|
+
if (!box || !cell)
|
|
85
|
+
return;
|
|
86
|
+
cell.focus({ preventScroll: true });
|
|
87
|
+
var row = cell.parentElement;
|
|
88
|
+
var inFirstRow = row ? Array.prototype.indexOf.call(row.children, cell) < COLUMNS : false;
|
|
89
|
+
var group = inFirstRow ? cell.closest('[role="group"]') : null;
|
|
90
|
+
var top = (group !== null && group !== void 0 ? group : cell).getBoundingClientRect().top;
|
|
91
|
+
var bottom = cell.getBoundingClientRect().bottom;
|
|
92
|
+
var view = box.getBoundingClientRect();
|
|
93
|
+
if (top < view.top)
|
|
94
|
+
box.scrollTop -= view.top - top;
|
|
95
|
+
else if (bottom > view.bottom)
|
|
96
|
+
box.scrollTop += bottom - view.bottom;
|
|
97
|
+
};
|
|
98
|
+
// ArrowDown goes to the first emoji, Tab to the one that holds the tab stop. Tab stops here so a
|
|
99
|
+
// `returnFocus` Popover does not take it as leaving; Shift+Tab is left to the Popover.
|
|
100
|
+
var onFieldKeyDown = function (e) {
|
|
101
|
+
if (total === 0 || e.altKey || e.ctrlKey || e.metaKey)
|
|
102
|
+
return;
|
|
103
|
+
if (e.key === 'ArrowDown') {
|
|
104
|
+
e.preventDefault();
|
|
105
|
+
focusCell(0);
|
|
106
|
+
}
|
|
107
|
+
else if (e.key === 'Tab' && !e.shiftKey) {
|
|
108
|
+
e.preventDefault();
|
|
109
|
+
e.stopPropagation();
|
|
110
|
+
focusCell(stop);
|
|
111
|
+
}
|
|
112
|
+
};
|
|
113
|
+
var onGridKeyDown = function (e) {
|
|
114
|
+
var _a, _b;
|
|
115
|
+
if (!(e.target instanceof HTMLButtonElement) || e.altKey || e.ctrlKey || e.metaKey)
|
|
116
|
+
return;
|
|
117
|
+
// Shift+Tab goes back to the field; Tab from the grid is left to the Popover
|
|
118
|
+
if (e.key === 'Tab' && e.shiftKey) {
|
|
119
|
+
e.preventDefault();
|
|
120
|
+
e.stopPropagation();
|
|
121
|
+
(_a = document.getElementById(searchId)) === null || _a === void 0 ? void 0 : _a.focus({ preventScroll: true });
|
|
122
|
+
return;
|
|
123
|
+
}
|
|
124
|
+
if (e.shiftKey)
|
|
125
|
+
return;
|
|
126
|
+
if (!['ArrowLeft', 'ArrowRight', 'ArrowUp', 'ArrowDown', 'Home', 'End'].includes(e.key))
|
|
127
|
+
return;
|
|
128
|
+
e.preventDefault();
|
|
129
|
+
var next = move(sizes, stop, e.key);
|
|
130
|
+
if (next === 'field')
|
|
131
|
+
(_b = document.getElementById(searchId)) === null || _b === void 0 ? void 0 : _b.focus({ preventScroll: true });
|
|
132
|
+
else
|
|
133
|
+
focusCell(next);
|
|
134
|
+
};
|
|
135
|
+
var flat = 0;
|
|
136
|
+
return (<div id={id} role="group" aria-label={ariaLabel} className="flex flex-col gap-small w-fit">
|
|
137
|
+
<TextField id={searchId} type="search" size="small" aria-label="Search emoji" aria-describedby={"".concat(id, "-status")} placeholder="Search emoji" value={query} onChange={function (e) {
|
|
138
|
+
setQuery(e.target.value);
|
|
139
|
+
setActive(0);
|
|
140
|
+
}} onKeyDown={onFieldKeyDown}/>
|
|
141
|
+
<p id={"".concat(id, "-status")} role="status" aria-live="polite" className="px-1 text-caption text-fg-primary">{status}</p>
|
|
142
|
+
{total > 0 && (<div ref={scroller} className="max-h-72 overflow-y-auto" style={{ scrollbarWidth: 'thin' }} onKeyDown={onGridKeyDown}>
|
|
143
|
+
{sections.map(function (section) {
|
|
144
|
+
var headingId = "".concat(id, "-group-").concat(section.id);
|
|
145
|
+
return (<div key={section.id} role="group" aria-labelledby={headingId}>
|
|
146
|
+
<h3 id={headingId} className="px-1 py-1 text-caption text-fg-primary">{section.label}</h3>
|
|
147
|
+
<div className="grid grid-cols-8 w-80">
|
|
148
|
+
{section.emojis.map(function (emoji) {
|
|
149
|
+
var _a;
|
|
150
|
+
var index = flat++;
|
|
151
|
+
var on = (_a = selected === null || selected === void 0 ? void 0 : selected.includes(emoji.char)) !== null && _a !== void 0 ? _a : false;
|
|
152
|
+
return (<button key={emoji.char} type="button" tabIndex={index === stop ? 0 : -1} aria-label={emoji.name} aria-pressed={selected ? on : undefined} className={"w-10 h-10 flex items-center justify-center rounded-control cursor-pointer ".concat(on ? 'bg-background-accent200' : 'hover:bg-background-accent100', " ").concat(stateTransition, " ").concat(focusRing)} onFocus={function () { return setActive(index); }} onClick={function () { return onPick(emoji); }}>
|
|
153
|
+
<span aria-hidden="true" className="text-h5 leading-none">{emoji.char}</span>
|
|
154
|
+
</button>);
|
|
155
|
+
})}
|
|
156
|
+
</div>
|
|
157
|
+
</div>);
|
|
158
|
+
})}
|
|
159
|
+
</div>)}
|
|
160
|
+
</div>);
|
|
161
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import MenuItem from './menuItem';
|
|
3
|
+
type MenuItemTag = NonNullable<React.ComponentProps<typeof MenuItem>['tag']>;
|
|
4
|
+
interface ItemListItem {
|
|
5
|
+
id: string;
|
|
6
|
+
label: string;
|
|
7
|
+
secondLabel?: string;
|
|
8
|
+
/** Makes the row a link. A click, Enter or Space follows it; a keyboard move only calls `onSelect`. */
|
|
9
|
+
href?: string;
|
|
10
|
+
tag?: MenuItemTag;
|
|
11
|
+
userHandle?: string;
|
|
12
|
+
userImgUrl?: string;
|
|
13
|
+
}
|
|
14
|
+
interface ItemListProps {
|
|
15
|
+
/** Prefix for the rows' ids: a row is `<id>-<item.id>`. */
|
|
16
|
+
id: string;
|
|
17
|
+
items: ItemListItem[];
|
|
18
|
+
/** The open item. Its row is the list's one tab stop; with none, the first row is. */
|
|
19
|
+
selectedId?: string;
|
|
20
|
+
/**
|
|
21
|
+
* `how` is 'keyboard' for a move with the arrows, Home, End or a letter: replace the address (`router.replace`), so Back
|
|
22
|
+
* does not step through each row. It is 'pointer' when the row is activated, by a click, Enter or Space: a link row follows
|
|
23
|
+
* its link then, so push (or let the link do it).
|
|
24
|
+
*/
|
|
25
|
+
onSelect: (id: string, how: 'pointer' | 'keyboard') => void;
|
|
26
|
+
'aria-label': string;
|
|
27
|
+
/** Whether a move with the arrows, Home, End or a letter also opens the row. `'md'` (default) does so from 768px up; below it Enter or Space opens. */
|
|
28
|
+
selectOnMove?: boolean | 'md';
|
|
29
|
+
}
|
|
30
|
+
export default function ItemList({ id, items, selectedId, onSelect, 'aria-label': ariaLabel, selectOnMove }: ItemListProps): React.JSX.Element;
|
|
31
|
+
export { ItemList };
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import React, { useEffect, useLayoutEffect, useRef } from 'react';
|
|
3
|
+
import Navigation from './navigation';
|
|
4
|
+
import MenuItem from './menuItem';
|
|
5
|
+
import { nextIndex } from '../internal/menu';
|
|
6
|
+
// useLayoutEffect warns during server rendering on React 18
|
|
7
|
+
var useIsomorphicLayoutEffect = typeof window !== 'undefined' ? useLayoutEffect : useEffect;
|
|
8
|
+
var MOVE_KEYS = ['ArrowDown', 'ArrowUp', 'Home', 'End'];
|
|
9
|
+
// A list of rows beside their detail, moved with the keyboard. The keys are handled on the rows
|
|
10
|
+
// only, so arrows typed in a field, or used to scroll the page, never move it.
|
|
11
|
+
export default function ItemList(_a) {
|
|
12
|
+
var _b;
|
|
13
|
+
var id = _a.id, items = _a.items, selectedId = _a.selectedId, onSelect = _a.onSelect, ariaLabel = _a["aria-label"], _c = _a.selectOnMove, selectOnMove = _c === void 0 ? 'md' : _c;
|
|
14
|
+
var rowId = function (itemId) { return "".concat(id, "-").concat(itemId); };
|
|
15
|
+
// A link row's id is on the content inside its <a>, which is what takes focus
|
|
16
|
+
var rowEl = function (itemId) {
|
|
17
|
+
var _a;
|
|
18
|
+
var el = document.getElementById(rowId(itemId));
|
|
19
|
+
return (_a = el === null || el === void 0 ? void 0 : el.closest('a')) !== null && _a !== void 0 ? _a : el;
|
|
20
|
+
};
|
|
21
|
+
var stop = items.some(function (item) { return item.id === selectedId; }) ? selectedId : (_b = items[0]) === null || _b === void 0 ? void 0 : _b.id;
|
|
22
|
+
// When the open row is removed while it has focus, focus goes to the row now at its place, else the last
|
|
23
|
+
var focusedId = useRef(null);
|
|
24
|
+
var prev = useRef({ items: items, selectedId: selectedId });
|
|
25
|
+
useIsomorphicLayoutEffect(function () {
|
|
26
|
+
var _a;
|
|
27
|
+
var _b = prev.current, before = _b.items, was = _b.selectedId;
|
|
28
|
+
prev.current = { items: items, selectedId: selectedId };
|
|
29
|
+
if (was == null || items.some(function (item) { return item.id === was; }) || focusedId.current !== was)
|
|
30
|
+
return;
|
|
31
|
+
focusedId.current = null;
|
|
32
|
+
var active = document.activeElement;
|
|
33
|
+
if (active && active !== document.body)
|
|
34
|
+
return;
|
|
35
|
+
var at = before.findIndex(function (item) { return item.id === was; });
|
|
36
|
+
var next = items[Math.min(at, items.length - 1)];
|
|
37
|
+
if (next)
|
|
38
|
+
(_a = rowEl(next.id)) === null || _a === void 0 ? void 0 : _a.focus();
|
|
39
|
+
});
|
|
40
|
+
var onKeyDown = function (index) { return function (e) {
|
|
41
|
+
var _a;
|
|
42
|
+
var row = rowEl(items[index].id);
|
|
43
|
+
if (!row || e.target !== row || e.defaultPrevented || e.altKey || e.ctrlKey || e.metaKey)
|
|
44
|
+
return;
|
|
45
|
+
if (e.key === ' ') {
|
|
46
|
+
// A link does not click itself on Space, so click it here. A button row's MenuItem clicks itself and calls
|
|
47
|
+
// preventDefault first, so the defaultPrevented check above keeps it from clicking twice.
|
|
48
|
+
e.preventDefault();
|
|
49
|
+
row.click();
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
var count = items.length;
|
|
53
|
+
var to = e.key === 'ArrowDown' ? Math.min(index + 1, count - 1)
|
|
54
|
+
: e.key === 'ArrowUp' ? Math.max(index - 1, 0)
|
|
55
|
+
: nextIndex({ key: e.key, current: index, count: count, labels: items.map(function (item) { return item.label; }) });
|
|
56
|
+
if (!MOVE_KEYS.includes(e.key) && to === index)
|
|
57
|
+
return;
|
|
58
|
+
e.preventDefault();
|
|
59
|
+
if (to === index)
|
|
60
|
+
return;
|
|
61
|
+
(_a = rowEl(items[to].id)) === null || _a === void 0 ? void 0 : _a.focus();
|
|
62
|
+
var select = selectOnMove === 'md' ? window.matchMedia('(min-width: 768px)').matches : selectOnMove;
|
|
63
|
+
if (select)
|
|
64
|
+
onSelect(items[to].id, 'keyboard');
|
|
65
|
+
}; };
|
|
66
|
+
return (<Navigation aria-label={ariaLabel}>
|
|
67
|
+
{items.map(function (item, index) {
|
|
68
|
+
var selected = item.id === selectedId;
|
|
69
|
+
return (<div key={item.id} onKeyDown={onKeyDown(index)} onFocus={function () { return (focusedId.current = item.id); }} onBlur={function (e) {
|
|
70
|
+
// Focus that moves to another element leaves the row; a row removed from the page keeps its mark
|
|
71
|
+
if (e.relatedTarget)
|
|
72
|
+
focusedId.current = null;
|
|
73
|
+
}}
|
|
74
|
+
// Every activation is a click (Enter and Space too) and a link follows it, so it is never a 'keyboard' move
|
|
75
|
+
onClick={function () { return onSelect(item.id, 'pointer'); }}>
|
|
76
|
+
<MenuItem id={rowId(item.id)} href={item.href} role="button" label={item.label} secondLabel={item.secondLabel} tag={item.tag} userHandle={item.userHandle} userImgUrl={item.userImgUrl} isSelected={selected} aria-current={selected ? (item.href ? 'page' : true) : undefined} tabIndex={item.id === stop ? 0 : -1}/>
|
|
77
|
+
</div>);
|
|
78
|
+
})}
|
|
79
|
+
</Navigation>);
|
|
80
|
+
}
|
|
81
|
+
export { ItemList };
|
|
@@ -1,34 +1,58 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
export interface LightboxImage {
|
|
3
|
+
kind?: 'image';
|
|
3
4
|
src: string;
|
|
4
5
|
/** Required: it names the thumbnail, titles the viewer when there is no caption, and stands in for an image that fails. */
|
|
5
6
|
alt: string;
|
|
6
7
|
/** Shown under the image, and as the viewer's title. */
|
|
7
8
|
caption?: string;
|
|
8
9
|
}
|
|
10
|
+
/** A video played with the browser's own controls. It never starts by itself and its captions are on by default. */
|
|
11
|
+
export type LightboxVideo = {
|
|
12
|
+
kind: 'video';
|
|
13
|
+
src: string;
|
|
14
|
+
/** Shown before it plays, and as its thumbnail. */
|
|
15
|
+
poster: string;
|
|
16
|
+
/** Required: it names the video and its thumbnail, titles the viewer when there is no caption, and stands in for a video that fails. */
|
|
17
|
+
alt: string;
|
|
18
|
+
/** Shown under the video, and as the viewer's title. */
|
|
19
|
+
caption?: string;
|
|
20
|
+
/** Required: a WebVTT file, shown by default. */
|
|
21
|
+
captions: {
|
|
22
|
+
src: string;
|
|
23
|
+
srclang: string;
|
|
24
|
+
label: string;
|
|
25
|
+
};
|
|
26
|
+
};
|
|
27
|
+
export type LightboxItem = LightboxImage | LightboxVideo;
|
|
9
28
|
interface LightboxProps {
|
|
10
|
-
|
|
11
|
-
|
|
29
|
+
/** Images and videos, in order. */
|
|
30
|
+
images: LightboxItem[];
|
|
31
|
+
/** The item shown, counted from 0. */
|
|
12
32
|
index: number;
|
|
13
33
|
onIndexChange: (index: number) => void;
|
|
14
34
|
isOpen: boolean;
|
|
15
35
|
onClose: () => void;
|
|
16
|
-
/** Names the dialog. Defaults to 'Image viewer'. The visible title is the
|
|
36
|
+
/** Names the dialog. Defaults to 'Image viewer'. The visible title is the item's caption or alt text. */
|
|
17
37
|
'aria-label'?: string;
|
|
18
38
|
}
|
|
19
39
|
/**
|
|
20
|
-
* Images in a full-size Modal: the
|
|
21
|
-
* 'Previous image' and 'Next image'
|
|
40
|
+
* Images and videos in a full-size Modal: the item fits the viewport, its caption under it, and '2 of 5' after the
|
|
41
|
+
* title. 'Previous image' and 'Next image' ('Previous video' and 'Next video' when that neighbour is a video),
|
|
42
|
+
* ArrowLeft and ArrowRight, and a 40px swipe on touch step one item and stop at
|
|
22
43
|
* the ends; the Button at an end is disabled and focus moves to the other one, as Pagination does. Escape, the
|
|
23
|
-
* backdrop and Close close it, and the Modal gives focus back to what opened it.
|
|
44
|
+
* backdrop and Close close it, and the Modal gives focus back to what opened it. A video item plays with the browser's
|
|
45
|
+
* controls and its captions on; it never starts by itself, the arrows and a swipe on it are left to it, and it pauses
|
|
46
|
+
* when the viewer steps away or closes.
|
|
24
47
|
*/
|
|
25
48
|
export default function Lightbox({ images, index, onIndexChange, isOpen, onClose, 'aria-label': ariaLabel, }: LightboxProps): React.JSX.Element | null;
|
|
26
49
|
/**
|
|
27
|
-
* A thumbnail that opens the Lightbox: a button named 'Open image: <alt>' around a cropped Figure.
|
|
28
|
-
*
|
|
50
|
+
* A thumbnail that opens the Lightbox: a button named 'Open image: <alt>' around a cropped Figure. A video's thumbnail
|
|
51
|
+
* is its poster with a Play circle, named 'Play video: <alt>'. When the image or poster fails, a tile with 'Image not
|
|
52
|
+
* loaded' takes its place in the same box, and it still opens the viewer.
|
|
29
53
|
*/
|
|
30
54
|
export declare function LightboxThumbnail({ image, onOpen }: {
|
|
31
|
-
image:
|
|
55
|
+
image: LightboxItem;
|
|
32
56
|
onOpen: () => void;
|
|
33
57
|
}): React.JSX.Element;
|
|
34
58
|
export { Lightbox };
|
|
@@ -11,7 +11,7 @@ var __assign = (this && this.__assign) || function () {
|
|
|
11
11
|
return __assign.apply(this, arguments);
|
|
12
12
|
};
|
|
13
13
|
import React, { useEffect, useLayoutEffect, useRef, useState } from 'react';
|
|
14
|
-
import { ChevronLeft, ChevronRight, ImageOff, X } from 'lucide-react';
|
|
14
|
+
import { ChevronLeft, ChevronRight, ImageOff, Play, VideoOff, X } from 'lucide-react';
|
|
15
15
|
import Modal from './modal';
|
|
16
16
|
import IconButton from './iconButton';
|
|
17
17
|
import Icon from './icon';
|
|
@@ -21,10 +21,10 @@ import { formatCount } from './formatNumber';
|
|
|
21
21
|
import { focusRing } from './sharedStyles';
|
|
22
22
|
// useLayoutEffect warns during server rendering on React 18
|
|
23
23
|
var useIsomorphicLayoutEffect = typeof window !== 'undefined' ? useLayoutEffect : useEffect;
|
|
24
|
-
// A horizontal move this long on touch steps to the next or previous
|
|
24
|
+
// A horizontal move this long on touch steps to the next or previous item
|
|
25
25
|
var SWIPE_PX = 40;
|
|
26
|
-
// The image in its frame, or the words that stand in for it when it fails. Mounted per
|
|
27
|
-
// layout effect attaches the error listener before the browser can report a failure.
|
|
26
|
+
// The image or video in its frame, or the words that stand in for it when it fails. Mounted per item (keyed by src), so
|
|
27
|
+
// its layout effect attaches the error listener before the browser can report a failure.
|
|
28
28
|
function Frame(_a) {
|
|
29
29
|
var image = _a.image, broken = _a.broken, onBroken = _a.onBroken, onSwipe = _a.onSwipe;
|
|
30
30
|
var ref = useRef(null);
|
|
@@ -33,15 +33,24 @@ function Frame(_a) {
|
|
|
33
33
|
onBrokenRef.current = onBroken;
|
|
34
34
|
useIsomorphicLayoutEffect(function () {
|
|
35
35
|
var _a;
|
|
36
|
-
var
|
|
37
|
-
if (!
|
|
36
|
+
var media = (_a = ref.current) === null || _a === void 0 ? void 0 : _a.querySelector('img, video');
|
|
37
|
+
if (!media)
|
|
38
38
|
return;
|
|
39
39
|
var fail = function () { return onBrokenRef.current(); };
|
|
40
|
-
|
|
41
|
-
|
|
40
|
+
media.addEventListener('error', fail);
|
|
41
|
+
if (media instanceof HTMLVideoElement && media.error)
|
|
42
|
+
fail();
|
|
43
|
+
return function () {
|
|
44
|
+
media.removeEventListener('error', fail);
|
|
45
|
+
// A video stops when the viewer steps to another item
|
|
46
|
+
if (media instanceof HTMLVideoElement)
|
|
47
|
+
media.pause();
|
|
48
|
+
};
|
|
42
49
|
}, []);
|
|
50
|
+
var video = image.kind === 'video';
|
|
43
51
|
return (<div ref={ref} className="relative min-h-0 flex-1 touch-pan-y touch-pinch-zoom [&_img]:absolute [&_img]:inset-0 [&_img]:h-full [&_img]:w-full" onPointerDown={function (e) {
|
|
44
|
-
|
|
52
|
+
// A swipe that starts on a video is left to the video's controls
|
|
53
|
+
start.current = e.pointerType === 'touch' && !(e.target instanceof HTMLVideoElement) ? { x: e.clientX, y: e.clientY } : null;
|
|
45
54
|
}} onPointerUp={function (e) {
|
|
46
55
|
var s = start.current;
|
|
47
56
|
start.current = null;
|
|
@@ -55,20 +64,26 @@ function Frame(_a) {
|
|
|
55
64
|
start.current = null;
|
|
56
65
|
}}>
|
|
57
66
|
{broken ? (<div className="absolute inset-0 flex flex-col items-center justify-center gap-small rounded-control bg-background-panel p-large text-center">
|
|
58
|
-
<Icon icon={ImageOff} size="medium" color="disabled"/>
|
|
59
|
-
<p className="text-body1 text-fg-primary">This image could not be loaded
|
|
67
|
+
<Icon icon={video ? VideoOff : ImageOff} size="medium" color="disabled"/>
|
|
68
|
+
<p className="text-body1 text-fg-primary">{video ? 'This video could not be loaded.' : 'This image could not be loaded.'}</p>
|
|
60
69
|
<p className="text-body2 text-fg-secondary">{image.alt}</p>
|
|
61
|
-
</div>) : (<
|
|
70
|
+
</div>) : image.kind === 'video' ? (<video src={image.src} poster={image.poster} aria-label={image.alt} controls playsInline preload="metadata" className="absolute inset-0 m-auto max-h-full max-w-full object-contain">
|
|
71
|
+
<track kind="captions" src={image.captions.src} srcLang={image.captions.srclang} label={image.captions.label} default/>
|
|
72
|
+
</video>) : (<Image src={image.src} alt={image.alt} fit="contain"/>)}
|
|
62
73
|
</div>);
|
|
63
74
|
}
|
|
64
75
|
/**
|
|
65
|
-
* Images in a full-size Modal: the
|
|
66
|
-
* 'Previous image' and 'Next image'
|
|
76
|
+
* Images and videos in a full-size Modal: the item fits the viewport, its caption under it, and '2 of 5' after the
|
|
77
|
+
* title. 'Previous image' and 'Next image' ('Previous video' and 'Next video' when that neighbour is a video),
|
|
78
|
+
* ArrowLeft and ArrowRight, and a 40px swipe on touch step one item and stop at
|
|
67
79
|
* the ends; the Button at an end is disabled and focus moves to the other one, as Pagination does. Escape, the
|
|
68
|
-
* backdrop and Close close it, and the Modal gives focus back to what opened it.
|
|
80
|
+
* backdrop and Close close it, and the Modal gives focus back to what opened it. A video item plays with the browser's
|
|
81
|
+
* controls and its captions on; it never starts by itself, the arrows and a swipe on it are left to it, and it pauses
|
|
82
|
+
* when the viewer steps away or closes.
|
|
69
83
|
*/
|
|
70
84
|
export default function Lightbox(_a) {
|
|
71
|
-
var
|
|
85
|
+
var _b, _c;
|
|
86
|
+
var images = _a.images, index = _a.index, onIndexChange = _a.onIndexChange, isOpen = _a.isOpen, onClose = _a.onClose, _d = _a["aria-label"], ariaLabel = _d === void 0 ? 'Image viewer' : _d;
|
|
72
87
|
var count = images.length;
|
|
73
88
|
var at = Math.min(Math.max(index, 0), Math.max(count - 1, 0));
|
|
74
89
|
var image = images[at];
|
|
@@ -81,7 +96,7 @@ export default function Lightbox(_a) {
|
|
|
81
96
|
var pending = useRef(null);
|
|
82
97
|
var onChange = useRef(onIndexChange);
|
|
83
98
|
onChange.current = onIndexChange;
|
|
84
|
-
var
|
|
99
|
+
var _e = useState({}), broken = _e[0], setBroken = _e[1];
|
|
85
100
|
var go = function (to, from) {
|
|
86
101
|
if (to < 0 || to > count - 1 || to === at)
|
|
87
102
|
return;
|
|
@@ -105,7 +120,14 @@ export default function Lightbox(_a) {
|
|
|
105
120
|
return;
|
|
106
121
|
(_b = (p.focus === 'prev' ? prevRef : nextRef).current) === null || _b === void 0 ? void 0 : _b.focus();
|
|
107
122
|
}, [at]);
|
|
108
|
-
//
|
|
123
|
+
// A playing video stops as the viewer starts to close, not when it has faded out
|
|
124
|
+
useEffect(function () {
|
|
125
|
+
var _a, _b;
|
|
126
|
+
if (!isOpen)
|
|
127
|
+
(_b = (_a = viewRef.current) === null || _a === void 0 ? void 0 : _a.querySelector('video')) === null || _b === void 0 ? void 0 : _b.pause();
|
|
128
|
+
}, [isOpen]);
|
|
129
|
+
// ArrowLeft and ArrowRight step while focus is in this viewer, wherever it is in the dialog, except on a video, where
|
|
130
|
+
// they seek
|
|
109
131
|
useEffect(function () {
|
|
110
132
|
if (!isOpen || !many)
|
|
111
133
|
return;
|
|
@@ -115,6 +137,8 @@ export default function Lightbox(_a) {
|
|
|
115
137
|
return;
|
|
116
138
|
if (e.key !== 'ArrowLeft' && e.key !== 'ArrowRight')
|
|
117
139
|
return;
|
|
140
|
+
if (e.target instanceof HTMLVideoElement)
|
|
141
|
+
return;
|
|
118
142
|
var dialog = (_a = viewRef.current) === null || _a === void 0 ? void 0 : _a.closest('[role="dialog"]');
|
|
119
143
|
if (!dialog || !(e.target instanceof Node) || !dialog.contains(e.target))
|
|
120
144
|
return;
|
|
@@ -141,24 +165,27 @@ export default function Lightbox(_a) {
|
|
|
141
165
|
{image.caption && <figcaption aria-hidden="true" className="text-body2 text-fg-secondary">{image.caption}</figcaption>}
|
|
142
166
|
</figure>
|
|
143
167
|
{many && (<div className="flex shrink-0 items-center justify-between gap-medium">
|
|
144
|
-
<IconButton ref={prevRef} color="tertiary" size="large" state={atFirst ? 'disabled' : 'enabled'} icon={ChevronLeft} ariaLabel=
|
|
168
|
+
<IconButton ref={prevRef} color="tertiary" size="large" state={atFirst ? 'disabled' : 'enabled'} icon={ChevronLeft} ariaLabel={((_b = images[at - 1]) === null || _b === void 0 ? void 0 : _b.kind) === 'video' ? 'Previous video' : 'Previous image'} onClick={function () { return go(at - 1, 'prev'); }}/>
|
|
145
169
|
{/* The count is in the title; say it when it changes, as the title is not read again */}
|
|
146
170
|
<span className="sr-only" aria-live="polite" aria-atomic="true">{image.caption ? "".concat(image.caption, ". ").concat(image.alt, ", ").concat(of) : "".concat(image.alt, ", ").concat(of)}</span>
|
|
147
|
-
<IconButton ref={nextRef} color="tertiary" size="large" state={atLast ? 'disabled' : 'enabled'} icon={ChevronRight} ariaLabel=
|
|
171
|
+
<IconButton ref={nextRef} color="tertiary" size="large" state={atLast ? 'disabled' : 'enabled'} icon={ChevronRight} ariaLabel={((_c = images[at + 1]) === null || _c === void 0 ? void 0 : _c.kind) === 'video' ? 'Next video' : 'Next image'} onClick={function () { return go(at + 1, 'next'); }}/>
|
|
148
172
|
</div>)}
|
|
149
173
|
</div>
|
|
150
174
|
</Modal>);
|
|
151
175
|
}
|
|
152
176
|
/**
|
|
153
|
-
* A thumbnail that opens the Lightbox: a button named 'Open image: <alt>' around a cropped Figure.
|
|
154
|
-
*
|
|
177
|
+
* A thumbnail that opens the Lightbox: a button named 'Open image: <alt>' around a cropped Figure. A video's thumbnail
|
|
178
|
+
* is its poster with a Play circle, named 'Play video: <alt>'. When the image or poster fails, a tile with 'Image not
|
|
179
|
+
* loaded' takes its place in the same box, and it still opens the viewer.
|
|
155
180
|
*/
|
|
156
181
|
export function LightboxThumbnail(_a) {
|
|
157
182
|
var image = _a.image, onOpen = _a.onOpen;
|
|
158
183
|
var ref = useRef(null);
|
|
184
|
+
var video = image.kind === 'video';
|
|
185
|
+
var src = image.kind === 'video' ? image.poster : image.src;
|
|
159
186
|
// The src that failed, so a new src starts over and a late result for an old one changes nothing
|
|
160
187
|
var _b = useState(null), failedSrc = _b[0], setFailedSrc = _b[1];
|
|
161
|
-
var broken = failedSrc ===
|
|
188
|
+
var broken = failedSrc === src;
|
|
162
189
|
useIsomorphicLayoutEffect(function () {
|
|
163
190
|
var _a;
|
|
164
191
|
if (broken)
|
|
@@ -166,7 +193,6 @@ export function LightboxThumbnail(_a) {
|
|
|
166
193
|
var img = (_a = ref.current) === null || _a === void 0 ? void 0 : _a.querySelector('img');
|
|
167
194
|
if (!img)
|
|
168
195
|
return;
|
|
169
|
-
var src = image.src;
|
|
170
196
|
var live = true;
|
|
171
197
|
var fail = function () {
|
|
172
198
|
if (live)
|
|
@@ -193,13 +219,18 @@ export function LightboxThumbnail(_a) {
|
|
|
193
219
|
if (probe)
|
|
194
220
|
probe.onerror = null;
|
|
195
221
|
};
|
|
196
|
-
}, [
|
|
197
|
-
return (<button ref={ref} type="button" aria-label={"Open image: ".concat(image.alt)} onClick={onOpen} className={"block w-full cursor-zoom-in rounded-container transition-opacity hover:opacity-90 motion-reduce:transition-none ".concat(focusRing)}>
|
|
222
|
+
}, [src, broken]);
|
|
223
|
+
return (<button ref={ref} type="button" aria-label={video ? "Play video: ".concat(image.alt) : "Open image: ".concat(image.alt)} onClick={onOpen} className={"block w-full ".concat(video ? 'cursor-pointer' : 'cursor-zoom-in', " rounded-container transition-opacity hover:opacity-90 motion-reduce:transition-none ").concat(focusRing)}>
|
|
198
224
|
<Figure crop={4 / 3}>
|
|
199
225
|
{broken ? (<div className="absolute inset-0 flex flex-col items-center justify-center gap-small bg-background-panel p-small text-center">
|
|
200
226
|
<Icon icon={ImageOff} size="small" color="disabled"/>
|
|
201
227
|
<span className="text-caption text-fg-secondary">Image not loaded</span>
|
|
202
|
-
</div>) : (<Image src={
|
|
228
|
+
</div>) : (<Image src={src} alt=""/>)}
|
|
229
|
+
{video && !broken && (<span className="absolute inset-0 flex items-center justify-center">
|
|
230
|
+
<span className="rounded-full border-2 border-fg-primary bg-background-default p-small">
|
|
231
|
+
<Icon icon={Play} size="medium"/>
|
|
232
|
+
</span>
|
|
233
|
+
</span>)}
|
|
203
234
|
</Figure>
|
|
204
235
|
</button>);
|
|
205
236
|
}
|
|
@@ -30,7 +30,7 @@ interface MenuItemProps {
|
|
|
30
30
|
* list (mentions, commands) pass `aria-selected={isActive}` so it follows the highlighted row.
|
|
31
31
|
*/
|
|
32
32
|
'aria-selected'?: boolean;
|
|
33
|
-
/** Select keeps focus on its trigger and passes -1 */
|
|
33
|
+
/** Select keeps focus on its trigger and passes -1. On a link it goes on the `<a>`, and only when given. */
|
|
34
34
|
tabIndex?: number;
|
|
35
35
|
/** `danger` gives the label and the left icon the error text color, for Delete and the like. `isSelected` wins over it. */
|
|
36
36
|
color?: 'default' | 'danger';
|
|
@@ -7,7 +7,7 @@ import Tag from './tag';
|
|
|
7
7
|
import { focusRing, pressFeedbackAny, stateTransition } from './sharedStyles';
|
|
8
8
|
export default function MenuItem(_a) {
|
|
9
9
|
var _b;
|
|
10
|
-
var href = _a.href, iconName = _a.iconName, icon = _a.icon, userHandle = _a.userHandle, userImgUrl = _a.userImgUrl, label = _a.label, secondLabel = _a.secondLabel, isSelected = _a.isSelected, onClick = _a.onClick, _c = _a.className, className = _c === void 0 ? '' : _c, _d = _a.size, size = _d === void 0 ? 'medium' : _d, tag = _a.tag, iconRight = _a.iconRight, rightAction = _a.rightAction, _e = _a.role, role = _e === void 0 ? 'menuitem' : _e, id = _a.id, _f = _a.isActive, isActive = _f === void 0 ? false : _f, ariaSelected = _a["aria-selected"],
|
|
10
|
+
var href = _a.href, iconName = _a.iconName, icon = _a.icon, userHandle = _a.userHandle, userImgUrl = _a.userImgUrl, label = _a.label, secondLabel = _a.secondLabel, isSelected = _a.isSelected, onClick = _a.onClick, _c = _a.className, className = _c === void 0 ? '' : _c, _d = _a.size, size = _d === void 0 ? 'medium' : _d, tag = _a.tag, iconRight = _a.iconRight, rightAction = _a.rightAction, _e = _a.role, role = _e === void 0 ? 'menuitem' : _e, id = _a.id, _f = _a.isActive, isActive = _f === void 0 ? false : _f, ariaSelected = _a["aria-selected"], tabIndex = _a.tabIndex, _g = _a.color, color = _g === void 0 ? 'default' : _g, ariaCurrent = _a["aria-current"], ariaLabel = _a["aria-label"], ariaExpanded = _a["aria-expanded"], _h = _a.level, level = _h === void 0 ? 1 : _h;
|
|
11
11
|
// Size-based icon and text classes
|
|
12
12
|
var iconSize = { tiny: 'w-4 h-4', small: 'w-5 h-5', medium: 'w-6 h-6' }[size];
|
|
13
13
|
var labelClass = { tiny: 'text-caption', small: 'text-body2', medium: 'text-body1' }[size];
|
|
@@ -18,7 +18,7 @@ export default function MenuItem(_a) {
|
|
|
18
18
|
var danger = color === 'danger' && !isSelected;
|
|
19
19
|
var content = (<div id={id} role={href ? undefined : role}
|
|
20
20
|
// A link wrapper is already focusable; otherwise the row itself takes focus
|
|
21
|
-
tabIndex={href ? undefined : tabIndex} aria-selected={role === 'option' ? ariaSelected !== null && ariaSelected !== void 0 ? ariaSelected : !!isSelected : undefined} aria-checked={!href && role === 'menuitemradio' ? !!isSelected : undefined} aria-current={href ? undefined : ariaCurrent} aria-label={href ? undefined : ariaLabel} aria-expanded={href ? undefined : ariaExpanded} className={"\n flex items-center ".concat(paddingClass, " rounded-control cursor-pointer justify-between text-left ").concat(stateTransition, " ").concat(pressFeedbackAny, " ").concat(focusRing, "\n ").concat(isSelected
|
|
21
|
+
tabIndex={href ? undefined : tabIndex !== null && tabIndex !== void 0 ? tabIndex : 0} aria-selected={role === 'option' ? ariaSelected !== null && ariaSelected !== void 0 ? ariaSelected : !!isSelected : undefined} aria-checked={!href && role === 'menuitemradio' ? !!isSelected : undefined} aria-current={href ? undefined : ariaCurrent} aria-label={href ? undefined : ariaLabel} aria-expanded={href ? undefined : ariaExpanded} className={"\n flex items-center ".concat(paddingClass, " rounded-control cursor-pointer justify-between text-left ").concat(stateTransition, " ").concat(pressFeedbackAny, " ").concat(focusRing, "\n ").concat(isSelected
|
|
22
22
|
? 'bg-primary-dark text-primary-contrast'
|
|
23
23
|
: "hover:bg-background-accent200 ".concat(isActive ? 'bg-background-accent200' : ''), "\n ").concat(className, "\n ")} style={{ width: '100%' }} onClick={onClick} onKeyDown={function (e) {
|
|
24
24
|
if (!href && e.target === e.currentTarget && (e.key === 'Enter' || e.key === ' ')) {
|
|
@@ -50,6 +50,6 @@ export default function MenuItem(_a) {
|
|
|
50
50
|
</div>)}
|
|
51
51
|
</div>
|
|
52
52
|
</div>);
|
|
53
|
-
var row = href ? <NextLink href={href} aria-label={ariaLabel} aria-current={ariaCurrent} aria-expanded={ariaExpanded} className={"block rounded-control ".concat(focusRing)}>{content}</NextLink> : content;
|
|
53
|
+
var row = href ? <NextLink href={href} aria-label={ariaLabel} aria-current={ariaCurrent} aria-expanded={ariaExpanded} tabIndex={tabIndex} className={"block rounded-control ".concat(focusRing)}>{content}</NextLink> : content;
|
|
54
54
|
return level === 2 ? <div className="pl-6">{row}</div> : row;
|
|
55
55
|
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
export declare const MONTH_NAMES: string[];
|
|
2
|
+
/** Days in a month, `month` 1 to 12 */
|
|
3
|
+
export declare function daysInMonth(year: number, month: number): number;
|
|
4
|
+
/** 'M/D/YYYY', 'MM/DD/YYYY' or 'YYYY-MM-DD' to an ISO day; null for any other text or a day that does not exist */
|
|
5
|
+
export declare function parseTyped(text: string): string | null;
|
|
6
|
+
/** Whether the text is M/D/Y with a year of one to three digits, such as '11/16/26' */
|
|
7
|
+
export declare function shortYear(text: string): boolean;
|
|
8
|
+
/**
|
|
9
|
+
* Reads what was typed into a date field. Empty text is `{ value: '', error: null }`; text that is not a real date,
|
|
10
|
+
* or is outside `min`/`max`, is `{ value: '', error: <why> }`; a good date is its ISO day, its text as MM/DD/YYYY and no error.
|
|
11
|
+
*/
|
|
12
|
+
export declare function readTyped(text: string, min?: string, max?: string): {
|
|
13
|
+
value: string;
|
|
14
|
+
text: string;
|
|
15
|
+
error: string | null;
|
|
16
|
+
};
|
|
17
|
+
/** '2026-11-16' to '11/16/2026' */
|
|
18
|
+
export declare function toTyped(value: string): string;
|
|
19
|
+
/** '2026-11-16' to 'Nov 16, 2026' */
|
|
20
|
+
export declare function formatLong(value: string): string;
|
|
21
|
+
/** '2026-11-16' to 'November 2026' */
|
|
22
|
+
export declare function monthLabel(value: string): string;
|
|
23
|
+
export declare function addDays(value: string, n: number): string;
|
|
24
|
+
/** Moves by whole months and keeps the day, clamped to the last day of a shorter month (Jan 31 + 1 is Feb 28) */
|
|
25
|
+
export declare function addMonths(value: string, n: number): string;
|
|
26
|
+
/** ISO day strings sort as text */
|
|
27
|
+
export declare function compare(a: string, b: string): -1 | 0 | 1;
|
|
28
|
+
/** The user's own date, from the local clock */
|
|
29
|
+
export declare function todayIso(): string;
|
|
30
|
+
/** 0 for Sunday to 6 for Saturday */
|
|
31
|
+
export declare function weekday(value: string): number;
|
|
32
|
+
/** The month of `value` as weeks from Sunday to Saturday; `null` for the cells outside the month */
|
|
33
|
+
export declare function monthGrid(value: string): (string | null)[][];
|
|
34
|
+
/** Whether `value` is within `min` and `max` (either may be missing) */
|
|
35
|
+
export declare function inRange(value: string, min?: string, max?: string): boolean;
|