@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/Input/Input.tsx"],"mappings":";;;cAea,iBAAa
|
|
1
|
+
{"version":3,"file":"index.d.mts","names":[],"sources":["../../src/Input/Input.tsx"],"mappings":";;;cAea,iBAAa;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;KAqBrB,eAAe,eAAe;KAC9B,YAAY,mBAAmB;UAEnB,mBAAmB;;EAElC;;EAEA,YAAY;;EAEZ;;EAEA;;EAEA;;EAEA,aAAa;;EAEb;;EAEA,QAAQ;;EAER;;EAEA;;EAEA;;EAEA;;EAEA;;EAEA;;EAEA,eAAe;;EAEf;;EAEA,YAAY;;EAEZ;;;;;cAMI,UAAS,WAAA,YAAA,WAAA,eAAA,YAAA,MAAA,SAAA,aAAA,oBAAA,MAAA,cAAA,SAAA,qBAaZ,+BAAU,IAAA"}
|
package/dist/Input/index.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
+
import { useInputValueDebounce } from "../hooks/useInputValueDebounce/index.mjs";
|
|
1
2
|
import { useUniformField } from "../hooks/useUniformField/index.mjs";
|
|
2
3
|
import { useWatchFormReset } from "../hooks/useWatchFormReset/index.mjs";
|
|
3
|
-
import { useInputValueDebounce } from "../hooks/useInputValueDebounce/index.mjs";
|
|
4
4
|
import { cn, tv, variantsToClassNames } from "@fuf-stack/pixel-utils";
|
|
5
5
|
import { forwardRef, useState } from "react";
|
|
6
6
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
@@ -89,21 +89,24 @@ const InputPassword = forwardRef(({ classNames = void 0, clearable, endContent =
|
|
|
89
89
|
});
|
|
90
90
|
InputPassword.displayName = "InputPassword";
|
|
91
91
|
// src/Input/Input.tsx
|
|
92
|
-
const inputVariants = tv({
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
92
|
+
const inputVariants = tv({
|
|
93
|
+
slots: {
|
|
94
|
+
/** wrapper around the whole input */
|
|
95
|
+
base: "",
|
|
96
|
+
/** clear button */
|
|
97
|
+
clearButton: "",
|
|
98
|
+
/** actual input element */
|
|
99
|
+
input: "",
|
|
100
|
+
/** inner wrapper (HeroUI inputWrapper slot) */
|
|
101
|
+
inputWrapper: "bg-content1 group-data-[focus=true]:border-focus"
|
|
102
|
+
},
|
|
103
|
+
variants: { readOnly: { true: { base: "**:cursor-not-allowed cursor-not-allowed opacity-disabled" } } }
|
|
104
|
+
});
|
|
102
105
|
/**
|
|
103
106
|
* Input component based on [HeroUI Input](https://www.heroui.com//docs/components/input)
|
|
104
107
|
*/
|
|
105
108
|
const Input$1 = ({ className: _className = void 0, clearable = false, debounceDelay = 300, endContent = void 0, name, onClear = void 0, placeholder = " ", hidePasswordToggle = false, size = void 0, startContent = void 0, type = void 0, ...uniformFieldProps }) => {
|
|
106
|
-
const { ariaLabel, disabled, field: { onChange: fieldOnChange, onBlur: fieldOnBlur, value: fieldValue, ref }, errorMessage, invalid, label, required, testId, resetField } = useUniformField({
|
|
109
|
+
const { ariaLabel, disabled, field: { onChange: fieldOnChange, onBlur: fieldOnBlur, value: fieldValue, ref }, errorMessage, invalid, label, readOnly, required, testId, resetField } = useUniformField({
|
|
107
110
|
name,
|
|
108
111
|
type,
|
|
109
112
|
...uniformFieldProps
|
|
@@ -119,11 +122,12 @@ const Input$1 = ({ className: _className = void 0, clearable = false, debounceDe
|
|
|
119
122
|
resetField(name, { defaultValue: null });
|
|
120
123
|
onClear?.();
|
|
121
124
|
};
|
|
122
|
-
const
|
|
125
|
+
const isClearable = clearable && !readOnly;
|
|
126
|
+
const clearableProps = isClearable ? {
|
|
123
127
|
isClearable: true,
|
|
124
128
|
onClear: clearValue
|
|
125
129
|
} : {};
|
|
126
|
-
const variants = inputVariants();
|
|
130
|
+
const variants = inputVariants({ readOnly });
|
|
127
131
|
const classNames = variantsToClassNames(variants, _className, "base");
|
|
128
132
|
const commonProps = {
|
|
129
133
|
ref,
|
|
@@ -142,6 +146,7 @@ const Input$1 = ({ className: _className = void 0, clearable = false, debounceDe
|
|
|
142
146
|
id: testId,
|
|
143
147
|
isDisabled: disabled,
|
|
144
148
|
isInvalid: invalid,
|
|
149
|
+
isReadOnly: readOnly,
|
|
145
150
|
isRequired: required,
|
|
146
151
|
label,
|
|
147
152
|
labelPlacement: "outside",
|
|
@@ -168,7 +173,7 @@ const Input$1 = ({ className: _className = void 0, clearable = false, debounceDe
|
|
|
168
173
|
}
|
|
169
174
|
if (type === "password") return /* @__PURE__ */ jsx(InputPassword, {
|
|
170
175
|
...commonProps,
|
|
171
|
-
clearable,
|
|
176
|
+
clearable: isClearable,
|
|
172
177
|
hidePasswordToggle,
|
|
173
178
|
onChange,
|
|
174
179
|
onClear: clearValue,
|
package/dist/Input/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","names":["HeroInput","Input","HeroNumberInput","HeroInput","Input"],"sources":["../../src/Input/InputPassword.tsx","../../src/Input/Input.tsx","../../src/Input/index.ts"],"sourcesContent":["import type { InputProps as HeroInputProps } from '@heroui/input';\n\nimport { forwardRef, useState } from 'react';\nimport { FaEye, FaEyeSlash, FaXmark } from 'react-icons/fa6';\n\nimport { Input as HeroInput } from '@heroui/input';\n\nimport { cn } from '@fuf-stack/pixel-utils';\n\nimport { useWatchFormReset } from '../hooks/useWatchFormReset';\n\ninterface InputPasswordProps extends Omit<\n HeroInputProps,\n 'type' | 'value' | 'name' | 'isClearable' | 'onClear'\n> {\n clearable: boolean;\n hidePasswordToggle: boolean;\n name: string;\n onClear: () => void;\n testId: string;\n value: string;\n}\n\n/** Keeps password presentation separate from form registration and validation. */\nconst InputPassword = forwardRef<HTMLInputElement, InputPasswordProps>(\n (\n {\n classNames = undefined,\n clearable,\n endContent = undefined,\n isDisabled = false,\n name,\n onClear,\n onKeyDown = undefined,\n hidePasswordToggle,\n testId,\n value,\n ...inputProps\n },\n ref,\n ) => {\n const [isPasswordVisible, setIsPasswordVisible] = useState(false);\n\n // Reset visibility before rendering a reused field with new props.\n // Switching away from type=password unmounts this component altogether.\n const [previousPasswordField, setPreviousPasswordField] = useState({\n name,\n hidePasswordToggle,\n });\n if (\n previousPasswordField.name !== name ||\n previousPasswordField.hidePasswordToggle !== hidePasswordToggle\n ) {\n setPreviousPasswordField({ name, hidePasswordToggle });\n setIsPasswordVisible(false);\n }\n useWatchFormReset({\n onReset: () => {\n setIsPasswordVisible(false);\n },\n });\n\n const clearValue = () => {\n onClear();\n setIsPasswordVisible(false);\n };\n\n // HeroUI wraps endContent inside its clear button. Keep clear and reveal as\n // sibling buttons so custom content and the toggle never become nested buttons.\n const passwordEndContent = !hidePasswordToggle ? (\n <span className=\"inline-flex shrink-0 items-center gap-2\">\n {endContent}\n {clearable && !!value ? (\n <button\n aria-label=\"clear input\"\n className={cn(\n 'rounded-sm p-1 text-default-400 outline-none focus-visible:ring-2 focus-visible:ring-focus',\n classNames?.clearButton,\n )}\n disabled={isDisabled}\n onClick={clearValue}\n onMouseDown={(event) => {\n event.preventDefault();\n }}\n type=\"button\"\n >\n <FaXmark aria-hidden=\"true\" />\n </button>\n ) : null}\n <button\n aria-controls={testId}\n aria-label={isPasswordVisible ? 'Hide password' : 'Show password'}\n aria-pressed={isPasswordVisible}\n className=\"rounded-sm p-1 text-default-400 outline-none focus-visible:ring-2 focus-visible:ring-focus\"\n data-testid={`${testId}_password_toggle`}\n disabled={isDisabled}\n onClick={() => {\n setIsPasswordVisible((visible) => {\n return !visible;\n });\n }}\n // Preserve input focus for pointer activation and normal keyboard focus.\n onMouseDown={(event) => {\n event.preventDefault();\n }}\n type=\"button\"\n >\n {isPasswordVisible ? (\n <FaEyeSlash aria-hidden=\"true\" />\n ) : (\n <FaEye aria-hidden=\"true\" />\n )}\n </button>\n </span>\n ) : (\n endContent\n );\n\n const clearableProps: Pick<HeroInputProps, 'isClearable' | 'onClear'> =\n clearable && hidePasswordToggle\n ? { isClearable: true, onClear: clearValue }\n : {};\n\n return (\n <HeroInput\n {...inputProps}\n {...clearableProps}\n ref={ref}\n classNames={classNames}\n endContent={passwordEndContent}\n isDisabled={isDisabled}\n name={name}\n onKeyDown={\n !hidePasswordToggle && clearable\n ? (event) => {\n onKeyDown?.(event);\n if (\n !event.defaultPrevented &&\n event.key === 'Escape' &&\n value &&\n !isDisabled\n ) {\n event.preventDefault();\n clearValue();\n }\n }\n : onKeyDown\n }\n type={!hidePasswordToggle && isPasswordVisible ? 'text' : 'password'}\n value={value}\n />\n );\n },\n);\n\nInputPassword.displayName = 'InputPassword';\n\nexport default InputPassword;\n","import type { TVClassName, TVProps } from '@fuf-stack/pixel-utils';\nimport type { InputProps as HeroInputProps } from '@heroui/input';\nimport type { ReactNode } from 'react';\nimport type { InputValueTransform } from '../hooks/useInputValueTransform';\n\nimport { Input as HeroInput } from '@heroui/input';\nimport { NumberInput as HeroNumberInput } from '@heroui/number-input';\n\nimport { tv, variantsToClassNames } from '@fuf-stack/pixel-utils';\n\nimport { useInputValueDebounce } from '../hooks/useInputValueDebounce';\nimport { useUniformField } from '../hooks/useUniformField';\nimport InputPassword from './InputPassword';\n\n// input variants\nexport const inputVariants = tv({\n slots: {\n /** wrapper around the whole input */\n base: '',\n /** clear button */\n clearButton: '',\n /** actual input element */\n input: '',\n /** inner wrapper (HeroUI inputWrapper slot) */\n inputWrapper: 'bg-content1 group-data-[focus=true]:border-focus',\n },\n});\n\ntype VariantProps = TVProps<typeof inputVariants>;\ntype ClassName = TVClassName<typeof inputVariants>;\n\nexport interface InputProps extends VariantProps {\n /** Overrides the accessible name, otherwise derived from the field name when no visible label exists */\n ariaLabel?: string;\n /** Applies CSS classes to the input slots */\n className?: ClassName;\n /** Shows a clear button when the input has a value */\n clearable?: boolean;\n /** Sets the delay in milliseconds before updating form state (default: 300) */\n debounceDelay?: number;\n /** Disables the input */\n disabled?: boolean;\n /** Displays content at the end of the input */\n endContent?: ReactNode;\n /** Hides the visibility toggle for password inputs (default: false) */\n hidePasswordToggle?: boolean;\n /** Sets the field label */\n label?: ReactNode;\n /** Identifies the field in form state */\n name: string;\n /** Callback invoked when the input value is cleared */\n onClear?: () => void;\n /** Sets the placeholder text */\n placeholder?: string;\n /** Redacts the value from Uniform debug output; password inputs are always redacted */\n sensitive?: boolean;\n /** Sets the input size */\n size?: 'sm' | 'md' | 'lg';\n /** Displays content at the start of the input */\n startContent?: ReactNode;\n /** Sets the HTML data-testid attribute for e2e tests */\n testId?: string;\n /** Converts between display and form values */\n transform?: InputValueTransform<string>;\n /** Sets the input type */\n type?: 'number' | 'password';\n}\n\n/**\n * Input component based on [HeroUI Input](https://www.heroui.com//docs/components/input)\n */\nconst Input = ({\n className: _className = undefined,\n clearable = false,\n debounceDelay = 300,\n endContent = undefined,\n name,\n onClear = undefined,\n placeholder = ' ',\n hidePasswordToggle = false,\n size = undefined,\n startContent = undefined,\n type = undefined,\n ...uniformFieldProps\n}: InputProps) => {\n const {\n ariaLabel,\n disabled,\n field: {\n onChange: fieldOnChange,\n onBlur: fieldOnBlur,\n value: fieldValue,\n ref,\n },\n errorMessage,\n invalid,\n label,\n required,\n testId,\n resetField,\n } = useUniformField({ name, type, ...uniformFieldProps });\n\n // Use hook that provides debounced onChange and enhanced blur handling\n const { onChange, onBlur, value } = useInputValueDebounce({\n debounceDelay,\n name,\n onBlur: fieldOnBlur,\n onChange: fieldOnChange,\n value: fieldValue,\n });\n\n const clearValue = () => {\n // Clear initial values too, rather than restoring the default value.\n resetField(name, { defaultValue: null });\n onClear?.();\n };\n\n const clearableProps: Pick<HeroInputProps, 'isClearable' | 'onClear'> =\n clearable ? { isClearable: true, onClear: clearValue } : {};\n\n const variants = inputVariants();\n const classNames = variantsToClassNames(variants, _className, 'base');\n\n // Common props for both Input and NumberInput\n const commonProps = {\n ref,\n // Only add aria-label if there's no meaningful placeholder (HeroUI uses placeholder as aria-label)\n 'aria-label':\n !placeholder || placeholder.trim() === '' ? ariaLabel : undefined,\n // disable autocomplete\n autoComplete: 'off',\n classNames: {\n base: classNames.base,\n clearButton: classNames.clearButton,\n // set padding to 0 for error message exit animation\n helperWrapper: 'p-0',\n input: classNames.input,\n inputWrapper: classNames.inputWrapper,\n },\n 'data-testid': testId,\n endContent,\n errorMessage,\n id: testId,\n isDisabled: disabled,\n isInvalid: invalid,\n isRequired: required,\n label,\n labelPlacement: 'outside' as const,\n name,\n onBlur,\n placeholder,\n radius: 'sm' as const,\n size,\n startContent,\n variant: 'bordered' as const,\n };\n\n // Render NumberInput for number type\n if (type === 'number') {\n // Parse the string value to number - use null for empty/cleared state to keep component controlled\n const numberValue =\n value !== '' && value != null && !Number.isNaN(Number(value))\n ? Number(value)\n : null;\n\n return (\n <HeroNumberInput\n {...commonProps}\n {...clearableProps}\n // Disable thousands separator to avoid parsing issues\n formatOptions={{\n useGrouping: false,\n }}\n // NumberInput onChange receives either an event or a number\n onChange={(e: React.ChangeEvent<HTMLInputElement> | number) => {\n if (typeof e === 'number') {\n // Convert number to synthetic event and pass through debounced onChange\n onChange({\n target: { value: String(e) },\n });\n } else {\n // Pass event through debounced onChange\n onChange(e);\n }\n }}\n // @ts-expect-error - HeroUI NumberInput type is not compatible with null,\n // but it needs to be for empty/cleared state to be controlled\n value={numberValue}\n />\n );\n }\n\n if (type === 'password') {\n return (\n <InputPassword\n {...commonProps}\n clearable={clearable}\n hidePasswordToggle={hidePasswordToggle}\n onChange={onChange}\n onClear={clearValue}\n testId={testId}\n value={value}\n />\n );\n }\n\n return (\n <HeroInput\n {...commonProps}\n {...clearableProps}\n onChange={onChange}\n type={type}\n value={value}\n />\n );\n};\n\nexport default Input;\n","import Input from './Input';\n\nexport type { InputProps } from './Input';\n\nexport default Input;\n"],"mappings":";;;;;;;;;;;AAwBA,MAAM,gBAAgB,YAElB,EACE,aAAa,K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AW;GAExB,eAAe;GACf,OAAO,WAAW;GAClB,cAAc,WAAW;EAC3B;EACA,eAAe;EACf;EACA;EACA,IAAI;EACJ,YAAY;EACZ,WAAW;EACX,YAAY;EACZ;EACA,gBAAgB;EAChB;EACA;EACA;EACA,QAAQ;EACR;EACA;EACA,SAAS;CACX;CAGA,IAAI,SAAS,UAAU;EAErB,MAAM,cACJ,UAAU,MAAM,SAAS,QAAQ,CAAC,OAAO,MAAM,OAAO,KAAK,CAAC,IACxD,OAAO,KAAK,IACZ;EAEN,OACE,oBAACC,aAAD;GACE,GAAI;GACJ,GAAI;GAEJ,eAAe,EACb,aAAa,MACf;GAEA,WAAW,MAAoD;IAC7D,IAAI,OAAO,MAAM,UAEf,SAAS,EACP,QAAQ,EAAE,OAAO,OAAO,CAAC,EAAE,EAC7B,CAAC;SAGD,SAAS,CAAC;GAEd;GAGA,OAAO;EACR,CAAA;CAEL;CAEA,IAAI,SAAS,YACX,OACE,oBAAC,eAAD;EACE,GAAI;EACO;EACS;EACV;EACV,SAAS;EACD;EACD;CACR,CAAA;CAIL,OACE,oBAACC,OAAD;EACE,GAAI;EACJ,GAAI;EACM;EACJ;EACC;CACR,CAAA;AAEL;;ACnNA,IAAA,gBAAeC"}
|
|
1
|
+
{"version":3,"file":"index.mjs","names":["HeroInput","Input","HeroNumberInput","HeroInput","Input"],"sources":["../../src/Input/InputPassword.tsx","../../src/Input/Input.tsx","../../src/Input/index.ts"],"sourcesContent":["import type { InputProps as HeroInputProps } from '@heroui/input';\n\nimport { forwardRef, useState } from 'react';\nimport { FaEye, FaEyeSlash, FaXmark } from 'react-icons/fa6';\n\nimport { Input as HeroInput } from '@heroui/input';\n\nimport { cn } from '@fuf-stack/pixel-utils';\n\nimport { useWatchFormReset } from '../hooks/useWatchFormReset';\n\ninterface InputPasswordProps extends Omit<\n HeroInputProps,\n 'type' | 'value' | 'name' | 'isClearable' | 'onClear'\n> {\n clearable: boolean;\n hidePasswordToggle: boolean;\n name: string;\n onClear: () => void;\n testId: string;\n value: string;\n}\n\n/** Keeps password presentation separate from form registration and validation. */\nconst InputPassword = forwardRef<HTMLInputElement, InputPasswordProps>(\n (\n {\n classNames = undefined,\n clearable,\n endContent = undefined,\n isDisabled = false,\n name,\n onClear,\n onKeyDown = undefined,\n hidePasswordToggle,\n testId,\n value,\n ...inputProps\n },\n ref,\n ) => {\n const [isPasswordVisible, setIsPasswordVisible] = useState(false);\n\n // Reset visibility before rendering a reused field with new props.\n // Switching away from type=password unmounts this component altogether.\n const [previousPasswordField, setPreviousPasswordField] = useState({\n name,\n hidePasswordToggle,\n });\n if (\n previousPasswordField.name !== name ||\n previousPasswordField.hidePasswordToggle !== hidePasswordToggle\n ) {\n setPreviousPasswordField({ name, hidePasswordToggle });\n setIsPasswordVisible(false);\n }\n useWatchFormReset({\n onReset: () => {\n setIsPasswordVisible(false);\n },\n });\n\n const clearValue = () => {\n onClear();\n setIsPasswordVisible(false);\n };\n\n // HeroUI wraps endContent inside its clear button. Keep clear and reveal as\n // sibling buttons so custom content and the toggle never become nested buttons.\n const passwordEndContent = !hidePasswordToggle ? (\n <span className=\"inline-flex shrink-0 items-center gap-2\">\n {endContent}\n {clearable && !!value ? (\n <button\n aria-label=\"clear input\"\n className={cn(\n 'rounded-sm p-1 text-default-400 outline-none focus-visible:ring-2 focus-visible:ring-focus',\n classNames?.clearButton,\n )}\n disabled={isDisabled}\n onClick={clearValue}\n onMouseDown={(event) => {\n event.preventDefault();\n }}\n type=\"button\"\n >\n <FaXmark aria-hidden=\"true\" />\n </button>\n ) : null}\n <button\n aria-controls={testId}\n aria-label={isPasswordVisible ? 'Hide password' : 'Show password'}\n aria-pressed={isPasswordVisible}\n className=\"rounded-sm p-1 text-default-400 outline-none focus-visible:ring-2 focus-visible:ring-focus\"\n data-testid={`${testId}_password_toggle`}\n disabled={isDisabled}\n onClick={() => {\n setIsPasswordVisible((visible) => {\n return !visible;\n });\n }}\n // Preserve input focus for pointer activation and normal keyboard focus.\n onMouseDown={(event) => {\n event.preventDefault();\n }}\n type=\"button\"\n >\n {isPasswordVisible ? (\n <FaEyeSlash aria-hidden=\"true\" />\n ) : (\n <FaEye aria-hidden=\"true\" />\n )}\n </button>\n </span>\n ) : (\n endContent\n );\n\n const clearableProps: Pick<HeroInputProps, 'isClearable' | 'onClear'> =\n clearable && hidePasswordToggle\n ? { isClearable: true, onClear: clearValue }\n : {};\n\n return (\n <HeroInput\n {...inputProps}\n {...clearableProps}\n ref={ref}\n classNames={classNames}\n endContent={passwordEndContent}\n isDisabled={isDisabled}\n name={name}\n onKeyDown={\n !hidePasswordToggle && clearable\n ? (event) => {\n onKeyDown?.(event);\n if (\n !event.defaultPrevented &&\n event.key === 'Escape' &&\n value &&\n !isDisabled\n ) {\n event.preventDefault();\n clearValue();\n }\n }\n : onKeyDown\n }\n type={!hidePasswordToggle && isPasswordVisible ? 'text' : 'password'}\n value={value}\n />\n );\n },\n);\n\nInputPassword.displayName = 'InputPassword';\n\nexport default InputPassword;\n","import type { TVClassName, TVProps } from '@fuf-stack/pixel-utils';\nimport type { InputProps as HeroInputProps } from '@heroui/input';\nimport type { ReactNode } from 'react';\nimport type { InputValueTransform } from '../hooks/useInputValueTransform';\n\nimport { Input as HeroInput } from '@heroui/input';\nimport { NumberInput as HeroNumberInput } from '@heroui/number-input';\n\nimport { tv, variantsToClassNames } from '@fuf-stack/pixel-utils';\n\nimport { useInputValueDebounce } from '../hooks/useInputValueDebounce';\nimport { useUniformField } from '../hooks/useUniformField';\nimport InputPassword from './InputPassword';\n\n// input variants\nexport const inputVariants = tv({\n slots: {\n /** wrapper around the whole input */\n base: '',\n /** clear button */\n clearButton: '',\n /** actual input element */\n input: '',\n /** inner wrapper (HeroUI inputWrapper slot) */\n inputWrapper: 'bg-content1 group-data-[focus=true]:border-focus',\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 inputVariants>;\ntype ClassName = TVClassName<typeof inputVariants>;\n\nexport interface InputProps extends VariantProps {\n /** Overrides the accessible name, otherwise derived from the field name when no visible label exists */\n ariaLabel?: string;\n /** Applies CSS classes to the input slots */\n className?: ClassName;\n /** Shows a clear button when the input has a value */\n clearable?: boolean;\n /** Sets the delay in milliseconds before updating form state (default: 300) */\n debounceDelay?: number;\n /** Disables the input */\n disabled?: boolean;\n /** Displays content at the end of the input */\n endContent?: ReactNode;\n /** Hides the visibility toggle for password inputs (default: false) */\n hidePasswordToggle?: boolean;\n /** Sets the field label */\n label?: ReactNode;\n /** Identifies the field in form state */\n name: string;\n /** Callback invoked when the input value is cleared */\n onClear?: () => void;\n /** Sets the placeholder text */\n placeholder?: string;\n /** Prevents changes while keeping the input focusable and its value in validation and submission */\n readOnly?: boolean;\n /** Redacts the value from Uniform debug output; password inputs are always redacted */\n sensitive?: boolean;\n /** Sets the input size */\n size?: 'sm' | 'md' | 'lg';\n /** Displays content at the start of the input */\n startContent?: ReactNode;\n /** Sets the HTML data-testid attribute for e2e tests */\n testId?: string;\n /** Converts between display and form values */\n transform?: InputValueTransform<string>;\n /** Sets the input type */\n type?: 'number' | 'password';\n}\n\n/**\n * Input component based on [HeroUI Input](https://www.heroui.com//docs/components/input)\n */\nconst Input = ({\n className: _className = undefined,\n clearable = false,\n debounceDelay = 300,\n endContent = undefined,\n name,\n onClear = undefined,\n placeholder = ' ',\n hidePasswordToggle = false,\n size = undefined,\n startContent = undefined,\n type = undefined,\n ...uniformFieldProps\n}: InputProps) => {\n const {\n ariaLabel,\n disabled,\n field: {\n onChange: fieldOnChange,\n onBlur: fieldOnBlur,\n value: fieldValue,\n ref,\n },\n errorMessage,\n invalid,\n label,\n readOnly,\n required,\n testId,\n resetField,\n } = useUniformField({ name, type, ...uniformFieldProps });\n\n // Use hook that provides debounced onChange and enhanced blur handling\n const { onChange, onBlur, value } = useInputValueDebounce({\n debounceDelay,\n name,\n onBlur: fieldOnBlur,\n onChange: fieldOnChange,\n value: fieldValue,\n });\n\n const clearValue = () => {\n // Clear initial values too, rather than restoring the default value.\n resetField(name, { defaultValue: null });\n onClear?.();\n };\n\n // Read-only inputs keep their value, so they never offer clearing.\n const isClearable = clearable && !readOnly;\n const clearableProps: Pick<HeroInputProps, 'isClearable' | 'onClear'> =\n isClearable ? { isClearable: true, onClear: clearValue } : {};\n\n const variants = inputVariants({ readOnly });\n const classNames = variantsToClassNames(variants, _className, 'base');\n\n // Common props for both Input and NumberInput\n const commonProps = {\n ref,\n // Only add aria-label if there's no meaningful placeholder (HeroUI uses placeholder as aria-label)\n 'aria-label':\n !placeholder || placeholder.trim() === '' ? ariaLabel : undefined,\n // disable autocomplete\n autoComplete: 'off',\n classNames: {\n base: classNames.base,\n clearButton: classNames.clearButton,\n // set padding to 0 for error message exit animation\n helperWrapper: 'p-0',\n input: classNames.input,\n inputWrapper: classNames.inputWrapper,\n },\n 'data-testid': testId,\n endContent,\n errorMessage,\n id: testId,\n isDisabled: disabled,\n isInvalid: invalid,\n isReadOnly: readOnly,\n isRequired: required,\n label,\n labelPlacement: 'outside' as const,\n name,\n onBlur,\n placeholder,\n radius: 'sm' as const,\n size,\n startContent,\n variant: 'bordered' as const,\n };\n\n // Render NumberInput for number type\n if (type === 'number') {\n // Parse the string value to number - use null for empty/cleared state to keep component controlled\n const numberValue =\n value !== '' && value != null && !Number.isNaN(Number(value))\n ? Number(value)\n : null;\n\n return (\n <HeroNumberInput\n {...commonProps}\n {...clearableProps}\n // Disable thousands separator to avoid parsing issues\n formatOptions={{\n useGrouping: false,\n }}\n // NumberInput onChange receives either an event or a number\n onChange={(e: React.ChangeEvent<HTMLInputElement> | number) => {\n if (typeof e === 'number') {\n // Convert number to synthetic event and pass through debounced onChange\n onChange({\n target: { value: String(e) },\n });\n } else {\n // Pass event through debounced onChange\n onChange(e);\n }\n }}\n // @ts-expect-error - HeroUI NumberInput type is not compatible with null,\n // but it needs to be for empty/cleared state to be controlled\n value={numberValue}\n />\n );\n }\n\n if (type === 'password') {\n return (\n <InputPassword\n {...commonProps}\n clearable={isClearable}\n hidePasswordToggle={hidePasswordToggle}\n onChange={onChange}\n onClear={clearValue}\n testId={testId}\n value={value}\n />\n );\n }\n\n return (\n <HeroInput\n {...commonProps}\n {...clearableProps}\n onChange={onChange}\n type={type}\n value={value}\n />\n );\n};\n\nexport default Input;\n","import Input from './Input';\n\nexport type { InputProps } from './Input';\n\nexport default Input;\n"],"mappings":";;;;;;;;;;;AAwBA,MAAM,gBAAgB,YAElB,EACE,aAAa,KAAA,GACb,WACA,aAAa,KAAA,GACb,aAAa,OACb,MACA,SACA,YAAY,KAAA,GACZ,oBACA,QACA,OACA,GAAG,cAEL,QACG;CACH,MAAM,CAAC,mBAAmB,wBAAwB,SAAS,KAAK;CAIhE,MAAM,CAAC,uBAAuB,4BAA4B,SAAS;EACjE;EACA;CACF,CAAC;CACD,IACE,sBAAsB,SAAS,QAC/B,sBAAsB,uBAAuB,oBAC7C;EACA,yBAAyB;GAAE;GAAM;EAAmB,CAAC;EACrD,qBAAqB,KAAK;CAC5B;CACA,kBAAkB,EAChB,eAAe;EACb,qBAAqB,KAAK;CAC5B,EACF,CAAC;CAED,MAAM,mBAAmB;EACvB,QAAQ;EACR,qBAAqB,KAAK;CAC5B;CAIA,MAAM,qBAAqB,CAAC,qBAC1B,qBAAC,QAAD;EAAM,WAAU;EAAhB,UAAA;GACG;GACA,aAAa,CAAC,CAAC,QACd,oBAAC,UAAD;IACE,cAAW;IACX,WAAW,GACT,8FACA,YAAY,WACd;IACA,UAAU;IACV,SAAS;IACT,cAAc,UAAU;KACtB,MAAM,eAAe;IACvB;IACA,MAAK;IAEL,UAAA,oBAAC,SAAD,EAAS,eAAY,OAAQ,CAAA;GACvB,CAAA,IACN;GACJ,oBAAC,UAAD;IACE,iBAAe;IACf,cAAY,oBAAoB,kBAAkB;IAClD,gBAAc;IACd,WAAU;IACV,eAAa,GAAG,OAAO;IACvB,UAAU;IACV,eAAe;KACb,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