@yamada-ui/react 2.3.4-dev-20261114103548 → 2.3.4-dev-20261115223423

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.
@@ -1,6 +1,5 @@
1
1
  "use client";
2
2
  const require_dom = require("../../utils/dom.cjs");
3
- const require_ref = require("../../utils/ref.cjs");
4
3
  const require_utils_index = require("../../utils/index.cjs");
5
4
  const require_props = require("../../core/components/props.cjs");
6
5
  const require_hooks_use_controllable_state_index = require("../../hooks/use-controllable-state/index.cjs");
@@ -41,30 +40,24 @@ const useSwitch = (props = {}) => {
41
40
  const getThumbProps = (0, react.useCallback)((props = {}) => require_props.mergeProps(dataProps, { "data-checked": (0, require_utils_index.utils_exports.dataAttr)(checked) }, props)(), [checked, dataProps]);
42
41
  return {
43
42
  checked,
44
- getInputProps: (0, react.useCallback)((props = {}) => {
45
- return {
46
- ...require_props.mergeProps(ariaProps, dataProps, {
47
- id,
48
- type: "checkbox",
49
- name,
50
- style: require_dom.visuallyHiddenAttributes.style,
51
- checked,
52
- disabled,
53
- readOnly,
54
- required,
55
- role: "switch",
56
- tabIndex: interactive ? 0 : -1,
57
- value
58
- }, {
59
- onBlur: eventProps.onBlur,
60
- onFocus: eventProps.onFocus
61
- }, props, {
62
- onChange,
63
- onKeyDown
64
- })({ mergeRef: false }),
65
- ref: require_ref.mergeRefs(inputRef, props.ref, ref)
66
- };
67
- }, [
43
+ getInputProps: (0, react.useCallback)((props = {}) => require_props.mergeProps(ariaProps, dataProps, eventProps, {
44
+ id,
45
+ ref: inputRef,
46
+ type: "checkbox",
47
+ name,
48
+ style: require_dom.visuallyHiddenAttributes.style,
49
+ checked,
50
+ disabled,
51
+ readOnly,
52
+ required,
53
+ role: "switch",
54
+ tabIndex: interactive ? 0 : -1,
55
+ value
56
+ }, props, {
57
+ ref,
58
+ onChange,
59
+ onKeyDown
60
+ })(), [
68
61
  ariaProps,
69
62
  dataProps,
70
63
  id,
@@ -1 +1 @@
1
- {"version":3,"file":"use-switch.cjs","names":["useId","useFieldProps","useRef","useControllableState","useCallback","mergeProps","visuallyHiddenAttributes","mergeRefs"],"sources":["../../../../src/components/switch/use-switch.ts"],"sourcesContent":["\"use client\"\n\nimport type {\n ChangeEvent,\n ChangeEventHandler,\n FocusEventHandler,\n KeyboardEvent,\n} from \"react\"\nimport type { HTMLProps, HTMLRefAttributes, PropGetter } from \"../../core\"\nimport type { FieldProps } from \"../field\"\nimport { useCallback, useId, useRef } from \"react\"\nimport { mergeProps } from \"../../core\"\nimport { useControllableState } from \"../../hooks/use-controllable-state\"\nimport { dataAttr, mergeRefs, visuallyHiddenAttributes } from \"../../utils\"\nimport { useFieldProps } from \"../field\"\n\nexport interface UseSwitchProps<Y extends number | string = string>\n extends\n Omit<HTMLProps<\"label\">, \"onBlur\" | \"onChange\" | \"onFocus\" | \"ref\">,\n HTMLRefAttributes<\"input\">,\n FieldProps {\n /**\n * If `true`, the switch will be checked.\n *\n * @default false\n */\n checked?: boolean\n /**\n * If `true`, the switch will be checked when the Enter key is pressed.\n *\n * @default true\n */\n checkOnEnter?: boolean\n /**\n * If `true`, the switch will be initially checked.\n *\n * @default false\n */\n defaultChecked?: boolean\n /**\n * id assigned to input.\n */\n id?: string\n /**\n * The HTML `name` attribute used for forms.\n */\n name?: string\n /**\n * The tab-index property of the underlying input element.\n */\n tabIndex?: number\n /**\n * The value to be used in the switch input.\n */\n value?: Y\n /**\n * The callback invoked when the switch is blurred.\n */\n onBlur?: FocusEventHandler<HTMLInputElement>\n /**\n * The callback invoked when the checked state changes.\n */\n onChange?: ChangeEventHandler<HTMLInputElement>\n /**\n * The callback invoked when the switch is focused.\n */\n onFocus?: FocusEventHandler<HTMLInputElement>\n}\n\nexport const useSwitch = <Y extends number | string = string>(\n props: UseSwitchProps<Y> = {},\n) => {\n const uuid = useId()\n const {\n props: {\n id = uuid,\n ref,\n name,\n checked: checkedProp,\n checkOnEnter = true,\n defaultChecked = false,\n disabled,\n readOnly,\n required,\n value,\n onChange: onChangeProp,\n ...rest\n },\n ariaProps,\n dataProps,\n eventProps,\n } = useFieldProps(props)\n const interactive = !(readOnly || disabled)\n const inputRef = useRef<HTMLInputElement>(null)\n const [checked, setChecked] = useControllableState({\n defaultValue: defaultChecked,\n value: checkedProp,\n })\n\n const onChange = useCallback(\n (ev: ChangeEvent<HTMLInputElement>) => {\n if (!interactive) return ev.preventDefault()\n\n setChecked(ev.target.checked)\n onChangeProp?.(ev)\n },\n [onChangeProp, setChecked, interactive],\n )\n\n const onKeyDown = useCallback(\n (ev: KeyboardEvent<HTMLInputElement>) => {\n if (interactive && checkOnEnter && ev.key === \"Enter\")\n inputRef.current?.click()\n },\n [interactive, checkOnEnter],\n )\n\n const getRootProps: PropGetter<\"label\"> = useCallback(\n (props = {}) =>\n mergeProps(\n dataProps,\n { htmlFor: id, \"data-checked\": dataAttr(checked) },\n rest,\n props,\n )(),\n [checked, rest, id, dataProps],\n )\n\n const getTrackProps: PropGetter = useCallback(\n (props = {}) =>\n mergeProps(dataProps, { \"data-checked\": dataAttr(checked) }, props)(),\n [checked, dataProps],\n )\n\n const getThumbProps: PropGetter = useCallback(\n (props = {}) =>\n mergeProps(dataProps, { \"data-checked\": dataAttr(checked) }, props)(),\n [checked, dataProps],\n )\n\n const getInputProps: PropGetter<\"input\"> = useCallback(\n (props = {}) => {\n const mergedProps = mergeProps(\n ariaProps,\n dataProps,\n {\n id,\n type: \"checkbox\",\n name,\n style: visuallyHiddenAttributes.style,\n checked,\n disabled,\n readOnly,\n required,\n role: \"switch\",\n tabIndex: interactive ? 0 : -1,\n value,\n },\n { onBlur: eventProps.onBlur, onFocus: eventProps.onFocus },\n props,\n { onChange, onKeyDown },\n )({ mergeRef: false })\n\n return {\n ...mergedProps,\n ref: mergeRefs(inputRef, props.ref, ref),\n }\n },\n [\n ariaProps,\n dataProps,\n id,\n name,\n checked,\n disabled,\n readOnly,\n required,\n interactive,\n value,\n ref,\n eventProps,\n onChange,\n onKeyDown,\n ],\n )\n\n const getLabelProps: PropGetter<\"span\"> = useCallback(\n (props = {}) =>\n mergeProps(dataProps, { \"data-checked\": dataAttr(checked) }, props)(),\n [dataProps, checked],\n )\n\n return {\n checked,\n getInputProps,\n getLabelProps,\n getRootProps,\n getThumbProps,\n getTrackProps,\n }\n}\n\nexport type UseSwitchReturn = ReturnType<typeof useSwitch>\n"],"mappings":";;;;;;;;;AAqEA,MAAa,aACX,QAA2B,CAAC,MACzB;CACH,MAAM,QAAA,GAAOA,MAAAA,MAAAA,CAAM;CACnB,MAAM,EACJ,OAAO,EACL,KAAK,MACL,KACA,MACA,SAAS,aACT,eAAe,MACf,iBAAiB,OACjB,UACA,UACA,UACA,OACA,UAAU,cACV,GAAG,QAEL,WACA,WACA,eACEC,wBAAAA,cAAc,KAAK;CACvB,MAAM,cAAc,EAAE,YAAY;CAClC,MAAM,YAAA,GAAWC,MAAAA,OAAAA,CAAyB,IAAI;CAC9C,MAAM,CAAC,SAAS,cAAcC,2CAAAA,qBAAqB;EACjD,cAAc;EACd,OAAO;CACT,CAAC;CAED,MAAM,YAAA,GAAWC,MAAAA,YAAAA,EACd,OAAsC;EACrC,IAAI,CAAC,aAAa,OAAO,GAAG,eAAe;EAE3C,WAAW,GAAG,OAAO,OAAO;EAC5B,eAAe,EAAE;CACnB,GACA;EAAC;EAAc;EAAY;CAAW,CACxC;CAEA,MAAM,aAAA,GAAYA,MAAAA,YAAAA,EACf,OAAwC;EACvC,IAAI,eAAe,gBAAgB,GAAG,QAAQ,SAC5C,SAAS,SAAS,MAAM;CAC5B,GACA,CAAC,aAAa,YAAY,CAC5B;CAEA,MAAM,gBAAA,GAAoCA,MAAAA,YAAAA,EACvC,QAAQ,CAAC,MACRC,cAAAA,WACE,WACA;EAAE,SAAS;EAAI,iBAAA,GAAA,oBAAA,cAAgB,SAAA,CAAS,OAAO;CAAE,GACjD,MACA,KACF,CAAC,CAAC,GACJ;EAAC;EAAS;EAAM;EAAI;CAAS,CAC/B;CAEA,MAAM,iBAAA,GAA4BD,MAAAA,YAAAA,EAC/B,QAAQ,CAAC,MACRC,cAAAA,WAAW,WAAW,EAAE,iBAAA,GAAA,oBAAA,cAAgB,SAAA,CAAS,OAAO,EAAE,GAAG,KAAK,CAAC,CAAC,GACtE,CAAC,SAAS,SAAS,CACrB;CAEA,MAAM,iBAAA,GAA4BD,MAAAA,YAAAA,EAC/B,QAAQ,CAAC,MACRC,cAAAA,WAAW,WAAW,EAAE,iBAAA,GAAA,oBAAA,cAAgB,SAAA,CAAS,OAAO,EAAE,GAAG,KAAK,CAAC,CAAC,GACtE,CAAC,SAAS,SAAS,CACrB;CAsDA,OAAO;EACL;EACA,gBAAA,GAtDyCD,MAAAA,YAAAA,EACxC,QAAQ,CAAC,MAAM;GAsBd,OAAO;IACL,GAtBkBC,cAAAA,WAClB,WACA,WACA;KACE;KACA,MAAM;KACN;KACA,OAAOC,YAAAA,yBAAyB;KAChC;KACA;KACA;KACA;KACA,MAAM;KACN,UAAU,cAAc,IAAI;KAC5B;IACF,GACA;KAAE,QAAQ,WAAW;KAAQ,SAAS,WAAW;IAAQ,GACzD,OACA;KAAE;KAAU;IAAU,CACxB,CAAC,CAAC,EAAE,UAAU,MAAM,CAGL;IACb,KAAKC,YAAAA,UAAU,UAAU,MAAM,KAAK,GAAG;GACzC;EACF,GACA;GACE;GACA;GACA;GACA;GACA;GACA;GACA;GACA;GACA;GACA;GACA;GACA;GACA;GACA;EACF,CAWY;EACZ,gBAAA,GATwCH,MAAAA,YAAAA,EACvC,QAAQ,CAAC,MACRC,cAAAA,WAAW,WAAW,EAAE,iBAAA,GAAA,oBAAA,cAAgB,SAAA,CAAS,OAAO,EAAE,GAAG,KAAK,CAAC,CAAC,GACtE,CAAC,WAAW,OAAO,CAMP;EACZ;EACA;EACA;CACF;AACF"}
1
+ {"version":3,"file":"use-switch.cjs","names":["useId","useFieldProps","useRef","useControllableState","useCallback","mergeProps","visuallyHiddenAttributes"],"sources":["../../../../src/components/switch/use-switch.ts"],"sourcesContent":["\"use client\"\n\nimport type {\n ChangeEvent,\n ChangeEventHandler,\n FocusEventHandler,\n KeyboardEvent,\n} from \"react\"\nimport type { HTMLProps, HTMLRefAttributes, PropGetter } from \"../../core\"\nimport type { FieldProps } from \"../field\"\nimport { useCallback, useId, useRef } from \"react\"\nimport { mergeProps } from \"../../core\"\nimport { useControllableState } from \"../../hooks/use-controllable-state\"\nimport { dataAttr, visuallyHiddenAttributes } from \"../../utils\"\nimport { useFieldProps } from \"../field\"\n\nexport interface UseSwitchProps<Y extends number | string = string>\n extends\n Omit<HTMLProps<\"label\">, \"onBlur\" | \"onChange\" | \"onFocus\" | \"ref\">,\n HTMLRefAttributes<\"input\">,\n FieldProps {\n /**\n * If `true`, the switch will be checked.\n *\n * @default false\n */\n checked?: boolean\n /**\n * If `true`, the switch will be checked when the Enter key is pressed.\n *\n * @default true\n */\n checkOnEnter?: boolean\n /**\n * If `true`, the switch will be initially checked.\n *\n * @default false\n */\n defaultChecked?: boolean\n /**\n * id assigned to input.\n */\n id?: string\n /**\n * The HTML `name` attribute used for forms.\n */\n name?: string\n /**\n * The tab-index property of the underlying input element.\n */\n tabIndex?: number\n /**\n * The value to be used in the switch input.\n */\n value?: Y\n /**\n * The callback invoked when the switch is blurred.\n */\n onBlur?: FocusEventHandler<HTMLInputElement>\n /**\n * The callback invoked when the checked state changes.\n */\n onChange?: ChangeEventHandler<HTMLInputElement>\n /**\n * The callback invoked when the switch is focused.\n */\n onFocus?: FocusEventHandler<HTMLInputElement>\n}\n\nexport const useSwitch = <Y extends number | string = string>(\n props: UseSwitchProps<Y> = {},\n) => {\n const uuid = useId()\n const {\n props: {\n id = uuid,\n ref,\n name,\n checked: checkedProp,\n checkOnEnter = true,\n defaultChecked = false,\n disabled,\n readOnly,\n required,\n value,\n onChange: onChangeProp,\n ...rest\n },\n ariaProps,\n dataProps,\n eventProps,\n } = useFieldProps(props)\n const interactive = !(readOnly || disabled)\n const inputRef = useRef<HTMLInputElement>(null)\n const [checked, setChecked] = useControllableState({\n defaultValue: defaultChecked,\n value: checkedProp,\n })\n\n const onChange = useCallback(\n (ev: ChangeEvent<HTMLInputElement>) => {\n if (!interactive) return ev.preventDefault()\n\n setChecked(ev.target.checked)\n onChangeProp?.(ev)\n },\n [onChangeProp, setChecked, interactive],\n )\n\n const onKeyDown = useCallback(\n (ev: KeyboardEvent<HTMLInputElement>) => {\n if (interactive && checkOnEnter && ev.key === \"Enter\")\n inputRef.current?.click()\n },\n [interactive, checkOnEnter],\n )\n\n const getRootProps: PropGetter<\"label\"> = useCallback(\n (props = {}) =>\n mergeProps(\n dataProps,\n { htmlFor: id, \"data-checked\": dataAttr(checked) },\n rest,\n props,\n )(),\n [checked, rest, id, dataProps],\n )\n\n const getTrackProps: PropGetter = useCallback(\n (props = {}) =>\n mergeProps(dataProps, { \"data-checked\": dataAttr(checked) }, props)(),\n [checked, dataProps],\n )\n\n const getThumbProps: PropGetter = useCallback(\n (props = {}) =>\n mergeProps(dataProps, { \"data-checked\": dataAttr(checked) }, props)(),\n [checked, dataProps],\n )\n\n const getInputProps: PropGetter<\"input\"> = useCallback(\n (props = {}) =>\n mergeProps(\n ariaProps,\n dataProps,\n eventProps,\n {\n id,\n ref: inputRef,\n type: \"checkbox\",\n name,\n style: visuallyHiddenAttributes.style,\n checked,\n disabled,\n readOnly,\n required,\n role: \"switch\",\n tabIndex: interactive ? 0 : -1,\n value,\n },\n props,\n { ref, onChange, onKeyDown },\n )(),\n [\n ariaProps,\n dataProps,\n id,\n name,\n checked,\n disabled,\n readOnly,\n required,\n interactive,\n value,\n ref,\n eventProps,\n onChange,\n onKeyDown,\n ],\n )\n\n const getLabelProps: PropGetter<\"span\"> = useCallback(\n (props = {}) =>\n mergeProps(dataProps, { \"data-checked\": dataAttr(checked) }, props)(),\n [dataProps, checked],\n )\n\n return {\n checked,\n getInputProps,\n getLabelProps,\n getRootProps,\n getThumbProps,\n getTrackProps,\n }\n}\n\nexport type UseSwitchReturn = ReturnType<typeof useSw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,YAAAA,EAC/B,QAAQ,CAAC,MACRC,cAAAA,WAAW,WAAW,EAAE,iBAAA,GAAA,oBAAA,cAAgB,SAAA,CAAS,OAAO,EAAE,GAAG,KAAK,CAAC,CAAC,GACtE,CAAC,SAAS,SAAS,CACrB;CAiDA,OAAO;EACL;EACA,gBAAA,GAjDyCD,MAAAA,YAAAA,EACxC,QAAQ,CAAC,MACRC,cAAAA,WACE,WACA,WACA,YACA;GACE;GACA,KAAK;GACL,MAAM;GACN;GACA,OAAOC,YAAAA,yBAAyB;GAChC;GACA;GACA;GACA;GACA,MAAM;GACN,UAAU,cAAc,IAAI;GAC5B;EACF,GACA,OACA;GAAE;GAAK;GAAU;EAAU,CAC7B,CAAC,CAAC,GACJ;GACE;GACA;GACA;GACA;GACA;GACA;GACA;GACA;GACA;GACA;GACA;GACA;GACA;GACA;EACF,CAWY;EACZ,gBAAA,GATwCF,MAAAA,YAAAA,EACvC,QAAQ,CAAC,MACRC,cAAAA,WAAW,WAAW,EAAE,iBAAA,GAAA,oBAAA,cAAgB,SAAA,CAAS,OAAO,EAAE,GAAG,KAAK,CAAC,CAAC,GACtE,CAAC,WAAW,OAAO,CAMP;EACZ;EACA;EACA;CACF;AACF"}
@@ -1,6 +1,5 @@
1
1
  "use client";
2
2
  import { visuallyHiddenAttributes } from "../../utils/dom.js";
3
- import { mergeRefs } from "../../utils/ref.js";
4
3
  import { utils_exports } from "../../utils/index.js";
5
4
  import { mergeProps } from "../../core/components/props.js";
6
5
  import { useControllableState } from "../../hooks/use-controllable-state/index.js";
@@ -41,30 +40,24 @@ const useSwitch = (props = {}) => {
41
40
  const getThumbProps = useCallback((props = {}) => mergeProps(dataProps, { "data-checked": (0, utils_exports.dataAttr)(checked) }, props)(), [checked, dataProps]);
42
41
  return {
43
42
  checked,
44
- getInputProps: useCallback((props = {}) => {
45
- return {
46
- ...mergeProps(ariaProps, dataProps, {
47
- id,
48
- type: "checkbox",
49
- name,
50
- style: visuallyHiddenAttributes.style,
51
- checked,
52
- disabled,
53
- readOnly,
54
- required,
55
- role: "switch",
56
- tabIndex: interactive ? 0 : -1,
57
- value
58
- }, {
59
- onBlur: eventProps.onBlur,
60
- onFocus: eventProps.onFocus
61
- }, props, {
62
- onChange,
63
- onKeyDown
64
- })({ mergeRef: false }),
65
- ref: mergeRefs(inputRef, props.ref, ref)
66
- };
67
- }, [
43
+ getInputProps: useCallback((props = {}) => mergeProps(ariaProps, dataProps, eventProps, {
44
+ id,
45
+ ref: inputRef,
46
+ type: "checkbox",
47
+ name,
48
+ style: visuallyHiddenAttributes.style,
49
+ checked,
50
+ disabled,
51
+ readOnly,
52
+ required,
53
+ role: "switch",
54
+ tabIndex: interactive ? 0 : -1,
55
+ value
56
+ }, props, {
57
+ ref,
58
+ onChange,
59
+ onKeyDown
60
+ })(), [
68
61
  ariaProps,
69
62
  dataProps,
70
63
  id,
@@ -1 +1 @@
1
- {"version":3,"file":"use-switch.js","names":["dataAttr"],"sources":["../../../../src/components/switch/use-switch.ts"],"sourcesContent":["\"use client\"\n\nimport type {\n ChangeEvent,\n ChangeEventHandler,\n FocusEventHandler,\n KeyboardEvent,\n} from \"react\"\nimport type { HTMLProps, HTMLRefAttributes, PropGetter } from \"../../core\"\nimport type { FieldProps } from \"../field\"\nimport { useCallback, useId, useRef } from \"react\"\nimport { mergeProps } from \"../../core\"\nimport { useControllableState } from \"../../hooks/use-controllable-state\"\nimport { dataAttr, mergeRefs, visuallyHiddenAttributes } from \"../../utils\"\nimport { useFieldProps } from \"../field\"\n\nexport interface UseSwitchProps<Y extends number | string = string>\n extends\n Omit<HTMLProps<\"label\">, \"onBlur\" | \"onChange\" | \"onFocus\" | \"ref\">,\n HTMLRefAttributes<\"input\">,\n FieldProps {\n /**\n * If `true`, the switch will be checked.\n *\n * @default false\n */\n checked?: boolean\n /**\n * If `true`, the switch will be checked when the Enter key is pressed.\n *\n * @default true\n */\n checkOnEnter?: boolean\n /**\n * If `true`, the switch will be initially checked.\n *\n * @default false\n */\n defaultChecked?: boolean\n /**\n * id assigned to input.\n */\n id?: string\n /**\n * The HTML `name` attribute used for forms.\n */\n name?: string\n /**\n * The tab-index property of the underlying input element.\n */\n tabIndex?: number\n /**\n * The value to be used in the switch input.\n */\n value?: Y\n /**\n * The callback invoked when the switch is blurred.\n */\n onBlur?: FocusEventHandler<HTMLInputElement>\n /**\n * The callback invoked when the checked state changes.\n */\n onChange?: ChangeEventHandler<HTMLInputElement>\n /**\n * The callback invoked when the switch is focused.\n */\n onFocus?: FocusEventHandler<HTMLInputElement>\n}\n\nexport const useSwitch = <Y extends number | string = string>(\n props: UseSwitchProps<Y> = {},\n) => {\n const uuid = useId()\n const {\n props: {\n id = uuid,\n ref,\n name,\n checked: checkedProp,\n checkOnEnter = true,\n defaultChecked = false,\n disabled,\n readOnly,\n required,\n value,\n onChange: onChangeProp,\n ...rest\n },\n ariaProps,\n dataProps,\n eventProps,\n } = useFieldProps(props)\n const interactive = !(readOnly || disabled)\n const inputRef = useRef<HTMLInputElement>(null)\n const [checked, setChecked] = useControllableState({\n defaultValue: defaultChecked,\n value: checkedProp,\n })\n\n const onChange = useCallback(\n (ev: ChangeEvent<HTMLInputElement>) => {\n if (!interactive) return ev.preventDefault()\n\n setChecked(ev.target.checked)\n onChangeProp?.(ev)\n },\n [onChangeProp, setChecked, interactive],\n )\n\n const onKeyDown = useCallback(\n (ev: KeyboardEvent<HTMLInputElement>) => {\n if (interactive && checkOnEnter && ev.key === \"Enter\")\n inputRef.current?.click()\n },\n [interactive, checkOnEnter],\n )\n\n const getRootProps: PropGetter<\"label\"> = useCallback(\n (props = {}) =>\n mergeProps(\n dataProps,\n { htmlFor: id, \"data-checked\": dataAttr(checked) },\n rest,\n props,\n )(),\n [checked, rest, id, dataProps],\n )\n\n const getTrackProps: PropGetter = useCallback(\n (props = {}) =>\n mergeProps(dataProps, { \"data-checked\": dataAttr(checked) }, props)(),\n [checked, dataProps],\n )\n\n const getThumbProps: PropGetter = useCallback(\n (props = {}) =>\n mergeProps(dataProps, { \"data-checked\": dataAttr(checked) }, props)(),\n [checked, dataProps],\n )\n\n const getInputProps: PropGetter<\"input\"> = useCallback(\n (props = {}) => {\n const mergedProps = mergeProps(\n ariaProps,\n dataProps,\n {\n id,\n type: \"checkbox\",\n name,\n style: visuallyHiddenAttributes.style,\n checked,\n disabled,\n readOnly,\n required,\n role: \"switch\",\n tabIndex: interactive ? 0 : -1,\n value,\n },\n { onBlur: eventProps.onBlur, onFocus: eventProps.onFocus },\n props,\n { onChange, onKeyDown },\n )({ mergeRef: false })\n\n return {\n ...mergedProps,\n ref: mergeRefs(inputRef, props.ref, ref),\n }\n },\n [\n ariaProps,\n dataProps,\n id,\n name,\n checked,\n disabled,\n readOnly,\n required,\n interactive,\n value,\n ref,\n eventProps,\n onChange,\n onKeyDown,\n ],\n )\n\n const getLabelProps: PropGetter<\"span\"> = useCallback(\n (props = {}) =>\n mergeProps(dataProps, { \"data-checked\": dataAttr(checked) }, props)(),\n [dataProps, checked],\n )\n\n return {\n checked,\n getInputProps,\n getLabelProps,\n getRootProps,\n getThumbProps,\n getTrackProps,\n }\n}\n\nexport type UseSwitchReturn = ReturnType<typeof useSwitch>\n"],"mappings":";;;;;;;;;AAqEA,MAAa,aACX,QAA2B,CAAC,MACzB;CACH,MAAM,OAAO,MAAM;CACnB,MAAM,EACJ,OAAO,EACL,KAAK,MACL,KACA,MACA,SAAS,aACT,eAAe,MACf,iBAAiB,OACjB,UACA,UACA,UACA,OACA,UAAU,cACV,GAAG,QAEL,WACA,WACA,eACE,cAAc,KAAK;CACvB,MAAM,cAAc,EAAE,YAAY;CAClC,MAAM,WAAW,OAAyB,IAAI;CAC9C,MAAM,CAAC,SAAS,cAAc,qBAAqB;EACjD,cAAc;EACd,OAAO;CACT,CAAC;CAED,MAAM,WAAW,aACd,OAAsC;EACrC,IAAI,CAAC,aAAa,OAAO,GAAG,eAAe;EAE3C,WAAW,GAAG,OAAO,OAAO;EAC5B,eAAe,EAAE;CACnB,GACA;EAAC;EA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,EAAE,GAAG,KAAK,CAAC,CAAC,GACtE,CAAC,WAAW,OAAO,CAMP;EACZ;EACA;EACA;CACF;AACF"}
1
+ {"version":3,"file":"use-switch.js","names":["dataAttr"],"sources":["../../../../src/components/switch/use-switch.ts"],"sourcesContent":["\"use client\"\n\nimport type {\n ChangeEvent,\n ChangeEventHandler,\n FocusEventHandler,\n KeyboardEvent,\n} from \"react\"\nimport type { HTMLProps, HTMLRefAttributes, PropGetter } from \"../../core\"\nimport type { FieldProps } from \"../field\"\nimport { useCallback, useId, useRef } from \"react\"\nimport { mergeProps } from \"../../core\"\nimport { useControllableState } from \"../../hooks/use-controllable-state\"\nimport { dataAttr, visuallyHiddenAttributes } from \"../../utils\"\nimport { useFieldProps } from \"../field\"\n\nexport interface UseSwitchProps<Y extends number | string = string>\n extends\n Omit<HTMLProps<\"label\">, \"onBlur\" | \"onChange\" | \"onFocus\" | \"ref\">,\n HTMLRefAttributes<\"input\">,\n FieldProps {\n /**\n * If `true`, the switch will be checked.\n *\n * @default false\n */\n checked?: boolean\n /**\n * If `true`, the switch will be checked when the Enter key is pressed.\n *\n * @default true\n */\n checkOnEnter?: boolean\n /**\n * If `true`, the switch will be initially checked.\n *\n * @default false\n */\n defaultChecked?: boolean\n /**\n * id assigned to input.\n */\n id?: string\n /**\n * The HTML `name` attribute used for forms.\n */\n name?: string\n /**\n * The tab-index property of the underlying input element.\n */\n tabIndex?: number\n /**\n * The value to be used in the switch input.\n */\n value?: Y\n /**\n * The callback invoked when the switch is blurred.\n */\n onBlur?: FocusEventHandler<HTMLInputElement>\n /**\n * The callback invoked when the checked state changes.\n */\n onChange?: ChangeEventHandler<HTMLInputElement>\n /**\n * The callback invoked when the switch is focused.\n */\n onFocus?: FocusEventHandler<HTMLInputElement>\n}\n\nexport const useSwitch = <Y extends number | string = string>(\n props: UseSwitchProps<Y> = {},\n) => {\n const uuid = useId()\n const {\n props: {\n id = uuid,\n ref,\n name,\n checked: checkedProp,\n checkOnEnter = true,\n defaultChecked = false,\n disabled,\n readOnly,\n required,\n value,\n onChange: onChangeProp,\n ...rest\n },\n ariaProps,\n dataProps,\n eventProps,\n } = useFieldProps(props)\n const interactive = !(readOnly || disabled)\n const inputRef = useRef<HTMLInputElement>(null)\n const [checked, setChecked] = useControllableState({\n defaultValue: defaultChecked,\n value: checkedProp,\n })\n\n const onChange = useCallback(\n (ev: ChangeEvent<HTMLInputElement>) => {\n if (!interactive) return ev.preventDefault()\n\n setChecked(ev.target.checked)\n onChangeProp?.(ev)\n },\n [onChangeProp, setChecked, interactive],\n )\n\n const onKeyDown = useCallback(\n (ev: KeyboardEvent<HTMLInputElement>) => {\n if (interactive && checkOnEnter && ev.key === \"Enter\")\n inputRef.current?.click()\n },\n [interactive, checkOnEnter],\n )\n\n const getRootProps: PropGetter<\"label\"> = useCallback(\n (props = {}) =>\n mergeProps(\n dataProps,\n { htmlFor: id, \"data-checked\": dataAttr(checked) },\n rest,\n props,\n )(),\n [checked, rest, id, dataProps],\n )\n\n const getTrackProps: PropGetter = useCallback(\n (props = {}) =>\n mergeProps(dataProps, { \"data-checked\": dataAttr(checked) }, props)(),\n [checked, dataProps],\n )\n\n const getThumbProps: PropGetter = useCallback(\n (props = {}) =>\n mergeProps(dataProps, { \"data-checked\": dataAttr(checked) }, props)(),\n [checked, dataProps],\n )\n\n const getInputProps: PropGetter<\"input\"> = useCallback(\n (props = {}) =>\n mergeProps(\n ariaProps,\n dataProps,\n eventProps,\n {\n id,\n ref: inputRef,\n type: \"checkbox\",\n name,\n style: visuallyHiddenAttributes.style,\n checked,\n disabled,\n readOnly,\n required,\n role: \"switch\",\n tabIndex: interactive ? 0 : -1,\n value,\n },\n props,\n { ref, onChange, onKeyDown },\n )(),\n [\n ariaProps,\n dataProps,\n id,\n name,\n checked,\n disabled,\n readOnly,\n required,\n interactive,\n value,\n ref,\n eventProps,\n onChange,\n onKeyDown,\n ],\n )\n\n const getLabelProps: PropGetter<\"span\"> = useCallback(\n (props = {}) =>\n mergeProps(dataProps, { \"data-checked\": dataAttr(checked) }, props)(),\n [dataProps, checked],\n )\n\n return {\n checked,\n getInputProps,\n getLabelProps,\n getRootProps,\n getThumbProps,\n getTrackProps,\n }\n}\n\nexport type UseSwitchReturn = ReturnType<typeof useSwitch>\n"],"mappings":";;;;;;;;AAqEA,MAAa,aACX,QAA2B,CAAC,MACzB;CACH,MAAM,OAAO,MAAM;CACnB,MAAM,EACJ,OAAO,EACL,KAAK,MACL,KACA,MACA,SAAS,aACT,eAAe,MACf,iBAAiB,OACjB,UACA,UACA,UACA,OACA,UAAU,cACV,GAAG,QAEL,WACA,WACA,eACE,cAAc,KAAK;CACvB,MAAM,cAAc,EAAE,YAAY;CAClC,MAAM,WAAW,OAAyB,IAAI;CAC9C,MAAM,CAAC,SAAS,cAAc,qBAAqB;EACjD,cAAc;EACd,OAAO;CACT,CAAC;CAED,MAAM,WAAW,aACd,OAAsC;EACrC,IAAI,CAAC,aAAa,OAAO,GAAG,eAAe;EAE3C,WAAW,GAAG,OAAO,OAAO;EAC5B,eAAe,EAAE;CACnB,GACA;EAAC;EAAc;EAAY;CAAW,CACxC;CAEA,MAAM,YAAY,aACf,OAAwC;EACvC,IAAI,eAAe,gBAAgB,GAAG,QAAQ,SAC5C,SAAS,SAAS,MAAM;CAC5B,GACA,CAAC,aAAa,YAAY,CAC5B;CAEA,MAAM,eAAoC,aACvC,QAAQ,CAAC,MACR,WACE,WACA;EAAE,SAAS;EAAI,iBAAA,GAAgBA,cAAAA,SAAAA,CAAS,OAAO;CAAE,GACjD,MACA,KACF,CAAC,CAAC,GACJ;EAAC;EAAS;EAAM;EAAI;CAAS,CAC/B;CAEA,MAAM,gBAA4B,aAC/B,QAAQ,CAAC,MACR,WAAW,WAAW,EAAE,iBAAA,GAAgBA,cAAAA,SAAAA,CAAS,OAAO,EAAE,GAAG,KAAK,CAAC,CAAC,GACtE,CAAC,SAAS,SAAS,CACrB;CAEA,MAAM,gBAA4B,aAC/B,QAAQ,CAAC,MACR,WAAW,WAAW,EAAE,iBAAA,GAAgBA,cAAAA,SAAAA,CAAS,OAAO,EAAE,GAAG,KAAK,CAAC,CAAC,GACtE,CAAC,SAAS,SAAS,CACrB;CAiDA,OAAO;EACL;EACA,eAjDyC,aACxC,QAAQ,CAAC,MACR,WACE,WACA,WACA,YACA;GACE;GACA,KAAK;GACL,MAAM;GACN;GACA,OAAO,yBAAyB;GAChC;GACA;GACA;GACA;GACA,MAAM;GACN,UAAU,cAAc,IAAI;GAC5B;EACF,GACA,OACA;GAAE;GAAK;GAAU;EAAU,CAC7B,CAAC,CAAC,GACJ;GACE;GACA;GACA;GACA;GACA;GACA;GACA;GACA;GACA;GACA;GACA;GACA;GACA;GACA;EACF,CAWY;EACZ,eATwC,aACvC,QAAQ,CAAC,MACR,WAAW,WAAW,EAAE,iBAAA,GAAgBA,cAAAA,SAAAA,CAAS,OAAO,EAAE,GAAG,KAAK,CAAC,CAAC,GACtE,CAAC,WAAW,OAAO,CAMP;EACZ;EACA;EACA;CACF;AACF"}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@yamada-ui/react",
3
3
  "type": "module",
4
- "version": "2.3.4-dev-20261114103548",
4
+ "version": "2.3.4-dev-20261115223423",
5
5
  "description": "React UI components of the Yamada, by the Yamada, for the Yamada built with React and Emotion",
6
6
  "keywords": [
7
7
  "yamada",