@milktop/react-ui 0.3.30 → 0.3.31

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.
@@ -36,14 +36,16 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
36
36
  * TableRow, TableCell, TableCellTrigger, with DatePicker.Context for the
37
37
  * weeks, months and years to lay out.
38
38
  */
39
- import { Fragment, useId, useMemo, useState } from 'react';
39
+ import { Fragment, useContext, useId, useMemo, useState } from 'react';
40
40
  import { DatePicker as Ark, parseDate, useDatePicker } from '@ark-ui/react/date-picker';
41
41
  import { useFieldContext } from '@ark-ui/react/field';
42
+ import { Portal } from '@ark-ui/react/portal';
42
43
  import { DateFormatter, getLocalTimeZone, today } from '@internationalized/date';
43
44
  import { parseDateString } from '@zag-js/date-utils';
44
45
  import '../icons.js';
45
46
  import { useLocale, useMessages } from '../format/LocaleProvider.js';
46
47
  import { cx, partsOf, useControllable, withParts } from '../utils.js';
48
+ import { InLayer } from '../layer.js';
47
49
  import '../theme.css';
48
50
  import './date-picker.css';
49
51
  // Zag formats the input when the picker starts: a new locale (say, from the
@@ -105,13 +107,16 @@ function DatePickerInner(props) {
105
107
  setCurrent(next);
106
108
  onValueChange?.(next, details);
107
109
  }
