@fuf-stack/uniform 2.0.0-next.3 → 2.0.0-next.4
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/Checkboxes/index.d.mts +58 -58
- package/dist/Checkboxes/index.d.mts.map +1 -1
- package/dist/Checkboxes/index.mjs +10 -8
- package/dist/Checkboxes/index.mjs.map +1 -1
- package/dist/DatePicker/index.d.mts +46 -109
- package/dist/DatePicker/index.d.mts.map +1 -1
- package/dist/DatePicker/index.mjs +15 -23
- package/dist/DatePicker/index.mjs.map +1 -1
- package/dist/FieldArray/index.mjs +9 -7
- package/dist/FieldArray/index.mjs.map +1 -1
- package/dist/FieldCard/index.mjs +5 -8
- package/dist/FieldCard/index.mjs.map +1 -1
- package/dist/FieldHelper-B1DWl7eu.mjs +38 -0
- package/dist/FieldHelper-B1DWl7eu.mjs.map +1 -0
- package/dist/FieldLabel-DMTqq0Jj.mjs +29 -0
- package/dist/FieldLabel-DMTqq0Jj.mjs.map +1 -0
- package/dist/{FieldLayout-DcvQU0zN.mjs → FieldLayout-C9MEBZAC.mjs} +10 -17
- package/dist/FieldLayout-C9MEBZAC.mjs.map +1 -0
- package/dist/{FieldValidationError-iAayfTEw.mjs → FieldValidationError-BuLvuRyi.mjs} +3 -3
- package/dist/FieldValidationError-BuLvuRyi.mjs.map +1 -0
- package/dist/Input/index.d.mts +596 -431
- package/dist/Input/index.d.mts.map +1 -1
- package/dist/Input/index.mjs +7 -10
- package/dist/Input/index.mjs.map +1 -1
- package/dist/RadioBoxes/index.d.mts +79 -63
- package/dist/RadioBoxes/index.d.mts.map +1 -1
- package/dist/RadioBoxes/index.mjs +5 -13
- package/dist/RadioBoxes/index.mjs.map +1 -1
- package/dist/RadioTabs/index.d.mts +572 -317
- package/dist/RadioTabs/index.d.mts.map +1 -1
- package/dist/RadioTabs/index.mjs +11 -11
- package/dist/RadioTabs/index.mjs.map +1 -1
- package/dist/Radios/index.d.mts +44 -41
- package/dist/Radios/index.d.mts.map +1 -1
- package/dist/Radios/index.mjs +5 -13
- package/dist/Radios/index.mjs.map +1 -1
- package/dist/Select/index.d.mts +791 -599
- package/dist/Select/index.d.mts.map +1 -1
- package/dist/Select/index.mjs +7 -8
- package/dist/Select/index.mjs.map +1 -1
- package/dist/Slider/index.d.mts +664 -354
- package/dist/Slider/index.d.mts.map +1 -1
- package/dist/Slider/index.mjs +18 -26
- package/dist/Slider/index.mjs.map +1 -1
- package/dist/Switch/index.d.mts +1 -1
- package/dist/Switch/index.mjs +12 -17
- package/dist/Switch/index.mjs.map +1 -1
- package/dist/Switch-aBYStBoY.d.mts +990 -0
- package/dist/{Switch-Db2dpGz7.d.mts.map → Switch-aBYStBoY.d.mts.map} +1 -1
- package/dist/SwitchBox/index.d.mts +593 -231
- package/dist/SwitchBox/index.d.mts.map +1 -1
- package/dist/SwitchBox/index.mjs +14 -18
- package/dist/SwitchBox/index.mjs.map +1 -1
- package/dist/TextArea/index.d.mts +553 -216
- package/dist/TextArea/index.d.mts.map +1 -1
- package/dist/TextArea/index.mjs +7 -10
- package/dist/TextArea/index.mjs.map +1 -1
- package/dist/Time/index.d.mts +45 -45
- package/dist/Time/index.d.mts.map +1 -1
- package/dist/Time/index.mjs +17 -22
- package/dist/Time/index.mjs.map +1 -1
- package/dist/fieldHelperVariants-ClP8taiS.mjs +20 -0
- package/dist/fieldHelperVariants-ClP8taiS.mjs.map +1 -0
- package/dist/fieldLabelVariants-C4ZqECec.mjs +13 -0
- package/dist/fieldLabelVariants-C4ZqECec.mjs.map +1 -0
- package/dist/{FieldDescription-X_0s1Lhu.mjs → fieldProps-DWfz2jSO.mjs} +2 -13
- package/dist/fieldProps-DWfz2jSO.mjs.map +1 -0
- package/dist/{Switch-Db2dpGz7.d.mts → partials/FieldHelper/index.d.mts} +309 -408
- package/dist/partials/FieldHelper/index.d.mts.map +1 -0
- package/dist/partials/FieldHelper/index.mjs +7 -0
- package/dist/partials/FieldHelper/index.mjs.map +1 -0
- package/dist/partials/FieldLabel/index.d.mts +160 -0
- package/dist/partials/FieldLabel/index.d.mts.map +1 -0
- package/dist/partials/FieldLabel/index.mjs +7 -0
- package/dist/partials/FieldLabel/index.mjs.map +1 -0
- package/dist/partials/FieldValidationError/index.d.mts +2 -2
- package/dist/partials/FieldValidationError/index.mjs +1 -1
- package/dist/{radioControlVariants-BYRfaD6y.mjs → radioControlVariants-CbtG5U4_.mjs} +10 -6
- package/dist/radioControlVariants-CbtG5U4_.mjs.map +1 -0
- package/dist/{switchVariants-D16b2VaT.mjs → switchVariants-0Xa7TQYg.mjs} +5 -8
- package/dist/switchVariants-0Xa7TQYg.mjs.map +1 -0
- package/dist/{timeVariants-CtXyNKmW.mjs → timeVariants-Bkt4iwXx.mjs} +12 -10
- package/dist/timeVariants-Bkt4iwXx.mjs.map +1 -0
- package/dist/{FieldLabel-DrNWJIVh.mjs → useUniformField-TTNPTsVn.mjs} +3 -28
- package/dist/useUniformField-TTNPTsVn.mjs.map +1 -0
- package/package.json +4 -2
- package/dist/FieldDescription-X_0s1Lhu.mjs.map +0 -1
- package/dist/FieldLabel-DrNWJIVh.mjs.map +0 -1
- package/dist/FieldLayout-DcvQU0zN.mjs.map +0 -1
- package/dist/FieldValidationError-iAayfTEw.mjs.map +0 -1
- package/dist/radioControlVariants-BYRfaD6y.mjs.map +0 -1
- package/dist/switchVariants-D16b2VaT.mjs.map +0 -1
- package/dist/timeVariants-CtXyNKmW.mjs.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.mts","names":[],"sources":["../../src/SwitchBox/switchBoxVariants.ts","../../src/SwitchBox/SwitchBox.tsx"],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"index.d.mts","names":[],"sources":["../../src/SwitchBox/switchBoxVariants.ts","../../src/SwitchBox/SwitchBox.tsx"],"mappings":";;;qBAMa,qBAAiB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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,cAAA,qBAQhB,mCAAc,IAAA"}
|
package/dist/SwitchBox/index.mjs
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import { t as
|
|
1
|
+
import { t as useUniformField } from "../useUniformField-TTNPTsVn.mjs";
|
|
2
|
+
import { t as getFieldControlProps } from "../fieldProps-DWfz2jSO.mjs";
|
|
3
|
+
import { n as FieldDescription, t as FieldHelper } from "../FieldHelper-B1DWl7eu.mjs";
|
|
4
|
+
import { t as FieldLabel } from "../FieldLabel-DMTqq0Jj.mjs";
|
|
5
|
+
import { t as switchVariants } from "../switchVariants-0Xa7TQYg.mjs";
|
|
6
|
+
import { t as fieldHelperVariants } from "../fieldHelperVariants-ClP8taiS.mjs";
|
|
4
7
|
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
5
8
|
import { tv } from "@fuf-stack/pixel-utils";
|
|
6
9
|
import { useStyling } from "@fuf-stack/pixels/StylingProvider";
|
|
@@ -13,15 +16,12 @@ import { VisuallyHidden } from "react-aria/VisuallyHidden";
|
|
|
13
16
|
import { useToggleState } from "react-stately/useToggleState";
|
|
14
17
|
// src/SwitchBox/switchBoxVariants.ts
|
|
15
18
|
const switchBoxVariants = tv({
|
|
19
|
+
extend: fieldHelperVariants,
|
|
16
20
|
slots: {
|
|
17
21
|
/** Selectable box containing the toggle and text */
|
|
18
22
|
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"],
|
|
19
23
|
/** Supporting text for the field */
|
|
20
|
-
description: "text-foreground opacity-70",
|
|
21
|
-
/** Container for validation messages */
|
|
22
|
-
errorMessage: "text-danger text-tiny",
|
|
23
|
-
/** Container below the switch for validation messages */
|
|
24
|
-
helperWrapper: "relative ml-0 block p-0",
|
|
24
|
+
description: "pt-0 text-foreground opacity-70",
|
|
25
25
|
/** Decorative icon beside the option text */
|
|
26
26
|
icon: "",
|
|
27
27
|
/** Visible field label */
|
|
@@ -175,16 +175,12 @@ const SwitchBoxControl = ({ field, className, size, thumbIcon, icon }) => {
|
|
|
175
175
|
thumbIcon
|
|
176
176
|
}) : null
|
|
177
177
|
]
|
|
178
|
-
}),
|
|
179
|
-
className: classNames
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
id: ids.error,
|
|
185
|
-
children: errorMessage
|
|
186
|
-
})
|
|
187
|
-
}) : null] });
|
|
178
|
+
}), /* @__PURE__ */ jsx(FieldHelper, {
|
|
179
|
+
className: classNames,
|
|
180
|
+
errorMessage,
|
|
181
|
+
ids,
|
|
182
|
+
invalid
|
|
183
|
+
})] });
|
|
188
184
|
};
|
|
189
185
|
// src/SwitchBox/SwitchBox.tsx
|
|
190
186
|
/** Form toggle field with a switch inside a selectable card */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","names":[],"sources":["../../src/SwitchBox/switchBoxVariants.ts","../../src/SwitchBox/subcomponents/SwitchBoxTrack.tsx","../../src/SwitchBox/subcomponents/SwitchBoxControl.tsx","../../src/SwitchBox/SwitchBox.tsx","../../src/SwitchBox/index.ts"],"sourcesContent":["import type { TVClassName } from '@fuf-stack/pixel-utils';\n\nimport { tv } from '@fuf-stack/pixel-utils';\n\nexport const switchBoxVariants = tv({\n slots: {\n /** Selectable box containing the toggle and text */\n box: [\n // box layout and surface\n 'group inline-flex w-full cursor-pointer items-center justify-between rounded-lg border-2 border-default',\n // hover and selection feedback\n 'hover:bg-content2 data-[selected=true]:border-focus',\n ],\n /** Supporting text for the field */\n description: 'text-foreground opacity-70',\n /** Container for validation messages */\n errorMessage: 'text-danger text-tiny',\n /** Container below the switch for validation messages */\n helperWrapper: 'relative ml-0 block p-0',\n /** Decorative icon beside the option text */\n icon: '',\n /** Visible field label */\n label: 'font-medium text-foreground',\n /** Movable indicator showing the current value */\n thumb: '',\n /** Content inside the toggle thumb */\n thumbIcon: '',\n /** Container arranging the selectable content */\n wrapper: '',\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, override every descendant\n box: 'cursor-not-allowed opacity-disabled **:cursor-not-allowed hover:bg-transparent',\n },\n },\n size: {\n lg: {\n box: 'gap-4 p-5',\n description: 'text-small',\n label: 'text-base',\n },\n md: {\n box: 'gap-4 p-4',\n description: 'text-small',\n label: 'text-sm',\n },\n sm: {\n box: 'gap-2 p-3',\n description: 'text-xs',\n label: 'text-xs',\n },\n },\n },\n defaultVariants: {\n size: 'md',\n },\n});\n\nexport type ClassName = TVClassName<typeof switchBoxVariants>;\n","import type { SwitchBoxProps } from '../SwitchBox';\n\ninterface SwitchBoxTrackProps extends Pick<SwitchBoxProps, 'thumbIcon'> {\n /** CSS class name */\n className: Record<'thumb' | 'thumbIcon' | 'wrapper', string>;\n /** Current toggle state supplied to the icon callback */\n selected: boolean;\n}\n\n/** Visual toggle track and thumb, including the selection-aware icon callback */\nconst SwitchBoxTrack = ({\n className: trackClassNames,\n selected,\n thumbIcon,\n}: SwitchBoxTrackProps) => {\n return (\n <span aria-hidden className={trackClassNames.wrapper} data-slot=\"wrapper\">\n <span className={trackClassNames.thumb} data-slot=\"thumb\">\n {typeof thumbIcon === 'function'\n ? thumbIcon({\n isSelected: selected,\n className: trackClassNames.thumbIcon,\n width: '1em',\n height: '1em',\n 'data-checked': String(selected),\n })\n : thumbIcon}\n </span>\n </span>\n );\n};\n\nexport default SwitchBoxTrack;\n","import type { UniformField } from '../../hooks/useUniformField/types';\nimport type { SwitchBoxProps } from '../SwitchBox';\n\nimport { mergeProps } from 'react-aria/mergeProps';\nimport { useFocusRing } from 'react-aria/useFocusRing';\nimport { useHover } from 'react-aria/useHover';\nimport { useObjectRef } from 'react-aria/useObjectRef';\nimport { useSwitch } from 'react-aria/useSwitch';\nimport { VisuallyHidden } from 'react-aria/VisuallyHidden';\nimport { useToggleState } from 'react-stately/useToggleState';\n\nimport { useStyling } from '@fuf-stack/pixels/StylingProvider';\n\nimport { getFieldControlProps } from '../../helpers/fieldProps/fieldProps';\nimport FieldDescription from '../../partials/FieldDescription/FieldDescription';\nimport FieldLabel from '../../partials/FieldLabel/FieldLabel';\nimport { switchVariants } from '../../Switch/switchVariants';\nimport { switchBoxVariants } from '../switchBoxVariants';\nimport SwitchBoxTrack from './SwitchBoxTrack';\n\ninterface SwitchBoxControlProps extends Pick<\n SwitchBoxProps,\n 'className' | 'icon' | 'size' | 'thumbIcon'\n> {\n /** Bound field values, interactions and metadata */\n field: UniformField<unknown, boolean>;\n}\n\n/**\n * Selectable switch box with label, description and validation messages\n *\n * @see https://react-aria.adobe.com/useSwitch\n */\nconst SwitchBoxControl = ({\n field,\n className,\n size,\n thumbIcon,\n icon,\n}: SwitchBoxControlProps) => {\n const {\n description,\n disabled,\n errorMessage,\n ids,\n ref: inputRef,\n invalid,\n label,\n name,\n onBlur,\n onChange: onValueChange,\n readOnly,\n required,\n testId,\n value,\n } = field;\n\n // associate the editable control with its label and messages\n const controlProps = getFieldControlProps(field);\n\n const styling = useStyling();\n const controlRef = useObjectRef<HTMLInputElement>(inputRef);\n const state = useToggleState({\n isReadOnly: readOnly,\n isSelected: !!value,\n onChange: onValueChange,\n });\n const { inputProps, labelProps, isPressed } = useSwitch(\n {\n ...controlProps,\n children: label,\n isDisabled: disabled,\n isInvalid: invalid,\n isReadOnly: readOnly,\n isRequired: required,\n name,\n onBlur,\n validationBehavior: 'aria',\n },\n state,\n controlRef,\n );\n const { focusProps, isFocused, isFocusVisible } = useFocusRing();\n const { hoverProps, isHovered } = useHover({ isDisabled: disabled });\n\n // classNames from slots\n const variants = styling.resolve(switchBoxVariants, {\n disabled,\n invalid,\n readOnly,\n size,\n });\n const classNames = styling.variantsToClassNames(variants, className, 'box');\n\n const trackVariants = styling.resolve(switchVariants, { size });\n const trackClassNames = styling.variantsToClassNames(trackVariants, {\n wrapper: classNames.wrapper,\n thumb: classNames.thumb,\n thumbIcon: classNames.thumbIcon,\n });\n\n return (\n <>\n <label\n {...mergeProps(labelProps, hoverProps)}\n className={classNames.box}\n data-component=\"switch-box\"\n data-focus={isFocused || undefined}\n data-focus-visible={isFocusVisible || undefined}\n data-hover={isHovered || undefined}\n data-invalid={invalid}\n data-pressed={isPressed || undefined}\n data-readonly={readOnly || undefined}\n data-required={required}\n data-selected={state.isSelected || undefined}\n data-testid={testId}\n htmlFor={ids.control}\n >\n {/* native toggle for keyboard and assistive technology */}\n <VisuallyHidden elementType=\"span\">\n <input\n {...mergeProps(inputProps, focusProps, controlProps)}\n ref={controlRef}\n data-slot=\"input\"\n />\n </VisuallyHidden>\n {!icon ? (\n <SwitchBoxTrack\n className={trackClassNames}\n selected={state.isSelected}\n thumbIcon={thumbIcon}\n />\n ) : null}\n {icon ? <div className={classNames.icon}>{icon}</div> : null}\n\n {/* label and supporting text */}\n <div className=\"grow\">\n {label ? (\n <FieldLabel\n as=\"div\"\n className={classNames.label}\n id={ids.label}\n required={required}\n >\n {label}\n </FieldLabel>\n ) : null}\n {description ? (\n <FieldDescription\n className={classNames.description}\n data-slot={undefined}\n id={ids.description}\n >\n {description}\n </FieldDescription>\n ) : null}\n </div>\n {icon ? (\n <SwitchBoxTrack\n className={trackClassNames}\n selected={state.isSelected}\n thumbIcon={thumbIcon}\n />\n ) : null}\n </label>\n\n {/* validation messages below the box */}\n {invalid ? (\n <div className={classNames.helperWrapper} data-slot=\"helper-wrapper\">\n <div\n className={classNames.errorMessage}\n data-slot=\"error-message\"\n id={ids.error}\n >\n {errorMessage}\n </div>\n </div>\n ) : null}\n </>\n );\n};\n\nexport default SwitchBoxControl;\n","import type { ReactNode } from 'react';\nimport type { SwitchProps } from '../Switch/Switch';\nimport type { ClassName } from './switchBoxVariants';\n\nimport useUniformField from '../hooks/useUniformField/useUniformField';\nimport SwitchBoxControl from './subcomponents/SwitchBoxControl';\n\nexport { switchBoxVariants } from './switchBoxVariants';\n\nexport interface SwitchBoxProps {\n /** CSS class name */\n className?: ClassName;\n /** Help text associated with the field */\n description?: ReactNode;\n /** Disables the field */\n disabled?: boolean;\n /** Icon to be displayed in the box */\n icon?: ReactNode;\n /** Field label */\n label?: ReactNode;\n /** Field name */\n name: string;\n /** Prevents toggling while keeping the 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 for e2e tests */\n testId?: string;\n /** Content or render callback inside the toggle thumb */\n thumbIcon?: SwitchProps['thumbIcon'];\n}\n\n/** Form toggle field with a switch inside a selectable card */\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 { field } = useUniformField({\n ...uniformFieldProps,\n description,\n name,\n });\n\n return (\n <SwitchBoxControl\n className={className}\n field={field}\n icon={icon}\n size={size}\n thumbIcon={thumbIcon}\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":";;;;;;;;;;;;;;AAIA,MAAa,oBAAoB,GAAG;CAClC,OAAO;;EAEL,KAAK,CAEH,2GAEA,qDACF;;EAEA,aAAa;;EAEb,cAAc;;EAEd,eAAe;;EAEf,MAAM;;EAEN,OAAO;;EAEP,OAAO;;EAEP,WAAW;;EAEX,SAAS;CACX;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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AA;CACF,CAAA,IACH,IACJ,EAAA,CAAA;AAEN;;;ACjJA,MAAM,aAAa,EACjB,YAAY,KAAA,GACZ,cAAc,KAAA,GACd,OAAO,KAAA,GACP,MACA,OAAO,KAAA,GACP,YAAY,KAAA,GACZ,GAAG,wBACiB;CACpB,MAAM,EAAE,UAAU,gBAAgB;EAChC,GAAG;EACH;EACA;CACF,CAAC;CAED,OACE,oBAAC,kBAAD;EACa;EACJ;EACD;EACA;EACK;CACZ,CAAA;AAEL;;ACrDA,IAAA,oBAAe"}
|
|
1
|
+
{"version":3,"file":"index.mjs","names":[],"sources":["../../src/SwitchBox/switchBoxVariants.ts","../../src/SwitchBox/subcomponents/SwitchBoxTrack.tsx","../../src/SwitchBox/subcomponents/SwitchBoxControl.tsx","../../src/SwitchBox/SwitchBox.tsx","../../src/SwitchBox/index.ts"],"sourcesContent":["import type { TVClassName } from '@fuf-stack/pixel-utils';\n\nimport { tv } from '@fuf-stack/pixel-utils';\n\nimport { fieldHelperVariants } from '../partials/FieldHelper/fieldHelperVariants';\n\nexport const switchBoxVariants = tv({\n extend: fieldHelperVariants,\n slots: {\n /** Selectable box containing the toggle and text */\n box: [\n // box layout and surface\n 'group inline-flex w-full cursor-pointer items-center justify-between rounded-lg border-2 border-default',\n // hover and selection feedback\n 'hover:bg-content2 data-[selected=true]:border-focus',\n ],\n /** Supporting text for the field */\n // inside the box, without the spacing below a control\n description: 'pt-0 text-foreground opacity-70',\n /** Decorative icon beside the option text */\n icon: '',\n /** Visible field label */\n label: 'font-medium text-foreground',\n /** Movable indicator showing the current value */\n thumb: '',\n /** Content inside the toggle thumb */\n thumbIcon: '',\n /** Container arranging the selectable content */\n wrapper: '',\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, override every descendant\n box: 'cursor-not-allowed opacity-disabled **:cursor-not-allowed hover:bg-transparent',\n },\n },\n size: {\n lg: {\n box: 'gap-4 p-5',\n description: 'text-small',\n label: 'text-base',\n },\n md: {\n box: 'gap-4 p-4',\n description: 'text-small',\n label: 'text-sm',\n },\n sm: {\n box: 'gap-2 p-3',\n description: 'text-xs',\n label: 'text-xs',\n },\n },\n },\n defaultVariants: {\n size: 'md',\n },\n});\n\nexport type ClassName = TVClassName<typeof switchBoxVariants>;\n","import type { SwitchBoxProps } from '../SwitchBox';\n\ninterface SwitchBoxTrackProps extends Pick<SwitchBoxProps, 'thumbIcon'> {\n /** CSS class name */\n className: Record<'thumb' | 'thumbIcon' | 'wrapper', string>;\n /** Current toggle state supplied to the icon callback */\n selected: boolean;\n}\n\n/** Visual toggle track and thumb, including the selection-aware icon callback */\nconst SwitchBoxTrack = ({\n className: trackClassNames,\n selected,\n thumbIcon,\n}: SwitchBoxTrackProps) => {\n return (\n <span aria-hidden className={trackClassNames.wrapper} data-slot=\"wrapper\">\n <span className={trackClassNames.thumb} data-slot=\"thumb\">\n {typeof thumbIcon === 'function'\n ? thumbIcon({\n isSelected: selected,\n className: trackClassNames.thumbIcon,\n width: '1em',\n height: '1em',\n 'data-checked': String(selected),\n })\n : thumbIcon}\n </span>\n </span>\n );\n};\n\nexport default SwitchBoxTrack;\n","import type { UniformField } from '../../hooks/useUniformField/types';\nimport type { SwitchBoxProps } from '../SwitchBox';\n\nimport { mergeProps } from 'react-aria/mergeProps';\nimport { useFocusRing } from 'react-aria/useFocusRing';\nimport { useHover } from 'react-aria/useHover';\nimport { useObjectRef } from 'react-aria/useObjectRef';\nimport { useSwitch } from 'react-aria/useSwitch';\nimport { VisuallyHidden } from 'react-aria/VisuallyHidden';\nimport { useToggleState } from 'react-stately/useToggleState';\n\nimport { useStyling } from '@fuf-stack/pixels/StylingProvider';\n\nimport { getFieldControlProps } from '../../helpers/fieldProps/fieldProps';\nimport FieldDescription from '../../partials/FieldDescription/FieldDescription';\nimport FieldHelper from '../../partials/FieldHelper/FieldHelper';\nimport FieldLabel from '../../partials/FieldLabel/FieldLabel';\nimport { switchVariants } from '../../Switch/switchVariants';\nimport { switchBoxVariants } from '../switchBoxVariants';\nimport SwitchBoxTrack from './SwitchBoxTrack';\n\ninterface SwitchBoxControlProps extends Pick<\n SwitchBoxProps,\n 'className' | 'icon' | 'size' | 'thumbIcon'\n> {\n /** Bound field values, interactions and metadata */\n field: UniformField<unknown, boolean>;\n}\n\n/**\n * Selectable switch box with label, description and validation messages\n *\n * @see https://react-aria.adobe.com/useSwitch\n */\nconst SwitchBoxControl = ({\n field,\n className,\n size,\n thumbIcon,\n icon,\n}: SwitchBoxControlProps) => {\n const {\n description,\n disabled,\n errorMessage,\n ids,\n ref: inputRef,\n invalid,\n label,\n name,\n onBlur,\n onChange: onValueChange,\n readOnly,\n required,\n testId,\n value,\n } = field;\n\n // associate the editable control with its label and messages\n const controlProps = getFieldControlProps(field);\n\n const styling = useStyling();\n const controlRef = useObjectRef<HTMLInputElement>(inputRef);\n const state = useToggleState({\n isReadOnly: readOnly,\n isSelected: !!value,\n onChange: onValueChange,\n });\n const { inputProps, labelProps, isPressed } = useSwitch(\n {\n ...controlProps,\n children: label,\n isDisabled: disabled,\n isInvalid: invalid,\n isReadOnly: readOnly,\n isRequired: required,\n name,\n onBlur,\n validationBehavior: 'aria',\n },\n state,\n controlRef,\n );\n const { focusProps, isFocused, isFocusVisible } = useFocusRing();\n const { hoverProps, isHovered } = useHover({ isDisabled: disabled });\n\n // classNames from slots\n const variants = styling.resolve(switchBoxVariants, {\n disabled,\n invalid,\n readOnly,\n size,\n });\n const classNames = styling.variantsToClassNames(variants, className, 'box');\n\n const trackVariants = styling.resolve(switchVariants, { size });\n const trackClassNames = styling.variantsToClassNames(trackVariants, {\n wrapper: classNames.wrapper,\n thumb: classNames.thumb,\n thumbIcon: classNames.thumbIcon,\n });\n\n return (\n <>\n <label\n {...mergeProps(labelProps, hoverProps)}\n className={classNames.box}\n data-component=\"switch-box\"\n data-focus={isFocused || undefined}\n data-focus-visible={isFocusVisible || undefined}\n data-hover={isHovered || undefined}\n data-invalid={invalid}\n data-pressed={isPressed || undefined}\n data-readonly={readOnly || undefined}\n data-required={required}\n data-selected={state.isSelected || undefined}\n data-testid={testId}\n htmlFor={ids.control}\n >\n {/* native toggle for keyboard and assistive technology */}\n <VisuallyHidden elementType=\"span\">\n <input\n {...mergeProps(inputProps, focusProps, controlProps)}\n ref={controlRef}\n data-slot=\"input\"\n />\n </VisuallyHidden>\n {!icon ? (\n <SwitchBoxTrack\n className={trackClassNames}\n selected={state.isSelected}\n thumbIcon={thumbIcon}\n />\n ) : null}\n {icon ? <div className={classNames.icon}>{icon}</div> : null}\n\n {/* label and supporting text */}\n <div className=\"grow\">\n {label ? (\n <FieldLabel\n as=\"div\"\n className={classNames.label}\n id={ids.label}\n required={required}\n >\n {label}\n </FieldLabel>\n ) : null}\n {description ? (\n <FieldDescription\n className={classNames.description}\n data-slot={undefined}\n id={ids.description}\n >\n {description}\n </FieldDescription>\n ) : null}\n </div>\n {icon ? (\n <SwitchBoxTrack\n className={trackClassNames}\n selected={state.isSelected}\n thumbIcon={thumbIcon}\n />\n ) : null}\n </label>\n\n {/* validation messages below the box, its description is inside */}\n <FieldHelper\n className={classNames}\n errorMessage={errorMessage}\n ids={ids}\n invalid={invalid}\n />\n </>\n );\n};\n\nexport default SwitchBoxControl;\n","import type { ReactNode } from 'react';\nimport type { SwitchProps } from '../Switch/Switch';\nimport type { ClassName } from './switchBoxVariants';\n\nimport useUniformField from '../hooks/useUniformField/useUniformField';\nimport SwitchBoxControl from './subcomponents/SwitchBoxControl';\n\nexport { switchBoxVariants } from './switchBoxVariants';\n\nexport interface SwitchBoxProps {\n /** CSS class name */\n className?: ClassName;\n /** Help text associated with the field */\n description?: ReactNode;\n /** Disables the field */\n disabled?: boolean;\n /** Icon to be displayed in the box */\n icon?: ReactNode;\n /** Field label */\n label?: ReactNode;\n /** Field name */\n name: string;\n /** Prevents toggling while keeping the 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 for e2e tests */\n testId?: string;\n /** Content or render callback inside the toggle thumb */\n thumbIcon?: SwitchProps['thumbIcon'];\n}\n\n/** Form toggle field with a switch inside a selectable card */\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 { field } = useUniformField({\n ...uniformFieldProps,\n description,\n name,\n });\n\n return (\n <SwitchBoxControl\n className={className}\n field={field}\n icon={icon}\n size={size}\n thumbIcon={thumbIcon}\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":";;;;;;;;;;;;;;;;;AAMA,MAAa,oBAAoB,GAAG;CAClC,QAAQ;CACR,OAAO;;EAEL,KAAK,CAEH,2GAEA,qDACF;;EAGA,aAAa;;EAEb,MAAM;;EAEN,OAAO;;EAEP,OAAO;;EAEP,WAAW;;EAEX,SAAS;CACX;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;;;AC3DD,MAAM,kBAAkB,EACtB,WAAW,iBACX,UACA,gBACyB;CACzB,OACE,oBAAC,QAAD;EAAM,eAAA;EAAY,WAAW,gBAAgB;EAAS,aAAU;EAC9D,U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