@zyncat/ui 0.20.0 → 0.21.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/dist/alert.js +6 -6
- package/dist/badge.css +20 -11
- package/dist/badge.js +100 -2
- package/dist/badge.js.map +1 -1
- package/dist/{bloom-HV23M4AW.js → bloom-5MZXLNKG.js} +23 -5
- package/dist/bloom-5MZXLNKG.js.map +1 -0
- package/dist/button.js +2 -2
- package/dist/{chunk-JINATP4N.js → chunk-2W7FOMWE.js} +7 -8
- package/dist/chunk-2W7FOMWE.js.map +1 -0
- package/dist/{chunk-LNAV5E7S.js → chunk-3HE7N3UK.js} +7 -3
- package/dist/chunk-3HE7N3UK.js.map +1 -0
- package/dist/{chunk-UKPX3RIP.js → chunk-47OMFFIB.js} +3 -3
- package/dist/{chunk-UKPX3RIP.js.map → chunk-47OMFFIB.js.map} +1 -1
- package/dist/chunk-4M5FMCFJ.js +16 -0
- package/dist/chunk-4M5FMCFJ.js.map +1 -0
- package/dist/chunk-6BY5G7BI.js +122 -0
- package/dist/chunk-6BY5G7BI.js.map +1 -0
- package/dist/{chunk-RLNCRDAL.js → chunk-AOEO2LCZ.js} +4 -4
- package/dist/{chunk-RLNCRDAL.js.map → chunk-AOEO2LCZ.js.map} +1 -1
- package/dist/{chunk-BRKGYLEQ.js → chunk-AQMR7ZYO.js} +8 -3
- package/dist/chunk-AQMR7ZYO.js.map +1 -0
- package/dist/{chunk-N43NDSME.js → chunk-AXZBD7LY.js} +6 -3
- package/dist/chunk-AXZBD7LY.js.map +1 -0
- package/dist/{chunk-V6QAAOA5.js → chunk-BWGK3OD6.js} +9 -6
- package/dist/chunk-BWGK3OD6.js.map +1 -0
- package/dist/{chunk-VQFILXQN.js → chunk-CYZKPUCG.js} +70 -8
- package/dist/chunk-CYZKPUCG.js.map +1 -0
- package/dist/{chunk-AIAPXRCI.js → chunk-DEZIQTBW.js} +176 -103
- package/dist/chunk-DEZIQTBW.js.map +1 -0
- package/dist/{tide-DJZMDAFT.js → chunk-DVLKB3CZ.js} +15 -12
- package/dist/chunk-DVLKB3CZ.js.map +1 -0
- package/dist/{chunk-F64Z42PJ.js → chunk-GM7IPTTT.js} +5 -6
- package/dist/chunk-GM7IPTTT.js.map +1 -0
- package/dist/chunk-ITW5UCVU.js +24 -0
- package/dist/chunk-ITW5UCVU.js.map +1 -0
- package/dist/{chunk-TDHLZY6I.js → chunk-JQZ3FTHP.js} +77 -18
- package/dist/chunk-JQZ3FTHP.js.map +1 -0
- package/dist/{chunk-PXQBJMPJ.js → chunk-LC6NQQER.js} +3 -3
- package/dist/{chunk-PXQBJMPJ.js.map → chunk-LC6NQQER.js.map} +1 -1
- package/dist/{chunk-M2KGLH2G.js → chunk-LV442ZOR.js} +10 -10
- package/dist/{chunk-M2KGLH2G.js.map → chunk-LV442ZOR.js.map} +1 -1
- package/dist/{chunk-F2TB3TT6.js → chunk-PNFFK5HY.js} +4 -4
- package/dist/{chunk-F2TB3TT6.js.map → chunk-PNFFK5HY.js.map} +1 -1
- package/dist/{chunk-2YGHPQ66.js → chunk-Q5N24VII.js} +2 -2
- package/dist/{chunk-2YGHPQ66.js.map → chunk-Q5N24VII.js.map} +1 -1
- package/dist/{chunk-XKDR22VE.js → chunk-SPFHWHJ6.js} +8 -4
- package/dist/chunk-SPFHWHJ6.js.map +1 -0
- package/dist/{chunk-TRPAKUIB.js → chunk-TBIY5YR5.js} +8 -8
- package/dist/{chunk-TRPAKUIB.js.map → chunk-TBIY5YR5.js.map} +1 -1
- package/dist/chunk-TXJQUN7C.js +108 -0
- package/dist/chunk-TXJQUN7C.js.map +1 -0
- package/dist/{chunk-VZXML7EH.js → chunk-V4ZN5RD4.js} +12 -3
- package/dist/chunk-V4ZN5RD4.js.map +1 -0
- package/dist/{chunk-VJXP256V.js → chunk-ZSP4ZTII.js} +7 -7
- package/dist/{chunk-VJXP256V.js.map → chunk-ZSP4ZTII.js.map} +1 -1
- package/dist/confetti.js +1 -1
- package/dist/crossfade-XFZLFLT7.js +91 -0
- package/dist/crossfade-XFZLFLT7.js.map +1 -0
- package/dist/date-field.js +20 -18
- package/dist/date-field.js.map +1 -1
- package/dist/date-picker.css +0 -1
- package/dist/date-range-field.js +22 -20
- package/dist/date-range-field.js.map +1 -1
- package/dist/datetime-field.js +21 -19
- package/dist/datetime-field.js.map +1 -1
- package/dist/dialog.js +9 -9
- package/dist/dropdown.css +12 -9
- package/dist/dropdown.js +37 -20
- package/dist/dropdown.js.map +1 -1
- package/dist/emoji-picker.js +14 -14
- package/dist/flow-field.js +1 -1
- package/dist/glide.js +2 -2
- package/dist/instagram-feed.js +2 -2
- package/dist/lens.js +1 -1
- package/dist/menu-surface.css +81 -7
- package/dist/modal.js +8 -8
- package/dist/morphing-text.js +1 -1
- package/dist/motion-devtools.js +3 -3
- package/dist/motion.js +9 -0
- package/dist/motion.js.map +1 -0
- package/dist/multi-select.js +34 -16
- package/dist/multi-select.js.map +1 -1
- package/dist/number-field.js +2 -2
- package/dist/odometer.css +16 -10
- package/dist/odometer.js +105 -72
- package/dist/odometer.js.map +1 -1
- package/dist/otp-field.js +17 -9
- package/dist/otp-field.js.map +1 -1
- package/dist/pagination.js +4 -4
- package/dist/{paint-CJQCM6ZO.js → paint-NLTI6TEF.js} +5 -3
- package/dist/paint-NLTI6TEF.js.map +1 -0
- package/dist/popover.js +9 -9
- package/dist/radio-group.css +8 -4
- package/dist/radio-group.js +5 -5
- package/dist/select.css +33 -6
- package/dist/select.js +25 -12
- package/dist/select.js.map +1 -1
- package/dist/sheet.js +9 -9
- package/dist/support-rail.js +11 -11
- package/dist/table.css +8 -3
- package/dist/table.js +7 -7
- package/dist/tabs.css +19 -5
- package/dist/tabs.js +7 -5
- package/dist/tabs.js.map +1 -1
- package/dist/tag.js +4 -4
- package/dist/textarea.css +13 -1
- package/dist/textarea.js +36 -23
- package/dist/textarea.js.map +1 -1
- package/dist/theme-grid.js +5 -5
- package/dist/theme-switcher.js +14 -14
- package/dist/{theme-transition-VGLPZDJI.js → theme-transition-FDF2REFD.js} +27 -7
- package/dist/theme-transition-FDF2REFD.js.map +1 -0
- package/dist/theme-transition.css +49 -0
- package/dist/theme.js +2 -2
- package/dist/theme.js.map +1 -1
- package/dist/tide-AGGMQEJV.js +4 -0
- package/dist/tide-AGGMQEJV.js.map +1 -0
- package/dist/tiktok.js +2 -2
- package/dist/time-field.js +5 -3
- package/dist/time-field.js.map +1 -1
- package/dist/toast.js +7 -7
- package/dist/toggle-tag.js +2 -2
- package/dist/toggle.js +4 -15
- package/dist/toggle.js.map +1 -1
- package/dist/tooltip.js +6 -7
- package/dist/tooltip.js.map +1 -1
- package/dist/trigger.css +0 -1
- package/dist/types/components/composites/date-picker/DateField.d.ts +1 -1
- package/dist/types/components/composites/date-picker/DateRangeField.d.ts +1 -1
- package/dist/types/components/composites/date-picker/DateTimeField.d.ts +1 -1
- package/dist/types/components/composites/date-picker/TimeField.d.ts +1 -1
- package/dist/types/components/composites/date-picker/field-shell.d.ts +5 -1
- package/dist/types/components/composites/dropdown/Dropdown.d.ts +13 -2
- package/dist/types/components/composites/dropdown/types.d.ts +5 -2
- package/dist/types/components/composites/select/MultiSelect.d.ts +23 -3
- package/dist/types/components/composites/select/Select.d.ts +20 -4
- package/dist/types/components/composites/select/core/index.d.ts +2 -1
- package/dist/types/components/composites/select/core/menu.d.ts +8 -5
- package/dist/types/components/composites/select/core/panel.d.ts +6 -4
- package/dist/types/components/composites/select/core/trigger.d.ts +7 -2
- package/dist/types/components/composites/select/core/types.d.ts +9 -0
- package/dist/types/components/composites/select/core/use-listbox.d.ts +5 -3
- package/dist/types/components/composites/tabs/Tabs.d.ts +4 -1
- package/dist/types/components/expressive/odometer/Odometer.d.ts +1 -1
- package/dist/types/components/expressive/odometer/roll.d.ts +20 -0
- package/dist/types/components/expressive/theme-transition/scene.d.ts +3 -0
- package/dist/types/components/internal/menu/highlight.d.ts +9 -1
- package/dist/types/components/internal/menu/menu-row.d.ts +4 -0
- package/dist/types/components/internal/menu/use-anchor-width.d.ts +2 -0
- package/dist/types/components/internal/overlay/layer.d.ts +5 -8
- package/dist/types/components/internal/overlay/track-anchor.d.ts +5 -0
- package/dist/types/components/internal/utils/activation.d.ts +1 -0
- package/dist/types/components/primitives/badge/Badge.d.ts +17 -8
- package/dist/types/components/primitives/badge/morph-label.d.ts +3 -0
- package/dist/types/components/primitives/badge/use-glint-on-change.d.ts +2 -0
- package/dist/types/components/primitives/input/OtpField.d.ts +2 -2
- package/dist/types/components/primitives/textarea/Textarea.d.ts +2 -2
- package/dist/types/components/primitives/textarea/char-meter.d.ts +6 -0
- package/dist/types/components/primitives/toggle/switch-glyph.d.ts +6 -0
- package/dist/types/motion/crossfade.d.ts +3 -0
- package/dist/types/motion/element.d.ts +6 -3
- package/dist/types/motion/flip.d.ts +8 -2
- package/dist/types/motion/motion.d.ts +7 -0
- package/dist/types/theme-scope.d.ts +5 -0
- package/dist/types/tokens/component-styles.generated.d.ts +0 -2
- package/dist/types/tokens/theme-tokens.generated.d.ts +37 -31
- package/dist/typing-lines.js +1 -1
- package/dist/youtube.js +2 -2
- package/package.json +6 -11
- package/skills/zyncat-ui/SKILL.md +2 -2
- package/skills/zyncat-ui/references/components.md +3 -4
- package/skills/zyncat-ui/references/theming.md +3 -3
- package/src/components/composites/date-picker/DateField.tsx +2 -0
- package/src/components/composites/date-picker/DateRangeField.tsx +2 -0
- package/src/components/composites/date-picker/DateTimeField.tsx +2 -0
- package/src/components/composites/date-picker/TimeField.tsx +2 -0
- package/src/components/composites/date-picker/date-picker.css +0 -1
- package/src/components/composites/date-picker/field-shell.tsx +14 -1
- package/src/components/composites/dropdown/Dropdown.tsx +20 -3
- package/src/components/composites/dropdown/Dropdown.usage.md +2 -0
- package/src/components/composites/dropdown/dropdown.css +12 -9
- package/src/components/composites/dropdown/menu-panel.tsx +28 -13
- package/src/components/composites/dropdown/types.ts +5 -2
- package/src/components/composites/select/MultiSelect.tsx +56 -5
- package/src/components/composites/select/MultiSelect.usage.md +10 -0
- package/src/components/composites/select/Select.tsx +32 -2
- package/src/components/composites/select/Select.usage.md +13 -1
- package/src/components/composites/select/core/index.ts +2 -1
- package/src/components/composites/select/core/menu.tsx +28 -15
- package/src/components/composites/select/core/panel.tsx +57 -52
- package/src/components/composites/select/core/trigger.tsx +44 -11
- package/src/components/composites/select/core/types.ts +10 -0
- package/src/components/composites/select/core/use-listbox.ts +77 -31
- package/src/components/composites/select/select.css +33 -6
- package/src/components/composites/table/table.css +8 -3
- package/src/components/composites/tabs/Tabs.tsx +5 -0
- package/src/components/composites/tabs/tabs.css +19 -5
- package/src/components/composites/tooltip/tooltip-host.tsx +1 -1
- package/src/components/expressive/odometer/Odometer.tsx +45 -92
- package/src/components/expressive/odometer/Odometer.usage.md +2 -2
- package/src/components/expressive/odometer/odometer.css +16 -10
- package/src/components/expressive/odometer/roll.ts +94 -0
- package/src/components/expressive/theme-transition/bloom.ts +22 -2
- package/src/components/expressive/theme-transition/paint.ts +2 -0
- package/src/components/expressive/theme-transition/scene.ts +3 -0
- package/src/components/expressive/theme-transition/theme-transition.css +49 -0
- package/src/components/expressive/theme-transition/theme-transition.ts +21 -1
- package/src/components/expressive/theme-transition/tide.ts +15 -10
- package/src/components/internal/menu/highlight.ts +20 -2
- package/src/components/internal/menu/menu-row.tsx +36 -8
- package/src/components/internal/menu/menu-surface.css +81 -7
- package/src/components/internal/menu/use-anchor-width.ts +26 -0
- package/src/components/internal/overlay/layer.tsx +11 -23
- package/src/components/internal/overlay/position.ts +17 -6
- package/src/components/internal/overlay/track-anchor.ts +69 -0
- package/src/components/internal/overlay/trigger.css +0 -1
- package/src/components/internal/utils/activation.ts +5 -0
- package/src/components/primitives/badge/Badge.tsx +38 -15
- package/src/components/primitives/badge/Badge.usage.md +12 -5
- package/src/components/primitives/badge/badge.css +20 -11
- package/src/components/primitives/badge/morph-label.tsx +71 -0
- package/src/components/primitives/badge/use-glint-on-change.ts +16 -0
- package/src/components/primitives/input/OtpField.tsx +17 -9
- package/src/components/primitives/radio-group/radio-group.css +8 -4
- package/src/components/primitives/textarea/Textarea.tsx +20 -24
- package/src/components/primitives/textarea/char-meter.tsx +34 -0
- package/src/components/primitives/textarea/textarea.css +13 -1
- package/src/components/primitives/toggle/Toggle.tsx +3 -12
- package/src/components/primitives/toggle/switch-glyph.tsx +25 -0
- package/src/engine/flip.ts +5 -1
- package/src/motion/crossfade.ts +97 -0
- package/src/motion/element.tsx +10 -7
- package/src/motion/flip.ts +62 -23
- package/src/motion/glide.tsx +5 -0
- package/src/motion/motion.ts +7 -0
- package/src/motion/motion.usage.md +34 -0
- package/src/motion/presence.tsx +4 -0
- package/src/motion/use-motion.ts +8 -3
- package/src/theme-scope.ts +19 -0
- package/src/tokens/base.css +7 -0
- package/src/tokens/color.css +17 -15
- package/src/tokens/component-styles.generated.ts +0 -2
- package/src/tokens/dark.css +3 -0
- package/src/tokens/decisions.css +5 -3
- package/src/tokens/semantic.css +12 -6
- package/src/tokens/spacing.css +3 -3
- package/src/tokens/theme-tokens.generated.ts +37 -31
- package/tailwind.css +2 -0
- package/dist/bloom-HV23M4AW.js.map +0 -1
- package/dist/chunk-2DNKZ57E.js +0 -72
- package/dist/chunk-2DNKZ57E.js.map +0 -1
- package/dist/chunk-AIAPXRCI.js.map +0 -1
- package/dist/chunk-BRKGYLEQ.js.map +0 -1
- package/dist/chunk-F64Z42PJ.js.map +0 -1
- package/dist/chunk-JINATP4N.js.map +0 -1
- package/dist/chunk-LNAV5E7S.js.map +0 -1
- package/dist/chunk-N43NDSME.js.map +0 -1
- package/dist/chunk-RJENXXTI.js +0 -93
- package/dist/chunk-RJENXXTI.js.map +0 -1
- package/dist/chunk-RW2A4M2Q.js +0 -57
- package/dist/chunk-RW2A4M2Q.js.map +0 -1
- package/dist/chunk-TDHLZY6I.js.map +0 -1
- package/dist/chunk-V6QAAOA5.js.map +0 -1
- package/dist/chunk-VDOBLABP.js +0 -38
- package/dist/chunk-VDOBLABP.js.map +0 -1
- package/dist/chunk-VQFILXQN.js.map +0 -1
- package/dist/chunk-VZXML7EH.js.map +0 -1
- package/dist/chunk-XKDR22VE.js.map +0 -1
- package/dist/count-badge.js +0 -13
- package/dist/count-badge.js.map +0 -1
- package/dist/paint-CJQCM6ZO.js.map +0 -1
- package/dist/status-badge.js +0 -72
- package/dist/status-badge.js.map +0 -1
- package/dist/theme-transition-VGLPZDJI.js.map +0 -1
- package/dist/tide-DJZMDAFT.js.map +0 -1
- package/dist/types/components/primitives/badge/CountBadge.d.ts +0 -8
- package/dist/types/components/primitives/badge/StatusBadge.d.ts +0 -15
- package/src/components/primitives/badge/CountBadge.tsx +0 -20
- package/src/components/primitives/badge/CountBadge.usage.md +0 -13
- package/src/components/primitives/badge/StatusBadge.tsx +0 -113
- package/src/components/primitives/badge/StatusBadge.usage.md +0 -14
|
@@ -20,8 +20,9 @@ import { popIn, popOut } from '../../../motion/presets';
|
|
|
20
20
|
import type { DisableableAnimation } from '../../../motion/timing';
|
|
21
21
|
import { motionFor } from '../../../tokens/motion-tokens';
|
|
22
22
|
import { useControllable } from '../../internal/hooks/use-controllable';
|
|
23
|
+
import type { MenuSize, MenuWeight, MenuWidth } from '../../internal/menu/highlight';
|
|
23
24
|
import { ovCloneTrigger, OverlayPortal } from '../../internal/overlay/layer';
|
|
24
|
-
import type
|
|
25
|
+
import { pressedByKeyboard, type ActivateOn } from '../../internal/utils/activation';
|
|
25
26
|
import { MenuPanel } from './menu-panel';
|
|
26
27
|
import {
|
|
27
28
|
levelKey,
|
|
@@ -68,6 +69,16 @@ export interface DropdownProps {
|
|
|
68
69
|
/** Hue of the highlight that travels between rows: the neutral wash, or the accent wash with accent
|
|
69
70
|
* ink on the active row. @default 'neutral' */
|
|
70
71
|
highlight?: 'neutral' | 'accent';
|
|
72
|
+
/** Menu density - row type and padding on every row, submenus included; a row carrying a
|
|
73
|
+
* description sits one step taller than a plain one. The trigger is your own node, so this
|
|
74
|
+
* never touches it. @default 'md' */
|
|
75
|
+
size?: MenuSize;
|
|
76
|
+
/** Weight of every row label. @default 'medium' */
|
|
77
|
+
weight?: MenuWeight;
|
|
78
|
+
/** Width of the top-level menu. `auto` fits the rows, `trigger` is never narrower than the trigger,
|
|
79
|
+
* and `sm` | `md` | `lg` are fixed steps with long labels ellipsizing. Submenus always fit their
|
|
80
|
+
* rows. @default 'auto' */
|
|
81
|
+
width?: MenuWidth;
|
|
71
82
|
/** Short accent bar on the leading edge of the highlight, marking the active row. @default false */
|
|
72
83
|
rail?: boolean;
|
|
73
84
|
|
|
@@ -94,6 +105,9 @@ export function Dropdown({
|
|
|
94
105
|
align = 'start',
|
|
95
106
|
highlight = 'neutral',
|
|
96
107
|
rail = false,
|
|
108
|
+
size = 'md',
|
|
109
|
+
weight = 'medium',
|
|
110
|
+
width = 'auto',
|
|
97
111
|
id,
|
|
98
112
|
ariaLabel,
|
|
99
113
|
htmlProps,
|
|
@@ -101,7 +115,7 @@ export function Dropdown({
|
|
|
101
115
|
}: DropdownProps) {
|
|
102
116
|
const [open, setOpen] = useControllable(controlledOpen, defaultOpen, onOpenChange);
|
|
103
117
|
const [path, setPath] = useState<string[]>([]);
|
|
104
|
-
const [seed, setSeed] = useState({ key: ROOT_LEVEL, focus: '
|
|
118
|
+
const [seed, setSeed] = useState({ key: ROOT_LEVEL, focus: 'selected' as SeedFocus });
|
|
105
119
|
|
|
106
120
|
const refs = useRef(new Map<string, RefObject<HTMLElement>>());
|
|
107
121
|
const hoverDepth = useRef(-1);
|
|
@@ -137,6 +151,9 @@ export function Dropdown({
|
|
|
137
151
|
align,
|
|
138
152
|
highlight,
|
|
139
153
|
rail,
|
|
154
|
+
size,
|
|
155
|
+
weight,
|
|
156
|
+
width,
|
|
140
157
|
ariaLabel,
|
|
141
158
|
htmlProps,
|
|
142
159
|
seed,
|
|
@@ -167,7 +184,7 @@ export function Dropdown({
|
|
|
167
184
|
<Fragment>
|
|
168
185
|
{ovCloneTrigger(trigger, {
|
|
169
186
|
open,
|
|
170
|
-
onPress: () => (open ? dismiss(false) : show('first')),
|
|
187
|
+
onPress: (e) => (open ? dismiss(false) : show(pressedByKeyboard(e) ? 'first' : 'selected')),
|
|
171
188
|
onKeyDown: (e) => {
|
|
172
189
|
if (open || (e.key !== 'ArrowDown' && e.key !== 'ArrowUp')) return;
|
|
173
190
|
e.preventDefault();
|
|
@@ -10,6 +10,8 @@ DropdownGroup[] (labelled sections); a row with its own items opens a submenu, n
|
|
|
10
10
|
you like. content on a row opens your own panel body in place of a submenu; selected marks the
|
|
11
11
|
current value of a single-choice group with a check. Keyboard is the APG menu button: arrows move,
|
|
12
12
|
Right/Left open and close a submenu, Enter/Space commit, typeahead, Esc one level, Tab the lot.
|
|
13
|
+
size sm|md|lg sets the vertical padding of every row, submenus included; weight sets the label
|
|
14
|
+
weight regular|medium|semibold.
|
|
13
15
|
highlight neutral|accent picks the hue of the highlight travelling between rows; rail adds a short
|
|
14
16
|
accent bar on its leading edge. returnFocus false leaves focus where a committing row put it.
|
|
15
17
|
|
|
@@ -4,7 +4,6 @@
|
|
|
4
4
|
.zc-dropdown__menu {
|
|
5
5
|
--menu-max-width: min(20rem, 92vw);
|
|
6
6
|
--menu-max-height: min(26rem, 70vh);
|
|
7
|
-
min-width: 11rem;
|
|
8
7
|
}
|
|
9
8
|
|
|
10
9
|
.zc-dropdown__menu[data-danger-active='true'] {
|
|
@@ -25,14 +24,6 @@
|
|
|
25
24
|
color: var(--menu-active-ink, var(--text-strong));
|
|
26
25
|
}
|
|
27
26
|
|
|
28
|
-
.zc-dropdown__item[data-danger='true'],
|
|
29
|
-
.zc-dropdown__item[data-danger='true'][data-active='true'] {
|
|
30
|
-
color: var(--danger-text);
|
|
31
|
-
}
|
|
32
|
-
.zc-dropdown__item[data-danger='true'] .zc-menu-row__icon {
|
|
33
|
-
color: var(--danger);
|
|
34
|
-
}
|
|
35
|
-
|
|
36
27
|
.zc-dropdown__item-caret {
|
|
37
28
|
flex: 0 0 auto;
|
|
38
29
|
color: var(--text-subtle);
|
|
@@ -51,6 +42,18 @@
|
|
|
51
42
|
color: var(--text-accent);
|
|
52
43
|
}
|
|
53
44
|
|
|
45
|
+
.zc-dropdown__item[data-danger='true'] {
|
|
46
|
+
color: var(--danger-text);
|
|
47
|
+
}
|
|
48
|
+
.zc-dropdown__item[data-danger='true'] .zc-menu-row__label {
|
|
49
|
+
color: var(--danger-text);
|
|
50
|
+
}
|
|
51
|
+
.zc-dropdown__item[data-danger='true'] .zc-menu-row__icon,
|
|
52
|
+
.zc-dropdown__item[data-danger='true'] .zc-dropdown__item-check,
|
|
53
|
+
.zc-dropdown__item[data-danger='true'] .zc-dropdown__item-caret {
|
|
54
|
+
color: var(--danger);
|
|
55
|
+
}
|
|
56
|
+
|
|
54
57
|
.zc-dropdown__item[data-disabled='true'] {
|
|
55
58
|
cursor: not-allowed;
|
|
56
59
|
color: var(--text-disabled);
|
|
@@ -5,12 +5,14 @@ import '../../internal/menu/menu-surface.css';
|
|
|
5
5
|
import { useEffect, useLayoutEffect, useMemo, useRef, useState, type KeyboardEvent, type RefObject } from 'react';
|
|
6
6
|
|
|
7
7
|
import { GlidePill, useGlide } from '../../../motion/glide';
|
|
8
|
+
import { Presence } from '../../../motion/presence';
|
|
8
9
|
import { useMotion, type MotionSpecs } from '../../../motion/use-motion';
|
|
9
10
|
import { edgeEnabled, matchPrefix, stepEnabled } from '../../internal/collection/collection';
|
|
10
11
|
import { useTypeahead } from '../../internal/hooks/use-typeahead';
|
|
11
12
|
import { Icon } from '../../internal/icon/Icon';
|
|
12
|
-
import {
|
|
13
|
+
import { menuSurfaceAttrs } from '../../internal/menu/highlight';
|
|
13
14
|
import { MenuRow } from '../../internal/menu/menu-row';
|
|
15
|
+
import { useAnchorWidth } from '../../internal/menu/use-anchor-width';
|
|
14
16
|
import { useReturnFocus } from '../../internal/overlay/focus';
|
|
15
17
|
import { useOutsidePress, useOverlayEntry } from '../../internal/overlay/layer';
|
|
16
18
|
import { useAnchorPosition } from '../../internal/overlay/position';
|
|
@@ -52,7 +54,12 @@ export function MenuPanel({ chain, depth, ...motion }: { chain: MenuChain; depth
|
|
|
52
54
|
|
|
53
55
|
const { groups, flat } = useMemo(() => normalize(level.items), [level.items]);
|
|
54
56
|
const indexOf = useMemo(() => new Map(flat.map((item, i) => [item.id, i] as const)), [flat]);
|
|
55
|
-
const
|
|
57
|
+
const seedIndex = () => {
|
|
58
|
+
if (seed === 'none') return -1;
|
|
59
|
+
if (seed === 'selected') return flat.findIndex((item) => item.selected && !item.disabled);
|
|
60
|
+
return edgeEnabled(flat, seed === 'last');
|
|
61
|
+
};
|
|
62
|
+
const [activeIdx, setActiveIdx] = useState(seedIndex);
|
|
56
63
|
|
|
57
64
|
const panelRef = refFor('panel:' + level.key);
|
|
58
65
|
const rowFor = (i: number) => refFor('row:' + levelKey(depth, flat[i].id)) as unknown as RefObject<HTMLDivElement>;
|
|
@@ -72,6 +79,7 @@ export function MenuPanel({ chain, depth, ...motion }: { chain: MenuChain; depth
|
|
|
72
79
|
const place = { side: nested ? 'right' : chain.side, align: nested ? 'start' : chain.align } as const;
|
|
73
80
|
useMotion(panelRef, motion);
|
|
74
81
|
useReturnFocus(panelRef);
|
|
82
|
+
useAnchorWidth(anchorRef, panelRef, !nested && chain.width === 'trigger');
|
|
75
83
|
useAnchorPosition({ ...place, arrow: false, triggerRef: anchorRef, panelRef });
|
|
76
84
|
useOutsidePress({ entry, refs: [panelRef, anchorRef], enabled: !nested, onPress: () => chain.dismiss(false) });
|
|
77
85
|
|
|
@@ -85,8 +93,13 @@ export function MenuPanel({ chain, depth, ...motion }: { chain: MenuChain; depth
|
|
|
85
93
|
|
|
86
94
|
useLayoutEffect(() => {
|
|
87
95
|
if (seed === 'none') return;
|
|
88
|
-
if (contentLevel)
|
|
89
|
-
|
|
96
|
+
if (contentLevel) {
|
|
97
|
+
panelRef.current?.focus();
|
|
98
|
+
return;
|
|
99
|
+
}
|
|
100
|
+
const i = seedIndex();
|
|
101
|
+
if (i < 0) panelRef.current?.focus();
|
|
102
|
+
setActiveIdx(i);
|
|
90
103
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
91
104
|
}, [seed]);
|
|
92
105
|
|
|
@@ -244,14 +257,16 @@ export function MenuPanel({ chain, depth, ...motion }: { chain: MenuChain; depth
|
|
|
244
257
|
return (
|
|
245
258
|
<>
|
|
246
259
|
<GlidePill className="zc-menu-glide" glide={glide} />
|
|
247
|
-
{
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
260
|
+
<Presence initial={false}>
|
|
261
|
+
{groups.length > 1 || groups[0]?.label
|
|
262
|
+
? groups.map((group, gi) => (
|
|
263
|
+
<div className="zc-dropdown__group" role="group" aria-label={group.label || undefined} key={gi}>
|
|
264
|
+
{group.label && <div className="zc-menu-group-label">{group.label}</div>}
|
|
265
|
+
{group.items.map(renderRow)}
|
|
266
|
+
</div>
|
|
267
|
+
))
|
|
268
|
+
: flat.map(renderRow)}
|
|
269
|
+
</Presence>
|
|
255
270
|
</>
|
|
256
271
|
);
|
|
257
272
|
}
|
|
@@ -259,7 +274,7 @@ export function MenuPanel({ chain, depth, ...motion }: { chain: MenuChain; depth
|
|
|
259
274
|
return (
|
|
260
275
|
<div
|
|
261
276
|
{...(nested ? undefined : chain.htmlProps)}
|
|
262
|
-
{...
|
|
277
|
+
{...menuSurfaceAttrs({ ...chain, width: nested ? 'auto' : chain.width })}
|
|
263
278
|
ref={panelRef as unknown as RefObject<HTMLDivElement>}
|
|
264
279
|
id={menuId}
|
|
265
280
|
className={cx('zc-menu-surface zc-menu-scroller zc-dropdown__menu', !nested && chain.htmlProps?.className)}
|
|
@@ -2,7 +2,7 @@ import type { HTMLAttributes, ReactNode, RefObject } from 'react';
|
|
|
2
2
|
|
|
3
3
|
import type { DataAttributes } from '../../../dom-props';
|
|
4
4
|
import { normalizeCollection, type NormalizedGroup } from '../../internal/collection/collection';
|
|
5
|
-
import type { MenuHighlight } from '../../internal/menu/highlight';
|
|
5
|
+
import type { MenuHighlight, MenuSize, MenuWeight, MenuWidth } from '../../internal/menu/highlight';
|
|
6
6
|
import type { ActivateOn } from '../../internal/utils/activation';
|
|
7
7
|
|
|
8
8
|
export interface DropdownItem {
|
|
@@ -94,7 +94,7 @@ export function resolveLevels(items: DropdownItems, path: string[]): Level[] {
|
|
|
94
94
|
return levels;
|
|
95
95
|
}
|
|
96
96
|
|
|
97
|
-
export type SeedFocus = 'first' | 'last' | 'none';
|
|
97
|
+
export type SeedFocus = 'first' | 'last' | 'selected' | 'none';
|
|
98
98
|
|
|
99
99
|
export interface MenuChain {
|
|
100
100
|
levels: Level[];
|
|
@@ -104,6 +104,9 @@ export interface MenuChain {
|
|
|
104
104
|
align: 'start' | 'center' | 'end';
|
|
105
105
|
highlight: MenuHighlight;
|
|
106
106
|
rail: boolean;
|
|
107
|
+
size: MenuSize;
|
|
108
|
+
weight: MenuWeight;
|
|
109
|
+
width: MenuWidth;
|
|
107
110
|
ariaLabel?: string;
|
|
108
111
|
htmlProps?: HTMLAttributes<HTMLDivElement> & DataAttributes;
|
|
109
112
|
seed: { key: string; focus: SeedFocus };
|
|
@@ -7,10 +7,20 @@ import type { HTMLAttributes, ReactNode } from 'react';
|
|
|
7
7
|
import type { DataAttributes } from '../../../dom-props';
|
|
8
8
|
import type { DisableableAnimation } from '../../../motion/timing';
|
|
9
9
|
import { useControllable } from '../../internal/hooks/use-controllable';
|
|
10
|
+
import type { MenuSize, MenuWeight, MenuWidth } from '../../internal/menu/highlight';
|
|
10
11
|
import type { ActivateOn } from '../../internal/utils/activation';
|
|
11
12
|
import { cx } from '../../internal/utils/cx';
|
|
12
13
|
import { CheckGlyph } from '../../primitives/checkbox/check-glyph';
|
|
13
|
-
import {
|
|
14
|
+
import { SwitchGlyph } from '../../primitives/toggle/switch-glyph';
|
|
15
|
+
import {
|
|
16
|
+
ListboxPanel,
|
|
17
|
+
SelectTrigger,
|
|
18
|
+
useListbox,
|
|
19
|
+
type CustomTrigger,
|
|
20
|
+
type SelectGroup,
|
|
21
|
+
type SelectMenuHtmlProps,
|
|
22
|
+
type SelectOption,
|
|
23
|
+
} from './core';
|
|
14
24
|
|
|
15
25
|
export type { SelectOption, SelectGroup } from './core';
|
|
16
26
|
|
|
@@ -25,8 +35,20 @@ export interface MultiSelectProps {
|
|
|
25
35
|
onChange?: (value: string[], toggled: SelectOption) => void;
|
|
26
36
|
/** Trigger text when nothing is selected. @default 'Select options' */
|
|
27
37
|
placeholder?: string;
|
|
28
|
-
/**
|
|
38
|
+
/** Trigger height, type and padding. The menu follows it unless `menuSize` overrides. @default 'md' */
|
|
29
39
|
size?: 'sm' | 'md' | 'lg';
|
|
40
|
+
/** Menu density on its own - row type, row padding, the filter field and the row checkbox. A row
|
|
41
|
+
* carrying a description sits one step taller than a plain one at every step. @default the `size` value */
|
|
42
|
+
menuSize?: MenuSize;
|
|
43
|
+
/** Weight of every option label in the menu. @default 'medium' */
|
|
44
|
+
weight?: MenuWeight;
|
|
45
|
+
/** Glyph mirroring each option's selected state at the trailing edge: a checkbox, or a switch for a
|
|
46
|
+
* settings-style menu where every option is an independent on/off. Decoration only - the option
|
|
47
|
+
* semantics are the same either way. @default 'checkbox' */
|
|
48
|
+
marker?: 'checkbox' | 'switch';
|
|
49
|
+
/** Menu width. `trigger` is never narrower than the trigger, `auto` fits the options, and
|
|
50
|
+
* `sm` | `md` | `lg` are fixed steps with long labels ellipsizing. @default 'trigger' */
|
|
51
|
+
width?: MenuWidth;
|
|
30
52
|
/** Disabled - trigger is inert and the menu cannot open. @default false */
|
|
31
53
|
disabled?: boolean;
|
|
32
54
|
/** Danger ring + border. @default false */
|
|
@@ -50,16 +72,32 @@ export interface MultiSelectProps {
|
|
|
50
72
|
ariaLabel?: string;
|
|
51
73
|
/** Standard <div> attributes (className, style, data-*, ...) forwarded to the select root. */
|
|
52
74
|
htmlProps?: HTMLAttributes<HTMLDivElement> & DataAttributes;
|
|
75
|
+
/** Standard attributes (className, style, data-*, ...) forwarded to the menu panel, which portals
|
|
76
|
+
* to <body> and inherits nothing from the root. */
|
|
77
|
+
menuProps?: SelectMenuHtmlProps;
|
|
53
78
|
/** Whether the trigger and the options fire on `pointerdown` (snappier) or wait for `click`.
|
|
54
79
|
* @default 'pointerdown' */
|
|
55
80
|
activateOn?: ActivateOn;
|
|
56
81
|
/** Menu open/close timing - motion tokens only, or `null` to disable. @default duration 'base' + ease 'entrance'/'exit' */
|
|
57
82
|
animation?: DisableableAnimation;
|
|
83
|
+
/** Your own element in place of the built-in trigger. It is cloned with the combobox wiring - role,
|
|
84
|
+
* aria, open/close, arrow keys, and the anchor the menu measures - so it must render one focusable
|
|
85
|
+
* element that forwards its props and ref. Pass a function to read `{ open, selected }`. */
|
|
86
|
+
trigger?: CustomTrigger<SelectOption[]>;
|
|
58
87
|
}
|
|
59
88
|
|
|
60
|
-
|
|
89
|
+
type MultiSelectMarker = NonNullable<MultiSelectProps['marker']>;
|
|
90
|
+
|
|
91
|
+
function OptionMarker({ marker, checked, size }: { marker: MultiSelectMarker; checked: boolean; size: MenuSize }) {
|
|
92
|
+
if (marker === 'switch') {
|
|
93
|
+
return (
|
|
94
|
+
<span className={cx('zc-sw', size === 'sm' && 'zc-sw--sm')} aria-hidden="true">
|
|
95
|
+
<SwitchGlyph checked={checked} readOnly tabIndex={-1} />
|
|
96
|
+
</span>
|
|
97
|
+
);
|
|
98
|
+
}
|
|
61
99
|
return (
|
|
62
|
-
<span className=
|
|
100
|
+
<span className={cx('zc-cbx', size === 'sm' && 'zc-cbx--sm')} aria-hidden="true">
|
|
63
101
|
<CheckGlyph checked={checked} readOnly tabIndex={-1} />
|
|
64
102
|
</span>
|
|
65
103
|
);
|
|
@@ -72,6 +110,7 @@ export function MultiSelect({
|
|
|
72
110
|
onChange,
|
|
73
111
|
placeholder = 'Select options',
|
|
74
112
|
size = 'md',
|
|
113
|
+
menuSize = size,
|
|
75
114
|
disabled = false,
|
|
76
115
|
invalid = false,
|
|
77
116
|
loading = false,
|
|
@@ -79,12 +118,17 @@ export function MultiSelect({
|
|
|
79
118
|
searchPlaceholder = 'Filter options',
|
|
80
119
|
highlight = 'neutral',
|
|
81
120
|
rail = false,
|
|
121
|
+
weight = 'medium',
|
|
122
|
+
marker = 'checkbox',
|
|
123
|
+
width = 'trigger',
|
|
82
124
|
leadingIcon = null,
|
|
83
125
|
id,
|
|
84
126
|
ariaLabel,
|
|
85
127
|
htmlProps,
|
|
128
|
+
menuProps,
|
|
86
129
|
activateOn = 'pointerdown',
|
|
87
130
|
animation,
|
|
131
|
+
trigger,
|
|
88
132
|
}: MultiSelectProps) {
|
|
89
133
|
const [value, setValue] = useControllable<string[], SelectOption>(
|
|
90
134
|
controlledValue,
|
|
@@ -109,6 +153,7 @@ export function MultiSelect({
|
|
|
109
153
|
|
|
110
154
|
const selectedOptions = lb.flat.filter((o) => isSelected(o.value));
|
|
111
155
|
const isPlaceholder = !loading && selectedOptions.length === 0;
|
|
156
|
+
const customTrigger = typeof trigger === 'function' ? trigger({ open: lb.open, selected: selectedOptions }) : trigger;
|
|
112
157
|
|
|
113
158
|
return (
|
|
114
159
|
<div
|
|
@@ -116,6 +161,7 @@ export function MultiSelect({
|
|
|
116
161
|
className={cx('zc-select', htmlProps?.className)}
|
|
117
162
|
data-multiple="true"
|
|
118
163
|
data-size={size}
|
|
164
|
+
data-custom-trigger={customTrigger ? 'true' : undefined}
|
|
119
165
|
data-open={lb.open ? 'true' : undefined}
|
|
120
166
|
data-disabled={disabled ? 'true' : undefined}
|
|
121
167
|
data-invalid={invalid ? 'true' : undefined}
|
|
@@ -123,6 +169,7 @@ export function MultiSelect({
|
|
|
123
169
|
>
|
|
124
170
|
<SelectTrigger
|
|
125
171
|
lb={lb}
|
|
172
|
+
node={customTrigger}
|
|
126
173
|
disabled={disabled}
|
|
127
174
|
invalid={invalid}
|
|
128
175
|
ariaLabel={ariaLabel}
|
|
@@ -141,9 +188,13 @@ export function MultiSelect({
|
|
|
141
188
|
multiple
|
|
142
189
|
highlight={highlight}
|
|
143
190
|
rail={rail}
|
|
191
|
+
size={menuSize}
|
|
192
|
+
weight={weight}
|
|
193
|
+
width={width}
|
|
144
194
|
activateOn={activateOn}
|
|
145
195
|
animation={animation}
|
|
146
|
-
|
|
196
|
+
menuProps={menuProps}
|
|
197
|
+
check={(sel) => <OptionMarker marker={marker} checked={sel} size={menuSize} />}
|
|
147
198
|
/>
|
|
148
199
|
</div>
|
|
149
200
|
);
|
|
@@ -7,7 +7,17 @@ Many-of listbox; stays open while toggling, trigger summarises as first +N.
|
|
|
7
7
|
|
|
8
8
|
value: string[], onChange(string[]); searchable. highlight neutral|accent picks the hue of the
|
|
9
9
|
highlight travelling between options; rail adds a short accent bar on its leading edge.
|
|
10
|
+
trigger replaces the built-in combobox with your own element - a node, or a function of
|
|
11
|
+
{ open, selected } where selected is the SelectOption[] in option order. It is cloned with the full
|
|
12
|
+
wiring - role, aria-expanded/controls/activedescendant, open/close, arrow keys - and becomes the
|
|
13
|
+
anchor the menu measures, so it must render ONE focusable element that forwards its props and its ref
|
|
14
|
+
(a Button does; a plain div is not focusable). placeholder and leadingIcon then stop applying and the
|
|
15
|
+
root drops its width: 100%, leaving the trigger its intrinsic width; size still drives the menu,
|
|
16
|
+
loading still blocks opening, disabled still makes it inert with aria-disabled.
|
|
10
17
|
|
|
11
18
|
```tsx
|
|
12
19
|
<MultiSelect options={PEOPLE} value={ids} onChange={setIds} placeholder="Choose members" ariaLabel="Members" />
|
|
20
|
+
<MultiSelect options={PEOPLE} value={ids} onChange={setIds} ariaLabel="Members" trigger={({ selected }) => (
|
|
21
|
+
<Button variant="secondary">{selected.length ? `${selected.length} members` : 'Members'}</Button>
|
|
22
|
+
)} />
|
|
13
23
|
```
|
|
@@ -7,13 +7,16 @@ import type { HTMLAttributes, ReactNode } from 'react';
|
|
|
7
7
|
import type { DataAttributes } from '../../../dom-props';
|
|
8
8
|
import type { DisableableAnimation } from '../../../motion/timing';
|
|
9
9
|
import { useControllable } from '../../internal/hooks/use-controllable';
|
|
10
|
+
import type { MenuSize, MenuWeight, MenuWidth } from '../../internal/menu/highlight';
|
|
10
11
|
import type { ActivateOn } from '../../internal/utils/activation';
|
|
11
12
|
import { cx } from '../../internal/utils/cx';
|
|
12
13
|
import {
|
|
13
14
|
ListboxPanel,
|
|
14
15
|
SelectTrigger,
|
|
15
16
|
useListbox,
|
|
17
|
+
type CustomTrigger,
|
|
16
18
|
type SelectGroup,
|
|
19
|
+
type SelectMenuHtmlProps,
|
|
17
20
|
type SelectOption,
|
|
18
21
|
type SelectTriggerHtmlProps,
|
|
19
22
|
} from './core';
|
|
@@ -31,8 +34,16 @@ export interface SelectProps {
|
|
|
31
34
|
onChange?: (value: string, option: SelectOption) => void;
|
|
32
35
|
/** Trigger text when nothing is selected. @default 'Select an option' */
|
|
33
36
|
placeholder?: string;
|
|
34
|
-
/**
|
|
37
|
+
/** Trigger height, type and padding. The menu follows it unless `menuSize` overrides. @default 'md' */
|
|
35
38
|
size?: 'sm' | 'md' | 'lg';
|
|
39
|
+
/** Menu density on its own - row type, row padding and the filter field. A row carrying a
|
|
40
|
+
* description sits one step taller than a plain one at every step. @default the `size` value */
|
|
41
|
+
menuSize?: MenuSize;
|
|
42
|
+
/** Weight of every option label in the menu. @default 'medium' */
|
|
43
|
+
weight?: MenuWeight;
|
|
44
|
+
/** Menu width. `trigger` is never narrower than the trigger, `auto` fits the options, and
|
|
45
|
+
* `sm` | `md` | `lg` are fixed steps with long labels ellipsizing. @default 'trigger' */
|
|
46
|
+
width?: MenuWidth;
|
|
36
47
|
/** Disabled - trigger is inert and the menu cannot open. @default false */
|
|
37
48
|
disabled?: boolean;
|
|
38
49
|
/** Danger ring + border. @default false */
|
|
@@ -56,6 +67,9 @@ export interface SelectProps {
|
|
|
56
67
|
ariaLabel?: string;
|
|
57
68
|
/** Standard <div> attributes (className, style, data-*, ...) forwarded to the select root. */
|
|
58
69
|
htmlProps?: HTMLAttributes<HTMLDivElement> & DataAttributes;
|
|
70
|
+
/** Standard attributes (className, style, data-*, ...) forwarded to the menu panel, which portals
|
|
71
|
+
* to <body> and inherits nothing from the root. */
|
|
72
|
+
menuProps?: SelectMenuHtmlProps;
|
|
59
73
|
/** Whether the trigger and the options fire on `pointerdown` (snappier) or wait for `click`.
|
|
60
74
|
* @default 'pointerdown' */
|
|
61
75
|
activateOn?: ActivateOn;
|
|
@@ -63,8 +77,12 @@ export interface SelectProps {
|
|
|
63
77
|
animation?: DisableableAnimation;
|
|
64
78
|
/** Standard <button> attributes (className, style, aria-*, data-*, ...) merged onto the trigger.
|
|
65
79
|
* `onClick` and `onKeyDown` run before the built-in open/close and arrow-key handling, which
|
|
66
|
-
* cannot be replaced - the trigger is the combobox. */
|
|
80
|
+
* cannot be replaced - the trigger is the combobox. Ignored when `trigger` replaces it. */
|
|
67
81
|
triggerProps?: SelectTriggerHtmlProps;
|
|
82
|
+
/** Your own element in place of the built-in trigger. It is cloned with the combobox wiring - role,
|
|
83
|
+
* aria, open/close, arrow keys, and the anchor the menu measures - so it must render one focusable
|
|
84
|
+
* element that forwards its props and ref. Pass a function to read `{ open, selected }`. */
|
|
85
|
+
trigger?: CustomTrigger<SelectOption | null>;
|
|
68
86
|
/** Show check icon on selected value */
|
|
69
87
|
showCheck?: boolean;
|
|
70
88
|
}
|
|
@@ -76,6 +94,7 @@ export function Select({
|
|
|
76
94
|
onChange,
|
|
77
95
|
placeholder = 'Select an option',
|
|
78
96
|
size = 'md',
|
|
97
|
+
menuSize = size,
|
|
79
98
|
disabled = false,
|
|
80
99
|
invalid = false,
|
|
81
100
|
loading = false,
|
|
@@ -83,13 +102,17 @@ export function Select({
|
|
|
83
102
|
searchPlaceholder = 'Filter options',
|
|
84
103
|
highlight = 'neutral',
|
|
85
104
|
rail = false,
|
|
105
|
+
weight = 'medium',
|
|
106
|
+
width = 'trigger',
|
|
86
107
|
leadingIcon = null,
|
|
87
108
|
id,
|
|
88
109
|
ariaLabel,
|
|
89
110
|
htmlProps,
|
|
111
|
+
menuProps,
|
|
90
112
|
activateOn = 'pointerdown',
|
|
91
113
|
animation,
|
|
92
114
|
triggerProps,
|
|
115
|
+
trigger,
|
|
93
116
|
showCheck = true,
|
|
94
117
|
}: SelectProps) {
|
|
95
118
|
const [value, setValue] = useControllable<string | null, SelectOption>(controlledValue, defaultValue, onChange);
|
|
@@ -108,12 +131,14 @@ export function Select({
|
|
|
108
131
|
|
|
109
132
|
const selected = lb.flat.find((o) => o.value === value) || null;
|
|
110
133
|
const isPlaceholder = !loading && !selected;
|
|
134
|
+
const customTrigger = typeof trigger === 'function' ? trigger({ open: lb.open, selected }) : trigger;
|
|
111
135
|
|
|
112
136
|
return (
|
|
113
137
|
<div
|
|
114
138
|
{...htmlProps}
|
|
115
139
|
className={cx('zc-select', htmlProps?.className)}
|
|
116
140
|
data-size={size}
|
|
141
|
+
data-custom-trigger={customTrigger ? 'true' : undefined}
|
|
117
142
|
data-open={lb.open ? 'true' : undefined}
|
|
118
143
|
data-disabled={disabled ? 'true' : undefined}
|
|
119
144
|
data-invalid={invalid ? 'true' : undefined}
|
|
@@ -121,6 +146,7 @@ export function Select({
|
|
|
121
146
|
>
|
|
122
147
|
<SelectTrigger
|
|
123
148
|
lb={lb}
|
|
149
|
+
node={customTrigger}
|
|
124
150
|
disabled={disabled}
|
|
125
151
|
invalid={invalid}
|
|
126
152
|
ariaLabel={ariaLabel}
|
|
@@ -138,8 +164,12 @@ export function Select({
|
|
|
138
164
|
ariaLabel={ariaLabel}
|
|
139
165
|
highlight={highlight}
|
|
140
166
|
rail={rail}
|
|
167
|
+
size={menuSize}
|
|
168
|
+
weight={weight}
|
|
169
|
+
width={width}
|
|
141
170
|
activateOn={activateOn}
|
|
142
171
|
animation={animation}
|
|
172
|
+
menuProps={menuProps}
|
|
143
173
|
{...(!showCheck && { check: () => null })}
|
|
144
174
|
/>
|
|
145
175
|
</div>
|
|
@@ -6,8 +6,17 @@ Docs: https://ui.zyncat.app/select
|
|
|
6
6
|
Single-select listbox in a popover, searchable; holds value: string | null.
|
|
7
7
|
|
|
8
8
|
options: SelectOption[]; value: string|null, onChange(value); searchable, leadingIcon, placeholder,
|
|
9
|
-
invalid, loading, ariaLabel.
|
|
9
|
+
invalid, loading, ariaLabel. size sets the trigger height and the row padding in the menu together; weight sets the option
|
|
10
|
+
label weight regular|medium|semibold.
|
|
11
|
+
highlight neutral|accent picks the hue of the highlight travelling
|
|
10
12
|
between options; rail adds a short accent bar on its leading edge.
|
|
13
|
+
trigger replaces the built-in combobox with your own element - a node, or a function of
|
|
14
|
+
{ open, selected } where selected is the SelectOption or null. It is cloned with the full wiring -
|
|
15
|
+
role, aria-expanded/controls/activedescendant, open/close, arrow keys - and becomes the anchor the
|
|
16
|
+
menu measures, so it must render ONE focusable element that forwards its props and its ref (a Button
|
|
17
|
+
does; a plain div is not focusable). placeholder, leadingIcon and triggerProps then stop applying and
|
|
18
|
+
the root drops its width: 100%, leaving the trigger its intrinsic width; size still drives the menu,
|
|
19
|
+
loading still blocks opening, disabled still makes it inert with aria-disabled.
|
|
11
20
|
|
|
12
21
|
```tsx
|
|
13
22
|
<Select
|
|
@@ -18,4 +27,7 @@ between options; rail adds a short accent bar on its leading edge.
|
|
|
18
27
|
placeholder="Choose a time zone"
|
|
19
28
|
ariaLabel="Time zone"
|
|
20
29
|
/>
|
|
30
|
+
<Select options={TIMEZONES} value={tz} onChange={setTz} ariaLabel="Time zone" trigger={({ open, selected }) => (
|
|
31
|
+
<Button variant="secondary" data-open={open || undefined}>{selected?.label ?? 'Choose a time zone'}</Button>
|
|
32
|
+
)} />
|
|
21
33
|
```
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
export { useListbox } from './use-listbox';
|
|
2
|
-
export { SelectTrigger, type SelectTriggerHtmlProps } from './trigger';
|
|
2
|
+
export { SelectTrigger, type CustomTrigger, type SelectTriggerHtmlProps } from './trigger';
|
|
3
3
|
export { ListboxPanel } from './panel';
|
|
4
|
+
export type { SelectMenuHtmlProps } from './menu';
|
|
4
5
|
export type { SelectOption, SelectGroup } from './types';
|
|
@@ -1,16 +1,22 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
|
|
3
|
-
import {
|
|
3
|
+
import { useRef, type HTMLAttributes, type ReactNode, type RefObject } from 'react';
|
|
4
4
|
|
|
5
|
+
import type { DataAttributes } from '../../../../dom-props';
|
|
5
6
|
import type { Layer } from '../../../../engine';
|
|
6
7
|
import { resolveMotionTiming } from '../../../../motion/motion-timing';
|
|
7
8
|
import { Presence } from '../../../../motion/presence';
|
|
8
9
|
import type { DisableableAnimation } from '../../../../motion/timing';
|
|
9
10
|
import { useMotion, type MotionSpecs } from '../../../../motion/use-motion';
|
|
10
11
|
import { motionFor, type MotionTransition } from '../../../../tokens/motion-tokens';
|
|
11
|
-
import {
|
|
12
|
+
import { menuSurfaceAttrs, type MenuSurfaceProps } from '../../../internal/menu/highlight';
|
|
13
|
+
import { useAnchorWidth } from '../../../internal/menu/use-anchor-width';
|
|
14
|
+
import { useReturnFocus } from '../../../internal/overlay/focus';
|
|
12
15
|
import { OverlayPortal, useOutsidePress, useOverlayEntry } from '../../../internal/overlay/layer';
|
|
13
16
|
import { useAnchorPosition } from '../../../internal/overlay/position';
|
|
17
|
+
import { cx } from '../../../internal/utils/cx';
|
|
18
|
+
|
|
19
|
+
export type SelectMenuHtmlProps = HTMLAttributes<HTMLDivElement> & DataAttributes;
|
|
14
20
|
|
|
15
21
|
const SELECT_MENU_TIMING = {
|
|
16
22
|
open: { duration: 'base', ease: 'entrance' },
|
|
@@ -37,13 +43,14 @@ function selectMenuLayers(
|
|
|
37
43
|
];
|
|
38
44
|
}
|
|
39
45
|
|
|
40
|
-
export interface SelectMenuProps extends
|
|
46
|
+
export interface SelectMenuProps extends MenuSurfaceProps {
|
|
41
47
|
open: boolean;
|
|
42
48
|
menuId: string;
|
|
43
49
|
requestClose: () => void;
|
|
44
|
-
triggerRef: RefObject<
|
|
50
|
+
triggerRef: RefObject<HTMLElement | null>;
|
|
45
51
|
multiple?: boolean;
|
|
46
52
|
animation?: DisableableAnimation;
|
|
53
|
+
menuProps?: SelectMenuHtmlProps;
|
|
47
54
|
children?: ReactNode;
|
|
48
55
|
}
|
|
49
56
|
|
|
@@ -54,6 +61,10 @@ function MenuSurface({
|
|
|
54
61
|
multiple,
|
|
55
62
|
highlight,
|
|
56
63
|
rail,
|
|
64
|
+
size,
|
|
65
|
+
weight,
|
|
66
|
+
width = 'trigger',
|
|
67
|
+
menuProps,
|
|
57
68
|
animate,
|
|
58
69
|
exit,
|
|
59
70
|
children,
|
|
@@ -61,26 +72,20 @@ function MenuSurface({
|
|
|
61
72
|
const menuRef = useRef<HTMLDivElement>(null);
|
|
62
73
|
const entry = useOverlayEntry({ nodeRef: menuRef, dismissible: true, requestClose });
|
|
63
74
|
useMotion(menuRef, { animate, exit });
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
const t = triggerRef.current;
|
|
67
|
-
if (t && menuRef.current) menuRef.current.style.minWidth = t.getBoundingClientRect().width + 'px';
|
|
68
|
-
};
|
|
69
|
-
apply();
|
|
70
|
-
window.addEventListener('resize', apply);
|
|
71
|
-
return () => window.removeEventListener('resize', apply);
|
|
72
|
-
}, []); // eslint-disable-line react-hooks/exhaustive-deps
|
|
75
|
+
useReturnFocus(menuRef);
|
|
76
|
+
useAnchorWidth(triggerRef, menuRef, width === 'trigger');
|
|
73
77
|
useAnchorPosition({ side: 'bottom', align: 'start', arrow: false, triggerRef, panelRef: menuRef });
|
|
74
78
|
useOutsidePress({ entry, refs: [menuRef, triggerRef], enabled: true, onPress: requestClose });
|
|
75
79
|
|
|
76
80
|
return (
|
|
77
81
|
<div
|
|
82
|
+
{...menuProps}
|
|
78
83
|
ref={menuRef}
|
|
79
|
-
className=
|
|
84
|
+
className={cx('zc-menu-surface zc-select__menu', menuProps?.className)}
|
|
80
85
|
id={menuId}
|
|
81
86
|
role="presentation"
|
|
82
87
|
data-multiple={multiple ? 'true' : undefined}
|
|
83
|
-
{...
|
|
88
|
+
{...menuSurfaceAttrs({ highlight, rail, size, weight, width })}
|
|
84
89
|
>
|
|
85
90
|
{children}
|
|
86
91
|
</div>
|
|
@@ -95,7 +100,11 @@ export function SelectMenu({
|
|
|
95
100
|
multiple,
|
|
96
101
|
highlight,
|
|
97
102
|
rail,
|
|
103
|
+
size,
|
|
104
|
+
weight,
|
|
105
|
+
width,
|
|
98
106
|
animation,
|
|
107
|
+
menuProps,
|
|
99
108
|
children,
|
|
100
109
|
}: SelectMenuProps) {
|
|
101
110
|
return (
|
|
@@ -112,6 +121,10 @@ export function SelectMenu({
|
|
|
112
121
|
multiple={multiple}
|
|
113
122
|
highlight={highlight}
|
|
114
123
|
rail={rail}
|
|
124
|
+
size={size}
|
|
125
|
+
weight={weight}
|
|
126
|
+
width={width}
|
|
127
|
+
menuProps={menuProps}
|
|
115
128
|
>
|
|
116
129
|
{children}
|
|
117
130
|
</MenuSurface>
|