@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-slider.js","names":["isNumber","valueToPercent","percentToValue","roundNumberToStep","clampNumber","isArray","dataAttr","cx","handlerAll"],"sources":["../../../../src/components/slider/use-slider.ts"],"sourcesContent":["\"use client\"\n\nimport type { KeyboardEvent } from \"react\"\nimport type {\n HTMLProps,\n HTMLRefAttributes,\n Orientation,\n PropGetter,\n RequiredPropGetter,\n} from \"../../core\"\nimport type { Point } from \"../../utils\"\nimport type { FieldProps } from \"../field\"\nimport { useCallback, useRef } 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 dataAttr,\n handlerAll,\n isArray,\n isNumber,\n mergeRefs,\n percentToValue,\n roundNumberToStep,\n runKeyAction,\n valueToPercent,\n visuallyHiddenAttributes,\n} from \"../../utils\"\nimport { useFieldProps } from \"../field\"\n\nexport interface UseSliderProps<Y extends [number, number] | number = number>\n extends\n Omit<HTMLProps, \"defaultValue\" | \"onChange\" | \"ref\">,\n HTMLRefAttributes<\"input\">,\n FieldProps {\n /**\n * The minimum distance between slider thumbs.\n * Useful for preventing the thumbs from being too close together.\n *\n * @default 0\n */\n betweenThumbs?: number\n /**\n * The initial value of the slider.\n */\n defaultValue?: Y\n /**\n * The base `id` to use for the slider.\n */\n id?: string\n /**\n * The maximum allowed value of the slider. Cannot be less than min.\n *\n * @default 100\n */\n max?: number\n /**\n * The minimum allowed value of the slider. Cannot be greater than max.\n *\n * @default 0\n */\n min?: number\n /**\n * The name attribute of the hidden `input` field.\n * This is particularly useful in forms.\n */\n name?: string\n /**\n * The orientation of the slider.\n *\n * @default 'horizontal'\n */\n orientation?: Orientation\n /**\n * The step in which increments or decrements have to be made.\n *\n * @default 1\n */\n step?: number\n /**\n * The value of the slider.\n */\n value?: Y\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, index: number) => string | undefined\n /**\n * Function called whenever the slider value changes.\n */\n onChange?: (value: Y) => void\n /**\n * Function called when the user is done selecting a new value.\n */\n onChangeEnd?: (value: Y) => void\n /**\n * Function called when the user starts selecting a new value.\n */\n onChangeStart?: (value: Y) => void\n}\n\nexport const useSlider = <Y extends [number, number] | number = number>(\n props: UseSliderProps<Y> = {},\n) => {\n const {\n props: {\n id,\n ref,\n name,\n \"aria-labelledby\": ariaLabelledBy,\n \"aria-valuetext\": ariaValueText,\n betweenThumbs = 0,\n defaultValue = 0 as Y,\n disabled,\n getAriaValueText,\n max = 100,\n min = 0,\n orientation = \"horizontal\",\n readOnly,\n required,\n step = 1,\n value: valueProp,\n onChange: onChangeProp,\n onChangeEnd,\n onChangeStart,\n ...rest\n },\n ariaProps,\n dataProps,\n eventProps,\n } = useFieldProps(props)\n const [value, setValue] = useControllableState({\n defaultValue,\n value: valueProp,\n onChange: onChangeProp,\n })\n const { t } = useI18n(\"slider\")\n const currentIndex = useRef(0)\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 if (range) {\n const start = currentIndex.current === 0\n const oppositeIndex = currentIndex.current === 0 ? 1 : 0\n const oppositeValue = value[oppositeIndex]\n\n onChangeEnd?.(\n (start ? [panValue, oppositeValue] : [oppositeValue, panValue]) as Y,\n )\n } else {\n onChangeEnd?.(panValue as Y)\n }\n },\n onMove: (_, point, rect) => {\n if (!interactive) return\n\n const panValue = getPanValue(point, rect)\n\n onChange(currentIndex.current, panValue)\n },\n onStart: (_, point, rect) => {\n if (!interactive) return\n\n const panValue = getPanValue(point, rect)\n\n if (range) {\n const distances = value.map((value) => Math.abs(value - panValue))\n const closest = Math.min(...distances)\n const index = distances.indexOf(closest)\n\n currentIndex.current = index\n\n const start = index === 0\n const oppositeIndex = index === 0 ? 1 : 0\n const oppositeValue = value[oppositeIndex]\n\n onChangeStart?.(\n (start ? [panValue, oppositeValue] : [oppositeValue, panValue]) as Y,\n )\n } else {\n currentIndex.current = 0\n\n onChangeStart?.(value)\n }\n\n onChange(currentIndex.current, panValue)\n },\n })\n const range = !isNumber(value)\n const percent = (\n range\n ? value.map((value) => valueToPercent(value, min, max))\n : valueToPercent(value, min, max)\n ) as Y extends number ? number : number[]\n const tenStep = (max - min) / 10\n const oneStep = step || (max - min) / 100\n\n if (max < min) console.warn(\"Do not assign a number less than 'min' to 'max'\")\n\n const getMinMax = useCallback(\n (index: number) => {\n const start = index === 0\n const oppositeIndex = index === 0 ? 1 : 0\n const oppositeValue = range ? value[oppositeIndex] : value\n\n return {\n max: range ? (start ? oppositeValue - betweenThumbs : max) : max,\n min: range ? (start ? min : oppositeValue + betweenThumbs) : min,\n }\n },\n [betweenThumbs, max, min, range, value],\n )\n\n const getPanValue = useCallback(\n ({ x, y }: Point, { bottom, height, left, width }: DOMRect) => {\n const diff = orientation === \"horizontal\" ? x - left : bottom - y\n const length = orientation === \"horizontal\" ? width : height\n const percent = diff / length\n\n let nextValue = percentToValue(percent, min, max)\n\n nextValue = parseFloat(roundNumberToStep(nextValue, min, step))\n nextValue = clampNumber(nextValue, min, max)\n\n return nextValue\n },\n [orientation, min, max, step],\n )\n\n const onChange = useCallback(\n (index: number, value: number) => {\n if (!interactive) return\n\n const { max, min } = getMinMax(index)\n\n value = parseFloat(roundNumberToStep(value, min, oneStep))\n value = clampNumber(value, min, max)\n\n setValue((prev) => {\n if (isArray(prev)) {\n const next = [...prev]\n\n next[index] = value\n\n return next as Y\n } else {\n return value as Y\n }\n })\n },\n [getMinMax, interactive, oneStep, setValue],\n )\n\n const stepUp = useCallback(\n (index: number, step = oneStep) =>\n range\n ? onChange(index, value[index]! + step)\n : onChange(index, value + step),\n [oneStep, range, onChange, value],\n )\n\n const stepDown = useCallback(\n (index: number, step = oneStep) =>\n range\n ? onChange(index, value[index]! - step)\n : onChange(index, value - step),\n [oneStep, range, onChange, value],\n )\n\n const onKeyDown = useCallback(\n (index: number) => (ev: KeyboardEvent<HTMLDivElement>) => {\n const { max, min } = getMinMax(index)\n\n runKeyAction(ev, {\n ArrowDown: () => stepDown(index),\n ArrowLeft: () => stepDown(index),\n ArrowRight: () => stepUp(index),\n ArrowUp: () => stepUp(index),\n End: () => onChange(index, max),\n Home: () => onChange(index, min),\n PageDown: () => stepDown(index, tenStep),\n PageUp: () => stepUp(index, tenStep),\n })\n },\n [getMinMax, onChange, stepDown, stepUp, tenStep],\n )\n\n const getRootProps: PropGetter = useCallback(\n (props = {}) => {\n const computedProps: HTMLProps = mergeProps(\n dataProps,\n { \"data-orientation\": orientation },\n rest,\n props,\n { onBlur: eventProps.onBlur, onFocus: eventProps.onFocus },\n )()\n\n computedProps.style ??= {}\n\n if (isArray(percent)) {\n computedProps.style[\"--range-start\"] = `${Math.abs(percent[0]!)}%`\n computedProps.style[\"--range-end\"] = `${Math.abs(percent[1]!)}%`\n } else {\n computedProps.style[\"--range-start\"] = \"0%\"\n computedProps.style[\"--range-end\"] = `${Math.abs(percent)}%`\n }\n\n return computedProps\n },\n [dataProps, eventProps, orientation, percent, rest],\n )\n\n const getInputProps: PropGetter<\"input\", { index?: number }> = useCallback(\n ({ index = 0, ...props } = {}) => ({\n ...visuallyHiddenAttributes,\n ...dataProps,\n ...ariaProps,\n id,\n type: \"hidden\",\n name,\n disabled,\n readOnly,\n required,\n value: range ? value[index]! : value,\n ...props,\n ref: index === 0 ? mergeRefs(props.ref, ref) : props.ref,\n }),\n [\n dataProps,\n ariaProps,\n id,\n name,\n disabled,\n readOnly,\n required,\n range,\n value,\n ref,\n ],\n )\n\n const getTrackProps: PropGetter = useCallback(\n (props) =>\n getPanEventProps({\n ...dataProps,\n \"data-orientation\": orientation,\n ...props,\n }),\n [dataProps, getPanEventProps, orientation],\n )\n\n const getRangeProps: PropGetter = useCallback(\n (props) => ({\n ...dataProps,\n \"data-orientation\": orientation,\n \"data-range\": dataAttr(range),\n ...props,\n }),\n [dataProps, orientation, range],\n )\n\n const getMarkProps: RequiredPropGetter<\"div\", { value: number }> =\n useCallback(\n ({ style, value: valueProp, ...props }) => {\n const between = range\n ? value[0] < valueProp && valueProp < value[1]\n : valueProp < value\n const percent = valueToPercent(valueProp, min, max)\n\n return {\n ...dataProps,\n \"aria-hidden\": true,\n \"data-between\": dataAttr(between),\n \"data-orientation\": orientation,\n role: \"presentation\",\n ...props,\n style: { ...style, \"--mark-position\": `${percent}%` },\n }\n },\n [dataProps, max, min, orientation, range, value],\n )\n\n const getThumbProps: PropGetter<\"div\", { index?: number }> = useCallback(\n ({ index = 0, ...rest } = {}) => {\n const { max, min } = getMinMax(index)\n\n const props: HTMLProps = {\n ...dataProps,\n ...ariaProps,\n \"aria-label\": t(\"Slider thumb\"),\n \"aria-orientation\": orientation,\n \"aria-valuemax\": max,\n \"aria-valuemin\": min,\n role: \"slider\",\n tabIndex: interactive ? 0 : -1,\n ...rest,\n \"aria-labelledby\": cx(rest[\"aria-labelledby\"], ariaLabelledBy),\n onKeyDown: handlerAll(rest.onKeyDown, onKeyDown(index)),\n }\n\n if (range) {\n const currentValue = value[index]!\n\n props[\"data-start\"] = dataAttr(index === 0)\n props[\"data-end\"] = dataAttr(index === 1)\n props[\"aria-valuenow\"] = currentValue\n props[\"aria-valuetext\"] =\n ariaValueText ??\n getAriaValueText?.(currentValue, index) ??\n currentValue.toString()\n } else {\n props[\"data-end\"] = dataAttr(index === 0)\n props[\"aria-valuenow\"] = value\n props[\"aria-valuetext\"] =\n ariaValueText ?? getAriaValueText?.(value, index) ?? value.toString()\n }\n\n return props\n },\n [\n t,\n ariaLabelledBy,\n ariaProps,\n ariaValueText,\n dataProps,\n getAriaValueText,\n getMinMax,\n interactive,\n onKeyDown,\n orientation,\n range,\n value,\n ],\n )\n\n return {\n percent,\n range,\n setValue,\n stepDown,\n stepUp,\n value,\n getInputProps,\n getMarkProps,\n getRangeProps,\n getRootProps,\n getThumbProps,\n getTrackProps,\n onChange,\n }\n}\n\nexport type UseSliderReturn = ReturnType<typeof useSlider>\n"],"mappings":";;;;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 {"version":3,"file":"use-slider.js","names":["isNumber","valueToPercent","percentToValue","roundNumberToStep","clampNumber","isArray","dataAttr"],"sources":["../../../../src/components/slider/use-slider.ts"],"sourcesContent":["\"use client\"\n\nimport type { KeyboardEvent } from \"react\"\nimport type {\n HTMLProps,\n HTMLRefAttributes,\n Orientation,\n PropGetter,\n RequiredPropGetter,\n} from \"../../core\"\nimport type { Point } from \"../../utils\"\nimport type { FieldProps } from \"../field\"\nimport { useCallback, useRef } 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 dataAttr,\n isArray,\n isNumber,\n mergeRefs,\n percentToValue,\n roundNumberToStep,\n runKeyAction,\n valueToPercent,\n visuallyHiddenAttributes,\n} from \"../../utils\"\nimport { useFieldProps } from \"../field\"\n\nexport interface UseSliderProps<Y extends [number, number] | number = number>\n extends\n Omit<HTMLProps, \"defaultValue\" | \"onChange\" | \"ref\">,\n HTMLRefAttributes<\"input\">,\n FieldProps {\n /**\n * The minimum distance between slider thumbs.\n * Useful for preventing the thumbs from being too close together.\n *\n * @default 0\n */\n betweenThumbs?: number\n /**\n * The initial value of the slider.\n */\n defaultValue?: Y\n /**\n * The base `id` to use for the slider.\n */\n id?: string\n /**\n * The maximum allowed value of the slider. Cannot be less than min.\n *\n * @default 100\n */\n max?: number\n /**\n * The minimum allowed value of the slider. Cannot be greater than max.\n *\n * @default 0\n */\n min?: number\n /**\n * The name attribute of the hidden `input` field.\n * This is particularly useful in forms.\n */\n name?: string\n /**\n * The orientation of the slider.\n *\n * @default 'horizontal'\n */\n orientation?: Orientation\n /**\n * The step in which increments or decrements have to be made.\n *\n * @default 1\n */\n step?: number\n /**\n * The value of the slider.\n */\n value?: Y\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, index: number) => string | undefined\n /**\n * Function called whenever the slider value changes.\n */\n onChange?: (value: Y) => void\n /**\n * Function called when the user is done selecting a new value.\n */\n onChangeEnd?: (value: Y) => void\n /**\n * Function called when the user starts selecting a new value.\n */\n onChangeStart?: (value: Y) => void\n}\n\nexport const useSlider = <Y extends [number, number] | number = number>(\n props: UseSliderProps<Y> = {},\n) => {\n const {\n props: {\n id,\n ref,\n name,\n \"aria-labelledby\": ariaLabelledBy,\n \"aria-valuetext\": ariaValueText,\n betweenThumbs = 0,\n defaultValue = 0 as Y,\n disabled,\n getAriaValueText,\n max = 100,\n min = 0,\n orientation = \"horizontal\",\n readOnly,\n required,\n step = 1,\n value: valueProp,\n onChange: onChangeProp,\n onChangeEnd,\n onChangeStart,\n ...rest\n },\n ariaProps,\n dataProps,\n eventProps,\n } = useFieldProps(props)\n const [value, setValue] = useControllableState({\n defaultValue,\n value: valueProp,\n onChange: onChangeProp,\n })\n const { t } = useI18n(\"slider\")\n const currentIndex = useRef(0)\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 if (range) {\n const start = currentIndex.current === 0\n const oppositeIndex = currentIndex.current === 0 ? 1 : 0\n const oppositeValue = value[oppositeIndex]\n\n onChangeEnd?.(\n (start ? [panValue, oppositeValue] : [oppositeValue, panValue]) as Y,\n )\n } else {\n onChangeEnd?.(panValue as Y)\n }\n },\n onMove: (_, point, rect) => {\n if (!interactive) return\n\n const panValue = getPanValue(point, rect)\n\n onChange(currentIndex.current, panValue)\n },\n onStart: (_, point, rect) => {\n if (!interactive) return\n\n const panValue = getPanValue(point, rect)\n\n if (range) {\n const distances = value.map((value) => Math.abs(value - panValue))\n const closest = Math.min(...distances)\n const index = distances.indexOf(closest)\n\n currentIndex.current = index\n\n const start = index === 0\n const oppositeIndex = index === 0 ? 1 : 0\n const oppositeValue = value[oppositeIndex]\n\n onChangeStart?.(\n (start ? [panValue, oppositeValue] : [oppositeValue, panValue]) as Y,\n )\n } else {\n currentIndex.current = 0\n\n onChangeStart?.(value)\n }\n\n onChange(currentIndex.current, panValue)\n },\n })\n const range = !isNumber(value)\n const percent = (\n range\n ? value.map((value) => valueToPercent(value, min, max))\n : valueToPercent(value, min, max)\n ) as Y extends number ? number : number[]\n const tenStep = (max - min) / 10\n const oneStep = step || (max - min) / 100\n\n if (max < min) console.warn(\"Do not assign a number less than 'min' to 'max'\")\n\n const getMinMax = useCallback(\n (index: number) => {\n const start = index === 0\n const oppositeIndex = index === 0 ? 1 : 0\n const oppositeValue = range ? value[oppositeIndex] : value\n\n return {\n max: range ? (start ? oppositeValue - betweenThumbs : max) : max,\n min: range ? (start ? min : oppositeValue + betweenThumbs) : min,\n }\n },\n [betweenThumbs, max, min, range, value],\n )\n\n const getPanValue = useCallback(\n ({ x, y }: Point, { bottom, height, left, width }: DOMRect) => {\n const diff = orientation === \"horizontal\" ? x - left : bottom - y\n const length = orientation === \"horizontal\" ? width : height\n const percent = diff / length\n\n let nextValue = percentToValue(percent, min, max)\n\n nextValue = parseFloat(roundNumberToStep(nextValue, min, step))\n nextValue = clampNumber(nextValue, min, max)\n\n return nextValue\n },\n [orientation, min, max, step],\n )\n\n const onChange = useCallback(\n (index: number, value: number) => {\n if (!interactive) return\n\n const { max, min } = getMinMax(index)\n\n value = parseFloat(roundNumberToStep(value, min, oneStep))\n value = clampNumber(value, min, max)\n\n setValue((prev) => {\n if (isArray(prev)) {\n const next = [...prev]\n\n next[index] = value\n\n return next as Y\n } else {\n return value as Y\n }\n })\n },\n [getMinMax, interactive, oneStep, setValue],\n )\n\n const stepUp = useCallback(\n (index: number, step = oneStep) =>\n range\n ? onChange(index, value[index]! + step)\n : onChange(index, value + step),\n [oneStep, range, onChange, value],\n )\n\n const stepDown = useCallback(\n (index: number, step = oneStep) =>\n range\n ? onChange(index, value[index]! - step)\n : onChange(index, value - step),\n [oneStep, range, onChange, value],\n )\n\n const onKeyDown = useCallback(\n (index: number) => (ev: KeyboardEvent<HTMLDivElement>) => {\n const { max, min } = getMinMax(index)\n\n runKeyAction(ev, {\n ArrowDown: () => stepDown(index),\n ArrowLeft: () => stepDown(index),\n ArrowRight: () => stepUp(index),\n ArrowUp: () => stepUp(index),\n End: () => onChange(index, max),\n Home: () => onChange(index, min),\n PageDown: () => stepDown(index, tenStep),\n PageUp: () => stepUp(index, tenStep),\n })\n },\n [getMinMax, onChange, stepDown, stepUp, tenStep],\n )\n\n const getRootProps: PropGetter = useCallback(\n (props = {}) => {\n const computedProps: HTMLProps = mergeProps(\n dataProps,\n { \"data-orientation\": orientation },\n rest,\n props,\n { onBlur: eventProps.onBlur, onFocus: eventProps.onFocus },\n )()\n\n computedProps.style ??= {}\n\n if (isArray(percent)) {\n computedProps.style[\"--range-start\"] = `${Math.abs(percent[0]!)}%`\n computedProps.style[\"--range-end\"] = `${Math.abs(percent[1]!)}%`\n } else {\n computedProps.style[\"--range-start\"] = \"0%\"\n computedProps.style[\"--range-end\"] = `${Math.abs(percent)}%`\n }\n\n return computedProps\n },\n [dataProps, eventProps, orientation, percent, rest],\n )\n\n const getInputProps: PropGetter<\"input\", { index?: number }> = useCallback(\n ({ index = 0, ...props } = {}) => ({\n ...visuallyHiddenAttributes,\n ...dataProps,\n ...ariaProps,\n id,\n type: \"hidden\",\n name,\n disabled,\n readOnly,\n required,\n value: range ? value[index]! : value,\n ...props,\n ref: index === 0 ? mergeRefs(props.ref, ref) : props.ref,\n }),\n [\n dataProps,\n ariaProps,\n id,\n name,\n disabled,\n readOnly,\n required,\n range,\n value,\n ref,\n ],\n )\n\n const getTrackProps: PropGetter = useCallback(\n (props) =>\n getPanEventProps({\n ...dataProps,\n \"data-orientation\": orientation,\n ...props,\n }),\n [dataProps, getPanEventProps, orientation],\n )\n\n const getRangeProps: PropGetter = useCallback(\n (props) => ({\n ...dataProps,\n \"data-orientation\": orientation,\n \"data-range\": dataAttr(range),\n ...props,\n }),\n [dataProps, orientation, range],\n )\n\n const getMarkProps: RequiredPropGetter<\"div\", { value: number }> =\n useCallback(\n ({ style, value: valueProp, ...props }) => {\n const between = range\n ? value[0] < valueProp && valueProp < value[1]\n : valueProp < value\n const percent = valueToPercent(valueProp, min, max)\n\n return {\n ...dataProps,\n \"aria-hidden\": true,\n \"data-between\": dataAttr(between),\n \"data-orientation\": orientation,\n role: \"presentation\",\n ...props,\n style: { ...style, \"--mark-position\": `${percent}%` },\n }\n },\n [dataProps, max, min, orientation, range, value],\n )\n\n const getThumbProps: PropGetter<\"div\", { index?: number }> = useCallback(\n ({ index = 0, ...rest } = {}) => {\n const { max, min } = getMinMax(index)\n\n return mergeProps(\n {\n ...dataProps,\n ...ariaProps,\n \"aria-label\": t(\"Slider thumb\"),\n \"aria-labelledby\": ariaLabelledBy,\n \"aria-orientation\": orientation,\n \"aria-valuemax\": max,\n \"aria-valuemin\": min,\n role: \"slider\",\n tabIndex: interactive ? 0 : -1,\n },\n range\n ? {\n \"aria-valuenow\": value[index]!,\n \"aria-valuetext\":\n ariaValueText ??\n getAriaValueText?.(value[index]!, index) ??\n value[index]!.toString(),\n \"data-end\": dataAttr(index === 1),\n \"data-start\": dataAttr(index === 0),\n }\n : {\n \"aria-valuenow\": value,\n \"aria-valuetext\":\n ariaValueText ??\n getAriaValueText?.(value, index) ??\n value.toString(),\n \"data-end\": dataAttr(index === 0),\n },\n rest,\n { onKeyDown: onKeyDown(index) },\n )()\n },\n [\n t,\n ariaLabelledBy,\n ariaProps,\n ariaValueText,\n dataProps,\n getAriaValueText,\n getMinMax,\n interactive,\n onKeyDown,\n orientation,\n range,\n value,\n ],\n )\n\n return {\n percent,\n range,\n setValue,\n stepDown,\n stepUp,\n value,\n getInputProps,\n getMarkProps,\n getRangeProps,\n getRootProps,\n getThumbProps,\n getTrackProps,\n onChange,\n }\n}\n\nexport type UseSliderReturn = ReturnType<typeof useSlider>\n"],"mappings":";;;;;;;;;;;AAyGA,MAAa,aACX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A,CAAe,WAAW,KAAK,GAAG;GAElD,OAAO;IACL,GAAG;IACH,eAAe;IACf,iBAAA,GAAgBK,cAAAA,SAAAA,CAAS,OAAO;IAChC,oBAAoB;IACpB,MAAM;IACN,GAAG;IACH,OAAO;KAAE,GAAG;KAAO,mBAAmB,GAAG,QAAQ;IAAG;GACtD;EACF,GACA;GAAC;GAAW;GAAK;GAAK;GAAa;GAAO;EAAK,CAiEtC;EACX;EACA;EACA,eAjE2D,aAC1D,EAAE,QAAQ,GAAG,GAAG,SAAS,CAAC,MAAM;GAC/B,MAAM,EAAE,KAAK,QAAQ,UAAU,KAAK;GAEpC,OAAO,WACL;IACE,GAAG;IACH,GAAG;IACH,cAAc,EAAE,cAAc;IAC9B,mBAAmB;IACnB,oBAAoB;IACpB,iBAAiB;IACjB,iBAAiB;IACjB,MAAM;IACN,UAAU,cAAc,IAAI;GAC9B,GACA,QACI;IACE,iBAAiB,MAAM;IACvB,kBACE,iBACA,mBAAmB,MAAM,QAAS,KAAK,KACvC,MAAM,MAAM,CAAE,SAAS;IACzB,aAAA,GAAYA,cAAAA,SAAAA,CAAS,UAAU,CAAC;IAChC,eAAA,GAAcA,cAAAA,SAAAA,CAAS,UAAU,CAAC;GACpC,IACA;IACE,iBAAiB;IACjB,kBACE,iBACA,mBAAmB,OAAO,KAAK,KAC/B,MAAM,SAAS;IACjB,aAAA,GAAYA,cAAAA,SAAAA,CAAS,UAAU,CAAC;GAClC,GACJ,MACA,EAAE,WAAW,UAAU,KAAK,EAAE,CAChC,CAAC,CAAC;EACJ,GACA;GACE;GACA;GACA;GACA;GACA;GACA;GACA;GACA;GACA;GACA;GACA;GACA;EACF,CAcY;EACZ;EACA;CACF;AACF"}
@@ -1,7 +1,6 @@
1
1
  "use client";