110
+ // Opened from a dialog or sheet, it shows on top of it (as Popover does)
111
+ const inLayer = useContext(InLayer);
112
+ const layered = inLayer && !inline ? { 'data-layered': '' } : {};
108
113
  const picker = useDatePicker({
109
114
  locale, selectionMode: range ? 'range' : 'single',
110
115
  value: [].concat(current ?? []).filter((iso) => !!iso).map((iso) => parseDate(iso)),
111
116
  onValueChange: change,
112
117
  ...(min && { min: parseDate(min) }), ...(max && { max: parseDate(max) }),
113
118
  ...(unavailable && { isDateUnavailable: unavailable }),
114
- positioning: { placement },
119
+ positioning: { placement, strategy: 'fixed' },
115
120
  ...(t.zag.datePicker && { translations: t.zag.datePicker }),
116
121
  ...(inline && { inline: true }),
117
122
  // Inside a Field, its label points at the first input.
@@ -201,12 +206,12 @@ function DatePickerInner(props) {
201
206
  picker.setValue(values);
202
207
  }
203
208
  const view = picker.view;
204
- const content = (_jsx(Ark.Content, { ...part('content'), children: _jsxs(Ark.View, { view: view, ...part('view'), children: [_jsxs(Ark.ViewControl, { ...part('view-control'), children: [prev ? _jsx(Ark.PrevTrigger, { asChild: true, children: prev })
209
+ const content = (_jsx(Ark.Content, { ...part('content'), ...layered, children: _jsxs(Ark.View, { view: view, ...part('view'), children: [_jsxs(Ark.ViewControl, { ...part('view-control'), children: [prev ? _jsx(Ark.PrevTrigger, { asChild: true, children: prev })
205
210
  : _jsx(Ark.PrevTrigger, { ...part('prev-trigger'), children: _jsx("iconify-icon", { icon: "lucide:chevron-left" }) }), _jsx(Ark.ViewTrigger, { ...part('view-trigger'), children: view === 'day' ? picker.visibleRangeText.start
206
211
  : view === 'month' ? picker.visibleRange.start.year
207
212
  : `${picker.getDecade().start} – ${picker.getDecade().end}` }), next ? _jsx(Ark.NextTrigger, { asChild: true, children: next })
208
213
  : _jsx(Ark.NextTrigger, { ...part('next-trigger'), children: _jsx("iconify-icon", { icon: "lucide:chevron-right" }) })] }), view === 'day' && (_jsxs(Ark.Table, { ...part('table'), children: [_jsx(Ark.TableHead, { children: _jsx(Ark.TableRow, { children: picker.weekDays.map((day, i) => _jsx(Ark.TableHeader, { ...part('table-header'), "aria-label": day.long, children: day.narrow }, i)) }) }), _jsx(Ark.TableBody, { children: picker.weeks.map((week, i) => (_jsx(Ark.TableRow, { children: week.map((date) => (_jsx(Ark.TableCell, { value: date, ...part('table-cell'), children: _jsx(Ark.TableCellTrigger, { ...part('table-cell-trigger'), children: date.day }) }, date.toString()))) }, i))) })] })), view === 'month' && (_jsx(Ark.Table, { columns: 4, ...part('table'), children: _jsx(Ark.TableBody, { children: picker.getMonthsGrid({ columns: 4, format: 'short' }).map((row, i) => (_jsx(Ark.TableRow, { children: row.map((month) => (_jsx(Ark.TableCell, { value: month.value, columns: 4, ...part('table-cell'), children: _jsx(Ark.TableCellTrigger, { ...part('table-cell-trigger'), "data-wide": "", children: month.label }) }, month.value))) }, i))) }) })), view === 'year' && (_jsx(Ark.Table, { columns: 4, ...part('table'), children: _jsx(Ark.TableBody, { children: picker.getYearsGrid({ columns: 4 }).map((row, i) => (_jsx(Ark.TableRow, { children: row.map((year) => (_jsx(Ark.TableCell, { value: year.value, columns: 4, ...part('table-cell'), children: _jsx(Ark.TableCellTrigger, { ...part('table-cell-trigger'), "data-wide": "", children: year.label }) }, year.value))) }, i))) }) }))] }) }));
209
- return (_jsxs(Ark.RootProvider, { value: picker, ...rest, ...part('root'), className: cx(className, classes?.root), "data-inline": inline || undefined, children: [label && !field && _jsx(Ark.Label, { ...part('label'), children: label }), !inline && _jsxs(Ark.Control, { ...part('control'), children: [(range ? [0, 1] : [0]).map((index) => _jsxs(Fragment, { children: [index === 1 && _jsx("span", { ...part('separator'), children: "\u2013" }), _jsx(Ark.Input, { index: index, ...part('input'), size: 10, fixOnBlur: false, "data-error-for": errorId, onKeyDownCapture: (e) => step(e, index), onInputCapture: (e) => separate(e, pattern), onBlur: (e) => commit(e.currentTarget, index), "aria-invalid": problem?.index === index || undefined, "aria-describedby": [field?.ariaDescribedby, problem?.index === index && errorId].filter(Boolean).join(' ') || undefined })] }, index)), _jsx(Ark.ClearTrigger, { ...part('clear-trigger'), onClick: () => report(null), children: _jsx("iconify-icon", { icon: "lucide:x" }) }), _jsx(Ark.Trigger, { ...part('trigger'), children: _jsx("iconify-icon", { icon: "lucide:calendar" }) })] }), problem && !inline && _jsx("div", { ...part('error'), id: errorId, role: "alert", children: problem.reason }), inline ? content : _jsx(Ark.Positioner, { ...part('positioner'), children: content })] }));
214
+ return (_jsxs(Ark.RootProvider, { value: picker, ...rest, ...part('root'), className: cx(className, classes?.root), "data-inline": inline || undefined, children: [label && !field && _jsx(Ark.Label, { ...part('label'), children: label }), !inline && _jsxs(Ark.Control, { ...part('control'), children: [(range ? [0, 1] : [0]).map((index) => _jsxs(Fragment, { children: [index === 1 && _jsx("span", { ...part('separator'), children: "\u2013" }), _jsx(Ark.Input, { index: index, ...part('input'), size: 10, fixOnBlur: false, "data-error-for": errorId, onKeyDownCapture: (e) => step(e, index), onInputCapture: (e) => separate(e, pattern), onBlur: (e) => commit(e.currentTarget, index), "aria-invalid": problem?.index === index || undefined, "aria-describedby": [field?.ariaDescribedby, problem?.index === index && errorId].filter(Boolean).join(' ') || undefined })] }, index)), _jsx(Ark.ClearTrigger, { ...part('clear-trigger'), onClick: () => report(null), children: _jsx("iconify-icon", { icon: "lucide:x" }) }), _jsx(Ark.Trigger, { ...part('trigger'), children: _jsx("iconify-icon", { icon: "lucide:calendar" }) })] }), problem && !inline && _jsx("div", { ...part('error'), id: errorId, role: "alert", children: problem.reason }), inline ? content : _jsx(Portal, { children: _jsx(Ark.Positioner, { ...part('positioner'), ...layered, children: content }) })] }));
210
215
  }
211
216
  export const DatePicker = withParts(DatePickerShortcut, {
212
217
  Root: Ark.Root,
@@ -27,6 +27,10 @@
27
27
  /* The positioner carries the z-index itself. Zag sets it inline as
28
28
  var(--z-index) but doesn't always fill in the variable, so set both. */
29
29
  [data-scope=date-picker][data-part=positioner] { z-index: 50; --z-index: 50; }
30
+ /* Opened from a dialog or sheet (100): above it, below tooltips (110). Zag copies the content's
31
+ z-index onto the positioner when it opens, numbering each open layer (--layer-index). */
32
+ [data-scope=date-picker][data-part=positioner][data-layered] { z-index: 105; --z-index: 105; }
33
+ [data-scope=date-picker][data-part=content][data-layered] { z-index: calc(105 + var(--layer-index, 0)); }
30
34
  [data-scope=date-picker][data-part=content] { z-index: 50; padding: 0.75rem; background: var(--ui-surface); outline: none;
31
35
  border: 1px solid var(--ui-border); border-radius: calc(var(--ui-radius) + 2px); box-shadow: var(--ui-shadow);
32
36
  /* An inline calendar in a popover (EventCalendar's date jump): the popover is the card. */
@@ -1,12 +1,14 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  // Select without search: a button that opens the list. Used by Select.tsx,
3
3
  // which documents the props.
4
- import { Fragment, useMemo, useRef } from 'react';
4
+ import { Fragment, useContext, useMemo, useRef } from 'react';
5
5
  import { Select as Ark, createListCollection, useSelect } from '@ark-ui/react/select';
6
6
  import { useFieldContext } from '@ark-ui/react/field';
7
+ import { Portal } from '@ark-ui/react/portal';
7
8
  import '../icons.js';
8
9
  import { cx, partsOf, slot } from '../utils.js';
9
10
  import { useMessages } from '../format/LocaleProvider.js';
11
+ import { InLayer } from '../layer.js';
10
12
  import { useItems } from './items.js';
11
13
  import '../theme.css';
12
14
  import './select.css';
@@ -45,9 +47,11 @@ searchable: _searchable, load: _load, debounce: _debounce, loadingText: _loading
45
47
  }
46
48
  const select = useSelect({
47
49
  collection, value: keys, onValueChange: change, onOpenChange: openChange, multiple, deselectable, closeOnSelect: closeOnSelect ?? !multiple, disabled,
48
- positioning: { placement, sameWidth: true }, ...(name && { name }),
50
+ positioning: { placement, sameWidth: true, strategy: 'fixed' }, ...(name && { name }),
49
51
  ...(t.zag.select && { translations: t.zag.select }),
50
52
  });
53
+ // Opened from a dialog or sheet, it shows on top of it (as Popover does)
54
+ const layered = useContext(InLayer) ? { 'data-layered': '' } : {};
51
55
  // The latest api, for the timers below.
52
56
  const api = useRef(select);
53
57
  api.current = select;
@@ -78,5 +82,5 @@ searchable: _searchable, load: _load, debounce: _debounce, loadingText: _loading
78
82
  : renderValue && select.hasSelectedItems
79
83
  // Your rendering of the chosen item(s), in place of Ark's text.
80
84
  ? _jsx("span", { ...part('value-text'), children: select.selectedItems.map((item, i) => _jsxs(Fragment, { children: [i > 0 && ', ', renderValue(item)] }, keyOf(item))) })
81
- : _jsx(Ark.ValueText, { ...part('value-text'), placeholder: placeholder }), _jsx(Ark.Indicator, { ...part('indicator'), children: _jsx("iconify-icon", { icon: "lucide:chevron-down" }) })] }), clearable && _jsx(Ark.ClearTrigger, { ...part('clear-trigger'), children: _jsx("iconify-icon", { icon: "lucide:x" }) })] }), _jsx(Ark.Positioner, { ...part('positioner'), children: _jsxs(Ark.Content, { ...part('content'), children: [listed.map((item) => (_jsxs(Ark.Item, { item: item, ...part('item'), children: [_jsx(Ark.ItemText, { ...part('item-text'), children: renderItem ? renderItem(item, { selected: keys.includes(keyOf(item)) }) : labelOf(item) }), _jsx(Ark.ItemIndicator, { ...part('item-indicator'), children: _jsx("iconify-icon", { icon: "lucide:check" }) })] }, keyOf(item)))), !listed.length && _jsx("div", { ...part('empty'), children: slot(empty, emptyText, { query: '' }) })] }) }), _jsx(Ark.HiddenSelect, {})] }));
85
+ : _jsx(Ark.ValueText, { ...part('value-text'), placeholder: placeholder }), _jsx(Ark.Indicator, { ...part('indicator'), children: _jsx("iconify-icon", { icon: "lucide:chevron-down" }) })] }), clearable && _jsx(Ark.ClearTrigger, { ...part('clear-trigger'), children: _jsx("iconify-icon", { icon: "lucide:x" }) })] }), _jsx(Portal, { children: _jsx(Ark.Positioner, { ...part('positioner'), ...layered, children: _jsxs(Ark.Content, { ...part('content'), ...layered, children: [listed.map((item) => (_jsxs(Ark.Item, { item: item, ...part('item'), children: [_jsx(Ark.ItemText, { ...part('item-text'), children: renderItem ? renderItem(item, { selected: keys.includes(keyOf(item)) }) : labelOf(item) }), _jsx(Ark.ItemIndicator, { ...part('item-indicator'), children: _jsx("iconify-icon", { icon: "lucide:check" }) })] }, keyOf(item)))), !listed.length && _jsx("div", { ...part('empty'), children: slot(empty, emptyText, { query: '' }) })] }) }) }), _jsx(Ark.HiddenSelect, {})] }));
82
86
  }
