@yamada-ui/react 2.3.0-dev-20261024165228 → 2.3.0-dev-20261025045056

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.
Files changed (124) hide show
  1. package/dist/cjs/components/accordion/use-accordion.cjs +4 -5
  2. package/dist/cjs/components/accordion/use-accordion.cjs.map +1 -1
  3. package/dist/cjs/components/checkbox/use-checkbox-group.cjs +6 -6
  4. package/dist/cjs/components/checkbox/use-checkbox-group.cjs.map +1 -1
  5. package/dist/cjs/components/checkbox/use-checkbox.cjs +17 -18
  6. package/dist/cjs/components/checkbox/use-checkbox.cjs.map +1 -1
  7. package/dist/cjs/components/code/code.style.cjs +2 -1
  8. package/dist/cjs/components/code/code.style.cjs.map +1 -1
  9. package/dist/cjs/components/color-picker/use-color-picker.cjs +14 -16
  10. package/dist/cjs/components/color-picker/use-color-picker.cjs.map +1 -1
  11. package/dist/cjs/components/color-selector/use-color-selector.cjs +4 -5
  12. package/dist/cjs/components/color-selector/use-color-selector.cjs.map +1 -1
  13. package/dist/cjs/components/dropzone/use-dropzone.cjs +3 -4
  14. package/dist/cjs/components/dropzone/use-dropzone.cjs.map +1 -1
  15. package/dist/cjs/components/file-input/use-file-input.cjs +5 -5
  16. package/dist/cjs/components/file-input/use-file-input.cjs.map +1 -1
  17. package/dist/cjs/components/kbd/kbd.style.cjs +2 -1
  18. package/dist/cjs/components/kbd/kbd.style.cjs.map +1 -1
  19. package/dist/cjs/components/menu/use-menu.cjs +36 -49
  20. package/dist/cjs/components/menu/use-menu.cjs.map +1 -1
  21. package/dist/cjs/components/modal/use-modal.cjs +5 -7
  22. package/dist/cjs/components/modal/use-modal.cjs.map +1 -1
  23. package/dist/cjs/components/native-popover/use-native-popover.cjs +8 -8
  24. package/dist/cjs/components/native-popover/use-native-popover.cjs.map +1 -1
  25. package/dist/cjs/components/pin-input/use-pin-input.cjs +10 -9
  26. package/dist/cjs/components/pin-input/use-pin-input.cjs.map +1 -1
  27. package/dist/cjs/components/radio/use-radio-group.cjs +12 -13
  28. package/dist/cjs/components/radio/use-radio-group.cjs.map +1 -1
  29. package/dist/cjs/components/radio/use-radio.cjs +15 -18
  30. package/dist/cjs/components/radio/use-radio.cjs.map +1 -1
  31. package/dist/cjs/components/saturation-slider/use-saturation-slider.cjs +4 -6
  32. package/dist/cjs/components/saturation-slider/use-saturation-slider.cjs.map +1 -1
  33. package/dist/cjs/components/select/use-select.cjs +5 -6
  34. package/dist/cjs/components/select/use-select.cjs.map +1 -1
  35. package/dist/cjs/components/sidebar/use-sidebar.cjs +13 -19
  36. package/dist/cjs/components/sidebar/use-sidebar.cjs.map +1 -1
  37. package/dist/cjs/components/slider/use-slider.cjs +13 -18
  38. package/dist/cjs/components/slider/use-slider.cjs.map +1 -1
  39. package/dist/cjs/components/steps/use-steps.cjs +4 -6
  40. package/dist/cjs/components/steps/use-steps.cjs.map +1 -1
  41. package/dist/cjs/components/tabs/use-tabs.cjs +5 -5
  42. package/dist/cjs/components/tabs/use-tabs.cjs.map +1 -1
  43. package/dist/cjs/components/tooltip/use-tooltip.cjs +13 -14
  44. package/dist/cjs/components/tooltip/use-tooltip.cjs.map +1 -1
  45. package/dist/cjs/core/components/props.cjs +12 -1
  46. package/dist/cjs/core/components/props.cjs.map +1 -1
  47. package/dist/cjs/core/index.cjs +2 -0
  48. package/dist/cjs/core/system/index.cjs +2 -0
  49. package/dist/cjs/core/system/styled.cjs +23 -12
  50. package/dist/cjs/core/system/styled.cjs.map +1 -1
  51. package/dist/cjs/hooks/use-combobox/index.cjs +23 -28
  52. package/dist/cjs/hooks/use-combobox/index.cjs.map +1 -1
  53. package/dist/cjs/index.cjs +4 -0
  54. package/dist/esm/components/accordion/use-accordion.js +4 -5
  55. package/dist/esm/components/accordion/use-accordion.js.map +1 -1
  56. package/dist/esm/components/checkbox/use-checkbox-group.js +6 -6
  57. package/dist/esm/components/checkbox/use-checkbox-group.js.map +1 -1
  58. package/dist/esm/components/checkbox/use-checkbox.js +17 -18
  59. package/dist/esm/components/checkbox/use-checkbox.js.map +1 -1
  60. package/dist/esm/components/code/code.style.js +2 -1
  61. package/dist/esm/components/code/code.style.js.map +1 -1
  62. package/dist/esm/components/color-picker/use-color-picker.js +14 -16
  63. package/dist/esm/components/color-picker/use-color-picker.js.map +1 -1
  64. package/dist/esm/components/color-selector/use-color-selector.js +4 -5
  65. package/dist/esm/components/color-selector/use-color-selector.js.map +1 -1
  66. package/dist/esm/components/dropzone/use-dropzone.js +3 -4
  67. package/dist/esm/components/dropzone/use-dropzone.js.map +1 -1
  68. package/dist/esm/components/file-input/use-file-input.js +5 -5
  69. package/dist/esm/components/file-input/use-file-input.js.map +1 -1
  70. package/dist/esm/components/kbd/kbd.style.js +2 -1
  71. package/dist/esm/components/kbd/kbd.style.js.map +1 -1
  72. package/dist/esm/components/menu/use-menu.js +36 -49
  73. package/dist/esm/components/menu/use-menu.js.map +1 -1
  74. package/dist/esm/components/modal/use-modal.js +5 -7
  75. package/dist/esm/components/modal/use-modal.js.map +1 -1
  76. package/dist/esm/components/native-popover/use-native-popover.js +8 -8
  77. package/dist/esm/components/native-popover/use-native-popover.js.map +1 -1
  78. package/dist/esm/components/pin-input/use-pin-input.js +10 -9
  79. package/dist/esm/components/pin-input/use-pin-input.js.map +1 -1
  80. package/dist/esm/components/radio/use-radio-group.js +12 -13
  81. package/dist/esm/components/radio/use-radio-group.js.map +1 -1
  82. package/dist/esm/components/radio/use-radio.js +15 -18
  83. package/dist/esm/components/radio/use-radio.js.map +1 -1
  84. package/dist/esm/components/saturation-slider/use-saturation-slider.js +4 -6
  85. package/dist/esm/components/saturation-slider/use-saturation-slider.js.map +1 -1
  86. package/dist/esm/components/select/use-select.js +5 -6
  87. package/dist/esm/components/select/use-select.js.map +1 -1
  88. package/dist/esm/components/sidebar/use-sidebar.js +13 -19
  89. package/dist/esm/components/sidebar/use-sidebar.js.map +1 -1
  90. package/dist/esm/components/slider/use-slider.js +13 -18
  91. package/dist/esm/components/slider/use-slider.js.map +1 -1
  92. package/dist/esm/components/steps/use-steps.js +4 -6
  93. package/dist/esm/components/steps/use-steps.js.map +1 -1
  94. package/dist/esm/components/tabs/use-tabs.js +5 -5
  95. package/dist/esm/components/tabs/use-tabs.js.map +1 -1
  96. package/dist/esm/components/tooltip/use-tooltip.js +14 -15
  97. package/dist/esm/components/tooltip/use-tooltip.js.map +1 -1
  98. package/dist/esm/core/components/props.js +12 -1
  99. package/dist/esm/core/components/props.js.map +1 -1
  100. package/dist/esm/core/index.js +2 -2
  101. package/dist/esm/core/system/index.js +2 -2
  102. package/dist/esm/core/system/styled.js +22 -13
  103. package/dist/esm/core/system/styled.js.map +1 -1
  104. package/dist/esm/hooks/use-combobox/index.js +23 -28
  105. package/dist/esm/hooks/use-combobox/index.js.map +1 -1
  106. package/dist/esm/index.js +4 -2
  107. package/dist/types/components/carousel/carousel.style.d.ts +2 -2
  108. package/dist/types/components/menu/menu.style.d.ts +2 -2
  109. package/dist/types/components/menu/use-menu.d.ts +1 -1
  110. package/dist/types/components/segmented-control/segmented-control.style.d.ts +2 -2
  111. package/dist/types/components/steps/steps.style.d.ts +1 -1
  112. package/dist/types/components/steps/use-steps.d.ts +1 -1
  113. package/dist/types/components/tabs/use-tabs.d.ts +1 -1
  114. package/dist/types/components/timeline/timeline.d.ts +1 -1
  115. package/dist/types/components/timeline/timeline.style.d.ts +1 -1
  116. package/dist/types/components/tree/tree.style.d.ts +1 -1
  117. package/dist/types/core/components/index.d.ts +2 -2
  118. package/dist/types/core/components/props.d.ts +2 -1
  119. package/dist/types/core/index.d.ts +3 -3
  120. package/dist/types/core/system/index.d.ts +2 -2
  121. package/dist/types/core/system/styled.d.ts +1 -0
  122. package/dist/types/hooks/use-combobox/index.d.ts +1 -1
  123. package/dist/types/index.d.ts +4 -4
  124. package/package.json +2 -2
