@milktop/react-ui 0.3.9 → 0.3.11

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.
@@ -35,8 +35,9 @@
35
35
  * Files, so on submit: new = items that are Files, kept = the rest, removed =
36
36
  * the saved ones no longer there.
37
37
  *
38
- * Clicking an image opens it large; other files open their `url`, if any, in
39
- * a new tab (see `onOpen`). Files with a `url` get a download button.
38
+ * Clicking an image opens it large, with arrows (and the arrow keys) to move
39
+ * through the others; other files open their `url`, if any, in a new tab (see
40
+ * `onOpen`). Files with a `url` get a download button.
40
41
  */
41
42
  import { type HTMLAttributes, type ReactNode } from 'react';
42
43
  import '../icons.js';
@@ -81,7 +82,7 @@ export type AttachmentsProps = Omit<HTMLAttributes<HTMLDivElement>, 'onDrop'> &
81
82
  name?: string;
82
83
  keptName?: string;
83
84
  disabled?: boolean;
84
- classes?: Classes<'root' | 'header' | 'label' | 'switch' | 'empty' | 'files' | 'file' | 'open' | 'thumb' | 'icon' | 'ext' | 'meta' | 'name' | 'size' | 'actions' | 'action' | 'addTile' | 'addInput' | 'addIcon' | 'addText' | 'addLabel' | 'limit' | 'rejected' | 'dropHint' | 'preview' | 'downloadLink'>;
85
+ classes?: Classes<'root' | 'header' | 'label' | 'switch' | 'empty' | 'files' | 'file' | 'open' | 'thumb' | 'icon' | 'ext' | 'meta' | 'name' | 'size' | 'actions' | 'action' | 'addTile' | 'addInput' | 'addIcon' | 'addText' | 'addLabel' | 'limit' | 'rejected' | 'dropHint' | 'stage' | 'preview' | 'step' | 'position' | 'downloadLink'>;
85
86
  };
86
87
  export declare const formatSize: (bytes: number, locale?: string) => string;
87
88
  export declare function Attachments({ items: itemsProp, defaultItems, onItemsChange, layout: layoutProp, defaultLayout, onLayoutChange, switchable, persist, columns, removable, addable, accept, maxFiles, maxFileSize, addLabel: addLabelProp, emptyText, onOpen, onRemove, onAdd, onReject, label, name, keptName, disabled: disabledProp, className, classes, style, ...rest }: AttachmentsProps): import("react").JSX.Element;
@@ -36,8 +36,9 @@ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-run
36
36
  * Files, so on submit: new = items that are Files, kept = the rest, removed =
37
37
  * the saved ones no longer there.
38
38
  *
39
- * Clicking an image opens it large; other files open their `url`, if any, in
40
- * a new tab (see `onOpen`). Files with a `url` get a download button.
39
+ * Clicking an image opens it large, with arrows (and the arrow keys) to move
40
+ * through the others; other files open their `url`, if any, in a new tab (see
41
+ * `onOpen`). Files with a `url` get a download button.
41
42
  */
42
43
  import { useEffect, useId, useMemo, useRef, useState } from 'react';
43
44
  import { createFileTypeValidator, getAcceptAttrString, getFileKey } from '@zag-js/file-utils';
@@ -223,17 +224,29 @@ export function Attachments({ items: itemsProp, defaultItems = [], onItemsChange
223
224
  return () => observer.disconnect();
224
225
  }, [layout, columns, list.length]);
225
226
  const addWide = layout === 'grid' && gridColumns > 0 && list.length > 0 && list.length % gridColumns === 0;
226
- const [previewing, setPreviewing] = useState(null);
227
+ const images = list.filter((entry) => entry.image && entry.url);
228
+ const [previewIndex, setPreviewIndex] = useState(0);
227
229
  const [previewOpen, setPreviewOpen] = useState(false);
230
+ const previewing = images[previewIndex];
231
+ const several = images.length > 1;
232
+ const step = (by) => setPreviewIndex((index) => (index + by + images.length) % images.length);
233
+ function previewKey(e) {
234
+ if (!several)
235
+ return;
236
+ if (e.key === 'ArrowLeft')
237
+ step(-1);
238
+ if (e.key === 'ArrowRight')
239
+ step(1);
240
+ }
228
241
  function open(entry) {
229
242
  if (onOpen?.(entry.item))
230
243
  return;
231
244
  if (entry.image && entry.url) {
232
- setPreviewing(entry);
245
+ setPreviewIndex(images.indexOf(entry));
233
246
  setPreviewOpen(true);
234
247
  }
235
248
  else if (entry.url)
236
249
  window.open(entry.url, '_blank', 'noopener');
237
250
  }