@@ -1,12 +1,14 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
2
2
  // Select with search: an input that filters the list, loads it, or creates
3
3
  // items. Used by Select.tsx, which documents the props.
4
- import { useEffect, useMemo, useRef, useState } from 'react';
4
+ import { useContext, useEffect, useMemo, useRef, useState } from 'react';
5
5
  import { Combobox as Ark, createListCollection, useCombobox, } from '@ark-ui/react/combobox';
6
6
  import { useFieldContext } from '@ark-ui/react/field';
7
+ import { Portal } from '@ark-ui/react/portal';
7
8
  import '../icons.js';
8
9
  import { cx, partOf, partsOf, slot } from '../utils.js';
9
10
  import { useMessages } from '../format/LocaleProvider.js';
11
+ import { InLayer } from '../layer.js';
10
12
  import { useItems } from './items.js';
11
13
  import '../theme.css';
12
14
  import './search-select.css';
@@ -116,12 +118,14 @@ searchable: _searchable, tags: _tags, deselectable: _deselectable, className, cl
116
118
  keepPlace(details.value);
117
119
  setCurrent(multiple ? chosen : chosen[0] ?? null);
118
120
  }
121
+ // Opened from a dialog or sheet, it shows on top of it (as Popover does)
122
+ const layered = useContext(InLayer) ? { 'data-layered': '' } : {};
119
123
  const combobox = useCombobox({
120
124
  collection, value: keys, onValueChange: change, onInputValueChange: inputChange,
121
125
  multiple, disabled, placeholder, openOnClick: true, inputBehavior: 'autohighlight',
122
126
  ...(t.zag.combobox && { translations: t.zag.combobox }),
123
127
  closeOnSelect: closeOnSelect ?? !multiple, selectionBehavior: multiple ? 'clear' : 'replace',
124
- positioning: { placement, sameWidth: true }, ...(name && { name }),
128
+ positioning: { placement, sameWidth: true, strategy: 'fixed' }, ...(name && { name }),
125
129
  });
