@yamada-ui/react 2.3.0-dev-20261024181815 → 2.3.0-dev-20261026034146
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/components/accordion/use-accordion.cjs +4 -5
- package/dist/cjs/components/accordion/use-accordion.cjs.map +1 -1
- package/dist/cjs/components/checkbox/use-checkbox-group.cjs +6 -6
- package/dist/cjs/components/checkbox/use-checkbox-group.cjs.map +1 -1
- package/dist/cjs/components/checkbox/use-checkbox.cjs +17 -18
- package/dist/cjs/components/checkbox/use-checkbox.cjs.map +1 -1
- package/dist/cjs/components/color-picker/use-color-picker.cjs +14 -16
- package/dist/cjs/components/color-picker/use-color-picker.cjs.map +1 -1
- package/dist/cjs/components/color-selector/use-color-selector.cjs +4 -5
- package/dist/cjs/components/color-selector/use-color-selector.cjs.map +1 -1
- package/dist/cjs/components/dropzone/use-dropzone.cjs +3 -4
- package/dist/cjs/components/dropzone/use-dropzone.cjs.map +1 -1
- package/dist/cjs/components/file-input/use-file-input.cjs +5 -5
- package/dist/cjs/components/file-input/use-file-input.cjs.map +1 -1
- package/dist/cjs/components/menu/use-menu.cjs +36 -49
- package/dist/cjs/components/menu/use-menu.cjs.map +1 -1
- package/dist/cjs/components/modal/use-modal.cjs +5 -7
- package/dist/cjs/components/modal/use-modal.cjs.map +1 -1
- package/dist/cjs/components/native-popover/use-native-popover.cjs +8 -8
- package/dist/cjs/components/native-popover/use-native-popover.cjs.map +1 -1
- package/dist/cjs/components/pin-input/use-pin-input.cjs +10 -9
- package/dist/cjs/components/pin-input/use-pin-input.cjs.map +1 -1
- package/dist/cjs/components/radio/use-radio-group.cjs +12 -13
- package/dist/cjs/components/radio/use-radio-group.cjs.map +1 -1
- package/dist/cjs/components/radio/use-radio.cjs +15 -18
- package/dist/cjs/components/radio/use-radio.cjs.map +1 -1
- package/dist/cjs/components/saturation-slider/use-saturation-slider.cjs +4 -6
- package/dist/cjs/components/saturation-slider/use-saturation-slider.cjs.map +1 -1
- package/dist/cjs/components/select/use-select.cjs +5 -6
- package/dist/cjs/components/select/use-select.cjs.map +1 -1
- package/dist/cjs/components/sidebar/use-sidebar.cjs +13 -19
- package/dist/cjs/components/sidebar/use-sidebar.cjs.map +1 -1
- package/dist/cjs/components/slider/use-slider.cjs +13 -18
- package/dist/cjs/components/slider/use-slider.cjs.map +1 -1
- package/dist/cjs/components/steps/use-steps.cjs +4 -6
- package/dist/cjs/components/steps/use-steps.cjs.map +1 -1
- package/dist/cjs/components/tabs/use-tabs.cjs +5 -5
- package/dist/cjs/components/tabs/use-tabs.cjs.map +1 -1
- package/dist/cjs/components/tooltip/use-tooltip.cjs +13 -14
- package/dist/cjs/components/tooltip/use-tooltip.cjs.map +1 -1
- package/dist/cjs/core/components/props.cjs +12 -1
- package/dist/cjs/core/components/props.cjs.map +1 -1
- package/dist/cjs/core/index.cjs +2 -0
- package/dist/cjs/core/system/index.cjs +2 -0
- package/dist/cjs/core/system/styled.cjs +23 -12
- package/dist/cjs/core/system/styled.cjs.map +1 -1
- package/dist/cjs/hooks/use-combobox/index.cjs +23 -28
- package/dist/cjs/hooks/use-combobox/index.cjs.map +1 -1
- package/dist/cjs/index.cjs +4 -0
- package/dist/esm/components/accordion/use-accordion.js +4 -5
- package/dist/esm/components/accordion/use-accordion.js.map +1 -1
- package/dist/esm/components/checkbox/use-checkbox-group.js +6 -6
- package/dist/esm/components/checkbox/use-checkbox-group.js.map +1 -1
- package/dist/esm/components/checkbox/use-checkbox.js +17 -18
- package/dist/esm/components/checkbox/use-checkbox.js.map +1 -1
- package/dist/esm/components/color-picker/use-color-picker.js +14 -16
- package/dist/esm/components/color-picker/use-color-picker.js.map +1 -1
- package/dist/esm/components/color-selector/use-color-selector.js +4 -5
- package/dist/esm/components/color-selector/use-color-selector.js.map +1 -1
- package/dist/esm/components/dropzone/use-dropzone.js +3 -4
- package/dist/esm/components/dropzone/use-dropzone.js.map +1 -1
- package/dist/esm/components/file-input/use-file-input.js +5 -5
- package/dist/esm/components/file-input/use-file-input.js.map +1 -1
- package/dist/esm/components/menu/use-menu.js +36 -49
- package/dist/esm/components/menu/use-menu.js.map +1 -1
- package/dist/esm/components/modal/use-modal.js +5 -7
- package/dist/esm/components/modal/use-modal.js.map +1 -1
- package/dist/esm/components/native-popover/use-native-popover.js +8 -8
- package/dist/esm/components/native-popover/use-native-popover.js.map +1 -1
- package/dist/esm/components/pin-input/use-pin-input.js +10 -9
- package/dist/esm/components/pin-input/use-pin-input.js.map +1 -1
- package/dist/esm/components/radio/use-radio-group.js +12 -13
- package/dist/esm/components/radio/use-radio-group.js.map +1 -1
- package/dist/esm/components/radio/use-radio.js +15 -18
- package/dist/esm/components/radio/use-radio.js.map +1 -1
- package/dist/esm/components/saturation-slider/use-saturation-slider.js +4 -6
- package/dist/esm/components/saturation-slider/use-saturation-slider.js.map +1 -1
- package/dist/esm/components/select/use-select.js +5 -6
- package/dist/esm/components/select/use-select.js.map +1 -1
- package/dist/esm/components/sidebar/use-sidebar.js +13 -19
- package/dist/esm/components/sidebar/use-sidebar.js.map +1 -1
- package/dist/esm/components/slider/use-slider.js +13 -18
- package/dist/esm/components/slider/use-slider.js.map +1 -1
- package/dist/esm/components/steps/use-steps.js +4 -6
- package/dist/esm/components/steps/use-steps.js.map +1 -1
- package/dist/esm/components/tabs/use-tabs.js +5 -5
- package/dist/esm/components/tabs/use-tabs.js.map +1 -1
- package/dist/esm/components/tooltip/use-tooltip.js +14 -15
- package/dist/esm/components/tooltip/use-tooltip.js.map +1 -1
- package/dist/esm/core/components/props.js +12 -1
- package/dist/esm/core/components/props.js.map +1 -1
- package/dist/esm/core/index.js +2 -2
- package/dist/esm/core/system/index.js +2 -2
- package/dist/esm/core/system/styled.js +22 -13
- package/dist/esm/core/system/styled.js.map +1 -1
- package/dist/esm/hooks/use-combobox/index.js +23 -28
- package/dist/esm/hooks/use-combobox/index.js.map +1 -1
- package/dist/esm/index.js +4 -2
- package/dist/types/components/chart/polar-chart.style.d.ts +1 -1
- package/dist/types/components/menu/use-menu.d.ts +1 -1
- package/dist/types/components/steps/use-steps.d.ts +1 -1
- package/dist/types/components/tabs/use-tabs.d.ts +1 -1
- package/dist/types/core/components/index.d.ts +2 -2
- package/dist/types/core/components/props.d.ts +2 -1
- package/dist/types/core/index.d.ts +3 -3
- package/dist/types/core/system/index.d.ts +2 -2
- package/dist/types/core/system/styled.d.ts +1 -0
- package/dist/types/hooks/use-combobox/index.d.ts +1 -1
- package/dist/types/index.d.ts +4 -4
- package/package.json +2 -2
|
@@ -233,31 +233,26 @@ const useSlider = (props = {}) => {
|
|
|
233
233
|
getRootProps,
|
|
234
234
|
getThumbProps: (0, react.useCallback)(({ index = 0, ...rest } = {}) => {
|
|
235
235
|
const { max, min } = getMinMax(index);
|
|
236
|
-
|
|
236
|
+
return require_props.mergeProps({
|
|
237
237
|
...dataProps,
|
|
238
238
|
...ariaProps,
|
|
239
239
|
"aria-label": t("Slider thumb"),
|
|
240
|
+
"aria-labelledby": ariaLabelledBy,
|
|
240
241
|
"aria-orientation": orientation,
|
|
241
242
|
"aria-valuemax": max,
|
|
242
243
|
"aria-valuemin": min,
|
|
243
244
|
role: "slider",
|
|
244
|
-
tabIndex: interactive ? 0 : -1
|
|
245
|
-
|
|
246
|
-
"aria-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
} else {
|
|
256
|
-
props["data-end"] = (0, require_utils_index.utils_exports.dataAttr)(index === 0);
|
|
257
|
-
props["aria-valuenow"] = value;
|
|
258
|
-
props["aria-valuetext"] = ariaValueText ?? getAriaValueText?.(value, index) ?? value.toString();
|
|
259
|
-
}
|
|
260
|
-
return props;
|
|
245
|
+
tabIndex: interactive ? 0 : -1
|
|
246
|
+
}, range ? {
|
|
247
|
+
"aria-valuenow": value[index],
|
|
248
|
+
"aria-valuetext": ariaValueText ?? getAriaValueText?.(value[index], index) ?? value[index].toString(),
|
|
249
|
+
"data-end": (0, require_utils_index.utils_exports.dataAttr)(index === 1),
|
|
250
|
+
"data-start": (0, require_utils_index.utils_exports.dataAttr)(index === 0)
|
|
251
|
+
} : {
|
|
252
|
+
"aria-valuenow": value,
|
|
253
|
+
"aria-valuetext": ariaValueText ?? getAriaValueText?.(value, index) ?? value.toString(),
|
|
254
|
+
"data-end": (0, require_utils_index.utils_exports.dataAttr)(index === 0)
|
|
255
|
+
}, rest, { onKeyDown: onKeyDown(index) })();
|
|
261
256
|
}, [
|
|
262
257
|
t,
|
|
263
258
|
ariaLabelledBy,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-slider.cjs","names":["useFieldProps","useControllableState","useI18n","useRef","usePanEvent","useCallback","mergeProps","visuallyHiddenAttributes","mergeRefs"],"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":";;;;;;;;;;;AA2GA,MAAa,aACX,QAA2B,CAAC,MACzB;CACH,MAAM,EACJ,OAAO,EACL,IACA,KACA,MACA,mBAAmB,gBACnB,kBAAkB,eAClB,gBAAgB,GAChB,eAAe,GACf,UACA,kBACA,MAAM,KACN,MAAM,GACN,cAAc,cACd,UACA,UACA,OAAO,GACP,OAAO,WACP,UAAU,cACV,aACA,eACA,GAAG,QAEL,WACA,WACA,eACEA,wBAAAA,cAAc,KAAK;CACvB,MAAM,CAAC,OAAO,YAAYC,2CAAAA,qBAAqB;EAC7C;EACA,OAAO;EACP,UAAU;CACZ,CAAC;CACD,MAAM,EAAE,MAAMC,sBAAAA,QAAQ,QAAQ;CAC9B,MAAM,gBAAA,GAAeC,MAAAA,OAAAA,CAAO,CAAC;CAC7B,MAAM,cAAc,EAAE,YAAY;CAClC,MAAM,CAAC,GAAG,oBAAoBC,kCAAAA,YAA4B;EACxD,QAAQ,GAAG,OAAO,SAAS;GACzB,IAAI,CAAC,aAAa;GAElB,MAAM,WAAW,YAAY,OAAO,IAAI;GAExC,IAAI,OAAO;IACT,MAAM,QAAQ,aAAa,YAAY;IACvC,MAAM,gBAAgB,aAAa,YA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EAAE,QAAQ,GAAG,GAAG,SAAS,CAAC,MAAM;GAC/B,MAAM,EAAE,KAAK,QAAQ,UAAU,KAAK;GAEpC,MAAM,QAAmB;IACvB,GAAG;IACH,GAAG;IACH,cAAc,EAAE,cAAc;IAC9B,oBAAoB;IACpB,iBAAiB;IACjB,iBAAiB;IACjB,MAAM;IACN,UAAU,cAAc,IAAI;IAC5B,GAAG;IACH,oBAAA,GAAA,oBAAA,cAAmB,GAAA,CAAG,KAAK,oBAAoB,cAAc;IAC7D,YAAA,GAAA,oBAAA,cAAW,WAAA,CAAW,KAAK,WAAW,UAAU,KAAK,CAAC;GACxD;GAEA,IAAI,OAAO;IACT,MAAM,eAAe,MAAM;IAE3B,MAAM,iBAAA,GAAA,oBAAA,cAAgB,SAAA,CAAS,UAAU,CAAC;IAC1C,MAAM,eAAA,GAAA,oBAAA,cAAc,SAAA,CAAS,UAAU,CAAC;IACxC,MAAM,mBAAmB;IACzB,MAAM,oBACJ,iBACA,mBAAmB,cAAc,KAAK,KACtC,aAAa,SAAS;GAC1B,OAAO;IACL,MAAM,eAAA,GAAA,oBAAA,cAAc,SAAA,CAAS,UAAU,CAAC;IACxC,MAAM,mBAAmB;IACzB,MAAM,oBACJ,iBAAiB,mBAAmB,OAAO,KAAK,KAAK,MAAM,SAAS;GACxE;GAEA,OAAO;EACT,GACA;GACE;GACA;GACA;GACA;GACA;GACA;GACA;GACA;GACA;GACA;GACA;GACA;EACF,CAcY;EACZ;EACA;CACF;AACF"}
|
|
1
|
+
{"version":3,"file":"use-slider.cjs","names":["useFieldProps","useControllableState","useI18n","useRef","usePanEvent","useCallback","mergeProps","visuallyHiddenAttributes","mergeRefs"],"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,QAA2B,CAAC,MACzB;CACH,MAAM,EACJ,OAAO,EACL,IACA,KACA,MACA,mBAAmB,gBACnB,kBAAkB,eAClB,gBAAgB,GAChB,eAAe,GACf,UACA,kBACA,MAAM,KACN,MAAM,GACN,cAAc,cACd,UACA,UACA,OAAO,GACP,OAAO,WACP,UAAU,cACV,aACA,eACA,GAAG,QAEL,WACA,WACA,eACEA,wBAAAA,cAAc,KAAK;CACvB,MAAM,C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
|
1
1
|
"use client";
|
|
2
2
|
const require_context = require("../../utils/context.cjs");
|
|
3
3
|
const require_effect = require("../../utils/effect.cjs");
|
|
4
|
-
const require_ref = require("../../utils/ref.cjs");
|
|
5
4
|
const require_utils_index = require("../../utils/index.cjs");
|
|
6
5
|
const require_environment_provider = require("../../core/system/environment-provider.cjs");
|
|
7
6
|
const require_props = require("../../core/components/props.cjs");
|
|
@@ -78,7 +77,7 @@ const useSteps = ({ count = 0, defaultIndex = 0, index: indexProp, orientation =
|
|
|
78
77
|
onPrev
|
|
79
78
|
};
|
|
80
79
|
};
|
|
81
|
-
const useStepsItem = ({
|
|
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 = (0, react.useCallback)((
|
|
99
|
+
const getRootProps = (0, react.useCallback)((props = {}) => require_props.mergeProps({
|
|
100
|
+
ref: register,
|
|
101
101
|
"aria-current": current ? "step" : void 0,
|
|
102
|
-
"aria-labelledby": (0, require_utils_index.utils_exports.cx)(ariaLabelledbyProp, ariaLabelledby),
|
|
103
102
|
"data-orientation": orientation,
|
|
104
103
|
[statusDataAttr]: (0, require_utils_index.utils_exports.dataAttr)(true)
|
|
105
|
-
}, rest, props
|
|
106
|
-
ariaLabelledbyProp,
|
|
104
|
+
}, rest, props)(), [
|
|
107
105
|
current,
|
|
108
106
|
orientation,
|
|
109
107
|
statusDataAttr,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-steps.cjs","names":["createDescendants","createContext","useControllableState","useId","useCallback","mergeProps","useEnvironment","mergeRefs"],"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,wBACdA,oCAAAA,kBAAiC;AASrC,MAAM,CAAC,cAAc,mBAAmBC,gBAAAA,cAA4B,EAClE,MAAM,eACR,CAAC;AAMD,MAAM,CAAC,kBAAkB,uBAAuBA,gBAAAA,cAC9C,EACE,MA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,oBAAoB,cAAc;EACxD,oBAAoB;GACnB,kBAAA,GAAA,oBAAA,cAAiB,SAAA,CAAS,IAAI;CACjC,GACA,MACA,OACA,EAAE,KAAKE,YAAAA,UAAU,KAAK,QAAQ,EAAE,CAClC,CAAC,CAAC,GACJ;EAAC;EAAoB;EAAS;EAAa;EAAgB;EAAM;CAAQ,CAC3E;CAEA,MAAM,iBAAA,GAAkCH,MAAAA,YAAAA,EACrC,WAAW;GACT,kBAAA,GAAA,oBAAA,cAAiB,SAAA,CAAS,IAAI;EAC/B,GAAG;CACL,IACA,CAAC,cAAc,CACjB;CA4BA,OAAO;EACL;EACA;EACA;EACA;EACA,sBAAA,GA/B2CA,MAAAA,YAAAA,EAC1C,WAAW;IACT,kBAAA,GAAA,oBAAA,cAAiB,SAAA,CAAS,IAAI;GAC/B,GAAG;EACL,IACA,CAAC,cAAc,CA0BG;EAClB,oBAAA,GAxBoCA,MAAAA,YAAAA,EACnC,WAAW;IACT,kBAAA,GAAA,oBAAA,cAAiB,SAAA,CAAS,IAAI;GAC/B,GAAG;EACL,IACA,CAAC,cAAc,CAmBC;EAChB;EACA,oBAAA,GAlBoCA,MAAAA,YAAAA,EACnC,WAAW;GACV,oBAAoB;GACpB,MAAM;IACL,kBAAA,GAAA,oBAAA,cAAiB,SAAA,CAAS,IAAI;GAC/B,GAAG;EACL,IACA,CAAC,aAAa,cAAc,CAWZ;EAChB;CACF;AACF"}
|
|
1
|
+
{"version":3,"file":"use-steps.cjs","names":["createDescendants","createContext","useControllableState","useId","useCallback","mergeProps","useEnvironment"],"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,wBACdA,oCAAAA,kBAAiC;AASrC,MAAM,CAAC,cAAc,mBAAmBC,gBAAAA,cAA4B,EAClE,MAAM,eACR,CAAC;AAMD,MAAM,CAAC,kBAAkB,uBAAuBA,gBAAAA,cAC9C,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,YAAYC,2CAAAA,qBAAqB;EAC7C,cAAc;EACd,OAAO;EACP;CACF,CAAC;CACD,MAAM,MAAA,GAAKC,MAAAA,MAAAA,CAAM;CAEjB,MAAM,aAAA,GAAYC,MAAAA,YAAAA,EACf,cAAwC;EACvC,IAAI,YAAY,OAAO,OAAO;OACzB,IAAI,YAAY,OAAO,OAA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0BG;EAClB,oBAAA,GAxBoCA,MAAAA,YAAAA,EACnC,WAAW;IACT,kBAAA,GAAA,oBAAA,cAAiB,SAAA,CAAS,IAAI;GAC/B,GAAG;EACL,IACA,CAAC,cAAc,CAmBC;EAChB;EACA,oBAAA,GAlBoCA,MAAAA,YAAAA,EACnC,WAAW;GACV,oBAAoB;GACpB,MAAM;IACL,kBAAA,GAAA,oBAAA,cAAiB,SAAA,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,
|
|
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: (0, react.useCallback)((
|
|
146
|
+
getRootProps: (0, react.useCallback)((props = {}) => require_props.mergeProps({
|
|
147
147
|
id,
|
|
148
|
-
|
|
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
|
|
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.cjs","names":["createDescendants","createContext","useId","useControllableState","useState","useCallback","mergeProps","mergeRefs"],"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,sBACdA,oCAAAA,kBAAqC;AAIzC,MAAM,EACJ,oBAAoB,4BACpB,eAAe,uBACf,gBAAgB,2BACdA,oCAAAA,kBAAkC;AAatC,MAAM,CAAC,aAAa,kBAAkBC,gBAAAA,cAA2B,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,QAAA,GAAOC,MAAAA,MAAAA,CAAM;CACnB,MAAM,iBAAiB,kBAAkB;CACzC,MAAM,sBAAsB,uBAAuB;CACnD,MAAM,CAAC,OAAO,YAAYC,2CAAAA,qBAAqB;EAC7C,cAAc;EACd,OAAO;EACP;CACF,CAAC;CACD,MAAM,CAAC,cAAc,oBAAA,GAAmBC,MAAAA,SAAAA,CAAiB,KAAK;CAC9D,MAAM,aAAa,gBAAgB;CAEnC,OAAO;CAEP,MAAM,mBAAA,GAAkBC,MAAAA,YAAAA,OAAkB;EACxC,MAAM,QAAQ,eAAe,kBAAkB;EAE/C,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,OAAO;EAC1D,CACF,CAAC,CAAC,EAAE,YAAY,MAAM,CAAC,GACzB;GACE;GACA;GACA;GACA;GACA;GACA;GACA;GACA;GACA;EACF,CAGmC;CAAE;AACzC;AAWA,MAAa,eAAe,EAC1B,IACA,mBAAmB,oBACnB,OACA,GAAG,WACmB;CACtB,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,eAAA,GAlBOF,MAAAA,YAAAA,EAC9B,EAAE,KAAK,mBAAmB,gBAAgB,GAAG,UAAU,CAAC,MACvDC,cAAAA,WACE;GACE;GACA,oBAAA,GAAA,oBAAA,cAAmB,GAAA,CAAG,oBAAoB,gBAAgB,KAAK;GAC/D,oBAAoB;GACpB,QAAQ,CAAC;GACT,MAAM;GACN,UAAU,WAAW,IAAI;EAC3B,GACA,MACA,OACA,EAAE,KAAKC,YAAAA,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.cjs","names":["createDescendants","createContext","useId","useControllableState","useState","useCallback","mergeProps","mergeRefs"],"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":";;;;;;;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;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,6 +1,5 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
const require_effect = require("../../utils/effect.cjs");
|
|
3
|
-
const require_ref = require("../../utils/ref.cjs");
|
|
4
3
|
const require_utils_index = require("../../utils/index.cjs");
|
|
5
4
|
const require_props = require("../../core/components/props.cjs");
|
|
6
5
|
const require_hooks_use_popper_index = require("../../hooks/use-popper/index.cjs");
|
|
@@ -70,21 +69,21 @@ const useTooltip = (props = {}) => {
|
|
|
70
69
|
clearTimeout(openTimeout.current);
|
|
71
70
|
clearTimeout(closeTimeout.current);
|
|
72
71
|
});
|
|
73
|
-
const getTriggerProps = (0, react.useCallback)((
|
|
74
|
-
return getReferenceProps({
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
onBlur:
|
|
79
|
-
onClick:
|
|
80
|
-
onFocus:
|
|
81
|
-
onPointerEnter: (
|
|
72
|
+
const getTriggerProps = (0, react.useCallback)((props = {}) => {
|
|
73
|
+
return getReferenceProps(require_props.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: (
|
|
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.cjs","names":["usePopperProps","useId","useRef","useDisclosure","usePopper","useCallback","
|
|
1
|
+
{"version":3,"file":"use-tooltip.cjs","names":["usePopperProps","useId","useRef","useDisclosure","usePopper","useCallback","mergeProps","popperProps","useSplitProps"],"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,cAA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AAgB,WAAA,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,GAAGE,+BAAAA;CACH;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF;AAEA,MAAa,mBAIX,OACA,aACG;CACH,OAAOC,cAAAA,cACL,OACA,aAAa,QAAQ,QAAQ,CAAC,UAAU,SAAS,GAAQ,CAAC,CAC5D;AAWF"}
|
|
@@ -15,6 +15,13 @@ const cssProps = /* @__PURE__ */ new Set([
|
|
|
15
15
|
...require_styles.styleProperties,
|
|
16
16
|
...require_styles.vendorProperties
|
|
17
17
|
]);
|
|
18
|
+
const ariaSpaceSeparatedProps = /* @__PURE__ */ new Set([
|
|
19
|
+
"aria-controls",
|
|
20
|
+
"aria-describedby",
|
|
21
|
+
"aria-flowto",
|
|
22
|
+
"aria-labelledby",
|
|
23
|
+
"aria-owns"
|
|
24
|
+
]);
|
|
18
25
|
function createShouldForwardProp(forwardProps = []) {
|
|
19
26
|
return function(prop) {
|
|
20
27
|
if (forwardProps.includes(prop)) return true;
|
|
@@ -23,7 +30,7 @@ function createShouldForwardProp(forwardProps = []) {
|
|
|
23
30
|
};
|
|
24
31
|
}
|
|
25
32
|
function mergeProps(...args) {
|
|
26
|
-
return function({ mergeClassName = true, mergeCSS = true, mergeEvent = true, mergeRef = true, mergeStyle = true } = {}) {
|
|
33
|
+
return function({ mergeAria = true, mergeClassName = true, mergeCSS = true, mergeEvent = true, mergeRef = true, mergeStyle = true } = {}) {
|
|
27
34
|
let result = {};
|
|
28
35
|
for (const props of args) {
|
|
29
36
|
if ((0, require_utils_index.utils_exports.isUndefined)(props)) continue;
|
|
@@ -40,6 +47,10 @@ function mergeProps(...args) {
|
|
|
40
47
|
result[key] = (0, require_utils_index.utils_exports.cx)(result[key], props[key]);
|
|
41
48
|
continue;
|
|
42
49
|
}
|
|
50
|
+
if (mergeAria && ariaSpaceSeparatedProps.has(key)) {
|
|
51
|
+
result[key] = (0, require_utils_index.utils_exports.cx)(result[key], props[key]);
|
|
52
|
+
continue;
|
|
53
|
+
}
|
|
43
54
|
if (mergeStyle && key === "style") {
|
|
44
55
|
result[key] = (0, require_utils_index.utils_exports.merge)(result[key] ?? {}, props[key] ?? {});
|
|
45
56
|
continue;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"props.cjs","names":["conditionProperties","styleProperties","vendorProperties","mergeRefs","isEqual","useMemo"],"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\
|
|
1
|
+
{"version":3,"file":"props.cjs","names":["conditionProperties","styleProperties","vendorProperties","mergeRefs","isEqual","useMemo"],"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,GAAGA,mBAAAA;CACH,GAAGC,eAAAA;CACH,GAAGC,eAAAA;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,WAAW,MACX,aAAa,MACb,WAAW,MACX,aAAa,SACQ,CAAC,GAAG;EACzB,IAAI,SAAe,CAAC;EAEpB,KAAK,MAAM,SAAS,MAAM;GACxB,KAAA,GAAA,oBAAA,cAAI,YAAA,CAAY,KAAK,GAAG;GAExB,KAAK,MAAM,OAAO,QAAQ;I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A,cAAI,SAAA,CAAS,KAAK,GAAG;GAC1B,QAAQ,aAAa,OAAO,IAAI;GAEhC,KAAA,GAAA,oBAAA,cAAI,cAAA,CAAc,KAAK,GAAG;GAE1B,UAAA,GAAA,oBAAA,cAAS,MAAA,CAAM,QAAQ,GAAG,MAAM,MAAM,CAAC;EACzC;CACF,CAAC;CAED,OAAO;AACT;AAEA,SAAgB,gBACd,OACA,MACA;CACA,QAAA,GAAOA,MAAAA,QAAAA,OAAc,aAAa,OAAO,IAAI,GAAG,CAAC,OAAO,IAAI,CAAC;AAC/D"}
|
package/dist/cjs/core/index.cjs
CHANGED
|
@@ -43,6 +43,7 @@ exports.DEFAULT_LOCALE = require_constant.DEFAULT_LOCALE;
|
|
|
43
43
|
exports.DEFAULT_VAR_PREFIX = require_constant.DEFAULT_VAR_PREFIX;
|
|
44
44
|
exports.EnvironmentProvider = require_environment_provider.EnvironmentProvider;
|
|
45
45
|
exports.GlobalStyles = require_theme_provider.GlobalStyles;
|
|
46
|
+
exports.HydrationContext = require_styled.HydrationContext;
|
|
46
47
|
exports.SystemProvider = require_system_provider.SystemProvider;
|
|
47
48
|
exports.THEME_SCHEME_STORAGE_KEY = require_constant.THEME_SCHEME_STORAGE_KEY;
|
|
48
49
|
exports.ThemeProvider = require_theme_provider.ThemeProvider;
|
|
@@ -155,6 +156,7 @@ exports.useComponentSlotStyle = require_use_component_style.useComponentSlotStyl
|
|
|
155
156
|
exports.useComponentStyle = require_use_component_style.useComponentStyle;
|
|
156
157
|
exports.useEnvironment = require_environment_provider.useEnvironment;
|
|
157
158
|
exports.useExtractProps = require_props.useExtractProps;
|
|
159
|
+
exports.useHydrationContext = require_styled.useHydrationContext;
|
|
158
160
|
exports.useInjectVarsIntoCss = require_use_inject_vars.useInjectVarsIntoCss;
|
|
159
161
|
exports.useInjectVarsIntoProps = require_use_inject_vars.useInjectVarsIntoProps;
|
|
160
162
|
exports.useSplitProps = require_props.useSplitProps;
|
|
@@ -20,6 +20,7 @@ exports.ColorModeScript = require_storage_script.ColorModeScript;
|
|
|
20
20
|
exports.ColorSchemeContext = require_styled.ColorSchemeContext;
|
|
21
21
|
exports.EnvironmentProvider = require_environment_provider.EnvironmentProvider;
|
|
22
22
|
exports.GlobalStyles = require_theme_provider.GlobalStyles;
|
|
23
|
+
exports.HydrationContext = require_styled.HydrationContext;
|
|
23
24
|
exports.SystemProvider = require_system_provider.SystemProvider;
|
|
24
25
|
exports.ThemeProvider = require_theme_provider.ThemeProvider;
|
|
25
26
|
exports.ThemeSchemeScript = require_storage_script.ThemeSchemeScript;
|
|
@@ -56,6 +57,7 @@ exports.useColorMode = require_color_mode_provider.useColorMode;
|
|
|
56
57
|
exports.useColorModeValue = require_use_color_mode_value.useColorModeValue;
|
|
57
58
|
exports.useColorSchemeContext = require_styled.useColorSchemeContext;
|
|
58
59
|
exports.useEnvironment = require_environment_provider.useEnvironment;
|
|
60
|
+
exports.useHydrationContext = require_styled.useHydrationContext;
|
|
59
61
|
exports.useSystem = require_system_provider.useSystem;
|
|
60
62
|
exports.useSystemColorMode = require_use_system_color_mode.useSystemColorMode;
|
|
61
63
|
exports.useTheme = require_theme_provider.useTheme;
|
|
@@ -65,6 +65,10 @@ const [ColorSchemeContext, useColorSchemeContext] = require_context.createContex
|
|
|
65
65
|
name: "ColorSchemeContext",
|
|
66
66
|
strict: false
|
|
67
67
|
});
|
|
68
|
+
const [HydrationContext, useHydrationContext] = require_context.createContext({
|
|
69
|
+
name: "HydrationContext",
|
|
70
|
+
strict: false
|
|
71
|
+
});
|
|
68
72
|
function createStyled(el, { name, base, compounds, props, sizes, variants, defaultProps, transferProps, ...options } = {}) {
|
|
69
73
|
const displayName = options.displayName ?? require_utils.getDisplayName(name, "");
|
|
70
74
|
const shouldForwardProp = !options.shouldForwardProp ? require_props.createShouldForwardProp(options.forwardProps) : void 0;
|
|
@@ -91,6 +95,7 @@ function createStyled(el, { name, base, compounds, props, sizes, variants, defau
|
|
|
91
95
|
const forwardAsChild = options.forwardAsChild || options.forwardProps?.includes("asChild");
|
|
92
96
|
const [omittedProps, styleProps] = useSplitProps(props, shouldForwardProp);
|
|
93
97
|
const [, rest] = require_use_component_style.useComponentStyle(omittedProps, componentStyleOptions);
|
|
98
|
+
const suppressHydrationWarning = useHydrationContext();
|
|
94
99
|
const [cssArray, colorScheme, forwardProps] = (0, react.useMemo)(() => {
|
|
95
100
|
const { css, colorScheme, ...forwardProps } = rest;
|
|
96
101
|
return [
|
|
@@ -100,6 +105,7 @@ function createStyled(el, { name, base, compounds, props, sizes, variants, defau
|
|
|
100
105
|
];
|
|
101
106
|
}, [rest]);
|
|
102
107
|
styleProps.colorScheme ??= colorScheme;
|
|
108
|
+
forwardProps.suppressHydrationWarning ??= suppressHydrationWarning;
|
|
103
109
|
if (forwardProps.className) className = (0, _emotion_utils.getRegisteredStyles)(cache.registered, registered.current, forwardProps.className).trim();
|
|
104
110
|
const interpolations = (0, react.useMemo)(() => [...registered.current, ...(0, require_utils_index.utils_exports.filterEmpty)([...cssArray, styleProps].map(require_css.css(system, theme)))], [
|
|
105
111
|
cssArray,
|
|
@@ -116,19 +122,22 @@ function createStyled(el, { name, base, compounds, props, sizes, variants, defau
|
|
|
116
122
|
className,
|
|
117
123
|
children
|
|
118
124
|
};
|
|
119
|
-
return /* @__PURE__ */ (0, react_jsx_runtime.
|
|
125
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(ColorSchemeContext, {
|
|
120
126
|
value: styleProps.colorScheme,
|
|
121
|
-
children:
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
127
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(HydrationContext, {
|
|
128
|
+
value: mergedProps.suppressHydrationWarning,
|
|
129
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(Insertion, {
|
|
130
|
+
cache,
|
|
131
|
+
htmlTag,
|
|
132
|
+
serialized
|
|
133
|
+
}), asChild && !forwardAsChild ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_slot.Slot, {
|
|
134
|
+
ref,
|
|
135
|
+
...mergedProps
|
|
136
|
+
}) : /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Component, {
|
|
137
|
+
ref,
|
|
138
|
+
...mergedProps
|
|
139
|
+
})]
|
|
140
|
+
})
|
|
132
141
|
});
|
|
133
142
|
});
|
|
134
143
|
StyledComponent.displayName = displayName || "StyledComponent";
|
|
@@ -136,7 +145,9 @@ function createStyled(el, { name, base, compounds, props, sizes, variants, defau
|
|
|
136
145
|
}
|
|
137
146
|
//#endregion
|
|
138
147
|
exports.ColorSchemeContext = ColorSchemeContext;
|
|
148
|
+
exports.HydrationContext = HydrationContext;
|
|
139
149
|
exports.createStyled = createStyled;
|
|
140
150
|
exports.useColorSchemeContext = useColorSchemeContext;
|
|
151
|
+
exports.useHydrationContext = useHydrationContext;
|
|
141
152
|
|
|
142
153
|
//# sourceMappingURL=styled.cjs.map
|