238
- return (_jsxs("div", { ...rest, ...part('root'), className: cx(className, classes?.root), ref: root, "data-layout": layout, "aria-labelledby": labelId, "aria-describedby": field?.ariaDescribedby, "aria-invalid": field?.invalid || undefined, "data-invalid": field?.invalid || undefined, "data-disabled": disabled || undefined, "data-empty": !list.length || undefined, "data-add-wide": addWide || undefined, "data-fixed": columns ? '' : undefined, style: { ...style, ...(columns && { '--columns': columns }) }, onDragEnter: dragOver, onDragOver: dragOver, onDragLeave: dragLeave, onDrop: dropped, role: "group", children: [((label && !field) || switchable) && (_jsxs("div", { ...part('header'), children: [label && !field && _jsx("span", { ...part('label'), id: labelId, children: label }), switchable && (_jsx(Segmented, { className: classes?.switch, size: "sm", iconOnly: true, "aria-label": t.attachments.layout, items: layouts, value: layout, onValueChange: (next) => next && setLayout(next) }))] })), name && _jsx("input", { ref: posted, type: "file", name: name, multiple: true, hidden: true, "aria-hidden": "true", tabIndex: -1 }), keptName && keptIds.map((kept) => _jsx("input", { type: "hidden", name: keptName, value: String(kept) }, String(kept))), !list.length && !addable && emptyText && _jsx("p", { ...part('empty'), children: emptyText }), _jsxs("ul", { ...part('files'), ref: filesEl, children: [list.map((entry, i) => (_jsxs("li", { ...part('file'), children: [_jsxs("button", { ...part('open'), type: "button", "aria-label": t.attachments.open(entry.name), onClick: () => open(entry), children: [_jsx("span", { ...part('thumb'), children: entry.thumb ? _jsx("img", { src: entry.thumb, alt: "", loading: "lazy" }) : _jsxs(_Fragment, { children: [_jsx("iconify-icon", { ...part('icon'), icon: entry.icon, "aria-hidden": "true" }), entry.ext && _jsx("span", { ...part('ext'), children: entry.ext })] }) }), _jsxs("span", { ...part('meta'), children: [_jsx("span", { ...part('name'), children: entry.name }), entry.size && _jsx("span", { ...part('size'), children: entry.size })] })] }), _jsxs("span", { ...part('actions'), children: [entry.url && (_jsx("a", { ...part('action'), href: entry.url, download: entry.name, "aria-label": t.attachments.downloadFile(entry.name), children: _jsx("iconify-icon", { icon: "lucide:download" }) })), removable && (_jsx("button", { ...part('action'), type: "button", "aria-label": t.common.remove(entry.name), onClick: () => remove(entry), children: _jsx("iconify-icon", { icon: "lucide:x" }) }))] })] }, i))), addable && !atMax && (_jsx("li", { ...part('file'), "data-add": "", children: _jsxs("label", { ...part('add-tile'), children: [_jsx("input", { ...part('add-input'), ...(field && { id: field.ids.control }), type: "file", multiple: maxFiles !== 1, ...(accept && { accept }), onChange: added }), _jsx("span", { ...part('add-icon'), children: _jsx("iconify-icon", { icon: "lucide:plus" }) }), _jsxs("span", { ...part('add-text'), children: [_jsx("span", { ...part('add-label'), children: addLabel }), !list.length && _jsx("span", { ...part('limit'), children: t.attachments.orDrop }), maxFiles && list.length > 0 && _jsx("span", { ...part('limit'), children: t.attachments.count(count, maxFiles) })] })] }) }))] }), rejected.length > 0 && (_jsx("ul", { ...part('rejected'), role: "alert", children: rejected.map((item, i) => _jsx("li", { children: t.attachments.notAdded(item.file.name, item.reason) }, i)) })), dragging && (_jsxs("div", { ...part('drop-hint'), "aria-hidden": "true", children: [_jsx("iconify-icon", { icon: "lucide:upload" }), _jsx("span", { children: atMax && maxFiles ? t.attachments.limit(maxFiles) : t.attachments.dropToAdd })] })), _jsx(Dialog, { size: "lg", heading: previewing?.name, open: previewOpen, onOpenChange: setPreviewOpen, footer: previewing && _jsx("a", { ...part('download-link'), href: previewing.url, download: previewing.name, children: t.attachments.download }), children: previewing && _jsx("img", { ...part('preview'), src: previewing.url, alt: previewing.name }) })] }));
251
+ return (_jsxs("div", { ...rest, ...part('root'), className: cx(className, classes?.root), ref: root, "data-layout": layout, "aria-labelledby": labelId, "aria-describedby": field?.ariaDescribedby, "aria-invalid": field?.invalid || undefined, "data-invalid": field?.invalid || undefined, "data-disabled": disabled || undefined, "data-empty": !list.length || undefined, "data-add-wide": addWide || undefined, "data-fixed": columns ? '' : undefined, style: { ...style, ...(columns && { '--columns': columns }) }, onDragEnter: dragOver, onDragOver: dragOver, onDragLeave: dragLeave, onDrop: dropped, role: "group", children: [((label && !field) || switchable) && (_jsxs("div", { ...part('header'), children: [label && !field && _jsx("span", { ...part('label'), id: labelId, children: label }), switchable && (_jsx(Segmented, { className: classes?.switch, size: "sm", iconOnly: true, "aria-label": t.attachments.layout, items: layouts, value: layout, onValueChange: (next) => next && setLayout(next) }))] })), name && _jsx("input", { ref: posted, type: "file", name: name, multiple: true, hidden: true, "aria-hidden": "true", tabIndex: -1 }), keptName && keptIds.map((kept) => _jsx("input", { type: "hidden", name: keptName, value: String(kept) }, String(kept))), !list.length && !addable && emptyText && _jsx("p", { ...part('empty'), children: emptyText }), _jsxs("ul", { ...part('files'), ref: filesEl, children: [list.map((entry, i) => (_jsxs("li", { ...part('file'), children: [_jsxs("button", { ...part('open'), type: "button", "aria-label": t.attachments.open(entry.name), onClick: () => open(entry), children: [_jsx("span", { ...part('thumb'), children: entry.thumb ? _jsx("img", { src: entry.thumb, alt: "", loading: "lazy" }) : _jsxs(_Fragment, { children: [_jsx("iconify-icon", { ...part('icon'), icon: entry.icon, "aria-hidden": "true" }), entry.ext && _jsx("span", { ...part('ext'), children: entry.ext })] }) }), _jsxs("span", { ...part('meta'), children: [_jsx("span", { ...part('name'), children: entry.name }), entry.size && _jsx("span", { ...part('size'), children: entry.size })] })] }), _jsxs("span", { ...part('actions'), children: [entry.url && (_jsx("a", { ...part('action'), href: entry.url, download: entry.name, "aria-label": t.attachments.downloadFile(entry.name), children: _jsx("iconify-icon", { icon: "lucide:download" }) })), removable && (_jsx("button", { ...part('action'), type: "button", "aria-label": t.common.remove(entry.name), onClick: () => remove(entry), children: _jsx("iconify-icon", { icon: "lucide:x" }) }))] })] }, i))), addable && !atMax && (_jsx("li", { ...part('file'), "data-add": "", children: _jsxs("label", { ...part('add-tile'), children: [_jsx("input", { ...part('add-input'), ...(field && { id: field.ids.control }), type: "file", multiple: maxFiles !== 1, ...(accept && { accept }), onChange: added }), _jsx("span", { ...part('add-icon'), children: _jsx("iconify-icon", { icon: "lucide:plus" }) }), _jsxs("span", { ...part('add-text'), children: [_jsx("span", { ...part('add-label'), children: addLabel }), !list.length && _jsx("span", { ...part('limit'), children: t.attachments.orDrop }), maxFiles && list.length > 0 && _jsx("span", { ...part('limit'), children: t.attachments.count(count, maxFiles) })] })] }) }))] }), rejected.length > 0 && (_jsx("ul", { ...part('rejected'), role: "alert", children: rejected.map((item, i) => _jsx("li", { children: t.attachments.notAdded(item.file.name, item.reason) }, i)) })), dragging && (_jsxs("div", { ...part('drop-hint'), "aria-hidden": "true", children: [_jsx("iconify-icon", { icon: "lucide:upload" }), _jsx("span", { children: atMax && maxFiles ? t.attachments.limit(maxFiles) : t.attachments.dropToAdd })] })), _jsx(Dialog, { size: "lg", heading: previewing?.name, open: previewOpen, onOpenChange: setPreviewOpen, onKeyDown: previewKey, footer: previewing && _jsxs(_Fragment, { children: [several && _jsxs("span", { ...part('position'), children: [previewIndex + 1, " / ", images.length] }), _jsx("a", { ...part('download-link'), href: previewing.url, download: previewing.name, children: t.attachments.download })] }), children: previewing && (_jsxs("div", { ...part('stage'), "data-several": several || undefined, children: [_jsx("img", { ...part('preview'), src: previewing.url, alt: previewing.name }), several && _jsxs(_Fragment, { children: [_jsx("button", { ...part('step'), "data-side": "previous", type: "button", "aria-label": t.attachments.previous, onClick: () => step(-1), children: _jsx("iconify-icon", { icon: "lucide:chevron-left" }) }), _jsx("button", { ...part('step'), "data-side": "next", type: "button", "aria-label": t.attachments.next, onClick: () => step(1), children: _jsx("iconify-icon", { icon: "lucide:chevron-right" }) })] })] })) })] }));
239
252
  }
