@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
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.mts","names":[],"sources":["../../src/Slider/Slider.tsx"],"mappings":";;;qBAaa,kBAAc
|
|
1
|
+
{"version":3,"file":"index.d.mts","names":[],"sources":["../../src/Slider/Slider.tsx"],"mappings":";;;qBAaa,kBAAc;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;KA0CtB,eAAe,eAAe;KAC9B,YAAY,mBAAmB;UAEnB,oBAAoB;;EAEnC;;EAEA,YAAY;;EAEZ;;EAEA,aAAa;;EAEb;;EAEA;;;;;EAKA;;;;;EAKA;;EAEA;;EAEA;;;;;EAKA;;;;;EAKA;;EAEA,eAAe;;;;;EAKf;;EAEA;;EAEA,YAAY;;;;;cAMR,WAAU,WAAA,YAAA,YAAA,UAAA,UAAA,MAAA,WAAA,MAAA,cAAA,SAAA,qBAYb,gCAAW,IAAA"}
|
package/dist/Slider/index.mjs
CHANGED
|
@@ -1,38 +1,41 @@
|
|
|
1
1
|
import { useUniformField } from "../hooks/useUniformField/index.mjs";
|
|
2
2
|
import { cn, tv, variantsToClassNames } from "@fuf-stack/pixel-utils";
|
|
3
|
-
import { useRef } from "react";
|
|
3
|
+
import { useEffect, useRef } from "react";
|
|
4
4
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
5
5
|
import { VisuallyHidden } from "@react-aria/visually-hidden";
|
|
6
6
|
import { Slider } from "@heroui/slider";
|
|
7
7
|
// src/Slider/Slider.tsx
|
|
8
|
-
const sliderVariants = tv({
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
8
|
+
const sliderVariants = tv({
|
|
9
|
+
slots: {
|
|
10
|
+
base: [
|
|
11
|
+
"group",
|
|
12
|
+
"flex w-full flex-col",
|
|
13
|
+
"gap-y-1.5"
|
|
14
|
+
],
|
|
15
|
+
endContent: "",
|
|
16
|
+
errorMessage: "ml-1 mt-1",
|
|
17
|
+
filler: "",
|
|
18
|
+
label: "cursor-default text-sm text-foreground subpixel-antialiased group-data-[invalid=true]:!text-danger group-data-[required=true]:after:ml-0.5 group-data-[required=true]:after:text-danger group-data-[required=true]:after:content-[\"*\"]",
|
|
19
|
+
labelWrapper: "mb-1",
|
|
20
|
+
mark: "",
|
|
21
|
+
startContent: "",
|
|
22
|
+
step: "",
|
|
23
|
+
thumb: [
|
|
24
|
+
"group-data-[invalid=true]:data-[focused=true]:outline-2",
|
|
25
|
+
"group-data-[invalid=true]:data-[focused=true]:outline-focus",
|
|
26
|
+
"group-data-[invalid=true]:data-[focused=true]:outline-offset-2"
|
|
27
|
+
],
|
|
28
|
+
track: "",
|
|
29
|
+
trackWrapper: "",
|
|
30
|
+
value: ""
|
|
31
|
+
},
|
|
32
|
+
variants: { readOnly: { true: { base: "**:cursor-not-allowed cursor-not-allowed opacity-disabled" } } }
|
|
33
|
+
});
|
|
31
34
|
/**
|
|
32
35
|
* Slider component based on [HeroUI Slider](https://www.heroui.com//docs/components/slider)
|
|
33
36
|
*/
|
|
34
37
|
const Slider$1 = ({ className = void 0, endContent = void 0, fillOffset = void 0, maxValue = 100, minValue = 0, name, showSteps = false, size = "md", startContent = void 0, step = 1, ...uniformFieldProps }) => {
|
|
35
|
-
const { ariaLabel, disabled, field, getErrorMessageProps, getHelperWrapperProps, invalid, label, onBlur, onChange, ref, required, errorMessage, testId } = useUniformField({
|
|
38
|
+
const { ariaLabel, disabled, field, getErrorMessageProps, getHelperWrapperProps, invalid, label, onBlur, onChange, readOnly, ref, required, errorMessage, testId } = useUniformField({
|
|
36
39
|
name,
|
|
37
40
|
...uniformFieldProps
|
|
38
41
|
});
|
|
@@ -40,8 +43,17 @@ const Slider$1 = ({ className = void 0, endContent = void 0, fillOffset = void 0
|
|
|
40
43
|
const focusSliderInput = () => {
|
|
41
44
|
if (!disabled) visualSliderRef.current?.querySelector("[data-slot=\"thumb\"] input[type=\"range\"]:not(:disabled)")?.focus();
|
|
42
45
|
};
|
|
43
|
-
|
|
46
|
+
useEffect(() => {
|
|
47
|
+
visualSliderRef.current?.querySelectorAll("[data-slot=\"thumb\"] input[type=\"range\"]").forEach((input) => {
|
|
48
|
+
if (readOnly) input.setAttribute("aria-readonly", "true");
|
|
49
|
+
else input.removeAttribute("aria-readonly");
|
|
50
|
+
});
|
|
51
|
+
}, [readOnly]);
|
|
52
|
+
const variants = sliderVariants({ readOnly });
|
|
44
53
|
const classNames = variantsToClassNames(variants, className, "base");
|
|
54
|
+
const handleChange = (nextValue) => {
|
|
55
|
+
if (!readOnly) onChange(nextValue);
|
|
56
|
+
};
|
|
45
57
|
const currentValue = field.value != null ? Number(field.value) : minValue;
|
|
46
58
|
return /* @__PURE__ */ jsxs("div", {
|
|
47
59
|
className: classNames.base,
|
|
@@ -56,13 +68,14 @@ const Slider$1 = ({ className = void 0, endContent = void 0, fillOffset = void 0
|
|
|
56
68
|
/* @__PURE__ */ jsx(VisuallyHidden, { children: /* @__PURE__ */ jsx("input", {
|
|
57
69
|
ref,
|
|
58
70
|
"aria-label": ariaLabel,
|
|
71
|
+
"aria-readonly": readOnly || void 0,
|
|
59
72
|
disabled,
|
|
60
73
|
max: maxValue,
|
|
61
74
|
min: minValue,
|
|
62
75
|
name,
|
|
63
76
|
onBlur,
|
|
64
77
|
onChange: (e) => {
|
|
65
|
-
|
|
78
|
+
handleChange(Number(e.target.value));
|
|
66
79
|
},
|
|
67
80
|
onFocus: focusSliderInput,
|
|
68
81
|
step,
|
|
@@ -95,7 +108,7 @@ const Slider$1 = ({ className = void 0, endContent = void 0, fillOffset = void 0
|
|
|
95
108
|
minValue,
|
|
96
109
|
name: `${name}_slider`,
|
|
97
110
|
onBlur,
|
|
98
|
-
onChange,
|
|
111
|
+
onChange: handleChange,
|
|
99
112
|
showSteps,
|
|
100
113
|
size,
|
|
101
114
|
startContent,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","names":["Slider","HeroUISlider","Slider"],"sources":["../../src/Slider/Slider.tsx","../../src/Slider/index.ts"],"sourcesContent":["import type { TVClassName, TVProps } from '@fuf-stack/pixel-utils';\nimport type { ReactNode } from 'react';\nimport type { InputValueTransform } from '../hooks/useInputValueTransform';\n\nimport { useRef } from 'react';\n\nimport { Slider as HeroUISlider } from '@heroui/slider';\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 sliderVariants = tv({\n slots: {\n base: [\n // Enables group-data selectors used by slider slots.\n 'group',\n // Match shared field wrapper layout.\n 'flex w-full flex-col',\n // Keep spacing between label/track consistent.\n 'gap-y-1.5',\n ],\n endContent: '',\n errorMessage: 'ml-1 mt-1',\n filler: '',\n // see HeroUI styles for group-data condition,\n // e.g.: https://github.com/heroui-inc/heroui/blob/main/packages/core/theme/src/components/select.ts\n label:\n 'cursor-default text-sm text-foreground subpixel-antialiased group-data-[invalid=true]:!text-danger group-data-[required=true]:after:ml-0.5 group-data-[required=true]:after:text-danger group-data-[required=true]:after:content-[\"*\"]',\n labelWrapper: 'mb-1',\n mark: '',\n startContent: '',\n step: '',\n // Validation focuses the input after a mouse submission. HeroUI's keyboard\n // focus-visible state stays false, so expose that focus while invalid too.\n thumb: [\n 'group-data-[invalid=true]:data-[focused=true]:outline-2',\n 'group-data-[invalid=true]:data-[focused=true]:outline-focus',\n 'group-data-[invalid=true]:data-[focused=true]:outline-offset-2',\n ],\n track: '',\n trackWrapper: '',\n value: '',\n },\n});\n\ntype VariantProps = TVProps<typeof sliderVariants>;\ntype ClassName = TVClassName<typeof sliderVariants>;\n\nexport interface SliderProps extends VariantProps {\n /** Custom aria-label for accessibility. If not provided, falls back to field name when no visible label exists */\n ariaLabel?: string;\n /** CSS class name */\n className?: ClassName;\n /** input field is disabled */\n disabled?: boolean;\n /** Content to display at the end of the slider */\n endContent?: ReactNode;\n /** The offset from where the fill should start */\n fillOffset?: number;\n /** form field label */\n label?: string;\n /**\n * The maximum value of the slider\n * @default 100\n */\n maxValue?: number;\n /**\n * The minimum value of the slider\n * @default 0\n */\n minValue?: number;\n /** form field name */\n name: string;\n /**\n * Whether to show step dots on the slider\n * @default false\n */\n showSteps?: boolean;\n /**\n * The size of the slider\n * @default \"md\"\n */\n size?: 'sm' | 'md' | 'lg';\n /** Content to display at the start of the slider */\n startContent?: ReactNode;\n /**\n * The step value of the slider\n * @default 1\n */\n step?: number;\n /** HTML data-testid attribute used in e2e tests */\n testId?: string;\n /** Transform between stored form values and numeric slider values. Range and step use display units. */\n transform?: InputValueTransform<number>;\n}\n\n/**\n * Slider component based on [HeroUI Slider](https://www.heroui.com//docs/components/slider)\n */\nconst Slider = ({\n className = undefined,\n endContent = undefined,\n fillOffset = undefined,\n maxValue = 100,\n minValue = 0,\n name,\n showSteps = false,\n size = 'md',\n startContent = undefined,\n step = 1,\n ...uniformFieldProps\n}: SliderProps) => {\n const {\n ariaLabel,\n disabled,\n field,\n getErrorMessageProps,\n getHelperWrapperProps,\n invalid,\n label,\n onBlur,\n onChange,\n ref,\n required,\n errorMessage,\n testId,\n } = useUniformField({\n name,\n ...uniformFieldProps,\n });\n\n // Ref for the visual slider to forward focus\n const visualSliderRef = useRef<HTMLDivElement>(null);\n const focusSliderInput = () => {\n if (!disabled) {\n visualSliderRef.current\n ?.querySelector<HTMLInputElement>(\n '[data-slot=\"thumb\"] input[type=\"range\"]:not(:disabled)',\n )\n ?.focus();\n }\n };\n\n // classNames from slots\n const variants = sliderVariants();\n const classNames = variantsToClassNames(variants, className, 'base');\n\n // Get the current value, defaulting to minValue if null/undefined\n const currentValue = field.value != null ? Number(field.value) : minValue;\n\n return (\n <div\n className={classNames.base}\n data-invalid={invalid}\n data-required={required}\n data-testid={testId}\n onFocus={(event) => {\n // Descendant focus events bubble here too; leave those alone.\n if (event.target === event.currentTarget) {\n focusSliderInput();\n }\n }}\n tabIndex={disabled ? undefined : -1}\n >\n {/* Visually hidden input for form accessibility and focus management */}\n <VisuallyHidden>\n <input\n ref={ref}\n aria-label={ariaLabel}\n disabled={disabled}\n max={maxValue}\n min={minValue}\n name={name}\n onBlur={onBlur}\n onChange={(e) => {\n onChange(Number(e.target.value));\n }}\n // RHF error focus must reach the interactive input as well.\n onFocus={focusSliderInput}\n step={step}\n tabIndex={-1}\n type=\"range\"\n value={currentValue}\n />\n </VisuallyHidden>\n {/* Visual HeroUISlider component */}\n <HeroUISlider\n ref={visualSliderRef}\n aria-label={ariaLabel}\n classNames={{\n endContent: classNames.endContent,\n filler: classNames.filler,\n label: classNames.label,\n labelWrapper: classNames.labelWrapper,\n mark: classNames.mark,\n startContent: classNames.startContent,\n step: classNames.step,\n thumb: classNames.thumb,\n track: classNames.track,\n trackWrapper: classNames.trackWrapper,\n value: classNames.value,\n }}\n color={invalid ? 'danger' : 'primary'}\n endContent={endContent}\n fillOffset={fillOffset}\n isDisabled={disabled}\n label={label}\n maxValue={maxValue}\n minValue={minValue}\n name={`${name}_slider`}\n onBlur={onBlur}\n onChange={onChange}\n showSteps={showSteps}\n size={size}\n startContent={startContent}\n step={step}\n value={currentValue}\n />\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 </div>\n );\n};\n\nexport default Slider;\n","import Slider from './Slider';\n\nexport type { SliderProps } from './Slider';\n\nexport { sliderVariants } from './Slider';\n\nexport default Slider;\n"],"mappings":";;;;;;;AAaA,MAAa,iBAAiB,GAAG,EAC/B,OAAO;CACL,MAAM;EAEJ;EAEA;EAEA;CACF;CACA,YAAY;CACZ,cAAc;CACd,QAAQ;CAGR,OACE;CACF,cAAc;CACd,MAAM;CACN,cAAc;CACd,MAAM;CAGN,OAAO;EACL;EACA;EACA;CACF;CACA,OAAO;CACP,cAAc;CACd,OAAO;AACT,EACF,CAAC;;;;AAwDD,MAAMA,YAAU,EACd,YAAY,KAAA,GACZ,aAAa,KAAA,GACb,aAAa,KAAA,GACb,WAAW,KACX,WAAW,GACX,MACA,YAAY,OACZ,OAAO,MACP,eAAe,KAAA,GACf,OAAO,GACP,GAAG,wBACc;CACjB,MAAM,EACJ,WACA,UACA,OACA,sBACA,uBACA,SACA,OACA,QACA,UACA,KACA,UACA,cACA,WACE,gBAAgB;EAClB;EACA,GAAG;CACL,CAAC;CAGD,MAAM,kBAAkB,OAAuB,IAAI;CACnD,MAAM,yBAAyB;EAC7B,IAAI,CAAC,UACH,gBAAgB,SACZ,cACA,4DACF,CAAC,EACC,MAAM;CAEd;CAGA,MAAM,WAAW,eAAe;CAChC,MAAM,aAAa,qBAAqB,UAAU,WAAW,MAAM;CAGnE,MAAM,eAAe,MAAM,SAAS,OAAO,OAAO,MAAM,KAAK,IAAI;CAEjE,OACE,qBAAC,OAAD;EACE,WAAW,WAAW;EACtB,gBAAc;EACd,iBAAe;EACf,eAAa;EACb,UAAU,UAAU;GAElB,IAAI,MAAM,WAAW,MAAM,eACzB,iBAAiB;EAErB;EACA,UAAU,WAAW,KAAA,IAAY;EAXnC,UAAA;GAcE,oBAAC,gBAAD,EAAA,UACE,oBAAC,SAAD;IACO;IACL,cAAY;IACF;IACV,KAAK;IACL,KAAK;IACC;IACE;IACR,WAAW,MAAM;KACf,SAAS,OAAO,EAAE,OAAO,KAAK,CAAC;IACjC;IAEA,SAAS;IACH;IACN,UAAU;IACV,MAAK;IACL,OAAO;GACR,CAAA,EACa,CAAA;GAEhB,oBAACC,QAAD;IACE,KAAK;IACL,cAAY;IACZ,YAAY;KACV,YAAY,WAAW;KACvB,QAAQ,WAAW;KACnB,OAAO,WAAW;KAClB,cAAc,WAAW;KACzB,MAAM,WAAW;KACjB,cAAc,WAAW;KACzB,MAAM,WAAW;KACjB,OAAO,WAAW;KAClB,OAAO,WAAW;KAClB,cAAc,WAAW;KACzB,OAAO,WAAW;IACpB;IACA,OAAO,UAAU,WAAW;IAChB;IACA;IACZ,YAAY;IACL;IACG;IACA;IACV,MAAM,GAAG,KAAK;IACN;IACE;IACC;IACL;IACQ;IACR;IACN,OAAO;GACR,CAAA;GACA,UACC,oBAAC,OAAD;IACE,GAAI,sBAAsB;IAC1B,WAAW,GACT,sBAAsB,CAAC,EAAE,WAEzB,YACF;IAEA,UAAA,oBAAC,OAAD;KAAK,GAAI,qBAAqB;KAAI,UAAA;IAAkB,CAAA;GACjD,CAAA,IACH;EACD;;AAET;;ACpOA,IAAA,iBAAeC"}
|
|
1
|
+
{"version":3,"file":"index.mjs","names":["Slider","HeroUISlider","Slider"],"sources":["../../src/Slider/Slider.tsx","../../src/Slider/index.ts"],"sourcesContent":["import type { TVClassName, TVProps } from '@fuf-stack/pixel-utils';\nimport type { ReactNode } from 'react';\nimport type { InputValueTransform } from '../hooks/useInputValueTransform';\n\nimport { useEffect, useRef } from 'react';\n\nimport { Slider as HeroUISlider } from '@heroui/slider';\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 sliderVariants = tv({\n slots: {\n base: [\n // Enables group-data selectors used by slider slots.\n 'group',\n // Match shared field wrapper layout.\n 'flex w-full flex-col',\n // Keep spacing between label/track consistent.\n 'gap-y-1.5',\n ],\n endContent: '',\n errorMessage: 'ml-1 mt-1',\n filler: '',\n // see HeroUI styles for group-data condition,\n // e.g.: https://github.com/heroui-inc/heroui/blob/main/packages/core/theme/src/components/select.ts\n label:\n 'cursor-default text-sm text-foreground subpixel-antialiased group-data-[invalid=true]:!text-danger group-data-[required=true]:after:ml-0.5 group-data-[required=true]:after:text-danger group-data-[required=true]:after:content-[\"*\"]',\n labelWrapper: 'mb-1',\n mark: '',\n startContent: '',\n step: '',\n // Validation focuses the input after a mouse submission. HeroUI's keyboard\n // focus-visible state stays false, so expose that focus while invalid too.\n thumb: [\n 'group-data-[invalid=true]:data-[focused=true]:outline-2',\n 'group-data-[invalid=true]:data-[focused=true]:outline-focus',\n 'group-data-[invalid=true]:data-[focused=true]:outline-offset-2',\n ],\n track: '',\n trackWrapper: '',\n value: '',\n },\n variants: {\n readOnly: {\n true: {\n // Inner controls set their own cursors, so override every descendant.\n base: '**:cursor-not-allowed cursor-not-allowed opacity-disabled',\n },\n },\n },\n});\n\ntype VariantProps = TVProps<typeof sliderVariants>;\ntype ClassName = TVClassName<typeof sliderVariants>;\n\nexport interface SliderProps extends VariantProps {\n /** Custom aria-label for accessibility. If not provided, falls back to field name when no visible label exists */\n ariaLabel?: string;\n /** CSS class name */\n className?: ClassName;\n /** input field is disabled */\n disabled?: boolean;\n /** Content to display at the end of the slider */\n endContent?: ReactNode;\n /** The offset from where the fill should start */\n fillOffset?: number;\n /** form field label */\n label?: string;\n /**\n * The maximum value of the slider\n * @default 100\n */\n maxValue?: number;\n /**\n * The minimum value of the slider\n * @default 0\n */\n minValue?: number;\n /** form field name */\n name: string;\n /** Prevents changes while keeping the slider focusable and its value in validation and submission */\n readOnly?: boolean;\n /**\n * Whether to show step dots on the slider\n * @default false\n */\n showSteps?: boolean;\n /**\n * The size of the slider\n * @default \"md\"\n */\n size?: 'sm' | 'md' | 'lg';\n /** Content to display at the start of the slider */\n startContent?: ReactNode;\n /**\n * The step value of the slider\n * @default 1\n */\n step?: number;\n /** HTML data-testid attribute used in e2e tests */\n testId?: string;\n /** Transform between stored form values and numeric slider values. Range and step use display units. */\n transform?: InputValueTransform<number>;\n}\n\n/**\n * Slider component based on [HeroUI Slider](https://www.heroui.com//docs/components/slider)\n */\nconst Slider = ({\n className = undefined,\n endContent = undefined,\n fillOffset = undefined,\n maxValue = 100,\n minValue = 0,\n name,\n showSteps = false,\n size = 'md',\n startContent = undefined,\n step = 1,\n ...uniformFieldProps\n}: SliderProps) => {\n const {\n ariaLabel,\n disabled,\n field,\n getErrorMessageProps,\n getHelperWrapperProps,\n invalid,\n label,\n onBlur,\n onChange,\n readOnly,\n ref,\n required,\n errorMessage,\n testId,\n } = useUniformField({\n name,\n ...uniformFieldProps,\n });\n\n // Ref for the visual slider to forward focus\n const visualSliderRef = useRef<HTMLDivElement>(null);\n const focusSliderInput = () => {\n if (!disabled) {\n visualSliderRef.current\n ?.querySelector<HTMLInputElement>(\n '[data-slot=\"thumb\"] input[type=\"range\"]:not(:disabled)',\n )\n ?.focus();\n }\n };\n\n // HeroUI renders the thumb's range input internally and offers no prop for\n // it, so mark it read-only directly; screen readers announce this state when\n // keyboard focus reaches the thumb.\n useEffect(() => {\n visualSliderRef.current\n ?.querySelectorAll<HTMLInputElement>(\n '[data-slot=\"thumb\"] input[type=\"range\"]',\n )\n .forEach((input) => {\n if (readOnly) {\n input.setAttribute('aria-readonly', 'true');\n } else {\n input.removeAttribute('aria-readonly');\n }\n });\n }, [readOnly]);\n\n // classNames from slots\n const variants = sliderVariants({ readOnly });\n const classNames = variantsToClassNames(variants, className, 'base');\n\n // HeroUI Slider has no read-only mode: it stays focusable and controlled,\n // and changes are ignored so the thumb keeps the stored value.\n const handleChange = (nextValue: number | number[]) => {\n if (!readOnly) {\n onChange(nextValue);\n }\n };\n\n // Get the current value, defaulting to minValue if null/undefined\n const currentValue = field.value != null ? Number(field.value) : minValue;\n\n return (\n <div\n className={classNames.base}\n data-invalid={invalid}\n data-required={required}\n data-testid={testId}\n onFocus={(event) => {\n // Descendant focus events bubble here too; leave those alone.\n if (event.target === event.currentTarget) {\n focusSliderInput();\n }\n }}\n tabIndex={disabled ? undefined : -1}\n >\n {/* Visually hidden input for form accessibility and focus management */}\n <VisuallyHidden>\n <input\n ref={ref}\n aria-label={ariaLabel}\n aria-readonly={readOnly || undefined}\n disabled={disabled}\n max={maxValue}\n min={minValue}\n name={name}\n onBlur={onBlur}\n onChange={(e) => {\n handleChange(Number(e.target.value));\n }}\n // RHF error focus must reach the interactive input as well.\n onFocus={focusSliderInput}\n step={step}\n tabIndex={-1}\n type=\"range\"\n value={currentValue}\n />\n </VisuallyHidden>\n {/* Visual HeroUISlider component */}\n <HeroUISlider\n ref={visualSliderRef}\n aria-label={ariaLabel}\n classNames={{\n endContent: classNames.endContent,\n filler: classNames.filler,\n label: classNames.label,\n labelWrapper: classNames.labelWrapper,\n mark: classNames.mark,\n startContent: classNames.startContent,\n step: classNames.step,\n thumb: classNames.thumb,\n track: classNames.track,\n trackWrapper: classNames.trackWrapper,\n value: classNames.value,\n }}\n color={invalid ? 'danger' : 'primary'}\n endContent={endContent}\n fillOffset={fillOffset}\n isDisabled={disabled}\n label={label}\n maxValue={maxValue}\n minValue={minValue}\n name={`${name}_slider`}\n onBlur={onBlur}\n onChange={handleChange}\n showSteps={showSteps}\n size={size}\n startContent={startContent}\n step={step}\n value={currentValue}\n />\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 </div>\n );\n};\n\nexport default Slider;\n","import Slider from './Slider';\n\nexport type { SliderProps } from './Slider';\n\nexport { sliderVariants } from './Slider';\n\nexport default Slider;\n"],"mappings":";;;;;;;AAaA,MAAa,iBAAiB,GAAG;CAC/B,OAAO;EACL,MAAM;GAEJ;GAEA;GAEA;EACF;EACA,YAAY;EACZ,cAAc;EACd,QAAQ;EAGR,OACE;EACF,cAAc;EACd,MAAM;EACN,cAAc;EACd,MAAM;EAGN,OAAO;GACL;GACA;GACA;EACF;EACA,OAAO;EACP,cAAc;EACd,OAAO;CACT;CACA,UAAU,EACR,UAAU,EACR,MAAM,EAEJ,MAAM,4DACR,EACF,EACF;AACF,CAAC;;;;AA0DD,MAAMA,YAAU,EACd,YAAY,KAAA,GACZ,aAAa,KAAA,GACb,aAAa,KAAA,GACb,WAAW,KACX,WAAW,GACX,MACA,YAAY,OACZ,OAAO,MACP,eAAe,KAAA,GACf,OAAO,GACP,GAAG,wBACc;CACjB,MAAM,EACJ,WACA,UACA,OACA,sBACA,uBACA,SACA,OACA,QACA,UACA,UACA,KACA,UACA,cACA,WACE,gBAAgB;EAClB;EACA,GAAG;CACL,CAAC;CAGD,MAAM,kBAAkB,OAAuB,IAAI;CACnD,MAAM,yBAAyB;EAC7B,IAAI,CAAC,UACH,gBAAgB,SACZ,cACA,4DACF,CAAC,EACC,MAAM;CAEd;CAKA,gBAAgB;EACd,gBAAgB,SACZ,iBACA,6CACF,CAAC,CACA,SAAS,UAAU;GAClB,IAAI,UACF,MAAM,aAAa,iBAAiB,MAAM;QAE1C,MAAM,gBAAgB,eAAe;EAEzC,CAAC;CACL,GAAG,CAAC,QAAQ,CAAC;CAGb,MAAM,WAAW,eAAe,EAAE,SAAS,CAAC;CAC5C,MAAM,aAAa,qBAAqB,UAAU,WAAW,MAAM;CAInE,MAAM,gBAAgB,cAAiC;EACrD,IAAI,CAAC,UACH,SAAS,SAAS;CAEtB;CAGA,MAAM,eAAe,MAAM,SAAS,OAAO,OAAO,MAAM,KAAK,IAAI;CAEjE,OACE,qBAAC,OAAD;EACE,WAAW,WAAW;EACtB,gBAAc;EACd,iBAAe;EACf,eAAa;EACb,UAAU,UAAU;GAElB,IAAI,MAAM,WAAW,MAAM,eACzB,iBAAiB;EAErB;EACA,UAAU,WAAW,KAAA,IAAY;EAXnC,UAAA;GAcE,oBAAC,gBAAD,EAAA,UACE,oBAAC,SAAD;IACO;IACL,cAAY;IACZ,iBAAe,YAAY,KAAA;IACjB;IACV,KAAK;IACL,KAAK;IACC;IACE;IACR,WAAW,MAAM;KACf,aAAa,OAAO,EAAE,OAAO,KAAK,CAAC;IACrC;IAEA,SAAS;IACH;IACN,UAAU;IACV,MAAK;IACL,OAAO;GACR,CAAA,EACa,CAAA;GAEhB,oBAACC,QAAD;IACE,KAAK;IACL,cAAY;IACZ,YAAY;KACV,YAAY,WAAW;KACvB,QAAQ,WAAW;KACnB,OAAO,WAAW;KAClB,cAAc,WAAW;KACzB,MAAM,WAAW;KACjB,cAAc,WAAW;KACzB,MAAM,WAAW;KACjB,OAAO,WAAW;KAClB,OAAO,WAAW;KAClB,cAAc,WAAW;KACzB,OAAO,WAAW;IACpB;IACA,OAAO,UAAU,WAAW;IAChB;IACA;IACZ,YAAY;IACL;IACG;IACA;IACV,MAAM,GAAG,KAAK;IACN;IACR,UAAU;IACC;IACL;IACQ;IACR;IACN,OAAO;GACR,CAAA;GACA,UACC,oBAAC,OAAD;IACE,GAAI,sBAAsB;IAC1B,WAAW,GACT,sBAAsB,CAAC,EAAE,WAEzB,YACF;IAEA,UAAA,oBAAC,OAAD;KAAK,GAAI,qBAAqB;KAAI,UAAA;IAAkB,CAAA;GACjD,CAAA,IACH;EACD;;AAET;;ACzQA,IAAA,iBAAeC"}
|