@yamada-ui/react 2.3.4-dev-20261116074825 → 2.3.4-dev-20261116083009
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/components/checkbox/use-checkbox-group.cjs +6 -15
- package/dist/cjs/components/checkbox/use-checkbox-group.cjs.map +1 -1
- package/dist/cjs/components/checkbox/use-checkbox.cjs +7 -16
- package/dist/cjs/components/checkbox/use-checkbox.cjs.map +1 -1
- package/dist/cjs/components/radio/use-radio-group.cjs +2 -7
- package/dist/cjs/components/radio/use-radio-group.cjs.map +1 -1
- package/dist/cjs/components/radio/use-radio.cjs +5 -12
- package/dist/cjs/components/radio/use-radio.cjs.map +1 -1
- package/dist/esm/components/checkbox/use-checkbox-group.js +6 -15
- package/dist/esm/components/checkbox/use-checkbox-group.js.map +1 -1
- package/dist/esm/components/checkbox/use-checkbox.js +7 -16
- package/dist/esm/components/checkbox/use-checkbox.js.map +1 -1
- package/dist/esm/components/radio/use-radio-group.js +2 -7
- package/dist/esm/components/radio/use-radio-group.js.map +1 -1
- package/dist/esm/components/radio/use-radio.js +5 -12
- package/dist/esm/components/radio/use-radio.js.map +1 -1
- package/dist/types/components/alert/alert.style.d.ts +1 -1
- package/dist/types/components/autocomplete/autocomplete.style.d.ts +1 -1
- package/dist/types/components/avatar/avatar.d.ts +3 -3
- package/dist/types/components/avatar/avatar.style.d.ts +1 -1
- package/dist/types/components/calendar/calendar.style.d.ts +2 -2
- package/dist/types/components/carousel/carousel.style.d.ts +2 -2
- package/dist/types/components/chart/cartesian-chart.style.d.ts +1 -1
- package/dist/types/components/chart/polar-chart.style.d.ts +1 -1
- package/dist/types/components/checkbox-card/checkbox-card.d.ts +3 -3
- package/dist/types/components/checkbox-card/checkbox-card.style.d.ts +1 -1
- package/dist/types/components/color-picker/color-picker.style.d.ts +1 -1
- package/dist/types/components/color-selector/color-selector.style.d.ts +2 -2
- package/dist/types/components/data-list/data-list.style.d.ts +1 -1
- package/dist/types/components/date-picker/date-picker.style.d.ts +1 -1
- package/dist/types/components/drawer/drawer.style.d.ts +2 -2
- package/dist/types/components/dropzone/dropzone.d.ts +1 -1
- package/dist/types/components/dropzone/dropzone.style.d.ts +1 -1
- package/dist/types/components/empty-state/empty-state.style.d.ts +2 -2
- package/dist/types/components/file-input/file-input.style.d.ts +1 -1
- package/dist/types/components/form/form.style.d.ts +1 -1
- package/dist/types/components/modal/modal.style.d.ts +2 -2
- package/dist/types/components/native-select/native-select.style.d.ts +1 -1
- package/dist/types/components/notice/notice.style.d.ts +1 -1
- package/dist/types/components/number-input/number-input.style.d.ts +1 -1
- package/dist/types/components/password-input/password-input.style.d.ts +1 -1
- package/dist/types/components/pin-input/pin-input.style.d.ts +1 -1
- package/dist/types/components/radio-card/radio-card.d.ts +3 -3
- package/dist/types/components/radio-card/radio-card.style.d.ts +1 -1
- package/dist/types/components/select/select.style.d.ts +1 -1
- package/dist/types/components/steps/steps.style.d.ts +1 -1
- package/dist/types/components/tag/tag.style.d.ts +1 -1
- package/dist/types/components/timeline/timeline.d.ts +1 -1
- package/dist/types/components/timeline/timeline.style.d.ts +1 -1
- package/dist/types/providers/i18n-provider/i18n-provider.d.ts +1 -1
- package/package.json +1 -1
|
@@ -45,12 +45,10 @@ const useCheckboxGroup = (props = {}) => {
|
|
|
45
45
|
return {
|
|
46
46
|
max,
|
|
47
47
|
value,
|
|
48
|
-
getInputProps: (0, react.useCallback)((props = {}) => {
|
|
48
|
+
getInputProps: (0, react.useCallback)(({ disabled, ...props } = {}) => {
|
|
49
49
|
const checked = !(0, require_utils_index.utils_exports.isUndefined)(value) && ((0, require_utils_index.utils_exports.isString)(props.value) || (0, require_utils_index.utils_exports.isNumber)(props.value)) && value.includes(props.value);
|
|
50
50
|
const trulyDisabled = !checked && (0, require_utils_index.utils_exports.isNumber)(max) && value.length >= max;
|
|
51
|
-
return {
|
|
52
|
-
...dataProps,
|
|
53
|
-
...ariaProps,
|
|
51
|
+
return require_props.mergeProps(dataProps, ariaProps, {
|
|
54
52
|
type: "checkbox",
|
|
55
53
|
style: require_dom.visuallyHiddenAttributes.style,
|
|
56
54
|
"aria-checked": checked,
|
|
@@ -58,14 +56,10 @@ const useCheckboxGroup = (props = {}) => {
|
|
|
58
56
|
"data-checked": (0, require_utils_index.utils_exports.dataAttr)(checked),
|
|
59
57
|
"data-disabled": (0, require_utils_index.utils_exports.dataAttr)(trulyDisabled),
|
|
60
58
|
checked,
|
|
59
|
+
disabled: Boolean(disabled || trulyDisabled),
|
|
61
60
|
readOnly,
|
|
62
|
-
required
|
|
63
|
-
|
|
64
|
-
disabled: Boolean(props.disabled || trulyDisabled),
|
|
65
|
-
onBlur: (0, require_utils_index.utils_exports.handlerAll)(props.onBlur, eventProps.onBlur),
|
|
66
|
-
onChange: (0, require_utils_index.utils_exports.handlerAll)(props.onChange, onChange),
|
|
67
|
-
onFocus: (0, require_utils_index.utils_exports.handlerAll)(props.onFocus, eventProps.onFocus)
|
|
68
|
-
};
|
|
61
|
+
required
|
|
62
|
+
}, props, eventProps, { onChange })();
|
|
69
63
|
}, [
|
|
70
64
|
ariaProps,
|
|
71
65
|
dataProps,
|
|
@@ -76,10 +70,7 @@ const useCheckboxGroup = (props = {}) => {
|
|
|
76
70
|
required,
|
|
77
71
|
value
|
|
78
72
|
]),
|
|
79
|
-
getLabelProps: (0, react.useCallback)((props) => (
|
|
80
|
-
...dataProps,
|
|
81
|
-
...props
|
|
82
|
-
}), [dataProps]),
|
|
73
|
+
getLabelProps: (0, react.useCallback)((props = {}) => require_props.mergeProps(dataProps, props)(), [dataProps]),
|
|
83
74
|
getRootProps,
|
|
84
75
|
onChange
|
|
85
76
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-checkbox-group.cjs","names":["createContext","useFieldProps","useControllableState","useCallback","mergeProps","visuallyHiddenAttributes"],"sources":["../../../../src/components/checkbox/use-checkbox-group.ts"],"sourcesContent":["\"use client\"\n\nimport type { ChangeEvent } from \"react\"\nimport type { HTMLProps, PropGetter } from \"../../core\"\nimport type { FieldProps } from \"../field\"\nimport { useCallback } from \"react\"\nimport { mergeProps } from \"../../core\"\nimport { useControllableState } from \"../../hooks/use-controllable-state\"\nimport {\n ariaAttr,\n createContext,\n dataAttr,\n
|
|
1
|
+
{"version":3,"file":"use-checkbox-group.cjs","names":["createContext","useFieldProps","useControllableState","useCallback","mergeProps","visuallyHiddenAttributes"],"sources":["../../../../src/components/checkbox/use-checkbox-group.ts"],"sourcesContent":["\"use client\"\n\nimport type { ChangeEvent } from \"react\"\nimport type { HTMLProps, PropGetter } from \"../../core\"\nimport type { FieldProps } from \"../field\"\nimport { useCallback } from \"react\"\nimport { mergeProps } from \"../../core\"\nimport { useControllableState } from \"../../hooks/use-controllable-state\"\nimport {\n ariaAttr,\n createContext,\n dataAttr,\n isNumber,\n isObject,\n isString,\n isUndefined,\n visuallyHiddenAttributes,\n} from \"../../utils\"\nimport { useFieldProps } from \"../field\"\n\ninterface CheckboxGroupContext extends Omit<\n UseCheckboxGroupReturn,\n \"getRootProps\"\n> {}\n\nconst [CheckboxGroupContext, useCheckboxGroupContext] =\n createContext<CheckboxGroupContext>({\n name: \"CheckboxGroupContext\",\n strict: false,\n })\n\nexport { CheckboxGroupContext, useCheckboxGroupContext }\n\nexport interface UseCheckboxGroupProps<Y extends string = string>\n extends Omit<HTMLProps, \"defaultValue\" | \"onChange\" | \"value\">, FieldProps {\n /**\n * The initial value of the checkbox group.\n *\n * @default []\n */\n defaultValue?: Y[]\n /**\n * The maximum number of checkboxes that can be checked.\n */\n max?: number\n /**\n * The value of the checkbox group.\n */\n value?: Y[]\n /**\n * The callback fired when any children checkbox is checked or unchecked.\n */\n onChange?: (value: Y[]) => void\n}\n\nexport const useCheckboxGroup = <Y extends string = string>(\n props: UseCheckboxGroupProps<Y> = {},\n) => {\n const {\n context: { labelId } = {},\n props: {\n defaultValue = [],\n disabled,\n max,\n readOnly,\n required,\n value: valueProp,\n onChange: onChangeProp,\n ...rest\n },\n ariaProps: { \"aria-describedby\": ariaDescribedby, ...ariaProps },\n dataProps,\n eventProps,\n } = useFieldProps(props)\n const interactive = !(readOnly || disabled)\n const [value, setValue] = useControllableState({\n defaultValue,\n value: valueProp,\n onChange: onChangeProp,\n })\n\n const onChange = useCallback(\n (valueOrEv: ChangeEvent<HTMLInputElement> | Y) => {\n if (!interactive) return\n\n if (isObject(valueOrEv)) valueOrEv = valueOrEv.target.value as Y\n\n setValue((prev) => {\n if (prev.includes(valueOrEv))\n return prev.filter((prevValue) => prevValue !== valueOrEv)\n else if (!isNumber(max) || prev.length < max)\n return [...prev, valueOrEv]\n else return prev\n })\n },\n [interactive, max, setValue],\n )\n\n const getRootProps: PropGetter = useCallback(\n (props = {}) =>\n mergeProps(\n dataProps,\n {\n \"aria-describedby\": ariaDescribedby,\n \"aria-labelledby\": labelId,\n role: \"group\",\n },\n rest,\n props,\n )(),\n [ariaDescribedby, dataProps, labelId, rest],\n )\n\n const getInputProps: PropGetter<\"input\"> = useCallback(\n ({ disabled, ...props } = {}) => {\n const checked =\n !isUndefined(value) &&\n (isString(props.value) || isNumber(props.value)) &&\n value.includes(props.value as Y)\n const trulyDisabled = !checked && isNumber(max) && value.length >= max\n\n return mergeProps(\n dataProps,\n ariaProps,\n {\n type: \"checkbox\",\n style: visuallyHiddenAttributes.style,\n \"aria-checked\": checked,\n \"aria-disabled\": ariaAttr(trulyDisabled),\n \"data-checked\": dataAttr(checked),\n \"data-disabled\": dataAttr(trulyDisabled),\n checked,\n disabled: Boolean(disabled || trulyDisabled),\n readOnly,\n required,\n },\n props,\n eventProps,\n { onChange },\n )()\n },\n [\n ariaProps,\n dataProps,\n eventProps,\n max,\n onChange,\n readOnly,\n required,\n value,\n ],\n )\n\n const getLabelProps: PropGetter<\"label\"> = useCallback(\n (props = {}) => mergeProps(dataProps, props)(),\n [dataProps],\n )\n\n return {\n max,\n value,\n getInputProps,\n getLabelProps,\n getRootProps,\n onChange,\n }\n}\n\nexport type Use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AM,UACJ,EAAA,GAAA,oBAAA,cAAC,YAAA,CAAY,KAAK,OAAA,GAAA,oBAAA,cACjB,SAAA,CAAS,MAAM,KAAK,MAAA,GAAA,oBAAA,cAAK,SAAA,CAAS,MAAM,KAAK,MAC9C,MAAM,SAAS,MAAM,KAAU;GACjC,MAAM,gBAAgB,CAAC,YAAA,GAAA,oBAAA,cAAW,SAAA,CAAS,GAAG,KAAK,MAAM,UAAU;GAEnE,OAAOC,cAAAA,WACL,WACA,WACA;IACE,MAAM;IACN,OAAOC,YAAAA,yBAAyB;IAChC,gBAAgB;IAChB,kBAAA,GAAA,oBAAA,cAAiB,SAAA,CAAS,aAAa;IACvC,iBAAA,GAAA,oBAAA,cAAgB,SAAA,CAAS,OAAO;IAChC,kBAAA,GAAA,oBAAA,cAAiB,SAAA,CAAS,aAAa;IACvC;IACA,UAAU,QAAQ,YAAY,aAAa;IAC3C;IACA;GACF,GACA,OACA,YACA,EAAE,SAAS,CACb,CAAC,CAAC;EACJ,GACA;GACE;GACA;GACA;GACA;GACA;GACA;GACA;GACA;EACF,CAWY;EACZ,gBAAA,GATyCF,MAAAA,YAAAA,EACxC,QAAQ,CAAC,MAAMC,cAAAA,WAAW,WAAW,KAAK,CAAC,CAAC,GAC7C,CAAC,SAAS,CAOE;EACZ;EACA;CACF;AACF"}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
const require_dom = require("../../utils/dom.cjs");
|
|
3
|
-
const require_ref = require("../../utils/ref.cjs");
|
|
4
3
|
const require_props = require("../../core/components/props.cjs");
|
|
5
4
|
const require_hooks_use_controllable_state_index = require("../../hooks/use-controllable-state/index.cjs");
|
|
6
5
|
const require_utils_index = require("../../utils/index.cjs");
|
|
@@ -39,8 +38,7 @@ const useCheckbox = ({ "aria-describedby": ariaDescribedbyProp, ...props } = {})
|
|
|
39
38
|
setChecked
|
|
40
39
|
]);
|
|
41
40
|
const getRootProps = (0, react.useCallback)((props = {}) => {
|
|
42
|
-
const merged = require_props.mergeProps({
|
|
43
|
-
...dataProps,
|
|
41
|
+
const merged = require_props.mergeProps(dataProps, {
|
|
44
42
|
"data-checked": (0, require_utils_index.utils_exports.dataAttr)(checked),
|
|
45
43
|
"data-indeterminate": (0, require_utils_index.utils_exports.dataAttr)(indeterminate)
|
|
46
44
|
}, rest, props)();
|
|
@@ -53,11 +51,9 @@ const useCheckbox = ({ "aria-describedby": ariaDescribedbyProp, ...props } = {})
|
|
|
53
51
|
getLabelProps
|
|
54
52
|
]);
|
|
55
53
|
const getInputProps = (0, react.useCallback)((props = {}) => {
|
|
56
|
-
const sharedProps = require_props.mergeProps({
|
|
57
|
-
...dataProps,
|
|
58
|
-
...ariaProps,
|
|
54
|
+
const sharedProps = require_props.mergeProps({ ref }, dataProps, ariaProps, {
|
|
59
55
|
id,
|
|
60
|
-
ref:
|
|
56
|
+
ref: indeterminateRef,
|
|
61
57
|
type: "checkbox",
|
|
62
58
|
name,
|
|
63
59
|
style: require_dom.visuallyHiddenAttributes.style,
|
|
@@ -74,10 +70,7 @@ const useCheckbox = ({ "aria-describedby": ariaDescribedbyProp, ...props } = {})
|
|
|
74
70
|
required,
|
|
75
71
|
tabIndex,
|
|
76
72
|
value
|
|
77
|
-
}, props, {
|
|
78
|
-
...eventProps,
|
|
79
|
-
onChange
|
|
80
|
-
})();
|
|
73
|
+
}, props, eventProps, { onChange })();
|
|
81
74
|
return getGroupInputProps?.(sharedProps) ?? sharedProps;
|
|
82
75
|
}, [
|
|
83
76
|
dataProps,
|
|
@@ -104,13 +97,11 @@ const useCheckbox = ({ "aria-describedby": ariaDescribedbyProp, ...props } = {})
|
|
|
104
97
|
return {
|
|
105
98
|
checked,
|
|
106
99
|
indeterminate,
|
|
107
|
-
getIndicatorProps: (0, react.useCallback)((props = {}) => ({
|
|
108
|
-
...dataProps,
|
|
100
|
+
getIndicatorProps: (0, react.useCallback)((props = {}) => require_props.mergeProps(dataProps, {
|
|
109
101
|
"aria-hidden": "true",
|
|
110
102
|
"data-checked": (0, require_utils_index.utils_exports.dataAttr)(checked),
|
|
111
|
-
"data-indeterminate": (0, require_utils_index.utils_exports.dataAttr)(indeterminate)
|
|
112
|
-
|
|
113
|
-
}), [
|
|
103
|
+
"data-indeterminate": (0, require_utils_index.utils_exports.dataAttr)(indeterminate)
|
|
104
|
+
}, props)(), [
|
|
114
105
|
dataProps,
|
|
115
106
|
checked,
|
|
116
107
|
indeterminate
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-checkbox.cjs","names":["useCheckboxGroupContext","useId","useFieldProps","useControllableEventState","useCallback","mergeProps","
|
|
1
|
+
{"version":3,"file":"use-checkbox.cjs","names":["useCheckboxGroupContext","useId","useFieldProps","useControllableEventState","useCallback","mergeProps","visuallyHiddenAttributes"],"sources":["../../../../src/components/checkbox/use-checkbox.ts"],"sourcesContent":["\"use client\"\n\nimport type { ChangeEvent, ChangeEventHandler, FocusEventHandler } from \"react\"\nimport type { HTMLProps, HTMLRefAttributes, PropGetter } from \"../../core\"\nimport type { FieldProps } from \"../field\"\nimport { useCallback, useId } from \"react\"\nimport { mergeProps } from \"../../core\"\nimport { useControllableEventState } from \"../../hooks/use-controllable-state\"\nimport {\n ariaAttr,\n dataAttr,\n isNumber,\n isUndefined,\n visuallyHiddenAttributes,\n} from \"../../utils\"\nimport { useFieldProps } from \"../field\"\nimport { useCheckboxGroupContext } from \"./use-checkbox-group\"\n\nexport interface UseCheckboxProps<Y extends string = string>\n extends\n Omit<HTMLProps<\"label\">, \"onBlur\" | \"onChange\" | \"onFocus\" | \"ref\">,\n HTMLRefAttributes<\"input\">,\n FieldProps {\n /**\n * If `true`, the checkbox will be checked.\n */\n checked?: boolean\n /**\n * If `true`, the checkbox will be initially checked.\n *\n * @default false\n */\n defaultChecked?: boolean\n /**\n * id assigned to input.\n */\n id?: string\n /**\n * If `true`, the checkbox will be indeterminate.\n *\n * @default false\n */\n indeterminate?: boolean\n /**\n * The name of the input field in a checkbox.\n */\n name?: string\n /**\n * The value of the checkbox.\n */\n value?: Y\n /**\n * The callback invoked when the checkbox is blurred.\n */\n onBlur?: FocusEventHandler<HTMLInputElement>\n /**\n * The callback invoked when the checked state changes.\n */\n onChange?: ChangeEventHandler<HTMLInputElement>\n /**\n * The callback invoked when the checkbox is focused.\n */\n onFocus?: FocusEventHandler<HTMLInputElement>\n}\n\nexport const useCheckbox = <Y extends string = string>({\n \"aria-describedby\": ariaDescribedbyProp,\n ...props\n}: UseCheckboxProps<Y> = {}) => {\n const group = useCheckboxGroupContext()\n const {\n max,\n value: groupValue,\n getInputProps: getGroupInputProps,\n getLabelProps,\n } = group ?? {}\n const uuid = useId()\n const {\n props: {\n id,\n ref,\n name,\n \"aria-controls\": ariaControls,\n \"aria-labelledby\": ariaLabelledby,\n checked: checkedProp,\n defaultChecked = false,\n disabled,\n indeterminate = false,\n readOnly,\n required,\n tabIndex,\n value,\n onChange: onChangeProp,\n ...rest\n },\n ariaProps: { \"aria-describedby\": ariaDescribedby, ...ariaProps },\n dataProps,\n eventProps,\n } = useFieldProps({\n id: group ? uuid : undefined,\n ...props,\n notSupportReadOnly: true,\n })\n const resolvedAriaDescribedby = group ? ariaDescribedbyProp : ariaDescribedby\n const resolvedChecked =\n !isUndefined(groupValue) && !isUndefined(value)\n ? groupValue.includes(value)\n : checkedProp\n const [checked, setChecked] = useControllableEventState({\n defaultValue: defaultChecked,\n value: resolvedChecked,\n onChange: onChangeProp,\n })\n const trulyDisabled =\n !checked && isNumber(max) && group && group.value.length >= max\n const interactive = !(readOnly || trulyDisabled)\n const indeterminateRef = useCallback(\n (el: HTMLInputElement | null) => {\n if (el) el.indeterminate = indeterminate\n },\n [indeterminate],\n )\n\n const onChange = useCallback(\n (ev: ChangeEvent<HTMLInputElement>) => {\n if (!interactive) return (ev.defaultPrevented = true)\n\n if (indeterminate) ev.target.checked = true\n\n setChecked(ev)\n },\n [interactive, indeterminate, setChecked],\n )\n\n const getRootProps: PropGetter<\"label\"> = useCallback(\n (props = {}) => {\n const merged = mergeProps(\n dataProps,\n {\n \"data-checked\": dataAttr(checked),\n \"data-indeterminate\": dataAttr(indeterminate),\n },\n rest,\n props,\n )()\n\n return getLabelProps?.(merged) ?? merged\n },\n [dataProps, checked, indeterminate, rest, getLabelProps],\n )\n\n const getInputProps: PropGetter<\"input\"> = useCallback(\n (props = {}) => {\n const sharedProps = mergeProps(\n { ref },\n dataProps,\n ariaProps,\n {\n id,\n ref: indeterminateRef,\n type: \"checkbox\",\n name,\n style: visuallyHiddenAttributes.style,\n \"aria-checked\": indeterminate ? (\"mixed\" as const) : checked,\n \"aria-controls\": ariaControls,\n \"aria-describedby\": resolvedAriaDescribedby,\n \"aria-disabled\": ariaAttr(!interactive),\n \"aria-labelledby\": ariaLabelledby,\n \"data-checked\": dataAttr(checked),\n \"data-indeterminate\": dataAttr(indeterminate),\n checked,\n disabled,\n readOnly,\n required,\n tabIndex,\n value,\n },\n props,\n eventProps,\n { onChange },\n )()\n\n return getGroupInputProps?.(sharedProps) ?? sharedProps\n },\n [\n dataProps,\n ariaProps,\n id,\n name,\n indeterminate,\n checked,\n ariaControls,\n resolvedAriaDescribedby,\n interactive,\n ariaLabelledby,\n disabled,\n readOnly,\n required,\n tabIndex,\n value,\n ref,\n indeterminateRef,\n eventProps,\n onChange,\n getGroupInputProps,\n ],\n )\n\n const getIndicatorProps: PropGetter = useCallback(\n (props = {}) =>\n mergeProps(\n dataProps,\n {\n \"aria-hidden\": \"true\",\n \"data-checked\": dataAttr(checked),\n \"data-indeterminate\": dataAttr(indeterminate),\n },\n props,\n )(),\n [dataProps, checked, indeterminate],\n )\n\n return {\n checked,\n indeterminate,\n getIndicatorProps,\n getInputProps,\n getRootProps,\n onChange,\n }\n}\n\nexport type UseCheckboxReturn = ReturnType<typeof useCheckbox>\n"],"mappings":";;;;;;;;;AAiEA,MAAa,eAA0C,EACrD,oBAAoB,qBACpB,GAAG,UACoB,CAAC,MAAM;CAC9B,MAAM,QAAQA,2BAAAA,wBAAwB;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AA,oBAAA,cAAgB,SAAA,CAAS,OAAO;GAChC,uBAAA,GAAA,oBAAA,cAAsB,SAAA,CAAS,aAAa;EAC9C,GACA,MACA,KACF,CAAC,CAAC;EAEF,OAAO,gBAAgB,MAAM,KAAK;CACpC,GACA;EAAC;EAAW;EAAS;EAAe;EAAM;CAAa,CACzD;CAEA,MAAM,iBAAA,GAAqCD,MAAAA,YAAAA,EACxC,QAAQ,CAAC,MAAM;EACd,MAAM,cAAcC,cAAAA,WAClB,EAAE,IAAI,GACN,WACA,WACA;GACE;GACA,KAAK;GACL,MAAM;GACN;GACA,OAAOC,YAAAA,yBAAyB;GAChC,gBAAgB,gBAAiB,UAAoB;GACrD,iBAAiB;GACjB,oBAAoB;GACpB,kBAAA,GAAA,oBAAA,cAAiB,SAAA,CAAS,CAAC,WAAW;GACtC,mBAAmB;GACnB,iBAAA,GAAA,oBAAA,cAAgB,SAAA,CAAS,OAAO;GAChC,uBAAA,GAAA,oBAAA,cAAsB,SAAA,CAAS,aAAa;GAC5C;GACA;GACA;GACA;GACA;GACA;EACF,GACA,OACA,YACA,EAAE,SAAS,CACb,CAAC,CAAC;EAEF,OAAO,qBAAqB,WAAW,KAAK;CAC9C,GACA;EACE;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;CACF,CACF;CAgBA,OAAO;EACL;EACA;EACA,oBAAA,GAjBoCF,MAAAA,YAAAA,EACnC,QAAQ,CAAC,MACRC,cAAAA,WACE,WACA;GACE,eAAe;GACf,iBAAA,GAAA,oBAAA,cAAgB,SAAA,CAAS,OAAO;GAChC,uBAAA,GAAA,oBAAA,cAAsB,SAAA,CAAS,aAAa;EAC9C,GACA,KACF,CAAC,CAAC,GACJ;GAAC;GAAW;GAAS;EAAa,CAMlB;EAChB;EACA;EACA;CACF;AACF"}
|
|
@@ -45,9 +45,7 @@ const useRadioGroup = (props = {}) => {
|
|
|
45
45
|
value,
|
|
46
46
|
getInputProps: (0, react.useCallback)((props = {}) => {
|
|
47
47
|
const checked = !(0, require_utils_index.utils_exports.isUndefined)(value) && value === props.value;
|
|
48
|
-
return require_props.mergeProps({
|
|
49
|
-
...dataProps,
|
|
50
|
-
...ariaProps,
|
|
48
|
+
return require_props.mergeProps(dataProps, ariaProps, {
|
|
51
49
|
type: "radio",
|
|
52
50
|
name: id,
|
|
53
51
|
style: require_dom.visuallyHiddenAttributes.style,
|
|
@@ -57,10 +55,7 @@ const useRadioGroup = (props = {}) => {
|
|
|
57
55
|
disabled,
|
|
58
56
|
readOnly,
|
|
59
57
|
required
|
|
60
|
-
}, props, {
|
|
61
|
-
onChange,
|
|
62
|
-
...eventProps
|
|
63
|
-
})();
|
|
58
|
+
}, props, eventProps, { onChange })();
|
|
64
59
|
}, [
|
|
65
60
|
ariaProps,
|
|
66
61
|
dataProps,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-radio-group.cjs","names":["createContext","useId","useFieldProps","useControllableState","useCallback","mergeProps","visuallyHiddenAttributes"],"sources":["../../../../src/components/radio/use-radio-group.ts"],"sourcesContent":["\"use client\"\n\nimport type { ChangeEvent } from \"react\"\nimport type { HTMLProps, PropGetter } from \"../../core\"\nimport type { FieldProps } from \"../field\"\nimport { useCallback, useId } from \"react\"\nimport { mergeProps } from \"../../core\"\nimport { useControllableState } from \"../../hooks/use-controllable-state\"\nimport {\n createContext,\n dataAttr,\n isObject,\n isUndefined,\n visuallyHiddenAttributes,\n} from \"../../utils\"\nimport { useFieldProps } from \"../field\"\n\ninterface RadioGroupContext extends Omit<UseRadioGroupReturn, \"getRootProps\"> {}\n\nconst [RadioGroupContext, useRadioGroupContext] =\n createContext<RadioGroupContext>({\n name: \"RadioGroupContext\",\n strict: false,\n })\n\nexport { RadioGroupContext, useRadioGroupContext }\n\nexport interface UseRadioGroupProps<Y extends string = string>\n extends Omit<HTMLProps, \"defaultValue\" | \"onChange\" | \"value\">, FieldProps {\n /**\n * The initial value of the radio group.\n */\n defaultValue?: Y\n /**\n * The value of the radio group.\n */\n value?: Y\n /**\n * The callback fired when any children radio is checked or unchecked.\n */\n onChange?: (value: Y) => void\n}\n\nexport const useRadioGroup = <Y extends string = string>(\n props: UseRadioGroupProps<Y> = {},\n) => {\n const uuid = useId()\n const {\n context: { labelId } = {},\n props: {\n id = uuid,\n defaultValue,\n disabled,\n readOnly,\n required,\n value: valueProp,\n onChange: onChangeProp,\n ...rest\n },\n ariaProps: { \"aria-describedby\": ariaDescribedby, ...ariaProps },\n dataProps,\n eventProps,\n } = useFieldProps({\n ...props,\n notSupportReadOnly: true,\n })\n const interactive = !(readOnly || disabled)\n const [value, setValue] = useControllableState({\n defaultValue,\n value: valueProp,\n onChange: onChangeProp,\n })\n\n const onChange = useCallback(\n (valueOrEv: ChangeEvent<HTMLInputElement> | Y) => {\n if (!interactive) return\n\n if (isObject(valueOrEv)) setValue(valueOrEv.target.value as Y)\n else setValue(valueOrEv)\n },\n [interactive, setValue],\n )\n\n const getRootProps: PropGetter = useCallback(\n (props = {}) =>\n mergeProps(\n dataProps,\n {\n id,\n \"aria-describedby\": ariaDescribedby,\n \"aria-labelledby\": labelId,\n role: \"radiogroup\",\n },\n rest,\n props,\n )(),\n [ariaDescribedby, dataProps, id, labelId, rest],\n )\n\n const getInputProps: PropGetter<\"input\"> = useCallback(\n (props = {}) => {\n const checked = !isUndefined(value) && value === props.value\n\n return mergeProps(\n
|
|
1
|
+
{"version":3,"file":"use-radio-group.cjs","names":["createContext","useId","useFieldProps","useControllableState","useCallback","mergeProps","visuallyHiddenAttributes"],"sources":["../../../../src/components/radio/use-radio-group.ts"],"sourcesContent":["\"use client\"\n\nimport type { ChangeEvent } from \"react\"\nimport type { HTMLProps, PropGetter } from \"../../core\"\nimport type { FieldProps } from \"../field\"\nimport { useCallback, useId } from \"react\"\nimport { mergeProps } from \"../../core\"\nimport { useControllableState } from \"../../hooks/use-controllable-state\"\nimport {\n createContext,\n dataAttr,\n isObject,\n isUndefined,\n visuallyHiddenAttributes,\n} from \"../../utils\"\nimport { useFieldProps } from \"../field\"\n\ninterface RadioGroupContext extends Omit<UseRadioGroupReturn, \"getRootProps\"> {}\n\nconst [RadioGroupContext, useRadioGroupContext] =\n createContext<RadioGroupContext>({\n name: \"RadioGroupContext\",\n strict: false,\n })\n\nexport { RadioGroupContext, useRadioGroupContext }\n\nexport interface UseRadioGroupProps<Y extends string = string>\n extends Omit<HTMLProps, \"defaultValue\" | \"onChange\" | \"value\">, FieldProps {\n /**\n * The initial value of the radio group.\n */\n defaultValue?: Y\n /**\n * The value of the radio group.\n */\n value?: Y\n /**\n * The callback fired when any children radio is checked or unchecked.\n */\n onChange?: (value: Y) => void\n}\n\nexport const useRadioGroup = <Y extends string = string>(\n props: UseRadioGroupProps<Y> = {},\n) => {\n const uuid = useId()\n const {\n context: { labelId } = {},\n props: {\n id = uuid,\n defaultValue,\n disabled,\n readOnly,\n required,\n value: valueProp,\n onChange: onChangeProp,\n ...rest\n },\n ariaProps: { \"aria-describedby\": ariaDescribedby, ...ariaProps },\n dataProps,\n eventProps,\n } = useFieldProps({\n ...props,\n notSupportReadOnly: true,\n })\n const interactive = !(readOnly || disabled)\n const [value, setValue] = useControllableState({\n defaultValue,\n value: valueProp,\n onChange: onChangeProp,\n })\n\n const onChange = useCallback(\n (valueOrEv: ChangeEvent<HTMLInputElement> | Y) => {\n if (!interactive) return\n\n if (isObject(valueOrEv)) setValue(valueOrEv.target.value as Y)\n else setValue(valueOrEv)\n },\n [interactive, setValue],\n )\n\n const getRootProps: PropGetter = useCallback(\n (props = {}) =>\n mergeProps(\n dataProps,\n {\n id,\n \"aria-describedby\": ariaDescribedby,\n \"aria-labelledby\": labelId,\n role: \"radiogroup\",\n },\n rest,\n props,\n )(),\n [ariaDescribedby, dataProps, id, labelId, rest],\n )\n\n const getInputProps: PropGetter<\"input\"> = useCallback(\n (props = {}) => {\n const checked = !isUndefined(value) && value === props.value\n\n return mergeProps(\n dataProps,\n ariaProps,\n {\n type: \"radio\",\n name: id,\n style: visuallyHiddenAttributes.style,\n \"aria-checked\": checked,\n \"data-checked\": dataAttr(checked),\n checked,\n disabled,\n readOnly,\n required,\n },\n props,\n eventProps,\n { onChange },\n )()\n },\n [\n ariaProps,\n dataProps,\n disabled,\n eventProps,\n id,\n onChange,\n readOnly,\n required,\n value,\n ],\n )\n\n const getLabelProps: PropGetter<\"label\"> = useCallback(\n (props) => ({\n ...dataProps,\n ...props,\n }),\n [dataProps],\n )\n\n return {\n name: id,\n value,\n getInputProps,\n getLabelProps,\n getRootProps,\n onChange,\n }\n}\n\nexport type UseRadioGroupReturn = ReturnType<typeof useRadioGroup>\n"],"mappings":";;;;;;;;;AAmBA,MAAM,CAAC,mBAAmB,wBACxBA,gBAAAA,cAAiC;CAC/B,MAAM;CACN,QAAQ;AACV,CAAC;AAoBH,MAAa,iBACX,QAA+B,CAAC,MAC7B;CACH,MAAM,QAAA,GAAOC,MAAAA,MAAAA,CAAM;CACnB,MAAM,EACJ,SAAS,EAAE,YAAY,CAAC,GACxB,OAAO,EACL,KAAK,MACL,cACA,UACA,UACA,UACA,OAAO,WACP,UAAU,cACV,GAAG,QAEL,WAAW,EAAE,oBAAoB,iBAAiB,GAAG,aACrD,WACA,eACEC,wBAAAA,cAAc;EAChB,GAAG;EACH,oBAAoB;CACtB,CAAC;CACD,MAAM,cAAc,EAAE,YAAY;CAClC,MAAM,CAAC,OAAO,YAAYC,2CAAAA,qBAAqB;EAC7C;EACA,OAAO;EACP,UAAU;CACZ,CAAC;CAED,MAAM,YAAA,GAAWC,MAAAA,YAAAA,EACd,cAAiD;EAChD,IAAI,CAAC,aAAa;EAElB,KAAA,GAAA,oBAAA,cAAI,SAAA,CAAS,SAAS,GAAG,SAAS,UAAU,OAAO,KAAU;OACxD,SAAS,SAAS;CACzB,GACA,CAAC,aAAa,QAAQ,CACxB;CAEA,MAAM,gBAAA,GAA2BA,MAAAA,YAAAA,EAC9B,QAAQ,CAAC,MACRC,cAAAA,WACE,WACA;EACE;EACA,oBAAoB;EACpB,mBAAmB;EACnB,MAAM;CACR,GACA,MACA,KACF,CAAC,CAAC,GACJ;EAAC;EAAiB;EAAW;EAAI;EAAS;CAAI,CAChD;CA8CA,OAAO;EACL,MAAM;EACN;EACA,gBAAA,GA/CyCD,MAAAA,YAAAA,EACxC,QAAQ,CAAC,MAAM;GACd,MAAM,UAAU,EAAA,GAAA,oBAAA,cAAC,YAAA,CAAY,KAAK,KAAK,UAAU,MAAM;GAEvD,OAAOC,cAAAA,WACL,WACA,WACA;IACE,MAAM;IACN,MAAM;IACN,OAAOC,YAAAA,yBAAyB;IAChC,gBAAgB;IAChB,iBAAA,GAAA,oBAAA,cAAgB,SAAA,CAAS,OAAO;IAChC;IACA;IACA;IACA;GACF,GACA,OACA,YACA,EAAE,SAAS,CACb,CAAC,CAAC;EACJ,GACA;GACE;GACA;GACA;GACA;GACA;GACA;GACA;GACA;GACA;EACF,CAcY;EACZ,gBAAA,GAZyCF,MAAAA,YAAAA,EACxC,WAAW;GACV,GAAG;GACH,GAAG;EACL,IACA,CAAC,SAAS,CAOE;EACZ;EACA;CACF;AACF"}
|
|
@@ -38,9 +38,7 @@ const useRadio = ({ "aria-describedby": ariaDescribedbyProp, ...props } = {}) =>
|
|
|
38
38
|
rest
|
|
39
39
|
]);
|
|
40
40
|
const getInputProps = (0, react.useCallback)((props = {}) => {
|
|
41
|
-
const sharedProps = require_props.mergeProps({
|
|
42
|
-
...dataProps,
|
|
43
|
-
...ariaProps,
|
|
41
|
+
const sharedProps = require_props.mergeProps(dataProps, ariaProps, {
|
|
44
42
|
id,
|
|
45
43
|
ref,
|
|
46
44
|
type: "radio",
|
|
@@ -57,10 +55,7 @@ const useRadio = ({ "aria-describedby": ariaDescribedbyProp, ...props } = {}) =>
|
|
|
57
55
|
required,
|
|
58
56
|
tabIndex,
|
|
59
57
|
value
|
|
60
|
-
}, props, {
|
|
61
|
-
...eventProps,
|
|
62
|
-
onChange
|
|
63
|
-
})();
|
|
58
|
+
}, props, eventProps, { onChange })();
|
|
64
59
|
return getGroupInputProps?.(sharedProps) ?? sharedProps;
|
|
65
60
|
}, [
|
|
66
61
|
dataProps,
|
|
@@ -83,12 +78,10 @@ const useRadio = ({ "aria-describedby": ariaDescribedbyProp, ...props } = {}) =>
|
|
|
83
78
|
]);
|
|
84
79
|
return {
|
|
85
80
|
checked,
|
|
86
|
-
getIndicatorProps: (0, react.useCallback)((props = {}) => ({
|
|
87
|
-
...dataProps,
|
|
81
|
+
getIndicatorProps: (0, react.useCallback)((props = {}) => require_props.mergeProps(dataProps, {
|
|
88
82
|
"aria-hidden": "true",
|
|
89
|
-
"data-checked": (0, require_utils_index.utils_exports.dataAttr)(checked)
|
|
90
|
-
|
|
91
|
-
}), [dataProps, checked]),
|
|
83
|
+
"data-checked": (0, require_utils_index.utils_exports.dataAttr)(checked)
|
|
84
|
+
}, props)(), [dataProps, checked]),
|
|
92
85
|
getInputProps,
|
|
93
86
|
getRootProps,
|
|
94
87
|
onChange
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-radio.cjs","names":["useRadioGroupContext","useId","useFieldProps","useControllableEventState","useCallback","mergeProps","visuallyHiddenAttributes"],"sources":["../../../../src/components/radio/use-radio.ts"],"sourcesContent":["\"use client\"\n\nimport type { ChangeEvent, ChangeEventHandler, FocusEventHandler } from \"react\"\nimport type { HTMLProps, HTMLRefAttributes, PropGetter } from \"../../core\"\nimport type { FieldProps } from \"../field\"\nimport { useCallback, useId } from \"react\"\nimport { mergeProps } from \"../../core\"\nimport { useControllableEventState } from \"../../hooks/use-controllable-state\"\nimport { dataAttr, isUndefined, visuallyHiddenAttributes } from \"../../utils\"\nimport { useFieldProps } from \"../field\"\nimport { useRadioGroupContext } from \"./use-radio-group\"\n\nexport interface UseRadioProps<Y extends string = string>\n extends\n Omit<HTMLProps<\"label\">, \"onBlur\" | \"onChange\" | \"onFocus\" | \"ref\">,\n HTMLRefAttributes<\"input\">,\n FieldProps {\n /**\n * If `true`, the radio will be checked.\n */\n checked?: boolean\n /**\n * If `true`, the radio will be initially checked.\n *\n * @default false\n */\n defaultChecked?: boolean\n /**\n * id assigned to input.\n */\n id?: string\n /**\n * The name of the input field in a radio.\n */\n name?: string\n /**\n * The value of the radio.\n */\n value?: Y\n /**\n * The callback invoked when the radio is blurred.\n */\n onBlur?: FocusEventHandler<HTMLInputElement>\n /**\n * The callback invoked when the checked state changes.\n */\n onChange?: ChangeEventHandler<HTMLInputElement>\n /**\n * The callback invoked when the radio is focused.\n */\n onFocus?: FocusEventHandler<HTMLInputElement>\n}\n\nexport const useRadio = <Y extends string = string>({\n \"aria-describedby\": ariaDescribedbyProp,\n ...props\n}: UseRadioProps<Y> = {}) => {\n const group = useRadioGroupContext()\n const {\n name: groupName,\n value: groupValue,\n getInputProps: getGroupInputProps,\n getLabelProps,\n } = group ?? {}\n const uuid = useId()\n const {\n props: {\n id,\n ref,\n name = groupName,\n \"aria-controls\": ariaControls,\n \"aria-labelledby\": ariaLabelledby,\n checked: checkedProp,\n defaultChecked = false,\n disabled,\n readOnly,\n required,\n tabIndex,\n value,\n onChange: onChangeProp,\n ...rest\n },\n ariaProps: { \"aria-describedby\": ariaDescribedby, ...ariaProps },\n dataProps,\n eventProps,\n } = useFieldProps({\n id: group ? uuid : undefined,\n ...props,\n notSupportReadOnly: true,\n })\n const interactive = !(readOnly || disabled)\n const resolvedAriaDescribedby = group ? ariaDescribedbyProp : ariaDescribedby\n const resolvedChecked =\n !isUndefined(groupValue) && !isUndefined(value)\n ? groupValue === value\n : checkedProp\n const [checked, setChecked] = useControllableEventState({\n defaultValue: defaultChecked,\n value: resolvedChecked,\n onChange: onChangeProp,\n })\n\n const onChange = useCallback(\n (ev: ChangeEvent<HTMLInputElement>) => {\n if (!interactive) return (ev.defaultPrevented = true)\n\n setChecked(ev)\n },\n [setChecked, interactive],\n )\n\n const getRootProps: PropGetter<\"label\"> = useCallback(\n (props = {}) => {\n const sharedProps = mergeProps(\n dataProps,\n { \"data-checked\": dataAttr(checked) },\n rest,\n props,\n )()\n\n return getLabelProps?.(sharedProps) ?? sharedProps\n },\n [dataProps, getLabelProps, checked, rest],\n )\n\n const getInputProps: PropGetter<\"input\"> = useCallback(\n (props = {}) => {\n const sharedProps = mergeProps(\n
|
|
1
|
+
{"version":3,"file":"use-radio.cjs","names":["useRadioGroupContext","useId","useFieldProps","useControllableEventState","useCallback","mergeProps","visuallyHiddenAttributes"],"sources":["../../../../src/components/radio/use-radio.ts"],"sourcesContent":["\"use client\"\n\nimport type { ChangeEvent, ChangeEventHandler, FocusEventHandler } from \"react\"\nimport type { HTMLProps, HTMLRefAttributes, PropGetter } from \"../../core\"\nimport type { FieldProps } from \"../field\"\nimport { useCallback, useId } from \"react\"\nimport { mergeProps } from \"../../core\"\nimport { useControllableEventState } from \"../../hooks/use-controllable-state\"\nimport { dataAttr, isUndefined, visuallyHiddenAttributes } from \"../../utils\"\nimport { useFieldProps } from \"../field\"\nimport { useRadioGroupContext } from \"./use-radio-group\"\n\nexport interface UseRadioProps<Y extends string = string>\n extends\n Omit<HTMLProps<\"label\">, \"onBlur\" | \"onChange\" | \"onFocus\" | \"ref\">,\n HTMLRefAttributes<\"input\">,\n FieldProps {\n /**\n * If `true`, the radio will be checked.\n */\n checked?: boolean\n /**\n * If `true`, the radio will be initially checked.\n *\n * @default false\n */\n defaultChecked?: boolean\n /**\n * id assigned to input.\n */\n id?: string\n /**\n * The name of the input field in a radio.\n */\n name?: string\n /**\n * The value of the radio.\n */\n value?: Y\n /**\n * The callback invoked when the radio is blurred.\n */\n onBlur?: FocusEventHandler<HTMLInputElement>\n /**\n * The callback invoked when the checked state changes.\n */\n onChange?: ChangeEventHandler<HTMLInputElement>\n /**\n * The callback invoked when the radio is focused.\n */\n onFocus?: FocusEventHandler<HTMLInputElement>\n}\n\nexport const useRadio = <Y extends string = string>({\n \"aria-describedby\": ariaDescribedbyProp,\n ...props\n}: UseRadioProps<Y> = {}) => {\n const group = useRadioGroupContext()\n const {\n name: groupName,\n value: groupValue,\n getInputProps: getGroupInputProps,\n getLabelProps,\n } = group ?? {}\n const uuid = useId()\n const {\n props: {\n id,\n ref,\n name = groupName,\n \"aria-controls\": ariaControls,\n \"aria-labelledby\": ariaLabelledby,\n checked: checkedProp,\n defaultChecked = false,\n disabled,\n readOnly,\n required,\n tabIndex,\n value,\n onChange: onChangeProp,\n ...rest\n },\n ariaProps: { \"aria-describedby\": ariaDescribedby, ...ariaProps },\n dataProps,\n eventProps,\n } = useFieldProps({\n id: group ? uuid : undefined,\n ...props,\n notSupportReadOnly: true,\n })\n const interactive = !(readOnly || disabled)\n const resolvedAriaDescribedby = group ? ariaDescribedbyProp : ariaDescribedby\n const resolvedChecked =\n !isUndefined(groupValue) && !isUndefined(value)\n ? groupValue === value\n : checkedProp\n const [checked, setChecked] = useControllableEventState({\n defaultValue: defaultChecked,\n value: resolvedChecked,\n onChange: onChangeProp,\n })\n\n const onChange = useCallback(\n (ev: ChangeEvent<HTMLInputElement>) => {\n if (!interactive) return (ev.defaultPrevented = true)\n\n setChecked(ev)\n },\n [setChecked, interactive],\n )\n\n const getRootProps: PropGetter<\"label\"> = useCallback(\n (props = {}) => {\n const sharedProps = mergeProps(\n dataProps,\n { \"data-checked\": dataAttr(checked) },\n rest,\n props,\n )()\n\n return getLabelProps?.(sharedProps) ?? sharedProps\n },\n [dataProps, getLabelProps, checked, rest],\n )\n\n const getInputProps: PropGetter<\"input\"> = useCallback(\n (props = {}) => {\n const sharedProps = mergeProps(\n dataProps,\n ariaProps,\n {\n id,\n ref,\n type: \"radio\",\n name,\n style: visuallyHiddenAttributes.style,\n \"aria-checked\": checked,\n \"aria-controls\": ariaControls,\n \"aria-describedby\": resolvedAriaDescribedby,\n \"aria-labelledby\": ariaLabelledby,\n \"data-checked\": dataAttr(checked),\n checked,\n disabled,\n readOnly,\n required,\n tabIndex,\n value,\n },\n props,\n eventProps,\n { onChange },\n )()\n\n return getGroupInputProps?.(sharedProps) ?? sharedProps\n },\n [\n dataProps,\n ariaProps,\n id,\n name,\n checked,\n ariaControls,\n resolvedAriaDescribedby,\n ariaLabelledby,\n disabled,\n readOnly,\n required,\n tabIndex,\n value,\n ref,\n eventProps,\n onChange,\n getGroupInputProps,\n ],\n )\n\n const getIndicatorProps: PropGetter = useCallback(\n (props = {}) =>\n mergeProps(\n dataProps,\n { \"aria-hidden\": \"true\", \"data-checked\": dataAttr(checked) },\n props,\n )(),\n [dataProps, checked],\n )\n\n return {\n checked,\n getIndicatorProps,\n getInputProps,\n getRootProps,\n onChange,\n }\n}\n\nexport type UseRadioReturn = ReturnType<typeof useRadio>\n"],"mappings":";;;;;;;;;AAqDA,MAAa,YAAuC,EAClD,oBAAoB,qBACpB,GAAG,UACiB,CAAC,MAAM;CAC3B,MAAM,QAAQA,wBAAAA,qBAAqB;CACnC,MAAM,EACJ,MAAM,WACN,OAAO,YACP,eAAe,oBACf,kBACE,SAAS,CAAC;CACd,MAAM,QAAA,GAAOC,MAAAA,MAAAA,CAAM;CACnB,MAAM,EACJ,OAAO,EACL,IACA,KACA,OAAO,WACP,iBAAiB,cACjB,mBAAmB,gBACnB,SAAS,aACT,iBAAiB,OACjB,UACA,UACA,UACA,UACA,OACA,UAAU,cACV,GAAG,QAEL,WAAW,EAAE,oBAAoB,iBAAiB,GAAG,aACrD,WACA,eACEC,wBAAAA,cAAc;EAChB,IAAI,QAAQ,OAAO,KAAA;EACnB,GAAG;EACH,oBAAoB;CACtB,CAAC;CACD,MAAM,cAAc,EAAE,YAAY;CAClC,MAAM,0BAA0B,QAAQ,sBAAsB;CAC9D,MAAM,kBACJ,EAAA,GAAA,oBAAA,cAAC,YAAA,CAAY,UAAU,KAAK,EAAA,GAAA,oBAAA,cAAC,YAAA,CAAY,KAAK,IAC1C,eAAe,QACf;CACN,MAAM,CAAC,SAAS,cAAcC,2CAAAA,0BAA0B;EACtD,cAAc;EACd,OAAO;EACP,UAAU;CACZ,CAAC;CAED,MAAM,YAAA,GAAWC,MAAAA,YAAAA,EACd,OAAsC;EACrC,IAAI,CAAC,aAAa,OAAQ,GAAG,mBAAmB;EAEhD,WAAW,EAAE;CACf,GACA,CAAC,YAAY,WAAW,CAC1B;CAEA,MAAM,gBAAA,GAAoCA,MAAAA,YAAAA,EACvC,QAAQ,CAAC,MAAM;EACd,MAAM,cAAcC,cAAAA,WAClB,WACA,EAAE,iBAAA,GAAA,oBAAA,cAAgB,SAAA,CAAS,OAAO,EAAE,GACpC,MACA,KACF,CAAC,CAAC;EAEF,OAAO,gBAAgB,WAAW,KAAK;CACzC,GACA;EAAC;EAAW;EAAe;EAAS;CAAI,CAC1C;CAEA,MAAM,iBAAA,GAAqCD,MAAAA,YAAAA,EACxC,QAAQ,CAAC,MAAM;EACd,MAAM,cAAcC,cAAAA,WAClB,WACA,WACA;GACE;GACA;GACA,MAAM;GACN;GACA,OAAOC,YAAAA,yBAAyB;GAChC,gBAAgB;GAChB,iBAAiB;GACjB,oBAAoB;GACpB,mBAAmB;GACnB,iBAAA,GAAA,oBAAA,cAAgB,SAAA,CAAS,OAAO;GAChC;GACA;GACA;GACA;GACA;GACA;EACF,GACA,OACA,YACA,EAAE,SAAS,CACb,CAAC,CAAC;EAEF,OAAO,qBAAqB,WAAW,KAAK;CAC9C,GACA;EACE;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;CACF,CACF;CAYA,OAAO;EACL;EACA,oBAAA,GAZoCF,MAAAA,YAAAA,EACnC,QAAQ,CAAC,MACRC,cAAAA,WACE,WACA;GAAE,eAAe;GAAQ,iBAAA,GAAA,oBAAA,cAAgB,SAAA,CAAS,OAAO;EAAE,GAC3D,KACF,CAAC,CAAC,GACJ,CAAC,WAAW,OAAO,CAKH;EAChB;EACA;EACA;CACF;AACF"}
|
|
@@ -45,12 +45,10 @@ const useCheckboxGroup = (props = {}) => {
|
|
|
45
45
|
return {
|
|
46
46
|
max,
|
|
47
47
|
value,
|
|
48
|
-
getInputProps: useCallback((props = {}) => {
|
|
48
|
+
getInputProps: useCallback(({ disabled, ...props } = {}) => {
|
|
49
49
|
const checked = !(0, utils_exports.isUndefined)(value) && ((0, utils_exports.isString)(props.value) || (0, utils_exports.isNumber)(props.value)) && value.includes(props.value);
|
|
50
50
|
const trulyDisabled = !checked && (0, utils_exports.isNumber)(max) && value.length >= max;
|
|
51
|
-
return {
|
|
52
|
-
...dataProps,
|
|
53
|
-
...ariaProps,
|
|
51
|
+
return mergeProps(dataProps, ariaProps, {
|
|
54
52
|
type: "checkbox",
|
|
55
53
|
style: visuallyHiddenAttributes.style,
|
|
56
54
|
"aria-checked": checked,
|
|
@@ -58,14 +56,10 @@ const useCheckboxGroup = (props = {}) => {
|
|
|
58
56
|
"data-checked": (0, utils_exports.dataAttr)(checked),
|
|
59
57
|
"data-disabled": (0, utils_exports.dataAttr)(trulyDisabled),
|
|
60
58
|
checked,
|
|
59
|
+
disabled: Boolean(disabled || trulyDisabled),
|
|
61
60
|
readOnly,
|
|
62
|
-
required
|
|
63
|
-
|
|
64
|
-
disabled: Boolean(props.disabled || trulyDisabled),
|
|
65
|
-
onBlur: (0, utils_exports.handlerAll)(props.onBlur, eventProps.onBlur),
|
|
66
|
-
onChange: (0, utils_exports.handlerAll)(props.onChange, onChange),
|
|
67
|
-
onFocus: (0, utils_exports.handlerAll)(props.onFocus, eventProps.onFocus)
|
|
68
|
-
};
|
|
61
|
+
required
|
|
62
|
+
}, props, eventProps, { onChange })();
|
|
69
63
|
}, [
|
|
70
64
|
ariaProps,
|
|
71
65
|
dataProps,
|
|
@@ -76,10 +70,7 @@ const useCheckboxGroup = (props = {}) => {
|
|
|
76
70
|
required,
|
|
77
71
|
value
|
|
78
72
|
]),
|
|
79
|
-
getLabelProps: useCallback((props) => (
|
|
80
|
-
...dataProps,
|
|
81
|
-
...props
|
|
82
|
-
}), [dataProps]),
|
|
73
|
+
getLabelProps: useCallback((props = {}) => mergeProps(dataProps, props)(), [dataProps]),
|
|
83
74
|
getRootProps,
|
|
84
75
|
onChange
|
|
85
76
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-checkbox-group.js","names":["createContext","isObject","isNumber","isUndefined","isString","ariaAttr","dataAttr"
|
|
1
|
+
{"version":3,"file":"use-checkbox-group.js","names":["createContext","isObject","isNumber","isUndefined","isString","ariaAttr","dataAttr"],"sources":["../../../../src/components/checkbox/use-checkbox-group.ts"],"sourcesContent":["\"use client\"\n\nimport type { ChangeEvent } from \"react\"\nimport type { HTMLProps, PropGetter } from \"../../core\"\nimport type { FieldProps } from \"../field\"\nimport { useCallback } from \"react\"\nimport { mergeProps } from \"../../core\"\nimport { useControllableState } from \"../../hooks/use-controllable-state\"\nimport {\n ariaAttr,\n createContext,\n dataAttr,\n isNumber,\n isObject,\n isString,\n isUndefined,\n visuallyHiddenAttributes,\n} from \"../../utils\"\nimport { useFieldProps } from \"../field\"\n\ninterface CheckboxGroupContext extends Omit<\n UseCheckboxGroupReturn,\n \"getRootProps\"\n> {}\n\nconst [CheckboxGroupContext, useCheckboxGroupContext] =\n createContext<CheckboxGroupContext>({\n name: \"CheckboxGroupContext\",\n strict: false,\n })\n\nexport { CheckboxGroupContext, useCheckboxGroupContext }\n\nexport interface UseCheckboxGroupProps<Y extends string = string>\n extends Omit<HTMLProps, \"defaultValue\" | \"onChange\" | \"value\">, FieldProps {\n /**\n * The initial value of the checkbox group.\n *\n * @default []\n */\n defaultValue?: Y[]\n /**\n * The maximum number of checkboxes that can be checked.\n */\n max?: number\n /**\n * The value of the checkbox group.\n */\n value?: Y[]\n /**\n * The callback fired when any children checkbox is checked or unchecked.\n */\n onChange?: (value: Y[]) => void\n}\n\nexport const useCheckboxGroup = <Y extends string = string>(\n props: UseCheckboxGroupProps<Y> = {},\n) => {\n const {\n context: { labelId } = {},\n props: {\n defaultValue = [],\n disabled,\n max,\n readOnly,\n required,\n value: valueProp,\n onChange: onChangeProp,\n ...rest\n },\n ariaProps: { \"aria-describedby\": ariaDescribedby, ...ariaProps },\n dataProps,\n eventProps,\n } = useFieldProps(props)\n const interactive = !(readOnly || disabled)\n const [value, setValue] = useControllableState({\n defaultValue,\n value: valueProp,\n onChange: onChangeProp,\n })\n\n const onChange = useCallback(\n (valueOrEv: ChangeEvent<HTMLInputElement> | Y) => {\n if (!interactive) return\n\n if (isObject(valueOrEv)) valueOrEv = valueOrEv.target.value as Y\n\n setValue((prev) => {\n if (prev.includes(valueOrEv))\n return prev.filter((prevValue) => prevValue !== valueOrEv)\n else if (!isNumber(max) || prev.length < max)\n return [...prev, valueOrEv]\n else return prev\n })\n },\n [interactive, max, setValue],\n )\n\n const getRootProps: PropGetter = useCallback(\n (props = {}) =>\n mergeProps(\n dataProps,\n {\n \"aria-describedby\": ariaDescribedby,\n \"aria-labelledby\": labelId,\n role: \"group\",\n },\n rest,\n props,\n )(),\n [ariaDescribedby, dataProps, labelId, rest],\n )\n\n const getInputProps: PropGetter<\"input\"> = useCallback(\n ({ disabled, ...props } = {}) => {\n const checked =\n !isUndefined(value) &&\n (isString(props.value) || isNumber(props.value)) &&\n value.includes(props.value as Y)\n const trulyDisabled = !checked && isNumber(max) && value.length >= max\n\n return mergeProps(\n dataProps,\n ariaProps,\n {\n type: \"checkbox\",\n style: visuallyHiddenAttributes.style,\n \"aria-checked\": checked,\n \"aria-disabled\": ariaAttr(trulyDisabled),\n \"data-checked\": dataAttr(checked),\n \"data-disabled\": dataAttr(trulyDisabled),\n checked,\n disabled: Boolean(disabled || trulyDisabled),\n readOnly,\n required,\n },\n props,\n eventProps,\n { onChange },\n )()\n },\n [\n ariaProps,\n dataProps,\n eventProps,\n max,\n onChange,\n readOnly,\n required,\n value,\n ],\n )\n\n const getLabelProps: PropGetter<\"label\"> = useCallback(\n (props = {}) => mergeProps(dataProps, props)(),\n [dataProps],\n )\n\n return {\n max,\n value,\n getInputProps,\n getLabelProps,\n getRootProps,\n onChange,\n }\n}\n\nexport type UseCheckboxGroupReturn = ReturnType<typeof useCheckbo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C9C,MAAM,SAAS,MAAM,KAAU;GACjC,MAAM,gBAAgB,CAAC,YAAA,GAAWA,cAAAA,SAAAA,CAAS,GAAG,KAAK,MAAM,UAAU;GAEnE,OAAO,WACL,WACA,WACA;IACE,MAAM;IACN,OAAO,yBAAyB;IAChC,gBAAgB;IAChB,kBAAA,GAAiBG,cAAAA,SAAAA,CAAS,aAAa;IACvC,iBAAA,GAAgBC,cAAAA,SAAAA,CAAS,OAAO;IAChC,kBAAA,GAAiBA,cAAAA,SAAAA,CAAS,aAAa;IACvC;IACA,UAAU,QAAQ,YAAY,aAAa;IAC3C;IACA;GACF,GACA,OACA,YACA,EAAE,SAAS,CACb,CAAC,CAAC;EACJ,GACA;GACE;GACA;GACA;GACA;GACA;GACA;GACA;GACA;EACF,CAWY;EACZ,eATyC,aACxC,QAAQ,CAAC,MAAM,WAAW,WAAW,KAAK,CAAC,CAAC,GAC7C,CAAC,SAAS,CAOE;EACZ;EACA;CACF;AACF"}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { visuallyHiddenAttributes } from "../../utils/dom.js";
|
|
3
|
-
import { mergeRefs } from "../../utils/ref.js";
|
|
4
3
|
import { mergeProps } from "../../core/components/props.js";
|
|
5
4
|
import { useControllableEventState } from "../../hooks/use-controllable-state/index.js";
|
|
6
5
|
import { utils_exports } from "../../utils/index.js";
|
|
@@ -39,8 +38,7 @@ const useCheckbox = ({ "aria-describedby": ariaDescribedbyProp, ...props } = {})
|
|
|
39
38
|
setChecked
|
|
40
39
|
]);
|
|
41
40
|
const getRootProps = useCallback((props = {}) => {
|
|
42
|
-
const merged = mergeProps({
|
|
43
|
-
...dataProps,
|
|
41
|
+
const merged = mergeProps(dataProps, {
|
|
44
42
|
"data-checked": (0, utils_exports.dataAttr)(checked),
|
|
45
43
|
"data-indeterminate": (0, utils_exports.dataAttr)(indeterminate)
|
|
46
44
|
}, rest, props)();
|
|
@@ -53,11 +51,9 @@ const useCheckbox = ({ "aria-describedby": ariaDescribedbyProp, ...props } = {})
|
|
|
53
51
|
getLabelProps
|
|
54
52
|
]);
|
|
55
53
|
const getInputProps = useCallback((props = {}) => {
|
|
56
|
-
const sharedProps = mergeProps({
|
|
57
|
-
...dataProps,
|
|
58
|
-
...ariaProps,
|
|
54
|
+
const sharedProps = mergeProps({ ref }, dataProps, ariaProps, {
|
|
59
55
|
id,
|
|
60
|
-
ref:
|
|
56
|
+
ref: indeterminateRef,
|
|
61
57
|
type: "checkbox",
|
|
62
58
|
name,
|
|
63
59
|
style: visuallyHiddenAttributes.style,
|
|
@@ -74,10 +70,7 @@ const useCheckbox = ({ "aria-describedby": ariaDescribedbyProp, ...props } = {})
|
|
|
74
70
|
required,
|
|
75
71
|
tabIndex,
|
|
76
72
|
value
|
|
77
|
-
}, props, {
|
|
78
|
-
...eventProps,
|
|
79
|
-
onChange
|
|
80
|
-
})();
|
|
73
|
+
}, props, eventProps, { onChange })();
|
|
81
74
|
return getGroupInputProps?.(sharedProps) ?? sharedProps;
|
|
82
75
|
}, [
|
|
83
76
|
dataProps,
|
|
@@ -104,13 +97,11 @@ const useCheckbox = ({ "aria-describedby": ariaDescribedbyProp, ...props } = {})
|
|
|
104
97
|
return {
|
|
105
98
|
checked,
|
|
106
99
|
indeterminate,
|
|
107
|
-
getIndicatorProps: useCallback((props = {}) => ({
|
|
108
|
-
...dataProps,
|
|
100
|
+
getIndicatorProps: useCallback((props = {}) => mergeProps(dataProps, {
|
|
109
101
|
"aria-hidden": "true",
|
|
110
102
|
"data-checked": (0, utils_exports.dataAttr)(checked),
|
|
111
|
-
"data-indeterminate": (0, utils_exports.dataAttr)(indeterminate)
|
|
112
|
-
|
|
113
|
-
}), [
|
|
103
|
+
"data-indeterminate": (0, utils_exports.dataAttr)(indeterminate)
|
|
104
|
+
}, props)(), [
|
|
114
105
|
dataProps,
|
|
115
106
|
checked,
|
|
116
107
|
indeterminate
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-checkbox.js","names":["isUndefined","isNumber","dataAttr","ariaAttr"],"sources":["../../../../src/components/checkbox/use-checkbox.ts"],"sourcesContent":["\"use client\"\n\nimport type { ChangeEvent, ChangeEventHandler, FocusEventHandler } from \"react\"\nimport type { HTMLProps, HTMLRefAttributes, PropGetter } from \"../../core\"\nimport type { FieldProps } from \"../field\"\nimport { useCallback, useId } from \"react\"\nimport { mergeProps } from \"../../core\"\nimport { useControllableEventState } from \"../../hooks/use-controllable-state\"\nimport {\n ariaAttr,\n dataAttr,\n isNumber,\n isUndefined,\n
|
|
1
|
+
{"version":3,"file":"use-checkbox.js","names":["isUndefined","isNumber","dataAttr","ariaAttr"],"sources":["../../../../src/components/checkbox/use-checkbox.ts"],"sourcesContent":["\"use client\"\n\nimport type { ChangeEvent, ChangeEventHandler, FocusEventHandler } from \"react\"\nimport type { HTMLProps, HTMLRefAttributes, PropGetter } from \"../../core\"\nimport type { FieldProps } from \"../field\"\nimport { useCallback, useId } from \"react\"\nimport { mergeProps } from \"../../core\"\nimport { useControllableEventState } from \"../../hooks/use-controllable-state\"\nimport {\n ariaAttr,\n dataAttr,\n isNumber,\n isUndefined,\n visuallyHiddenAttributes,\n} from \"../../utils\"\nimport { useFieldProps } from \"../field\"\nimport { useCheckboxGroupContext } from \"./use-checkbox-group\"\n\nexport interface UseCheckboxProps<Y extends string = string>\n extends\n Omit<HTMLProps<\"label\">, \"onBlur\" | \"onChange\" | \"onFocus\" | \"ref\">,\n HTMLRefAttributes<\"input\">,\n FieldProps {\n /**\n * If `true`, the checkbox will be checked.\n */\n checked?: boolean\n /**\n * If `true`, the checkbox will be initially checked.\n *\n * @default false\n */\n defaultChecked?: boolean\n /**\n * id assigned to input.\n */\n id?: string\n /**\n * If `true`, the checkbox will be indeterminate.\n *\n * @default false\n */\n indeterminate?: boolean\n /**\n * The name of the input field in a checkbox.\n */\n name?: string\n /**\n * The value of the checkbox.\n */\n value?: Y\n /**\n * The callback invoked when the checkbox is blurred.\n */\n onBlur?: FocusEventHandler<HTMLInputElement>\n /**\n * The callback invoked when the checked state changes.\n */\n onChange?: ChangeEventHandler<HTMLInputElement>\n /**\n * The callback invoked when the checkbox is focused.\n */\n onFocus?: FocusEventHandler<HTMLInputElement>\n}\n\nexport const useCheckbox = <Y extends string = string>({\n \"aria-describedby\": ariaDescribedbyProp,\n ...props\n}: UseCheckboxProps<Y> = {}) => {\n const group = useCheckboxGroupContext()\n const {\n max,\n value: groupValue,\n getInputProps: getGroupInputProps,\n getLabelProps,\n } = group ?? {}\n const uuid = useId()\n const {\n props: {\n id,\n ref,\n name,\n \"aria-controls\": ariaControls,\n \"aria-labelledby\": ariaLabelledby,\n checked: checkedProp,\n defaultChecked = false,\n disabled,\n indeterminate = false,\n readOnly,\n required,\n tabIndex,\n value,\n onChange: onChangeProp,\n ...rest\n },\n ariaProps: { \"aria-describedby\": ariaDescribedby, ...ariaProps },\n dataProps,\n eventProps,\n } = useFieldProps({\n id: group ? uuid : undefined,\n ...props,\n notSupportReadOnly: true,\n })\n const resolvedAriaDescribedby = group ? ariaDescribedbyProp : ariaDescribedby\n const resolvedChecked =\n !isUndefined(groupValue) && !isUndefined(value)\n ? groupValue.includes(value)\n : checkedProp\n const [checked, setChecked] = useControllableEventState({\n defaultValue: defaultChecked,\n value: resolvedChecked,\n onChange: onChangeProp,\n })\n const trulyDisabled =\n !checked && isNumber(max) && group && group.value.length >= max\n const interactive = !(readOnly || trulyDisabled)\n const indeterminateRef = useCallback(\n (el: HTMLInputElement | null) => {\n if (el) el.indeterminate = indeterminate\n },\n [indeterminate],\n )\n\n const onChange = useCallback(\n (ev: ChangeEvent<HTMLInputElement>) => {\n if (!interactive) return (ev.defaultPrevented = true)\n\n if (indeterminate) ev.target.checked = true\n\n setChecked(ev)\n },\n [interactive, indeterminate, setChecked],\n )\n\n const getRootProps: PropGetter<\"label\"> = useCallback(\n (props = {}) => {\n const merged = mergeProps(\n dataProps,\n {\n \"data-checked\": dataAttr(checked),\n \"data-indeterminate\": dataAttr(indeterminate),\n },\n rest,\n props,\n )()\n\n return getLabelProps?.(merged) ?? merged\n },\n [dataProps, checked, indeterminate, rest, getLabelProps],\n )\n\n const getInputProps: PropGetter<\"input\"> = useCallback(\n (props = {}) => {\n const sharedProps = mergeProps(\n { ref },\n dataProps,\n ariaProps,\n {\n id,\n ref: indeterminateRef,\n type: \"checkbox\",\n name,\n style: visuallyHiddenAttributes.style,\n \"aria-checked\": indeterminate ? (\"mixed\" as const) : checked,\n \"aria-controls\": ariaControls,\n \"aria-describedby\": resolvedAriaDescribedby,\n \"aria-disabled\": ariaAttr(!interactive),\n \"aria-labelledby\": ariaLabelledby,\n \"data-checked\": dataAttr(checked),\n \"data-indeterminate\": dataAttr(indeterminate),\n checked,\n disabled,\n readOnly,\n required,\n tabIndex,\n value,\n },\n props,\n eventProps,\n { onChange },\n )()\n\n return getGroupInputProps?.(sharedProps) ?? sharedProps\n },\n [\n dataProps,\n ariaProps,\n id,\n name,\n indeterminate,\n checked,\n ariaControls,\n resolvedAriaDescribedby,\n interactive,\n ariaLabelledby,\n disabled,\n readOnly,\n required,\n tabIndex,\n value,\n ref,\n indeterminateRef,\n eventProps,\n onChange,\n getGroupInputProps,\n ],\n )\n\n const getIndicatorProps: PropGetter = useCallback(\n (props = {}) =>\n mergeProps(\n dataProps,\n {\n \"aria-hidden\": \"true\",\n \"data-checked\": dataAttr(checked),\n \"data-indeterminate\": dataAttr(indeterminate),\n },\n props,\n )(),\n [dataProps, checked, indeterminate],\n )\n\n return {\n checked,\n indeterminate,\n getIndicatorProps,\n getInputProps,\n getRootProps,\n onChange,\n }\n}\n\nexport type UseCheckboxReturn = ReturnType<typeof useCheckbox>\n"],"mappings":";;;;;;;;;AAiEA,MAAa,eAA0C,EACrD,oBAAoB,qBACpB,GAAG,UACoB,CAAC,MAAM;CAC9B,MAAM,QAAQ,wBAAwB;CACtC,MAAM,EACJ,KACA,OAAO,YACP,eAAe,oBACf,kBACE,SAAS,CAAC;CACd,MAAM,OAAO,MAAM;C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AqC,aACxC,QAAQ,CAAC,MAAM;EACd,MAAM,cAAc,WAClB,EAAE,IAAI,GACN,WACA,WACA;GACE;GACA,KAAK;GACL,MAAM;GACN;GACA,OAAO,yBAAyB;GAChC,gBAAgB,gBAAiB,UAAoB;GACrD,iBAAiB;GACjB,oBAAoB;GACpB,kBAAA,GAAiBC,cAAAA,SAAAA,CAAS,CAAC,WAAW;GACtC,mBAAmB;GACnB,iBAAA,GAAgBD,cAAAA,SAAAA,CAAS,OAAO;GAChC,uBAAA,GAAsBA,cAAAA,SAAAA,CAAS,aAAa;GAC5C;GACA;GACA;GACA;GACA;GACA;EACF,GACA,OACA,YACA,EAAE,SAAS,CACb,CAAC,CAAC;EAEF,OAAO,qBAAqB,WAAW,KAAK;CAC9C,GACA;EACE;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;CACF,CACF;CAgBA,OAAO;EACL;EACA;EACA,mBAjBoC,aACnC,QAAQ,CAAC,MACR,WACE,WACA;GACE,eAAe;GACf,iBAAA,GAAgBA,cAAAA,SAAAA,CAAS,OAAO;GAChC,uBAAA,GAAsBA,cAAAA,SAAAA,CAAS,aAAa;EAC9C,GACA,KACF,CAAC,CAAC,GACJ;GAAC;GAAW;GAAS;EAAa,CAMlB;EAChB;EACA;EACA;CACF;AACF"}
|
|
@@ -45,9 +45,7 @@ const useRadioGroup = (props = {}) => {
|
|
|
45
45
|
value,
|
|
46
46
|
getInputProps: useCallback((props = {}) => {
|
|
47
47
|
const checked = !(0, utils_exports.isUndefined)(value) && value === props.value;
|
|
48
|
-
return mergeProps({
|
|
49
|
-
...dataProps,
|
|
50
|
-
...ariaProps,
|
|
48
|
+
return mergeProps(dataProps, ariaProps, {
|
|
51
49
|
type: "radio",
|
|
52
50
|
name: id,
|
|
53
51
|
style: visuallyHiddenAttributes.style,
|
|
@@ -57,10 +55,7 @@ const useRadioGroup = (props = {}) => {
|
|
|
57
55
|
disabled,
|
|
58
56
|
readOnly,
|
|
59
57
|
required
|
|
60
|
-
}, props, {
|
|
61
|
-
onChange,
|
|
62
|
-
...eventProps
|
|
63
|
-
})();
|
|
58
|
+
}, props, eventProps, { onChange })();
|
|
64
59
|
}, [
|
|
65
60
|
ariaProps,
|
|
66
61
|
dataProps,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-radio-group.js","names":["createContext","isObject","isUndefined","dataAttr"],"sources":["../../../../src/components/radio/use-radio-group.ts"],"sourcesContent":["\"use client\"\n\nimport type { ChangeEvent } from \"react\"\nimport type { HTMLProps, PropGetter } from \"../../core\"\nimport type { FieldProps } from \"../field\"\nimport { useCallback, useId } from \"react\"\nimport { mergeProps } from \"../../core\"\nimport { useControllableState } from \"../../hooks/use-controllable-state\"\nimport {\n createContext,\n dataAttr,\n isObject,\n isUndefined,\n visuallyHiddenAttributes,\n} from \"../../utils\"\nimport { useFieldProps } from \"../field\"\n\ninterface RadioGroupContext extends Omit<UseRadioGroupReturn, \"getRootProps\"> {}\n\nconst [RadioGroupContext, useRadioGroupContext] =\n createContext<RadioGroupContext>({\n name: \"RadioGroupContext\",\n strict: false,\n })\n\nexport { RadioGroupContext, useRadioGroupContext }\n\nexport interface UseRadioGroupProps<Y extends string = string>\n extends Omit<HTMLProps, \"defaultValue\" | \"onChange\" | \"value\">, FieldProps {\n /**\n * The initial value of the radio group.\n */\n defaultValue?: Y\n /**\n * The value of the radio group.\n */\n value?: Y\n /**\n * The callback fired when any children radio is checked or unchecked.\n */\n onChange?: (value: Y) => void\n}\n\nexport const useRadioGroup = <Y extends string = string>(\n props: UseRadioGroupProps<Y> = {},\n) => {\n const uuid = useId()\n const {\n context: { labelId } = {},\n props: {\n id = uuid,\n defaultValue,\n disabled,\n readOnly,\n required,\n value: valueProp,\n onChange: onChangeProp,\n ...rest\n },\n ariaProps: { \"aria-describedby\": ariaDescribedby, ...ariaProps },\n dataProps,\n eventProps,\n } = useFieldProps({\n ...props,\n notSupportReadOnly: true,\n })\n const interactive = !(readOnly || disabled)\n const [value, setValue] = useControllableState({\n defaultValue,\n value: valueProp,\n onChange: onChangeProp,\n })\n\n const onChange = useCallback(\n (valueOrEv: ChangeEvent<HTMLInputElement> | Y) => {\n if (!interactive) return\n\n if (isObject(valueOrEv)) setValue(valueOrEv.target.value as Y)\n else setValue(valueOrEv)\n },\n [interactive, setValue],\n )\n\n const getRootProps: PropGetter = useCallback(\n (props = {}) =>\n mergeProps(\n dataProps,\n {\n id,\n \"aria-describedby\": ariaDescribedby,\n \"aria-labelledby\": labelId,\n role: \"radiogroup\",\n },\n rest,\n props,\n )(),\n [ariaDescribedby, dataProps, id, labelId, rest],\n )\n\n const getInputProps: PropGetter<\"input\"> = useCallback(\n (props = {}) => {\n const checked = !isUndefined(value) && value === props.value\n\n return mergeProps(\n
|
|
1
|
+
{"version":3,"file":"use-radio-group.js","names":["createContext","isObject","isUndefined","dataAttr"],"sources":["../../../../src/components/radio/use-radio-group.ts"],"sourcesContent":["\"use client\"\n\nimport type { ChangeEvent } from \"react\"\nimport type { HTMLProps, PropGetter } from \"../../core\"\nimport type { FieldProps } from \"../field\"\nimport { useCallback, useId } from \"react\"\nimport { mergeProps } from \"../../core\"\nimport { useControllableState } from \"../../hooks/use-controllable-state\"\nimport {\n createContext,\n dataAttr,\n isObject,\n isUndefined,\n visuallyHiddenAttributes,\n} from \"../../utils\"\nimport { useFieldProps } from \"../field\"\n\ninterface RadioGroupContext extends Omit<UseRadioGroupReturn, \"getRootProps\"> {}\n\nconst [RadioGroupContext, useRadioGroupContext] =\n createContext<RadioGroupContext>({\n name: \"RadioGroupContext\",\n strict: false,\n })\n\nexport { RadioGroupContext, useRadioGroupContext }\n\nexport interface UseRadioGroupProps<Y extends string = string>\n extends Omit<HTMLProps, \"defaultValue\" | \"onChange\" | \"value\">, FieldProps {\n /**\n * The initial value of the radio group.\n */\n defaultValue?: Y\n /**\n * The value of the radio group.\n */\n value?: Y\n /**\n * The callback fired when any children radio is checked or unchecked.\n */\n onChange?: (value: Y) => void\n}\n\nexport const useRadioGroup = <Y extends string = string>(\n props: UseRadioGroupProps<Y> = {},\n) => {\n const uuid = useId()\n const {\n context: { labelId } = {},\n props: {\n id = uuid,\n defaultValue,\n disabled,\n readOnly,\n required,\n value: valueProp,\n onChange: onChangeProp,\n ...rest\n },\n ariaProps: { \"aria-describedby\": ariaDescribedby, ...ariaProps },\n dataProps,\n eventProps,\n } = useFieldProps({\n ...props,\n notSupportReadOnly: true,\n })\n const interactive = !(readOnly || disabled)\n const [value, setValue] = useControllableState({\n defaultValue,\n value: valueProp,\n onChange: onChangeProp,\n })\n\n const onChange = useCallback(\n (valueOrEv: ChangeEvent<HTMLInputElement> | Y) => {\n if (!interactive) return\n\n if (isObject(valueOrEv)) setValue(valueOrEv.target.value as Y)\n else setValue(valueOrEv)\n },\n [interactive, setValue],\n )\n\n const getRootProps: PropGetter = useCallback(\n (props = {}) =>\n mergeProps(\n dataProps,\n {\n id,\n \"aria-describedby\": ariaDescribedby,\n \"aria-labelledby\": labelId,\n role: \"radiogroup\",\n },\n rest,\n props,\n )(),\n [ariaDescribedby, dataProps, id, labelId, rest],\n )\n\n const getInputProps: PropGetter<\"input\"> = useCallback(\n (props = {}) => {\n const checked = !isUndefined(value) && value === props.value\n\n return mergeProps(\n dataProps,\n ariaProps,\n {\n type: \"radio\",\n name: id,\n style: visuallyHiddenAttributes.style,\n \"aria-checked\": checked,\n \"data-checked\": dataAttr(checked),\n checked,\n disabled,\n readOnly,\n required,\n },\n props,\n eventProps,\n { onChange },\n )()\n },\n [\n ariaProps,\n dataProps,\n disabled,\n eventProps,\n id,\n onChange,\n readOnly,\n required,\n value,\n ],\n )\n\n const getLabelProps: PropGetter<\"label\"> = useCallback(\n (props) => ({\n ...dataProps,\n ...props,\n }),\n [dataProps],\n )\n\n return {\n name: id,\n value,\n getInputProps,\n getLabelProps,\n getRootProps,\n onChange,\n }\n}\n\nexport type UseRadioGroupReturn = ReturnType<type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;GACA;GACA;GACA;GACA;GACA;EACF,CAcY;EACZ,eAZyC,aACxC,WAAW;GACV,GAAG;GACH,GAAG;EACL,IACA,CAAC,SAAS,CAOE;EACZ;EACA;CACF;AACF"}
|
|
@@ -38,9 +38,7 @@ const useRadio = ({ "aria-describedby": ariaDescribedbyProp, ...props } = {}) =>
|
|
|
38
38
|
rest
|
|
39
39
|
]);
|
|
40
40
|
const getInputProps = useCallback((props = {}) => {
|
|
41
|
-
const sharedProps = mergeProps({
|
|
42
|
-
...dataProps,
|
|
43
|
-
...ariaProps,
|
|
41
|
+
const sharedProps = mergeProps(dataProps, ariaProps, {
|
|
44
42
|
id,
|
|
45
43
|
ref,
|
|
46
44
|
type: "radio",
|
|
@@ -57,10 +55,7 @@ const useRadio = ({ "aria-describedby": ariaDescribedbyProp, ...props } = {}) =>
|
|
|
57
55
|
required,
|
|
58
56
|
tabIndex,
|
|
59
57
|
value
|
|
60
|
-
}, props, {
|
|
61
|
-
...eventProps,
|
|
62
|
-
onChange
|
|
63
|
-
})();
|
|
58
|
+
}, props, eventProps, { onChange })();
|
|
64
59
|
return getGroupInputProps?.(sharedProps) ?? sharedProps;
|
|
65
60
|
}, [
|
|
66
61
|
dataProps,
|
|
@@ -83,12 +78,10 @@ const useRadio = ({ "aria-describedby": ariaDescribedbyProp, ...props } = {}) =>
|
|
|
83
78
|
]);
|
|
84
79
|
return {
|
|
85
80
|
checked,
|
|
86
|
-
getIndicatorProps: useCallback((props = {}) => ({
|
|
87
|
-
...dataProps,
|
|
81
|
+
getIndicatorProps: useCallback((props = {}) => mergeProps(dataProps, {
|
|
88
82
|
"aria-hidden": "true",
|
|
89
|
-
"data-checked": (0, utils_exports.dataAttr)(checked)
|
|
90
|
-
|
|
91
|
-
}), [dataProps, checked]),
|
|
83
|
+
"data-checked": (0, utils_exports.dataAttr)(checked)
|
|
84
|
+
}, props)(), [dataProps, checked]),
|
|
92
85
|
getInputProps,
|
|
93
86
|
getRootProps,
|
|
94
87
|
onChange
|