126
130
  // The latest api, for the timers and promises here.
127
131
  const api = useRef(combobox);
@@ -183,8 +187,8 @@ searchable: _searchable, tags: _tags, deselectable: _deselectable, className, cl
183
187
  setQuery('');
184
188
  }, 0);
185
189
  }
186
- return (_jsxs(Ark.RootProvider, { value: combobox, ...rest, ...part('root'), className: cx(className, classes?.root), "data-size": size, "data-variant": variant, onBlur: revert, children: [label && !field && _jsx(Ark.Label, { ...part('label'), children: label }), _jsxs(Ark.Control, { ...part('control'), onMouseDown: focusInput, children: [start != null && _jsx("span", { ...part('start'), children: typeof start === 'function' ? start((keys[0] !== undefined ? byKey(keys[0]) : undefined) ?? null) : start }), _jsxs("div", { ...part('tags'), children: [picked.map((item) => (_jsxs("span", { ...part('tag'), children: [_jsx("span", { ...part('tag-text'), children: renderValue ? renderValue(item) : labelOf(item) }), _jsx("button", { ...part('tag-remove'), type: "button", tabIndex: -1, "aria-label": t.common.remove(labelOf(item)), onClick: (e) => { e.stopPropagation(); unpick(keyOf(item)); }, children: _jsx("iconify-icon", { icon: "lucide:x" }) })] }, keyOf(item)))), _jsx(Ark.Input, { ref: input, ...part('input'), placeholder: picked.length ? '' : placeholder, onKeyDown: removeLast })] }), clearable && _jsx(Ark.ClearTrigger, { ...part('clear-trigger'), children: _jsx("iconify-icon", { icon: "lucide:x" }) }), _jsx(Ark.Trigger, { ...part('trigger'), children: _jsx("iconify-icon", { icon: "lucide:chevron-down" }) })] }), _jsx(Ark.Positioner, { ...part('positioner'), children: _jsxs(Ark.Content, { ...part('content'), children: [listed.map((item) => (_jsxs(Ark.Item, { item: item, ...part('item'), children: [_jsx(Ark.ItemText, { ...part('item-text'), children: renderItem ? renderItem(item, { selected: keys.includes(keyOf(item)) }) : labelOf(item) }), _jsx(Ark.ItemIndicator, { ...part('item-indicator'), children: _jsx("iconify-icon", { icon: "lucide:check" }) })] }, keyOf(item)))), !listed.length && !creating && (_jsx("div", { ...part('empty'), children: loading ? loadingText : slot(empty, emptyText, { query: typed }) })), creating && (_jsx(Ark.Item, { item: creating, ...part('create'), children: renderCreate ? renderCreate(creating.label)
187
- : _jsxs(_Fragment, { children: [_jsx("iconify-icon", { icon: "lucide:plus", "aria-hidden": "true" }), _jsx("span", { children: t.select.create(creating.label) })] }) }))] }) })] }));
190
+ return (_jsxs(Ark.RootProvider, { value: combobox, ...rest, ...part('root'), className: cx(className, classes?.root), "data-size": size, "data-variant": variant, onBlur: revert, children: [label && !field && _jsx(Ark.Label, { ...part('label'), children: label }), _jsxs(Ark.Control, { ...part('control'), onMouseDown: focusInput, children: [start != null && _jsx("span", { ...part('start'), children: typeof start === 'function' ? start((keys[0] !== undefined ? byKey(keys[0]) : undefined) ?? null) : start }), _jsxs("div", { ...part('tags'), children: [picked.map((item) => (_jsxs("span", { ...part('tag'), children: [_jsx("span", { ...part('tag-text'), children: renderValue ? renderValue(item) : labelOf(item) }), _jsx("button", { ...part('tag-remove'), type: "button", tabIndex: -1, "aria-label": t.common.remove(labelOf(item)), onClick: (e) => { e.stopPropagation(); unpick(keyOf(item)); }, children: _jsx("iconify-icon", { icon: "lucide:x" }) })] }, keyOf(item)))), _jsx(Ark.Input, { ref: input, ...part('input'), placeholder: picked.length ? '' : placeholder, onKeyDown: removeLast })] }), clearable && _jsx(Ark.ClearTrigger, { ...part('clear-trigger'), children: _jsx("iconify-icon", { icon: "lucide:x" }) }), _jsx(Ark.Trigger, { ...part('trigger'), children: _jsx("iconify-icon", { icon: "lucide:chevron-down" }) })] }), _jsx(Portal, { children: _jsx(Ark.Positioner, { ...part('positioner'), ...layered, children: _jsxs(Ark.Content, { ...part('content'), ...layered, children: [listed.map((item) => (_jsxs(Ark.Item, { item: item, ...part('item'), children: [_jsx(Ark.ItemText, { ...part('item-text'), children: renderItem ? renderItem(item, { selected: keys.includes(keyOf(item)) }) : labelOf(item) }), _jsx(Ark.ItemIndicator, { ...part('item-indicator'), children: _jsx("iconify-icon", { icon: "lucide:check" }) })] }, keyOf(item)))), !listed.length && !creating && (_jsx("div", { ...part('empty'), children: loading ? loadingText : slot(empty, emptyText, { query: typed }) })), creating && (_jsx(Ark.Item, { item: creating, ...part('create'), children: renderCreate ? renderCreate(creating.label)
191
+ : _jsxs(_Fragment, { children: [_jsx("iconify-icon", { icon: "lucide:plus", "aria-hidden": "true" }), _jsx("span", { children: t.select.create(creating.label) })] }) }))] }) }) })] }));
188
192
  }