@@ -79,7 +79,17 @@
79
79
  justify-content: center; gap: 0.375rem; border-radius: calc(var(--ui-radius) + 4px); border: 2px dashed var(--ui-accent);
80
80
  background: color-mix(in srgb, var(--ui-accent-soft) 85%, transparent); color: var(--ui-accent-soft-text); font-weight: 500; pointer-events: none; font-size: 20px;
81
81
  & span { font-size: 14px; } }
82
+ /* With several images it keeps one height, so the arrows stay put from image to image. */
83
+ [data-scope=attachments][data-part=stage] { position: relative;
84
+ &[data-several] { display: flex; align-items: center; justify-content: center; height: 70vh; } }
82
85
  [data-scope=attachments][data-part=preview] { display: block; max-width: 100%; max-height: 70vh; margin: 0 auto; border-radius: var(--ui-radius); }
86
+ [data-scope=attachments][data-part=step] { position: absolute; top: 50%; translate: 0 -50%; display: grid; place-items: center; width: 2.25rem; height: 2.25rem; padding: 0;
87
+ border: 1px solid var(--ui-border); border-radius: 50%; background: var(--ui-surface); color: var(--ui-text); cursor: pointer; font-size: 18px; box-shadow: var(--ui-card-shadow);
88
+ &:hover { background: var(--ui-hover); }
89
+ &:focus-visible { outline: 2px solid var(--ui-ring-soft); }
90
+ &[data-side=previous] { left: 0.5rem; }
91
+ &[data-side=next] { right: 0.5rem; } }
92
+ [data-scope=attachments][data-part=position] { margin-right: auto; align-self: center; font-size: 14px; color: var(--ui-muted); font-variant-numeric: tabular-nums; }
83
93
  [data-scope=attachments][data-part=download-link] { display: inline-flex; align-items: center; height: var(--ui-control-height-sm); padding: 0 0.75rem;
84
94
  border-radius: var(--ui-radius); border: 1px solid var(--ui-border); color: var(--ui-text); text-decoration: none; font-size: 14px;
85
95
  &:hover { background: var(--ui-hover); } }