@@ -1 +1 @@
1
- {"version":3,"file":"use-pin-input.cjs","names":["createDescendants","useId","useFieldProps","useState","useControllableState","useCallback","mergeProps"],"sources":["../../../../src/components/pin-input/use-pin-input.ts"],"sourcesContent":["\"use client\"\n\nimport type { ChangeEvent, KeyboardEvent } from \"react\"\nimport type { HTMLProps, PropGetter, RequiredPropGetter } from \"../../core\"\nimport type { FieldProps } from \"../field\"\nimport { useCallback, useEffect, useId, useState } from \"react\"\nimport { mergeProps } from \"../../core\"\nimport { useControllableState } from \"../../hooks/use-controllable-state\"\nimport { createDescendants } from \"../../hooks/use-descendants\"\nimport { cx, filterUndefined, handlerAll, runKeyAction } from \"../../utils\"\nimport { useFieldProps } from \"../field\"\n\nconst {\n DescendantsContext: PinInputDescendantsContext,\n useDescendant: usePinInputDescendant,\n useDescendants: usePinInputDescendants,\n} = createDescendants<HTMLInputElement>()\n\nexport {\n PinInputDescendantsContext,\n usePinInputDescendant,\n usePinInputDescendants,\n}\n\nconst toArray = (value?: string) => value?.split(\"\")\n\nconst validate = (value: string, type: UsePinInputProps[\"type\"]) => {\n const NUMERIC_REGEX = /^[0-9]+$/\n const ALPHA_NUMERIC_REGEX = /^[a-zA-Z0-9]+$/i\n\n const regex = type === \"alphanumeric\" ? ALPHA_NUMERIC_REGEX : NUMERIC_REGEX\n\n return regex.test(value)\n}\n\nexport interface UsePinInputProps\n extends\n Omit<HTMLProps, \"defaultValue\" | \"mask\" | \"onChange\" | \"value\">,\n FieldProps {\n /**\n * If `true`, the pin input receives focus on mount.\n *\n * @default false\n */\n autoFocus?: boolean\n /**\n * The initial value of the pin input.\n */\n defaultValue?: string\n /**\n * The top-level id string that will be applied to the input fields.\n * The index of the input will be appended to this top-level id.\n */\n id?: string\n /**\n * The number of inputs to display.\n *\n * @default 4\n */\n items?: number\n /**\n * If `true`, focus will move automatically to the next input once filled.\n *\n * @default true\n */\n manageFocus?: boolean\n /**\n * If `true`, the input's value will be masked just like `type=password`.\n */\n mask?: boolean\n /**\n * If `true`, the pin input component signals to its fields that they should.\n */\n otp?: boolean\n /**\n * The placeholder for the pin input.\n *\n * @default '◯'\n */\n placeholder?: string\n /**\n * The type of values the pin-input should allow.\n *\n * @default 'number'\n */\n type?: \"alphanumeric\" | \"number\"\n /**\n * The value of the pin input.\n */\n value?: string\n /**\n * Function called on input change.\n */\n onChange?: (value: string) => void\n /**\n * Function called when all inputs have valid values.\n */\n onComplete?: (value: string) => void\n}\n\nexport const usePinInput = (props: UsePinInputProps = {}) => {\n const uuid = useId()\n const {\n context: { labelId } = {},\n props: {\n id = uuid,\n type = \"number\",\n autoFocus,\n defaultValue,\n disabled,\n items = 4,\n manageFocus = true,\n mask,\n otp = false,\n placeholder = \"◯\",\n readOnly,\n value,\n onChange: onChangeProp,\n onComplete,\n ...rest\n },\n ariaProps,\n dataProps,\n eventProps,\n } = useFieldProps(props)\n const descendants = usePinInputDescendants()\n const [moveFocus, setMoveFocus] = useState<boolean>(true)\n const [focusedIndex, setFocusedIndex] = useState<number>(-1)\n const [values, setValues] = useControllableState<string[]>({\n defaultValue: toArray(defaultValue) || [],\n value: toArray(value),\n onChange: (values) => onChangeProp?.(values.join(\"\")),\n })\n\n const focusNext = useCallback(\n (index: number) => {\n if (!moveFocus || !manageFocus) return\n\n const next = descendants.nextValue(index, false)\n\n if (!next) return\n\n requestAnimationFrame(() => next.node.focus())\n },\n [descendants, moveFocus, manageFocus],\n )\n\n const focusInputField = useCallback(\n (direction: \"next\" | \"prev\", index: number) => {\n const input =\n direction === \"next\"\n ? descendants.nextValue(index, false)\n : descendants.prevValue(index, false)\n\n if (!input) return\n\n const valueLength = input.node.value.length\n\n requestAnimationFrame(() => {\n input.node.focus()\n input.node.setSelectionRange(0, valueLength)\n })\n },\n [descendants],\n )\n\n const setValue = useCallback(\n (value: string, index: number, focus = true) => {\n let nextValues = [...values]\n\n nextValues[index] = value\n\n setValues(nextValues)\n\n nextValues = nextValues.filter(Boolean)\n\n const complete = value !== \"\" && nextValues.length === descendants.count()\n\n if (complete) {\n onComplete?.(nextValues.join(\"\"))\n descendants.value(index)?.node.blur()\n } else if (focus) {\n focusNext(index)\n }\n },\n [values, setValues, descendants, onComplete, focusNext],\n )\n\n const getNextValue = useCallback(\n (value: string | undefined, eventValue: string) => {\n let nextValue = eventValue\n\n if (!value?.length) return nextValue\n\n if (value.startsWith(eventValue.charAt(0)))\n nextValue = eventValue.charAt(1)\n else if (value.startsWith(eventValue.charAt(1)))\n nextValue = eventValue.charAt(0)\n\n return nextValue\n },\n [],\n )\n\n const onChange = useCallback(\n (index: number) =>\n ({ target }: ChangeEvent<HTMLInputElement>) => {\n const eventValue = target.value\n const currentValue = values[index]\n const nextValue = getNextValue(currentValue, eventValue)\n\n if (nextValue === \"\") {\n setValue(\"\", index)\n\n return\n }\n\n if (eventValue.length > 2) {\n if (!validate(eventValue, type)) return\n\n const nextValue = eventValue\n .split(\"\")\n .filter((_, index) => index < descendants.count())\n\n setValues(nextValue)\n\n if (nextValue.length === descendants.count()) {\n onComplete?.(nextValue.join(\"\"))\n descendants.value(index)?.node.blur()\n }\n } else {\n if (validate(nextValue, type)) setValue(nextValue, index)\n\n setMoveFocus(true)\n }\n },\n [descendants, getNextValue, onComplete, setValue, setValues, type, values],\n )\n\n const onKeyDown = useCallback(\n (index: number) => (ev: KeyboardEvent<HTMLInputElement>) => {\n if (!manageFocus) return\n\n runKeyAction(\n ev,\n {\n ArrowLeft: (ev) => {\n ev.preventDefault()\n focusInputField(\"prev\", index)\n },\n ArrowRight: (ev) => {\n ev.preventDefault()\n focusInputField(\"next\", index)\n },\n Backspace: (ev) => {\n if ((ev.target as HTMLInputElement).value === \"\") {\n const prevInput = descendants.prevValue(index, false)\n\n if (!prevInput) return\n\n setValue(\"\", index - 1, false)\n prevInput.node.focus()\n setMoveFocus(true)\n } else {\n setMoveFocus(false)\n }\n },\n },\n { preventDefault: false },\n )\n },\n [descendants, focusInputField, manageFocus, setValue],\n )\n\n const onFocus = useCallback(\n (index: number) => () => setFocusedIndex(index),\n [],\n )\n\n const onBlur = useCallback(() => setFocusedIndex(-1), [])\n\n useEffect(() => {\n if (!autoFocus) return\n\n const firstValue = descendants.firstValue()\n\n if (!firstValue) return\n\n requestAnimationFrame(() => firstValue.node.focus())\n }, [autoFocus, descendants])\n\n const getRootProps: PropGetter = useCallback(\n (props) => mergeProps({ role: \"group\" }, rest, props)(),\n [rest],\n )\n\n const getInputProps: RequiredPropGetter<\"input\", { index: number }> =\n useCallback(\n ({ \"aria-labelledby\": ariaLabelledby, index, ...props }) => ({\n ...ariaProps,\n ...dataProps,\n type: mask ? \"password\" : type === \"number\" ? \"tel\" : \"text\",\n \"aria-labelledby\": cx(ariaLabelledby, labelId),\n autoComplete: otp ? \"one-time-code\" : \"off\",\n disabled,\n inputMode: type === \"number\" ? \"numeric\" : \"text\",\n placeholder:\n focusedIndex === index && !readOnly && !props.readOnly\n ? \"\"\n : placeholder,\n readOnly,\n value: values[index] || \"\",\n ...filterUndefined(props),\n id: `${id}${index ? `-${index}` : \"\"}`,\n onBlur: handlerAll(eventProps.onBlur, props.onBlur, onBlur),\n onChange: handlerAll(props.onChange, onChange(index)),\n onFocus: handlerAll(eventProps.onFocus, props.onFocus, onFocus(index)),\n onKeyDown: handlerAll(props.onKeyDown, onKeyDown(index)),\n }),\n [\n ariaProps,\n dataProps,\n eventProps,\n mask,\n type,\n labelId,\n otp,\n disabled,\n focusedIndex,\n readOnly,\n placeholder,\n values,\n id,\n onBlur,\n onChange,\n onFocus,\n onKeyDown,\n ],\n )\n\n return {\n descendants,\n items,\n getInputProps,\n getRootProps,\n }\n}\n\nexport type UsePinInputReturn = ReturnType<typeof usePinInput>\n"],"mappings":";;;;;;;;;AAYA,MAAM,EACJ,oBAAoB,4BACpB,eAAe,uBACf,gBAAgB,2BACdA,oCAAAA,kBAAoC;AAQxC,MAAM,WAAW,UAAmB,OAAO,MAAM,EAAE;AAEnD,MAAM,YAAY,OAAe,SAAmC;CAMlE,QAFc,SAAS,iBAAiB,oBAAsB,WAAA,CAEjD,KAAK,KAAK;AACzB;AAmEA,MAAa,eAAe,QAA0B,CAAC,MAAM;CAC3D,MAAM,QAAA,GAAOC,MAAAA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a;GAC3D,GAAG;GACH,GAAG;GACH,MAAM,OAAO,aAAa,SAAS,WAAW,QAAQ;GACtD,oBAAA,GAAA,oBAAA,cAAmB,GAAA,CAAG,gBAAgB,OAAO;GAC7C,cAAc,MAAM,kBAAkB;GACtC;GACA,WAAW,SAAS,WAAW,YAAY;GAC3C,aACE,iBAAiB,SAAS,CAAC,YAAY,CAAC,MAAM,WAC1C,KACA;GACN;GACA,OAAO,OAAO,UAAU;GACxB,IAAA,GAAA,oBAAA,cAAG,gBAAA,CAAgB,KAAK;GACxB,IAAI,GAAG,KAAK,QAAQ,IAAI,UAAU;GAClC,SAAA,GAAA,oBAAA,cAAQ,WAAA,CAAW,WAAW,QAAQ,MAAM,QAAQ,MAAM;GAC1D,WAAA,GAAA,oBAAA,cAAU,WAAA,CAAW,MAAM,UAAU,SAAS,KAAK,CAAC;GACpD,UAAA,GAAA,oBAAA,cAAS,WAAA,CAAW,WAAW,SAAS,MAAM,SAAS,QAAQ,KAAK,CAAC;GACrE,YAAA,GAAA,oBAAA,cAAW,WAAA,CAAW,MAAM,WAAW,UAAU,KAAK,CAAC;EACzD,IACA;GACE;GACA;GACA;GACA;GACA;GACA;GACA;GACA;GACA;GACA;GACA;GACA;GACA;GACA;GACA;GACA;GACA;EACF,CAMU;EACZ;CACF;AACF"}
1
+ {"version":3,"file":"use-pin-input.cjs","names":["createDescendants","useId","useFieldProps","useState","useControllableState","useCallback","mergeProps"],"sources":["../../../../src/components/pin-input/use-pin-input.ts"],"sourcesContent":["\"use client\"\n\nimport type { ChangeEvent, KeyboardEvent } from \"react\"\nimport type { HTMLProps, PropGetter, RequiredPropGetter } from \"../../core\"\nimport type { FieldProps } from \"../field\"\nimport { useCallback, useEffect, useId, useState } from \"react\"\nimport { mergeProps } from \"../../core\"\nimport { useControllableState } from \"../../hooks/use-controllable-state\"\nimport { createDescendants } from \"../../hooks/use-descendants\"\nimport { filterUndefined, runKeyAction } from \"../../utils\"\nimport { useFieldProps } from \"../field\"\n\nconst {\n DescendantsContext: PinInputDescendantsContext,\n useDescendant: usePinInputDescendant,\n useDescendants: usePinInputDescendants,\n} = createDescendants<HTMLInputElement>()\n\nexport {\n PinInputDescendantsContext,\n usePinInputDescendant,\n usePinInputDescendants,\n}\n\nconst toArray = (value?: string) => value?.split(\"\")\n\nconst validate = (value: string, type: UsePinInputProps[\"type\"]) => {\n const NUMERIC_REGEX = /^[0-9]+$/\n const ALPHA_NUMERIC_REGEX = /^[a-zA-Z0-9]+$/i\n\n const regex = type === \"alphanumeric\" ? ALPHA_NUMERIC_REGEX : NUMERIC_REGEX\n\n return regex.test(value)\n}\n\nexport interface UsePinInputProps\n extends\n Omit<HTMLProps, \"defaultValue\" | \"mask\" | \"onChange\" | \"value\">,\n FieldProps {\n /**\n * If `true`, the pin input receives focus on mount.\n *\n * @default false\n */\n autoFocus?: boolean\n /**\n * The initial value of the pin input.\n */\n defaultValue?: string\n /**\n * The top-level id string that will be applied to the input fields.\n * The index of the input will be appended to this top-level id.\n */\n id?: string\n /**\n * The number of inputs to display.\n *\n * @default 4\n */\n items?: number\n /**\n * If `true`, focus will move automatically to the next input once filled.\n *\n * @default true\n */\n manageFocus?: boolean\n /**\n * If `true`, the input's value will be masked just like `type=password`.\n */\n mask?: boolean\n /**\n * If `true`, the pin input component signals to its fields that they should.\n */\n otp?: boolean\n /**\n * The placeholder for the pin input.\n *\n * @default '◯'\n */\n placeholder?: string\n /**\n * The type of values the pin-input should allow.\n *\n * @default 'number'\n */\n type?: \"alphanumeric\" | \"number\"\n /**\n * The value of the pin input.\n */\n value?: string\n /**\n * Function called on input change.\n */\n onChange?: (value: string) => void\n /**\n * Function called when all inputs have valid values.\n */\n onComplete?: (value: string) => void\n}\n\nexport const usePinInput = (props: UsePinInputProps = {}) => {\n const uuid = useId()\n const {\n context: { labelId } = {},\n props: {\n id = uuid,\n type = \"number\",\n autoFocus,\n defaultValue,\n disabled,\n items = 4,\n manageFocus = true,\n mask,\n otp = false,\n placeholder = \"◯\",\n readOnly,\n value,\n onChange: onChangeProp,\n onComplete,\n ...rest\n },\n ariaProps,\n dataProps,\n eventProps,\n } = useFieldProps(props)\n const descendants = usePinInputDescendants()\n const [moveFocus, setMoveFocus] = useState<boolean>(true)\n const [focusedIndex, setFocusedIndex] = useState<number>(-1)\n const [values, setValues] = useControllableState<string[]>({\n defaultValue: toArray(defaultValue) || [],\n value: toArray(value),\n onChange: (values) => onChangeProp?.(values.join(\"\")),\n })\n\n const focusNext = useCallback(\n (index: number) => {\n if (!moveFocus || !manageFocus) return\n\n const next = descendants.nextValue(index, false)\n\n if (!next) return\n\n requestAnimationFrame(() => next.node.focus())\n },\n [descendants, moveFocus, manageFocus],\n )\n\n const focusInputField = useCallback(\n (direction: \"next\" | \"prev\", index: number) => {\n const input =\n direction === \"next\"\n ? descendants.nextValue(index, false)\n : descendants.prevValue(index, false)\n\n if (!input) return\n\n const valueLength = input.node.value.length\n\n requestAnimationFrame(() => {\n input.node.focus()\n input.node.setSelectionRange(0, valueLength)\n })\n },\n [descendants],\n )\n\n const setValue = useCallback(\n (value: string, index: number, focus = true) => {\n let nextValues = [...values]\n\n nextValues[index] = value\n\n setValues(nextValues)\n\n nextValues = nextValues.filter(Boolean)\n\n const complete = value !== \"\" && nextValues.length === descendants.count()\n\n if (complete) {\n onComplete?.(nextValues.join(\"\"))\n descendants.value(index)?.node.blur()\n } else if (focus) {\n focusNext(index)\n }\n },\n [values, setValues, descendants, onComplete, focusNext],\n )\n\n const getNextValue = useCallback(\n (value: string | undefined, eventValue: string) => {\n let nextValue = eventValue\n\n if (!value?.length) return nextValue\n\n if (value.startsWith(eventValue.charAt(0)))\n nextValue = eventValue.charAt(1)\n else if (value.startsWith(eventValue.charAt(1)))\n nextValue = eventValue.charAt(0)\n\n return nextValue\n },\n [],\n )\n\n const onChange = useCallback(\n (index: number) =>\n ({ target }: ChangeEvent<HTMLInputElement>) => {\n const eventValue = target.value\n const currentValue = values[index]\n const nextValue = getNextValue(currentValue, eventValue)\n\n if (nextValue === \"\") {\n setValue(\"\", index)\n\n return\n }\n\n if (eventValue.length > 2) {\n if (!validate(eventValue, type)) return\n\n const nextValue = eventValue\n .split(\"\")\n .filter((_, index) => index < descendants.count())\n\n setValues(nextValue)\n\n if (nextValue.length === descendants.count()) {\n onComplete?.(nextValue.join(\"\"))\n descendants.value(index)?.node.blur()\n }\n } else {\n if (validate(nextValue, type)) setValue(nextValue, index)\n\n setMoveFocus(true)\n }\n },\n [descendants, getNextValue, onComplete, setValue, setValues, type, values],\n )\n\n const onKeyDown = useCallback(\n (index: number) => (ev: KeyboardEvent<HTMLInputElement>) => {\n if (!manageFocus) return\n\n runKeyAction(\n ev,\n {\n ArrowLeft: (ev) => {\n ev.preventDefault()\n focusInputField(\"prev\", index)\n },\n ArrowRight: (ev) => {\n ev.preventDefault()\n focusInputField(\"next\", index)\n },\n Backspace: (ev) => {\n if ((ev.target as HTMLInputElement).value === \"\") {\n const prevInput = descendants.prevValue(index, false)\n\n if (!prevInput) return\n\n setValue(\"\", index - 1, false)\n prevInput.node.focus()\n setMoveFocus(true)\n } else {\n setMoveFocus(false)\n }\n },\n },\n { preventDefault: false },\n )\n },\n [descendants, focusInputField, manageFocus, setValue],\n )\n\n const onFocus = useCallback(\n (index: number) => () => setFocusedIndex(index),\n [],\n )\n\n const onBlur = useCallback(() => setFocusedIndex(-1), [])\n\n useEffect(() => {\n if (!autoFocus) return\n\n const firstValue = descendants.firstValue()\n\n if (!firstValue) return\n\n requestAnimationFrame(() => firstValue.node.focus())\n }, [autoFocus, descendants])\n\n const getRootProps: PropGetter = useCallback(\n (props) => mergeProps({ role: \"group\" }, rest, props)(),\n [rest],\n )\n\n const getInputProps: RequiredPropGetter<\"input\", { index: number }> =\n useCallback(\n ({ index, ...props }) =>\n mergeProps(\n {\n ...ariaProps,\n ...dataProps,\n ...eventProps,\n type: mask ? \"password\" : type === \"number\" ? \"tel\" : \"text\",\n \"aria-labelledby\": labelId,\n autoComplete: otp ? \"one-time-code\" : \"off\",\n disabled,\n inputMode: type === \"number\" ? \"numeric\" : \"text\",\n placeholder:\n focusedIndex === index && !readOnly && !props.readOnly\n ? \"\"\n : placeholder,\n readOnly,\n value: values[index] || \"\",\n },\n filterUndefined(props),\n {\n id: `${id}${index ? `-${index}` : \"\"}`,\n onBlur,\n onChange: onChange(index),\n onFocus: onFocus(index),\n onKeyDown: onKeyDown(index),\n },\n )(),\n [\n ariaProps,\n dataProps,\n eventProps,\n mask,\n type,\n labelId,\n otp,\n disabled,\n focusedIndex,\n readOnly,\n placeholder,\n values,\n id,\n onBlur,\n onChange,\n onFocus,\n onKeyDown,\n ],\n )\n\n return {\n descendants,\n items,\n getInputProps,\n getRootProps,\n }\n}\n\nexport type UsePinInputReturn = ReturnType<typeof usePinInput>\n"],"mappings":";;;;;;;;;AAYA,MAAM,EACJ,oBAAoB,4BACpB,eAAe,uBACf,gBAAgB,2BACdA,oCAAAA,kBAAoC;AAQxC,MAAM,WAAW,UAAmB,OAAO,MAAM,EAAE;AAEnD,MAAM,YAAY,OAAe,SAAmC;CAMlE,QAFc,SAAS,iBAAiB,oBAAsB,WAAA,CAEjD,KAAK,KAAK;AACzB;AAmEA,MAAa,eAAe,QAA0B,CAAC,MAAM;CAC3D,MAAM,QAAA,GAAOC,MAAAA,MAAAA,CAAM;CACnB,MAAM,EACJ,SAAS,EAAE,YAAY,CAAC,GACxB,OAAO,EACL,KAAK,MACL,OAAO,UACP,WACA,cACA,UACA,QAAQ,GACR,cAAc,MACd,MACA,MAAM,OACN,cAAc,KACd,UACA,OACA,UAAU,cACV,YACA,GAAG,QAEL,WACA,WACA,eACEC,wBAAAA,cAAc,KAAK;CACvB,MAAM,cAAc,uBAAuB;CAC3C,MAAM,CAAC,WAAW,iBAAA,GAAgBC,MAAAA,SAAAA,CAAkB,IAAI;CACxD,MAAM,CAAC,cAAc,oBAAA,GAAmBA,MAAAA,SAAAA,CAAiB,EAAE;CAC3D,MAAM,CAAC,QAAQ,aAAaC,2CAAAA,qBAA+B;E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ACE;GACA;GACA;GACA;GACA;GACA;GACA;GACA;GACA;GACA;GACA;GACA;GACA;GACA;GACA;GACA;GACA;EACF,CAMU;EACZ;CACF;AACF"}
@@ -13,7 +13,7 @@ const [RadioGroupContext, useRadioGroupContext] = require_context.createContext(
13
13
  });
