@fuf-stack/uniform 1.28.1 → 1.30.0
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/README.md +6 -0
- package/dist/Checkboxes/index.d.mts +57 -10
- package/dist/Checkboxes/index.d.mts.map +1 -1
- package/dist/Checkboxes/index.mjs +8 -3
- package/dist/Checkboxes/index.mjs.map +1 -1
- package/dist/DatePicker/index.d.mts +129 -1120
- package/dist/DatePicker/index.d.mts.map +1 -1
- package/dist/DatePicker/index.mjs +38 -32
- package/dist/DatePicker/index.mjs.map +1 -1
- package/dist/FieldArray/index.mjs +2 -2
- package/dist/FieldCard/index.mjs +1 -1
- package/dist/FieldReset/index.d.mts +415 -0
- package/dist/FieldReset/index.d.mts.map +1 -0
- package/dist/FieldReset/index.mjs +241 -0
- package/dist/FieldReset/index.mjs.map +1 -0
- package/dist/Form/index.d.mts +2 -2
- package/dist/Form/index.mjs +2 -2
- package/dist/Form/index.mjs.map +1 -1
- package/dist/{FormContext-BnNJYZOo.d.mts → FormContext-Dvt3MiKq.d.mts} +3 -3
- package/dist/{FormContext-BnNJYZOo.d.mts.map → FormContext-Dvt3MiKq.d.mts.map} +1 -1
- package/dist/Input/index.d.mts +63 -452
- package/dist/Input/index.d.mts.map +1 -1
- package/dist/Input/index.mjs +20 -15
- package/dist/Input/index.mjs.map +1 -1
- package/dist/RadioBoxes/index.d.mts +163 -894
- package/dist/RadioBoxes/index.d.mts.map +1 -1
- package/dist/RadioBoxes/index.mjs +27 -20
- package/dist/RadioBoxes/index.mjs.map +1 -1
- package/dist/RadioTabs/index.d.mts +93 -43
- package/dist/RadioTabs/index.d.mts.map +1 -1
- package/dist/RadioTabs/index.mjs +8 -5
- package/dist/RadioTabs/index.mjs.map +1 -1
- package/dist/Radios/index.d.mts +122 -1027
- package/dist/Radios/index.d.mts.map +1 -1
- package/dist/Radios/index.mjs +22 -18
- package/dist/Radios/index.mjs.map +1 -1
- package/dist/Select/index.d.mts +440 -3028
- package/dist/Select/index.d.mts.map +1 -1
- package/dist/Select/index.mjs +79 -45
- package/dist/Select/index.mjs.map +1 -1
- package/dist/Slider/index.d.mts +162 -1325
- package/dist/Slider/index.d.mts.map +1 -1
- package/dist/Slider/index.mjs +41 -28
- package/dist/Slider/index.mjs.map +1 -1
- package/dist/Switch/index.d.mts +125 -944
- package/dist/Switch/index.d.mts.map +1 -1
- package/dist/Switch/index.mjs +18 -14
- package/dist/Switch/index.mjs.map +1 -1
- package/dist/SwitchBox/index.d.mts +140 -99
- package/dist/SwitchBox/index.d.mts.map +1 -1
- package/dist/SwitchBox/index.mjs +9 -6
- package/dist/SwitchBox/index.mjs.map +1 -1
- package/dist/TextArea/index.d.mts +63 -452
- package/dist/TextArea/index.d.mts.map +1 -1
- package/dist/TextArea/index.mjs +17 -13
- package/dist/TextArea/index.mjs.map +1 -1
- package/dist/Time/index.d.mts +82 -729
- package/dist/Time/index.d.mts.map +1 -1
- package/dist/Time/index.mjs +22 -18
- package/dist/Time/index.mjs.map +1 -1
- package/dist/hooks/useFormContext/index.d.mts +1 -1
- package/dist/hooks/useUniformField/index.d.mts +1 -1
- package/dist/hooks/useUniformField/index.mjs +5 -1
- package/dist/hooks/useUniformField/index.mjs.map +1 -1
- package/dist/hooks/useUniformFieldArray/index.d.mts +1 -1
- package/dist/{index-DaiTW5Bl.d.mts → index-DsB0_365.d.mts} +9 -2
- package/dist/index-DsB0_365.d.mts.map +1 -0
- package/dist/{useFormContext-BhPzFXwF.d.mts → useFormContext-BSSUZ0Md.d.mts} +2 -2
- package/dist/{useFormContext-BhPzFXwF.d.mts.map → useFormContext-BSSUZ0Md.d.mts.map} +1 -1
- package/package.json +5 -4
- package/dist/index-DaiTW5Bl.d.mts.map +0 -1
package/dist/SwitchBox/index.mjs
CHANGED
|
@@ -16,11 +16,12 @@ const switchBoxVariants = tv({
|
|
|
16
16
|
thumbIcon: ""
|
|
17
17
|
},
|
|
18
18
|
variants: {
|
|
19
|
-
|
|
20
|
-
|
|
19
|
+
disabled: { true: { box: "pointer-events-none opacity-disabled" } },
|
|
20
|
+
invalid: { true: {
|
|
21
21
|
box: "!border-danger",
|
|
22
22
|
label: "!text-danger"
|
|
23
23
|
} },
|
|
24
|
+
readOnly: { true: { box: "**:cursor-not-allowed cursor-not-allowed opacity-disabled hover:bg-transparent" } },
|
|
24
25
|
size: {
|
|
25
26
|
sm: {
|
|
26
27
|
box: "gap-2 p-3",
|
|
@@ -45,7 +46,7 @@ const switchBoxVariants = tv({
|
|
|
45
46
|
* SwitchBox component - A card-like box with a switch control
|
|
46
47
|
*/
|
|
47
48
|
const SwitchBox = ({ className = void 0, description = void 0, icon = void 0, name, size = void 0, thumbIcon = void 0, ...uniformFieldProps }) => {
|
|
48
|
-
const { defaultValue, disabled, errorMessage, field, getErrorMessageProps, getHelperWrapperProps, invalid, label, onBlur, onChange, ref, required, testId } = useUniformField({
|
|
49
|
+
const { defaultValue, disabled, errorMessage, field, getErrorMessageProps, getHelperWrapperProps, invalid, label, onBlur, onChange, readOnly, ref, required, testId } = useUniformField({
|
|
49
50
|
name,
|
|
50
51
|
...uniformFieldProps
|
|
51
52
|
});
|
|
@@ -53,6 +54,7 @@ const SwitchBox = ({ className = void 0, description = void 0, icon = void 0, na
|
|
|
53
54
|
const { Component, slots, isSelected, getBaseProps, getInputProps, getWrapperProps } = useSwitch({
|
|
54
55
|
defaultSelected: !!defaultValue,
|
|
55
56
|
isDisabled: disabled,
|
|
57
|
+
isReadOnly: readOnly,
|
|
56
58
|
isSelected: !!field.value,
|
|
57
59
|
name: `${name}_switch`,
|
|
58
60
|
onValueChange: onChange,
|
|
@@ -60,8 +62,9 @@ const SwitchBox = ({ className = void 0, description = void 0, icon = void 0, na
|
|
|
60
62
|
thumbIcon
|
|
61
63
|
});
|
|
62
64
|
const variants = switchBoxVariants({
|
|
63
|
-
|
|
64
|
-
|
|
65
|
+
disabled,
|
|
66
|
+
invalid,
|
|
67
|
+
readOnly,
|
|
65
68
|
size
|
|
66
69
|
});
|
|
67
70
|
const classNames = variantsToClassNames(variants, className, "box");
|
|
@@ -78,7 +81,7 @@ const SwitchBox = ({ className = void 0, description = void 0, icon = void 0, na
|
|
|
78
81
|
checked: !!field.value,
|
|
79
82
|
name,
|
|
80
83
|
onChange: (e) => {
|
|
81
|
-
onChange(e.target.checked);
|
|
84
|
+
if (!readOnly) onChange(e.target.checked);
|
|
82
85
|
},
|
|
83
86
|
onFocus: () => {
|
|
84
87
|
visualSwitchRef.current?.focus();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","names":[],"sources":["../../src/SwitchBox/SwitchBox.tsx","../../src/SwitchBox/index.ts"],"sourcesContent":["import type { TVClassName } from '@fuf-stack/pixel-utils';\nimport type { SwitchProps as HeroSwitchProps } from '@heroui/switch';\nimport type { ReactNode } from 'react';\n\nimport { useRef } from 'react';\n\nimport { useSwitch } from '@heroui/switch';\nimport { VisuallyHidden } from '@react-aria/visually-hidden';\n\nimport { cn, tv, variantsToClassNames } from '@fuf-stack/pixel-utils';\n\nimport { useUniformField } from '../hooks/useUniformField';\n\nexport const switchBoxVariants = tv({\n slots: {\n box: 'group inline-flex w-full cursor-pointer items-center justify-between rounded-lg border-2 border-default hover:bg-content2 data-[selected=true]:border-focus',\n description: 'text-foreground opacity-70',\n icon: '',\n label:\n 'font-medium text-foreground group-data-[required=true]:after:ml-0.5 group-data-[required=true]:after:text-danger group-data-[required=true]:after:content-[\"*\"]',\n wrapper: '',\n thumb: '',\n thumbIcon: '',\n },\n variants: {\n isDisabled: {\n true: {\n box: 'pointer-events-none opacity-disabled',\n },\n },\n isInvalid: {\n true: {\n box: '!border-danger',\n label: '!text-danger',\n },\n },\n size: {\n sm: {\n box: 'gap-2 p-3',\n description: 'text-xs',\n label: 'text-xs',\n },\n md: {\n box: 'gap-4 p-4',\n description: 'text-small',\n label: 'text-sm',\n },\n lg: {\n box: 'gap-4 p-5',\n description: 'text-small',\n label: 'text-base',\n },\n },\n },\n defaultVariants: {\n size: 'md',\n },\n});\n\ntype ClassName = TVClassName<typeof switchBoxVariants>;\n\nexport interface SwitchBoxProps {\n /** CSS class name */\n className?: ClassName;\n /** Description text displayed below the label */\n description?: ReactNode;\n /** whether the switch should be disabled */\n disabled?: boolean;\n /** Icon to be displayed in the box */\n icon?: ReactNode;\n /** component displayed as the label */\n label?: ReactNode;\n /** name the field is registered under */\n name: string;\n /** whether the field is required */\n required?: boolean;\n /* Size of the switch */\n size?: 'sm' | 'md' | 'lg';\n /** HTML data-testid attribute used in e2e tests */\n testId?: string;\n /** Icon to be displayed inside the thumb */\n thumbIcon?: HeroSwitchProps['thumbIcon'];\n}\n\n/**\n * SwitchBox component - A card-like box with a switch control\n */\nconst SwitchBox = ({\n className = undefined,\n description = undefined,\n icon = undefined,\n name,\n size = undefined,\n thumbIcon = undefined,\n ...uniformFieldProps\n}: SwitchBoxProps) => {\n const {\n defaultValue,\n disabled,\n errorMessage,\n field,\n getErrorMessageProps,\n getHelperWrapperProps,\n invalid,\n label,\n onBlur,\n onChange,\n ref,\n required,\n testId,\n } = useUniformField({\n name,\n ...uniformFieldProps,\n });\n\n // Ref for the visual switch to forward focus\n const visualSwitchRef = useRef<HTMLInputElement>(null);\n\n // Use the useSwitch hook to get access to all the necessary props\n const {\n Component,\n slots,\n isSelected,\n getBaseProps,\n getInputProps,\n getWrapperProps,\n } = useSwitch({\n defaultSelected: !!defaultValue,\n isDisabled: disabled,\n isSelected: !!field.value,\n name: `${name}_switch`,\n onValueChange: onChange,\n size,\n thumbIcon,\n });\n\n // classNames from slots\n const variants = switchBoxVariants({\n isDisabled: disabled,\n isInvalid: invalid,\n size,\n });\n const classNames = variantsToClassNames(variants, className, 'box');\n\n return (\n <>\n <Component\n {...getBaseProps()}\n className={classNames.box}\n data-invalid={invalid}\n data-required={required}\n data-testid={testId}\n >\n <VisuallyHidden>\n <input\n ref={ref}\n aria-label={typeof label === 'string' ? label : name}\n checked={!!field.value}\n name={name}\n onChange={(e) => {\n onChange(e.target.checked);\n }}\n onFocus={() => {\n // When RHF focuses this hidden input (e.g., on validation error),\n // forward focus to the visual switch to show focus ring\n visualSwitchRef.current?.focus();\n }}\n tabIndex={-1}\n type=\"checkbox\"\n />\n {/* Visual switch input for focus ring */}\n <input\n ref={visualSwitchRef}\n {...getInputProps()}\n onBlur={(e) => {\n // Call HeroUI's internal onBlur to clear focus state and remove focus ring\n getInputProps().onBlur?.(e);\n // Then call RHF's onBlur to mark field as touched\n onBlur();\n }}\n />\n </VisuallyHidden>\n {!icon ? (\n <span\n {...getWrapperProps()}\n className={cn(getWrapperProps().className, classNames.wrapper)}\n >\n <span className={cn(slots.thumb({ class: classNames.thumb }))}>\n {thumbIcon && typeof thumbIcon === 'function'\n ? thumbIcon({\n isSelected: !!isSelected,\n className: slots.thumbIcon({ class: classNames.thumbIcon }),\n width: '1em',\n height: '1em',\n 'data-checked': isSelected ? 'true' : 'false',\n })\n : thumbIcon}\n </span>\n </span>\n ) : null}\n {icon ? <div className={classNames.icon}>{icon}</div> : null}\n <div className=\"grow\">\n {label ? <div className={classNames.label}>{label}</div> : null}\n {description ? (\n <div className={classNames.description}>{description}</div>\n ) : null}\n </div>\n {icon ? (\n <span\n {...getWrapperProps()}\n className={cn(getWrapperProps().className, classNames.wrapper)}\n >\n <span className={cn(slots.thumb({ class: classNames.thumb }))}>\n {thumbIcon && typeof thumbIcon === 'function'\n ? thumbIcon({\n isSelected: !!isSelected,\n className: slots.thumbIcon({ class: classNames.thumbIcon }),\n width: '1em',\n height: '1em',\n 'data-checked': isSelected ? 'true' : 'false',\n })\n : thumbIcon}\n </span>\n </span>\n ) : null}\n </Component>\n {invalid ? (\n <div\n {...getHelperWrapperProps()}\n className={cn(\n getHelperWrapperProps()?.className,\n // force helper to be visible (for some reason it's hidden by default) and remove margin\n 'ml-0 block',\n )}\n >\n <div {...getErrorMessageProps()}>{errorMessage}</div>\n </div>\n ) : null}\n </>\n );\n};\n\nexport default SwitchBox;\n","import SwitchBox from './SwitchBox';\n\nexport type { SwitchBoxProps } from './SwitchBox';\n\nexport { switchBoxVariants } from './SwitchBox';\n\nexport default SwitchBox;\n"],"mappings":";;;;;;;AAaA,MAAa,oBAAoB,GAAG;CAClC,OAAO;EACL,KAAK;EACL,aAAa;EACb,MAAM;EACN,OACE;EACF,SAAS;EACT,OAAO;EACP,WAAW;CACb;CACA,UAAU;EACR,YAAY,EACV,MAAM,EACJ,KAAK,uCACP,EACF;EACA,WAAW,EACT,MAAM;GACJ,KAAK;GACL,OAAO;EACT,EACF;EACA,MAAM;GACJ,IAAI;IACF,KAAK;IACL,aAAa;IACb,OAAO;GACT;GACA,IAAI;IACF,KAAK;IACL,aAAa;IACb,OAAO;GACT;GACA,IAAI;IACF,KAAK;IACL,aAAa;IACb,OAAO;GACT;EACF;CACF;CACA,iBAAiB,EACf,MAAM,KACR;AACF,CAAC;;;;AA8BD,MAAM,aAAa,EACjB,YAAY,KAAA,GACZ,cAAc,KAAA,GACd,OAAO,KAAA,GACP,MACA,OAAO,KAAA,GACP,YAAY,KAAA,GACZ,GAAG,wBACiB;CACpB,MAAM,EACJ,cACA,UACA,cACA,OACA,sBACA,uBACA,SACA,OACA,QACA,UACA,KACA,UACA,WACE,gBAAgB;EAClB;EACA,GAAG;CACL,CAAC;CAGD,MAAM,kBAAkB,OAAyB,IAAI;CAGrD,MAAM,EACJ,WACA,OACA,YACA,cACA,eACA,oBACE,UAAU;EACZ,iBAAiB,CAAC,CAAC;EACnB,YAAY;EACZ,YAAY,CAAC,CAAC,MAAM;EACpB,MAAM,GAAG,KAAK;EACd,eAAe;EACf;EACA;CACF,CAAC;CAGD,MAAM,WAAW,kBAAkB;EACjC,YAAY;EACZ,WAAW;EACX;CACF,CAAC;CACD,MAAM,aAAa,qBAAqB,UAAU,WAAW,KAAK;CAElE,OACE,qBAAA,UAAA,EAAA,UAAA,CACE,qBAAC,WAAD;EACE,GAAI,aAAa;EACjB,WAAW,WAAW;EACtB,gBAAc;EACd,iBAAe;EAC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M,WAAW,GAAG,MAAM,MAAM,EAAE,OAAO,WAAW,MAAM,CAAC,CAAC;KACzD,UAAA,aAAa,OAAO,cAAc,aAC/B,UAAU;MACR,YAAY,CAAC,CAAC;MACd,WAAW,MAAM,UAAU,EAAE,OAAO,WAAW,UAAU,CAAC;MAC1D,OAAO;MACP,QAAQ;MACR,gBAAgB,aAAa,SAAS;KACxC,CAAC,IACD;IACA,CAAA;GACF,CAAA,IACJ;EACK;CACV,CAAA,GAAA,UACC,oBAAC,OAAD;EACE,GAAI,sBAAsB;EAC1B,WAAW,GACT,sBAAsB,CAAC,EAAE,WAEzB,YACF;EAEA,UAAA,oBAAC,OAAD;GAAK,GAAI,qBAAqB;GAAI,UAAA;EAAkB,CAAA;CACjD,CAAA,IACH,IACJ,EAAA,CAAA;AAEN;;AC1OA,IAAA,oBAAe"}
|
|
1
|
+
{"version":3,"file":"index.mjs","names":[],"sources":["../../src/SwitchBox/SwitchBox.tsx","../../src/SwitchBox/index.ts"],"sourcesContent":["import type { TVClassName } from '@fuf-stack/pixel-utils';\nimport type { SwitchProps as HeroSwitchProps } from '@heroui/switch';\nimport type { ReactNode } from 'react';\n\nimport { useRef } from 'react';\n\nimport { useSwitch } from '@heroui/switch';\nimport { VisuallyHidden } from '@react-aria/visually-hidden';\n\nimport { cn, tv, variantsToClassNames } from '@fuf-stack/pixel-utils';\n\nimport { useUniformField } from '../hooks/useUniformField';\n\nexport const switchBoxVariants = tv({\n slots: {\n box: 'group inline-flex w-full cursor-pointer items-center justify-between rounded-lg border-2 border-default hover:bg-content2 data-[selected=true]:border-focus',\n description: 'text-foreground opacity-70',\n icon: '',\n label:\n 'font-medium text-foreground group-data-[required=true]:after:ml-0.5 group-data-[required=true]:after:text-danger group-data-[required=true]:after:content-[\"*\"]',\n wrapper: '',\n thumb: '',\n thumbIcon: '',\n },\n variants: {\n disabled: {\n true: {\n box: 'pointer-events-none opacity-disabled',\n },\n },\n invalid: {\n true: {\n box: '!border-danger',\n label: '!text-danger',\n },\n },\n readOnly: {\n true: {\n // Inner controls set their own cursors, so override every descendant.\n box: '**:cursor-not-allowed cursor-not-allowed opacity-disabled hover:bg-transparent',\n },\n },\n size: {\n sm: {\n box: 'gap-2 p-3',\n description: 'text-xs',\n label: 'text-xs',\n },\n md: {\n box: 'gap-4 p-4',\n description: 'text-small',\n label: 'text-sm',\n },\n lg: {\n box: 'gap-4 p-5',\n description: 'text-small',\n label: 'text-base',\n },\n },\n },\n defaultVariants: {\n size: 'md',\n },\n});\n\ntype ClassName = TVClassName<typeof switchBoxVariants>;\n\nexport interface SwitchBoxProps {\n /** CSS class name */\n className?: ClassName;\n /** Description text displayed below the label */\n description?: ReactNode;\n /** whether the switch should be disabled */\n disabled?: boolean;\n /** Icon to be displayed in the box */\n icon?: ReactNode;\n /** component displayed as the label */\n label?: ReactNode;\n /** name the field is registered under */\n name: string;\n /** Prevents changes while keeping the switch focusable and its value in validation and submission */\n readOnly?: boolean;\n /** whether the field is required */\n required?: boolean;\n /* Size of the switch */\n size?: 'sm' | 'md' | 'lg';\n /** HTML data-testid attribute used in e2e tests */\n testId?: string;\n /** Icon to be displayed inside the thumb */\n thumbIcon?: HeroSwitchProps['thumbIcon'];\n}\n\n/**\n * SwitchBox component - A card-like box with a switch control\n */\nconst SwitchBox = ({\n className = undefined,\n description = undefined,\n icon = undefined,\n name,\n size = undefined,\n thumbIcon = undefined,\n ...uniformFieldProps\n}: SwitchBoxProps) => {\n const {\n defaultValue,\n disabled,\n errorMessage,\n field,\n getErrorMessageProps,\n getHelperWrapperProps,\n invalid,\n label,\n onBlur,\n onChange,\n readOnly,\n ref,\n required,\n testId,\n } = useUniformField({\n name,\n ...uniformFieldProps,\n });\n\n // Ref for the visual switch to forward focus\n const visualSwitchRef = useRef<HTMLInputElement>(null);\n\n // Use the useSwitch hook to get access to all the necessary props\n const {\n Component,\n slots,\n isSelected,\n getBaseProps,\n getInputProps,\n getWrapperProps,\n } = useSwitch({\n defaultSelected: !!defaultValue,\n isDisabled: disabled,\n isReadOnly: readOnly,\n isSelected: !!field.value,\n name: `${name}_switch`,\n onValueChange: onChange,\n size,\n thumbIcon,\n });\n\n // classNames from slots\n const variants = switchBoxVariants({\n disabled,\n invalid,\n readOnly,\n size,\n });\n const classNames = variantsToClassNames(variants, className, 'box');\n\n return (\n <>\n <Component\n {...getBaseProps()}\n className={classNames.box}\n data-invalid={invalid}\n data-required={required}\n data-testid={testId}\n >\n <VisuallyHidden>\n <input\n ref={ref}\n aria-label={typeof label === 'string' ? label : name}\n checked={!!field.value}\n name={name}\n onChange={(e) => {\n if (!readOnly) {\n onChange(e.target.checked);\n }\n }}\n onFocus={() => {\n // When RHF focuses this hidden input (e.g., on validation error),\n // forward focus to the visual switch to show focus ring\n visualSwitchRef.current?.focus();\n }}\n tabIndex={-1}\n type=\"checkbox\"\n />\n {/* Visual switch input for focus ring */}\n <input\n ref={visualSwitchRef}\n {...getInputProps()}\n onBlur={(e) => {\n // Call HeroUI's internal onBlur to clear focus state and remove focus ring\n getInputProps().onBlur?.(e);\n // Then call RHF's onBlur to mark field as touched\n onBlur();\n }}\n />\n </VisuallyHidden>\n {!icon ? (\n <span\n {...getWrapperProps()}\n className={cn(getWrapperProps().className, classNames.wrapper)}\n >\n <span className={cn(slots.thumb({ class: classNames.thumb }))}>\n {thumbIcon && typeof thumbIcon === 'function'\n ? thumbIcon({\n isSelected: !!isSelected,\n className: slots.thumbIcon({ class: classNames.thumbIcon }),\n width: '1em',\n height: '1em',\n 'data-checked': isSelected ? 'true' : 'false',\n })\n : thumbIcon}\n </span>\n </span>\n ) : null}\n {icon ? <div className={classNames.icon}>{icon}</div> : null}\n <div className=\"grow\">\n {label ? <div className={classNames.label}>{label}</div> : null}\n {description ? (\n <div className={classNames.description}>{description}</div>\n ) : null}\n </div>\n {icon ? (\n <span\n {...getWrapperProps()}\n className={cn(getWrapperProps().className, classNames.wrapper)}\n >\n <span className={cn(slots.thumb({ class: classNames.thumb }))}>\n {thumbIcon && typeof thumbIcon === 'function'\n ? thumbIcon({\n isSelected: !!isSelected,\n className: slots.thumbIcon({ class: classNames.thumbIcon }),\n width: '1em',\n height: '1em',\n 'data-checked': isSelected ? 'true' : 'false',\n })\n : thumbIcon}\n </span>\n </span>\n ) : null}\n </Component>\n {invalid ? (\n <div\n {...getHelperWrapperProps()}\n className={cn(\n getHelperWrapperProps()?.className,\n // force helper to be visible (for some reason it's hidden by default) and remove margin\n 'ml-0 block',\n )}\n >\n <div {...getErrorMessageProps()}>{errorMessage}</div>\n </div>\n ) : null}\n </>\n );\n};\n\nexport default SwitchBox;\n","import SwitchBox from './SwitchBox';\n\nexport type { SwitchBoxProps } from './SwitchBox';\n\nexport { switchBoxVariants } from './SwitchBox';\n\nexport default SwitchBox;\n"],"mappings":";;;;;;;AAaA,MAAa,oBAAoB,GAAG;CAClC,OAAO;EACL,KAAK;EACL,aAAa;EACb,MAAM;EACN,OACE;EACF,SAAS;EACT,OAAO;EACP,WAAW;CACb;CACA,UAAU;EACR,UAAU,EACR,MAAM,EACJ,KAAK,uCACP,EACF;EACA,SAAS,EACP,MAAM;GACJ,KAAK;GACL,OAAO;EACT,EACF;EACA,UAAU,EACR,MAAM,EAEJ,KAAK,iFACP,EACF;EACA,MAAM;GACJ,IAAI;IACF,KAAK;IACL,aAAa;IACb,OAAO;GACT;GACA,IAAI;IACF,KAAK;IACL,aAAa;IACb,OAAO;GACT;GACA,IAAI;IACF,KAAK;IACL,aAAa;IACb,OAAO;GACT;EACF;CACF;CACA,iBAAiB,EACf,MAAM,KACR;AACF,CAAC;;;;AAgCD,MAAM,aAAa,EACjB,YAAY,KAAA,GACZ,cAAc,KAAA,GACd,OAAO,KAAA,GACP,MACA,OAAO,KAAA,GACP,YAAY,KAAA,GACZ,GAAG,wBACiB;CACpB,MAAM,EACJ,cACA,UACA,cACA,OACA,sBACA,uBACA,SACA,OACA,QACA,UACA,UACA,KACA,UACA,WACE,gBAAgB;EAClB;EACA,GAAG;CACL,CAAC;CAGD,MAAM,kBAAk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