189
193
  /**
190
194
  * Combobox's parts, for a searchable select built by hand (Select's own
@@ -30,6 +30,10 @@
30
30
  /* The positioner carries the z-index itself. Zag sets it inline as
31
31
  var(--z-index) but doesn't always fill in the variable, so set both. */
32
32
  [data-scope=combobox][data-part=positioner] { z-index: 50; --z-index: 50; }
33
+ /* Opened from a dialog or sheet (100): above it, below tooltips (110). Zag copies the content's
34
+ z-index onto the positioner when it opens, numbering each open layer (--layer-index). */
35
+ [data-scope=combobox][data-part=positioner][data-layered] { z-index: 105; --z-index: 105; }
36
+ [data-scope=combobox][data-part=content][data-layered] { z-index: calc(105 + var(--layer-index, 0)); }
33
37
  [data-scope=combobox][data-part=content] { z-index: 50; margin: 0; padding: 0.25rem; list-style: none; box-sizing: border-box; outline: none;
34
38
  max-height: min(300px, var(--available-height)); overflow-y: auto; font-weight: 400;
35
39
  background: var(--ui-surface); border: 1px solid var(--ui-border); border-radius: calc(var(--ui-radius) + 2px); box-shadow: var(--ui-shadow); }
@@ -34,6 +34,10 @@
34
34
  /* The positioner carries the z-index itself. Zag sets it inline as
35
35
  var(--z-index) but doesn't always fill in the variable, so set both. */
36
36
  [data-scope=select][data-part=positioner] { z-index: 50; --z-index: 50; }
37
+ /* Opened from a dialog or sheet (100): above it, below tooltips (110). Zag copies the content's
38
+ z-index onto the positioner when it opens, numbering each open layer (--layer-index). */
39
+ [data-scope=select][data-part=positioner][data-layered] { z-index: 105; --z-index: 105; }
40
+ [data-scope=select][data-part=content][data-layered] { z-index: calc(105 + var(--layer-index, 0)); }
37
41
  [data-scope=select][data-part=content] { z-index: 50; margin: 0; padding: 0.25rem; list-style: none; box-sizing: border-box;
38
42
  outline: none; max-height: min(300px, var(--available-height)); overflow-y: auto;
39
43
  background: var(--ui-surface); border: 1px solid var(--ui-border);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@milktop/react-ui",
3
- "version": "0.3.30",
3
+ "version": "0.3.31",
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",