@@ -9,9 +9,9 @@
9
9
  transition: background-color 120ms, border-color 120ms;
10
10
 
11
11
  &:hover { background: var(--ui-hover); }
12
- &:active { translate: 0 1px; }
12
+ &:active { filter: brightness(0.96); }
13
13
  &:focus-visible { outline: 2px solid var(--ui-ring-soft); border-color: var(--ui-ring); }
14
- &:disabled { opacity: 0.5; cursor: not-allowed; translate: none; }
14
+ &:disabled { opacity: 0.5; cursor: not-allowed; filter: none; }
15
15
 
16
16
  &[data-variant=primary] { background: var(--ui-accent); border-color: var(--ui-accent); color: var(--ui-accent-text);
17
17
  &:hover { filter: brightness(1.1); } }
@@ -25,7 +25,7 @@
25
25
  &[data-variant=link] { height: auto; padding: 0; background: transparent; border-color: transparent; color: var(--ui-accent);
26
26
  font-size: inherit; font-weight: inherit; line-height: inherit; white-space: normal; text-align: start;
27
27
  &:hover { background: transparent; text-decoration: underline; }
28
- &:active { translate: none; } }
28
+ &:active { filter: none; } }
29
29
 
30
30
  &[data-size=sm] { height: var(--ui-control-height-sm); padding: 0 0.625rem; font-size: 12px; gap: 0.375rem; }
31
31
  &[data-size=lg] { height: var(--ui-control-height-lg); padding: 0 1.25rem; font-size: 16px; }
