@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,15 +1,39 @@
|
|
|
1
|
+
"use client";
|
|
1
2
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { connect, machine } from "@zag-js/radio-group";
|
|
2
4
|
import { normalizeProps, useMachine } from "@zag-js/react";
|
|
3
5
|
import { createContext, useContext, useId } from "react";
|
|
4
6
|
import { Label } from "../atoms/label.js";
|
|
5
7
|
import { StatusText } from "../atoms/status-text.js";
|
|
8
|
+
import { getControlledChoiceInputProps, handleChoiceArrowKey, isSilentChoiceReset, mergeChoiceInputProps, runSilentChoiceReset, trackChoiceFormControl, useChoiceFocusRecovery } from "../internal/choice-control.js";
|
|
6
9
|
import { joinDescribedBy, useDescribedBy, useRegisterDescription } from "../internal/described-by.js";
|
|
7
10
|
import { tv } from "../utils.js";
|
|
8
|
-
|
|
11
|
+
const radioChoiceMachine = {
|
|
12
|
+
...machine,
|
|
13
|
+
implementations: {
|
|
14
|
+
...machine.implementations,
|
|
15
|
+
effects: {
|
|
16
|
+
...machine.implementations?.effects,
|
|
17
|
+
trackFormControlState ({ scope, context, prop, action }) {
|
|
18
|
+
const root = scope.getById(scope.ids?.root ?? `radio-group:${scope.id}`);
|
|
19
|
+
return trackChoiceFormControl(root, ()=>{
|
|
20
|
+
if (void 0 === prop("value")) runSilentChoiceReset(context, ()=>context.set("value", context.initial("value")));
|
|
21
|
+
else action([
|
|
22
|
+
"syncInputElements"
|
|
23
|
+
]);
|
|
24
|
+
}, (disabled)=>context.set("fieldsetDisabled", disabled));
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
};
|
|
9
29
|
const radioGroupVariants = tv({
|
|
10
30
|
slots: {
|
|
11
31
|
root: [
|
|
12
|
-
"flex w-full flex-col"
|
|
32
|
+
"flex w-full flex-col",
|
|
33
|
+
"focus-visible:outline-(style:--default-ring-style)",
|
|
34
|
+
"focus-visible:outline-(length:--default-ring-width)",
|
|
35
|
+
"focus-visible:outline-radio-group-ring",
|
|
36
|
+
"focus-visible:outline-offset-(length:--default-ring-offset)"
|
|
13
37
|
],
|
|
14
38
|
itemGroup: [
|
|
15
39
|
"relative flex",
|
|
@@ -21,14 +45,15 @@ const radioGroupVariants = tv({
|
|
|
21
45
|
"grid grid-cols-(--radio-group-item-grid) items-start",
|
|
22
46
|
"cursor-pointer select-none",
|
|
23
47
|
"data-disabled:cursor-not-allowed",
|
|
24
|
-
"data-readonly:cursor-default"
|
|
48
|
+
"data-readonly:not-data-disabled:cursor-default data-readonly:select-text"
|
|
25
49
|
],
|
|
26
50
|
itemControl: [
|
|
27
|
-
"row-start-1 self-center",
|
|
51
|
+
"form-control-readonly form-control-disabled row-start-1 self-center",
|
|
28
52
|
"inline-grid shrink-0 place-items-center rounded-radio-group-control",
|
|
29
53
|
"border-(length:--border-width-radio-group)",
|
|
30
54
|
"border-radio-group-item-border-base",
|
|
31
55
|
"bg-radio-group-item-bg",
|
|
56
|
+
"data-readonly:not-data-disabled:data-[state=checked]:border-radio-group-border-choice-selected",
|
|
32
57
|
"transition-colors duration-200 motion-reduce:transition-none",
|
|
33
58
|
"data-hover:bg-radio-group-item-bg-hover",
|
|
34
59
|
"data-hover:border-radio-group-item-border-hover",
|
|
@@ -49,6 +74,7 @@ const radioGroupVariants = tv({
|
|
|
49
74
|
"token-icon-radio-group-checked",
|
|
50
75
|
"opacity-0 transition-opacity duration-200 motion-reduce:transition-none",
|
|
51
76
|
"data-[state=checked]:opacity-100",
|
|
77
|
+
"data-readonly:not-data-disabled:text-radio-group-fg-choice-selected",
|
|
52
78
|
"data-disabled:data-[state=checked]:text-radio-group-item-indicator-disabled"
|
|
53
79
|
],
|
|
54
80
|
itemText: [
|
|
@@ -66,29 +92,29 @@ const radioGroupVariants = tv({
|
|
|
66
92
|
outline: {
|
|
67
93
|
itemControl: [
|
|
68
94
|
"data-[state=checked]:bg-radio-group-item-bg-outline-checked",
|
|
69
|
-
"data-[state=checked]:border-radio-group-
|
|
95
|
+
"data-[state=checked]:border-radio-group-border-choice-selected",
|
|
70
96
|
"data-hover:data-[state=checked]:bg-radio-group-item-bg-outline-checked-hover",
|
|
71
|
-
"data-hover:data-[state=checked]:border-radio-group-
|
|
97
|
+
"data-hover:data-[state=checked]:border-radio-group-border-choice-selected"
|
|
72
98
|
],
|
|
73
|
-
itemIndicator: "text-radio-group-
|
|
99
|
+
itemIndicator: "text-radio-group-fg-choice-selected"
|
|
74
100
|
},
|
|
75
101
|
subtle: {
|
|
76
102
|
itemControl: [
|
|
77
103
|
"data-[state=checked]:bg-radio-group-item-bg-subtle-checked",
|
|
78
|
-
"data-[state=checked]:border-radio-group-
|
|
104
|
+
"data-[state=checked]:border-radio-group-border-choice-selected",
|
|
79
105
|
"data-hover:data-[state=checked]:bg-radio-group-item-bg-subtle-checked-hover",
|
|
80
|
-
"data-hover:data-[state=checked]:border-radio-group-
|
|
106
|
+
"data-hover:data-[state=checked]:border-radio-group-border-choice-selected"
|
|
81
107
|
],
|
|
82
|
-
itemIndicator: "text-radio-group-
|
|
108
|
+
itemIndicator: "text-radio-group-fg-choice-selected"
|
|
83
109
|
},
|
|
84
110
|
solid: {
|
|
85
111
|
itemControl: [
|
|
86
112
|
"data-[state=checked]:bg-radio-group-item-bg-solid-checked",
|
|
87
|
-
"data-[state=checked]:border-radio-group-
|
|
113
|
+
"data-[state=checked]:border-radio-group-border-solid-selected",
|
|
88
114
|
"data-hover:data-[state=checked]:bg-radio-group-item-bg-solid-checked-hover",
|
|
89
|
-
"data-hover:data-[state=checked]:border-radio-group-
|
|
115
|
+
"data-hover:data-[state=checked]:border-radio-group-border-solid-selected"
|
|
90
116
|
],
|
|
91
|
-
itemIndicator: "text-radio-group-
|
|
117
|
+
itemIndicator: "text-radio-group-fg-solid-selected"
|
|
92
118
|
}
|
|
93
119
|
},
|
|
94
120
|
size: {
|
|
@@ -129,6 +155,7 @@ const radioGroupVariants = tv({
|
|
|
129
155
|
size: "md"
|
|
130
156
|
}
|
|
131
157
|
});
|
|
158
|
+
const ignoreDescription = ()=>()=>void 0;
|
|
132
159
|
const RadioGroupContext = /*#__PURE__*/ createContext(null);
|
|
133
160
|
function useRadioGroupContext() {
|
|
134
161
|
const context = useContext(RadioGroupContext);
|
|
@@ -141,46 +168,63 @@ function useRadioGroupItemContext() {
|
|
|
141
168
|
if (!context) throw new Error("RadioGroup item components must be used within RadioGroup.Item");
|
|
142
169
|
return context;
|
|
143
170
|
}
|
|
144
|
-
function RadioGroup({ id: providedId, disabled = false, required = false, orientation = "vertical", validateStatus = "default", onValueChange, variant = "outline", size = "md", children, className, ref, ...machineProps }) {
|
|
171
|
+
function RadioGroup({ "aria-label": ariaLabel, "aria-labelledby": ariaLabelledBy, "aria-describedby": ariaDescribedByProp, id: providedId, disabled = false, readOnly = false, required = false, orientation = "vertical", validateStatus = "default", onValueChange, variant = "outline", size = "md", children, className, ref, ...machineProps }) {
|
|
145
172
|
const generatedId = useId();
|
|
146
173
|
const id = providedId || generatedId;
|
|
147
174
|
const invalid = "error" === validateStatus;
|
|
148
|
-
const service = useMachine(
|
|
175
|
+
const service = useMachine(radioChoiceMachine, {
|
|
149
176
|
...machineProps,
|
|
150
177
|
id,
|
|
151
178
|
disabled,
|
|
179
|
+
readOnly: readOnly && !disabled,
|
|
152
180
|
required,
|
|
153
181
|
orientation,
|
|
154
182
|
invalid,
|
|
155
183
|
onValueChange: ({ value: nextValue })=>{
|
|
156
|
-
onValueChange?.(nextValue);
|
|
184
|
+
if (!(readOnly || disabled || isSilentChoiceReset(service.context))) onValueChange?.(nextValue);
|
|
157
185
|
}
|
|
158
186
|
});
|
|
159
|
-
const api =
|
|
187
|
+
const api = connect(service, normalizeProps);
|
|
188
|
+
const focusRef = useChoiceFocusRecovery();
|
|
160
189
|
const styles = radioGroupVariants({
|
|
161
190
|
size,
|
|
162
191
|
variant
|
|
163
192
|
});
|
|
164
193
|
const describedBy = useDescribedBy();
|
|
194
|
+
const errors = useDescribedBy();
|
|
165
195
|
return /*#__PURE__*/ jsx(RadioGroupContext.Provider, {
|
|
166
196
|
value: {
|
|
167
197
|
api,
|
|
198
|
+
readOnly: readOnly && !disabled,
|
|
199
|
+
callerDescribedBy: ariaDescribedByProp,
|
|
200
|
+
errorMessageId: errors.describedById,
|
|
201
|
+
registerError: errors.registerDescription,
|
|
202
|
+
...describedBy,
|
|
168
203
|
variant,
|
|
169
204
|
size,
|
|
170
205
|
orientation,
|
|
171
206
|
disabled,
|
|
172
207
|
required,
|
|
173
208
|
validateStatus,
|
|
174
|
-
statusTextId: `${id}-status
|
|
175
|
-
...describedBy
|
|
209
|
+
statusTextId: `${id}-status`
|
|
176
210
|
},
|
|
177
211
|
children: /*#__PURE__*/ jsx("div", {
|
|
178
212
|
className: styles.root({
|
|
179
213
|
className
|
|
180
214
|
}),
|
|
181
|
-
ref:
|
|
215
|
+
ref: (node)=>{
|
|
216
|
+
focusRef.current = node;
|
|
217
|
+
if ("function" == typeof ref) return ref(node);
|
|
218
|
+
if (ref) ref.current = node;
|
|
219
|
+
},
|
|
182
220
|
...api.getRootProps(),
|
|
183
|
-
"aria-describedby": joinDescribedBy(describedBy.describedById),
|
|
221
|
+
"aria-describedby": joinDescribedBy(ariaDescribedByProp, describedBy.describedById),
|
|
222
|
+
"aria-errormessage": errors.describedById,
|
|
223
|
+
"aria-invalid": invalid || !!errors.describedById || void 0,
|
|
224
|
+
"aria-label": ariaLabel,
|
|
225
|
+
"aria-labelledby": ariaLabelledBy ?? (ariaLabel ? void 0 : api.getRootProps()["aria-labelledby"]),
|
|
226
|
+
role: "radiogroup",
|
|
227
|
+
tabIndex: -1,
|
|
184
228
|
children: children
|
|
185
229
|
})
|
|
186
230
|
});
|
|
@@ -223,9 +267,11 @@ RadioGroup.Item = function({ value, disabled, invalid, children, className, ref,
|
|
|
223
267
|
disabled,
|
|
224
268
|
invalid
|
|
225
269
|
};
|
|
270
|
+
const descriptions = useDescribedBy();
|
|
226
271
|
return /*#__PURE__*/ jsx(RadioGroupItemContext.Provider, {
|
|
227
272
|
value: {
|
|
228
|
-
itemProps
|
|
273
|
+
itemProps,
|
|
274
|
+
...descriptions
|
|
229
275
|
},
|
|
230
276
|
children: /*#__PURE__*/ jsx("label", {
|
|
231
277
|
className: styles.item({
|
|
@@ -239,19 +285,43 @@ RadioGroup.Item = function({ value, disabled, invalid, children, className, ref,
|
|
|
239
285
|
});
|
|
240
286
|
};
|
|
241
287
|
RadioGroup.ItemHiddenInput = function({ className, ref, ...props }) {
|
|
242
|
-
const { api, size, variant } = useRadioGroupContext();
|
|
243
|
-
const { itemProps } = useRadioGroupItemContext();
|
|
288
|
+
const { api, size, variant, readOnly, callerDescribedBy, describedById, errorMessageId, validateStatus } = useRadioGroupContext();
|
|
289
|
+
const { itemProps, describedById: itemDescriptionId } = useRadioGroupItemContext();
|
|
244
290
|
const styles = radioGroupVariants({
|
|
245
291
|
size,
|
|
246
292
|
variant
|
|
247
293
|
});
|
|
294
|
+
const inputProps = getControlledChoiceInputProps(mergeChoiceInputProps(props, api.getItemHiddenInputProps(itemProps)), api.getItemState(itemProps).checked);
|
|
248
295
|
return /*#__PURE__*/ jsx("input", {
|
|
249
296
|
className: styles.hiddenInput({
|
|
250
297
|
className
|
|
251
298
|
}),
|
|
252
299
|
ref: ref,
|
|
253
|
-
...
|
|
254
|
-
|
|
300
|
+
...inputProps,
|
|
301
|
+
"aria-describedby": joinDescribedBy(props["aria-describedby"], callerDescribedBy, describedById, itemDescriptionId),
|
|
302
|
+
"aria-errormessage": "error" === validateStatus || errorMessageId ? errorMessageId : void 0,
|
|
303
|
+
"aria-invalid": api.getItemState(itemProps).invalid || !!errorMessageId || void 0,
|
|
304
|
+
disabled: api.getItemState(itemProps).disabled,
|
|
305
|
+
onKeyDown: (event)=>{
|
|
306
|
+
inputProps.onKeyDown?.(event);
|
|
307
|
+
if (!readOnly) handleChoiceArrowKey(event);
|
|
308
|
+
},
|
|
309
|
+
onKeyDownCapture: (event)=>{
|
|
310
|
+
props.onKeyDownCapture?.(event);
|
|
311
|
+
if (readOnly && [
|
|
312
|
+
" ",
|
|
313
|
+
"ArrowLeft",
|
|
314
|
+
"ArrowRight",
|
|
315
|
+
"ArrowUp",
|
|
316
|
+
"ArrowDown",
|
|
317
|
+
"Home",
|
|
318
|
+
"End"
|
|
319
|
+
].includes(event.key)) {
|
|
320
|
+
event.preventDefault();
|
|
321
|
+
event.stopPropagation();
|
|
322
|
+
}
|
|
323
|
+
},
|
|
324
|
+
readOnly: readOnly
|
|
255
325
|
});
|
|
256
326
|
};
|
|
257
327
|
RadioGroup.ItemControl = function({ children, className, ref, ...props }) {
|
|
@@ -274,6 +344,7 @@ RadioGroup.ItemControl = function({ children, className, ref, ...props }) {
|
|
|
274
344
|
"aria-hidden": "true",
|
|
275
345
|
className: styles.itemIndicator(),
|
|
276
346
|
"data-disabled": itemState.disabled || void 0,
|
|
347
|
+
"data-readonly": api.getRootProps()["aria-readonly"] ? "" : void 0,
|
|
277
348
|
"data-state": itemState.checked ? "checked" : "unchecked"
|
|
278
349
|
}),
|
|
279
350
|
children
|
|
@@ -314,7 +385,10 @@ RadioGroup.ItemText = function({ children, className, ref, ...props }) {
|
|
|
314
385
|
};
|
|
315
386
|
RadioGroup.ItemDescription = function({ children, className, ref, ...props }) {
|
|
316
387
|
const { api, size, variant } = useRadioGroupContext();
|
|
317
|
-
const { itemProps } = useRadioGroupItemContext();
|
|
388
|
+
const { itemProps, registerDescription } = useRadioGroupItemContext();
|
|
389
|
+
const generatedId = useId();
|
|
390
|
+
const id = props.id ?? generatedId;
|
|
391
|
+
useRegisterDescription(id, registerDescription);
|
|
318
392
|
const styles = radioGroupVariants({
|
|
319
393
|
size,
|
|
320
394
|
variant
|
|
@@ -327,17 +401,20 @@ RadioGroup.ItemDescription = function({ children, className, ref, ...props }) {
|
|
|
327
401
|
"data-disabled": itemState.disabled || void 0,
|
|
328
402
|
ref: ref,
|
|
329
403
|
...props,
|
|
404
|
+
id: id,
|
|
330
405
|
children: children
|
|
331
406
|
});
|
|
332
407
|
};
|
|
333
408
|
RadioGroup.StatusText = function({ status, size: sizeProp, showIcon, children, ...props }) {
|
|
334
|
-
const { size, validateStatus,
|
|
409
|
+
const { size, validateStatus, registerDescription, registerError } = useRadioGroupContext();
|
|
410
|
+
const generatedId = useId();
|
|
411
|
+
const id = props.id ?? generatedId;
|
|
335
412
|
const effectiveSize = sizeProp ?? size;
|
|
336
413
|
const effectiveStatus = status ?? validateStatus;
|
|
337
|
-
const id = props.id ?? statusTextId;
|
|
338
414
|
useRegisterDescription(id, registerDescription);
|
|
415
|
+
useRegisterDescription(id, "error" === effectiveStatus ? registerError : ignoreDescription);
|
|
339
416
|
return /*#__PURE__*/ jsx(StatusText, {
|
|
340
|
-
showIcon:
|
|
417
|
+
showIcon: "default" !== effectiveStatus || showIcon,
|
|
341
418
|
size: effectiveSize,
|
|
342
419
|
status: effectiveStatus,
|
|
343
420
|
...props,
|
|
@@ -346,4 +423,4 @@ RadioGroup.StatusText = function({ status, size: sizeProp, showIcon, children, .
|
|
|
346
423
|
});
|
|
347
424
|
};
|
|
348
425
|
RadioGroup.displayName = "RadioGroup";
|
|
349
|
-
export { RadioGroup, radioGroupVariants, useRadioGroupContext };
|
|
426
|
+
export { RadioGroup, radioChoiceMachine, radioGroupVariants, useRadioGroupContext };
|
|
@@ -1,10 +1,15 @@
|
|
|
1
|
+
"use client";
|
|
1
2
|
import { jsx } from "react/jsx-runtime";
|
|
2
|
-
import { createContext, useContext, useEffect, useId, useState } from "react";
|
|
3
|
+
import { createContext, useContext, useEffect, useId, useMemo, useRef, useState } from "react";
|
|
3
4
|
import { createPortal } from "react-dom";
|
|
4
5
|
import { ActionIcon } from "../atoms/action-icon.js";
|
|
5
6
|
import { Button } from "../atoms/button.js";
|
|
6
7
|
import { Input } from "../atoms/input.js";
|
|
7
8
|
import { Label } from "../atoms/label.js";
|
|
9
|
+
import { StatusText } from "../atoms/status-text.js";
|
|
10
|
+
import { joinDescribedBy, useDescribedBy, useRegisterDescription } from "../internal/described-by.js";
|
|
11
|
+
import { subscribeOwnerFormReset } from "../internal/form-control-lifecycle.js";
|
|
12
|
+
import { useEffectiveDisabled } from "../internal/use-effective-disabled.js";
|
|
8
13
|
import { tv } from "../utils.js";
|
|
9
14
|
const searchFormVariants = tv({
|
|
10
15
|
slots: {
|
|
@@ -34,16 +39,19 @@ const searchFormVariants = tv({
|
|
|
34
39
|
sm: {
|
|
35
40
|
root: "gap-search-form-sm",
|
|
36
41
|
button: "h-form-control-sm",
|
|
42
|
+
input: "data-clearable:pe-(--height-form-control-sm)",
|
|
37
43
|
clearButton: "end-(length:--padding-input-sm)"
|
|
38
44
|
},
|
|
39
45
|
md: {
|
|
40
46
|
root: "gap-search-form-md",
|
|
41
47
|
button: "h-form-control-md",
|
|
48
|
+
input: "data-clearable:pe-(--height-form-control-md)",
|
|
42
49
|
clearButton: "end-(length:--padding-input-md)"
|
|
43
50
|
},
|
|
44
51
|
lg: {
|
|
45
52
|
root: "gap-search-form-lg",
|
|
46
53
|
button: "h-form-control-lg",
|
|
54
|
+
input: "data-clearable:pe-(--height-form-control-lg)",
|
|
47
55
|
clearButton: "end-(length:--padding-input-lg)"
|
|
48
56
|
}
|
|
49
57
|
},
|
|
@@ -68,20 +76,56 @@ function useSearchFormContext() {
|
|
|
68
76
|
if (!context) throw new Error("SearchForm components must be used within SearchForm");
|
|
69
77
|
return context;
|
|
70
78
|
}
|
|
71
|
-
function SearchForm({ size = "md", gapped = false, children, defaultValue = "", value, onValueChange, className, ref, onSubmit, ...props }) {
|
|
79
|
+
function SearchForm({ size = "md", gapped = false, readOnly = false, disabled: explicitDisabled = false, validateStatus = "default", children, defaultValue = "", value, onValueChange, className, ref, onSubmit, ...props }) {
|
|
72
80
|
const generatedId = useId();
|
|
73
81
|
const inputId = `search-input-${generatedId}`;
|
|
74
|
-
const [
|
|
82
|
+
const [formElement, setFormElement] = useState(null);
|
|
75
83
|
const [clearSlot, setClearSlot] = useState(null);
|
|
84
|
+
const disabled = useEffectiveDisabled(clearSlot ?? formElement, explicitDisabled);
|
|
85
|
+
const formRef = useMemo(()=>(node)=>{
|
|
86
|
+
setFormElement(node);
|
|
87
|
+
const cleanup = "function" == typeof ref ? ref(node) : void 0;
|
|
88
|
+
if (ref && "function" != typeof ref) ref.current = node;
|
|
89
|
+
return ()=>{
|
|
90
|
+
if ("function" == typeof cleanup) cleanup();
|
|
91
|
+
else if ("function" == typeof ref) ref(null);
|
|
92
|
+
else if (ref) ref.current = null;
|
|
93
|
+
};
|
|
94
|
+
}, [
|
|
95
|
+
ref
|
|
96
|
+
]);
|
|
97
|
+
const initialValue = useRef(defaultValue);
|
|
98
|
+
const [internalValue, setInternalValue] = useState(defaultValue);
|
|
76
99
|
const [hasClearButton, setHasClearButton] = useState(false);
|
|
100
|
+
const [inputReadOnly, setInputReadOnly] = useState(false);
|
|
101
|
+
const [inputDisabled, setInputDisabled] = useState(false);
|
|
102
|
+
const [hasLabel, setHasLabel] = useState(false);
|
|
103
|
+
const [hasButton, setHasButton] = useState(false);
|
|
104
|
+
const descriptions = useDescribedBy();
|
|
105
|
+
const errors = useDescribedBy();
|
|
106
|
+
const blocked = readOnly || disabled || inputReadOnly || inputDisabled;
|
|
77
107
|
const isControlled = void 0 !== value;
|
|
78
108
|
const inputValue = isControlled ? value : internalValue;
|
|
109
|
+
const reset = useRef(()=>void 0);
|
|
110
|
+
reset.current = ()=>{
|
|
111
|
+
if (!isControlled) setInternalValue(initialValue.current);
|
|
112
|
+
const input = clearSlot?.querySelector("input");
|
|
113
|
+
if (input) input.value = value ?? initialValue.current;
|
|
114
|
+
};
|
|
115
|
+
useEffect(()=>{
|
|
116
|
+
const input = clearSlot?.querySelector("input");
|
|
117
|
+
return input ? subscribeOwnerFormReset(input, ()=>reset.current()) : void 0;
|
|
118
|
+
}, [
|
|
119
|
+
clearSlot
|
|
120
|
+
]);
|
|
79
121
|
const setInputValue = (newValue)=>{
|
|
122
|
+
if (blocked) return;
|
|
80
123
|
if (!isControlled) setInternalValue(newValue);
|
|
81
124
|
onValueChange?.(newValue);
|
|
82
125
|
};
|
|
83
126
|
const clearInput = ()=>{
|
|
84
127
|
setInputValue("");
|
|
128
|
+
clearSlot?.querySelector("input")?.focus();
|
|
85
129
|
};
|
|
86
130
|
const handleSubmit = (e)=>{
|
|
87
131
|
e.preventDefault();
|
|
@@ -95,6 +139,17 @@ function SearchForm({ size = "md", gapped = false, children, defaultValue = "",
|
|
|
95
139
|
value: {
|
|
96
140
|
size,
|
|
97
141
|
gapped,
|
|
142
|
+
readOnly: readOnly || inputReadOnly,
|
|
143
|
+
disabled: disabled || inputDisabled,
|
|
144
|
+
setInputReadOnly,
|
|
145
|
+
setInputDisabled,
|
|
146
|
+
validateStatus,
|
|
147
|
+
descriptions,
|
|
148
|
+
errors,
|
|
149
|
+
hasLabel,
|
|
150
|
+
setHasLabel,
|
|
151
|
+
hasButton,
|
|
152
|
+
setHasButton,
|
|
98
153
|
inputId,
|
|
99
154
|
inputValue,
|
|
100
155
|
setInputValue,
|
|
@@ -111,7 +166,7 @@ function SearchForm({ size = "md", gapped = false, children, defaultValue = "",
|
|
|
111
166
|
className
|
|
112
167
|
}),
|
|
113
168
|
onSubmit: handleSubmit,
|
|
114
|
-
ref:
|
|
169
|
+
ref: formRef,
|
|
115
170
|
...props,
|
|
116
171
|
children: children
|
|
117
172
|
})
|
|
@@ -119,7 +174,13 @@ function SearchForm({ size = "md", gapped = false, children, defaultValue = "",
|
|
|
119
174
|
});
|
|
120
175
|
}
|
|
121
176
|
SearchForm.Label = function({ children, className, ...props }) {
|
|
122
|
-
const { inputId, size } = useSearchFormContext();
|
|
177
|
+
const { inputId, size, setHasLabel } = useSearchFormContext();
|
|
178
|
+
useEffect(()=>{
|
|
179
|
+
setHasLabel(true);
|
|
180
|
+
return ()=>setHasLabel(false);
|
|
181
|
+
}, [
|
|
182
|
+
setHasLabel
|
|
183
|
+
]);
|
|
123
184
|
return /*#__PURE__*/ jsx(Label, {
|
|
124
185
|
className: className,
|
|
125
186
|
htmlFor: inputId,
|
|
@@ -144,19 +205,34 @@ SearchForm.Control = function({ children, className, ref, ...props }) {
|
|
|
144
205
|
});
|
|
145
206
|
};
|
|
146
207
|
SearchForm.Input = function({ className, placeholder = "Search...", ref, ...props }) {
|
|
147
|
-
const { inputId, inputValue, setInputValue, size, gapped, hasValue, hasClearButton, setClearSlot } = useSearchFormContext();
|
|
208
|
+
const { inputId, inputValue, setInputValue, size, gapped, hasValue, hasClearButton, setClearSlot, readOnly, disabled, setInputReadOnly, setInputDisabled, hasLabel, hasButton, descriptions, errors, validateStatus } = useSearchFormContext();
|
|
209
|
+
useEffect(()=>{
|
|
210
|
+
setInputReadOnly(Boolean(props.readOnly));
|
|
211
|
+
return ()=>setInputReadOnly(false);
|
|
212
|
+
}, [
|
|
213
|
+
props.readOnly,
|
|
214
|
+
setInputReadOnly
|
|
215
|
+
]);
|
|
216
|
+
useEffect(()=>{
|
|
217
|
+
setInputDisabled(Boolean(props.disabled));
|
|
218
|
+
return ()=>setInputDisabled(false);
|
|
219
|
+
}, [
|
|
220
|
+
props.disabled,
|
|
221
|
+
setInputDisabled
|
|
222
|
+
]);
|
|
148
223
|
const styles = searchFormVariants({
|
|
149
224
|
size,
|
|
150
|
-
gapped
|
|
225
|
+
gapped: gapped || !hasButton
|
|
151
226
|
});
|
|
152
227
|
return /*#__PURE__*/ jsx("div", {
|
|
153
228
|
className: styles.inputWrapper(),
|
|
154
229
|
ref: setClearSlot,
|
|
155
230
|
children: /*#__PURE__*/ jsx(Input, {
|
|
156
|
-
"aria-label": props["aria-label"]
|
|
231
|
+
"aria-label": props["aria-label"] ?? (hasLabel ? void 0 : "Search"),
|
|
157
232
|
className: styles.input({
|
|
158
233
|
className
|
|
159
234
|
}),
|
|
235
|
+
"data-clearable": hasValue && hasClearButton && !readOnly && !disabled ? "" : void 0,
|
|
160
236
|
id: inputId,
|
|
161
237
|
onChange: (e)=>setInputValue(e.target.value),
|
|
162
238
|
placeholder: placeholder,
|
|
@@ -164,13 +240,25 @@ SearchForm.Input = function({ className, placeholder = "Search...", ref, ...prop
|
|
|
164
240
|
size: size,
|
|
165
241
|
type: "search",
|
|
166
242
|
value: inputValue,
|
|
167
|
-
|
|
168
|
-
|
|
243
|
+
...props,
|
|
244
|
+
"aria-describedby": joinDescribedBy(props["aria-describedby"], descriptions.describedById),
|
|
245
|
+
"aria-errormessage": "error" === validateStatus ? errors.describedById : void 0,
|
|
246
|
+
"aria-invalid": "error" === validateStatus || props["aria-invalid"] || void 0,
|
|
247
|
+
"data-readonly": readOnly ? "" : void 0,
|
|
248
|
+
disabled: disabled || props.disabled,
|
|
249
|
+
readOnly: readOnly || props.readOnly,
|
|
250
|
+
variant: "default" === validateStatus ? props.variant : validateStatus
|
|
169
251
|
})
|
|
170
252
|
});
|
|
171
253
|
};
|
|
172
254
|
SearchForm.Button = function({ className, children, showSearchIcon = false, icon, iconPosition = "right", ...props }) {
|
|
173
|
-
const { size, gapped } = useSearchFormContext();
|
|
255
|
+
const { size, gapped, disabled, setHasButton } = useSearchFormContext();
|
|
256
|
+
useEffect(()=>{
|
|
257
|
+
setHasButton(true);
|
|
258
|
+
return ()=>setHasButton(false);
|
|
259
|
+
}, [
|
|
260
|
+
setHasButton
|
|
261
|
+
]);
|
|
174
262
|
const styles = searchFormVariants({
|
|
175
263
|
size,
|
|
176
264
|
gapped
|
|
@@ -186,11 +274,12 @@ SearchForm.Button = function({ className, children, showSearchIcon = false, icon
|
|
|
186
274
|
size: size,
|
|
187
275
|
type: "submit",
|
|
188
276
|
...props,
|
|
277
|
+
disabled: disabled || props.disabled,
|
|
189
278
|
children: children
|
|
190
279
|
});
|
|
191
280
|
};
|
|
192
281
|
SearchForm.ClearButton = function({ className, icon = "token-icon-close", tone = "neutral", ...props }) {
|
|
193
|
-
const { size, gapped, clearInput, hasValue, inputValue, clearSlot, setHasClearButton } = useSearchFormContext();
|
|
282
|
+
const { size, gapped, clearInput, hasValue, inputValue, clearSlot, setHasClearButton, readOnly, disabled } = useSearchFormContext();
|
|
194
283
|
const styles = searchFormVariants({
|
|
195
284
|
size,
|
|
196
285
|
gapped
|
|
@@ -201,7 +290,7 @@ SearchForm.ClearButton = function({ className, icon = "token-icon-close", tone =
|
|
|
201
290
|
}, [
|
|
202
291
|
setHasClearButton
|
|
203
292
|
]);
|
|
204
|
-
if (!(hasValue && clearSlot)) return null;
|
|
293
|
+
if (readOnly || disabled || !(hasValue && clearSlot)) return null;
|
|
205
294
|
return /*#__PURE__*/ createPortal(/*#__PURE__*/ jsx(ActionIcon, {
|
|
206
295
|
"aria-label": `Clear search: ${inputValue}`,
|
|
207
296
|
className: styles.clearButton({
|
|
@@ -214,5 +303,19 @@ SearchForm.ClearButton = function({ className, icon = "token-icon-close", tone =
|
|
|
214
303
|
...props
|
|
215
304
|
}), clearSlot);
|
|
216
305
|
};
|
|
306
|
+
SearchForm.StatusText = function({ status: statusProp, size: sizeProp, ...props }) {
|
|
307
|
+
const { size, descriptions, errors, validateStatus } = useSearchFormContext();
|
|
308
|
+
const generatedId = useId();
|
|
309
|
+
const id = props.id ?? `${generatedId}-status`;
|
|
310
|
+
const status = statusProp ?? validateStatus;
|
|
311
|
+
useRegisterDescription(id, descriptions.registerDescription);
|
|
312
|
+
useRegisterDescription(id, errors.registerDescription, "error" === status);
|
|
313
|
+
return /*#__PURE__*/ jsx(StatusText, {
|
|
314
|
+
...props,
|
|
315
|
+
id: id,
|
|
316
|
+
size: sizeProp ?? size,
|
|
317
|
+
status: status
|
|
318
|
+
});
|
|
319
|
+
};
|
|
217
320
|
SearchForm.displayName = "SearchForm";
|
|
218
321
|
export { SearchForm, searchFormVariants, useSearchFormContext };
|