@zyncat/ui 0.19.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.css +1 -2
- package/dist/alert.js +6 -6
- package/dist/avatar.css +1 -1
- package/dist/badge.css +21 -12
- 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.css +1 -2
- package/dist/button.js +2 -2
- package/dist/checkbox.css +1 -1
- 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/collapse.css +1 -1
- package/dist/confetti.css +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 +7 -8
- 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.css +1 -2
- package/dist/dialog.js +9 -9
- package/dist/digit-strip.css +1 -1
- package/dist/dropdown.css +13 -10
- package/dist/dropdown.js +37 -20
- package/dist/dropdown.js.map +1 -1
- package/dist/emoji-picker.js +14 -14
- package/dist/facebook-feed.css +1 -1
- package/dist/flow-field.css +1 -1
- package/dist/flow-field.js +1 -1
- package/dist/glide.js +2 -2
- package/dist/icon.css +1 -1
- package/dist/input.css +1 -4
- package/dist/instagram-feed.css +1 -1
- package/dist/instagram-feed.js +2 -2
- package/dist/lens.css +1 -1
- package/dist/lens.js +1 -1
- package/dist/menu-surface.css +82 -8
- package/dist/modal.css +1 -1
- package/dist/modal.js +8 -8
- package/dist/morphing-text.css +1 -1
- package/dist/morphing-text.js +1 -1
- package/dist/motion-devtools.css +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 +17 -11
- 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/overlay.css +1 -1
- package/dist/pagination.css +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.css +1 -1
- package/dist/popover.js +9 -9
- package/dist/radio-group.css +11 -5
- package/dist/radio-group.js +5 -5
- package/dist/select.css +34 -8
- package/dist/select.js +25 -12
- package/dist/select.js.map +1 -1
- package/dist/sheet.css +1 -1
- package/dist/sheet.js +9 -9
- package/dist/spinner.css +1 -1
- package/dist/styles.css +1 -1
- package/dist/support-rail.css +7 -2
- package/dist/support-rail.js +11 -11
- package/dist/table.css +10 -5
- package/dist/table.js +7 -7
- package/dist/tabs.css +32 -7
- package/dist/tabs.js +55 -44
- package/dist/tabs.js.map +1 -1
- package/dist/tag.css +1 -1
- package/dist/tag.js +4 -4
- package/dist/textarea.css +14 -2
- package/dist/textarea.js +36 -23
- package/dist/textarea.js.map +1 -1
- package/dist/theme-grid.js +5 -5
- package/dist/theme-switcher.css +1 -2
- 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 +50 -1
- 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.css +1 -1
- package/dist/tiktok.js +2 -2
- package/dist/time-field.js +5 -3
- package/dist/time-field.js.map +1 -1
- package/dist/toast.css +1 -1
- package/dist/toast.js +7 -7
- package/dist/toggle-tag.js +2 -2
- package/dist/toggle.css +1 -1
- package/dist/toggle.js +4 -15
- package/dist/toggle.js.map +1 -1
- package/dist/tooltip.css +1 -1
- package/dist/tooltip.js +6 -7
- package/dist/tooltip.js.map +1 -1
- package/dist/trigger.css +1 -2
- 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 +6 -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 +38 -32
- package/dist/typing-lines.css +1 -1
- package/dist/typing-lines.js +1 -1
- package/dist/weight-field.css +1 -1
- package/dist/youtube.css +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/alert/alert.css +1 -2
- 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 +7 -8
- package/src/components/composites/date-picker/field-shell.tsx +14 -1
- package/src/components/composites/dialog/dialog.css +1 -2
- 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 +13 -10
- package/src/components/composites/dropdown/menu-panel.tsx +28 -13
- package/src/components/composites/dropdown/types.ts +5 -2
- package/src/components/composites/emoji-picker/styles.css +1 -1
- package/src/components/composites/modal/modal.css +1 -1
- package/src/components/composites/pagination/pagination.css +1 -1
- package/src/components/composites/popover/popover.css +1 -1
- 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 +34 -8
- package/src/components/composites/sheet/sheet.css +1 -1
- package/src/components/composites/table/table.css +10 -5
- package/src/components/composites/tabs/Tabs.tsx +13 -1
- package/src/components/composites/tabs/tabs.css +32 -7
- package/src/components/composites/theme-switcher/theme-switcher.css +1 -2
- package/src/components/composites/toast/toast.css +1 -1
- package/src/components/composites/tooltip/tooltip-host.tsx +1 -1
- package/src/components/composites/tooltip/tooltip.css +1 -1
- package/src/components/compound/support-rail/support-rail.css +7 -2
- package/src/components/dev/motion-devtools.css +1 -1
- package/src/components/expressive/confetti/confetti.css +1 -1
- package/src/components/expressive/facebook-feed/facebook-feed.css +1 -1
- package/src/components/expressive/flow-field/flow-field.css +1 -1
- package/src/components/expressive/instagram-feed/instagram-feed.css +1 -1
- package/src/components/expressive/lens/lens.css +1 -1
- package/src/components/expressive/morphing-text/morphing-text.css +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 +17 -11
- 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 +50 -1
- package/src/components/expressive/theme-transition/theme-transition.ts +21 -1
- package/src/components/expressive/theme-transition/tide.ts +15 -10
- package/src/components/expressive/tiktok/tiktok.css +1 -1
- package/src/components/expressive/typing-lines/typing-lines.css +1 -1
- package/src/components/expressive/weight-field/weight-field.css +1 -1
- package/src/components/expressive/youtube/youtube.css +1 -1
- package/src/components/internal/glass/glass.css +1 -1
- package/src/components/internal/icon/icon.css +1 -1
- 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 +82 -8
- 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/overlay.css +1 -1
- 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 +1 -2
- package/src/components/internal/utils/activation.ts +5 -0
- package/src/components/primitives/avatar/avatar.css +1 -1
- 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 +21 -12
- package/src/components/primitives/badge/digit-strip.css +1 -1
- 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/button/button.css +1 -2
- package/src/components/primitives/checkbox/checkbox.css +1 -1
- package/src/components/primitives/collapse/collapse.css +1 -1
- package/src/components/primitives/input/OtpField.tsx +17 -9
- package/src/components/primitives/input/input.css +1 -4
- package/src/components/primitives/radio-group/radio-group.css +11 -5
- package/src/components/primitives/spinner/spinner.css +1 -1
- package/src/components/primitives/tag/tag.css +1 -1
- 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 +14 -2
- package/src/components/primitives/toggle/Toggle.tsx +3 -12
- package/src/components/primitives/toggle/switch-glyph.tsx +25 -0
- package/src/components/primitives/toggle/toggle.css +1 -1
- 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/styles.css +1 -1
- package/src/theme-scope.ts +19 -0
- package/src/tokens/base.css +62 -13
- package/src/tokens/color.css +18 -16
- package/src/tokens/component-styles.generated.ts +0 -2
- package/src/tokens/dark.css +4 -1
- package/src/tokens/decisions.css +6 -4
- package/src/tokens/elevation.css +1 -1
- package/src/tokens/glass.css +1 -1
- package/src/tokens/motion.css +4 -4
- package/src/tokens/radius.css +1 -1
- package/src/tokens/reset.css +17 -45
- package/src/tokens/semantic.css +13 -7
- package/src/tokens/spacing.css +4 -4
- package/src/tokens/theme-tokens.generated.ts +38 -32
- package/src/tokens/typography.css +1 -1
- package/tailwind.css +3 -1
- 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
|
@@ -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>
|
|
@@ -2,19 +2,20 @@
|
|
|
2
2
|
|
|
3
3
|
import '../../../internal/menu/menu-surface.css';
|
|
4
4
|
|
|
5
|
-
import {
|
|
5
|
+
import type { ReactNode } from 'react';
|
|
6
6
|
|
|
7
7
|
import { GlidePill } from '../../../../motion/glide';
|
|
8
|
+
import { Presence } from '../../../../motion/presence';
|
|
8
9
|
import type { DisableableAnimation } from '../../../../motion/timing';
|
|
9
10
|
import { Icon } from '../../../internal/icon/Icon';
|
|
10
|
-
import type {
|
|
11
|
-
import { MenuRow } from '../../../internal/menu/menu-row';
|
|
11
|
+
import type { MenuSurfaceProps } from '../../../internal/menu/highlight';
|
|
12
|
+
import { MenuGroupLabel, MenuRow } from '../../../internal/menu/menu-row';
|
|
12
13
|
import { activationProps, type ActivateOn } from '../../../internal/utils/activation';
|
|
13
|
-
import {
|
|
14
|
-
import {
|
|
14
|
+
import { SelectMenu, type SelectMenuHtmlProps } from './menu';
|
|
15
|
+
import type { ListRow } from './types';
|
|
15
16
|
import type { ListboxState } from './use-listbox';
|
|
16
17
|
|
|
17
|
-
export interface ListboxPanelProps extends
|
|
18
|
+
export interface ListboxPanelProps extends MenuSurfaceProps {
|
|
18
19
|
lb: ListboxState;
|
|
19
20
|
loading: boolean;
|
|
20
21
|
searchable: boolean;
|
|
@@ -23,6 +24,7 @@ export interface ListboxPanelProps extends MenuHighlightProps {
|
|
|
23
24
|
multiple?: boolean;
|
|
24
25
|
activateOn?: ActivateOn;
|
|
25
26
|
animation?: DisableableAnimation;
|
|
27
|
+
menuProps?: SelectMenuHtmlProps;
|
|
26
28
|
check?: (selected: boolean) => ReactNode;
|
|
27
29
|
}
|
|
28
30
|
|
|
@@ -54,11 +56,41 @@ export function ListboxPanel({
|
|
|
54
56
|
multiple,
|
|
55
57
|
highlight,
|
|
56
58
|
rail,
|
|
59
|
+
size,
|
|
60
|
+
weight,
|
|
61
|
+
width,
|
|
57
62
|
activateOn,
|
|
58
63
|
animation,
|
|
64
|
+
menuProps,
|
|
59
65
|
check = defaultCheck,
|
|
60
66
|
}: ListboxPanelProps) {
|
|
61
|
-
const
|
|
67
|
+
const grouped = lb.sections.some((s) => s.label);
|
|
68
|
+
const option = (row: ListRow) => {
|
|
69
|
+
const opt = row.option;
|
|
70
|
+
const isSel = lb.isSelected(opt.value);
|
|
71
|
+
return (
|
|
72
|
+
<MenuRow
|
|
73
|
+
key={opt.value}
|
|
74
|
+
data-idx={row.index}
|
|
75
|
+
id={lb.optId(opt.value)}
|
|
76
|
+
className="zc-select__option"
|
|
77
|
+
role="option"
|
|
78
|
+
aria-selected={isSel}
|
|
79
|
+
aria-disabled={opt.disabled || undefined}
|
|
80
|
+
data-selected={isSel ? 'true' : undefined}
|
|
81
|
+
data-active={row.index === lb.activeIdx ? 'true' : undefined}
|
|
82
|
+
data-disabled={opt.disabled ? 'true' : undefined}
|
|
83
|
+
onMouseEnter={() => !opt.disabled && lb.setActiveIdx(row.index)}
|
|
84
|
+
onMouseDown={(e) => e.preventDefault()}
|
|
85
|
+
{...activationProps<HTMLDivElement>(() => lb.commit(opt), { on: activateOn, holdFocus: true })}
|
|
86
|
+
icon={opt.icon}
|
|
87
|
+
label={opt.label}
|
|
88
|
+
description={opt.description}
|
|
89
|
+
trailing={check(isSel) ? <span className="zc-select__option-check">{check(isSel)}</span> : null}
|
|
90
|
+
/>
|
|
91
|
+
);
|
|
92
|
+
};
|
|
93
|
+
|
|
62
94
|
return (
|
|
63
95
|
<SelectMenu
|
|
64
96
|
open={lb.open}
|
|
@@ -68,7 +100,11 @@ export function ListboxPanel({
|
|
|
68
100
|
multiple={multiple}
|
|
69
101
|
highlight={highlight}
|
|
70
102
|
rail={rail}
|
|
103
|
+
size={size}
|
|
104
|
+
weight={weight}
|
|
105
|
+
width={width}
|
|
71
106
|
animation={animation}
|
|
107
|
+
menuProps={menuProps}
|
|
72
108
|
>
|
|
73
109
|
{searchable && !loading && (
|
|
74
110
|
<div className="zc-select__search">
|
|
@@ -97,59 +133,28 @@ export function ListboxPanel({
|
|
|
97
133
|
tabIndex={-1}
|
|
98
134
|
aria-label={ariaLabel}
|
|
99
135
|
aria-activedescendant={searchable ? undefined : lb.adId}
|
|
136
|
+
data-grouped={grouped ? 'true' : undefined}
|
|
100
137
|
onKeyDown={searchable ? undefined : lb.onMenuKeyDown}
|
|
101
138
|
>
|
|
102
|
-
<GlidePill className="zc-menu-glide zc-select__glide" glide={lb.glide} />
|
|
103
139
|
{loading ? (
|
|
104
140
|
<LoadingRows />
|
|
105
141
|
) : (
|
|
106
|
-
<
|
|
107
|
-
{lb.
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
key={opt.value}
|
|
119
|
-
id={visible ? lb.optId(opt.value) : undefined}
|
|
120
|
-
data-idx={visible ? i : undefined}
|
|
121
|
-
className="zc-select__option"
|
|
122
|
-
role="option"
|
|
123
|
-
aria-selected={isSel}
|
|
124
|
-
aria-hidden={!visible || undefined}
|
|
125
|
-
aria-disabled={opt.disabled || undefined}
|
|
126
|
-
data-selected={isSel ? 'true' : undefined}
|
|
127
|
-
data-active={visible && i === lb.activeIdx ? 'true' : undefined}
|
|
128
|
-
data-disabled={opt.disabled ? 'true' : undefined}
|
|
129
|
-
onMouseEnter={() => visible && !opt.disabled && lb.setActiveIdx(i)}
|
|
130
|
-
onMouseDown={(e) => e.preventDefault()}
|
|
131
|
-
{...activationProps<HTMLDivElement>(() => visible && lb.commit(opt), {
|
|
132
|
-
on: activateOn,
|
|
133
|
-
holdFocus: true,
|
|
134
|
-
})}
|
|
135
|
-
icon={opt.icon}
|
|
136
|
-
label={opt.label}
|
|
137
|
-
description={opt.description}
|
|
138
|
-
trailing={check(isSel) ? <span className="zc-select__option-check">{check(isSel)}</span> : null}
|
|
139
|
-
/>
|
|
140
|
-
);
|
|
141
|
-
return searchable ? (
|
|
142
|
-
<Collapse key={opt.value} open={visible} fade>
|
|
143
|
-
{row}
|
|
144
|
-
</Collapse>
|
|
145
|
-
) : (
|
|
146
|
-
row
|
|
147
|
-
);
|
|
148
|
-
})}
|
|
142
|
+
<div className="zc-menu-list" ref={lb.contentRef}>
|
|
143
|
+
<GlidePill className="zc-menu-glide zc-select__glide" glide={lb.glide} />
|
|
144
|
+
{lb.sections.map((section) => (
|
|
145
|
+
<div className="zc-select__group" role="group" aria-label={section.label || undefined} key={section.key}>
|
|
146
|
+
<Presence initial={false}>
|
|
147
|
+
{section.label && section.rows.length ? (
|
|
148
|
+
<MenuGroupLabel key="label" className="zc-select__group-label">
|
|
149
|
+
{section.label}
|
|
150
|
+
</MenuGroupLabel>
|
|
151
|
+
) : null}
|
|
152
|
+
{section.rows.map(option)}
|
|
153
|
+
</Presence>
|
|
149
154
|
</div>
|
|
150
155
|
))}
|
|
151
156
|
{lb.navItems.length === 0 && <EmptyRow query={lb.query} />}
|
|
152
|
-
</
|
|
157
|
+
</div>
|
|
153
158
|
)}
|
|
154
159
|
</div>
|
|
155
160
|
</SelectMenu>
|
|
@@ -1,16 +1,19 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
|
|
3
|
-
import type { ButtonHTMLAttributes, ReactNode } from 'react';
|
|
3
|
+
import type { ButtonHTMLAttributes, KeyboardEvent, ReactElement, ReactNode } from 'react';
|
|
4
4
|
|
|
5
5
|
import type { DataAttributes } from '../../../../dom-props';
|
|
6
6
|
import { Icon } from '../../../internal/icon/Icon';
|
|
7
7
|
import { IconSlot } from '../../../internal/icon/IconSlot';
|
|
8
|
+
import { ovCloneTrigger } from '../../../internal/overlay/layer';
|
|
8
9
|
import { activationProps, type ActivateOn } from '../../../internal/utils/activation';
|
|
9
10
|
import { cx } from '../../../internal/utils/cx';
|
|
10
11
|
import type { ListboxState } from './use-listbox';
|
|
11
12
|
|
|
12
13
|
export type SelectTriggerHtmlProps = Omit<ButtonHTMLAttributes<HTMLButtonElement>, 'type'> & DataAttributes;
|
|
13
14
|
|
|
15
|
+
export type CustomTrigger<Selected> = ReactElement | ((state: { open: boolean; selected: Selected }) => ReactElement);
|
|
16
|
+
|
|
14
17
|
export interface SelectTriggerProps extends SelectTriggerHtmlProps {
|
|
15
18
|
lb: ListboxState;
|
|
16
19
|
invalid?: boolean;
|
|
@@ -20,6 +23,7 @@ export interface SelectTriggerProps extends SelectTriggerHtmlProps {
|
|
|
20
23
|
isPlaceholder?: boolean;
|
|
21
24
|
count?: number;
|
|
22
25
|
activateOn?: ActivateOn;
|
|
26
|
+
node?: ReactElement | null;
|
|
23
27
|
}
|
|
24
28
|
|
|
25
29
|
export function SelectTrigger({
|
|
@@ -32,16 +36,51 @@ export function SelectTrigger({
|
|
|
32
36
|
count,
|
|
33
37
|
className,
|
|
34
38
|
activateOn,
|
|
39
|
+
disabled,
|
|
40
|
+
node,
|
|
35
41
|
onClick,
|
|
36
42
|
onPointerDown,
|
|
37
43
|
onKeyDown,
|
|
38
44
|
...rest
|
|
39
45
|
}: SelectTriggerProps) {
|
|
40
46
|
const { triggerRef, baseId, open, adId, show, requestClose } = lb;
|
|
47
|
+
|
|
48
|
+
const toggle = () => {
|
|
49
|
+
if (triggerRef.current) triggerRef.current.focus({ preventScroll: true });
|
|
50
|
+
if (open) requestClose();
|
|
51
|
+
else show();
|
|
52
|
+
};
|
|
53
|
+
const openOnArrow = (e: KeyboardEvent<HTMLElement>) => {
|
|
54
|
+
if (open || (e.key !== 'ArrowDown' && e.key !== 'ArrowUp')) return;
|
|
55
|
+
e.preventDefault();
|
|
56
|
+
show();
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
if (node)
|
|
60
|
+
return ovCloneTrigger(node, {
|
|
61
|
+
open,
|
|
62
|
+
onPress: toggle,
|
|
63
|
+
onKeyDown: openOnArrow,
|
|
64
|
+
panelId: lb.listId,
|
|
65
|
+
haspopup: 'listbox',
|
|
66
|
+
triggerRef,
|
|
67
|
+
activateOn,
|
|
68
|
+
holdFocus: true,
|
|
69
|
+
attrs: {
|
|
70
|
+
role: 'combobox',
|
|
71
|
+
'aria-activedescendant': adId,
|
|
72
|
+
...(ariaLabel && { 'aria-label': ariaLabel }),
|
|
73
|
+
...(invalid && { 'aria-invalid': true }),
|
|
74
|
+
...(disabled && { 'aria-disabled': true }),
|
|
75
|
+
},
|
|
76
|
+
});
|
|
77
|
+
|
|
41
78
|
return (
|
|
42
79
|
<button
|
|
43
80
|
type="button"
|
|
44
|
-
ref={
|
|
81
|
+
ref={(el) => {
|
|
82
|
+
triggerRef.current = el;
|
|
83
|
+
}}
|
|
45
84
|
id={baseId + '-trigger'}
|
|
46
85
|
className={cx('zc-select__trigger', className)}
|
|
47
86
|
role="combobox"
|
|
@@ -51,18 +90,12 @@ export function SelectTrigger({
|
|
|
51
90
|
aria-activedescendant={adId}
|
|
52
91
|
aria-label={ariaLabel}
|
|
53
92
|
aria-invalid={invalid || undefined}
|
|
93
|
+
disabled={disabled}
|
|
54
94
|
onKeyDown={(e) => {
|
|
55
95
|
onKeyDown?.(e);
|
|
56
|
-
|
|
57
|
-
e.preventDefault();
|
|
58
|
-
show();
|
|
59
|
-
}
|
|
96
|
+
openOnArrow(e);
|
|
60
97
|
}}
|
|
61
|
-
{...activationProps<HTMLButtonElement>(
|
|
62
|
-
on: activateOn,
|
|
63
|
-
onPointerDown,
|
|
64
|
-
onClick,
|
|
65
|
-
})}
|
|
98
|
+
{...activationProps<HTMLButtonElement>(toggle, { on: activateOn, holdFocus: true, onPointerDown, onClick })}
|
|
66
99
|
{...rest}
|
|
67
100
|
>
|
|
68
101
|
{leading && (
|
|
@@ -25,6 +25,16 @@ export interface SelectGroup {
|
|
|
25
25
|
|
|
26
26
|
export type NormalizedGroup = CollectionGroup<SelectOption>;
|
|
27
27
|
|
|
28
|
+
export interface ListRow {
|
|
29
|
+
option: SelectOption;
|
|
30
|
+
index: number;
|
|
31
|
+
}
|
|
32
|
+
export interface ListSection {
|
|
33
|
+
key: string;
|
|
34
|
+
label?: string;
|
|
35
|
+
rows: ListRow[];
|
|
36
|
+
}
|
|
37
|
+
|
|
28
38
|
export const normalize = (
|
|
29
39
|
options: SelectOption[] | SelectGroup[],
|
|
30
40
|
): { groups: NormalizedGroup[]; flat: SelectOption[] } =>
|