@@ -23,11 +23,15 @@
23
23
  * `navigate`; by default a link is clicked
24
24
  * - `placeholder`, `emptyText`, `label`; `hints`: false hides the keyboard
25
25
  * hints along the bottom
26
+ * - `scope`: what the search is narrowed to, shown before the input (a pill,
27
+ * a menu); give it its own `load`, `items` and `placeholder`. A new `load`
28
+ * searches again for what's typed. `onScopeClear`: Backspace in the empty
29
+ * input
26
30
  *
27
31
  * `formatHotkey('k')` gives how the shortcut reads here ('⌘K' or 'Ctrl K'),
28
32
  * for a trigger's hint.
29
33
  */
30
- import { type ReactElement } from 'react';
34
+ import { type ReactElement, type ReactNode } from 'react';
31
35
  import { Dialog } from '@ark-ui/react/dialog';
32
36
  import '../icons.js';
33
37
  import { type Classes } from '../utils.js';
@@ -60,7 +64,9 @@ export type CommandProps = Omit<Dialog.ContentProps, 'onSelect'> & {
60
64
  emptyText?: string;
61
65
  loadingText?: string;
62
66
  hints?: boolean;
67
+ scope?: ReactNode;
68
+ onScopeClear?: () => void;
63
69
  classes?: Classes<'backdrop' | 'positioner' | 'content' | 'search' | 'searchIcon' | 'input' | 'list' | 'status' | 'group' | 'groupLabel' | 'item' | 'icon' | 'text' | 'label' | 'description' | 'shortcut' | 'hints' | 'key'>;
64
70
  };
65
71
  export declare function formatHotkey(key?: string): string;
66
- export declare function Command({ items, load, debounce, onSelect, trigger, open: openProp, defaultOpen, onOpenChange, hotkey, navigate, label: labelProp, placeholder: placeholderProp, emptyText: emptyTextProp, loadingText: loadingTextProp, hints, className, classes, ...rest }: CommandProps): import("react").JSX.Element;
72
+ export declare function Command({ items, load, debounce, onSelect, trigger, open: openProp, defaultOpen, onOpenChange, hotkey, navigate, label: labelProp, placeholder: placeholderProp, emptyText: emptyTextProp, loadingText: loadingTextProp, hints, scope, onScopeClear, className, classes, ...rest }: CommandProps): import("react").JSX.Element;
@@ -24,6 +24,10 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
24
24
  * `navigate`; by default a link is clicked
25
25
  * - `placeholder`, `emptyText`, `label`; `hints`: false hides the keyboard
26
26
  * hints along the bottom
27
+ * - `scope`: what the search is narrowed to, shown before the input (a pill,
28
+ * a menu); give it its own `load`, `items` and `placeholder`. A new `load`
29
+ * searches again for what's typed. `onScopeClear`: Backspace in the empty
30
+ * input
27
31
  *
28
32
  * `formatHotkey('k')` gives how the shortcut reads here ('⌘K' or 'Ctrl K'),
29
33
  * for a trigger's hint.
@@ -57,7 +61,7 @@ function go(href) {
57
61
  link.click();
58
62
  link.remove();
59
63
  }