2
2
  import { createContext as createContext$1 } from "../../utils/context.js";
3
3
  import { useSafeLayoutEffect } from "../../utils/effect.js";
4
- import { mergeRefs } from "../../utils/ref.js";
5
4
  import { utils_exports } from "../../utils/index.js";
6
5
  import { useEnvironment } from "../../core/system/environment-provider.js";
7
6
  import { mergeProps } from "../../core/components/props.js";
@@ -78,7 +77,7 @@ const useSteps = ({ count = 0, defaultIndex = 0, index: indexProp, orientation =
78
77
  onPrev
79
78
  };
80
79
  };
81
- const useStepsItem = ({ "aria-labelledby": ariaLabelledbyProp, index, ...rest }) => {
80
+ const useStepsItem = ({ index, ...rest }) => {
82
81
  const { descendants, register } = useStepsDescendant();
83
82
  const { id, getStatus, orientation } = useStepsContext();
84
83
  const status = getStatus(index);
@@ -97,13 +96,12 @@ const useStepsItem = ({ "aria-labelledby": ariaLabelledbyProp, index, ...rest })
97
96
  id,
98
97
  index
99
98
  ]);
100
- const getRootProps = useCallback(({ ref, "aria-labelledby": ariaLabelledby, ...props } = {}) => mergeProps({
99
+ const getRootProps = useCallback((props = {}) => mergeProps({
100
+ ref: register,
101
101
  "aria-current": current ? "step" : void 0,
102
- "aria-labelledby": (0, utils_exports.cx)(ariaLabelledbyProp, ariaLabelledby),
103
102
  "data-orientation": orientation,
104
103
  [statusDataAttr]: (0, utils_exports.dataAttr)(true)
105
- }, rest, props, { ref: mergeRefs(ref, register) })(), [
106
- ariaLabelledbyProp,
104
+ }, rest, props)(), [
107
105
  current,
108
106
  orientation,
109
107
  statusDataAttr,
@@ -1 +1 @@
1
- {"version":3,"file":"use-steps.js","names":["createContext","handlerAll","cx","dataAttr"],"sources":["../../../../src/components/steps/use-steps.ts"],"sourcesContent":["\"use client\"\n\nimport type { HTMLProps, Orientation, PropGetter } from \"../../core\"\nimport { useCallback, useId } from \"react\"\nimport { mergeProps, useEnvironment } from \"../../core\"\nimport { useControllableState } from \"../../hooks/use-controllable-state\"\nimport { createDescendants } from \"../../hooks/use-descendants\"\nimport {\n createContext,\n cx,\n dataAttr,\n handlerAll,\n mergeRefs,\n setAttribute,\n useSafeLayoutEffect,\n} from \"../../utils\"\n\nexport type StepStatusScheme = \"complete\" | \"current\" | \"incomplete\"\n\nconst {\n DescendantsContext: StepsDescendantsContext,\n useDescendant: useStepsDescendant,\n useDescendants: useStepsDescendants,\n} = createDescendants<HTMLLIElement>()\n\nexport { StepsDescendantsContext, useStepsDescendant, useStepsDescendants }\n\ninterface StepsContext extends Omit<\n UseStepsReturn,\n \"descendants\" | \"getRootProps\"\n> {}\n\nconst [StepsContext, useStepsContext] = createContext<StepsContext>({\n name: \"StepsContext\",\n})\n\nexport { StepsContext, useStepsContext }\n\ninterface StepsItemContext extends Omit<UseStepsItemReturn, \"getRootProps\"> {}\n\nconst [StepsItemContext, useStepsItemContext] = createContext<StepsItemContext>(\n {\n name: \"StepsItemContext\",\n },\n)\n\nexport { StepsItemContext, useStepsItemContext }\n\nexport interface UseStepsProps extends Omit<HTMLProps, \"onChange\"> {\n /**\n * The total number of steps.\n */\n count?: number\n /**\n * The initial index of the active step.\n *\n * @default 0\n */\n defaultIndex?: number\n /**\n * The index of the active step.\n */\n index?: number\n /**\n * The orientation of the steps.\n *\n * @default 'horizontal'\n */\n orientation?: Orientation\n /**\n * The callback function that is called when the active step index is changed.\n */\n onChange?: (index: number) => void\n}\n\nexport const useSteps = ({\n count = 0,\n defaultIndex = 0,\n index: indexProp,\n orientation = \"horizontal\",\n onChange,\n ...rest\n}: UseStepsProps = {}) => {\n const descendants = useStepsDescendants()\n const [index, setIndex] = useControllableState({\n defaultValue: defaultIndex,\n value: indexProp,\n onChange,\n })\n const id = useId()\n\n const getStatus = useCallback(\n (indexProp: number): StepStatusScheme => {\n if (indexProp < index) return \"complete\"\n else if (indexProp > index) return \"incomplete\"\n else return \"current\"\n },\n [index],\n )\n\n const onPrev = useCallback(\n () => setIndex((index) => Math.max(0, index - 1)),\n [setIndex],\n )\n\n const onNext = useCallback(() => {\n setIndex((index) => Math.min(count, index + 1))\n }, [count, setIndex])\n\n const getRootProps: PropGetter = useCallback(\n (props = {}) => mergeProps(rest, props)(),\n [rest],\n )\n\n const getListProps: PropGetter<\"ol\"> = useCallback(\n (props) => {\n return {\n \"data-orientation\": orientation,\n ...props,\n }\n },\n [orientation],\n )\n\n const getContentProps: PropGetter<\"div\", { index?: number }> = useCallback(\n ({ index: indexProp = count, ...props } = {}) => ({\n id: `${id}-${indexProp}`,\n hidden: indexProp !== index,\n tabIndex: 0,\n ...props,\n }),\n [count, id, index],\n )\n\n const getPrevTriggerProps: PropGetter<\"button\"> = useCallback(\n (props = {}) => ({\n disabled: index === 0,\n ...props,\n onClick: handlerAll(props.onClick, onPrev),\n }),\n [onPrev, index],\n )\n\n const getNextTriggerProps: PropGetter<\"button\"> = useCallback(\n (props = {}) => {\n return {\n disabled: count <= index,\n ...props,\n onClick: handlerAll(props.onClick, onNext),\n }\n },\n [count, index, onNext],\n )\n\n return {\n id,\n count,\n descendants,\n getStatus,\n index,\n orientation,\n setIndex,\n getContentProps,\n getListProps,\n getNextTriggerProps,\n getPrevTriggerProps,\n getRootProps,\n onNext,\n onPrev,\n }\n}\n\nexport type UseStepsReturn = ReturnType<typeof useSteps>\n\nexport interface UseStepsItemProps extends HTMLProps<\"li\"> {\n /**\n * The index of the step.\n */\n index: number\n}\n\nexport const useStepsItem = ({\n \"aria-labelledby\": ariaLabelledbyProp,\n index,\n ...rest\n}: UseStepsItemProps) => {\n const { descendants, register } = useStepsDescendant()\n const { id, getStatus, orientation } = useStepsContext()\n const status = getStatus(index)\n const current = status === \"current\"\n const first = index === 0\n const last = index === descendants.lastValue()?.index\n const statusDataAttr = `data-${status}`\n const { getDocument } = useEnvironment()\n\n useSafeLayoutEffect(() => {\n const el = descendants.value(index)?.node\n const hasContent = !!getDocument()?.getElementById(`${id}-${index}`)\n\n if (el && hasContent) setAttribute(el, \"aria-labelledby\", `${id}-${index}`)\n }, [descendants, getDocument, id, index])\n\n const getRootProps: PropGetter<\"li\"> = useCallback(\n ({ ref, \"aria-labelledby\": ariaLabelledby, ...props } = {}) =>\n mergeProps(\n {\n \"aria-current\": current ? \"step\" : undefined,\n \"aria-labelledby\": cx(ariaLabelledbyProp, ariaLabelledby),\n \"data-orientation\": orientation,\n [statusDataAttr]: dataAttr(true),\n },\n rest,\n props,\n { ref: mergeRefs(ref, register) },\n )(),\n [ariaLabelledbyProp, current, orientation, statusDataAttr, rest, register],\n )\n\n const getTitleProps: PropGetter<\"h3\"> = useCallback(\n (props) => ({\n [statusDataAttr]: dataAttr(true),\n ...props,\n }),\n [statusDataAttr],\n )\n\n const getDescriptionProps: PropGetter<\"p\"> = useCallback(\n (props) => ({\n [statusDataAttr]: dataAttr(true),\n ...props,\n }),\n [statusDataAttr],\n )\n\n const getIndicatorProps: PropGetter = useCallback(\n (props) => ({\n [statusDataAttr]: dataAttr(true),\n ...props,\n }),\n [statusDataAttr],\n )\n\n const getSeparatorProps: PropGetter = useCallback(\n (props) => ({\n \"data-orientation\": orientation,\n role: \"separator\",\n [statusDataAttr]: dataAttr(true),\n ...props,\n }),\n [orientation, statusDataAttr],\n )\n\n return {\n first,\n index,\n last,\n status,\n getDescriptionProps,\n getIndicatorProps,\n getRootProps,\n getSeparatorProps,\n getTitleProps,\n }\n}\n\nexport type UseStepsItemReturn = ReturnType<typeof useStepsItem>\n"],"mappings":";;;;;;;;;;;AAmBA,MAAM,EACJ,oBAAoB,yBACpB,eAAe,oBACf,gBAAgB,wBACd,kBAAiC;AASrC,MAAM,CAAC,cAAc,mBAAmBA,gBAA4B,EAClE,MAAM,eACR,CAAC;AAMD,MAAM,CAAC,kBAAkB,uBAAuBA,gBAC9C,EACE,MAAM,mBACR,CACF;AA+BA,MAAa,YAAY,EACvB,QAAQ,GACR,eAAe,GACf,OAAO,WACP,cAAc,cACd,UACA,GAAG,SACc,CAAC,MAAM;CACxB,MAAM,cAAc,oBAAoB;CACxC,MAAM,CAAC,OAAO,YAAY,qBAAqB;EAC7C,cAAc;EACd,OAAO;EACP;CACF,CAAC;CACD,MAAM,KAAK,MAAM;CAEjB,MAAM,YAAY,aACf,cAAwC;EACvC,IAAI,YAAY,OAAO,OAAO;OACzB,IAAI,YAAY,OAAO,OAAO;OAC9B,OAAO;CACd,GACA,CAAC,K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AAoB;GACpB,MAAM;IACL,kBAAA,GAAiBA,cAAAA,SAAAA,CAAS,IAAI;GAC/B,GAAG;EACL,IACA,CAAC,aAAa,cAAc,CAWZ;EAChB;CACF;AACF"}
1
+ {"version":3,"file":"use-steps.js","names":["createContext","handlerAll","dataAttr"],"sources":["../../../../src/components/steps/use-steps.ts"],"sourcesContent":["\"use client\"\n\nimport type { HTMLProps, Orientation, PropGetter } from \"../../core\"\nimport { useCallback, useId } from \"react\"\nimport { mergeProps, useEnvironment } from \"../../core\"\nimport { useControllableState } from \"../../hooks/use-controllable-state\"\nimport { createDescendants } from \"../../hooks/use-descendants\"\nimport {\n createContext,\n dataAttr,\n handlerAll,\n setAttribute,\n useSafeLayoutEffect,\n} from \"../../utils\"\n\nexport type StepStatusScheme = \"complete\" | \"current\" | \"incomplete\"\n\nconst {\n DescendantsContext: StepsDescendantsContext,\n useDescendant: useStepsDescendant,\n useDescendants: useStepsDescendants,\n} = createDescendants<HTMLLIElement>()\n\nexport { StepsDescendantsContext, useStepsDescendant, useStepsDescendants }\n\ninterface StepsContext extends Omit<\n UseStepsReturn,\n \"descendants\" | \"getRootProps\"\n> {}\n\nconst [StepsContext, useStepsContext] = createContext<StepsContext>({\n name: \"StepsContext\",\n})\n\nexport { StepsContext, useStepsContext }\n\ninterface StepsItemContext extends Omit<UseStepsItemReturn, \"getRootProps\"> {}\n\nconst [StepsItemContext, useStepsItemContext] = createContext<StepsItemContext>(\n {\n name: \"StepsItemContext\",\n },\n)\n\nexport { StepsItemContext, useStepsItemContext }\n\nexport interface UseStepsProps extends Omit<HTMLProps, \"onChange\"> {\n /**\n * The total number of steps.\n */\n count?: number\n /**\n * The initial index of the active step.\n *\n * @default 0\n */\n defaultIndex?: number\n /**\n * The index of the active step.\n */\n index?: number\n /**\n * The orientation of the steps.\n *\n * @default 'horizontal'\n */\n orientation?: Orientation\n /**\n * The callback function that is called when the active step index is changed.\n */\n onChange?: (index: number) => void\n}\n\nexport const useSteps = ({\n count = 0,\n defaultIndex = 0,\n index: indexProp,\n orientation = \"horizontal\",\n onChange,\n ...rest\n}: UseStepsProps = {}) => {\n const descendants = useStepsDescendants()\n const [index, setIndex] = useControllableState({\n defaultValue: defaultIndex,\n value: indexProp,\n onChange,\n })\n const id = useId()\n\n const getStatus = useCallback(\n (indexProp: number): StepStatusScheme => {\n if (indexProp < index) return \"complete\"\n else if (indexProp > index) return \"incomplete\"\n else return \"current\"\n },\n [index],\n )\n\n const onPrev = useCallback(\n () => setIndex((index) => Math.max(0, index - 1)),\n [setIndex],\n )\n\n const onNext = useCallback(() => {\n setIndex((index) => Math.min(count, index + 1))\n }, [count, setIndex])\n\n const getRootProps: PropGetter = useCallback(\n (props = {}) => mergeProps(rest, props)(),\n [rest],\n )\n\n const getListProps: PropGetter<\"ol\"> = useCallback(\n (props) => {\n return {\n \"data-orientation\": orientation,\n ...props,\n }\n },\n [orientation],\n )\n\n const getContentProps: PropGetter<\"div\", { index?: number }> = useCallback(\n ({ index: indexProp = count, ...props } = {}) => ({\n id: `${id}-${indexProp}`,\n hidden: indexProp !== index,\n tabIndex: 0,\n ...props,\n }),\n [count, id, index],\n )\n\n const getPrevTriggerProps: PropGetter<\"button\"> = useCallback(\n (props = {}) => ({\n disabled: index === 0,\n ...props,\n onClick: handlerAll(props.onClick, onPrev),\n }),\n [onPrev, index],\n )\n\n const getNextTriggerProps: PropGetter<\"button\"> = useCallback(\n (props = {}) => {\n return {\n disabled: count <= index,\n ...props,\n onClick: handlerAll(props.onClick, onNext),\n }\n },\n [count, index, onNext],\n )\n\n return {\n id,\n count,\n descendants,\n getStatus,\n index,\n orientation,\n setIndex,\n getContentProps,\n getListProps,\n getNextTriggerProps,\n getPrevTriggerProps,\n getRootProps,\n onNext,\n onPrev,\n }\n}\n\nexport type UseStepsReturn = ReturnType<typeof useSteps>\n\nexport interface UseStepsItemProps extends HTMLProps<\"li\"> {\n /**\n * The index of the step.\n */\n index: number\n}\n\nexport const useStepsItem = ({ index, ...rest }: UseStepsItemProps) => {\n const { descendants, register } = useStepsDescendant()\n const { id, getStatus, orientation } = useStepsContext()\n const status = getStatus(index)\n const current = status === \"current\"\n const first = index === 0\n const last = index === descendants.lastValue()?.index\n const statusDataAttr = `data-${status}`\n const { getDocument } = useEnvironment()\n\n useSafeLayoutEffect(() => {\n const el = descendants.value(index)?.node\n const hasContent = !!getDocument()?.getElementById(`${id}-${index}`)\n\n if (el && hasContent) setAttribute(el, \"aria-labelledby\", `${id}-${index}`)\n }, [descendants, getDocument, id, index])\n\n const getRootProps: PropGetter<\"li\"> = useCallback(\n (props = {}) =>\n mergeProps(\n {\n ref: register,\n \"aria-current\": current ? \"step\" : undefined,\n \"data-orientation\": orientation,\n [statusDataAttr]: dataAttr(true),\n },\n rest,\n props,\n )(),\n [current, orientation, statusDataAttr, rest, register],\n )\n\n const getTitleProps: PropGetter<\"h3\"> = useCallback(\n (props) => ({\n [statusDataAttr]: dataAttr(true),\n ...props,\n }),\n [statusDataAttr],\n )\n\n const getDescriptionProps: PropGetter<\"p\"> = useCallback(\n (props) => ({\n [statusDataAttr]: dataAttr(true),\n ...props,\n }),\n [statusDataAttr],\n )\n\n const getIndicatorProps: PropGetter = useCallback(\n (props) => ({\n [statusDataAttr]: dataAttr(true),\n ...props,\n }),\n [statusDataAttr],\n )\n\n const getSeparatorProps: PropGetter = useCallback(\n (props) => ({\n \"data-orientation\": orientation,\n role: \"separator\",\n [statusDataAttr]: dataAttr(true),\n ...props,\n }),\n [orientation, statusDataAttr],\n )\n\n return {\n first,\n index,\n last,\n status,\n getDescriptionProps,\n getIndicatorProps,\n getRootProps,\n getSeparatorProps,\n getTitleProps,\n }\n}\n\nexport type UseStepsItemReturn = ReturnType<typeof useStepsItem>\n"],"mappings":";;;;;;;;;;AAiBA,MAAM,EACJ,oBAAoB,yBACpB,eAAe,oBACf,gBAAgB,wBACd,kBAAiC;AASrC,MAAM,CAAC,cAAc,mBAAmBA,gBAA4B,EAClE,MAAM,eACR,CAAC;AAMD,MAAM,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C,WAAW;IACT,kBAAA,GAAiBA,cAAAA,SAAAA,CAAS,IAAI;GAC/B,GAAG;EACL,IACA,CAAC,cAAc,CA0BG;EAClB,mBAxBoC,aACnC,WAAW;IACT,kBAAA,GAAiBA,cAAAA,SAAAA,CAAS,IAAI;GAC/B,GAAG;EACL,IACA,CAAC,cAAc,CAmBC;EAChB;EACA,mBAlBoC,aACnC,WAAW;GACV,oBAAoB;GACpB,MAAM;IACL,kBAAA,GAAiBA,cAAAA,SAAAA,CAAS,IAAI;GAC/B,GAAG;EACL,IACA,CAAC,aAAa,cAAc,CAWZ;EAChB;CACF;AACF"}
@@ -134,7 +134,7 @@ const useTab = ({ id, disabled, index, ...rest }) => {
134
134
  ])
135
135
  };
136
136
  };
137
- const useTabPanel = ({ id, "aria-labelledby": ariaLabelledbyProp, index, ...rest }) => {
137
+ const useTabPanel = ({ id, index, ...rest }) => {
138
138
  const { id: rootId, index: selectedIndex, orientation } = useTabsContext();
139
139
  const { register } = useTabPanelDescendant();
140
140
  const tabId = `${rootId}-tab-${index}`;
@@ -143,16 +143,16 @@ const useTabPanel = ({ id, "aria-labelledby": ariaLabelledbyProp, index, ...rest
143
143
  return {
144
144
  index,
145
145
  selected,
146
- getRootProps: useCallback(({ ref, "aria-labelledby": ariaLabelledby, ...props } = {}) => mergeProps({
146
+ getRootProps: useCallback((props = {}) => mergeProps({
147
147
  id,
148
- "aria-labelledby": (0, utils_exports.cx)(ariaLabelledbyProp, ariaLabelledby, tabId),
148
+ ref: register,
149
+ "aria-labelledby": tabId,
149
150
  "data-orientation": orientation,
150
151
  hidden: !selected,
151
152
  role: "tabpanel",
152
153
  tabIndex: selected ? 0 : -1
153
- }, rest, props, { ref: mergeRefs(ref, register) })(), [
154
+ }, rest, props)(), [
154
155
  id,
155
- ariaLabelledbyProp,
156
156
  orientation,
157
157
  register,
158
158
  rest,
@@ -1 +1 @@
1
- {"version":3,"file":"use-tabs.js","names":["createContext","isUndefined","handlerAll","cx"],"sources":["../../../../src/components/tabs/use-tabs.ts"],"sourcesContent":["\"use client\"\n\nimport type { KeyboardEvent } from \"react\"\nimport type { HTMLProps, Orientation, PropGetter } from \"../../core\"\nimport { useCallback, useId, useState } from \"react\"\nimport { mergeProps } from \"../../core\"\nimport { useControllableState } from \"../../hooks/use-controllable-state\"\nimport { createDescendants } from \"../../hooks/use-descendants\"\nimport {\n createContext,\n cx,\n handlerAll,\n isUndefined,\n mergeRefs,\n runKeyAction,\n useUpdateEffect,\n} from \"../../utils\"\n\nconst {\n DescendantsContext: TabDescendantsContext,\n useDescendant: useTabDescendant,\n useDescendants: useTabDescendants,\n} = createDescendants<HTMLButtonElement>()\n\nexport { TabDescendantsContext, useTabDescendant, useTabDescendants }\n\nconst {\n DescendantsContext: TabPanelDescendantsContext,\n useDescendant: useTabPanelDescendant,\n useDescendants: useTabPanelDescendants,\n} = createDescendants<HTMLDivElement>()\n\nexport {\n TabPanelDescendantsContext,\n useTabPanelDescendant,\n useTabPanelDescendants,\n}\n\ninterface TabsContext extends Omit<\n UseTabsReturn,\n \"getRootProps\" | \"tabDescendants\" | \"tabPanelDescendants\"\n> {}\n\nconst [TabsContext, useTabsContext] = createContext<TabsContext>({\n name: \"TabsContext\",\n})\n\nexport { TabsContext, useTabsContext }\n\nexport interface UseTabsProps extends Omit<HTMLProps, \"onChange\"> {\n /**\n * The index of the selected tab.\n */\n defaultIndex?: number\n /**\n * The index of the selected tab.\n */\n index?: number\n /**\n * If `true`, the tabs will be manually activated and display its panel by pressing Space or Enter.\n *\n * If `false`, the tabs will be automatically activated and their panel is displayed when they receive focus.\n *\n * @default false\n */\n manual?: boolean\n /**\n * The orientation of the tabs.\n *\n * @default 'horizontal'\n */\n orientation?: Orientation\n /**\n * The callback invoked when the index changes.\n */\n onChange?: (index: number) => void\n}\n\nexport const useTabs = ({\n id,\n defaultIndex = 0,\n index: indexProp,\n manual = false,\n orientation = \"horizontal\",\n onChange,\n ...rest\n}: UseTabsProps = {}) => {\n const uuid = useId()\n const tabDescendants = useTabDescendants()\n const tabPanelDescendants = useTabPanelDescendants()\n const [index, setIndex] = useControllableState({\n defaultValue: defaultIndex,\n value: indexProp,\n onChange,\n })\n const [focusedIndex, setFocusedIndex] = useState<number>(index)\n const horizontal = orientation === \"horizontal\"\n\n id ??= uuid\n\n const onFocusFirstTab = useCallback(() => {\n const first = tabDescendants.enabledFirstValue()\n\n if (first) first.node.focus()\n }, [tabDescendants])\n\n const onFocusLastTab = useCallback(() => {\n const last = tabDescendants.enabledLastValue()\n\n if (last) last.node.focus()\n }, [tabDescendants])\n\n const onFocusNextTab = useCallback(() => {\n const next = tabDescendants.enabledNextValue(focusedIndex)\n\n if (next) next.node.focus()\n }, [tabDescendants, focusedIndex])\n\n const onFocusPrevTab = useCallback(() => {\n const prev = tabDescendants.enabledPrevValue(focusedIndex)\n\n if (prev) prev.node.focus()\n }, [tabDescendants, focusedIndex])\n\n const onKeyDown = useCallback(\n (ev: KeyboardEvent<HTMLDivElement>) => {\n runKeyAction(ev, {\n ArrowDown: !horizontal ? onFocusNextTab : undefined,\n ArrowLeft: horizontal ? onFocusPrevTab : undefined,\n ArrowRight: horizontal ? onFocusNextTab : undefined,\n ArrowUp: !horizontal ? onFocusPrevTab : undefined,\n End: onFocusLastTab,\n Home: onFocusFirstTab,\n })\n },\n [\n horizontal,\n onFocusNextTab,\n onFocusPrevTab,\n onFocusLastTab,\n onFocusFirstTab,\n ],\n )\n\n useUpdateEffect(() => {\n if (isUndefined(indexProp)) return\n\n setIndex(indexProp)\n setFocusedIndex(indexProp)\n }, [indexProp])\n\n const getRootProps: PropGetter = useCallback(\n ({ ref, ...props } = {}) =>\n mergeProps({ \"data-orientation\": orientation }, rest, props, { ref })(),\n [orientation, rest],\n )\n\n const getListProps: PropGetter = useCallback(\n (props = {}) => ({\n \"aria-orientation\": orientation,\n role: \"tablist\",\n ...props,\n onKeyDown: handlerAll(props.onKeyDown, onKeyDown),\n }),\n [orientation, onKeyDown],\n )\n\n return {\n id,\n focusedIndex,\n index,\n manual,\n orientation,\n setFocusedIndex,\n setIndex,\n tabDescendants,\n tabPanelDescendants,\n getListProps,\n getRootProps,\n }\n}\n\nexport type UseTabsReturn = ReturnType<typeof useTabs>\n\nexport interface UseTabProps extends HTMLProps<\"button\"> {\n /**\n * The index of the tab.\n */\n index: number\n}\n\nexport const useTab = ({ id, disabled, index, ...rest }: UseTabProps) => {\n const {\n id: rootId,\n index: selectedIndex,\n manual,\n orientation,\n setFocusedIndex,\n setIndex,\n } = useTabsContext()\n const { register } = useTabDescendant({ disabled })\n const tabPanelId = `${rootId}-panel-${index}`\n const selected = index === selectedIndex\n\n id ??= `${rootId}-tab-${index}`\n\n const onClick = useCallback(() => {\n if (!disabled) setIndex(index)\n }, [index, setIndex, disabled])\n\n const onFocus = useCallback(() => {\n if (disabled) return\n\n setFocusedIndex(index)\n\n if (!manual) setIndex(index)\n }, [setFocusedIndex, index, manual, disabled, setIndex])\n\n const getRootProps: PropGetter<\"button\"> = useCallback(\n ({ ref, ...props } = {}) =>\n mergeProps(\n {\n id,\n type: \"button\",\n \"aria-controls\": tabPanelId,\n \"aria-selected\": selected,\n \"data-orientation\": orientation,\n disabled,\n role: \"tab\",\n tabIndex: selected ? 0 : -1,\n },\n rest,\n props,\n { ref: mergeRefs(ref, register) },\n {\n onClick: handlerAll(props.onClick, rest.onClick, onClick),\n onFocus: handlerAll(props.onFocus, rest.onFocus, onFocus),\n },\n )({ mergeEvent: false }),\n [\n disabled,\n id,\n onClick,\n onFocus,\n orientation,\n register,\n rest,\n selected,\n tabPanelId,\n ],\n )\n\n return { index, selected, getRootProps }\n}\n\nexport type UseTabReturn = ReturnType<typeof useTab>\n\nexport interface UseTabPanelProps extends HTMLProps {\n /**\n * The index of the tab panel.\n */\n index: number\n}\n\nexport const useTabPanel = ({\n id,\n \"aria-labelledby\": ariaLabelledbyProp,\n index,\n ...rest\n}: UseTabPanelProps) => {\n const { id: rootId, index: selectedIndex, orientation } = useTabsContext()\n const { register } = useTabPanelDescendant()\n const tabId = `${rootId}-tab-${index}`\n const selected = index === selectedIndex\n\n id ??= `${rootId}-panel-${index}`\n\n const getRootProps: PropGetter = useCallback(\n ({ ref, \"aria-labelledby\": ariaLabelledby, ...props } = {}) =>\n mergeProps(\n {\n id,\n \"aria-labelledby\": cx(ariaLabelledbyProp, ariaLabelledby, tabId),\n \"data-orientation\": orientation,\n hidden: !selected,\n role: \"tabpanel\",\n tabIndex: selected ? 0 : -1,\n },\n rest,\n props,\n { ref: mergeRefs(ref, register) },\n )(),\n [id, ariaLabelledbyProp, orientation, register, rest, selected, tabId],\n )\n\n return { index, selected, getRootProps }\n}\n\nexport type UseTabPanelReturn = ReturnType<typeof useTabPanel>\n"],"mappings":";;;;;;;;;;;AAkBA,MAAM,EACJ,oBAAoB,uBACpB,eAAe,kBACf,gBAAgB,sBACd,kBAAqC;AAIzC,MAAM,EACJ,oBAAoB,4BACpB,eAAe,uBACf,gBAAgB,2BACd,kBAAkC;AAatC,MAAM,CAAC,aAAa,kBAAkBA,gBAA2B,EAC/D,MAAM,cACR,CAAC;AAiCD,MAAa,WAAW,EACtB,IACA,eAAe,GACf,OAAO,WACP,SAAS,OACT,cAAc,cACd,UACA,GAAG,SACa,CAAC,MAAM;CACvB,MAAM,OAAO,MAAM;CACnB,MAAM,iBAAiB,kBAAkB;CACzC,MAAM,sBAAsB,uBAAuB;CACnD,MAAM,CAAC,OAAO,YAAY,qBAAqB;EAC7C,cAAc;EACd,OAAO;EACP;CACF,CAAC;CACD,MAAM,CAAC,cAAc,mBAAmB,SAAiB,KAAK;CAC9D,MAAM,aAAa,gBAAgB;CAEnC,OAAO;CAEP,MAAM,kBAAkB,kBAAkB;EACxC,MAAM,QAAQ,eAAe,kBAAkB;EAE/C,IAAI,OAAO,MAAM,KAAK,MAAM;CAC9B,GAAG,CAAC,cAAc,CAAC;CAEnB,MAAM,iBAAiB,kBAAkB;EACvC,MAAM,OAAO,eAAe,iBAAiB;EAE7C,IAAI,MAAM,KAAK,KAAK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AO;EAAU,cAlBO,aAC9B,EAAE,KAAK,mBAAmB,gBAAgB,GAAG,UAAU,CAAC,MACvD,WACE;GACE;GACA,oBAAA,GAAmBC,cAAAA,GAAAA,CAAG,oBAAoB,gBAAgB,KAAK;GAC/D,oBAAoB;GACpB,QAAQ,CAAC;GACT,MAAM;GACN,UAAU,WAAW,IAAI;EAC3B,GACA,MACA,OACA,EAAE,KAAK,UAAU,KAAK,QAAQ,EAAE,CAClC,CAAC,CAAC,GACJ;GAAC;GAAI;GAAoB;GAAa;GAAU;GAAM;GAAU;EAAK,CAGlC;CAAE;AACzC"}
1
+ {"version":3,"file":"use-tabs.js","names":["createContext","isUndefined","handlerAll"],"sources":["../../../../src/components/tabs/use-tabs.ts"],"sourcesContent":["\"use client\"\n\nimport type { KeyboardEvent } from \"react\"\nimport type { HTMLProps, Orientation, PropGetter } from \"../../core\"\nimport { useCallback, useId, useState } from \"react\"\nimport { mergeProps } from \"../../core\"\nimport { useControllableState } from \"../../hooks/use-controllable-state\"\nimport { createDescendants } from \"../../hooks/use-descendants\"\nimport {\n createContext,\n handlerAll,\n isUndefined,\n mergeRefs,\n runKeyAction,\n useUpdateEffect,\n} from \"../../utils\"\n\nconst {\n DescendantsContext: TabDescendantsContext,\n useDescendant: useTabDescendant,\n useDescendants: useTabDescendants,\n} = createDescendants<HTMLButtonElement>()\n\nexport { TabDescendantsContext, useTabDescendant, useTabDescendants }\n\nconst {\n DescendantsContext: TabPanelDescendantsContext,\n useDescendant: useTabPanelDescendant,\n useDescendants: useTabPanelDescendants,\n} = createDescendants<HTMLDivElement>()\n\nexport {\n TabPanelDescendantsContext,\n useTabPanelDescendant,\n useTabPanelDescendants,\n}\n\ninterface TabsContext extends Omit<\n UseTabsReturn,\n \"getRootProps\" | \"tabDescendants\" | \"tabPanelDescendants\"\n> {}\n\nconst [TabsContext, useTabsContext] = createContext<TabsContext>({\n name: \"TabsContext\",\n})\n\nexport { TabsContext, useTabsContext }\n\nexport interface UseTabsProps extends Omit<HTMLProps, \"onChange\"> {\n /**\n * The index of the selected tab.\n */\n defaultIndex?: number\n /**\n * The index of the selected tab.\n */\n index?: number\n /**\n * If `true`, the tabs will be manually activated and display its panel by pressing Space or Enter.\n *\n * If `false`, the tabs will be automatically activated and their panel is displayed when they receive focus.\n *\n * @default false\n */\n manual?: boolean\n /**\n * The orientation of the tabs.\n *\n * @default 'horizontal'\n */\n orientation?: Orientation\n /**\n * The callback invoked when the index changes.\n */\n onChange?: (index: number) => void\n}\n\nexport const useTabs = ({\n id,\n defaultIndex = 0,\n index: indexProp,\n manual = false,\n orientation = \"horizontal\",\n onChange,\n ...rest\n}: UseTabsProps = {}) => {\n const uuid = useId()\n const tabDescendants = useTabDescendants()\n const tabPanelDescendants = useTabPanelDescendants()\n const [index, setIndex] = useControllableState({\n defaultValue: defaultIndex,\n value: indexProp,\n onChange,\n })\n const [focusedIndex, setFocusedIndex] = useState<number>(index)\n const horizontal = orientation === \"horizontal\"\n\n id ??= uuid\n\n const onFocusFirstTab = useCallback(() => {\n const first = tabDescendants.enabledFirstValue()\n\n if (first) first.node.focus()\n }, [tabDescendants])\n\n const onFocusLastTab = useCallback(() => {\n const last = tabDescendants.enabledLastValue()\n\n if (last) last.node.focus()\n }, [tabDescendants])\n\n const onFocusNextTab = useCallback(() => {\n const next = tabDescendants.enabledNextValue(focusedIndex)\n\n if (next) next.node.focus()\n }, [tabDescendants, focusedIndex])\n\n const onFocusPrevTab = useCallback(() => {\n const prev = tabDescendants.enabledPrevValue(focusedIndex)\n\n if (prev) prev.node.focus()\n }, [tabDescendants, focusedIndex])\n\n const onKeyDown = useCallback(\n (ev: KeyboardEvent<HTMLDivElement>) => {\n runKeyAction(ev, {\n ArrowDown: !horizontal ? onFocusNextTab : undefined,\n ArrowLeft: horizontal ? onFocusPrevTab : undefined,\n ArrowRight: horizontal ? onFocusNextTab : undefined,\n ArrowUp: !horizontal ? onFocusPrevTab : undefined,\n End: onFocusLastTab,\n Home: onFocusFirstTab,\n })\n },\n [\n horizontal,\n onFocusNextTab,\n onFocusPrevTab,\n onFocusLastTab,\n onFocusFirstTab,\n ],\n )\n\n useUpdateEffect(() => {\n if (isUndefined(indexProp)) return\n\n setIndex(indexProp)\n setFocusedIndex(indexProp)\n }, [indexProp])\n\n const getRootProps: PropGetter = useCallback(\n ({ ref, ...props } = {}) =>\n mergeProps({ \"data-orientation\": orientation }, rest, props, { ref })(),\n [orientation, rest],\n )\n\n const getListProps: PropGetter = useCallback(\n (props = {}) => ({\n \"aria-orientation\": orientation,\n role: \"tablist\",\n ...props,\n onKeyDown: handlerAll(props.onKeyDown, onKeyDown),\n }),\n [orientation, onKeyDown],\n )\n\n return {\n id,\n focusedIndex,\n index,\n manual,\n orientation,\n setFocusedIndex,\n setIndex,\n tabDescendants,\n tabPanelDescendants,\n getListProps,\n getRootProps,\n }\n}\n\nexport type UseTabsReturn = ReturnType<typeof useTabs>\n\nexport interface UseTabProps extends HTMLProps<\"button\"> {\n /**\n * The index of the tab.\n */\n index: number\n}\n\nexport const useTab = ({ id, disabled, index, ...rest }: UseTabProps) => {\n const {\n id: rootId,\n index: selectedIndex,\n manual,\n orientation,\n setFocusedIndex,\n setIndex,\n } = useTabsContext()\n const { register } = useTabDescendant({ disabled })\n const tabPanelId = `${rootId}-panel-${index}`\n const selected = index === selectedIndex\n\n id ??= `${rootId}-tab-${index}`\n\n const onClick = useCallback(() => {\n if (!disabled) setIndex(index)\n }, [index, setIndex, disabled])\n\n const onFocus = useCallback(() => {\n if (disabled) return\n\n setFocusedIndex(index)\n\n if (!manual) setIndex(index)\n }, [setFocusedIndex, index, manual, disabled, setIndex])\n\n const getRootProps: PropGetter<\"button\"> = useCallback(\n ({ ref, ...props } = {}) =>\n mergeProps(\n {\n id,\n type: \"button\",\n \"aria-controls\": tabPanelId,\n \"aria-selected\": selected,\n \"data-orientation\": orientation,\n disabled,\n role: \"tab\",\n tabIndex: selected ? 0 : -1,\n },\n rest,\n props,\n { ref: mergeRefs(ref, register) },\n {\n onClick: handlerAll(props.onClick, rest.onClick, onClick),\n onFocus: handlerAll(props.onFocus, rest.onFocus, onFocus),\n },\n )({ mergeEvent: false }),\n [\n disabled,\n id,\n onClick,\n onFocus,\n orientation,\n register,\n rest,\n selected,\n tabPanelId,\n ],\n )\n\n return { index, selected, getRootProps }\n}\n\nexport type UseTabReturn = ReturnType<typeof useTab>\n\nexport interface UseTabPanelProps extends HTMLProps {\n /**\n * The index of the tab panel.\n */\n index: number\n}\n\nexport const useTabPanel = ({ id, index, ...rest }: UseTabPanelProps) => {\n const { id: rootId, index: selectedIndex, orientation } = useTabsContext()\n const { register } = useTabPanelDescendant()\n const tabId = `${rootId}-tab-${index}`\n const selected = index === selectedIndex\n\n id ??= `${rootId}-panel-${index}`\n\n const getRootProps: PropGetter = useCallback(\n (props = {}) =>\n mergeProps(\n {\n id,\n ref: register,\n \"aria-labelledby\": tabId,\n \"data-orientation\": orientation,\n hidden: !selected,\n role: \"tabpanel\",\n tabIndex: selected ? 0 : -1,\n },\n rest,\n props,\n )(),\n [id, orientation, register, rest, selected, tabId],\n )\n\n return { index, selected, getRootProps }\n}\n\nexport type UseTabPanelReturn = ReturnType<typeof useTabPanel>\n"],"mappings":";;;;;;;;;;;AAiBA,MAAM,EACJ,oBAAoB,uBACpB,eAAe,kBACf,gBAAgB,sBACd,kBAAqC;AAIzC,MAAM,EACJ,oBAAoB,4BACpB,eAAe,uBACf,gBAAgB,2BACd,kBAAkC;AAatC,MAAM,CAAC,aAAa,kBAAkBA,gBAA2B,EAC/D,MAAM,cACR,CAAC;AAiCD,MAAa,WAAW,EACtB,IACA,eAAe,GACf,OAAO,WACP,SAAS,OACT,cAAc,cACd,UACA,GAAG,SACa,CAAC,MAAM;CACvB,MAAM,OAAO,MAAM;CACnB,MAAM,iBAAiB,kBAAkB;CACzC,MAAM,sBAAsB,uBAAuB;CACnD,MAAM,CAAC,OAAO,YAAY,qBAAqB;EAC7C,cAAc;EACd,OAAO;EACP;CACF,CAAC;CACD,MAA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;GACA;EACF,CAGmC;CAAE;AACzC;AAWA,MAAa,eAAe,EAAE,IAAI,OAAO,GAAG,WAA6B;CACvE,MAAM,EAAE,IAAI,QAAQ,OAAO,eAAe,gBAAgB,eAAe;CACzE,MAAM,EAAE,aAAa,sBAAsB;CAC3C,MAAM,QAAQ,GAAG,OAAO,OAAO;CAC/B,MAAM,WAAW,UAAU;CAE3B,OAAO,GAAG,OAAO,SAAS;CAoB1B,OAAO;EAAE;EAAO;EAAU,cAlBO,aAC9B,QAAQ,CAAC,MACR,WACE;GACE;GACA,KAAK;GACL,mBAAmB;GACnB,oBAAoB;GACpB,QAAQ,CAAC;GACT,MAAM;GACN,UAAU,WAAW,IAAI;EAC3B,GACA,MACA,KACF,CAAC,CAAC,GACJ;GAAC;GAAI;GAAa;GAAU;GAAM;GAAU;EAAK,CAGd;CAAE;AACzC"}
@@ -1,8 +1,7 @@
1
1
  "use client";
2
2
  import { useUnmountEffect } from "../../utils/effect.js";
3
- import { mergeRefs } from "../../utils/ref.js";
4
3
  import { utils_exports } from "../../utils/index.js";
5
- import { useSplitProps } from "../../core/components/props.js";
4
+ import { mergeProps, useSplitProps } from "../../core/components/props.js";
6
5
  import { popperProps, usePopper, usePopperProps } from "../../hooks/use-popper/index.js";
7
6
  import { useDisclosure } from "../../hooks/use-disclosure/use-disclosure.js";
8
7
  import { useEventListener } from "../../hooks/use-event-listener/index.js";
@@ -70,21 +69,21 @@ const useTooltip = (props = {}) => {
70
69
  clearTimeout(openTimeout.current);
71
70
  clearTimeout(closeTimeout.current);
72
71
  });
73
- const getTriggerProps = useCallback(({ "aria-describedby": ariaDescribedby, ...props } = {}) => {
74
- return getReferenceProps({
75
- ...props,
76
- ref: mergeRefs(props.ref, triggerRef),
77
- "aria-describedby": (0, utils_exports.cx)(ariaDescribedby, open ? describedbyId : void 0),
78
- onBlur: (0, utils_exports.handlerAll)(props.onBlur, onDelayClose),
79
- onClick: (0, utils_exports.handlerAll)(props.onClick, closeOnClick ? onDelayClose : void 0),
80
- onFocus: (0, utils_exports.handlerAll)(props.onFocus, onDelayOpen),
81
- onPointerEnter: (0, utils_exports.handlerAll)(props.onPointerEnter, (ev) => {
72
+ const getTriggerProps = useCallback((props = {}) => {
73
+ return getReferenceProps(mergeProps(props, {
74
+ ref: triggerRef,
75
+ "aria-describedby": open ? describedbyId : void 0
76
+ }, {
77
+ onBlur: onDelayClose,
78
+ onClick: closeOnClick ? onDelayClose : void 0,
79
+ onFocus: onDelayOpen,
80
+ onPointerEnter: (ev) => {
82
81
  if (ev.pointerType !== "touch") onDelayOpen();
83
- }),
84
- onPointerLeave: (0, utils_exports.handlerAll)(props.onPointerLeave, (ev) => {
82
+ },
83
+ onPointerLeave: (ev) => {
85
84
  if (ev.pointerType !== "touch") onDelayClose();
86
- })
87
- });
85
+ }
86
+ })());
88
87
  }, [
89
88
  getReferenceProps,
90
89
  describedbyId,
@@ -1 +1 @@
1
- {"version":3,"file":"use-tooltip.js","names":["getWindow","getDocument","cx","handlerAll","dataAttr"],"sources":["../../../../src/components/tooltip/use-tooltip.tsx"],"sourcesContent":["\"use client\"\n\nimport type { PropGetter } from \"../../core\"\nimport type { UseDisclosureProps } from \"../../hooks/use-disclosure\"\nimport type { UsePopperProps } from \"../../hooks/use-popper\"\nimport type { Dict } from \"../../utils\"\nimport { useCallback, useId, useRef } from \"react\"\nimport { useSplitProps } from \"../../core\"\nimport { useDisclosure } from \"../../hooks/use-disclosure\"\nimport { useEventListener } from \"../../hooks/use-event-listener\"\nimport { useOutsideClick } from \"../../hooks/use-outside-click\"\nimport { popperProps, usePopper, usePopperProps } from \"../../hooks/use-popper\"\nimport {\n cx,\n dataAttr,\n getDocument,\n getWindow,\n handlerAll,\n mergeRefs,\n useUnmountEffect,\n} from \"../../utils\"\n\nexport interface UseTooltipProps\n extends Omit<UseDisclosureProps, \"timing\">, UsePopperProps<\"button\"> {\n /**\n * The delay before hiding the tooltip.\n *\n * @default 100\n */\n closeDelay?: number\n /**\n * If `true`, the tooltip will hide on click.\n *\n * @default true\n */\n closeOnClick?: boolean\n /**\n * If `true`, the tooltip will hide on pressing Esc key.\n *\n * @default true\n */\n closeOnEsc?: boolean\n /**\n * If `true`, the tooltip will hide on scroll.\n *\n * @default false\n */\n closeOnScroll?: boolean\n /**\n * If `true`, the tooltip will be disabled.\n *\n * @default false\n */\n disabled?: boolean\n /**\n * The delay before showing the tooltip.\n *\n * @default 400\n */\n openDelay?: number\n}\n\nexport const useTooltip = (props: UseTooltipProps = {}) => {\n const [\n popperProps,\n {\n closeDelay = 0,\n closeOnClick = true,\n closeOnEsc = true,\n closeOnScroll,\n defaultOpen,\n disabled,\n open: openProp,\n openDelay = 0,\n onClose: onCloseProp,\n onOpen: onOpenProp,\n },\n ] = usePopperProps(props, [\"open\"])\n const describedbyId = useId()\n const triggerRef = useRef<HTMLElement>(null)\n const openTimeout = useRef<NodeJS.Timeout>(undefined)\n const closeTimeout = useRef<NodeJS.Timeout>(undefined)\n const { open, onClose, onOpen } = useDisclosure({\n defaultOpen,\n open: openProp,\n onClose: onCloseProp,\n onOpen: onOpenProp,\n })\n const { getPopperProps, getReferenceProps } = usePopper({\n open,\n ...popperProps,\n })\n\n const onForceClose = useCallback(() => {\n if (closeTimeout.current) {\n clearTimeout(closeTimeout.current)\n\n closeTimeout.current = undefined\n }\n\n onClose()\n }, [onClose])\n\n const onDelayOpen = useCallback(() => {\n if (!disabled && !openTimeout.current) {\n if (open) onForceClose()\n\n openTimeout.current = getWindow(triggerRef.current).setTimeout(\n onOpen,\n openDelay,\n )\n }\n }, [disabled, open, onForceClose, onOpen, openDelay])\n\n const onDelayClose = useCallback(() => {\n if (openTimeout.current) {\n clearTimeout(openTimeout.current)\n openTimeout.current = undefined\n }\n\n closeTimeout.current = getWindow(triggerRef.current).setTimeout(() => {\n onForceClose()\n }, closeDelay)\n }, [closeDelay, onForceClose])\n\n useEventListener(\n () => getDocument(triggerRef.current),\n \"keydown\",\n ({ key }) => {\n if (closeOnEsc && key === \"Escape\") onDelayClose()\n },\n )\n\n useEventListener(\n () => getDocument(triggerRef.current),\n \"scroll\",\n () => {\n if (open && closeOnScroll) onForceClose()\n },\n )\n\n useOutsideClick({\n ref: triggerRef,\n enabled: open,\n handler: () => {\n onDelayClose()\n },\n })\n\n useUnmountEffect(() => {\n clearTimeout(openTimeout.current)\n clearTimeout(closeTimeout.current)\n })\n\n const getTriggerProps: PropGetter<\"button\"> = useCallback(\n ({ \"aria-describedby\": ariaDescribedby, ...props } = {}) => {\n return getReferenceProps({\n ...props,\n ref: mergeRefs(props.ref, triggerRef),\n \"aria-describedby\": cx(\n ariaDescribedby,\n open ? describedbyId : undefined,\n ),\n onBlur: handlerAll(props.onBlur, onDelayClose),\n onClick: handlerAll(\n props.onClick,\n closeOnClick ? onDelayClose : undefined,\n ),\n onFocus: handlerAll(props.onFocus, onDelayOpen),\n onPointerEnter: handlerAll(props.onPointerEnter, (ev) => {\n if (ev.pointerType !== \"touch\") onDelayOpen()\n }),\n onPointerLeave: handlerAll(props.onPointerLeave, (ev) => {\n if (ev.pointerType !== \"touch\") onDelayClose()\n }),\n })\n },\n [\n getReferenceProps,\n describedbyId,\n onDelayOpen,\n open,\n closeOnClick,\n onDelayClose,\n ],\n )\n\n const getPositionerProps: PropGetter = useCallback(\n (props) => {\n return getPopperProps(props)\n },\n [getPopperProps],\n )\n\n const getContentProps: PropGetter = useCallback(\n (props = {}) => ({\n id: describedbyId,\n \"data-close\": dataAttr(!open),\n \"data-open\": dataAttr(open),\n role: \"tooltip\",\n onPointerLeave: handlerAll(props.onPointerLeave, onDelayClose),\n ...props,\n }),\n [describedbyId, onDelayClose, open],\n )\n\n return {\n open,\n getContentProps,\n getPositionerProps,\n getTriggerProps,\n onClose: onForceClose,\n onDelayClose,\n onDelayOpen,\n onOpen,\n }\n}\n\nexport type UseTooltipReturn = ReturnType<typeof useTooltip>\n\nexport const tooltipProps: (keyof UseTooltipProps)[] = [\n ...popperProps,\n \"open\",\n \"defaultOpen\",\n \"onOpen\",\n \"onClose\",\n \"closeDelay\",\n \"closeOnClick\",\n \"closeOnEsc\",\n \"closeOnScroll\",\n \"disabled\",\n \"openDelay\",\n]\n\nexport const useTooltipProps = <\n Y extends Dict = Dict,\n M extends keyof UseTooltipProps = keyof UseTooltipProps,\n>(\n props: Y,\n omitKeys?: M[],\n) => {\n return useSplitProps(\n props,\n tooltipProps.filter((key) => !omitKeys?.includes(key as M)),\n ) as unknown as [\n keyof UseTooltipProps extends M\n ? UseTooltipProps\n : Omit<UseTooltipProps, M>,\n Omit<\n Y,\n keyof UseTooltipProps extends M\n ? keyof UseTooltipProps\n : Exclude<keyof UseTooltipProps, M>\n >,\n ]\n}\n"],"mappings":";;;;;;;;;;;AA8DA,MAAa,cAAc,QAAyB,CAAC,MAAM;CACzD,MAAM,CACJ,aACA,EACE,aAAa,GACb,eAAe,MACf,aAAa,MACb,eACA,aACA,UACA,MAAM,UACN,YAAY,GACZ,SAAS,aACT,QAAQ,gBAER,eAAe,OAAO,CAAC,MAAM,CAAC;CAClC,MAAM,gBAAgB,MAAM;CAC5B,MAAM,aAAa,OAAoB,IAAI;CAC3C,MAAM,cAAc,OAAuB,KAAA,CAAS;CACpD,MAAM,eAAe,OAAuB,KAAA,CAAS;CACrD,MAAM,EAAE,MAAM,SAAS,WAAW,cAAc;EAC9C;EACA,MAAM;EACN,SAAS;EACT,QAAQ;CACV,CAAC;CACD,MAAM,EAAE,gBAAgB,sBAAsB,UAAU;EACtD;EACA,GAAG;CACL,CAAC;CAED,MAAM,eAAe,kBAAkB;EACrC,IAAI,aAAa,SAAS;GACxB,aAAa,aAAa,OAAO;GAEjC,aAAa,UAAU,KAAA;EACzB;EAEA,QAAQ;CACV,GAAG,CAAC,OAAO,CAAC;CAEZ,MAAM,cAAc,kBAAkB;EACpC,IAAI,CAAC,YAAY,CAAC,YAAY,SAAS;GACrC,IAAI,MAAM,aAAa;GAEvB,YAAY,WAAA,GAAUA,cAAAA,UAAAA,CAAU,WAAW,OAAO,CAAC,CAA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GAAgBA,cAAAA,WAAAA,CAAW,MAAM,iBAAiB,OAAO;IACvD,IAAI,GAAG,gBAAgB,SAAS,aAAa;GAC/C,CAAC;EACH,CAAC;CACH,GACA;EACE;EACA;EACA;EACA;EACA;EACA;CACF,CACF;CAEA,MAAM,qBAAiC,aACpC,UAAU;EACT,OAAO,eAAe,KAAK;CAC7B,GACA,CAAC,cAAc,CACjB;CAcA,OAAO;EACL;EACA,iBAdkC,aACjC,QAAQ,CAAC,OAAO;GACf,IAAI;GACJ,eAAA,GAAcC,cAAAA,SAAAA,CAAS,CAAC,IAAI;GAC5B,cAAA,GAAaA,cAAAA,SAAAA,CAAS,IAAI;GAC1B,MAAM;GACN,iBAAA,GAAgBD,cAAAA,WAAAA,CAAW,MAAM,gBAAgB,YAAY;GAC7D,GAAG;EACL,IACA;GAAC;GAAe;GAAc;EAAI,CAKpB;EACd;EACA;EACA,SAAS;EACT;EACA;EACA;CACF;AACF;AAIA,MAAa,eAA0C;CACrD,GAAG;CACH;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF;AAEA,MAAa,mBAIX,OACA,aACG;CACH,OAAO,cACL,OACA,aAAa,QAAQ,QAAQ,CAAC,UAAU,SAAS,GAAQ,CAAC,CAC5D;AAWF"}
1
+ {"version":3,"file":"use-tooltip.js","names":["getWindow","getDocument","dataAttr","handlerAll"],"sources":["../../../../src/components/tooltip/use-tooltip.tsx"],"sourcesContent":["\"use client\"\n\nimport type { PointerEvent } from \"react\"\nimport type { PropGetter } from \"../../core\"\nimport type { UseDisclosureProps } from \"../../hooks/use-disclosure\"\nimport type { UsePopperProps } from \"../../hooks/use-popper\"\nimport type { Dict } from \"../../utils\"\nimport { useCallback, useId, useRef } from \"react\"\nimport { mergeProps, useSplitProps } from \"../../core\"\nimport { useDisclosure } from \"../../hooks/use-disclosure\"\nimport { useEventListener } from \"../../hooks/use-event-listener\"\nimport { useOutsideClick } from \"../../hooks/use-outside-click\"\nimport { popperProps, usePopper, usePopperProps } from \"../../hooks/use-popper\"\nimport {\n dataAttr,\n getDocument,\n getWindow,\n handlerAll,\n useUnmountEffect,\n} from \"../../utils\"\n\nexport interface UseTooltipProps\n extends Omit<UseDisclosureProps, \"timing\">, UsePopperProps<\"button\"> {\n /**\n * The delay before hiding the tooltip.\n *\n * @default 100\n */\n closeDelay?: number\n /**\n * If `true`, the tooltip will hide on click.\n *\n * @default true\n */\n closeOnClick?: boolean\n /**\n * If `true`, the tooltip will hide on pressing Esc key.\n *\n * @default true\n */\n closeOnEsc?: boolean\n /**\n * If `true`, the tooltip will hide on scroll.\n *\n * @default false\n */\n closeOnScroll?: boolean\n /**\n * If `true`, the tooltip will be disabled.\n *\n * @default false\n */\n disabled?: boolean\n /**\n * The delay before showing the tooltip.\n *\n * @default 400\n */\n openDelay?: number\n}\n\nexport const useTooltip = (props: UseTooltipProps = {}) => {\n const [\n popperProps,\n {\n closeDelay = 0,\n closeOnClick = true,\n closeOnEsc = true,\n closeOnScroll,\n defaultOpen,\n disabled,\n open: openProp,\n openDelay = 0,\n onClose: onCloseProp,\n onOpen: onOpenProp,\n },\n ] = usePopperProps(props, [\"open\"])\n const describedbyId = useId()\n const triggerRef = useRef<HTMLButtonElement>(null)\n const openTimeout = useRef<NodeJS.Timeout>(undefined)\n const closeTimeout = useRef<NodeJS.Timeout>(undefined)\n const { open, onClose, onOpen } = useDisclosure({\n defaultOpen,\n open: openProp,\n onClose: onCloseProp,\n onOpen: onOpenProp,\n })\n const { getPopperProps, getReferenceProps } = usePopper({\n open,\n ...popperProps,\n })\n\n const onForceClose = useCallback(() => {\n if (closeTimeout.current) {\n clearTimeout(closeTimeout.current)\n\n closeTimeout.current = undefined\n }\n\n onClose()\n }, [onClose])\n\n const onDelayOpen = useCallback(() => {\n if (!disabled && !openTimeout.current) {\n if (open) onForceClose()\n\n openTimeout.current = getWindow(triggerRef.current).setTimeout(\n onOpen,\n openDelay,\n )\n }\n }, [disabled, open, onForceClose, onOpen, openDelay])\n\n const onDelayClose = useCallback(() => {\n if (openTimeout.current) {\n clearTimeout(openTimeout.current)\n openTimeout.current = undefined\n }\n\n closeTimeout.current = getWindow(triggerRef.current).setTimeout(() => {\n onForceClose()\n }, closeDelay)\n }, [closeDelay, onForceClose])\n\n useEventListener(\n () => getDocument(triggerRef.current),\n \"keydown\",\n ({ key }) => {\n if (closeOnEsc && key === \"Escape\") onDelayClose()\n },\n )\n\n useEventListener(\n () => getDocument(triggerRef.current),\n \"scroll\",\n () => {\n if (open && closeOnScroll) onForceClose()\n },\n )\n\n useOutsideClick({\n ref: triggerRef,\n enabled: open,\n handler: () => {\n onDelayClose()\n },\n })\n\n useUnmountEffect(() => {\n clearTimeout(openTimeout.current)\n clearTimeout(closeTimeout.current)\n })\n\n const getTriggerProps: PropGetter<\"button\"> = useCallback(\n (props = {}) => {\n return getReferenceProps(\n mergeProps(\n props,\n {\n ref: triggerRef,\n \"aria-describedby\": open ? describedbyId : undefined,\n },\n {\n onBlur: onDelayClose,\n onClick: closeOnClick ? onDelayClose : undefined,\n onFocus: onDelayOpen,\n onPointerEnter: (ev: PointerEvent<HTMLButtonElement>) => {\n if (ev.pointerType !== \"touch\") onDelayOpen()\n },\n onPointerLeave: (ev: PointerEvent<HTMLButtonElement>) => {\n if (ev.pointerType !== \"touch\") onDelayClose()\n },\n },\n )(),\n )\n },\n [\n getReferenceProps,\n describedbyId,\n onDelayOpen,\n open,\n closeOnClick,\n onDelayClose,\n ],\n )\n\n const getPositionerProps: PropGetter = useCallback(\n (props) => {\n return getPopperProps(props)\n },\n [getPopperProps],\n )\n\n const getContentProps: PropGetter = useCallback(\n (props = {}) => ({\n id: describedbyId,\n \"data-close\": dataAttr(!open),\n \"data-open\": dataAttr(open),\n role: \"tooltip\",\n onPointerLeave: handlerAll(props.onPointerLeave, onDelayClose),\n ...props,\n }),\n [describedbyId, onDelayClose, open],\n )\n\n return {\n open,\n getContentProps,\n getPositionerProps,\n getTriggerProps,\n onClose: onForceClose,\n onDelayClose,\n onDelayOpen,\n onOpen,\n }\n}\n\nexport type UseTooltipReturn = ReturnType<typeof useTooltip>\n\nexport const tooltipProps: (keyof UseTooltipProps)[] = [\n ...popperProps,\n \"open\",\n \"defaultOpen\",\n \"onOpen\",\n \"onClose\",\n \"closeDelay\",\n \"closeOnClick\",\n \"closeOnEsc\",\n \"closeOnScroll\",\n \"disabled\",\n \"openDelay\",\n]\n\nexport const useTooltipProps = <\n Y extends Dict = Dict,\n M extends keyof UseTooltipProps = keyof UseTooltipProps,\n>(\n props: Y,\n omitKeys?: M[],\n) => {\n return useSplitProps(\n props,\n tooltipProps.filter((key) => !omitKeys?.includes(key as M)),\n ) as unknown as [\n keyof UseTooltipProps extends M\n ? UseTooltipProps\n : Omit<UseTooltipProps, M>,\n Omit<\n Y,\n keyof UseTooltipProps extends M\n ? keyof UseTooltipProps\n : Exclude<keyof UseTooltipProps, M>\n >,\n ]\n}\n"],"mappings":";;;;;;;;;;AA6DA,MAAa,cAAc,QAAyB,CAAC,MAAM;CACzD,MAAM,CACJ,aACA,EACE,aAAa,GACb,eAAe,MACf,aAAa,MACb,eACA,aACA,UACA,MAAM,UACN,YAAY,GACZ,SAAS,aACT,QAAQ,gBAER,eAAe,OAAO,CAAC,MAAM,CAAC;CAClC,MAAM,gBAAgB,MAAM;CAC5B,MAAM,aAAa,OAA0B,IAAI;CACjD,MAAM,cAAc,OAAuB,KAAA,CAAS;CACpD,MAAM,eAAe,OAAuB,KAAA,CAAS;CACrD,MAAM,EAAE,MAAM,SAAS,WAAW,cAAc;EAC9C;EACA,MAAM;EACN,SAAS;EACT,QAAQ;CACV,CAAC;CACD,MAAM,EAAE,gBAAgB,sBAAsB,UAAU;EACtD;EACA,GAAG;CACL,CAAC;CAED,MAAM,eAAe,kBAAkB;EACrC,IAAI,aAAa,SAAS;GACxB,aAAa,aAAa,OAAO;GAEjC,aAAa,UAAU,KAAA;EACzB;EAEA,QAAQ;CACV,GAAG,CAAC,OAAO,CAAC;CAEZ,MAAM,cAAc,kBA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AEA,MAAM,qBAAiC,aACpC,UAAU;EACT,OAAO,eAAe,KAAK;CAC7B,GACA,CAAC,cAAc,CACjB;CAcA,OAAO;EACL;EACA,iBAdkC,aACjC,QAAQ,CAAC,OAAO;GACf,IAAI;GACJ,eAAA,GAAcC,cAAAA,SAAAA,CAAS,CAAC,IAAI;GAC5B,cAAA,GAAaA,cAAAA,SAAAA,CAAS,IAAI;GAC1B,MAAM;GACN,iBAAA,GAAgBC,cAAAA,WAAAA,CAAW,MAAM,gBAAgB,YAAY;GAC7D,GAAG;EACL,IACA;GAAC;GAAe;GAAc;EAAI,CAKpB;EACd;EACA;EACA,SAAS;EACT;EACA;EACA;CACF;AACF;AAIA,MAAa,eAA0C;CACrD,GAAG;CACH;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF;AAEA,MAAa,mBAIX,OACA,aACG;CACH,OAAO,cACL,OACA,aAAa,QAAQ,QAAQ,CAAC,UAAU,SAAS,GAAQ,CAAC,CAC5D;AAWF"}
@@ -13,6 +13,13 @@ const cssProps = /* @__PURE__ */ new Set([
13
13
  ...styleProperties,
14
14
  ...vendorProperties
15
15
  ]);
16
+ const ariaSpaceSeparatedProps = /* @__PURE__ */ new Set([
17
+ "aria-controls",
18
+ "aria-describedby",
19
+ "aria-flowto",
20
+ "aria-labelledby",
21
+ "aria-owns"
22
+ ]);
16
23
  function createShouldForwardProp(forwardProps = []) {
17
24
  return function(prop) {
18
25
  if (forwardProps.includes(prop)) return true;
@@ -21,7 +28,7 @@ function createShouldForwardProp(forwardProps = []) {
21
28
  };
22
29
  }
23
30
  function mergeProps(...args) {
24
- return function({ mergeClassName = true, mergeCSS = true, mergeEvent = true, mergeRef = true, mergeStyle = true } = {}) {
31
+ return function({ mergeAria = true, mergeClassName = true, mergeCSS = true, mergeEvent = true, mergeRef = true, mergeStyle = true } = {}) {
25
32
  let result = {};
26
33
  for (const props of args) {
27
34
  if ((0, utils_exports.isUndefined)(props)) continue;
@@ -38,6 +45,10 @@ function mergeProps(...args) {
38
45
  result[key] = (0, utils_exports.cx)(result[key], props[key]);
39
46
  continue;
40
47
  }
48
+ if (mergeAria && ariaSpaceSeparatedProps.has(key)) {
49
+ result[key] = (0, utils_exports.cx)(result[key], props[key]);
50
+ continue;
51
+ }
41
52
  if (mergeStyle && key === "style") {
42
53
  result[key] = (0, utils_exports.merge)(result[key] ?? {}, props[key] ?? {});
43
54
  continue;
@@ -1 +1 @@
1
- {"version":3,"file":"props.js","names":["isUndefined","isFunction","handlerAll","cx","merge","isArray","omitObject","splitObject","isObject","isEmptyObject"],"sources":["../../../../src/core/components/props.ts"],"sourcesContent":["import type { Dict, Merge } from \"../../utils\"\nimport { useMemo } from \"react\"\nimport isEqual from \"react-fast-compare\"\nimport {\n cx,\n handlerAll,\n isArray,\n isEmptyObject,\n isFunction,\n isObject,\n isUndefined,\n merge,\n mergeRefs,\n omitObject,\n splitObject,\n} from \"../../utils\"\nimport { conditionProperties, styleProperties, vendorProperties } from \"../css\"\n\ntype Optionalize<Y> = [Extract<Y, undefined>] extends [never]\n ? Y\n : Partial<Exclude<Y, undefined>>\n\ntype MergeAll<Y extends (Dict | undefined)[]> = Y extends [infer M]\n ? Optionalize<M>\n : Y extends [infer D, ...infer H]\n ? H extends (Dict | undefined)[]\n ? Merge<Optionalize<D>, MergeAll<H>>\n : Optionalize<D>\n : never\n\nfunction isEvent(key: string) {\n return /^on[A-Z]/.test(key)\n}\n\nexport const cssProps = new Set<string>([\n ...conditionProperties,\n ...styleProperties,\n ...vendorProperties,\n])\n\nexport type ShouldForwardProp = (prop: string) => boolean\n\nexport function createShouldForwardProp(\n forwardProps: string[] = [],\n): ShouldForwardProp {\n return function (prop: string): boolean {\n if (forwardProps.includes(prop)) return true\n\n if (prop.startsWith(\"--\")) return false\n\n return !cssProps.has(prop)\n }\n}\n\ninterface MergePropsOptions {\n mergeClassName?: boolean\n mergeCSS?: boolean\n mergeEvent?: boolean\n mergeRef?: boolean\n mergeStyle?: boolean\n}\n\nexport function mergeProps<Y extends Dict>(\n ...args: Y[]\n): (options?: MergePropsOptions) => Y\nexport function mergeProps<Y extends (Dict | undefined)[]>(\n ...args: Y\n): (options?: MergePropsOptions) => MergeAll<Y>\nexport function mergeProps(...args: (Dict | undefined)[]) {\n return function ({\n mergeClassName = true,\n mergeCSS = true,\n mergeEvent = true,\n mergeRef = true,\n mergeStyle = true,\n }: MergePropsOptions = {}) {\n let result: Dict = {}\n\n for (const props of args) {\n if (isUndefined(props)) continue\n\n for (const key in result) {\n if (mergeRef && key === \"ref\") {\n result[key] = mergeRefs(result[key], props[key])\n\n continue\n }\n\n if (\n mergeEvent &&\n isEvent(key) &&\n isFunction(result[key]) &&\n isFunction(props[key])\n ) {\n result[key] = handlerAll(result[key], props[key])\n\n continue\n }\n\n if (mergeClassName && (key === \"className\" || key === \"class\")) {\n result[key] = cx(result[key], props[key])\n\n continue\n }\n\n if (mergeStyle && key === \"style\") {\n result[key] = merge(result[key] ?? {}, props[key] ?? {})\n\n continue\n }\n\n if (mergeCSS && key === \"css\") {\n if (isArray(result[key])) {\n result[key].push(props[key])\n } else {\n result[key] ??= []\n\n result[key] = [result[key], props[key]]\n }\n\n continue\n }\n\n result[key] = !isUndefined(props[key]) ? props[key] : result[key]\n }\n\n for (const key in props)\n if (isUndefined(result[key])) result[key] = props[key]\n }\n\n return result as any\n }\n}\n\ntype CallbackProps<Y extends Dict = Dict> = (props: Y) => Y\n\ntype PropsOrCallback<Y extends Dict = Dict> = CallbackProps<Y> | Y\n\nexport function chainProps<Y extends Dict = Dict>(\n ...props: PropsOrCallback<Y>[]\n) {\n return function (options: MergePropsOptions = {}) {\n if (!props.length) return (a: Y) => a\n\n if (props.length === 1)\n return function (b: Y) {\n const a = props[0] ?? {}\n const c = isFunction(a) ? a(b) : mergeProps(a, b)(options)\n\n return c\n } as CallbackProps<Y>\n\n return props.reduce(function (a, b) {\n return function (c: Y = {} as Y) {\n const d = isFunction(a) ? a(c) : mergeProps(a, c)(options)\n const f = isFunction(b) ? b(d) : mergeProps(b, d)(options)\n\n return f\n }\n }) as CallbackProps<Y>\n }\n}\n\nexport function isEqualProps<\n Y extends Dict,\n M extends Dict,\n D extends keyof M | keyof Y,\n>(a: Y, b: M, omitKeys: D[] = []) {\n return isEqual(\n omitObject(a, omitKeys as (keyof Y)[]),\n omitObject(b, omitKeys as (keyof M)[]),\n )\n}\n\nexport function useSplitProps<Y extends Dict, M extends keyof Y>(\n props: Y,\n keys: M[] | readonly M[],\n) {\n return useMemo(() => splitObject<Y, M>(props, keys), [props, keys])\n}\n\nexport function extractProps(props: Dict, keys: readonly string[] | string[]) {\n let result: Dict = {}\n\n Object.entries(props).forEach(([key, value]) => {\n if (!cssProps.has(key)) return\n\n if (keys.includes(key)) {\n result = merge(result, { [key]: value })\n } else if (isObject(value)) {\n value = extractProps(value, keys)\n\n if (isEmptyObject(value)) return\n\n result = merge(result, { [key]: value })\n }\n })\n\n return result\n}\n\nexport function useExtractProps(\n props: Dict,\n keys: readonly string[] | string[],\n) {\n return useMemo(() => extractProps(props, keys), [props, keys])\n}\n"],"mappings":";;;;;;;AA8BA,SAAS,QAAQ,KAAa;CAC5B,OAAO,WAAW,KAAK,GAAG;AAC5B;AAEA,MAAa,2BAAW,IAAI,IAAY;CACtC,GAAG;CACH,GAAG;CACH,GAAG;AACL,CAAC;AAID,SAAgB,wBACd,eAAyB,CAAC,GACP;CACnB,OAAO,SAAU,MAAuB;EACtC,IAAI,aAAa,SAAS,IAAI,GAAG,OAAO;EAExC,IAAI,KAAK,WAAW,IAAI,GAAG,OAAO;EAElC,OAAO,CAAC,SAAS,IAAI,IAAI;CAC3B;AACF;AAgBA,SAAgB,WAAW,GAAG,MAA4B;CACxD,OAAO,SAAU,EACf,iBAAiB,MACjB,WAAW,MACX,aAAa,MACb,WAAW,MACX,aAAa,SACQ,CAAC,GAAG;EACzB,IAAI,SAAe,CAAC;EAEpB,KAAK,MAAM,SAAS,MAAM;GACxB,KAAA,GAAIA,cAAAA,YAAA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F,CAAC;CAED,OAAO;AACT;AAEA,SAAgB,gBACd,OACA,MACA;CACA,OAAO,cAAc,aAAa,OAAO,IAAI,GAAG,CAAC,OAAO,IAAI,CAAC;AAC/D"}
1
+ {"version":3,"file":"props.js","names":["isUndefined","isFunction","handlerAll","cx","merge","isArray","omitObject","splitObject","isObject","isEmptyObject"],"sources":["../../../../src/core/components/props.ts"],"sourcesContent":["import type { Dict, Merge } from \"../../utils\"\nimport { useMemo } from \"react\"\nimport isEqual from \"react-fast-compare\"\nimport {\n cx,\n handlerAll,\n isArray,\n isEmptyObject,\n isFunction,\n isObject,\n isUndefined,\n merge,\n mergeRefs,\n omitObject,\n splitObject,\n} from \"../../utils\"\nimport { conditionProperties, styleProperties, vendorProperties } from \"../css\"\n\ntype Optionalize<Y> = [Extract<Y, undefined>] extends [never]\n ? Y\n : Partial<Exclude<Y, undefined>>\n\ntype MergeAll<Y extends (Dict | undefined)[]> = Y extends [infer M]\n ? Optionalize<M>\n : Y extends [infer D, ...infer H]\n ? H extends (Dict | undefined)[]\n ? Merge<Optionalize<D>, MergeAll<H>>\n : Optionalize<D>\n : never\n\nfunction isEvent(key: string) {\n return /^on[A-Z]/.test(key)\n}\n\nexport const cssProps = new Set<string>([\n ...conditionProperties,\n ...styleProperties,\n ...vendorProperties,\n])\n\nconst ariaSpaceSeparatedProps = new Set<string>([\n \"aria-controls\",\n \"aria-describedby\",\n \"aria-flowto\",\n \"aria-labelledby\",\n \"aria-owns\",\n])\n\nexport type ShouldForwardProp = (prop: string) => boolean\n\nexport function createShouldForwardProp(\n forwardProps: string[] = [],\n): ShouldForwardProp {\n return function (prop: string): boolean {\n if (forwardProps.includes(prop)) return true\n\n if (prop.startsWith(\"--\")) return false\n\n return !cssProps.has(prop)\n }\n}\n\nexport interface MergePropsOptions {\n mergeAria?: boolean\n mergeClassName?: boolean\n mergeCSS?: boolean\n mergeEvent?: boolean\n mergeRef?: boolean\n mergeStyle?: boolean\n}\n\nexport function mergeProps<Y extends Dict>(\n ...args: Y[]\n): (options?: MergePropsOptions) => Y\nexport function mergeProps<Y extends (Dict | undefined)[]>(\n ...args: Y\n): (options?: MergePropsOptions) => MergeAll<Y>\nexport function mergeProps(...args: (Dict | undefined)[]) {\n return function ({\n mergeAria = true,\n mergeClassName = true,\n mergeCSS = true,\n mergeEvent = true,\n mergeRef = true,\n mergeStyle = true,\n }: MergePropsOptions = {}) {\n let result: Dict = {}\n\n for (const props of args) {\n if (isUndefined(props)) continue\n\n for (const key in result) {\n if (mergeRef && key === \"ref\") {\n result[key] = mergeRefs(result[key], props[key])\n\n continue\n }\n\n if (\n mergeEvent &&\n isEvent(key) &&\n isFunction(result[key]) &&\n isFunction(props[key])\n ) {\n result[key] = handlerAll(result[key], props[key])\n\n continue\n }\n\n if (mergeClassName && (key === \"className\" || key === \"class\")) {\n result[key] = cx(result[key], props[key])\n\n continue\n }\n\n if (mergeAria && ariaSpaceSeparatedProps.has(key)) {\n result[key] = cx(result[key], props[key])\n\n continue\n }\n\n if (mergeStyle && key === \"style\") {\n result[key] = merge(result[key] ?? {}, props[key] ?? {})\n\n continue\n }\n\n if (mergeCSS && key === \"css\") {\n if (isArray(result[key])) {\n result[key].push(props[key])\n } else {\n result[key] ??= []\n\n result[key] = [result[key], props[key]]\n }\n\n continue\n }\n\n result[key] = !isUndefined(props[key]) ? props[key] : result[key]\n }\n\n for (const key in props)\n if (isUndefined(result[key])) result[key] = props[key]\n }\n\n return result as any\n }\n}\n\ntype CallbackProps<Y extends Dict = Dict> = (props: Y) => Y\n\ntype PropsOrCallback<Y extends Dict = Dict> = CallbackProps<Y> | Y\n\nexport function chainProps<Y extends Dict = Dict>(\n ...props: PropsOrCallback<Y>[]\n) {\n return function (options: MergePropsOptions = {}) {\n if (!props.length) return (a: Y) => a\n\n if (props.length === 1)\n return function (b: Y) {\n const a = props[0] ?? {}\n const c = isFunction(a) ? a(b) : mergeProps(a, b)(options)\n\n return c\n } as CallbackProps<Y>\n\n return props.reduce(function (a, b) {\n return function (c: Y = {} as Y) {\n const d = isFunction(a) ? a(c) : mergeProps(a, c)(options)\n const f = isFunction(b) ? b(d) : mergeProps(b, d)(options)\n\n return f\n }\n }) as CallbackProps<Y>\n }\n}\n\nexport function isEqualProps<\n Y extends Dict,\n M extends Dict,\n D extends keyof M | keyof Y,\n>(a: Y, b: M, omitKeys: D[] = []) {\n return isEqual(\n omitObject(a, omitKeys as (keyof Y)[]),\n omitObject(b, omitKeys as (keyof M)[]),\n )\n}\n\nexport function useSplitProps<Y extends Dict, M extends keyof Y>(\n props: Y,\n keys: M[] | readonly M[],\n) {\n return useMemo(() => splitObject<Y, M>(props, keys), [props, keys])\n}\n\nexport function extractProps(props: Dict, keys: readonly string[] | string[]) {\n let result: Dict = {}\n\n Object.entries(props).forEach(([key, value]) => {\n if (!cssProps.has(key)) return\n\n if (keys.includes(key)) {\n result = merge(result, { [key]: value })\n } else if (isObject(value)) {\n value = extractProps(value, keys)\n\n if (isEmptyObject(value)) return\n\n result = merge(result, { [key]: value })\n }\n })\n\n return result\n}\n\nexport function useExtractProps(\n props: Dict,\n keys: readonly string[] | string[],\n) {\n return useMemo(() => extractProps(props, keys), [props, keys])\n}\n"],"mappings":";;;;;;;AA8BA,SAAS,QAAQ,KAAa;CAC5B,OAAO,WAAW,KAAK,GAAG;AAC5B;AAEA,MAAa,2BAAW,IAAI,IAAY;CACtC,GAAG;CACH,GAAG;CACH,GAAG;AACL,CAAC;AAED,MAAM,0CAA0B,IAAI,IAAY;CAC9C;CACA;CACA;CACA;CACA;AACF,CAAC;AAID,SAAgB,wBACd,eAAyB,CAAC,GACP;CACnB,OAAO,SAAU,MAAuB;EACtC,IAAI,aAAa,SAAS,IAAI,GAAG,OAAO;EAExC,IAAI,KAAK,WAAW,IAAI,GAAG,OAAO;EAElC,OAAO,CAAC,SAAS,IAAI,IAAI;CAC3B;AACF;AAiBA,SAAgB,WAAW,GAAG,MAA4B;CACxD,OAAO,SAAU,EACf,YAAY,MACZ,iBAAiB,MACjB,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,cAAAA,MAAAA,CAAM,QAAQ,GAAG,MAAM,MAAM,CAAC;OAClC,KAAA,GAAII,cAAAA,SAAAA,CAAS,KAAK,GAAG;GAC1B,QAAQ,aAAa,OAAO,IAAI;GAEhC,KAAA,GAAIC,cAAAA,cAAAA,CAAc,KAAK,GAAG;GAE1B,UAAA,GAASL,cAAAA,MAAAA,CAAM,QAAQ,GAAG,MAAM,MAAM,CAAC;EACzC;CACF,CAAC;CAED,OAAO;AACT;AAEA,SAAgB,gBACd,OACA,MACA;CACA,OAAO,cAAc,aAAa,OAAO,IAAI,GAAG,CAAC,OAAO,IAAI,CAAC;AAC/D"}
@@ -10,7 +10,7 @@ import { GlobalStyles, ThemeProvider, getPreventTransition, useTheme } from "./s
10
10
  import { useSystemColorMode } from "./system/use-system-color-mode.js";
11
11
  import { ColorModeContext, ColorModeProvider, useColorMode } from "./system/color-mode-provider.js";
12
12
  import { defineComponentSlotStyle, defineComponentStyle, defineConfig, defineSemanticTokens, defineStyles, defineTheme, defineThemeSchemes, defineTokens } from "./system/config.js";
13
- import { ColorSchemeContext, createStyled, useColorSchemeContext } from "./system/styled.js";
13
+ import { ColorSchemeContext, HydrationContext, createStyled, useColorSchemeContext, useHydrationContext } from "./system/styled.js";
14
14
  import { styled } from "./system/factory.js";
15
15
  import { ColorModeScript, ThemeSchemeScript, getStorageScript } from "./system/storage-script.js";
16
16
  import { getColorModeValue, useColorModeValue } from "./system/use-color-mode-value.js";
@@ -31,4 +31,4 @@ import { chainProps, createShouldForwardProp, cssProps, extractProps, isEqualPro
31
31
  import { getSlotClassName, mergeSlotCSS, useComponentSlotStyle, useComponentStyle } from "./components/use-component-style.js";
32
32
  import { getClassName, getDisplayName } from "./components/utils.js";
33
33
  import { createComponent, createSlotComponent } from "./components/create-component.js";
34
- export { COLOR_MODE_STORAGE_KEY, ColorModeContext, ColorModeProvider, ColorModeScript, ColorSchemeContext, DEFAULT_DIRECTION, DEFAULT_LAYERS, DEFAULT_LOCALE, DEFAULT_VAR_PREFIX, EnvironmentProvider, GlobalStyles, SystemProvider, THEME_SCHEME_STORAGE_KEY, ThemeProvider, ThemeSchemeScript, animation, animationProperties, aspectRatioProperties, atRuleStyles, attributeProperties, attributeSelectors, attributes, blurProperties, borderProperties, chainProps, colorMix, colorProperties, conditionProperties, conditionSelectors, conditions, createBreakpoints, createComponent, createLayers, createShouldForwardProp, createSlotComponent, createStorageManager, createStyled, createSystem, createVarRules, createVars, css, cssProps, defaultEnvironment, defaultLayers, defaultSystem, defineComponentSlotStyle, defineComponentStyle, defineConfig, defineSemanticTokens, defineStyles, defineTheme, defineThemeSchemes, defineTokens, display, durationProperties, easingProperties, extractProps, focusRingStyle, fontProperties, getCSS, getCSSFunction, getClassName, getColorModeValue, getColorSchemeVar, getCondition, getDisplayName, getPreventTransition, getSlotClassName, getStorageScript, getStyle, getVar, getVarName, gradient, gradientProperties, groupAttributeProperties, groupAttributeSelectors, groupAttributes, injectKeyframes, injectVars, isCSSFunction, isCSSToken, isCSSVar, isColorScheme, isEqualProps, keyframeProperties, keyframes, mergeCSS, mergeProps, mergeSlotCSS, mergeVars, peerAttributeProperties, peerAttributeSelectors, peerAttributes, pseudoClassProperties, pseudoClassSelectors, pseudoClasses, pseudoElementProperties, pseudoElementSelectors, pseudoElements, pseudoStyles, radiusProperties, shadowProperties, shorthandStyles, sizeProperties, spaceProperties, standardStyles, styleProperties, styled, styledStyles, styles, tokenToValue, tokenToVar, transformConditionalValue, transformInterpolation, transforms, useCSS, useColorMode, useColorModeValue, useColorSchemeContext, useComponentSlotStyle, useComponentStyle, useEnvironment, useExtractProps, useInjectVarsIntoCss, useInjectVarsIntoProps, useSplitProps, useSystem, useSystemColorMode, useTheme, varAttr, varToValue, variableLengthProperties, vendorProperties, zIndexProperties };
34
+ export { COLOR_MODE_STORAGE_KEY, ColorModeContext, ColorModeProvider, ColorModeScript, ColorSchemeContext, DEFAULT_DIRECTION, DEFAULT_LAYERS, DEFAULT_LOCALE, DEFAULT_VAR_PREFIX, EnvironmentProvider, GlobalStyles, HydrationContext, SystemProvider, THEME_SCHEME_STORAGE_KEY, ThemeProvider, ThemeSchemeScript, animation, animationProperties, aspectRatioProperties, atRuleStyles, attributeProperties, attributeSelectors, attributes, blurProperties, borderProperties, chainProps, colorMix, colorProperties, conditionProperties, conditionSelectors, conditions, createBreakpoints, createComponent, createLayers, createShouldForwardProp, createSlotComponent, createStorageManager, createStyled, createSystem, createVarRules, createVars, css, cssProps, defaultEnvironment, defaultLayers, defaultSystem, defineComponentSlotStyle, defineComponentStyle, defineConfig, defineSemanticTokens, defineStyles, defineTheme, defineThemeSchemes, defineTokens, display, durationProperties, easingProperties, extractProps, focusRingStyle, fontProperties, getCSS, getCSSFunction, getClassName, getColorModeValue, getColorSchemeVar, getCondition, getDisplayName, getPreventTransition, getSlotClassName, getStorageScript, getStyle, getVar, getVarName, gradient, gradientProperties, groupAttributeProperties, groupAttributeSelectors, groupAttributes, injectKeyframes, injectVars, isCSSFunction, isCSSToken, isCSSVar, isColorScheme, isEqualProps, keyframeProperties, keyframes, mergeCSS, mergeProps, mergeSlotCSS, mergeVars, peerAttributeProperties, peerAttributeSelectors, peerAttributes, pseudoClassProperties, pseudoClassSelectors, pseudoClasses, pseudoElementProperties, pseudoElementSelectors, pseudoElements, pseudoStyles, radiusProperties, shadowProperties, shorthandStyles, sizeProperties, spaceProperties, standardStyles, styleProperties, styled, styledStyles, styles, tokenToValue, tokenToVar, transformConditionalValue, transformInterpolation, transforms, useCSS, useColorMode, useColorModeValue, useColorSchemeContext, useComponentSlotStyle, useComponentStyle, useEnvironment, useExtractProps, useHydrationContext, useInjectVarsIntoCss, useInjectVarsIntoProps, useSplitProps, useSystem, useSystemColorMode, useTheme, varAttr, varToValue, variableLengthProperties, vendorProperties, zIndexProperties };
@@ -9,8 +9,8 @@ import { GlobalStyles, ThemeProvider, getPreventTransition, useTheme } from "./t
9
9
  import { useSystemColorMode } from "./use-system-color-mode.js";
10
10
  import { ColorModeContext, ColorModeProvider, useColorMode } from "./color-mode-provider.js";
11
11
  import { defineComponentSlotStyle, defineComponentStyle, defineConfig, defineSemanticTokens, defineStyles, defineTheme, defineThemeSchemes, defineTokens } from "./config.js";
12
- import { ColorSchemeContext, createStyled, useColorSchemeContext } from "./styled.js";
12
+ import { ColorSchemeContext, HydrationContext, createStyled, useColorSchemeContext, useHydrationContext } from "./styled.js";
13
13
  import { styled } from "./factory.js";
14
14
  import { ColorModeScript, ThemeSchemeScript, getStorageScript } from "./storage-script.js";
15
15
  import { getColorModeValue, useColorModeValue } from "./use-color-mode-value.js";
16
- export { ColorModeContext, ColorModeProvider, ColorModeScript, ColorSchemeContext, EnvironmentProvider, GlobalStyles, SystemProvider, ThemeProvider, ThemeSchemeScript, createBreakpoints, createLayers, createStorageManager, createStyled, createSystem, createVarRules, createVars, defaultEnvironment, defaultLayers, defaultSystem, defineComponentSlotStyle, defineComponentStyle, defineConfig, defineSemanticTokens, defineStyles, defineTheme, defineThemeSchemes, defineTokens, getColorModeValue, getColorSchemeVar, getPreventTransition, getStorageScript, getVar, getVarName, injectVars, isColorScheme, mergeVars, styled, transformInterpolation, useColorMode, useColorModeValue, useColorSchemeContext, useEnvironment, useSystem, useSystemColorMode, useTheme, varAttr };
16
+ export { ColorModeContext, ColorModeProvider, ColorModeScript, ColorSchemeContext, EnvironmentProvider, GlobalStyles, HydrationContext, SystemProvider, ThemeProvider, ThemeSchemeScript, createBreakpoints, createLayers, createStorageManager, createStyled, createSystem, createVarRules, createVars, defaultEnvironment, defaultLayers, defaultSystem, defineComponentSlotStyle, defineComponentStyle, defineConfig, defineSemanticTokens, defineStyles, defineTheme, defineThemeSchemes, defineTokens, getColorModeValue, getColorSchemeVar, getPreventTransition, getStorageScript, getVar, getVarName, injectVars, isColorScheme, mergeVars, styled, transformInterpolation, useColorMode, useColorModeValue, useColorSchemeContext, useEnvironment, useHydrationContext, useSystem, useSystemColorMode, useTheme, varAttr };
@@ -63,6 +63,10 @@ const [ColorSchemeContext, useColorSchemeContext] = createContext$1({
63
63
  name: "ColorSchemeContext",
64
64
  strict: false
65
65
  });
66
+ const [HydrationContext, useHydrationContext] = createContext$1({
67
+ name: "HydrationContext",
68
+ strict: false
69
+ });
66
70
  function createStyled(el, { name, base, compounds, props, sizes, variants, defaultProps, transferProps, ...options } = {}) {
67
71
  const displayName = options.displayName ?? getDisplayName(name, "");
68
72
  const shouldForwardProp = !options.shouldForwardProp ? createShouldForwardProp(options.forwardProps) : void 0;
@@ -89,6 +93,7 @@ function createStyled(el, { name, base, compounds, props, sizes, variants, defau
89
93
  const forwardAsChild = options.forwardAsChild || options.forwardProps?.includes("asChild");
90
94
  const [omittedProps, styleProps] = useSplitProps(props, shouldForwardProp);
91
95
  const [, rest] = useComponentStyle(omittedProps, componentStyleOptions);
96
+ const suppressHydrationWarning = useHydrationContext();
92
97
  const [cssArray, colorScheme, forwardProps] = useMemo(() => {
93
98
  const { css, colorScheme, ...forwardProps } = rest;
94
99
  return [
@@ -98,6 +103,7 @@ function createStyled(el, { name, base, compounds, props, sizes, variants, defau
98
103
  ];
99
104
  }, [rest]);
100
105
  styleProps.colorScheme ??= colorScheme;
106
+ forwardProps.suppressHydrationWarning ??= suppressHydrationWarning;
101
107
  if (forwardProps.className) className = getRegisteredStyles(cache.registered, registered.current, forwardProps.className).trim();
102
108
  const interpolations = useMemo(() => [...registered.current, ...(0, utils_exports.filterEmpty)([...cssArray, styleProps].map(css(system, theme)))], [
103
109
  cssArray,
@@ -114,25 +120,28 @@ function createStyled(el, { name, base, compounds, props, sizes, variants, defau
114
120
  className,
115
121
  children
116
122
  };
117
- return /* @__PURE__ */ jsxs(ColorSchemeContext, {
123
+ return /* @__PURE__ */ jsx(ColorSchemeContext, {
118
124
  value: styleProps.colorScheme,
119
- children: [/* @__PURE__ */ jsx(Insertion, {
120
- cache,
121
- htmlTag,
122
- serialized
123
- }), asChild && !forwardAsChild ? /* @__PURE__ */ jsx(Slot, {
124
- ref,
125
- ...mergedProps
126
- }) : /* @__PURE__ */ jsx(Component, {
127
- ref,
128
- ...mergedProps
129
- })]
125
+ children: /* @__PURE__ */ jsxs(HydrationContext, {
126
+ value: mergedProps.suppressHydrationWarning,
127
+ children: [/* @__PURE__ */ jsx(Insertion, {
128
+ cache,
129
+ htmlTag,
130
+ serialized
131
+ }), asChild && !forwardAsChild ? /* @__PURE__ */ jsx(Slot, {
132
+ ref,
133
+ ...mergedProps
134
+ }) : /* @__PURE__ */ jsx(Component, {
135
+ ref,
136
+ ...mergedProps
137
+ })]
138
+ })
130
139
  });
131
140
  });
132
141
  StyledComponent.displayName = displayName || "StyledComponent";
133
142
  return StyledComponent;
134
143
  }
135
144
  //#endregion
136
- export { ColorSchemeContext, createStyled, useColorSchemeContext };
145
+ export { ColorSchemeContext, HydrationContext, createStyled, useColorSchemeContext, useHydrationContext };
137
146
 
138
147
  //# sourceMappingURL=styled.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"styled.js","names":["isUndefined","createdDom","cx","splitObject","createContext","filterUndefined","runIfFn","toKebabCase","isString","toArray","filterEmpty"],"sources":["../../../../src/core/system/styled.tsx"],"sourcesContent":["\"use client\"\n\nimport type { EmotionCache, SerializedStyles } from \"@emotion/utils\"\nimport type { FC } from \"react\"\nimport type { Dict } from \"../../utils\"\nimport type { As, ShouldForwardProp, StyledComponent } from \"../components\"\nimport type { CSSModifierObject, CSSPropObject } from \"../css\"\nimport type {\n ColorScheme,\n ComponentStyle,\n System,\n UsageTheme,\n} from \"./index.type\"\nimport { withEmotionCache } from \"@emotion/react\"\nimport { serializeStyles } from \"@emotion/serialize\"\nimport { useInsertionEffectAlwaysWithSyncFallback } from \"@emotion/use-insertion-effect-with-fallbacks\"\nimport { getRegisteredStyles, registerStyles } from \"@emotion/utils\"\nimport { useMemo, useRef } from \"react\"\nimport isEqual from \"react-fast-compare\"\nimport { Slot } from \"../../components/slot\"\nimport {\n createContext,\n createdDom,\n cx,\n filterEmpty,\n filterUndefined,\n isString,\n isUndefined,\n runIfFn,\n splitObject,\n toArray,\n toKebabCase,\n} from \"../../utils\"\nimport {\n createShouldForwardProp,\n getDisplayName,\n useComponentStyle,\n} from \"../components\"\nimport { css } from \"../css\"\nimport { useSystem } from \"./system-provider\"\nimport { useTheme } from \"./theme-provider\"\n\ninterface InsertionProps {\n cache: EmotionCache\n htmlTag: boolean\n serialized: SerializedStyles\n}\n\nfunction normalizeHostSelector(rule: string, className: string) {\n const selector = `.${className}`\n\n return rule\n .replaceAll(\n `${selector}:host([data-mode=dark]) ${selector}`,\n `:host([data-mode=dark]) ${selector}`,\n )\n .replaceAll(\n `${selector}:host([data-mode=light]) ${selector}`,\n `:host([data-mode=light]) ${selector}`,\n )\n}\n\nfunction insertStyles(cache: EmotionCache, serialized: SerializedStyles) {\n const className = `${cache.key}-${serialized.name}`\n\n if (!isUndefined(cache.inserted[serialized.name])) return\n\n const sheet = Object.create(cache.sheet) as typeof cache.sheet\n\n sheet.insert = (rule) => {\n cache.sheet.insert(normalizeHostSelector(rule, className))\n }\n\n let styleForSsr = \"\"\n let current: SerializedStyles | undefined = serialized\n\n do {\n const style =\n cache.insert(\n serialized === current ? `.${className}` : \"\",\n current,\n sheet,\n true,\n ) || undefined\n\n if (!createdDom() && !isUndefined(style))\n styleForSsr += normalizeHostSelector(style, className)\n\n current = current.next\n } while (current !== undefined)\n\n return styleForSsr || undefined\n}\n\nconst Insertion: FC<InsertionProps> = ({ cache, htmlTag, serialized }) => {\n registerStyles(cache, serialized, htmlTag)\n\n const style = useInsertionEffectAlwaysWithSyncFallback(() =>\n insertStyles(cache, serialized),\n )\n\n if (!createdDom() && !isUndefined(style)) {\n let className = serialized.name\n let next = serialized.next\n\n while (next !== undefined) {\n className = cx(className, next.name) ?? \"\"\n next = next.next\n }\n\n return (\n <style\n data-emotion={cx(cache.key, className)}\n dangerouslySetInnerHTML={{ __html: style }}\n nonce={cache.sheet.nonce}\n />\n )\n } else {\n return null\n }\n}\n\nconst useSplitProps = <Y extends Dict, M extends Dict>(\n props: Dict,\n shouldForwardProp?: ShouldForwardProp,\n) => {\n const propsRef = useRef(props)\n\n if (!isEqual(propsRef.current, props)) propsRef.current = props\n\n const computedProps = propsRef.current\n\n return useMemo(\n () => splitObject<Y, M>(computedProps, shouldForwardProp),\n [computedProps, shouldForwardProp],\n )\n}\n\nexport const [ColorSchemeContext, useColorSchemeContext] =\n createContext<ColorScheme>({\n name: \"ColorSchemeContext\",\n strict: false,\n })\n\nexport interface StyledOptions<\n Y extends CSSPropObject = CSSPropObject,\n M extends CSSModifierObject = CSSModifierObject,\n D extends CSSModifierObject = CSSModifierObject,\n H extends number | string | symbol = string,\n> extends Omit<ComponentStyle<Y, M, D>, \"className\"> {\n className?: ((system: System) => string) | string\n displayName?: string\n forwardAsChild?: boolean\n name?: string\n shouldForwardProp?: boolean | ShouldForwardProp\n target?: string\n forwardProps?: string[]\n transferProps?: H[]\n}\n\nexport function createStyled<\n Y extends As,\n M extends object = {},\n D extends CSSPropObject = CSSPropObject,\n H extends CSSModifierObject = CSSModifierObject,\n R extends CSSModifierObject = CSSModifierObject,\n>(\n el: Y,\n {\n name,\n base,\n compounds,\n props,\n sizes,\n variants,\n defaultProps,\n transferProps,\n ...options\n }: StyledOptions<D, H, R, keyof M> = {},\n) {\n const displayName = options.displayName ?? getDisplayName(name, \"\")\n const shouldForwardProp = !options.shouldForwardProp\n ? createShouldForwardProp(options.forwardProps)\n : undefined\n const style = filterUndefined({\n base,\n compounds,\n props,\n sizes,\n variants,\n defaultProps,\n })\n\n const StyledComponent = withEmotionCache<Dict>(function (\n { as: Component = el, asChild, children, ...props },\n cache,\n ref,\n ) {\n let className: string | undefined = \"\"\n\n const system = useSystem()\n const { theme } = useTheme<UsageTheme>()\n const componentStyleOptions = {\n name,\n className: system.utils.getClassName(\n runIfFn(options.className, system) ?? toKebabCase(name ?? \"\"),\n ),\n style,\n transferProps,\n }\n const registered = useRef<string[]>([])\n const htmlTag = isString(Component)\n const forwardAsChild =\n options.forwardAsChild || options.forwardProps?.includes(\"asChild\")\n const [omittedProps, styleProps] = useSplitProps(props, shouldForwardProp)\n const [, rest] = useComponentStyle<any, {}>(\n omittedProps,\n componentStyleOptions,\n )\n const [cssArray, colorScheme, forwardProps] = useMemo(() => {\n const { css, colorScheme, ...forwardProps } = rest\n\n return [toArray(css), colorScheme, forwardProps]\n }, [rest])\n\n styleProps.colorScheme ??= colorScheme\n\n if (forwardProps.className)\n className = getRegisteredStyles(\n cache.registered,\n registered.current,\n forwardProps.className,\n ).trim()\n\n const interpolations = useMemo(\n () => [\n ...registered.current,\n ...filterEmpty([...cssArray, styleProps].map(css(system, theme))),\n ],\n [cssArray, system, styleProps, theme],\n )\n\n const serialized = useMemo(\n () => serializeStyles(interpolations, cache.registered),\n [interpolations, cache.registered],\n )\n\n className = cx(\n className,\n serialized.styles ? `${cache.key}-${serialized.name}` : undefined,\n )\n className = cx(className, options.target)\n\n if (!className) className = undefined\n\n const mergedProps = { ...forwardProps, className, children }\n\n return (\n <ColorSchemeContext value={styleProps.colorScheme}>\n <Insertion cache={cache} htmlTag={htmlTag} serialized={serialized} />\n\n {asChild && !forwardAsChild ? (\n <Slot ref={ref} {...mergedProps} />\n ) : (\n <Component ref={ref} {...mergedProps} />\n )}\n </ColorSchemeContext>\n )\n }) as StyledComponent<Y, M>\n\n StyledComponent.displayName = displayName || \"StyledComponent\"\n\n return StyledComponent\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAgDA,SAAS,sBAAsB,MAAc,WAAmB;CAC9D,MAAM,WAAW,IAAI;CAErB,OAAO,KACJ,WACC,GAAG,SAAS,0BAA0B,YACtC,2BAA2B,UAC7B,CAAC,CACA,WACC,GAAG,SAAS,2BAA2B,YACvC,4BAA4B,UAC9B;AACJ;AAEA,SAAS,aAAa,OAAqB,YAA8B;CACvE,MAAM,YAAY,GAAG,MAAM,IAAI,GAAG,WAAW;CAE7C,IAAI,EAAA,GAACA,cAAAA,YAAAA,CAAY,MAAM,SAAS,WAAW,KAAK,GAAG;CAEnD,MAAM,Q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AY,oBACV,MAAM,YACN,WAAW,SACX,aAAa,SACf,CAAC,CAAC,KAAK;EAET,MAAM,iBAAiB,cACf,CACJ,GAAG,WAAW,SACd,IAAA,GAAGC,cAAAA,YAAAA,CAAY,CAAC,GAAG,UAAU,UAAU,CAAC,CAAC,IAAI,IAAI,QAAQ,KAAK,CAAC,CAAC,CAClE,GACA;GAAC;GAAU;GAAQ;GAAY;EAAK,CACtC;EAEA,MAAM,aAAa,cACX,gBAAgB,gBAAgB,MAAM,UAAU,GACtD,CAAC,gBAAgB,MAAM,UAAU,CACnC;EAEA,aAAA,GAAYR,cAAAA,GAAAA,CACV,WACA,WAAW,SAAS,GAAG,MAAM,IAAI,GAAG,WAAW,SAAS,KAAA,CAC1D;EACA,aAAA,GAAYA,cAAAA,GAAAA,CAAG,WAAW,QAAQ,MAAM;EAExC,IAAI,CAAC,WAAW,YAAY,KAAA;EAE5B,MAAM,cAAc;GAAE,GAAG;GAAc;GAAW;EAAS;EAE3D,OACE,qBAAC,oBAAD;GAAoB,OAAO,WAAW;GAAtC,UAAA,CACE,oBAAC,WAAD;IAAkB;IAAgB;IAAqB;GAAa,CAAA,GAEnE,WAAW,CAAC,iBACX,oBAAC,MAAD;IAAW;IAAK,GAAI;GAAc,CAAA,IAElC,oBAAC,WAAD;IAAgB;IAAK,GAAI;GAAc,CAAA,CAEvB;;CAExB,CAAC;CAED,gBAAgB,cAAc,eAAe;CAE7C,OAAO;AACT"}
1
+ {"version":3,"file":"styled.js","names":["isUndefined","createdDom","cx","splitObject","createContext","filterUndefined","runIfFn","toKebabCase","isString","toArray","filterEmpty"],"sources":["../../../../src/core/system/styled.tsx"],"sourcesContent":["\"use client\"\n\nimport type { EmotionCache, SerializedStyles } from \"@emotion/utils\"\nimport type { FC } from \"react\"\nimport type { Dict } from \"../../utils\"\nimport type {\n As,\n HTMLProps,\n ShouldForwardProp,\n StyledComponent,\n} from \"../components\"\nimport type { CSSModifierObject, CSSPropObject } from \"../css\"\nimport type {\n ColorScheme,\n ComponentStyle,\n System,\n UsageTheme,\n} from \"./index.type\"\nimport { withEmotionCache } from \"@emotion/react\"\nimport { serializeStyles } from \"@emotion/serialize\"\nimport { useInsertionEffectAlwaysWithSyncFallback } from \"@emotion/use-insertion-effect-with-fallbacks\"\nimport { getRegisteredStyles, registerStyles } from \"@emotion/utils\"\nimport { useMemo, useRef } from \"react\"\nimport isEqual from \"react-fast-compare\"\nimport { Slot } from \"../../components/slot\"\nimport {\n createContext,\n createdDom,\n cx,\n filterEmpty,\n filterUndefined,\n isString,\n isUndefined,\n runIfFn,\n splitObject,\n toArray,\n toKebabCase,\n} from \"../../utils\"\nimport {\n createShouldForwardProp,\n getDisplayName,\n useComponentStyle,\n} from \"../components\"\nimport { css } from \"../css\"\nimport { useSystem } from \"./system-provider\"\nimport { useTheme } from \"./theme-provider\"\n\ninterface InsertionProps {\n cache: EmotionCache\n htmlTag: boolean\n serialized: SerializedStyles\n}\n\nfunction normalizeHostSelector(rule: string, className: string) {\n const selector = `.${className}`\n\n return rule\n .replaceAll(\n `${selector}:host([data-mode=dark]) ${selector}`,\n `:host([data-mode=dark]) ${selector}`,\n )\n .replaceAll(\n `${selector}:host([data-mode=light]) ${selector}`,\n `:host([data-mode=light]) ${selector}`,\n )\n}\n\nfunction insertStyles(cache: EmotionCache, serialized: SerializedStyles) {\n const className = `${cache.key}-${serialized.name}`\n\n if (!isUndefined(cache.inserted[serialized.name])) return\n\n const sheet = Object.create(cache.sheet) as typeof cache.sheet\n\n sheet.insert = (rule) => {\n cache.sheet.insert(normalizeHostSelector(rule, className))\n }\n\n let styleForSsr = \"\"\n let current: SerializedStyles | undefined = serialized\n\n do {\n const style =\n cache.insert(\n serialized === current ? `.${className}` : \"\",\n current,\n sheet,\n true,\n ) || undefined\n\n if (!createdDom() && !isUndefined(style))\n styleForSsr += normalizeHostSelector(style, className)\n\n current = current.next\n } while (current !== undefined)\n\n return styleForSsr || undefined\n}\n\nconst Insertion: FC<InsertionProps> = ({ cache, htmlTag, serialized }) => {\n registerStyles(cache, serialized, htmlTag)\n\n const style = useInsertionEffectAlwaysWithSyncFallback(() =>\n insertStyles(cache, serialized),\n )\n\n if (!createdDom() && !isUndefined(style)) {\n let className = serialized.name\n let next = serialized.next\n\n while (next !== undefined) {\n className = cx(className, next.name) ?? \"\"\n next = next.next\n }\n\n return (\n <style\n data-emotion={cx(cache.key, className)}\n dangerouslySetInnerHTML={{ __html: style }}\n nonce={cache.sheet.nonce}\n />\n )\n } else {\n return null\n }\n}\n\nconst useSplitProps = <Y extends Dict, M extends Dict>(\n props: Dict,\n shouldForwardProp?: ShouldForwardProp,\n) => {\n const propsRef = useRef(props)\n\n if (!isEqual(propsRef.current, props)) propsRef.current = props\n\n const computedProps = propsRef.current\n\n return useMemo(\n () => splitObject<Y, M>(computedProps, shouldForwardProp),\n [computedProps, shouldForwardProp],\n )\n}\n\nexport const [ColorSchemeContext, useColorSchemeContext] =\n createContext<ColorScheme>({\n name: \"ColorSchemeContext\",\n strict: false,\n })\n\nexport const [HydrationContext, useHydrationContext] = createContext<boolean>({\n name: \"HydrationContext\",\n strict: false,\n})\n\nexport interface StyledOptions<\n Y extends CSSPropObject = CSSPropObject,\n M extends CSSModifierObject = CSSModifierObject,\n D extends CSSModifierObject = CSSModifierObject,\n H extends number | string | symbol = string,\n> extends Omit<ComponentStyle<Y, M, D>, \"className\"> {\n className?: ((system: System) => string) | string\n displayName?: string\n forwardAsChild?: boolean\n name?: string\n shouldForwardProp?: boolean | ShouldForwardProp\n target?: string\n forwardProps?: string[]\n transferProps?: H[]\n}\n\nexport function createStyled<\n Y extends As,\n M extends object = {},\n D extends CSSPropObject = CSSPropObject,\n H extends CSSModifierObject = CSSModifierObject,\n R extends CSSModifierObject = CSSModifierObject,\n>(\n el: Y,\n {\n name,\n base,\n compounds,\n props,\n sizes,\n variants,\n defaultProps,\n transferProps,\n ...options\n }: StyledOptions<D, H, R, keyof M> = {},\n) {\n const displayName = options.displayName ?? getDisplayName(name, \"\")\n const shouldForwardProp = !options.shouldForwardProp\n ? createShouldForwardProp(options.forwardProps)\n : undefined\n const style = filterUndefined({\n base,\n compounds,\n props,\n sizes,\n variants,\n defaultProps,\n })\n\n const StyledComponent = withEmotionCache<Dict>(function (\n { as: Component = el, asChild, children, ...props },\n cache,\n ref,\n ) {\n let className: string | undefined = \"\"\n\n const system = useSystem()\n const { theme } = useTheme<UsageTheme>()\n const componentStyleOptions = {\n name,\n className: system.utils.getClassName(\n runIfFn(options.className, system) ?? toKebabCase(name ?? \"\"),\n ),\n style,\n transferProps,\n }\n const registered = useRef<string[]>([])\n const htmlTag = isString(Component)\n const forwardAsChild =\n options.forwardAsChild || options.forwardProps?.includes(\"asChild\")\n const [omittedProps, styleProps] = useSplitProps(props, shouldForwardProp)\n const [, rest] = useComponentStyle<any, {}>(\n omittedProps,\n componentStyleOptions,\n )\n const suppressHydrationWarning = useHydrationContext()\n const [cssArray, colorScheme, forwardProps] = useMemo(() => {\n const { css, colorScheme, ...forwardProps } = rest\n\n return [toArray(css), colorScheme, forwardProps]\n }, [rest])\n\n styleProps.colorScheme ??= colorScheme\n forwardProps.suppressHydrationWarning ??= suppressHydrationWarning\n\n if (forwardProps.className)\n className = getRegisteredStyles(\n cache.registered,\n registered.current,\n forwardProps.className,\n ).trim()\n\n const interpolations = useMemo(\n () => [\n ...registered.current,\n ...filterEmpty([...cssArray, styleProps].map(css(system, theme))),\n ],\n [cssArray, system, styleProps, theme],\n )\n\n const serialized = useMemo(\n () => serializeStyles(interpolations, cache.registered),\n [interpolations, cache.registered],\n )\n\n className = cx(\n className,\n serialized.styles ? `${cache.key}-${serialized.name}` : undefined,\n )\n className = cx(className, options.target)\n\n if (!className) className = undefined\n\n const mergedProps: HTMLProps = { ...forwardProps, className, children }\n\n return (\n <ColorSchemeContext value={styleProps.colorScheme}>\n <HydrationContext value={mergedProps.suppressHydrationWarning}>\n <Insertion cache={cache} htmlTag={htmlTag} serialized={serialized} />\n\n {asChild && !forwardAsChild ? (\n <Slot ref={ref} {...mergedProps} />\n ) : (\n <Component ref={ref} {...mergedProps} />\n )}\n </HydrationContext>\n </ColorSchemeContext>\n )\n }) as StyledComponent<Y, M>\n\n StyledComponent.displayName = displayName || \"StyledComponent\"\n\n return StyledComponent\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAqDA,SAAS,sBAAsB,MAAc,WAAmB;CAC9D,MAAM,WAAW,IAAI;CAErB,OAAO,KACJ,WACC,GAAG,SAAS,0BAA0B,YACtC,2BAA2B,UAC7B,CAAC,CACA,WACC,GAAG,SAAS,2BAA2B,YACvC,4BAA4B,UAC9B;AACJ;AAEA,SAAS,aAAa,OAAqB,YAA8B;CACvE,MAAM,YAAY,GAAG,MAAM,IAAI,GAAG,WAAW;CAE7C,IAAI,EAAA,GAACA,cAAAA,YAAAA,CAAY,MAAM,SAAS,WAAW,KAAK,GAAG;CAEnD,MAAM,QAAQ,OAAO,OAAO,MAAM,KAAK;CAEvC,MAAM,UAAU,SAAS;EACvB,MAAM,MAAM,OAAO,sBAAsB,MAAM,SAAS,CAAC;CAC3D;CAEA,IAAI,cAAc;CAClB,IAAI,UAAwC;CAE5C,GAAG;EACD,MAAM,QACJ,MAAM,OACJ,eAAe,UAAU,IAAI,cAAc,IAC3C,SACA,OACA,IACF,KAAK,KAAA;EAEP,IAAI,EAAA,GAACC,cAAAA,WAAAA,CAAW,KAAK,EAAA,GAACD,cAAAA,YAAAA,CAAY,KAAK,GACrC,eAAe,sBAAsB,OAAO,SAAS;EAEvD,UAAU,QAAQ;CACpB,SAAS,YAAY,KAAA;CAErB,OAAO,eAAe,KAAA;AACxB;AAEA,MAAM,aAAiC,EAAE,OAAO,SAAS,iBAAiB;CACxE,eAAe,OAAO,YAAY,OAAO;CAEzC,MAAM,QAAQ,+CACZ,aAAa,OAAO,UAAU,CAChC;CAEA,IAAI,EAAA,GAACC,cAAAA,WAAAA,CAAW,KAAK,EAAA,GAACD,cAAAA,YAAAA,CAAY,KAAK,GAAG;EACxC,IAAI,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