@techsio/ui-kit 0.56.1 → 0.58.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +128 -133
- package/dist/atoms/action-icon.js +9 -8
- package/dist/atoms/button.js +78 -18
- package/dist/atoms/checkbox.js +77 -17
- package/dist/atoms/hotkeys.js +26 -7
- package/dist/atoms/icon.js +5 -5
- package/dist/atoms/image.js +107 -2
- package/dist/atoms/input.js +57 -9
- package/dist/atoms/label.js +13 -4
- package/dist/atoms/link-button.js +14 -12
- package/dist/atoms/link.js +18 -4
- package/dist/atoms/numeric-input.js +293 -76
- package/dist/atoms/rating.js +306 -73
- package/dist/atoms/skeleton.js +18 -14
- package/dist/atoms/status-text.js +31 -18
- package/dist/atoms/textarea.js +59 -12
- package/dist/atoms/tooltip.js +64 -43
- package/dist/hotkeys.js +1 -0
- package/dist/internal/choice-control.js +173 -0
- package/dist/internal/combobox-query-sync.js +11 -0
- package/dist/internal/date-picker-coordinator.js +56 -40
- package/dist/internal/date-picker-dom.js +44 -0
- package/dist/internal/date-picker-input.js +30 -0
- package/dist/internal/described-by.js +23 -18
- package/dist/internal/form-control-lifecycle.js +122 -0
- package/dist/internal/molecules/command.context.js +1 -0
- package/dist/internal/molecules/drawer.context.js +1 -0
- package/dist/internal/molecules/vertical-navigation.context.js +1 -0
- package/dist/internal/molecules/vertical-navigation.styles.js +9 -2
- package/dist/internal/numeric-input-editing.js +87 -0
- package/dist/internal/organisms/sidebar.context.js +1 -0
- package/dist/internal/organisms/sidebar.focus.js +1 -0
- package/dist/internal/overlay-portal.js +72 -0
- package/dist/internal/reduced-motion.js +1 -0
- package/dist/internal/use-effective-disabled.js +8 -0
- package/dist/molecules/accordion.js +44 -30
- package/dist/molecules/availability-status.js +1 -0
- package/dist/molecules/breadcrumb.js +11 -11
- package/dist/molecules/carousel.js +279 -97
- package/dist/molecules/cascade-select.js +327 -81
- package/dist/molecules/chart.js +276 -38
- package/dist/molecules/color-select.js +181 -62
- package/dist/molecules/combobox.js +535 -182
- package/dist/molecules/command.js +2 -1
- package/dist/molecules/date-picker.js +571 -119
- package/dist/molecules/dialog.js +81 -47
- package/dist/molecules/drawer.js +54 -5
- package/dist/molecules/file-upload.js +373 -37
- package/dist/molecules/form-checkbox.js +65 -22
- package/dist/molecules/form-error-summary.js +29 -5
- package/dist/molecules/form-input.js +26 -30
- package/dist/molecules/form-numeric-input.js +11 -9
- package/dist/molecules/form-textarea.js +26 -23
- package/dist/molecules/menu.js +170 -47
- package/dist/molecules/pagination.js +100 -28
- package/dist/molecules/phone-input.js +172 -37
- package/dist/molecules/popover.js +53 -26
- package/dist/molecules/price-block.js +1 -0
- package/dist/molecules/product-card.js +23 -18
- package/dist/molecules/quantity-field.js +4 -2
- package/dist/molecules/radio-card.js +102 -30
- package/dist/molecules/radio-group.js +108 -31
- package/dist/molecules/search-form.js +116 -13
- package/dist/molecules/select.js +226 -81
- package/dist/molecules/slider.js +141 -30
- package/dist/molecules/steps.js +181 -50
- package/dist/molecules/switch.js +85 -20
- package/dist/molecules/tabs.js +227 -31
- package/dist/molecules/toast.js +146 -51
- package/dist/molecules/totals-summary.js +2 -1
- package/dist/molecules/tour.js +9 -5
- package/dist/molecules/tree-view.js +255 -109
- package/dist/molecules/vertical-navigation.js +8 -4
- package/dist/organisms/data-table.fields.js +25 -5
- package/dist/organisms/data-table.helpers.js +6 -2
- package/dist/organisms/data-table.js +580 -151
- package/dist/organisms/footer.js +18 -11
- package/dist/organisms/gallery.js +61 -24
- package/dist/organisms/header.js +106 -32
- package/dist/organisms/line-item.js +1 -0
- package/dist/organisms/sidebar.js +1 -0
- package/dist/organisms/table.js +22 -7
- package/dist/src/atoms/action-icon.d.ts +10 -10
- package/dist/src/atoms/action-icon.d.ts.map +1 -1
- package/dist/src/atoms/badge.d.ts +3 -3
- package/dist/src/atoms/badge.d.ts.map +1 -1
- package/dist/src/atoms/button.d.ts +35 -24
- package/dist/src/atoms/button.d.ts.map +1 -1
- package/dist/src/atoms/checkbox.d.ts +6 -5
- package/dist/src/atoms/checkbox.d.ts.map +1 -1
- package/dist/src/atoms/hotkeys.d.ts +3 -2
- package/dist/src/atoms/hotkeys.d.ts.map +1 -1
- package/dist/src/atoms/icon.d.ts +18 -17
- package/dist/src/atoms/icon.d.ts.map +1 -1
- package/dist/src/atoms/image.d.ts +14 -6
- package/dist/src/atoms/image.d.ts.map +1 -1
- package/dist/src/atoms/input.d.ts +23 -14
- package/dist/src/atoms/input.d.ts.map +1 -1
- package/dist/src/atoms/label.d.ts +4 -4
- package/dist/src/atoms/label.d.ts.map +1 -1
- package/dist/src/atoms/link-button.d.ts +54 -31
- package/dist/src/atoms/link-button.d.ts.map +1 -1
- package/dist/src/atoms/link.d.ts +30 -9
- package/dist/src/atoms/link.d.ts.map +1 -1
- package/dist/src/atoms/numeric-input.d.ts +23 -19
- package/dist/src/atoms/numeric-input.d.ts.map +1 -1
- package/dist/src/atoms/rating.d.ts +54 -26
- package/dist/src/atoms/rating.d.ts.map +1 -1
- package/dist/src/atoms/skeleton.d.ts +9 -9
- package/dist/src/atoms/skeleton.d.ts.map +1 -1
- package/dist/src/atoms/status-text.d.ts +21 -13
- package/dist/src/atoms/status-text.d.ts.map +1 -1
- package/dist/src/atoms/textarea.d.ts +22 -20
- package/dist/src/atoms/textarea.d.ts.map +1 -1
- package/dist/src/atoms/tooltip.d.ts +5 -5
- package/dist/src/atoms/tooltip.d.ts.map +1 -1
- package/dist/src/hotkeys.d.ts +1 -1
- package/dist/src/hotkeys.d.ts.map +1 -1
- package/dist/src/internal/choice-control.d.ts +18 -0
- package/dist/src/internal/choice-control.d.ts.map +1 -0
- package/dist/src/internal/combobox-query-sync.d.ts +4 -0
- package/dist/src/internal/combobox-query-sync.d.ts.map +1 -0
- package/dist/src/internal/date-picker-coordinator.d.ts +7 -1
- package/dist/src/internal/date-picker-coordinator.d.ts.map +1 -1
- package/dist/src/internal/date-picker-dom.d.ts +10 -0
- package/dist/src/internal/date-picker-dom.d.ts.map +1 -0
- package/dist/src/internal/date-picker-input.d.ts +7 -0
- package/dist/src/internal/date-picker-input.d.ts.map +1 -0
- package/dist/src/internal/described-by.d.ts +7 -1
- package/dist/src/internal/described-by.d.ts.map +1 -1
- package/dist/src/internal/form-control-lifecycle.d.ts +22 -0
- package/dist/src/internal/form-control-lifecycle.d.ts.map +1 -0
- package/dist/src/internal/molecules/vertical-navigation.context.d.ts +1 -1
- package/dist/src/internal/molecules/vertical-navigation.context.d.ts.map +1 -1
- package/dist/src/internal/molecules/vertical-navigation.styles.d.ts +21 -0
- package/dist/src/internal/molecules/vertical-navigation.styles.d.ts.map +1 -1
- package/dist/src/internal/numeric-input-editing.d.ts +13 -0
- package/dist/src/internal/numeric-input-editing.d.ts.map +1 -0
- package/dist/src/internal/overlay-portal.d.ts +18 -0
- package/dist/src/internal/overlay-portal.d.ts.map +1 -0
- package/dist/src/internal/use-effective-disabled.d.ts +4 -0
- package/dist/src/internal/use-effective-disabled.d.ts.map +1 -0
- package/dist/src/molecules/accordion.d.ts +25 -19
- package/dist/src/molecules/accordion.d.ts.map +1 -1
- package/dist/src/molecules/availability-status.d.ts +4 -1
- package/dist/src/molecules/availability-status.d.ts.map +1 -1
- package/dist/src/molecules/breadcrumb.d.ts +2 -2
- package/dist/src/molecules/breadcrumb.d.ts.map +1 -1
- package/dist/src/molecules/carousel.d.ts +51 -52
- package/dist/src/molecules/carousel.d.ts.map +1 -1
- package/dist/src/molecules/cascade-select.d.ts +23 -8
- package/dist/src/molecules/cascade-select.d.ts.map +1 -1
- package/dist/src/molecules/chart.d.ts +7 -1
- package/dist/src/molecules/chart.d.ts.map +1 -1
- package/dist/src/molecules/color-select.d.ts +19 -3
- package/dist/src/molecules/color-select.d.ts.map +1 -1
- package/dist/src/molecules/combobox.d.ts +23 -5
- package/dist/src/molecules/combobox.d.ts.map +1 -1
- package/dist/src/molecules/command.d.ts +1 -1
- package/dist/src/molecules/date-picker.d.ts +7 -3
- package/dist/src/molecules/date-picker.d.ts.map +1 -1
- package/dist/src/molecules/dialog.d.ts +7 -3
- package/dist/src/molecules/dialog.d.ts.map +1 -1
- package/dist/src/molecules/drawer.d.ts +4 -4
- package/dist/src/molecules/drawer.d.ts.map +1 -1
- package/dist/src/molecules/file-upload.d.ts +11 -6
- package/dist/src/molecules/file-upload.d.ts.map +1 -1
- package/dist/src/molecules/form-checkbox.d.ts +7 -2
- package/dist/src/molecules/form-checkbox.d.ts.map +1 -1
- package/dist/src/molecules/form-error-summary.d.ts +4 -3
- package/dist/src/molecules/form-error-summary.d.ts.map +1 -1
- package/dist/src/molecules/form-input.d.ts +5 -6
- package/dist/src/molecules/form-input.d.ts.map +1 -1
- package/dist/src/molecules/form-numeric-input.d.ts +5 -5
- package/dist/src/molecules/form-numeric-input.d.ts.map +1 -1
- package/dist/src/molecules/form-textarea.d.ts +5 -6
- package/dist/src/molecules/form-textarea.d.ts.map +1 -1
- package/dist/src/molecules/menu.d.ts +17 -3
- package/dist/src/molecules/menu.d.ts.map +1 -1
- package/dist/src/molecules/pagination.d.ts +1 -1
- package/dist/src/molecules/pagination.d.ts.map +1 -1
- package/dist/src/molecules/phone-input.d.ts +4 -1
- package/dist/src/molecules/phone-input.d.ts.map +1 -1
- package/dist/src/molecules/popover.d.ts +7 -1
- package/dist/src/molecules/popover.d.ts.map +1 -1
- package/dist/src/molecules/price-block.d.ts +1 -1
- package/dist/src/molecules/price-block.d.ts.map +1 -1
- package/dist/src/molecules/product-card.d.ts +20 -25
- package/dist/src/molecules/product-card.d.ts.map +1 -1
- package/dist/src/molecules/quantity-field.d.ts +1 -1
- package/dist/src/molecules/quantity-field.d.ts.map +1 -1
- package/dist/src/molecules/radio-card.d.ts +10 -3
- package/dist/src/molecules/radio-card.d.ts.map +1 -1
- package/dist/src/molecules/radio-group.d.ts +15 -6
- package/dist/src/molecules/radio-group.d.ts.map +1 -1
- package/dist/src/molecules/search-form.d.ts +37 -12
- package/dist/src/molecules/search-form.d.ts.map +1 -1
- package/dist/src/molecules/select.d.ts +34 -29
- package/dist/src/molecules/select.d.ts.map +1 -1
- package/dist/src/molecules/slider.d.ts +23 -2
- package/dist/src/molecules/slider.d.ts.map +1 -1
- package/dist/src/molecules/steps.d.ts +30 -10
- package/dist/src/molecules/steps.d.ts.map +1 -1
- package/dist/src/molecules/switch.d.ts +54 -33
- package/dist/src/molecules/switch.d.ts.map +1 -1
- package/dist/src/molecules/tabs.d.ts +11 -11
- package/dist/src/molecules/tabs.d.ts.map +1 -1
- package/dist/src/molecules/toast.d.ts +25 -13
- package/dist/src/molecules/toast.d.ts.map +1 -1
- package/dist/src/molecules/totals-summary.d.ts +1 -1
- package/dist/src/molecules/totals-summary.d.ts.map +1 -1
- package/dist/src/molecules/tour.d.ts +1 -1
- package/dist/src/molecules/tour.d.ts.map +1 -1
- package/dist/src/molecules/tree-view.d.ts +16 -20
- package/dist/src/molecules/tree-view.d.ts.map +1 -1
- package/dist/src/molecules/vertical-navigation.d.ts +2 -2
- package/dist/src/molecules/vertical-navigation.d.ts.map +1 -1
- package/dist/src/organisms/data-table.d.ts +24 -3
- package/dist/src/organisms/data-table.d.ts.map +1 -1
- package/dist/src/organisms/data-table.fields.d.ts +4 -1
- package/dist/src/organisms/data-table.fields.d.ts.map +1 -1
- package/dist/src/organisms/data-table.helpers.d.ts +5 -12
- package/dist/src/organisms/data-table.helpers.d.ts.map +1 -1
- package/dist/src/organisms/footer.d.ts +5 -5
- package/dist/src/organisms/footer.d.ts.map +1 -1
- package/dist/src/organisms/gallery.d.ts +11 -9
- package/dist/src/organisms/gallery.d.ts.map +1 -1
- package/dist/src/organisms/header.d.ts +24 -22
- package/dist/src/organisms/header.d.ts.map +1 -1
- package/dist/src/organisms/table.d.ts +14 -14
- package/dist/src/organisms/table.d.ts.map +1 -1
- package/dist/src/templates/accordion.d.ts +8 -6
- package/dist/src/templates/accordion.d.ts.map +1 -1
- package/dist/src/templates/breadcrumb.d.ts +1 -1
- package/dist/src/templates/breadcrumb.d.ts.map +1 -1
- package/dist/src/templates/carousel.d.ts +3 -3
- package/dist/src/templates/carousel.d.ts.map +1 -1
- package/dist/src/templates/facet-filter-panel.d.ts +9 -3
- package/dist/src/templates/facet-filter-panel.d.ts.map +1 -1
- package/dist/src/templates/gallery.d.ts +2 -2
- package/dist/src/templates/gallery.d.ts.map +1 -1
- package/dist/src/templates/numeric-input.d.ts +1 -1
- package/dist/src/templates/numeric-input.d.ts.map +1 -1
- package/dist/src/templates/popover.d.ts +4 -2
- package/dist/src/templates/popover.d.ts.map +1 -1
- package/dist/src/templates/product-card.d.ts +12 -4
- package/dist/src/templates/product-card.d.ts.map +1 -1
- package/dist/src/templates/search-suggestions.d.ts +1 -1
- package/dist/src/templates/select.d.ts +7 -2
- package/dist/src/templates/select.d.ts.map +1 -1
- package/dist/src/templates/tabs.d.ts +8 -7
- package/dist/src/templates/tabs.d.ts.map +1 -1
- package/dist/src/theme/theme-config.d.ts +9 -16
- package/dist/src/theme/theme-config.d.ts.map +1 -1
- package/dist/src/theme/theme-provider.d.ts +16 -21
- package/dist/src/theme/theme-provider.d.ts.map +1 -1
- package/dist/src/theme/theme-toggle.d.ts.map +1 -1
- package/dist/src/utils.d.ts.map +1 -1
- package/dist/templates/accordion.js +3 -1
- package/dist/templates/breadcrumb.js +11 -4
- package/dist/templates/carousel.js +3 -6
- package/dist/templates/facet-filter-panel.js +121 -52
- package/dist/templates/gallery.js +6 -2
- package/dist/templates/numeric-input.js +6 -1
- package/dist/templates/popover.js +6 -1
- package/dist/templates/product-card.js +52 -26
- package/dist/templates/select.js +6 -1
- package/dist/templates/tabs.js +4 -2
- package/dist/theme/theme-config.js +8 -16
- package/dist/theme/theme-provider.js +89 -63
- package/dist/theme/theme-toggle.js +17 -9
- package/dist/utils.js +11 -1
- package/package.json +9 -5
- package/src/tokens/_base.css +4 -3
- package/src/tokens/_business-atoms.css +103 -0
- package/src/tokens/_foundation-overrides.css +251 -0
- package/src/tokens/_reset.css +10 -10
- package/src/tokens/_scheme-scopes.css +4144 -0
- package/src/tokens/_semantic.css +1 -23
- package/src/tokens/_tokens-base.css +36 -32
- package/src/tokens/_typography.css +2 -1
- package/src/tokens/components/_form-control.css +149 -6
- package/src/tokens/components/_popup-surface.css +15 -29
- package/src/tokens/components/atoms/_action-icon.css +49 -0
- package/src/tokens/components/atoms/_button.css +67 -0
- package/src/tokens/components/atoms/_checkbox.css +47 -4
- package/src/tokens/components/atoms/_hotkeys.css +2 -0
- package/src/tokens/components/atoms/_icon.css +60 -7
- package/src/tokens/components/atoms/_image.css +18 -0
- package/src/tokens/components/atoms/_input.css +20 -0
- package/src/tokens/components/atoms/_label.css +3 -7
- package/src/tokens/components/atoms/_link.css +47 -5
- package/src/tokens/components/atoms/_numeric-input.css +111 -2
- package/src/tokens/components/atoms/_rating.css +55 -6
- package/src/tokens/components/atoms/_skeleton.css +12 -2
- package/src/tokens/components/atoms/_status-text.css +35 -5
- package/src/tokens/components/atoms/_textarea.css +32 -3
- package/src/tokens/components/atoms/_tooltip.css +25 -0
- package/src/tokens/components/molecules/_accordion.css +46 -5
- package/src/tokens/components/molecules/_breadcrumb.css +15 -4
- package/src/tokens/components/molecules/_carousel.css +67 -0
- package/src/tokens/components/molecules/_cascade-select.css +104 -0
- package/src/tokens/components/molecules/_chart.css +12 -14
- package/src/tokens/components/molecules/_color-select.css +21 -0
- package/src/tokens/components/molecules/_combobox.css +81 -0
- package/src/tokens/components/molecules/_command.css +1 -0
- package/src/tokens/components/molecules/_date-picker.css +66 -10
- package/src/tokens/components/molecules/_dialog.css +36 -4
- package/src/tokens/components/molecules/_drawer.css +39 -3
- package/src/tokens/components/molecules/_file-upload.css +16 -1
- package/src/tokens/components/molecules/_menu.css +17 -0
- package/src/tokens/components/molecules/_pagination.css +19 -0
- package/src/tokens/components/molecules/_phone-input.css +20 -5
- package/src/tokens/components/molecules/_popover.css +34 -0
- package/src/tokens/components/molecules/_product-card.css +49 -0
- package/src/tokens/components/molecules/_radio-card.css +35 -0
- package/src/tokens/components/molecules/_radio-group.css +8 -0
- package/src/tokens/components/molecules/_select.css +33 -0
- package/src/tokens/components/molecules/_slider.css +5 -0
- package/src/tokens/components/molecules/_steps.css +52 -0
- package/src/tokens/components/molecules/_switch.css +59 -10
- package/src/tokens/components/molecules/_tabs.css +61 -3
- package/src/tokens/components/molecules/_toast.css +60 -0
- package/src/tokens/components/molecules/_totals-summary.css +22 -22
- package/src/tokens/components/molecules/_tour.css +16 -1
- package/src/tokens/components/molecules/_tree-view.css +27 -3
- package/src/tokens/components/molecules/_vertical-navigation.css +21 -3
- package/src/tokens/components/organisms/_data-table.css +97 -0
- package/src/tokens/components/organisms/_footer.css +9 -0
- package/src/tokens/components/organisms/_gallery.css +11 -0
- package/src/tokens/components/organisms/_header.css +22 -0
- package/src/tokens/components/organisms/_sidebar.css +1 -1
- package/src/tokens/components/organisms/_table.css +31 -0
- package/src/tokens/components/templates/_facet-filter-panel.css +11 -1
- package/src/tokens/figma/akros/variables.css +6 -6
- package/src/tokens/figma/brand-overrides.css +162 -57
- package/src/tokens/figma/business/variables.css +6 -6
- package/src/tokens/figma/cyber/variables.css +115 -38
- package/src/tokens/figma/cyber-dark/variables.css +115 -38
- package/src/tokens/figma/dark/variables.css +4 -4
- package/src/tokens/figma/light/variables.css +43 -40
- package/src/tokens/figma/{neo → n1}/variables.css +114 -114
- package/src/tokens/figma/variables.css +639 -240
- package/src/tokens/theme.css +24 -4
- package/src/tokens/_colors.css +0 -5
- package/src/tokens/figma/neo-dark/variables.css +0 -457
|
@@ -1,13 +1,19 @@
|
|
|
1
|
+
"use client";
|
|
1
2
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
2
|
-
import { createElement, useEffect, useId, useMemo, useState } from "react";
|
|
3
|
+
import { createElement, useEffect, useId, useLayoutEffect, useMemo, useRef, useState } from "react";
|
|
3
4
|
import { collection as combobox_collection, connect, machine } from "@zag-js/combobox";
|
|
4
|
-
import {
|
|
5
|
+
import { mergeProps, normalizeProps, useMachine } from "@zag-js/react";
|
|
5
6
|
import { ActionIcon } from "../atoms/action-icon.js";
|
|
6
7
|
import { Button } from "../atoms/button.js";
|
|
7
8
|
import { Icon } from "../atoms/icon.js";
|
|
8
9
|
import { Input } from "../atoms/input.js";
|
|
9
10
|
import { Label } from "../atoms/label.js";
|
|
10
11
|
import { StatusText } from "../atoms/status-text.js";
|
|
12
|
+
import { acknowledgeComboboxQuery, queueComboboxQuery } from "../internal/combobox-query-sync.js";
|
|
13
|
+
import { joinDescribedBy } from "../internal/described-by.js";
|
|
14
|
+
import { subscribeOwnerFormReset, syncReactFormControl } from "../internal/form-control-lifecycle.js";
|
|
15
|
+
import { OverlayPortal } from "../internal/overlay-portal.js";
|
|
16
|
+
import { useEffectiveDisabled } from "../internal/use-effective-disabled.js";
|
|
11
17
|
import { tv } from "../utils.js";
|
|
12
18
|
const comboboxVariants = tv({
|
|
13
19
|
slots: {
|
|
@@ -15,7 +21,7 @@ const comboboxVariants = tv({
|
|
|
15
21
|
"relative flex w-full flex-col"
|
|
16
22
|
],
|
|
17
23
|
label: [
|
|
18
|
-
"block font-label
|
|
24
|
+
"block font-label"
|
|
19
25
|
],
|
|
20
26
|
control: [
|
|
21
27
|
"form-control-base relative flex w-full min-w-0 items-center overflow-clip",
|
|
@@ -48,13 +54,13 @@ const comboboxVariants = tv({
|
|
|
48
54
|
"p-combobox-trigger"
|
|
49
55
|
],
|
|
50
56
|
positioner: [
|
|
51
|
-
"isolate w-(--reference-width)"
|
|
57
|
+
"popup-layer isolate w-(--reference-width)"
|
|
52
58
|
],
|
|
53
59
|
content: [
|
|
54
|
-
"popup-surface-base",
|
|
60
|
+
"popup-surface-base popup-layer",
|
|
55
61
|
"w-full",
|
|
56
62
|
"flex flex-col overflow-hidden",
|
|
57
|
-
"duration-200 ease-out motion-safe:transition-[opacity,display,translate,scale]",
|
|
63
|
+
"duration-200 ease-out motion-safe:transition-[opacity,display,translate,scale] motion-reduce:transition-none motion-reduce:duration-0",
|
|
58
64
|
"transition-discrete",
|
|
59
65
|
"starting:scale-98 starting:opacity-0",
|
|
60
66
|
"data-[state=open]:starting:scale-98 data-[state=open]:starting:opacity-0",
|
|
@@ -75,18 +81,13 @@ const comboboxVariants = tv({
|
|
|
75
81
|
"min-w-0 flex-grow truncate"
|
|
76
82
|
],
|
|
77
83
|
item: [
|
|
78
|
-
"
|
|
79
|
-
"hover:bg-popup-item-bg-hover",
|
|
80
|
-
"data-highlighted:bg-popup-item-bg-hover",
|
|
81
|
-
"data-[state=checked]:bg-popup-item-bg-selected",
|
|
82
|
-
"data-[state=checked]:text-popup-item-fg-selected",
|
|
83
|
-
"data-disabled:cursor-not-allowed data-disabled:text-popup-item-fg-disabled",
|
|
84
|
+
"combobox-item-base",
|
|
84
85
|
"transition-colors duration-200 motion-reduce:transition-none"
|
|
85
86
|
],
|
|
86
87
|
itemIndicator: [
|
|
87
|
-
"
|
|
88
|
+
"absolute end-(--popup-item-x) top-1/2 -translate-y-1/2",
|
|
88
89
|
"flex items-center justify-center",
|
|
89
|
-
"size-(--size-popup-indicator) text-
|
|
90
|
+
"size-(--size-popup-indicator) text-current"
|
|
90
91
|
],
|
|
91
92
|
emptyState: [
|
|
92
93
|
"px-(--popup-item-x) py-(--popup-item-y)",
|
|
@@ -106,6 +107,15 @@ const comboboxVariants = tv({
|
|
|
106
107
|
"data-[validation=success]:text-combobox-success-fg",
|
|
107
108
|
"data-[validation=warning]:text-combobox-warning-fg"
|
|
108
109
|
],
|
|
110
|
+
selectedList: [
|
|
111
|
+
"m-0 flex min-w-0 list-none flex-wrap gap-combobox-sm p-0"
|
|
112
|
+
],
|
|
113
|
+
selectedItem: [
|
|
114
|
+
"flex min-w-0 max-w-full items-center rounded-combobox-sm border border-combobox-footer-border bg-combobox-bg-base ps-combobox-input-sm"
|
|
115
|
+
],
|
|
116
|
+
selectedLabel: [
|
|
117
|
+
"wrap-anywhere min-w-0 text-combobox-status-fg"
|
|
118
|
+
],
|
|
109
119
|
multiple: []
|
|
110
120
|
},
|
|
111
121
|
compoundSlots: [
|
|
@@ -154,16 +164,262 @@ const comboboxVariants = tv({
|
|
|
154
164
|
size: "md"
|
|
155
165
|
}
|
|
156
166
|
});
|
|
157
|
-
function
|
|
167
|
+
function ComboboxOption({ api, item, navigation, disabled, readOnly, navigate, renderItem, styles }) {
|
|
168
|
+
const { item: itemSlot, itemText, itemIndicator } = styles;
|
|
169
|
+
const itemProps = api.getItemProps({
|
|
170
|
+
item
|
|
171
|
+
});
|
|
172
|
+
const itemContent = renderItem ? renderItem(item) : /*#__PURE__*/ jsx("span", {
|
|
173
|
+
className: itemText(),
|
|
174
|
+
children: item.label
|
|
175
|
+
});
|
|
176
|
+
if (navigation) {
|
|
177
|
+
const blocked = disabled || readOnly || item.disabled || !item.href;
|
|
178
|
+
return /*#__PURE__*/ jsx("a", {
|
|
179
|
+
...itemProps,
|
|
180
|
+
"aria-label": item.label,
|
|
181
|
+
className: itemSlot(),
|
|
182
|
+
href: blocked ? void 0 : item.href,
|
|
183
|
+
onClick: (event)=>{
|
|
184
|
+
if (blocked) return void event.preventDefault();
|
|
185
|
+
itemProps.onClick?.(event);
|
|
186
|
+
if (navigate && !event.defaultPrevented && 0 === event.button && !event.metaKey && !event.ctrlKey && !event.shiftKey && !event.altKey) {
|
|
187
|
+
event.preventDefault();
|
|
188
|
+
navigate({
|
|
189
|
+
node: event.currentTarget,
|
|
190
|
+
href: event.currentTarget.href,
|
|
191
|
+
value: item.value
|
|
192
|
+
});
|
|
193
|
+
}
|
|
194
|
+
},
|
|
195
|
+
children: itemContent
|
|
196
|
+
});
|
|
197
|
+
}
|
|
198
|
+
return /*#__PURE__*/ jsxs("div", {
|
|
199
|
+
...itemProps,
|
|
200
|
+
"aria-label": item.label,
|
|
201
|
+
className: itemSlot(),
|
|
202
|
+
children: [
|
|
203
|
+
itemContent,
|
|
204
|
+
/*#__PURE__*/ jsx("span", {
|
|
205
|
+
...api.getItemIndicatorProps({
|
|
206
|
+
item
|
|
207
|
+
}),
|
|
208
|
+
className: itemIndicator(),
|
|
209
|
+
children: /*#__PURE__*/ jsx(Icon, {
|
|
210
|
+
icon: "token-icon-check",
|
|
211
|
+
size: "current"
|
|
212
|
+
})
|
|
213
|
+
})
|
|
214
|
+
]
|
|
215
|
+
});
|
|
216
|
+
}
|
|
217
|
+
function ComboboxOptions({ groups, ...optionProps }) {
|
|
218
|
+
const { api, styles } = optionProps;
|
|
219
|
+
const renderOption = (item)=>/*#__PURE__*/ createElement(ComboboxOption, {
|
|
220
|
+
...optionProps,
|
|
221
|
+
item: item,
|
|
222
|
+
key: item.value
|
|
223
|
+
});
|
|
224
|
+
if (!groups) return api.collection.items.map(renderOption);
|
|
225
|
+
const visibleValues = new Set(api.collection.items.map((item)=>item.value));
|
|
226
|
+
return groups.map((group)=>{
|
|
227
|
+
const groupItems = group.items.filter((item)=>visibleValues.has(item.value));
|
|
228
|
+
if (0 === groupItems.length) return null;
|
|
229
|
+
const groupProps = api.getItemGroupProps({
|
|
230
|
+
id: group.id
|
|
231
|
+
});
|
|
232
|
+
return /*#__PURE__*/ createElement("div", {
|
|
233
|
+
...groupProps,
|
|
234
|
+
"aria-labelledby": group.label ? groupProps["aria-labelledby"] : void 0,
|
|
235
|
+
key: group.id,
|
|
236
|
+
children: [
|
|
237
|
+
group.label && /*#__PURE__*/ jsx("div", {
|
|
238
|
+
...api.getItemGroupLabelProps({
|
|
239
|
+
htmlFor: group.id
|
|
240
|
+
}),
|
|
241
|
+
className: styles.groupLabel(),
|
|
242
|
+
children: group.label
|
|
243
|
+
}),
|
|
244
|
+
groupItems.map(renderOption)
|
|
245
|
+
]
|
|
246
|
+
});
|
|
247
|
+
});
|
|
248
|
+
}
|
|
249
|
+
function normalizeValue(value) {
|
|
250
|
+
if ("string" == typeof value) return value ? [
|
|
251
|
+
value
|
|
252
|
+
] : [];
|
|
253
|
+
return value;
|
|
254
|
+
}
|
|
255
|
+
function getResultsState({ loading, error, hasOptions, inputValue }) {
|
|
256
|
+
if (loading) return "loading";
|
|
257
|
+
if (error) return "error";
|
|
258
|
+
if (hasOptions) return "results";
|
|
259
|
+
return inputValue ? "empty" : "idle";
|
|
260
|
+
}
|
|
261
|
+
function ComboboxClearTrigger({ api, navigation, clearable, clearIcon, size, disabled, readOnly }) {
|
|
262
|
+
const hasValue = navigation ? Boolean(api.inputValue) : api.value.length > 0;
|
|
263
|
+
if (readOnly || !(clearable && hasValue)) return null;
|
|
264
|
+
return /*#__PURE__*/ jsx(ActionIcon, {
|
|
265
|
+
icon: clearIcon,
|
|
266
|
+
size: size ?? "md",
|
|
267
|
+
tone: "neutral",
|
|
268
|
+
...api.getClearTriggerProps(),
|
|
269
|
+
"aria-label": api.getClearTriggerProps()["aria-label"] ?? "Clear value",
|
|
270
|
+
disabled: disabled || readOnly,
|
|
271
|
+
hidden: false,
|
|
272
|
+
onClick: (event)=>{
|
|
273
|
+
if (navigation) {
|
|
274
|
+
if (disabled || readOnly) return;
|
|
275
|
+
api.setInputValue("");
|
|
276
|
+
api.focus();
|
|
277
|
+
} else api.getClearTriggerProps().onClick?.(event);
|
|
278
|
+
}
|
|
279
|
+
});
|
|
280
|
+
}
|
|
281
|
+
function ComboboxStatus({ state, styles, loadingMessage, error, onRetry, disabled, readOnly, retryLabel, noResultsMessage, inputValue }) {
|
|
282
|
+
if ("loading" === state) return /*#__PURE__*/ jsxs("div", {
|
|
283
|
+
className: styles.status(),
|
|
284
|
+
role: "status",
|
|
285
|
+
children: [
|
|
286
|
+
/*#__PURE__*/ jsx(Icon, {
|
|
287
|
+
icon: "token-icon-spinner",
|
|
288
|
+
size: "current"
|
|
289
|
+
}),
|
|
290
|
+
/*#__PURE__*/ jsx("span", {
|
|
291
|
+
children: loadingMessage
|
|
292
|
+
})
|
|
293
|
+
]
|
|
294
|
+
});
|
|
295
|
+
if ("error" === state) return /*#__PURE__*/ jsxs("div", {
|
|
296
|
+
className: styles.status(),
|
|
297
|
+
role: "alert",
|
|
298
|
+
children: [
|
|
299
|
+
/*#__PURE__*/ jsx("span", {
|
|
300
|
+
className: "min-w-0 flex-1",
|
|
301
|
+
children: error
|
|
302
|
+
}),
|
|
303
|
+
onRetry && /*#__PURE__*/ jsx(Button, {
|
|
304
|
+
disabled: disabled || readOnly,
|
|
305
|
+
onClick: onRetry,
|
|
306
|
+
size: "sm",
|
|
307
|
+
variant: "secondary",
|
|
308
|
+
children: retryLabel
|
|
309
|
+
})
|
|
310
|
+
]
|
|
311
|
+
});
|
|
312
|
+
if ("empty" === state) return /*#__PURE__*/ jsx("div", {
|
|
313
|
+
className: styles.emptyState(),
|
|
314
|
+
role: "status",
|
|
315
|
+
children: noResultsMessage.replace("{inputValue}", inputValue)
|
|
316
|
+
});
|
|
317
|
+
return null;
|
|
318
|
+
}
|
|
319
|
+
function Combobox({ id, name, "aria-label": ariaLabel, "aria-labelledby": ariaLabelledBy, "aria-describedby": ariaDescribedBy, label, size, placeholder = "Select option", disabled: explicitDisabled = false, readOnly = false, required = false, items, groups, value, defaultValue, inputValue, defaultInputValue, multiple = false, validateStatus, helpText, showHelpTextIcon = true, noResultsMessage = 'No results found for "{inputValue}"', clearable = true, selectionBehavior = "replace", closeOnSelect = true, allowCustomValue = false, loopFocus = true, autoFocus = false, open, defaultOpen, triggerIcon = "token-icon-combobox-chevron", triggerIconSize, clearIcon = "token-icon-combobox-clear", inputBehavior = "autocomplete", filterBehavior = "local", loading = false, loadingMessage = "Loading results", error, retryLabel = "Retry", onRetry, renderItem, onChange, onInputValueChange, onOpenChange, mode = "selection", navigate, footer, portalled = true, ref, inputProps = {}, className, ...rootProps }) {
|
|
158
320
|
const generatedId = useId();
|
|
159
321
|
const uniqueId = id || generatedId;
|
|
160
322
|
const listId = `${uniqueId}-listbox`;
|
|
161
323
|
const helpTextId = `${uniqueId}-help`;
|
|
324
|
+
const selectedTextId = `${uniqueId}-selected`;
|
|
162
325
|
const navigation = "navigation" === mode;
|
|
163
326
|
const allItems = useMemo(()=>groups ? groups.flatMap((group)=>group.items) : items ?? [], [
|
|
164
327
|
groups,
|
|
165
328
|
items
|
|
166
329
|
]);
|
|
330
|
+
const inputRef = useRef(null);
|
|
331
|
+
const [disabledElement, setDisabledElement] = useState(null);
|
|
332
|
+
const disabled = useEffectiveDisabled(disabledElement, explicitDisabled);
|
|
333
|
+
const fullCollection = useMemo(()=>combobox_collection({
|
|
334
|
+
items: allItems,
|
|
335
|
+
itemToString: (item)=>item.label,
|
|
336
|
+
itemToValue: (item)=>item.value
|
|
337
|
+
}), [
|
|
338
|
+
allItems
|
|
339
|
+
]);
|
|
340
|
+
const selectionCollection = useRef(fullCollection);
|
|
341
|
+
selectionCollection.current = fullCollection;
|
|
342
|
+
const initialValue = useRef(normalizeValue(defaultValue) ?? []);
|
|
343
|
+
const resetting = useRef(false);
|
|
344
|
+
const nativeInputOwnsQuery = useRef(false);
|
|
345
|
+
const nativeQueries = useRef(new Set());
|
|
346
|
+
const pendingQueries = useRef([]);
|
|
347
|
+
const [query, setQuery] = useState(inputValue ?? "");
|
|
348
|
+
useLayoutEffect(()=>{
|
|
349
|
+
if (void 0 === inputValue) return;
|
|
350
|
+
if (nativeInputOwnsQuery.current) {
|
|
351
|
+
const remaining = acknowledgeComboboxQuery(pendingQueries.current, inputValue);
|
|
352
|
+
if (null !== remaining) {
|
|
353
|
+
pendingQueries.current = remaining;
|
|
354
|
+
return;
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
nativeInputOwnsQuery.current = false;
|
|
358
|
+
nativeQueries.current.clear();
|
|
359
|
+
pendingQueries.current = [];
|
|
360
|
+
setQuery(inputValue);
|
|
361
|
+
if (inputRef.current && inputRef.current.value !== inputValue) syncReactFormControl(inputRef.current, inputValue);
|
|
362
|
+
}, [
|
|
363
|
+
inputValue
|
|
364
|
+
]);
|
|
365
|
+
const resetSelection = useRef(null);
|
|
366
|
+
useLayoutEffect(()=>{
|
|
367
|
+
const restored = resetSelection.current;
|
|
368
|
+
const controlled = normalizeValue(value);
|
|
369
|
+
if (restored && controlled && (restored.length !== controlled.length || restored.some((item, index)=>item !== controlled[index]))) resetSelection.current = null;
|
|
370
|
+
}, [
|
|
371
|
+
value
|
|
372
|
+
]);
|
|
373
|
+
const coordinatedMachine = useMemo(()=>{
|
|
374
|
+
const syncSelectedItems = machine.implementations?.actions?.syncSelectedItems;
|
|
375
|
+
const syncInputValue = machine.implementations?.actions?.syncInputValue;
|
|
376
|
+
if (!(syncSelectedItems && syncInputValue)) throw new Error("Combobox selection synchronization unavailable");
|
|
377
|
+
return {
|
|
378
|
+
...machine,
|
|
379
|
+
implementations: {
|
|
380
|
+
...machine.implementations,
|
|
381
|
+
actions: {
|
|
382
|
+
...machine.implementations?.actions,
|
|
383
|
+
syncInputValue (params) {
|
|
384
|
+
if (nativeInputOwnsQuery.current) return;
|
|
385
|
+
syncInputValue(params);
|
|
386
|
+
},
|
|
387
|
+
syncSelectedItems (params) {
|
|
388
|
+
if ("preserve" !== params.prop("selectionBehavior")) {
|
|
389
|
+
nativeInputOwnsQuery.current = false;
|
|
390
|
+
nativeQueries.current.clear();
|
|
391
|
+
pendingQueries.current = [];
|
|
392
|
+
}
|
|
393
|
+
syncSelectedItems({
|
|
394
|
+
...params,
|
|
395
|
+
prop (key) {
|
|
396
|
+
const propValue = params.prop(key);
|
|
397
|
+
if ("collection" === key) return selectionCollection.current;
|
|
398
|
+
const restored = resetSelection.current;
|
|
399
|
+
const selected = params.context.get("value");
|
|
400
|
+
if ("selectionBehavior" === key && restored && restored.length === selected.length && restored.every((item, index)=>item === selected[index])) return "preserve";
|
|
401
|
+
return propValue;
|
|
402
|
+
}
|
|
403
|
+
});
|
|
404
|
+
}
|
|
405
|
+
}
|
|
406
|
+
}
|
|
407
|
+
};
|
|
408
|
+
}, []);
|
|
409
|
+
const focusableRef = useMemo(()=>(node)=>{
|
|
410
|
+
inputRef.current = node;
|
|
411
|
+
const cleanup = "function" == typeof ref ? ref(node) : void 0;
|
|
412
|
+
if (ref && "function" != typeof ref) ref.current = node;
|
|
413
|
+
return ()=>{
|
|
414
|
+
inputRef.current = null;
|
|
415
|
+
if ("function" == typeof cleanup) cleanup();
|
|
416
|
+
else if ("function" == typeof ref) ref(null);
|
|
417
|
+
else if (ref) ref.current = null;
|
|
418
|
+
};
|
|
419
|
+
}, [
|
|
420
|
+
ref
|
|
421
|
+
]);
|
|
422
|
+
const [focusVisible, setFocusVisible] = useState(false);
|
|
167
423
|
const [options, setOptions] = useState(allItems);
|
|
168
424
|
useEffect(()=>{
|
|
169
425
|
setOptions(allItems);
|
|
@@ -178,15 +434,12 @@ function Combobox({ id, name, label, size, placeholder = "Select option", disabl
|
|
|
178
434
|
itemToValue: (item)=>item.value,
|
|
179
435
|
isItemDisabled: (item)=>Boolean(resultsHidden || item.disabled || readOnly || navigation && !item.href)
|
|
180
436
|
});
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
normalizedDefaultValue
|
|
188
|
-
] : [];
|
|
189
|
-
const service = useMachine(machine, {
|
|
437
|
+
const notifyInputValueChange = (nextQuery)=>{
|
|
438
|
+
if (!resetting.current) resetSelection.current = null;
|
|
439
|
+
if ("local" === filterBehavior) setOptions(allItems.filter((item)=>item.label.toLowerCase().includes(nextQuery.toLowerCase())));
|
|
440
|
+
if (!(resetting.current || readOnly || disabled)) onInputValueChange?.(nextQuery);
|
|
441
|
+
};
|
|
442
|
+
const service = useMachine(coordinatedMachine, {
|
|
190
443
|
id: uniqueId,
|
|
191
444
|
name: navigation ? void 0 : name,
|
|
192
445
|
collection,
|
|
@@ -196,8 +449,8 @@ function Combobox({ id, name, label, size, placeholder = "Select option", disabl
|
|
|
196
449
|
selectionBehavior: navigation ? "preserve" : selectionBehavior,
|
|
197
450
|
allowCustomValue: !navigation && allowCustomValue,
|
|
198
451
|
autoFocus,
|
|
199
|
-
open,
|
|
200
|
-
defaultOpen,
|
|
452
|
+
open: readOnly || disabled ? false : open,
|
|
453
|
+
defaultOpen: readOnly || disabled ? false : defaultOpen,
|
|
201
454
|
inputBehavior,
|
|
202
455
|
loopFocus,
|
|
203
456
|
navigate,
|
|
@@ -217,92 +470,157 @@ function Combobox({ id, name, label, size, placeholder = "Select option", disabl
|
|
|
217
470
|
input: `${uniqueId}-input`,
|
|
218
471
|
control: `${uniqueId}-control`
|
|
219
472
|
},
|
|
220
|
-
value: navigation ? [] :
|
|
221
|
-
defaultValue: navigation ? void 0 :
|
|
473
|
+
value: navigation ? [] : normalizeValue(value),
|
|
474
|
+
defaultValue: navigation ? void 0 : normalizeValue(defaultValue),
|
|
222
475
|
multiple: !navigation && multiple,
|
|
223
|
-
inputValue,
|
|
476
|
+
inputValue: void 0 === inputValue ? void 0 : query,
|
|
477
|
+
defaultInputValue,
|
|
224
478
|
onValueChange: ({ value: selectedValue })=>{
|
|
225
|
-
if (!
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
479
|
+
if (!resetting.current) resetSelection.current = null;
|
|
480
|
+
if (!(resetting.current || navigation || readOnly || disabled)) {
|
|
481
|
+
onChange?.(selectedValue);
|
|
482
|
+
if (void 0 !== value) queueMicrotask(()=>service.send({
|
|
483
|
+
type: "SELECTED_ITEMS.SYNC"
|
|
484
|
+
}));
|
|
231
485
|
}
|
|
232
|
-
onInputValueChange?.(newItemInputValue);
|
|
233
486
|
},
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
487
|
+
onInputValueChange: ({ inputValue: nextQuery, reason })=>{
|
|
488
|
+
if ("input-change" === reason && nativeQueries.current.has(nextQuery)) return;
|
|
489
|
+
nativeInputOwnsQuery.current = false;
|
|
490
|
+
nativeQueries.current.clear();
|
|
491
|
+
pendingQueries.current = [];
|
|
492
|
+
if (void 0 !== inputValue) setQuery(inputValue);
|
|
493
|
+
notifyInputValueChange(nextQuery);
|
|
494
|
+
},
|
|
495
|
+
onOpenChange: ({ open: nextOpen, reason })=>{
|
|
496
|
+
if ("input-change" !== reason) setOptions(allItems);
|
|
497
|
+
onOpenChange?.(nextOpen);
|
|
237
498
|
}
|
|
238
499
|
});
|
|
239
500
|
const api = connect(service, normalizeProps);
|
|
240
|
-
const
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
}
|
|
255
|
-
|
|
256
|
-
className: itemText(),
|
|
257
|
-
children: item.label
|
|
258
|
-
});
|
|
259
|
-
if (navigation) {
|
|
260
|
-
const blocked = disabled || readOnly || item.disabled || !item.href;
|
|
261
|
-
return /*#__PURE__*/ createElement("a", {
|
|
262
|
-
...itemProps,
|
|
263
|
-
"aria-label": item.label,
|
|
264
|
-
className: itemSlot(),
|
|
265
|
-
href: blocked ? void 0 : item.href,
|
|
266
|
-
key: item.value,
|
|
267
|
-
onClick: (event)=>{
|
|
268
|
-
if (blocked) return void event.preventDefault();
|
|
269
|
-
itemProps.onClick?.(event);
|
|
270
|
-
if (navigate && !event.defaultPrevented && 0 === event.button && !event.metaKey && !event.ctrlKey && !event.shiftKey && !event.altKey) {
|
|
271
|
-
event.preventDefault();
|
|
272
|
-
navigate({
|
|
273
|
-
node: event.currentTarget,
|
|
274
|
-
href: event.currentTarget.href,
|
|
275
|
-
value: item.value
|
|
276
|
-
});
|
|
277
|
-
}
|
|
278
|
-
}
|
|
279
|
-
}, itemContent);
|
|
501
|
+
const previousSelectionCollection = useRef(fullCollection);
|
|
502
|
+
useLayoutEffect(()=>{
|
|
503
|
+
const previous = previousSelectionCollection.current;
|
|
504
|
+
previousSelectionCollection.current = fullCollection;
|
|
505
|
+
if (previous === fullCollection || navigation || "replace" !== selectionBehavior || void 0 !== inputValue) return;
|
|
506
|
+
const selected = service.context.get("value");
|
|
507
|
+
if (selected.some((item)=>!fullCollection.find(item))) return;
|
|
508
|
+
const previousText = previous.stringifyMany(selected);
|
|
509
|
+
const nextText = fullCollection.stringifyMany(selected);
|
|
510
|
+
if (previousText === nextText || service.context.get("inputValue") !== previousText) return;
|
|
511
|
+
resetSelection.current = null;
|
|
512
|
+
resetting.current = true;
|
|
513
|
+
try {
|
|
514
|
+
service.context.set("inputValue", nextText);
|
|
515
|
+
} finally{
|
|
516
|
+
resetting.current = false;
|
|
280
517
|
}
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
"aria-label": item.label,
|
|
284
|
-
className: itemSlot(),
|
|
285
|
-
key: item.value,
|
|
286
|
-
children: [
|
|
287
|
-
itemContent,
|
|
288
|
-
/*#__PURE__*/ jsx("span", {
|
|
289
|
-
...api.getItemIndicatorProps({
|
|
290
|
-
item
|
|
291
|
-
}),
|
|
292
|
-
className: itemIndicator(),
|
|
293
|
-
children: /*#__PURE__*/ jsx(Icon, {
|
|
294
|
-
icon: "token-icon-check",
|
|
295
|
-
size: "current"
|
|
296
|
-
})
|
|
297
|
-
})
|
|
298
|
-
]
|
|
518
|
+
service.send({
|
|
519
|
+
type: "SELECTED_ITEMS.SYNC"
|
|
299
520
|
});
|
|
521
|
+
}, [
|
|
522
|
+
fullCollection,
|
|
523
|
+
inputValue,
|
|
524
|
+
navigation,
|
|
525
|
+
selectionBehavior,
|
|
526
|
+
service
|
|
527
|
+
]);
|
|
528
|
+
const initialQuery = useRef(service.context.initial("inputValue"));
|
|
529
|
+
const reset = useRef(()=>void 0);
|
|
530
|
+
reset.current = ()=>{
|
|
531
|
+
const restoredValue = navigation ? [] : normalizeValue(value) ?? initialValue.current;
|
|
532
|
+
const restoredQuery = inputValue ?? ("replace" !== selectionBehavior || navigation || void 0 === value && void 0 !== defaultInputValue ? defaultInputValue ?? initialQuery.current : restoredValue.map((itemValue)=>allItems.find((item)=>item.value === itemValue)?.label ?? api.selectedItems.find((item)=>item.value === itemValue)?.label ?? itemValue).join(", "));
|
|
533
|
+
resetSelection.current = restoredValue;
|
|
534
|
+
nativeInputOwnsQuery.current = false;
|
|
535
|
+
nativeQueries.current.clear();
|
|
536
|
+
pendingQueries.current = [];
|
|
537
|
+
if (void 0 !== inputValue) setQuery(inputValue);
|
|
538
|
+
resetting.current = true;
|
|
539
|
+
try {
|
|
540
|
+
if (void 0 === value) service.context.set("value", restoredValue);
|
|
541
|
+
if (void 0 === inputValue) service.context.set("inputValue", restoredQuery);
|
|
542
|
+
} finally{
|
|
543
|
+
resetting.current = false;
|
|
544
|
+
}
|
|
545
|
+
api.setOpen(false);
|
|
546
|
+
api.clearHighlightValue();
|
|
547
|
+
setOptions(allItems);
|
|
548
|
+
if (inputRef.current) syncReactFormControl(inputRef.current, restoredQuery);
|
|
300
549
|
};
|
|
550
|
+
useEffect(()=>{
|
|
551
|
+
const input = inputRef.current;
|
|
552
|
+
return input ? subscribeOwnerFormReset(input, ()=>reset.current()) : void 0;
|
|
553
|
+
}, []);
|
|
554
|
+
useEffect(()=>{
|
|
555
|
+
inputRef.current?.setCustomValidity(!navigation && required && 0 === api.value.length ? "Select an option from the suggestions." : "");
|
|
556
|
+
}, [
|
|
557
|
+
navigation,
|
|
558
|
+
required,
|
|
559
|
+
api.value.length
|
|
560
|
+
]);
|
|
561
|
+
const selectedText = api.value.map((selectedValue)=>allItems.find((item)=>item.value === selectedValue)?.label ?? api.selectedItems.find((item)=>item.value === selectedValue)?.label ?? selectedValue).join(", ");
|
|
562
|
+
useEffect(()=>{
|
|
563
|
+
if (readOnly && !navigation) {
|
|
564
|
+
if (service.context.get("inputValue") !== selectedText) service.send({
|
|
565
|
+
type: "INPUT_VALUE.SET",
|
|
566
|
+
value: selectedText
|
|
567
|
+
});
|
|
568
|
+
if (void 0 !== inputValue && inputValue !== selectedText) onInputValueChange?.(selectedText);
|
|
569
|
+
if (inputRef.current) inputRef.current.value = selectedText;
|
|
570
|
+
}
|
|
571
|
+
}, [
|
|
572
|
+
readOnly,
|
|
573
|
+
navigation,
|
|
574
|
+
selectedText,
|
|
575
|
+
service,
|
|
576
|
+
inputValue,
|
|
577
|
+
onInputValueChange
|
|
578
|
+
]);
|
|
579
|
+
const { role: _contentRole, tabIndex: _contentTabIndex, "aria-labelledby": _contentLabel, ...contentProps } = api.getContentProps();
|
|
580
|
+
const styles = comboboxVariants({
|
|
581
|
+
size
|
|
582
|
+
});
|
|
583
|
+
const { root, label: labelStyles, control, input, trigger, positioner, content, list, footer: footerSlot, triggerIndicator } = styles;
|
|
584
|
+
const state = getResultsState({
|
|
585
|
+
loading,
|
|
586
|
+
error,
|
|
587
|
+
hasOptions: api.collection.size > 0,
|
|
588
|
+
inputValue: api.inputValue
|
|
589
|
+
});
|
|
590
|
+
const machineInputProps = api.getInputProps();
|
|
591
|
+
const mergedInputProps = mergeProps({
|
|
592
|
+
...machineInputProps,
|
|
593
|
+
onChange (event) {
|
|
594
|
+
if (readOnly || disabled) return;
|
|
595
|
+
const nextQuery = event.currentTarget.value;
|
|
596
|
+
nativeInputOwnsQuery.current = true;
|
|
597
|
+
nativeQueries.current.add(nextQuery);
|
|
598
|
+
if (void 0 !== inputValue) {
|
|
599
|
+
pendingQueries.current = queueComboboxQuery(pendingQueries.current, nextQuery, inputValue);
|
|
600
|
+
setQuery(nextQuery);
|
|
601
|
+
}
|
|
602
|
+
notifyInputValueChange(nextQuery);
|
|
603
|
+
machineInputProps.onChange?.(event);
|
|
604
|
+
},
|
|
605
|
+
onBlur (event) {
|
|
606
|
+
nativeInputOwnsQuery.current = false;
|
|
607
|
+
nativeQueries.current.clear();
|
|
608
|
+
pendingQueries.current = [];
|
|
609
|
+
machineInputProps.onBlur?.(event);
|
|
610
|
+
if (void 0 !== inputValue) {
|
|
611
|
+
setQuery(inputValue);
|
|
612
|
+
syncReactFormControl(event.currentTarget, inputValue);
|
|
613
|
+
}
|
|
614
|
+
}
|
|
615
|
+
}, inputProps);
|
|
301
616
|
return /*#__PURE__*/ jsxs("div", {
|
|
302
|
-
...api.getRootProps(),
|
|
303
|
-
className: root(
|
|
617
|
+
...mergeProps(api.getRootProps(), rootProps),
|
|
618
|
+
className: root({
|
|
619
|
+
className
|
|
620
|
+
}),
|
|
304
621
|
"data-mode": mode,
|
|
305
622
|
"data-status": state,
|
|
623
|
+
ref: setDisabledElement,
|
|
306
624
|
children: [
|
|
307
625
|
label && /*#__PURE__*/ jsx(Label, {
|
|
308
626
|
className: labelStyles(),
|
|
@@ -314,35 +632,58 @@ function Combobox({ id, name, label, size, placeholder = "Select option", disabl
|
|
|
314
632
|
/*#__PURE__*/ jsxs("div", {
|
|
315
633
|
className: control(),
|
|
316
634
|
...api.getControlProps(),
|
|
635
|
+
"data-focus-visible": focusVisible ? "" : void 0,
|
|
317
636
|
"data-validation": validateStatus,
|
|
637
|
+
onBlurCapture: ()=>setFocusVisible(false),
|
|
638
|
+
onFocusCapture: (event)=>setFocusVisible(event.target.matches(":focus-visible")),
|
|
639
|
+
onKeyDownCapture: ()=>setFocusVisible(true),
|
|
640
|
+
onPointerDownCapture: ()=>setFocusVisible(false),
|
|
318
641
|
children: [
|
|
319
642
|
/*#__PURE__*/ jsx(Input, {
|
|
320
|
-
|
|
321
|
-
...api.getInputProps(),
|
|
643
|
+
...mergedInputProps,
|
|
322
644
|
"aria-controls": api.open ? listId : void 0,
|
|
323
|
-
"aria-describedby": helpText ? helpTextId : void 0,
|
|
324
|
-
|
|
645
|
+
"aria-describedby": joinDescribedBy(ariaDescribedBy, inputProps["aria-describedby"], helpText ? helpTextId : void 0, multiple && api.value.length ? selectedTextId : void 0),
|
|
646
|
+
"aria-errormessage": "error" === validateStatus ? joinDescribedBy(inputProps["aria-errormessage"], helpText ? helpTextId : void 0) : inputProps["aria-errormessage"],
|
|
647
|
+
"aria-invalid": "error" === validateStatus || inputProps["aria-invalid"] || void 0,
|
|
648
|
+
"aria-label": ariaLabel ?? inputProps["aria-label"],
|
|
649
|
+
"aria-labelledby": ariaLabelledBy ?? inputProps["aria-labelledby"] ?? (label && !(ariaLabel ?? inputProps["aria-label"]) ? api.getInputProps()["aria-labelledby"] : void 0),
|
|
650
|
+
"aria-required": required || void 0,
|
|
651
|
+
className: input({
|
|
652
|
+
className: inputProps.className
|
|
653
|
+
}),
|
|
654
|
+
defaultValue: api.inputValue,
|
|
655
|
+
disabled: disabled,
|
|
656
|
+
name: void 0,
|
|
657
|
+
onKeyDown: (event)=>{
|
|
658
|
+
inputProps.onKeyDown?.(event);
|
|
659
|
+
if (event.defaultPrevented) return;
|
|
660
|
+
if (!navigation && multiple && !disabled && !readOnly && !api.open && !api.inputValue && "Backspace" === event.key && !event.nativeEvent.isComposing) {
|
|
661
|
+
const lastValue = api.value.at(-1);
|
|
662
|
+
if (lastValue) {
|
|
663
|
+
event.preventDefault();
|
|
664
|
+
api.clearValue(lastValue);
|
|
665
|
+
}
|
|
666
|
+
return;
|
|
667
|
+
}
|
|
668
|
+
api.getInputProps().onKeyDown?.(event);
|
|
669
|
+
},
|
|
325
670
|
placeholder: placeholder,
|
|
326
|
-
|
|
327
|
-
|
|
671
|
+
readOnly: readOnly,
|
|
672
|
+
ref: focusableRef,
|
|
673
|
+
required: navigation && required,
|
|
674
|
+
size: size,
|
|
675
|
+
value: void 0
|
|
328
676
|
}),
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
onClick: (event)=>{
|
|
338
|
-
if (navigation) {
|
|
339
|
-
if (disabled || readOnly) return;
|
|
340
|
-
api.setInputValue("");
|
|
341
|
-
api.focus();
|
|
342
|
-
} else api.getClearTriggerProps().onClick?.(event);
|
|
343
|
-
}
|
|
677
|
+
/*#__PURE__*/ jsx(ComboboxClearTrigger, {
|
|
678
|
+
api: api,
|
|
679
|
+
clearable: clearable,
|
|
680
|
+
clearIcon: clearIcon,
|
|
681
|
+
disabled: disabled,
|
|
682
|
+
navigation: navigation,
|
|
683
|
+
readOnly: readOnly,
|
|
684
|
+
size: size
|
|
344
685
|
}),
|
|
345
|
-
/*#__PURE__*/ jsx(Button, {
|
|
686
|
+
!readOnly && /*#__PURE__*/ jsx(Button, {
|
|
346
687
|
...api.getTriggerProps(),
|
|
347
688
|
"aria-controls": api.open ? listId : void 0,
|
|
348
689
|
"aria-haspopup": "listbox",
|
|
@@ -357,80 +698,52 @@ function Combobox({ id, name, label, size, placeholder = "Select option", disabl
|
|
|
357
698
|
})
|
|
358
699
|
]
|
|
359
700
|
}),
|
|
360
|
-
|
|
701
|
+
!navigation && name && (api.value.length ? api.value : [
|
|
702
|
+
""
|
|
703
|
+
]).map((selectedValue)=>/*#__PURE__*/ jsx("input", {
|
|
704
|
+
disabled: disabled,
|
|
705
|
+
form: inputProps.form,
|
|
706
|
+
name: name,
|
|
707
|
+
type: "hidden",
|
|
708
|
+
value: selectedValue
|
|
709
|
+
}, selectedValue)),
|
|
710
|
+
/*#__PURE__*/ jsx(OverlayPortal, {
|
|
361
711
|
disabled: !portalled,
|
|
362
712
|
children: /*#__PURE__*/ jsx("div", {
|
|
363
713
|
...api.getPositionerProps(),
|
|
364
714
|
className: positioner(),
|
|
365
715
|
children: /*#__PURE__*/ jsxs("div", {
|
|
366
|
-
...
|
|
367
|
-
"aria-labelledby": void 0,
|
|
716
|
+
...contentProps,
|
|
368
717
|
className: content(),
|
|
369
718
|
"data-status": state,
|
|
370
|
-
role: void 0,
|
|
371
|
-
tabIndex: void 0,
|
|
372
719
|
children: [
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
}) : error ? /*#__PURE__*/ jsxs("div", {
|
|
386
|
-
className: statusSlot(),
|
|
387
|
-
role: "alert",
|
|
388
|
-
children: [
|
|
389
|
-
/*#__PURE__*/ jsx("span", {
|
|
390
|
-
className: "min-w-0 flex-1",
|
|
391
|
-
children: error
|
|
392
|
-
}),
|
|
393
|
-
onRetry && /*#__PURE__*/ jsx(Button, {
|
|
394
|
-
disabled: disabled || readOnly,
|
|
395
|
-
onClick: onRetry,
|
|
396
|
-
size: "sm",
|
|
397
|
-
variant: "secondary",
|
|
398
|
-
children: retryLabel
|
|
399
|
-
})
|
|
400
|
-
]
|
|
401
|
-
}) : showEmptyState ? /*#__PURE__*/ jsx("div", {
|
|
402
|
-
className: emptyState(),
|
|
403
|
-
role: "status",
|
|
404
|
-
children: noResultsMessage.replace("{inputValue}", api.inputValue)
|
|
405
|
-
}) : null,
|
|
720
|
+
/*#__PURE__*/ jsx(ComboboxStatus, {
|
|
721
|
+
disabled: disabled,
|
|
722
|
+
error: error,
|
|
723
|
+
inputValue: api.inputValue,
|
|
724
|
+
loadingMessage: loadingMessage,
|
|
725
|
+
noResultsMessage: noResultsMessage,
|
|
726
|
+
onRetry: onRetry,
|
|
727
|
+
readOnly: readOnly,
|
|
728
|
+
retryLabel: retryLabel,
|
|
729
|
+
state: state,
|
|
730
|
+
styles: styles
|
|
731
|
+
}),
|
|
406
732
|
/*#__PURE__*/ jsx("div", {
|
|
407
733
|
...api.getListProps(),
|
|
408
734
|
"aria-busy": loading || void 0,
|
|
409
735
|
className: list(),
|
|
410
736
|
id: listId,
|
|
411
|
-
children: !resultsHidden && (
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
key: group.id,
|
|
422
|
-
children: [
|
|
423
|
-
group.label && /*#__PURE__*/ jsx("div", {
|
|
424
|
-
...api.getItemGroupLabelProps({
|
|
425
|
-
htmlFor: group.id
|
|
426
|
-
}),
|
|
427
|
-
className: groupLabel(),
|
|
428
|
-
children: group.label
|
|
429
|
-
}),
|
|
430
|
-
groupItems.map(renderOption)
|
|
431
|
-
]
|
|
432
|
-
});
|
|
433
|
-
}) : collection.items.map(renderOption))
|
|
737
|
+
children: !resultsHidden && /*#__PURE__*/ jsx(ComboboxOptions, {
|
|
738
|
+
api: api,
|
|
739
|
+
disabled: disabled,
|
|
740
|
+
groups: groups,
|
|
741
|
+
navigate: navigate,
|
|
742
|
+
navigation: navigation,
|
|
743
|
+
readOnly: readOnly,
|
|
744
|
+
renderItem: renderItem,
|
|
745
|
+
styles: styles
|
|
746
|
+
})
|
|
434
747
|
}),
|
|
435
748
|
footer && /*#__PURE__*/ jsx("div", {
|
|
436
749
|
className: footerSlot(),
|
|
@@ -441,6 +754,46 @@ function Combobox({ id, name, label, size, placeholder = "Select option", disabl
|
|
|
441
754
|
})
|
|
442
755
|
})
|
|
443
756
|
}),
|
|
757
|
+
multiple && !navigation && api.value.length > 0 && /*#__PURE__*/ jsxs("div", {
|
|
758
|
+
children: [
|
|
759
|
+
/*#__PURE__*/ jsxs(StatusText, {
|
|
760
|
+
className: "sr-only",
|
|
761
|
+
id: selectedTextId,
|
|
762
|
+
size: size,
|
|
763
|
+
children: [
|
|
764
|
+
"Selected: ",
|
|
765
|
+
selectedText
|
|
766
|
+
]
|
|
767
|
+
}),
|
|
768
|
+
/*#__PURE__*/ jsx("ul", {
|
|
769
|
+
"aria-label": "Selected values",
|
|
770
|
+
className: styles.selectedList(),
|
|
771
|
+
children: api.value.map((selectedValue)=>{
|
|
772
|
+
const selectedLabel = allItems.find((item)=>item.value === selectedValue)?.label ?? api.selectedItems.find((item)=>item.value === selectedValue)?.label ?? selectedValue;
|
|
773
|
+
return /*#__PURE__*/ jsxs("li", {
|
|
774
|
+
className: styles.selectedItem(),
|
|
775
|
+
children: [
|
|
776
|
+
/*#__PURE__*/ jsx("span", {
|
|
777
|
+
className: styles.selectedLabel(),
|
|
778
|
+
children: selectedLabel
|
|
779
|
+
}),
|
|
780
|
+
!readOnly && /*#__PURE__*/ jsx(ActionIcon, {
|
|
781
|
+
"aria-label": `Remove ${selectedLabel}`,
|
|
782
|
+
disabled: disabled,
|
|
783
|
+
icon: "token-icon-combobox-clear",
|
|
784
|
+
onClick: ()=>{
|
|
785
|
+
if (disabled || readOnly) return;
|
|
786
|
+
api.clearValue(selectedValue);
|
|
787
|
+
api.focus();
|
|
788
|
+
},
|
|
789
|
+
size: size ?? "md"
|
|
790
|
+
})
|
|
791
|
+
]
|
|
792
|
+
}, selectedValue);
|
|
793
|
+
})
|
|
794
|
+
})
|
|
795
|
+
]
|
|
796
|
+
}),
|
|
444
797
|
helpText && /*#__PURE__*/ jsx(StatusText, {
|
|
445
798
|
id: helpTextId,
|
|
446
799
|
showIcon: showHelpTextIcon,
|