14
14
  const useRadioGroup = (props = {}) => {
15
15
  const uuid = (0, react.useId)();
16
- const { context: { labelId } = {}, props: { id = uuid, defaultValue, disabled, readOnly, required, value: valueProp, onChange: onChangeProp, ...rest }, ariaProps: { "aria-describedby": ariaDescribedbyProp, ...ariaProps }, dataProps, eventProps } = require_use_field_props.useFieldProps(props);
16
+ const { context: { labelId } = {}, props: { id = uuid, defaultValue, disabled, readOnly, required, value: valueProp, onChange: onChangeProp, ...rest }, ariaProps: { "aria-describedby": ariaDescribedby, ...ariaProps }, dataProps, eventProps } = require_use_field_props.useFieldProps(props);
17
17
  const interactive = !(readOnly || disabled);
18
18
  const [value, setValue] = require_hooks_use_controllable_state_index.useControllableState({
19
19
  defaultValue,
@@ -25,13 +25,13 @@ const useRadioGroup = (props = {}) => {
25
25
  if ((0, require_utils_index.utils_exports.isObject)(valueOrEv)) setValue(valueOrEv.target.value);
26
26
  else setValue(valueOrEv);
27
27
  }, [interactive, setValue]);
28
- const getRootProps = (0, react.useCallback)(({ ref, "aria-describedby": ariaDescribedby, "aria-labelledby": ariaLabelledby, ...props } = {}) => require_props.mergeProps(dataProps, {
28
+ const getRootProps = (0, react.useCallback)((props = {}) => require_props.mergeProps(dataProps, {
29
29
  id,
30
- "aria-describedby": (0, require_utils_index.utils_exports.cx)(ariaDescribedbyProp, ariaDescribedby),
31
- "aria-labelledby": (0, require_utils_index.utils_exports.cx)(labelId, ariaLabelledby),
30
+ "aria-describedby": ariaDescribedby,
31
+ "aria-labelledby": labelId,
32
32
  role: "radiogroup"
33
- }, { ref }, rest, props)(), [
34
- ariaDescribedbyProp,
33
+ }, rest, props)(), [
34
+ ariaDescribedby,
35
35
  dataProps,
36
36
  id,
37
37
  labelId,
@@ -42,7 +42,7 @@ const useRadioGroup = (props = {}) => {
42
42
  value,
43
43
  getInputProps: (0, react.useCallback)((props = {}) => {
44
44
  const checked = !(0, require_utils_index.utils_exports.isUndefined)(value) && value === props.value;
45
- return {
45
+ return require_props.mergeProps({
46
46
  ...dataProps,
47
47
  ...ariaProps,
48
48
  type: "radio",
@@ -53,12 +53,11 @@ const useRadioGroup = (props = {}) => {
53
53
  checked,
54
54
  disabled,
55
55
  readOnly,
56
- required,
57
- ...props,
58
- onBlur: (0, require_utils_index.utils_exports.handlerAll)(props.onBlur, eventProps.onBlur),
59
- onChange: (0, require_utils_index.utils_exports.handlerAll)(props.onChange, onChange),
60
- onFocus: (0, require_utils_index.utils_exports.handlerAll)(props.onFocus, eventProps.onFocus)
61
- };
56
+ required
57
+ }, props, {
58
+ onChange,
59
+ ...eventProps
60
+ })();
62
61
  }, [
63
62
  ariaProps,
64
63
  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 cx,\n dataAttr,\n handlerAll,\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\": ariaDescribedbyProp, ...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)) setValue(valueOrEv.target.value as Y)\n else setValue(valueOrEv)\n },\n [interactive, setValue],\n )\n\n const getRootProps: PropGetter = useCallback(\n ({\n ref,\n \"aria-describedby\": ariaDescribedby,\n \"aria-labelledby\": ariaLabelledby,\n ...props\n } = {}) =>\n mergeProps(\n dataProps,\n {\n id,\n \"aria-describedby\": cx(ariaDescribedbyProp, ariaDescribedby),\n \"aria-labelledby\": cx(labelId, ariaLabelledby),\n role: \"radiogroup\",\n },\n { ref },\n rest,\n props,\n )(),\n [ariaDescribedbyProp, 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 {\n ...dataProps,\n ...ariaProps,\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 ...props,\n onBlur: handlerAll(props.onBlur, eventProps.onBlur),\n onChange: handlerAll(props.onChange, onChange),\n onFocus: handlerAll(props.onFocus, eventProps.onFocus),\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":";;;;;;;;;AAqBA,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,qBAAqB,GAAG,aACzD,WACA,eACEC,wBAAAA,cAAc,KAAK;CACvB,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,EACC,KACA,oBAAoB,iBACpB,mBAAmB,gBACnB,GAAG,UACD,CAAC,MACHC,cAAAA,WACE,WACA;EACE;EACA,qBAAA,GAAA,oBAAA,cAAoB,GAAA,CAAG,qBAAqB,eAAe;EAC3D,oBAAA,GAAA,oBAAA,cAAmB,GAAA,CAAG,SAAS,cAAc;EAC7C,MAAM;CACR,GACA,EAAE,IAAI,GACN,MACA,KACF,CAAC,CAAC,GACJ;EAAC;EAAqB;EAAW;EAAI;EAAS;CAAI,CACpD;CA6CA,OAAO;EACL,MAAM;EACN;EACA,gBAAA,GA9CyCD,MAAAA,YAAAA,EACxC,QAAQ,CAAC,MAAM;GACd,MAAM,UAAU,EAAA,GAAA,oBAAA,cAAC,YAAA,CAAY,KAAK,KAAK,UAAU,MAAM;GAEvD,OAAO;IACL,GAAG;IACH,GAAG;IACH,MAAM;IACN,MAAM;IACN,OAAOE,YAAAA,yBAAyB;IAChC,gBAAgB;IAChB,iBAAA,GAAA,oBAAA,cAAgB,SAAA,CAAS,OAAO;IAChC;IACA;IACA;IACA;IACA,GAAG;IACH,SAAA,GAAA,oBAAA,cAAQ,WAAA,CAAW,MAAM,QAAQ,WAAW,MAAM;IAClD,WAAA,GAAA,oBAAA,cAAU,WAAA,CAAW,MAAM,UAAU,QAAQ;IAC7C,UAAA,GAAA,oBAAA,cAAS,WAAA,CAAW,MAAM,SAAS,WAAW,OAAO;GACvD;EACF,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"}
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(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)) 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 {\n ...dataProps,\n ...ariaProps,\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 { onChange, ...eventProps },\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,KAAK;CACvB,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;CA6CA,OAAO;EACL,MAAM;EACN;EACA,gBAAA,GA9CyCD,MAAAA,YAAAA,EACxC,QAAQ,CAAC,MAAM;GACd,MAAM,UAAU,EAAA,GAAA,oBAAA,cAAC,YAAA,CAAY,KAAK,KAAK,UAAU,MAAM;GAEvD,OAAOC,cAAAA,WACL;IACE,GAAG;IACH,GAAG;IACH,MAAM;IACN,MAAM;IACN,OAAOC,YAAAA,yBAAyB;IAChC,gBAAgB;IAChB,iBAAA,GAAA,oBAAA,cAAgB,SAAA,CAAS,OAAO;IAChC;IACA;IACA;IACA;GACF,GACA,OACA;IAAE;IAAU,GAAG;GAAW,CAC5B,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"}
@@ -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_utils_index = require("../../utils/index.cjs");
5
4
  const require_props = require("../../core/components/props.cjs");
6
5
  const require_hooks_use_controllable_state_index = require("../../hooks/use-controllable-state/index.cjs");
@@ -12,7 +11,7 @@ const useRadio = ({ "aria-describedby": ariaDescribedbyProp, ...props } = {}) =>
12
11
  const group = require_use_radio_group.useRadioGroupContext();
13
12
  const { name: groupName, value: groupValue, getInputProps: getGroupInputProps, getLabelProps } = group ?? {};
14
13
  const uuid = (0, react.useId)();
15
- const { props: { id, ref, name = groupName, "aria-controls": ariaControlsProp, "aria-labelledby": ariaLabelledbyProp, checked: checkedProp, defaultChecked = false, disabled, readOnly, required, tabIndex, value, onChange: onChangeProp, ...rest }, ariaProps: { "aria-describedby": ariaDescribedby, ...ariaProps }, dataProps, eventProps } = require_use_field_props.useFieldProps({
14
+ const { props: { id, ref, name = groupName, "aria-controls": ariaControls, "aria-labelledby": ariaLabelledby, checked: checkedProp, defaultChecked = false, disabled, readOnly, required, tabIndex, value, onChange: onChangeProp, ...rest }, ariaProps: { "aria-describedby": ariaDescribedby, ...ariaProps }, dataProps, eventProps } = require_use_field_props.useFieldProps({
16
15
  id: group ? uuid : void 0,
17
16
  ...props,
18
17
  notSupportReadOnly: true
@@ -38,31 +37,30 @@ const useRadio = ({ "aria-describedby": ariaDescribedbyProp, ...props } = {}) =>
38
37
  checked,
39
38
  rest
40
39
  ]);
41
- const getInputProps = (0, react.useCallback)(({ "aria-controls": ariaControls, "aria-describedby": ariaDescribedby, "aria-labelledby": ariaLabelledby, ...props } = {}) => {
42
- const sharedProps = {
40
+ const getInputProps = (0, react.useCallback)((props = {}) => {
41
+ const sharedProps = require_props.mergeProps({
43
42
  ...dataProps,
44
43
  ...ariaProps,
45
44
  id,
45
+ ref,
46
46
  type: "radio",
47
47
  name,
48
48
  style: require_dom.visuallyHiddenAttributes.style,
49
49
  "aria-checked": checked,
50
- "aria-controls": (0, require_utils_index.utils_exports.cx)(ariaControls, ariaControlsProp),
51
- "aria-describedby": (0, require_utils_index.utils_exports.cx)(resolvedAriaDescribedby, ariaDescribedby),
52
- "aria-labelledby": (0, require_utils_index.utils_exports.cx)(ariaLabelledby, ariaLabelledbyProp),
50
+ "aria-controls": ariaControls,
51
+ "aria-describedby": resolvedAriaDescribedby,
52
+ "aria-labelledby": ariaLabelledby,
53
53
  "data-checked": (0, require_utils_index.utils_exports.dataAttr)(checked),
54
54
  checked,
55
55
  disabled,
56
56
  readOnly,
57
57
  required,
58
58
  tabIndex,
59
- value,
60
- ...props,
61
- ref: require_ref.mergeRefs(props.ref, ref),
62
- onBlur: (0, require_utils_index.utils_exports.handlerAll)(props.onBlur, eventProps.onBlur),
63
- onChange: (0, require_utils_index.utils_exports.handlerAll)(props.onChange, onChange),
64
- onFocus: (0, require_utils_index.utils_exports.handlerAll)(props.onFocus, eventProps.onFocus)
65
- };
59
+ value
60
+ }, props, {
61
+ ...eventProps,
62
+ onChange
63
+ })();
66
64
  return getGroupInputProps?.(sharedProps) ?? sharedProps;
67
65
  }, [
68
66
  dataProps,
@@ -70,17 +68,16 @@ const useRadio = ({ "aria-describedby": ariaDescribedbyProp, ...props } = {}) =>
70
68
  id,
71
69
  name,
72
70
  checked,
73
- ariaControlsProp,
71
+ ariaControls,
74
72
  resolvedAriaDescribedby,
75
- ariaLabelledbyProp,
73
+ ariaLabelledby,
76
74
  disabled,
77
75
  readOnly,
78
76
  required,
79
77
  tabIndex,
80
78
  value,
81
79
  ref,
82
- eventProps.onBlur,
83
- eventProps.onFocus,
80
+ eventProps,
84
81
  onChange,
85
82
  getGroupInputProps
86
83
  ]);
@@ -1 +1 @@
1
- {"version":3,"file":"use-radio.cjs","names":["useRadioGroupContext","useId","useFieldProps","useControllableEventState","useCallback","mergeProps","visuallyHiddenAttributes","mergeRefs"],"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 {\n cx,\n dataAttr,\n handlerAll,\n isUndefined,\n mergeRefs,\n visuallyHiddenAttributes,\n} 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\": ariaControlsProp,\n \"aria-labelledby\": ariaLabelledbyProp,\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 ({\n \"aria-controls\": ariaControls,\n \"aria-describedby\": ariaDescribedby,\n \"aria-labelledby\": ariaLabelledby,\n ...props\n } = {}) => {\n const sharedProps = {\n ...dataProps,\n ...ariaProps,\n id,\n type: \"radio\",\n name,\n style: visuallyHiddenAttributes.style,\n \"aria-checked\": checked,\n \"aria-controls\": cx(ariaControls, ariaControlsProp),\n \"aria-describedby\": cx(resolvedAriaDescribedby, ariaDescribedby),\n \"aria-labelledby\": cx(ariaLabelledby, ariaLabelledbyProp),\n \"data-checked\": dataAttr(checked),\n checked,\n disabled,\n readOnly,\n required,\n tabIndex,\n value,\n ...props,\n ref: mergeRefs(props.ref, ref),\n onBlur: handlerAll(props.onBlur, eventProps.onBlur),\n onChange: handlerAll(props.onChange, onChange),\n onFocus: handlerAll(props.onFocus, eventProps.onFocus),\n }\n\n return getGroupInputProps?.(sharedProps) ?? sharedProps\n },\n [\n dataProps,\n ariaProps,\n id,\n name,\n checked,\n ariaControlsProp,\n resolvedAriaDescribedby,\n ariaLabelledbyProp,\n disabled,\n readOnly,\n required,\n tabIndex,\n value,\n ref,\n eventProps.onBlur,\n eventProps.onFocus,\n onChange,\n getGroupInputProps,\n ],\n )\n\n const getIndicatorProps: PropGetter = useCallback(\n (props = {}) => ({\n ...dataProps,\n \"aria-hidden\": \"true\",\n \"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":";;;;;;;;;;AA4DA,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,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;GAChB,kBAAA,GAAA,oBAAA,cAAiB,GAAA,CAAG,cAAc,gBAAgB;GAClD,qBAAA,GAAA,oBAAA,cAAoB,GAAA,CAAG,yBAAyB,eAAe;GAC/D,oBAAA,GAAA,oBAAA,cAAmB,GAAA,CAAG,gBAAgB,kBAAkB;GACxD,iBAAA,GAAA,oBAAA,cAAgB,SAAA,CAAS,OAAO;GAChC;GACA;GACA;GACA;GACA;GACA;GACA,GAAG;GACH,KAAKC,YAAAA,UAAU,MAAM,KAAK,GAAG;GAC7B,SAAA,GAAA,oBAAA,cAAQ,WAAA,CAAW,MAAM,QAAQ,WAAW,MAAM;GAClD,WAAA,GAAA,oBAAA,cAAU,WAAA,CAAW,MAAM,UAAU,QAAQ;GAC7C,UAAA,GAAA,oBAAA,cAAS,WAAA,CAAW,MAAM,SAAS,WAAW,OAAO;EACvD;EAEA,OAAO,qBAAqB,WAAW,KAAK;CAC9C,GACA;EACE;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA,WAAW;EACX,WAAW;EACX;EACA;CACF,CACF;CAYA,OAAO;EACL;EACA,oBAAA,GAZoCH,MAAAA,YAAAA,EACnC,QAAQ,CAAC,OAAO;GACf,GAAG;GACH,eAAe;GACf,iBAAA,GAAA,oBAAA,cAAgB,SAAA,CAAS,OAAO;GAChC,GAAG;EACL,IACA,CAAC,WAAW,OAAO,CAKH;EAChB;EACA;EACA;CACF;AACF"}
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 {\n ...dataProps,\n ...ariaProps,\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, 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 ...dataProps,\n \"aria-hidden\": \"true\",\n \"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;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H;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;GAAE,GAAG;GAAY;EAAS,CAC5B,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,OAAO;GACf,GAAG;GACH,eAAe;GACf,iBAAA,GAAA,oBAAA,cAAgB,SAAA,CAAS,OAAO;GAChC,GAAG;EACL,IACA,CAAC,WAAW,OAAO,CAKH;EAChB;EACA;EACA;CACF;AACF"}
@@ -170,10 +170,11 @@ const useSaturationSlider = (props = {}) => {
170
170
  value,
171
171
  getInputProps,
172
172
  getRootProps,
173
- getThumbProps: (0, react.useCallback)((props = {}) => ({
173
+ getThumbProps: (0, react.useCallback)((props = {}) => require_props.mergeProps({
174
174
  ...dataProps,
175
175
  ...ariaProps,
176
176
  "aria-label": t("Saturation and brightness thumb"),
177
+ "aria-labelledby": ariaLabelledBy,
177
178
  "aria-roledescription": "2D slider",
178
179
  "aria-valuemax": 100,
179
180
  "aria-valuemin": 0,
@@ -183,11 +184,8 @@ const useSaturationSlider = (props = {}) => {
183
184
  saturation: s * 100
184
185
  }),
185
186
  role: "slider",
186
- tabIndex: interactive ? 0 : -1,
187
- ...props,
188
- "aria-labelledby": (0, require_utils_index.utils_exports.cx)(props["aria-labelledby"], ariaLabelledBy),
189
- onKeyDown: (0, require_utils_index.utils_exports.handlerAll)(props.onKeyDown, onKeyDown)
190
- }), [
187
+ tabIndex: interactive ? 0 : -1
188
+ }, props, { onKeyDown })(), [
191
189
  ariaLabelledBy,
192
190
  ariaProps,
193
191
  ariaValueText,
@@ -1 +1 @@
1
- {"version":3,"file":"use-saturation-slider.cjs","names":["useFieldProps","useI18n","useControllableState","usePanEvent","useCallback","mergeProps","visuallyHiddenAttributes","mergeRefs"],"sources":["../../../../src/components/saturation-slider/use-saturation-slider.ts"],"sourcesContent":["\"use client\"\n\nimport type { KeyboardEvent } from \"react\"\nimport type { HTMLProps, HTMLRefAttributes, PropGetter } from \"../../core\"\nimport type { Point } from \"../../utils\"\nimport type { FieldProps } from \"../field\"\nimport { useCallback } from \"react\"\nimport { mergeProps } from \"../../core\"\nimport { useControllableState } from \"../../hooks/use-controllable-state\"\nimport { usePanEvent } from \"../../hooks/use-pan-event\"\nimport { useI18n } from \"../../providers/i18n-provider\"\nimport {\n clampNumber,\n cx,\n handlerAll,\n mergeRefs,\n roundNumberToStep,\n visuallyHiddenAttributes,\n} from \"../../utils\"\nimport { runKeyAction } from \"../../utils/dom\"\nimport { useFieldProps } from \"../field\"\n\nfunction clampValue(value: [number, number, number]) {\n return [\n clampNumber(value[0], 0, 360),\n clampNumber(value[1], 0, 1),\n clampNumber(value[2], 0, 1),\n ] as [number, number, number]\n}\n\nexport interface UseSaturationSliderProps\n extends\n Omit<HTMLProps, \"defaultValue\" | \"onChange\" | \"ref\">,\n HTMLRefAttributes<\"input\">,\n FieldProps {\n /**\n * The initial value of the saturation slider.\n *\n * @default [0, 0, 1]\n */\n defaultValue?: [number, number, number]\n /**\n * The base `id` to use for the slider.\n */\n id?: string\n /**\n * The name attribute of the hidden `input` field.\n * This is particularly useful in forms.\n */\n name?: string\n /**\n * The step in which increments or decrements have to be made.\n *\n * @default 0.01\n */\n step?: number\n /**\n * The value of the saturation slider.\n */\n value?: [number, number, number]\n /**\n * This is used to format the value so that screen readers\n * can speak out a more human-friendly value.\n *\n * It is used to set the `aria-valuetext` property of the input.\n */\n getAriaValueText?: (value: [number, number, number]) => string | undefined\n /**\n * Function called whenever the saturation slider value changes.\n */\n onChange?: (value: [number, number, number]) => void\n /**\n * Function called when the user is done selecting a new value.\n */\n onChangeEnd?: (value: [number, number, number]) => void\n /**\n * Function called when the user starts selecting a new value.\n */\n onChangeStart?: (value: [number, number, number]) => void\n}\n\nexport const useSaturationSlider = (props: UseSaturationSliderProps = {}) => {\n const {\n props: {\n id,\n ref,\n name,\n \"aria-labelledby\": ariaLabelledBy,\n \"aria-valuetext\": ariaValueText,\n defaultValue = [0, 0, 1],\n disabled,\n getAriaValueText,\n readOnly,\n required,\n step = 0.01,\n value: valueProp,\n onChange: onChangeProp,\n onChangeEnd,\n onChangeStart,\n ...rest\n },\n ariaProps,\n dataProps,\n eventProps,\n } = useFieldProps(props)\n const { t } = useI18n(\"saturationSlider\")\n const [value, setValue] = useControllableState({\n defaultValue,\n value: valueProp,\n onChange: onChangeProp,\n })\n const [h, s, v] = clampValue(value)\n const interactive = !(disabled || readOnly)\n const [_, getPanEventProps] = usePanEvent<HTMLDivElement>({\n onEnd: (_, point, rect) => {\n if (!interactive) return\n\n const panValue = getPanValue(point, rect)\n\n onChangeEnd?.(panValue)\n },\n onMove: (_, point, rect) => {\n if (!interactive) return\n\n const panValue = getPanValue(point, rect)\n\n setValue(panValue)\n },\n onStart: (_, point, rect) => {\n if (!interactive) return\n\n const panValue = getPanValue(point, rect)\n\n onChangeStart?.(value)\n setValue(panValue)\n },\n })\n\n const onChange = useCallback(\n ([h, s, v]: [number, number, number]) => {\n if (!interactive) return\n\n s = clampNumber(s, 0, 1)\n v = clampNumber(v, 0, 1)\n\n setValue([h, s, v])\n },\n [interactive, setValue],\n )\n\n const getPanValue = useCallback(\n (\n { x, y }: Point,\n { bottom, height, left, width }: DOMRect,\n ): [number, number, number] => {\n const diff = { x: x - left, y: bottom - y }\n const percent = { x: diff.x / width, y: diff.y / height }\n const clamp = {\n x: clampNumber(percent.x, 0, 1),\n y: clampNumber(percent.y, 0, 1),\n }\n const s = roundNumberToStep(clamp.x, 0, step)\n const v = roundNumberToStep(clamp.y, 0, step)\n\n return [h, parseFloat(s), parseFloat(v)]\n },\n [h, step],\n )\n\n const onKeyDown = useCallback(\n (ev: KeyboardEvent<HTMLDivElement>) => {\n runKeyAction(ev, {\n ArrowDown: () => onChange([h, s, v - step]),\n ArrowLeft: () => onChange([h, s - step, v]),\n ArrowRight: () => onChange([h, s + step, v]),\n ArrowUp: () => onChange([h, s, v + step]),\n })\n },\n [h, onChange, s, step, v],\n )\n\n const getRootProps: PropGetter = useCallback(\n (props = {}) => {\n const merged = mergeProps(dataProps, rest, props)()\n\n return {\n ...merged,\n style: {\n ...rest.style,\n ...props.style,\n \"--x\": `${Math.abs(s * 100)}%`,\n \"--y\": `${Math.abs(100 - v * 100)}%`,\n backgroundColor: `hsl(${h}, 100%, 50%)`,\n backgroundImage:\n \"linear-gradient(0deg, #000, transparent), linear-gradient(90deg, #fff, transparent)\",\n },\n onBlur: handlerAll(props.onBlur, eventProps.onBlur),\n onFocus: handlerAll(props.onFocus, eventProps.onFocus),\n }\n },\n [dataProps, eventProps, h, rest, s, v],\n )\n\n const getInputProps: PropGetter<\"input\"> = useCallback(\n (props = {}) => ({\n ...visuallyHiddenAttributes,\n ...dataProps,\n ...ariaProps,\n id,\n type: \"hidden\",\n name,\n disabled,\n readOnly,\n required,\n value: [h, s, v].toString(),\n ...props,\n ref: mergeRefs(props.ref, ref),\n }),\n [\n ariaProps,\n dataProps,\n disabled,\n h,\n id,\n name,\n readOnly,\n ref,\n required,\n s,\n v,\n ],\n )\n\n const getTrackProps: PropGetter = useCallback(\n (props = {}) => getPanEventProps({ ...dataProps, ...props }),\n [dataProps, getPanEventProps],\n )\n\n const getThumbProps: PropGetter = useCallback(\n (props = {}) => ({\n ...dataProps,\n ...ariaProps,\n \"aria-label\": t(\"Saturation and brightness thumb\"),\n \"aria-roledescription\": \"2D slider\",\n \"aria-valuemax\": 100,\n \"aria-valuemin\": 0,\n \"aria-valuenow\": s * 100,\n \"aria-valuetext\":\n ariaValueText ??\n getAriaValueText?.(value) ??\n t(\"Saturation {saturation}%, Brightness {brightness}%\", {\n brightness: v * 100,\n saturation: s * 100,\n }),\n role: \"slider\",\n tabIndex: interactive ? 0 : -1,\n ...props,\n \"aria-labelledby\": cx(props[\"aria-labelledby\"], ariaLabelledBy),\n onKeyDown: handlerAll(props.onKeyDown, onKeyDown),\n }),\n [\n ariaLabelledBy,\n ariaProps,\n ariaValueText,\n dataProps,\n getAriaValueText,\n interactive,\n onKeyDown,\n s,\n t,\n v,\n value,\n ],\n )\n\n return {\n setValue,\n value,\n getInputProps,\n getRootProps,\n getThumbProps,\n getTrackProps,\n onChange,\n }\n}\n\nexport type UseSaturationSliderReturn = ReturnType<typeof useSaturationSlider>\n"],"mappings":";;;;;;;;;;;AAsBA,SAAS,WAAW,OAAiC;CACnD,OAAO;GACL,GAAA,oBAAA,cAAA,YAAA,CAAY,MAAM,IAAI,GAAG,GAAG;GAC5B,GAAA,oBAAA,cAAA,YAAA,CAAY,MAAM,IAAI,GAAG,CAAC;GAC1B,GAAA,oBAAA,cAAA,YAAA,CAAY,MAAM,IAAI,GAAG,CAAC;CAC5B;AACF;AAqDA,MAAa,uBAAuB,QAAkC,CAAC,MAAM;CAC3E,MAAM,EACJ,OAAO,EACL,IACA,KACA,MACA,mBAAmB,gBACnB,kBAAkB,eAClB,eAAe;EAAC;EAAG;EAAG;CAAC,GACvB,UACA,kBACA,UACA,UACA,OAAO,KACP,OAAO,WACP,UAAU,cACV,aACA,eACA,GAAG,QAEL,WACA,WACA,eACEA,wBAAAA,cAAc,KAAK;CACvB,MAAM,EAAE,MAAMC,sBAAAA,QAAQ,kBAAkB;CACxC,MAAM,CAAC,OAAO,YAAYC,2CAAAA,qBAAqB;EAC7C;EACA,OAAO;EACP,UAAU;CACZ,CAAC;CACD,MAAM,CAAC,GAAG,GAAG,KAAK,WAAW,KAAK;CAClC,MAAM,cAAc,EAAE,YAAY;CAClC,MAAM,CAAC,GAAG,oBAAoBC,kCAAAA,YAA4B;EACxD,QAA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A;EACE;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;CACF,CACF;CAEA,MAAM,iBAAA,GAA4BH,MAAAA,YAAAA,EAC/B,QAAQ,CAAC,MAAM,iBAAiB;EAAE,GAAG;EAAW,GAAG;CAAM,CAAC,GAC3D,CAAC,WAAW,gBAAgB,CAC9B;CAuCA,OAAO;EACL;EACA;EACA;EACA;EACA,gBAAA,GA1CgCA,MAAAA,YAAAA,EAC/B,QAAQ,CAAC,OAAO;GACf,GAAG;GACH,GAAG;GACH,cAAc,EAAE,iCAAiC;GACjD,wBAAwB;GACxB,iBAAiB;GACjB,iBAAiB;GACjB,iBAAiB,IAAI;GACrB,kBACE,iBACA,mBAAmB,KAAK,KACxB,EAAE,sDAAsD;IACtD,YAAY,IAAI;IAChB,YAAY,IAAI;GAClB,CAAC;GACH,MAAM;GACN,UAAU,cAAc,IAAI;GAC5B,GAAG;GACH,oBAAA,GAAA,oBAAA,cAAmB,GAAA,CAAG,MAAM,oBAAoB,cAAc;GAC9D,YAAA,GAAA,oBAAA,cAAW,WAAA,CAAW,MAAM,WAAW,SAAS;EAClD,IACA;GACE;GACA;GACA;GACA;GACA;GACA;GACA;GACA;GACA;GACA;GACA;EACF,CAQY;EACZ;EACA;CACF;AACF"}
1
+ {"version":3,"file":"use-saturation-slider.cjs","names":["useFieldProps","useI18n","useControllableState","usePanEvent","useCallback","mergeProps","visuallyHiddenAttributes","mergeRefs"],"sources":["../../../../src/components/saturation-slider/use-saturation-slider.ts"],"sourcesContent":["\"use client\"\n\nimport type { KeyboardEvent } from \"react\"\nimport type { HTMLProps, HTMLRefAttributes, PropGetter } from \"../../core\"\nimport type { Point } from \"../../utils\"\nimport type { FieldProps } from \"../field\"\nimport { useCallback } from \"react\"\nimport { mergeProps } from \"../../core\"\nimport { useControllableState } from \"../../hooks/use-controllable-state\"\nimport { usePanEvent } from \"../../hooks/use-pan-event\"\nimport { useI18n } from \"../../providers/i18n-provider\"\nimport {\n clampNumber,\n handlerAll,\n mergeRefs,\n roundNumberToStep,\n visuallyHiddenAttributes,\n} from \"../../utils\"\nimport { runKeyAction } from \"../../utils/dom\"\nimport { useFieldProps } from \"../field\"\n\nfunction clampValue(value: [number, number, number]) {\n return [\n clampNumber(value[0], 0, 360),\n clampNumber(value[1], 0, 1),\n clampNumber(value[2], 0, 1),\n ] as [number, number, number]\n}\n\nexport interface UseSaturationSliderProps\n extends\n Omit<HTMLProps, \"defaultValue\" | \"onChange\" | \"ref\">,\n HTMLRefAttributes<\"input\">,\n FieldProps {\n /**\n * The initial value of the saturation slider.\n *\n * @default [0, 0, 1]\n */\n defaultValue?: [number, number, number]\n /**\n * The base `id` to use for the slider.\n */\n id?: string\n /**\n * The name attribute of the hidden `input` field.\n * This is particularly useful in forms.\n */\n name?: string\n /**\n * The step in which increments or decrements have to be made.\n *\n * @default 0.01\n */\n step?: number\n /**\n * The value of the saturation slider.\n */\n value?: [number, number, number]\n /**\n * This is used to format the value so that screen readers\n * can speak out a more human-friendly value.\n *\n * It is used to set the `aria-valuetext` property of the input.\n */\n getAriaValueText?: (value: [number, number, number]) => string | undefined\n /**\n * Function called whenever the saturation slider value changes.\n */\n onChange?: (value: [number, number, number]) => void\n /**\n * Function called when the user is done selecting a new value.\n */\n onChangeEnd?: (value: [number, number, number]) => void\n /**\n * Function called when the user starts selecting a new value.\n */\n onChangeStart?: (value: [number, number, number]) => void\n}\n\nexport const useSaturationSlider = (props: UseSaturationSliderProps = {}) => {\n const {\n props: {\n id,\n ref,\n name,\n \"aria-labelledby\": ariaLabelledBy,\n \"aria-valuetext\": ariaValueText,\n defaultValue = [0, 0, 1],\n disabled,\n getAriaValueText,\n readOnly,\n required,\n step = 0.01,\n value: valueProp,\n onChange: onChangeProp,\n onChangeEnd,\n onChangeStart,\n ...rest\n },\n ariaProps,\n dataProps,\n eventProps,\n } = useFieldProps(props)\n const { t } = useI18n(\"saturationSlider\")\n const [value, setValue] = useControllableState({\n defaultValue,\n value: valueProp,\n onChange: onChangeProp,\n })\n const [h, s, v] = clampValue(value)\n const interactive = !(disabled || readOnly)\n const [_, getPanEventProps] = usePanEvent<HTMLDivElement>({\n onEnd: (_, point, rect) => {\n if (!interactive) return\n\n const panValue = getPanValue(point, rect)\n\n onChangeEnd?.(panValue)\n },\n onMove: (_, point, rect) => {\n if (!interactive) return\n\n const panValue = getPanValue(point, rect)\n\n setValue(panValue)\n },\n onStart: (_, point, rect) => {\n if (!interactive) return\n\n const panValue = getPanValue(point, rect)\n\n onChangeStart?.(value)\n setValue(panValue)\n },\n })\n\n const onChange = useCallback(\n ([h, s, v]: [number, number, number]) => {\n if (!interactive) return\n\n s = clampNumber(s, 0, 1)\n v = clampNumber(v, 0, 1)\n\n setValue([h, s, v])\n },\n [interactive, setValue],\n )\n\n const getPanValue = useCallback(\n (\n { x, y }: Point,\n { bottom, height, left, width }: DOMRect,\n ): [number, number, number] => {\n const diff = { x: x - left, y: bottom - y }\n const percent = { x: diff.x / width, y: diff.y / height }\n const clamp = {\n x: clampNumber(percent.x, 0, 1),\n y: clampNumber(percent.y, 0, 1),\n }\n const s = roundNumberToStep(clamp.x, 0, step)\n const v = roundNumberToStep(clamp.y, 0, step)\n\n return [h, parseFloat(s), parseFloat(v)]\n },\n [h, step],\n )\n\n const onKeyDown = useCallback(\n (ev: KeyboardEvent<HTMLDivElement>) => {\n runKeyAction(ev, {\n ArrowDown: () => onChange([h, s, v - step]),\n ArrowLeft: () => onChange([h, s - step, v]),\n ArrowRight: () => onChange([h, s + step, v]),\n ArrowUp: () => onChange([h, s, v + step]),\n })\n },\n [h, onChange, s, step, v],\n )\n\n const getRootProps: PropGetter = useCallback(\n (props = {}) => {\n const merged = mergeProps(dataProps, rest, props)()\n\n return {\n ...merged,\n style: {\n ...rest.style,\n ...props.style,\n \"--x\": `${Math.abs(s * 100)}%`,\n \"--y\": `${Math.abs(100 - v * 100)}%`,\n backgroundColor: `hsl(${h}, 100%, 50%)`,\n backgroundImage:\n \"linear-gradient(0deg, #000, transparent), linear-gradient(90deg, #fff, transparent)\",\n },\n onBlur: handlerAll(props.onBlur, eventProps.onBlur),\n onFocus: handlerAll(props.onFocus, eventProps.onFocus),\n }\n },\n [dataProps, eventProps, h, rest, s, v],\n )\n\n const getInputProps: PropGetter<\"input\"> = useCallback(\n (props = {}) => ({\n ...visuallyHiddenAttributes,\n ...dataProps,\n ...ariaProps,\n id,\n type: \"hidden\",\n name,\n disabled,\n readOnly,\n required,\n value: [h, s, v].toString(),\n ...props,\n ref: mergeRefs(props.ref, ref),\n }),\n [\n ariaProps,\n dataProps,\n disabled,\n h,\n id,\n name,\n readOnly,\n ref,\n required,\n s,\n v,\n ],\n )\n\n const getTrackProps: PropGetter = useCallback(\n (props = {}) => getPanEventProps({ ...dataProps, ...props }),\n [dataProps, getPanEventProps],\n )\n\n const getThumbProps: PropGetter = useCallback(\n (props = {}) =>\n mergeProps(\n {\n ...dataProps,\n ...ariaProps,\n \"aria-label\": t(\"Saturation and brightness thumb\"),\n \"aria-labelledby\": ariaLabelledBy,\n \"aria-roledescription\": \"2D slider\",\n \"aria-valuemax\": 100,\n \"aria-valuemin\": 0,\n \"aria-valuenow\": s * 100,\n \"aria-valuetext\":\n ariaValueText ??\n getAriaValueText?.(value) ??\n t(\"Saturation {saturation}%, Brightness {brightness}%\", {\n brightness: v * 100,\n saturation: s * 100,\n }),\n role: \"slider\",\n tabIndex: interactive ? 0 : -1,\n },\n props,\n { onKeyDown },\n )(),\n [\n ariaLabelledBy,\n ariaProps,\n ariaValueText,\n dataProps,\n getAriaValueText,\n interactive,\n onKeyDown,\n s,\n t,\n v,\n value,\n ],\n )\n\n return {\n setValue,\n value,\n getInputProps,\n getRootProps,\n getThumbProps,\n getTrackProps,\n onChange,\n }\n}\n\nexport type UseSaturationSliderReturn = ReturnType<typeof useSaturationSlider>\n"],"mappings":";;;;;;;;;;;AAqBA,SAAS,WAAW,OAAiC;CACnD,OAAO;GACL,GAAA,oBAAA,cAAA,YAAA,CAAY,MAAM,IAA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C;GACH,MAAM;GACN,UAAU,cAAc,IAAI;EAC9B,GACA,OACA,EAAE,UAAU,CACd,CAAC,CAAC,GACJ;GACE;GACA;GACA;GACA;GACA;GACA;GACA;GACA;GACA;GACA;GACA;EACF,CAQY;EACZ;EACA;CACF;AACF"}
@@ -1,8 +1,8 @@
1
1
  "use client";
2
2
  const require_context = require("../../utils/context.cjs");
3
3
  const require_dom = require("../../utils/dom.cjs");
4
- const require_ref = require("../../utils/ref.cjs");
5
4
  const require_utils_index = require("../../utils/index.cjs");
5
+ const require_props = require("../../core/components/props.cjs");
6
6
  const require_hooks_use_controllable_state_index = require("../../hooks/use-controllable-state/index.cjs");
7
7
  const require_i18n_provider = require("../../providers/i18n-provider/i18n-provider.cjs");
8
8
  const require_use_field_props = require("../field/use-field-props.cjs");
@@ -132,13 +132,12 @@ const useSelect = (props = {}) => {
132
132
  ...dataProps,
133
133
  ...props
134
134
  }), [dataProps]);
135
- const getFieldProps = (0, react.useCallback)(({ ref, "aria-labelledby": ariaLabelledby, ...props } = {}) => getTriggerProps({
136
- ref: require_ref.mergeRefs(ref, fieldRef),
135
+ const getFieldProps = (0, react.useCallback)((props = {}) => getTriggerProps(require_props.mergeProps({
136
+ ref: fieldRef,
137
137
  "aria-label": placeholder,
138
- "aria-labelledby": (0, require_utils_index.utils_exports.cx)(ariaLabelledby, labelId),
139
- ...props,
138
+ "aria-labelledby": labelId,
140
139
  children
141
- }), [
140
+ }, props)()), [
142
141
  children,
143
142
  getTriggerProps,
144
143
  labelId,
@@ -1 +1 @@
1
- {"version":3,"file":"use-select.cjs","names":["createContext","useI18n","useFieldProps","useRef","useControllableState","useCallback","useMemo","useCombobox","isValidElement","cloneElement","mergeRefs","visuallyHiddenAttributes","runKeyAction","useComboboxItem"],"sources":["../../../../src/components/select/use-select.tsx"],"sourcesContent":["\"use client\"\n\nimport type { MouseEvent, ReactNode } from \"react\"\nimport type { HTMLProps, PropGetter } from \"../../core\"\nimport type {\n ComboboxItem,\n ComboboxItemWithValue,\n UseComboboxItemProps,\n UseComboboxProps,\n} from \"../../hooks/use-combobox\"\nimport type { Dict } from \"../../utils\"\nimport type { FieldProps } from \"../field\"\nimport {\n cloneElement,\n isValidElement,\n useCallback,\n useMemo,\n useRef,\n} from \"react\"\nimport { useCombobox, useComboboxItem } from \"../../hooks/use-combobox\"\nimport { useControllableState } from \"../../hooks/use-controllable-state\"\nimport { useI18n } from \"../../providers/i18n-provider\"\nimport {\n ariaAttr,\n createContext,\n cx,\n dataAttr,\n handlerAll,\n isArray,\n isNumber,\n isString,\n isUndefined,\n mergeRefs,\n runKeyAction,\n toArray,\n visuallyHiddenAttributes,\n} from \"../../utils\"\nimport { useFieldProps } from \"../field\"\n\ninterface SelectRenderProps extends ComboboxItemWithValue {\n count: number\n index: number\n separator: string\n onClear: () => void\n}\n\nexport interface SelectItemRender {\n (props: SelectRenderProps): ReactNode\n}\n\nconst defaultRender: SelectItemRender = ({\n count,\n index,\n label,\n separator,\n value,\n}) => {\n const last = count - 1 === index\n\n return (\n <span\n style={{ marginInlineEnd: \"var(--gap)\" }}\n data-placeholder={dataAttr(value === \"\")}\n >\n {label}\n {!last ? separator : null}\n </span>\n )\n}\n\ninterface SelectContext extends Pick<UseSelectReturn, \"max\" | \"value\"> {}\n\nconst [SelectContext, useSelectContext] = createContext<SelectContext>({\n name: \"SelectContext\",\n})\n\nexport { SelectContext, useSelectContext }\n\nexport interface UseSelectProps<Multiple extends boolean = false>\n extends\n Omit<HTMLProps, \"defaultValue\" | \"onChange\" | \"value\">,\n Omit<\n UseComboboxProps,\n \"defaultValue\" | \"initialFocusValue\" | \"onChange\" | \"value\"\n >,\n FieldProps {\n /**\n * The initial value of the select.\n */\n defaultValue?: Multiple extends true ? string[] : string\n /**\n * If `true`, the field will be focused when the clear icon is clicked.\n *\n * @default true\n */\n focusOnClear?: boolean\n /**\n * The `id` attribute of the input element.\n */\n id?: string\n /**\n * If `true`, include placeholder in options.\n *\n * @default true\n */\n includePlaceholder?: boolean\n /**\n * If provided, generate options based on items.\n *\n * @default []\n */\n items?: ComboboxItem[]\n /**\n * The maximum selectable value.\n */\n max?: number\n /**\n * If `true`, the select will be multiple.\n *\n * @default false\n */\n multiple?: Multiple\n /**\n * The `name` attribute of the input element.\n */\n name?: string\n /**\n * The placeholder for select.\n */\n placeholder?: string\n /**\n * The visual separator between each value.\n *\n * @default ','\n */\n separator?: string\n /**\n * The value of the select.\n */\n value?: Multiple extends true ? string[] : string\n /**\n * The callback invoked when value state changes.\n */\n onChange?: (value: Multiple extends true ? string[] : string) => void\n /**\n * The function to render the selected items.\n */\n render?: (props: SelectRenderProps) => ReactNode\n}\n\nexport const useSelect = <Multiple extends boolean = false>(\n props: UseSelectProps<Multiple> = {},\n) => {\n type MaybeValue = Multiple extends true ? string[] : string\n\n const { t } = useI18n(\"select\")\n const {\n context: { labelId } = {},\n props: {\n id,\n name,\n multiple = false,\n closeOnSelect = !multiple,\n defaultValue = (multiple ? [] : \"\") as MaybeValue,\n disabled,\n focusOnClear = true,\n includePlaceholder = !multiple,\n items: itemProp = [],\n max,\n placeholder,\n readOnly,\n render = defaultRender,\n required,\n separator = \",\",\n value: valueProp,\n onChange: onChangeProp,\n ...rest\n },\n ariaProps,\n dataProps,\n eventProps,\n } = useFieldProps(props)\n const fieldRef = useRef<HTMLDivElement>(null)\n const [value, setValue] = useControllableState({\n defaultValue,\n value: valueProp,\n onChange: onChangeProp,\n })\n const onChange = useCallback(\n (value: string) => {\n setValue((prev) => {\n if (isArray(prev))\n if (prev.includes(value))\n return prev.filter((prevValue) => prevValue !== value) as MaybeValue\n else if (!isNumber(max) || prev.length < max)\n return [...prev, value] as MaybeValue\n else return prev\n else return value as MaybeValue\n })\n },\n [max, setValue],\n )\n const items = useMemo<ComboboxItem[]>(() => {\n const items = [...itemProp]\n\n if (placeholder)\n items.unshift({\n hidden: !includePlaceholder,\n label: placeholder,\n value: \"\",\n })\n\n return items\n }, [itemProp, placeholder, includePlaceholder])\n const empty = useMemo(\n () => !items.filter(({ hidden }) => !hidden).length,\n [items],\n )\n const {\n descendants,\n interactive,\n open,\n getContentProps: getComboboxContentProps,\n getSeparatorProps,\n getTriggerProps,\n popoverProps,\n onActiveDescendant,\n onClose,\n onOpen,\n onSelect,\n } = useCombobox({\n closeOnSelect,\n disabled,\n initialFocusValue: isArray(value) ? value[0] : value,\n readOnly,\n onChange,\n ...ariaProps,\n ...dataProps,\n ...eventProps,\n ...rest,\n })\n const valueMap = useMemo<{ [key: string]: ComboboxItemWithValue }>(() => {\n const valueMap: { [key: string]: ComboboxItemWithValue } = {}\n\n items.forEach((item) => {\n if (\"items\" in item) {\n item.items.forEach((item) => {\n item.value ??= isString(item.label) ? item.label : undefined\n\n if (!isUndefined(item.value)) valueMap[item.value] = item\n })\n } else {\n item.value ??= isString(item.label) ? item.label : undefined\n\n if (!isUndefined(item.value)) valueMap[item.value] = item\n }\n })\n\n return valueMap\n }, [items])\n const selectedItems = useMemo<ComboboxItemWithValue[]>(() => {\n if (isArray(value))\n if (value.length) return toArray(value.map((value) => valueMap[value]))\n else return placeholder ? [{ label: placeholder, value: \"\" }] : []\n else return isString(value) ? toArray(valueMap[value]) : []\n }, [placeholder, value, valueMap])\n const children = useMemo<ReactNode>(() => {\n const count = selectedItems.length\n\n return selectedItems.map((item, index) => {\n const onClear = (ev?: MouseEvent<HTMLElement>) => {\n ev?.preventDefault()\n ev?.stopPropagation()\n\n if (item.value) onChange(item.value)\n }\n\n const component = render({\n count,\n index,\n separator,\n onClear,\n ...item,\n })\n\n if (isValidElement<Dict>(component))\n return cloneElement(component, { ...component.props, key: index })\n else return component\n })\n }, [onChange, render, selectedItems, separator])\n\n const onFocus = useCallback(() => {\n if (!interactive || !fieldRef.current) return\n\n fieldRef.current.focus()\n }, [interactive])\n\n const onClear = useCallback(() => {\n if (!interactive) return\n\n setValue((prev) => (isArray(prev) ? [] : \"\") as MaybeValue)\n\n if (!fieldRef.current) return\n\n if (focusOnClear) fieldRef.current.focus()\n }, [focusOnClear, interactive, setValue])\n\n const getRootProps: PropGetter = useCallback(\n (props) => ({ ...dataProps, ...props }),\n [dataProps],\n )\n\n const getFieldProps: PropGetter = useCallback(\n ({ ref, \"aria-labelledby\": ariaLabelledby, ...props } = {}) =>\n getTriggerProps({\n ref: mergeRefs(ref, fieldRef),\n \"aria-label\": placeholder,\n \"aria-labelledby\": cx(ariaLabelledby, labelId),\n ...props,\n children,\n }),\n [children, getTriggerProps, labelId, placeholder],\n )\n\n const getInputProps: PropGetter<\"input\"> = useCallback(\n (props = {}) => ({\n ...dataProps,\n ...visuallyHiddenAttributes,\n id,\n name,\n defaultValue: isString(value) ? value : value.join(\", \"),\n disabled,\n readOnly,\n required,\n ...props,\n onFocus: handlerAll(props.onFocus, onFocus),\n }),\n [dataProps, disabled, id, name, onFocus, readOnly, required, value],\n )\n\n const getContentProps: PropGetter = useCallback(\n (props) => getComboboxContentProps({ hidden: empty, ...props }),\n [empty, getComboboxContentProps],\n )\n\n const getIconProps: PropGetter = useCallback(\n (props) => ({ ...dataProps, ...props }),\n [dataProps],\n )\n\n const getClearIconProps: PropGetter = useCallback(\n (props = {}) =>\n getIconProps({\n \"aria-disabled\": ariaAttr(!interactive),\n \"aria-label\": t(\"Clear value\"),\n role: \"button\",\n tabIndex: interactive ? 0 : -1,\n ...props,\n onClick: handlerAll(props.onClick, onClear),\n onKeyDown: handlerAll(props.onKeyDown, (ev) =>\n runKeyAction(ev, { Enter: onClear, Space: onClear }),\n ),\n }),\n [getIconProps, interactive, onClear, t],\n )\n\n return {\n descendants,\n includePlaceholder,\n interactive,\n items,\n max,\n open,\n placeholder,\n setValue,\n value,\n valueMap,\n getClearIconProps,\n getContentProps,\n getFieldProps,\n getIconProps,\n getInputProps,\n getRootProps,\n getSeparatorProps,\n popoverProps,\n onActiveDescendant,\n onChange,\n onClose,\n onOpen,\n onSelect,\n }\n}\n\nexport type UseSelectReturn = ReturnType<typeof useSelect>\n\nexport interface UseSelectOptionProps extends UseComboboxItemProps {}\n\nexport const useSelectOption = ({\n children,\n closeOnSelect,\n disabled,\n hidden,\n value,\n ...rest\n}: UseSelectOptionProps = {}) => {\n const { max, value: selectedValue } = useSelectContext()\n\n value ??= isString(children) ? children : undefined\n\n const selected = isArray(selectedValue)\n ? !isUndefined(value) && selectedValue.includes(value)\n : selectedValue === value\n const completed =\n isNumber(max) && isArray(selectedValue) && selectedValue.length >= max\n const { getIndicatorProps, getItemProps } = useComboboxItem({\n children,\n closeOnSelect,\n disabled: disabled || hidden || (completed && !selected),\n hidden,\n selected,\n value,\n ...rest,\n })\n\n const getOptionProps: PropGetter = useCallback(\n (props = {}) => getItemProps(props),\n [getItemProps],\n )\n\n return { getIndicatorProps, getOptionProps }\n}\n\nexport type UseSelectOptionReturn = ReturnType<typeof useSelectOption>\n"],"mappings":";;;;;;;;;;;;AAkDA,MAAM,iBAAmC,EACvC,OACA,OACA,OACA,WACA,YACI;CACJ,MAAM,OAAO,QAAQ,MAAM;CAE3B,OACE,iBAAA,GAAA,kBAAA,KAAA,CAAC,QAAD;EACE,OAAO,EAAE,iBAAiB,aAAa;EACvC,qBAAA,GAAA,oBAAA,cAAkB,SAAA,CAAS,UAAU,EAAE;EAFzC,UAAA,CAIG,OACA,CAAC,OAAO,YAAY,IACjB;;AAEV;AAIA,MAAM,CAAC,eAAe,oBAAoBA,gBAAAA,cAA6B,EACrE,MAAM,gBACR,CAAC;AA4ED,MAAa,aACX,QAAkC,CAAC,MAChC;CAGH,MAAM,EAAE,MAAMC,sBAAAA,QAAQ,QAAQ;CAC9B,MAAM,EACJ,SAAS,EAAE,YAAY,CAAC,GACxB,OAAO,EACL,IACA,MACA,WAAW,OACX,gBAAgB,CAAC,UACjB,eAAgB,WAAW,CAAC,IAAI,IAChC,UACA,eAAe,MACf,qBAAqB,CAAC,UACtB,OAAO,WAAW,CAAC,GACnB,KACA,aACA,UACA,SAAS,eACT,UACA,YAAY,KACZ,OAAO,WACP,UAAU,cACV,GAAG,QAEL,WACA,WACA,eACEC,wBAAA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AAA,GAAA,oBAAA,cACJ,SAAA,CAAS,GAAG,MAAA,GAAA,oBAAA,cAAK,QAAA,CAAQ,aAAa,KAAK,cAAc,UAAU;CACrE,MAAM,EAAE,mBAAmB,iBAAiBC,iCAAAA,gBAAgB;EAC1D;EACA;EACA,UAAU,YAAY,UAAW,aAAa,CAAC;EAC/C;EACA;EACA;EACA,GAAG;CACL,CAAC;CAOD,OAAO;EAAE;EAAmB,iBAAA,GALOR,MAAAA,YAAAA,EAChC,QAAQ,CAAC,MAAM,aAAa,KAAK,GAClC,CAAC,YAAY,CAG0B;CAAE;AAC7C"}
1
+ {"version":3,"file":"use-select.cjs","names":["createContext","useI18n","useFieldProps","useRef","useControllableState","useCallback","useMemo","useCombobox","isValidElement","cloneElement","mergeProps","visuallyHiddenAttributes","runKeyAction","useComboboxItem"],"sources":["../../../../src/components/select/use-select.tsx"],"sourcesContent":["\"use client\"\n\nimport type { MouseEvent, ReactNode } from \"react\"\nimport type {\n ComboboxItem,\n ComboboxItemWithValue,\n UseComboboxItemProps,\n UseComboboxProps,\n} from \"../../hooks/use-combobox\"\nimport type { Dict } from \"../../utils\"\nimport type { FieldProps } from \"../field\"\nimport {\n cloneElement,\n isValidElement,\n useCallback,\n useMemo,\n useRef,\n} from \"react\"\nimport { type HTMLProps, mergeProps, type PropGetter } from \"../../core\"\nimport { useCombobox, useComboboxItem } from \"../../hooks/use-combobox\"\nimport { useControllableState } from \"../../hooks/use-controllable-state\"\nimport { useI18n } from \"../../providers/i18n-provider\"\nimport {\n ariaAttr,\n createContext,\n dataAttr,\n handlerAll,\n isArray,\n isNumber,\n isString,\n isUndefined,\n runKeyAction,\n toArray,\n visuallyHiddenAttributes,\n} from \"../../utils\"\nimport { useFieldProps } from \"../field\"\n\ninterface SelectRenderProps extends ComboboxItemWithValue {\n count: number\n index: number\n separator: string\n onClear: () => void\n}\n\nexport interface SelectItemRender {\n (props: SelectRenderProps): ReactNode\n}\n\nconst defaultRender: SelectItemRender = ({\n count,\n index,\n label,\n separator,\n value,\n}) => {\n const last = count - 1 === index\n\n return (\n <span\n style={{ marginInlineEnd: \"var(--gap)\" }}\n data-placeholder={dataAttr(value === \"\")}\n >\n {label}\n {!last ? separator : null}\n </span>\n )\n}\n\ninterface SelectContext extends Pick<UseSelectReturn, \"max\" | \"value\"> {}\n\nconst [SelectContext, useSelectContext] = createContext<SelectContext>({\n name: \"SelectContext\",\n})\n\nexport { SelectContext, useSelectContext }\n\nexport interface UseSelectProps<Multiple extends boolean = false>\n extends\n Omit<HTMLProps, \"defaultValue\" | \"onChange\" | \"value\">,\n Omit<\n UseComboboxProps,\n \"defaultValue\" | \"initialFocusValue\" | \"onChange\" | \"value\"\n >,\n FieldProps {\n /**\n * The initial value of the select.\n */\n defaultValue?: Multiple extends true ? string[] : string\n /**\n * If `true`, the field will be focused when the clear icon is clicked.\n *\n * @default true\n */\n focusOnClear?: boolean\n /**\n * The `id` attribute of the input element.\n */\n id?: string\n /**\n * If `true`, include placeholder in options.\n *\n * @default true\n */\n includePlaceholder?: boolean\n /**\n * If provided, generate options based on items.\n *\n * @default []\n */\n items?: ComboboxItem[]\n /**\n * The maximum selectable value.\n */\n max?: number\n /**\n * If `true`, the select will be multiple.\n *\n * @default false\n */\n multiple?: Multiple\n /**\n * The `name` attribute of the input element.\n */\n name?: string\n /**\n * The placeholder for select.\n */\n placeholder?: string\n /**\n * The visual separator between each value.\n *\n * @default ','\n */\n separator?: string\n /**\n * The value of the select.\n */\n value?: Multiple extends true ? string[] : string\n /**\n * The callback invoked when value state changes.\n */\n onChange?: (value: Multiple extends true ? string[] : string) => void\n /**\n * The function to render the selected items.\n */\n render?: (props: SelectRenderProps) => ReactNode\n}\n\nexport const useSelect = <Multiple extends boolean = false>(\n props: UseSelectProps<Multiple> = {},\n) => {\n type MaybeValue = Multiple extends true ? string[] : string\n\n const { t } = useI18n(\"select\")\n const {\n context: { labelId } = {},\n props: {\n id,\n name,\n multiple = false,\n closeOnSelect = !multiple,\n defaultValue = (multiple ? [] : \"\") as MaybeValue,\n disabled,\n focusOnClear = true,\n includePlaceholder = !multiple,\n items: itemProp = [],\n max,\n placeholder,\n readOnly,\n render = defaultRender,\n required,\n separator = \",\",\n value: valueProp,\n onChange: onChangeProp,\n ...rest\n },\n ariaProps,\n dataProps,\n eventProps,\n } = useFieldProps(props)\n const fieldRef = useRef<HTMLDivElement>(null)\n const [value, setValue] = useControllableState({\n defaultValue,\n value: valueProp,\n onChange: onChangeProp,\n })\n const onChange = useCallback(\n (value: string) => {\n setValue((prev) => {\n if (isArray(prev))\n if (prev.includes(value))\n return prev.filter((prevValue) => prevValue !== value) as MaybeValue\n else if (!isNumber(max) || prev.length < max)\n return [...prev, value] as MaybeValue\n else return prev\n else return value as MaybeValue\n })\n },\n [max, setValue],\n )\n const items = useMemo<ComboboxItem[]>(() => {\n const items = [...itemProp]\n\n if (placeholder)\n items.unshift({\n hidden: !includePlaceholder,\n label: placeholder,\n value: \"\",\n })\n\n return items\n }, [itemProp, placeholder, includePlaceholder])\n const empty = useMemo(\n () => !items.filter(({ hidden }) => !hidden).length,\n [items],\n )\n const {\n descendants,\n interactive,\n open,\n getContentProps: getComboboxContentProps,\n getSeparatorProps,\n getTriggerProps,\n popoverProps,\n onActiveDescendant,\n onClose,\n onOpen,\n onSelect,\n } = useCombobox({\n closeOnSelect,\n disabled,\n initialFocusValue: isArray(value) ? value[0] : value,\n readOnly,\n onChange,\n ...ariaProps,\n ...dataProps,\n ...eventProps,\n ...rest,\n })\n const valueMap = useMemo<{ [key: string]: ComboboxItemWithValue }>(() => {\n const valueMap: { [key: string]: ComboboxItemWithValue } = {}\n\n items.forEach((item) => {\n if (\"items\" in item) {\n item.items.forEach((item) => {\n item.value ??= isString(item.label) ? item.label : undefined\n\n if (!isUndefined(item.value)) valueMap[item.value] = item\n })\n } else {\n item.value ??= isString(item.label) ? item.label : undefined\n\n if (!isUndefined(item.value)) valueMap[item.value] = item\n }\n })\n\n return valueMap\n }, [items])\n const selectedItems = useMemo<ComboboxItemWithValue[]>(() => {\n if (isArray(value))\n if (value.length) return toArray(value.map((value) => valueMap[value]))\n else return placeholder ? [{ label: placeholder, value: \"\" }] : []\n else return isString(value) ? toArray(valueMap[value]) : []\n }, [placeholder, value, valueMap])\n const children = useMemo<ReactNode>(() => {\n const count = selectedItems.length\n\n return selectedItems.map((item, index) => {\n const onClear = (ev?: MouseEvent<HTMLElement>) => {\n ev?.preventDefault()\n ev?.stopPropagation()\n\n if (item.value) onChange(item.value)\n }\n\n const component = render({\n count,\n index,\n separator,\n onClear,\n ...item,\n })\n\n if (isValidElement<Dict>(component))\n return cloneElement(component, { ...component.props, key: index })\n else return component\n })\n }, [onChange, render, selectedItems, separator])\n\n const onFocus = useCallback(() => {\n if (!interactive || !fieldRef.current) return\n\n fieldRef.current.focus()\n }, [interactive])\n\n const onClear = useCallback(() => {\n if (!interactive) return\n\n setValue((prev) => (isArray(prev) ? [] : \"\") as MaybeValue)\n\n if (!fieldRef.current) return\n\n if (focusOnClear) fieldRef.current.focus()\n }, [focusOnClear, interactive, setValue])\n\n const getRootProps: PropGetter = useCallback(\n (props) => ({ ...dataProps, ...props }),\n [dataProps],\n )\n\n const getFieldProps: PropGetter = useCallback(\n (props = {}) =>\n getTriggerProps(\n mergeProps(\n {\n ref: fieldRef,\n \"aria-label\": placeholder,\n \"aria-labelledby\": labelId,\n children,\n },\n props,\n )(),\n ),\n [children, getTriggerProps, labelId, placeholder],\n )\n\n const getInputProps: PropGetter<\"input\"> = useCallback(\n (props = {}) => ({\n ...dataProps,\n ...visuallyHiddenAttributes,\n id,\n name,\n defaultValue: isString(value) ? value : value.join(\", \"),\n disabled,\n readOnly,\n required,\n ...props,\n onFocus: handlerAll(props.onFocus, onFocus),\n }),\n [dataProps, disabled, id, name, onFocus, readOnly, required, value],\n )\n\n const getContentProps: PropGetter = useCallback(\n (props) => getComboboxContentProps({ hidden: empty, ...props }),\n [empty, getComboboxContentProps],\n )\n\n const getIconProps: PropGetter = useCallback(\n (props) => ({ ...dataProps, ...props }),\n [dataProps],\n )\n\n const getClearIconProps: PropGetter = useCallback(\n (props = {}) =>\n getIconProps({\n \"aria-disabled\": ariaAttr(!interactive),\n \"aria-label\": t(\"Clear value\"),\n role: \"button\",\n tabIndex: interactive ? 0 : -1,\n ...props,\n onClick: handlerAll(props.onClick, onClear),\n onKeyDown: handlerAll(props.onKeyDown, (ev) =>\n runKeyAction(ev, { Enter: onClear, Space: onClear }),\n ),\n }),\n [getIconProps, interactive, onClear, t],\n )\n\n return {\n descendants,\n includePlaceholder,\n interactive,\n items,\n max,\n open,\n placeholder,\n setValue,\n value,\n valueMap,\n getClearIconProps,\n getContentProps,\n getFieldProps,\n getIconProps,\n getInputProps,\n getRootProps,\n getSeparatorProps,\n popoverProps,\n onActiveDescendant,\n onChange,\n onClose,\n onOpen,\n onSelect,\n }\n}\n\nexport type UseSelectReturn = ReturnType<typeof useSelect>\n\nexport interface UseSelectOptionProps extends UseComboboxItemProps {}\n\nexport const useSelectOption = ({\n children,\n closeOnSelect,\n disabled,\n hidden,\n value,\n ...rest\n}: UseSelectOptionProps = {}) => {\n const { max, value: selectedValue } = useSelectContext()\n\n value ??= isString(children) ? children : undefined\n\n const selected = isArray(selectedValue)\n ? !isUndefined(value) && selectedValue.includes(value)\n : selectedValue === value\n const completed =\n isNumber(max) && isArray(selectedValue) && selectedValue.length >= max\n const { getIndicatorProps, getItemProps } = useComboboxItem({\n children,\n closeOnSelect,\n disabled: disabled || hidden || (completed && !selected),\n hidden,\n selected,\n value,\n ...rest,\n })\n\n const getOptionProps: PropGetter = useCallback(\n (props = {}) => getItemProps(props),\n [getItemProps],\n )\n\n return { getIndicatorProps, getOptionProps }\n}\n\nexport type UseSelectOptionReturn = ReturnType<typeof useSelectOption>\n"],"mappings":";;;;;;;;;;;;AAgDA,MAAM,iBAAmC,EACvC,OACA,OACA,OACA,WACA,YACI;CACJ,MAAM,OAAO,QAAQ,MAAM;CAE3B,OACE,iBAAA,GAAA,kBAAA,KAAA,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IAAE,OAAO;IAAS,OAAO;GAAQ,CAAC,CACrD;EACF,CAAC,GACH;GAAC;GAAc;GAAa;GAAS;EAAC,CActB;EAChB;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;CACF;AACF;AAMA,MAAa,mBAAmB,EAC9B,UACA,eACA,UACA,QACA,OACA,GAAG,SACqB,CAAC,MAAM;CAC/B,MAAM,EAAE,KAAK,OAAO,kBAAkB,iBAAiB;CAEvD,WAAA,GAAA,oBAAA,cAAU,SAAA,CAAS,QAAQ,IAAI,WAAW,KAAA;CAE1C,MAAM,YAAA,GAAA,oBAAA,cAAW,QAAA,CAAQ,aAAa,IAClC,EAAA,GAAA,oBAAA,cAAC,YAAA,CAAY,KAAK,KAAK,cAAc,SAAS,KAAK,IACnD,kBAAkB;CACtB,MAAM,aAAA,GAAA,oBAAA,cACJ,SAAA,CAAS,GAAG,MAAA,GAAA,oBAAA,cAAK,QAAA,CAAQ,aAAa,KAAK,cAAc,UAAU;CACrE,MAAM,EAAE,mBAAmB,iBAAiBC,iCAAAA,gBAAgB;EAC1D;EACA;EACA,UAAU,YAAY,UAAW,aAAa,CAAC;EAC/C;EACA;EACA;EACA,GAAG;CACL,CAAC;CAOD,OAAO;EAAE;EAAmB,iBAAA,GALOR,MAAAA,YAAAA,EAChC,QAAQ,CAAC,MAAM,aAAa,KAAK,GAClC,CAAC,YAAY,CAG0B;CAAE;AAC7C"}
@@ -219,20 +219,15 @@ const useSidebarItem = ({ asyncChildren, children: childrenProp, defaultOpen, di
219
219
  } else onOpen();
220
220
  else onClose();
221
221
  }, [defaultExpanded]);
222
- const getItemProps = (0, react.useCallback)(({ ref, "aria-labelledby": ariaLabelledby, ...props } = {}) => {
223
- const merged = require_props.mergeProps({
224
- id: itemId,
225
- "aria-current": selected ? "page" : void 0,
226
- "aria-disabled": (0, require_utils_index.utils_exports.ariaAttr)(disabled),
227
- "aria-labelledby": (0, require_utils_index.utils_exports.cx)(ariaLabelledby, labelId),
228
- "data-disabled": (0, require_utils_index.utils_exports.dataAttr)(disabled),
229
- "data-selected": (0, require_utils_index.utils_exports.dataAttr)(selected)
230
- }, rest, props, { ref }, { ref: register })();
231
- return {
232
- ...merged,
233
- onClick: (0, require_utils_index.utils_exports.handlerAll)(merged.onClick, !group ? () => onSelectedChange(value) : void 0)
234
- };
235
- }, [
222
+ const getItemProps = (0, react.useCallback)((props = {}) => require_props.mergeProps({
223
+ id: itemId,
224
+ ref: register,
225
+ "aria-current": selected ? "page" : void 0,
226
+ "aria-disabled": (0, require_utils_index.utils_exports.ariaAttr)(disabled),
227
+ "aria-labelledby": labelId,
228
+ "data-disabled": (0, require_utils_index.utils_exports.dataAttr)(disabled),
229
+ "data-selected": (0, require_utils_index.utils_exports.dataAttr)(selected)
230
+ }, rest, props, { onClick: !group ? () => onSelectedChange(value) : void 0 })(), [
236
231
  itemId,
237
232
  register,
238
233
  selected,
@@ -311,13 +306,12 @@ const useSidebarItem = ({ asyncChildren, children: childrenProp, defaultOpen, di
311
306
  selected,
312
307
  selectedValue,
313
308
  value,
314
- getContentProps: (0, react.useCallback)(({ "aria-labelledby": ariaLabelledby, ...props } = {}) => ({
309
+ getContentProps: (0, react.useCallback)((props = {}) => require_props.mergeProps({
315
310
  id: contentId,
316
311
  "aria-busy": (0, require_utils_index.utils_exports.ariaAttr)(groupLoading),
317
- "aria-labelledby": (0, require_utils_index.utils_exports.cx)(ariaLabelledby, labelId),
318
- "data-disabled": (0, require_utils_index.utils_exports.dataAttr)(disabled),
319
- ...props
320
- }), [
312
+ "aria-labelledby": labelId,
313
+ "data-disabled": (0, require_utils_index.utils_exports.dataAttr)(disabled)
314
+ }, props)(), [
321
315
  contentId,
322
316
  labelId,
323
317
  disabled,