60
- export function Command({ items = [], load = null, debounce = 200, onSelect, trigger = null, open: openProp, defaultOpen = false, onOpenChange, hotkey = 'k', navigate = null, label: labelProp, placeholder: placeholderProp, emptyText: emptyTextProp, loadingText: loadingTextProp, hints = true, className, classes, ...rest }) {
64
+ export function Command({ items = [], load = null, debounce = 200, onSelect, trigger = null, open: openProp, defaultOpen = false, onOpenChange, hotkey = 'k', navigate = null, label: labelProp, placeholder: placeholderProp, emptyText: emptyTextProp, loadingText: loadingTextProp, hints = true, scope = null, onScopeClear, className, classes, ...rest }) {
61
65
  const t = useMessages();
62
66
  const label = labelProp ?? t.command.label;
63
67
  const placeholder = placeholderProp ?? t.command.placeholder;
@@ -143,6 +147,22 @@ export function Command({ items = [], load = null, debounce = 200, onSelect, tri
143
147
  setLoaded([]);
144
148
  latestSearch.current('');
145
149
  }, [open]);
150
+ // A new scope's `load`: its results for what's typed, and back to the input
151
+ // (a menu in `scope` would otherwise keep the focus).
152
+ const latestQuery = useRef(query);
153
+ useEffect(() => { latestQuery.current = query; });
154
+ const firstLoad = useRef(load);
155
+ useEffect(() => {
156
+ if (load === firstLoad.current)
157
+ return;
158
+ firstLoad.current = load;
159
+ if (!open)
160
+ return;
161
+ setLoaded([]);
162
+ latestSearch.current(latestQuery.current);
163
+ const id = setTimeout(() => input.current?.focus(), 0);
164
+ return () => clearTimeout(id);
165
+ }, [load, open]);
146
166
  // The first result stays highlighted as the results change, so Enter picks it.
147
167
  const resultKeys = results.map(keyOf).join('\u0000');
148
168
  useEffect(() => {
@@ -163,7 +183,8 @@ export function Command({ items = [], load = null, debounce = 200, onSelect, tri
163
183
  addEventListener('keydown', keydown);
164
184
  return () => removeEventListener('keydown', keydown);
165
185
  }, [hotkey, open, setOpen]);
166
- return (_jsxs(Dialog.Root, { open: open, onOpenChange: (details) => setOpen(details.open), lazyMount: true, unmountOnExit: true, initialFocusEl: () => input.current, children: [trigger && _jsx(Dialog.Trigger, { asChild: true, children: trigger }), _jsxs(Portal, { children: [_jsx(Dialog.Backdrop, { ...part('backdrop') }), _jsx(Dialog.Positioner, { ...part('positioner'), children: _jsxs(Dialog.Content, { ...rest, ...part('content'), className: cx(className, classes?.content), children: [_jsx(Dialog.Title, { ...part('title'), hidden: true, children: label }), _jsxs(Listbox.RootProvider, { value: list, children: [_jsx(Listbox.Label, { hidden: true, children: label }), _jsxs("div", { ...part('search'), children: [_jsx("iconify-icon", { ...part('search-icon'), icon: "lucide:search", "aria-hidden": "true" }), _jsx(Listbox.Input, { ref: input, className: classes?.input, autoHighlight: true, type: "text", placeholder: placeholder, value: query, onChange: (e) => search(e.target.value) }), _jsx("kbd", { ...part('key'), "data-esc": "", children: t.command.esc })] }), _jsx(Listbox.Content, { ref: listEl, className: classes?.list, children: !results.length
186
+ return (_jsxs(Dialog.Root, { open: open, onOpenChange: (details) => setOpen(details.open), lazyMount: true, unmountOnExit: true, initialFocusEl: () => input.current, children: [trigger && _jsx(Dialog.Trigger, { asChild: true, children: trigger }), _jsxs(Portal, { children: [_jsx(Dialog.Backdrop, { ...part('backdrop') }), _jsx(Dialog.Positioner, { ...part('positioner'), children: _jsxs(Dialog.Content, { ...rest, ...part('content'), className: cx(className, classes?.content), children: [_jsx(Dialog.Title, { ...part('title'), hidden: true, children: label }), _jsxs(Listbox.RootProvider, { value: list, children: [_jsx(Listbox.Label, { hidden: true, children: label }), _jsxs("div", { ...part('search'), children: [_jsx("iconify-icon", { ...part('search-icon'), icon: "lucide:search", "aria-hidden": "true" }), scope, _jsx(Listbox.Input, { ref: input, className: classes?.input, autoHighlight: true, type: "text", placeholder: placeholder, value: query, onChange: (e) => search(e.target.value), onKeyDown: (e) => { if (e.key === 'Backspace' && !query)
187
+ onScopeClear?.(); } }), _jsx("kbd", { ...part('key'), "data-esc": "", children: t.command.esc })] }), _jsx(Listbox.Content, { ref: listEl, className: classes?.list, children: !results.length
167
188
  ? _jsx("div", { ...part('status'), children: loading ? loadingText : emptyText })
168
189
  : groups.map((group) => (_jsxs(Listbox.ItemGroup, { className: classes?.group, children: [group.name && _jsx(Listbox.ItemGroupLabel, { className: classes?.groupLabel, children: group.name }), group.items.map((item) => (_jsxs(Listbox.Item, { item: item, highlightOnHover: true, className: classes?.item, children: [item.icon && _jsx("iconify-icon", { ...part('icon'), icon: item.icon, "aria-hidden": "true" }), _jsxs("span", { ...part('text'), children: [_jsx("span", { ...part('label'), children: item.label }), item.description && _jsx("span", { ...part('description'), children: item.description })] }), item.shortcut && _jsx("kbd", { ...part('shortcut'), children: item.shortcut })] }, keyOf(item))))] }, group.name))) }), hints && (_jsxs("div", { ...part('hints'), "aria-hidden": "true", children: [_jsxs("span", { children: [_jsx("kbd", { ...part('key'), children: "\u2191" }), _jsx("kbd", { ...part('key'), children: "\u2193" }), " ", t.command.toNavigate] }), _jsxs("span", { children: [_jsx("kbd", { ...part('key'), children: "\u21B5" }), " ", t.command.toSelect] })] }))] })] }) })] })] }));
169
190
  }
@@ -190,6 +190,8 @@ export type Messages = {
190
190
  orDrop: string;
191
191
  dropToAdd: string;
192
192
  download: string;
193
+ previous: string;
194
+ next: string;
193
195
  open: (name: string) => string;
194
196
  downloadFile: (name: string) => string;
195
197
  count: (count: number, max: number) => string;
@@ -60,7 +60,7 @@ export const en = {
60
60
  reasons: { FILE_INVALID_TYPE: 'Not an allowed type', FILE_TOO_LARGE: 'Too large', TOO_MANY_FILES: 'Too many files', FILE_TOO_SMALL: 'Too small' },
61
61
  },
62
62
  attachments: {
63
- add: 'Add files', layout: 'Layout', grid: 'Grid', list: 'List', orDrop: 'or drop files here', dropToAdd: 'Drop to add', download: 'Download',
63
+ add: 'Add files', layout: 'Layout', grid: 'Grid', list: 'List', orDrop: 'or drop files here', dropToAdd: 'Drop to add', download: 'Download', previous: 'Previous image', next: 'Next image',
64
64
  open: (name) => `Open ${name}`, downloadFile: (name) => `Download ${name}`,
65
65
  count: (count, max) => `${count} of ${max}`, limit: (max) => `The limit is ${max} files`,
66
66
  notType: 'not an accepted type', over: (size) => `over ${size}`, notAdded: (name, reason) => `${name} wasn’t added: ${reason}.`,
@@ -150,7 +150,7 @@ export const fr = {
150
150
  },
151
151
  attachments: {
152
152
  add: 'Ajouter des fichiers', layout: 'Affichage', grid: 'Grille', list: 'Liste', orDrop: 'ou déposez des fichiers ici',
153
- dropToAdd: 'Déposez pour ajouter', download: 'Télécharger',
153
+ dropToAdd: 'Déposez pour ajouter', download: 'Télécharger', previous: 'Image précédente', next: 'Image suivante',
154
154
  open: (name) => `Ouvrir ${name}`, downloadFile: (name) => `Télécharger ${name}`,
155
155
  count: (count, max) => `${count} sur ${max}`, limit: (max) => `La limite est de ${max} fichiers`,
156
156
  notType: 'type non accepté', over: (size) => `plus de ${size}`, notAdded: (name, reason) => `${name} n’a pas été ajouté : ${reason}.`,
@@ -11,7 +11,7 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
11
11
  * - `maxRows`: grow up to this many lines, then scroll
12
12
  * - `autogrow`: false for a fixed height the user can resize
13
13
  */
14
- import { useCallback, useId, useLayoutEffect, useRef } from 'react';
14
+ import { useCallback, useEffect, useId, useLayoutEffect, useRef } from 'react';
15
15
  import { Field, useFieldContext } from '@ark-ui/react/field';
16
16
  import { cx, partsOf } from '../utils.js';
17
17
  import '../theme.css';
@@ -22,10 +22,11 @@ export function Textarea({ label = null, rows = 3, maxRows = null, autogrow = tr
22
22
  const ownId = useId();
23
23
  const id = rest.id ?? `${ownId}-textarea`;
24
24
  const el = useRef(null);
25
- // Fits the height to the content, capped at maxRows.
25
+ // Fits the height to the content, capped at maxRows. Not while it isn't laid out (in a closed
26
+ // popover, a hidden tab): it would measure 0 and stay flat.
26
27
  const fit = useCallback(() => {
27
28
  const area = el.current;
28
- if (!autogrow || !area)
29
+ if (!autogrow || !area || !area.clientWidth)
29
30
  return;
30
31
  const line = parseFloat(getComputedStyle(area).lineHeight);
31
32
  const max = maxRows ? line * maxRows : Infinity;
@@ -34,6 +35,21 @@ export function Textarea({ label = null, rows = 3, maxRows = null, autogrow = tr
34
35
  area.style.overflowY = area.scrollHeight > max ? 'auto' : 'hidden';
35
36
  }, [autogrow, maxRows]);
36
37
  useLayoutEffect(fit, [fit, value]);
38
+ // Again when its width changes: once it's shown, and when the lines rewrap.
39
+ useEffect(() => {
40
+ const area = el.current;
41
+ if (!autogrow || !area)
42
+ return;
43
+ let width = area.clientWidth;
44
+ const observer = new ResizeObserver(() => {
45
+ if (area.clientWidth === width)
46
+ return;
47
+ width = area.clientWidth;
48
+ fit();
49
+ });
50
+ observer.observe(area);
51
+ return () => observer.disconnect();
52
+ }, [autogrow, fit]);
37
53
  function change(e) {
38
54
  onChange?.(e);
39
55
  onValueChange?.(e.target.value);
@@ -33,7 +33,10 @@ import '../theme.css';
33
33
  import './tooltip.css';
34
34
  function TooltipShortcut({ content = null, placement = 'top', openDelay = 0, closeDelay, interactive = false, disabled = false, open, defaultOpen, onOpenChange, className, classes, children, ...rest }) {
35
35
  const part = partsOf('tooltip', classes);
36
- return (_jsxs(Ark.Root, { openDelay: openDelay, interactive: interactive, disabled: disabled, lazyMount: true, unmountOnExit: true, positioning: { placement, strategy: 'fixed', gutter: 8 }, ...(closeDelay !== undefined && { closeDelay }), ...(open !== undefined && { open }), ...(defaultOpen !== undefined && { defaultOpen }), ...on('onOpenChange', onOpenChange, (details) => details.open), children: [isValidElement(children) && !children.props.disabled
36
+ const anchored = isValidElement(children) && !children.props.disabled;
37
+ // A trigger that's already another's (a menu's, a popover's) keeps that one's id: the tooltip finds it by it
38
+ const triggerId = anchored ? children.props.id : undefined;
39
+ return (_jsxs(Ark.Root, { openDelay: openDelay, ...(triggerId && { ids: { trigger: triggerId } }), interactive: interactive, disabled: disabled, lazyMount: true, unmountOnExit: true, positioning: { placement, strategy: 'fixed', gutter: 8 }, ...(closeDelay !== undefined && { closeDelay }), ...(open !== undefined && { open }), ...(defaultOpen !== undefined && { defaultOpen }), ...on('onOpenChange', onOpenChange, (details) => details.open), children: [anchored
37
40
  ? _jsx(Ark.Trigger, { asChild: true, children: children })
38
41
  : _jsx(Ark.Trigger, { asChild: true, children: _jsx("span", { ...part('trigger'), children: children }) }), _jsx(Portal, { children: _jsx(Ark.Positioner, { ...part('positioner'), children: _jsxs(Ark.Content, { ...rest, ...part('content'), className: cx(className, classes?.content), children: [_jsx(Ark.Arrow, { ...part('arrow'), children: _jsx(Ark.ArrowTip, { ...part('arrow-tip') }) }), content] }) }) })] }));
39
42
  }
@@ -2,9 +2,9 @@
2
2
  [data-scope=tooltip][data-part=trigger] { display: inline-flex; }
3
3
  /* The positioner carries the z-index itself. Zag sets it inline as
4
4
  var(--z-index) but doesn't always fill in the variable, so set both. */
5
- [data-scope=tooltip][data-part=positioner] { z-index: 60; --z-index: 60; }
5
+ [data-scope=tooltip][data-part=positioner] { z-index: 110; --z-index: 110; } /* above dialogs and sheets (100) */
6
6
  [data-scope=tooltip][data-part=content] {
7
- z-index: 60; max-width: 16rem; padding: 0.25rem 0.5rem; white-space: normal; font-weight: 400;
7
+ z-index: 110; max-width: 16rem; padding: 0.25rem 0.5rem; white-space: normal; font-weight: 400;
8
8
  background: var(--ui-text); color: var(--ui-surface); font-family: var(--ui-font); font-size: 12px; line-height: 1.4;
9
9
  border-radius: calc(var(--ui-radius) - 2px); box-shadow: var(--ui-shadow);
10
10
  --arrow-size: 8px; --arrow-background: var(--ui-text);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@milktop/react-ui",
3
- "version": "0.3.9",
3
+ "version": "0.3.11",
4
4
  "description": "React components on Ark UI (Zag state machines), with imba-ui's API and design",
5
5
  "license": "MIT",
6
6
  "author": "André Goldstein",