@fuf-stack/uniform 1.28.0 → 2.0.0-next.1

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.
Files changed (148) hide show
  1. package/README.md +6 -35
  2. package/dist/Checkboxes/index.d.mts +192 -263
  3. package/dist/Checkboxes/index.d.mts.map +1 -1
  4. package/dist/Checkboxes/index.mjs +294 -90
  5. package/dist/Checkboxes/index.mjs.map +1 -1
  6. package/dist/DatePicker/index.d.mts +1278 -496
  7. package/dist/DatePicker/index.d.mts.map +1 -1
  8. package/dist/DatePicker/index.mjs +403 -83
  9. package/dist/DatePicker/index.mjs.map +1 -1
  10. package/dist/FieldArray/index.d.mts +105 -98
  11. package/dist/FieldArray/index.d.mts.map +1 -1
  12. package/dist/FieldArray/index.mjs +344 -195
  13. package/dist/FieldArray/index.mjs.map +1 -1
  14. package/dist/FieldCard/index.d.mts +37 -35
  15. package/dist/FieldCard/index.d.mts.map +1 -1
  16. package/dist/FieldCard/index.mjs +187 -128
  17. package/dist/FieldCard/index.mjs.map +1 -1
  18. package/dist/{FieldCopyTestIdButton-9xTF-DBW.mjs → FieldCopyTestIdButton-DV0tkdh2.mjs} +4 -2
  19. package/dist/FieldCopyTestIdButton-DV0tkdh2.mjs.map +1 -0
  20. package/dist/FieldDescription-C4l0HKGL.mjs +36 -0
  21. package/dist/FieldDescription-C4l0HKGL.mjs.map +1 -0
  22. package/dist/FieldLabel-DKzqkuY1.mjs +125 -0
  23. package/dist/FieldLabel-DKzqkuY1.mjs.map +1 -0
  24. package/dist/FieldLayout-BLW5S-Jm.mjs +46 -0
  25. package/dist/FieldLayout-BLW5S-Jm.mjs.map +1 -0
  26. package/dist/FieldValidationError-DgkCL3cC.mjs +77 -0
  27. package/dist/FieldValidationError-DgkCL3cC.mjs.map +1 -0
  28. package/dist/Form/index.d.mts +12 -12
  29. package/dist/Form/index.d.mts.map +1 -1
  30. package/dist/Form/index.mjs +9 -7
  31. package/dist/Form/index.mjs.map +1 -1
  32. package/dist/{FormContext-CB7Glm02.mjs → FormContext-CHctWFAP.mjs} +51 -8
  33. package/dist/FormContext-CHctWFAP.mjs.map +1 -0
  34. package/dist/FormContext-CsFiNvuJ.d.mts.map +1 -1
  35. package/dist/Grid/index.mjs +1 -2
  36. package/dist/{Grid-CTs-Rb9G.mjs → Grid-DfcZeuib.mjs} +4 -2
  37. package/dist/Grid-DfcZeuib.mjs.map +1 -0
  38. package/dist/Input/index.d.mts +638 -394
  39. package/dist/Input/index.d.mts.map +1 -1
  40. package/dist/Input/index.mjs +414 -165
  41. package/dist/Input/index.mjs.map +1 -1
  42. package/dist/RadioBoxes/index.d.mts +1588 -125
  43. package/dist/RadioBoxes/index.d.mts.map +1 -1
  44. package/dist/RadioBoxes/index.mjs +159 -114
  45. package/dist/RadioBoxes/index.mjs.map +1 -1
  46. package/dist/RadioTabs/index.d.mts +300 -81
  47. package/dist/RadioTabs/index.d.mts.map +1 -1
  48. package/dist/RadioTabs/index.mjs +277 -86
  49. package/dist/RadioTabs/index.mjs.map +1 -1
  50. package/dist/Radios/index.d.mts +1354 -109
  51. package/dist/Radios/index.d.mts.map +1 -1
  52. package/dist/Radios/index.mjs +105 -54
  53. package/dist/Radios/index.mjs.map +1 -1
  54. package/dist/Select/index.d.mts +554 -3009
  55. package/dist/Select/index.d.mts.map +1 -1
  56. package/dist/Select/index.mjs +319 -177
  57. package/dist/Select/index.mjs.map +1 -1
  58. package/dist/Slider/index.d.mts +416 -1328
  59. package/dist/Slider/index.d.mts.map +1 -1
  60. package/dist/Slider/index.mjs +276 -94
  61. package/dist/Slider/index.mjs.map +1 -1
  62. package/dist/SubmitButton/index.d.mts.map +1 -1
  63. package/dist/SubmitButton/index.mjs +4 -1
  64. package/dist/SubmitButton/index.mjs.map +1 -1
  65. package/dist/Switch/index.d.mts +2 -1248
  66. package/dist/Switch/index.mjs +167 -68
  67. package/dist/Switch/index.mjs.map +1 -1
  68. package/dist/Switch-CvPO8IF9.d.mts +601 -0
  69. package/dist/Switch-CvPO8IF9.d.mts.map +1 -0
  70. package/dist/SwitchBox/index.d.mts +135 -39
  71. package/dist/SwitchBox/index.d.mts.map +1 -1
  72. package/dist/SwitchBox/index.mjs +142 -87
  73. package/dist/SwitchBox/index.mjs.map +1 -1
  74. package/dist/TextArea/index.d.mts +295 -411
  75. package/dist/TextArea/index.d.mts.map +1 -1
  76. package/dist/TextArea/index.mjs +200 -48
  77. package/dist/TextArea/index.mjs.map +1 -1
  78. package/dist/Time/index.d.mts +1170 -601
  79. package/dist/Time/index.d.mts.map +1 -1
  80. package/dist/Time/index.mjs +162 -74
  81. package/dist/Time/index.mjs.map +1 -1
  82. package/dist/helpers/index.d.mts +1 -1
  83. package/dist/helpers/index.mjs +1 -1
  84. package/dist/helpers/index.mjs.map +1 -1
  85. package/dist/hooks/useClientValidation/index.mjs +1 -1
  86. package/dist/hooks/useController/index.d.mts +31 -3
  87. package/dist/hooks/useController/index.d.mts.map +1 -0
  88. package/dist/hooks/useController/index.mjs +1 -2
  89. package/dist/hooks/useFormContext/index.d.mts +65 -3
  90. package/dist/hooks/useFormContext/index.d.mts.map +1 -0
  91. package/dist/hooks/useFormContext/index.mjs +1 -2
  92. package/dist/hooks/useInputValueDebounce/index.d.mts +11 -5
  93. package/dist/hooks/useInputValueDebounce/index.d.mts.map +1 -1
  94. package/dist/hooks/useInputValueDebounce/index.mjs +27 -5
  95. package/dist/hooks/useInputValueDebounce/index.mjs.map +1 -1
  96. package/dist/hooks/useInputValueTransform/index.d.mts +1 -2
  97. package/dist/hooks/useInputValueTransform/index.mjs +1 -2
  98. package/dist/hooks/useWatchFormReset/index.mjs +1 -1
  99. package/dist/hooks/useWatchUserChange/index.d.mts +2 -2
  100. package/dist/hooks/useWatchUserChange/index.d.mts.map +1 -1
  101. package/dist/hooks/useWatchUserChange/index.mjs +1 -1
  102. package/dist/hooks/useWatchUserChange/index.mjs.map +1 -1
  103. package/dist/{useInputValueTransform-LOaEim7k.d.mts → index-BS8IoBOn.d.mts} +3 -3
  104. package/dist/index-BS8IoBOn.d.mts.map +1 -0
  105. package/dist/partials/FieldCopyTestIdButton/index.mjs +1 -2
  106. package/dist/partials/FieldValidationError/index.d.mts +637 -3
  107. package/dist/partials/FieldValidationError/index.d.mts.map +1 -1
  108. package/dist/partials/FieldValidationError/index.mjs +1 -2
  109. package/dist/radioControlVariants-Cm6WufWo.mjs +188 -0
  110. package/dist/radioControlVariants-Cm6WufWo.mjs.map +1 -0
  111. package/dist/switchVariants-BaQw2DA7.mjs +67 -0
  112. package/dist/switchVariants-BaQw2DA7.mjs.map +1 -0
  113. package/dist/timeVariants-B9HDfNYt.mjs +58 -0
  114. package/dist/timeVariants-B9HDfNYt.mjs.map +1 -0
  115. package/dist/{useController-BBSbeKbn.mjs → useController-BCFeZbBZ.mjs} +2 -2
  116. package/dist/{useController-BBSbeKbn.mjs.map → useController-BCFeZbBZ.mjs.map} +1 -1
  117. package/dist/{useFormContext-DNb_B8LQ.mjs → useFormContext-BPjJjNnM.mjs} +2 -2
  118. package/dist/{useFormContext-DNb_B8LQ.mjs.map → useFormContext-BPjJjNnM.mjs.map} +1 -1
  119. package/dist/{useInputValueTransform-DJ5zkqSy.mjs → useInputValueTransform-Mw8YEOXT.mjs} +2 -2
  120. package/dist/{useInputValueTransform-DJ5zkqSy.mjs.map → useInputValueTransform-Mw8YEOXT.mjs.map} +1 -1
  121. package/package.json +17 -29
  122. package/dist/FieldCopyTestIdButton-9xTF-DBW.mjs.map +0 -1
  123. package/dist/FieldValidationError-ByRoIxaM.mjs +0 -50
  124. package/dist/FieldValidationError-ByRoIxaM.mjs.map +0 -1
  125. package/dist/FormContext-CB7Glm02.mjs.map +0 -1
  126. package/dist/Grid-CTs-Rb9G.mjs.map +0 -1
  127. package/dist/Switch/index.d.mts.map +0 -1
  128. package/dist/hooks/useInput/index.d.mts +0 -2
  129. package/dist/hooks/useInput/index.mjs +0 -7
  130. package/dist/hooks/useInput/index.mjs.map +0 -1
  131. package/dist/hooks/useUniformField/index.d.mts +0 -100
  132. package/dist/hooks/useUniformField/index.d.mts.map +0 -1
  133. package/dist/hooks/useUniformField/index.mjs +0 -139
  134. package/dist/hooks/useUniformField/index.mjs.map +0 -1
  135. package/dist/hooks/useUniformFieldArray/index.d.mts +0 -73
  136. package/dist/hooks/useUniformFieldArray/index.d.mts.map +0 -1
  137. package/dist/hooks/useUniformFieldArray/index.mjs +0 -101
  138. package/dist/hooks/useUniformFieldArray/index.mjs.map +0 -1
  139. package/dist/index-CAdGtKE_.d.mts +0 -1
  140. package/dist/index-CaxrMD1A.d.mts +0 -1
  141. package/dist/index-CwJo1b4Z.d.mts +0 -1
  142. package/dist/useController-DcK2YHbw.d.mts +0 -32
  143. package/dist/useController-DcK2YHbw.d.mts.map +0 -1
  144. package/dist/useFormContext-BegmYvGA.d.mts +0 -66
  145. package/dist/useFormContext-BegmYvGA.d.mts.map +0 -1
  146. package/dist/useInput-C0aJaAGe.mjs +0 -2
  147. package/dist/useInput-ClpHDPdr.d.mts +0 -2
  148. package/dist/useInputValueTransform-LOaEim7k.d.mts.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.mts","names":[],"sources":["../../src/Input/Input.tsx"],"mappings":";;;;cAea,iBAAa;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;KAarB,eAAe,eAAe;KAC9B,YAAY,mBAAmB;UAEnB,mBAAmB;;EAElC;;EAEA,YAAY;;EAEZ;;EAEA;;EAEA;;EAEA,aAAa;;EAEb,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"}
1
+ {"version":3,"file":"index.d.mts","names":[],"sources":["../../src/Input/inputVariants.ts","../../src/Input/Input.tsx"],"mappings":";;;;;qBAKa,iBAAa;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;KAsGd,YAAY,mBAAmB;;;UCjG1B;;EAEf;;EAEA,YAAY;;EAEZ;;EAEA;;EAEA,cAAc;;EAEd;;EAEA,aAAa;;EAEb;;EAEA,QAAQ;;EAER;;EAEA;;EAEA;;EAEA;;EAEA;;EAEA,eAAe;;EAEf;;EAEA,YAAY;;EAEZ;;;cAII,UAAS,WAAA,WAAA,eAAA,YAAA,cAAA,MAAA,MAAA,oBAAA,MAAA,SAAA,gBAAA,gBAaZ,+BAAU,IAAA"}
@@ -1,193 +1,442 @@
1
- import { useUniformField } from "../hooks/useUniformField/index.mjs";
2
- import { useWatchFormReset } from "../hooks/useWatchFormReset/index.mjs";
1
+ import { n as useUniformField } from "../FieldLabel-DKzqkuY1.mjs";
2
+ import { n as getFieldControlProps, r as getFieldDataAttributes } from "../FieldDescription-C4l0HKGL.mjs";
3
+ import { t as FieldLayout } from "../FieldLayout-BLW5S-Jm.mjs";
3
4
  import { useInputValueDebounce } from "../hooks/useInputValueDebounce/index.mjs";
4
- import { cn, tv, variantsToClassNames } from "@fuf-stack/pixel-utils";
5
- import { forwardRef, useState } from "react";
5
+ import { useEffect, useState } from "react";
6
6
  import { jsx, jsxs } from "react/jsx-runtime";
7
- import { FaEye, FaEyeSlash, FaXmark } from "react-icons/fa6";
8
- import { Input } from "@heroui/input";
9
- import { NumberInput } from "@heroui/number-input";
10
- //#region src/Input/InputPassword.tsx
11
- /** Keeps password presentation separate from form registration and validation. */
12
- const InputPassword = forwardRef(({ classNames = void 0, clearable, endContent = void 0, isDisabled = false, name, onClear, onKeyDown = void 0, hidePasswordToggle, testId, value, ...inputProps }, ref) => {
13
- const [isPasswordVisible, setIsPasswordVisible] = useState(false);
14
- const [previousPasswordField, setPreviousPasswordField] = useState({
7
+ import { tv } from "@fuf-stack/pixel-utils";
8
+ import { FaEye, FaEyeSlash } from "react-icons/fa6";
9
+ import { useStyling } from "@fuf-stack/pixels/StylingProvider";
10
+ import { Button, Group, Input, NumberField, TextField } from "react-aria-components";
11
+ import { useFocusRing } from "react-aria/useFocusRing";
12
+ import { useObjectRef } from "react-aria/useObjectRef";
13
+ //#region src/Input/inputVariants.ts
14
+ /** Default styles for all public Input slots */
15
+ const inputVariants = tv({
16
+ slots: {
17
+ /** Container grouping the label, control and hints */
18
+ base: "group relative flex w-full flex-col",
19
+ /** Button for clearing the current value */
20
+ clearButton: ["absolute end-3 z-10 -m-2 cursor-pointer rounded-full p-2 text-large opacity-70 outline-none", "hover:opacity-100 focus-visible:outline-2 focus-visible:outline-focus"],
21
+ /** Supporting text below the input */
22
+ description: "text-tiny text-foreground-500",
23
+ /** Container for validation messages */
24
+ errorMessage: "text-tiny text-danger",
25
+ /** Container for help text and validation messages */
26
+ helperWrapper: "relative flex flex-col p-0",
27
+ /** Row containing the input, addons and actions */
28
+ innerWrapper: "inline-flex h-full w-full items-center gap-0",
29
+ /** Native input for text or numeric entry */
30
+ input: [
31
+ "w-full min-w-0 bg-transparent bg-clip-text text-small font-normal text-inherit outline-none",
32
+ "placeholder:text-foreground-500 autofill:bg-transparent",
33
+ "data-[has-end-content=true]:pe-1.5 data-[has-start-content=true]:ps-1.5",
34
+ "dark:autofill:[-webkit-text-fill-color:var(--pixel-color-foreground)] [&::-ms-reveal]:hidden"
35
+ ],
36
+ /** Bordered container around the editable area */
37
+ inputWrapper: [
38
+ "relative inline-flex h-10 min-h-10 w-full cursor-text items-center shadow-xs",
39
+ "rounded-small border-medium border-default-200 bg-content1 px-3 text-foreground",
40
+ "transition-colors",
41
+ "group-data-[disabled=true]:pointer-events-none group-data-[focus=true]:border-focus group-data-[invalid=true]:border-danger data-[hovered=true]:border-default-400 group-data-[focus=true]:data-[hovered=true]:border-default-foreground",
42
+ "motion-reduce:transition-none"
43
+ ],
44
+ /** Label above the input */
45
+ label: "block cursor-default pb-1 text-small text-foreground group-data-[invalid=true]:text-danger",
46
+ /** Button for revealing or masking a password */
47
+ passwordToggle: "shrink-0 rounded-sm p-1 text-default-400 outline-none focus-visible:ring-2 focus-visible:ring-focus",
48
+ /** Container grouping increment and decrement buttons */
49
+ stepper: "flex h-full flex-col justify-center ps-1",
50
+ /** Buttons for increasing or decreasing the numeric value */
51
+ stepperButton: ["flex h-3 w-3 items-center justify-center text-default-foreground outline-none", "hover:opacity-hover focus-visible:outline-2 focus-visible:outline-focus"]
52
+ },
53
+ variants: {
54
+ filled: { true: {
55
+ base: "is-filled",
56
+ input: "is-filled",
57
+ inputWrapper: "is-filled"
58
+ } },
59
+ number: { true: { clearButton: "relative" } },
60
+ password: { true: {
61
+ clearButton: "relative end-auto m-0 p-1",
62
+ innerWrapper: "gap-2"
63
+ } },
64
+ clearable: { true: { input: "pe-6" } },
65
+ size: {
66
+ lg: {
67
+ input: "text-medium",
68
+ inputWrapper: "h-12 min-h-12",
69
+ label: "text-medium"
70
+ },
71
+ md: {},
72
+ sm: {
73
+ clearButton: "text-medium",
74
+ input: "text-small",
75
+ inputWrapper: "h-8 min-h-8 px-2",
76
+ label: "text-tiny"
77
+ }
78
+ },
79
+ disabled: { true: { base: "pointer-events-none opacity-disabled" } },
80
+ invalid: { true: {
81
+ input: "text-danger",
82
+ inputWrapper: "border-danger group-data-[focus=true]:border-danger data-[hovered=true]:border-danger group-data-[focus=true]:data-[hovered=true]:border-danger",
83
+ label: "text-danger"
84
+ } }
85
+ }
86
+ });
87
+ //#endregion
88
+ //#region src/Input/subcomponents/InputField.tsx
89
+ /**
90
+ * React Aria field root for text, password and number inputs.
91
+ *
92
+ * Provides TextField or NumberField context to the editable content and actions,
93
+ * forwards validation/accessibility state, and adapts numeric values to the
94
+ * binding's string display values. Preserves Uniform's root styling selectors.
95
+ *
96
+ * @see https://react-aria.adobe.com/TextField
97
+ * @see https://react-aria.adobe.com/NumberField
98
+ */
99
+ const InputField = ({ field, type, children, className = void 0, focused, hasValue, isFocusVisible }) => {
100
+ const { disabled, invalid, name, onBlur, onChange: onValueChange, required, value } = field;
101
+ const controlProps = getFieldControlProps(field);
102
+ const dataAttributes = getFieldDataAttributes(field);
103
+ const rootProps = {
104
+ ...controlProps,
105
+ ...dataAttributes,
106
+ className,
107
+ "data-component": "input",
108
+ "data-filled": hasValue || void 0,
109
+ "data-focus": focused || void 0,
110
+ "data-focus-visible": isFocusVisible || void 0,
111
+ "data-slot": "base",
112
+ isDisabled: disabled,
113
+ isInvalid: invalid,
114
+ isRequired: required,
15
115
  name,
16
- hidePasswordToggle
17
- });
18
- if (previousPasswordField.name !== name || previousPasswordField.hidePasswordToggle !== hidePasswordToggle) {
19
- setPreviousPasswordField({
20
- name,
21
- hidePasswordToggle
116
+ onBlur,
117
+ validationBehavior: "aria"
118
+ };
119
+ const handleNumberChange = (next) => {
120
+ onValueChange(Number.isNaN(next) ? "" : String(next));
121
+ };
122
+ if (type === "number") {
123
+ const numericValue = value !== "" && value != null ? Number(value) : NaN;
124
+ return /* @__PURE__ */ jsx(NumberField, {
125
+ ...rootProps,
126
+ formatOptions: { useGrouping: false },
127
+ onChange: handleNumberChange,
128
+ value: numericValue,
129
+ children
22
130
  });
23
- setIsPasswordVisible(false);
24
131
  }
25
- useWatchFormReset({ onReset: () => {
26
- setIsPasswordVisible(false);
27
- } });
28
- const clearValue = () => {
29
- onClear();
30
- setIsPasswordVisible(false);
31
- };
32
- const passwordEndContent = !hidePasswordToggle ? /* @__PURE__ */ jsxs("span", {
33
- className: "inline-flex shrink-0 items-center gap-2",
34
- children: [
35
- endContent,
36
- clearable && !!value ? /* @__PURE__ */ jsx("button", {
37
- "aria-label": "clear input",
38
- className: cn("rounded-sm p-1 text-default-400 outline-none focus-visible:ring-2 focus-visible:ring-focus", classNames?.clearButton),
39
- disabled: isDisabled,
40
- onClick: clearValue,
41
- onMouseDown: (event) => {
42
- event.preventDefault();
43
- },
44
- type: "button",
45
- children: /* @__PURE__ */ jsx(FaXmark, { "aria-hidden": "true" })
46
- }) : null,
47
- /* @__PURE__ */ jsx("button", {
48
- "aria-controls": testId,
49
- "aria-label": isPasswordVisible ? "Hide password" : "Show password",
50
- "aria-pressed": isPasswordVisible,
51
- className: "rounded-sm p-1 text-default-400 outline-none focus-visible:ring-2 focus-visible:ring-focus",
52
- "data-testid": `${testId}_password_toggle`,
53
- disabled: isDisabled,
54
- onClick: () => {
55
- setIsPasswordVisible((visible) => {
56
- return !visible;
57
- });
58
- },
59
- onMouseDown: (event) => {
60
- event.preventDefault();
61
- },
62
- type: "button",
63
- children: isPasswordVisible ? /* @__PURE__ */ jsx(FaEyeSlash, { "aria-hidden": "true" }) : /* @__PURE__ */ jsx(FaEye, { "aria-hidden": "true" })
132
+ return /* @__PURE__ */ jsx(TextField, {
133
+ ...rootProps,
134
+ onChange: onValueChange,
135
+ type: type ?? "text",
136
+ value: String(value ?? ""),
137
+ children
138
+ });
139
+ };
140
+ //#endregion
141
+ //#region src/Input/subcomponents/InputClearButton.tsx
142
+ /**
143
+ * React Aria Button that invokes the supplied clear action without taking focus.
144
+ *
145
+ * Uses slot=null to opt out of NumberField's increment/decrement button context.
146
+ * Renders custom end content when supplied, otherwise the default clear icon.
147
+ *
148
+ * @see https://react-aria.adobe.com/Button
149
+ * @see https://react-aria.adobe.com/NumberField
150
+ */
151
+ const InputClearButton = ({ children = void 0, className, disabled = void 0, onClear }) => {
152
+ return /* @__PURE__ */ jsx(Button, {
153
+ "aria-label": "clear input",
154
+ className,
155
+ "data-slot": "clear-button",
156
+ isDisabled: disabled,
157
+ onPress: onClear,
158
+ preventFocusOnPress: true,
159
+ slot: null,
160
+ children: children ?? /* @__PURE__ */ jsx("svg", {
161
+ "aria-hidden": true,
162
+ height: "1em",
163
+ viewBox: "0 0 24 24",
164
+ width: "1em",
165
+ children: /* @__PURE__ */ jsx("path", {
166
+ d: "M12 2a10 10 0 1010 10A10.016 10.016 0 0012 2zm3.36 12.3a.754.754 0 010 1.06.748.748 0 01-1.06 0l-2.3-2.3-2.3 2.3a.748.748 0 01-1.06 0 .754.754 0 010-1.06l2.3-2.3-2.3-2.3A.75.75 0 019.7 8.64l2.3 2.3 2.3-2.3a.75.75 0 011.06 1.06l-2.3 2.3z",
167
+ fill: "currentColor"
64
168
  })
65
- ]
66
- }) : endContent;
67
- const clearableProps = clearable && hidePasswordToggle ? {
68
- isClearable: true,
69
- onClear: clearValue
70
- } : {};
71
- return /* @__PURE__ */ jsx(Input, {
72
- ...inputProps,
73
- ...clearableProps,
74
- ref,
75
- classNames,
76
- endContent: passwordEndContent,
77
- isDisabled,
78
- name,
79
- onKeyDown: !hidePasswordToggle && clearable ? (event) => {
80
- onKeyDown?.(event);
81
- if (!event.defaultPrevented && event.key === "Escape" && value && !isDisabled) {
82
- event.preventDefault();
83
- clearValue();
84
- }
85
- } : onKeyDown,
86
- type: !hidePasswordToggle && isPasswordVisible ? "text" : "password",
87
- value
169
+ })
88
170
  });
89
- });
90
- InputPassword.displayName = "InputPassword";
171
+ };
91
172
  //#endregion
92
- //#region src/Input/Input.tsx
93
- const inputVariants = tv({ 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
- } });
173
+ //#region src/Input/subcomponents/InputPasswordToggle.tsx
103
174
  /**
104
- * Input component based on [HeroUI Input](https://www.heroui.com//docs/components/input)
175
+ * Password visibility action preserving input focus on pointer activation
176
+ *
177
+ * @see https://react-aria.adobe.com/Button
105
178
  */
106
- 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 }) => {
107
- const { ariaLabel, disabled, field: { onChange: fieldOnChange, onBlur: fieldOnBlur, value: fieldValue, ref }, errorMessage, invalid, label, required, testId, resetField } = useUniformField({
108
- name,
109
- type,
110
- ...uniformFieldProps
179
+ const InputPasswordToggle = ({ className, controlId, disabled = false, onToggle, testId, visible }) => {
180
+ return /* @__PURE__ */ jsx(Button, {
181
+ "aria-controls": controlId,
182
+ "aria-label": visible ? "Hide password" : "Show password",
183
+ "aria-pressed": visible,
184
+ className,
185
+ "data-testid": `${testId}_password_toggle`,
186
+ isDisabled: disabled,
187
+ onPress: onToggle,
188
+ preventFocusOnPress: true,
189
+ slot: null,
190
+ type: "button",
191
+ children: visible ? /* @__PURE__ */ jsx(FaEyeSlash, { "aria-hidden": "true" }) : /* @__PURE__ */ jsx(FaEye, { "aria-hidden": "true" })
111
192
  });
112
- const { onChange, onBlur, value } = useInputValueDebounce({
113
- debounceDelay,
114
- name,
115
- onBlur: fieldOnBlur,
116
- onChange: fieldOnChange,
117
- value: fieldValue
193
+ };
194
+ //#endregion
195
+ //#region src/Input/subcomponents/InputStepper.tsx
196
+ /** Decorative direction indicator for the number stepper buttons. */
197
+ const Chevron = ({ up = false }) => {
198
+ return /* @__PURE__ */ jsx("svg", {
199
+ "aria-hidden": true,
200
+ fill: "none",
201
+ height: "1em",
202
+ stroke: "currentColor",
203
+ strokeLinecap: "round",
204
+ strokeLinejoin: "round",
205
+ strokeWidth: "1.5",
206
+ viewBox: "0 0 24 24",
207
+ width: "1em",
208
+ children: /* @__PURE__ */ jsx("path", { d: up ? "m18 15-6-6-6 6" : "m6 9 6 6 6-6" })
209
+ });
210
+ };
211
+ /**
212
+ * Increment and decrement React Aria Buttons for the surrounding NumberField.
213
+ *
214
+ * Named slots connect each button to NumberField's value and disabled state.
215
+ * Keeps the controls outside the tab order so keyboard editing stays in the input.
216
+ *
217
+ * @see https://react-aria.adobe.com/NumberField
218
+ * @see https://react-aria.adobe.com/Button
219
+ */
220
+ const InputStepper = ({ className }) => {
221
+ return /* @__PURE__ */ jsxs("div", {
222
+ className: className.stepper,
223
+ "data-slot": "stepper-wrapper",
224
+ children: [/* @__PURE__ */ jsx(Button, {
225
+ className: className.stepperButton,
226
+ "data-slot": "increase-button",
227
+ slot: "increment",
228
+ children: /* @__PURE__ */ jsx(Chevron, { up: true })
229
+ }), /* @__PURE__ */ jsx(Button, {
230
+ className: className.stepperButton,
231
+ "data-slot": "decrease-button",
232
+ slot: "decrement",
233
+ children: /* @__PURE__ */ jsx(Chevron, {})
234
+ })]
235
+ });
236
+ };
237
+ //#endregion
238
+ //#region src/Input/subcomponents/InputWrapper.tsx
239
+ /**
240
+ * Bordered input surface built from React Aria Group and Input
241
+ *
242
+ * Arranges addons, clear actions and number steppers around the native input,
243
+ * forwards its ref and accessibility attributes, and reports wrapper interactions.
244
+ * The surrounding InputField supplies the TextField or NumberField context.
245
+ *
246
+ * @see https://react-aria.adobe.com/Group
247
+ * @see https://react-aria.adobe.com/TextField (Input composition)
248
+ * @see https://react-aria.adobe.com/NumberField (Input and stepper composition)
249
+ */
250
+ const InputWrapper = ({ field, clearable = false, endContent, hidePasswordToggle, inputRef, onClear, onFocusControl, onTogglePassword, passwordVisible, placeholder, startContent, type, className, focused, focusProps, hasValue }) => {
251
+ const { disabled, onChange: onValueChange, testId } = field;
252
+ const controlProps = getFieldControlProps(field);
253
+ const handleWrapperClick = (event) => {
254
+ if (!disabled && event.currentTarget === event.target) onFocusControl();
255
+ };
256
+ const handleChange = (event) => {
257
+ onValueChange(event.target.value);
258
+ };
259
+ const handleKeyDown = (event) => {
260
+ if (event.key === "Escape" && clearable && hasValue && !disabled) {
261
+ event.preventDefault();
262
+ onClear();
263
+ }
264
+ };
265
+ return /* @__PURE__ */ jsx(Group, {
266
+ ...focusProps,
267
+ className: className.inputWrapper,
268
+ "data-focus": focused || void 0,
269
+ "data-slot": "input-wrapper",
270
+ isDisabled: disabled,
271
+ onClick: handleWrapperClick,
272
+ children: /* @__PURE__ */ jsxs("div", {
273
+ className: className.innerWrapper,
274
+ "data-slot": "inner-wrapper",
275
+ children: [
276
+ startContent,
277
+ /* @__PURE__ */ jsx(Input, {
278
+ ...controlProps,
279
+ ref: inputRef,
280
+ autoComplete: "off",
281
+ className: className.input,
282
+ "data-filled": hasValue || void 0,
283
+ "data-has-end-content": !!endContent || clearable && hasValue || void 0,
284
+ "data-has-start-content": !!startContent || void 0,
285
+ "data-slot": "input",
286
+ "data-testid": testId,
287
+ onChange: type === "number" ? handleChange : void 0,
288
+ onKeyDown: handleKeyDown,
289
+ placeholder
290
+ }),
291
+ type === "password" ? endContent : null,
292
+ clearable && hasValue ? /* @__PURE__ */ jsx(InputClearButton, {
293
+ className: className.clearButton,
294
+ disabled,
295
+ onClear,
296
+ children: type !== "number" && type !== "password" && endContent ? endContent : void 0
297
+ }) : null,
298
+ type !== "password" && (!clearable || type === "number") ? endContent : null,
299
+ type === "password" && !hidePasswordToggle ? /* @__PURE__ */ jsx(InputPasswordToggle, {
300
+ className: className.passwordToggle,
301
+ controlId: field.ids.control,
302
+ disabled,
303
+ onToggle: onTogglePassword,
304
+ testId,
305
+ visible: passwordVisible
306
+ }) : null,
307
+ type === "number" ? /* @__PURE__ */ jsx(InputStepper, { className }) : null
308
+ ]
309
+ })
310
+ });
311
+ };
312
+ //#endregion
313
+ //#region src/Input/subcomponents/InputControl.tsx
314
+ /**
315
+ * Composes the Input presentation without registering a form field.
316
+ *
317
+ * Owns the editable ref, focus restoration and interaction styling.
318
+ * Connects InputField's Aria field root, FieldLayout and the editable content.
319
+ * Values, validation state and callbacks are supplied by the Input binding.
320
+ *
321
+ * @see https://react-aria.adobe.com/useFocusRing
322
+ * @see https://react-aria.adobe.com/TextField
323
+ * @see https://react-aria.adobe.com/NumberField
324
+ */
325
+ const InputControl = (props) => {
326
+ const { field, subscribeReset } = props;
327
+ const styling = useStyling();
328
+ const [passwordVisible, setPasswordVisible] = useState(false);
329
+ useEffect(() => {
330
+ const handleReset = () => {
331
+ setPasswordVisible(false);
332
+ };
333
+ return subscribeReset?.(handleReset);
334
+ }, [subscribeReset]);
335
+ const controlRef = useObjectRef(field.ref);
336
+ const { focusProps, isFocused: focused, isFocusVisible } = useFocusRing({
337
+ isTextInput: true,
338
+ within: true
339
+ });
340
+ const { size, type, clearable, className, hidePasswordToggle, onClear, onReset } = props;
341
+ const displayType = type === "password" && !hidePasswordToggle && passwordVisible ? "text" : type;
342
+ const { value, disabled, invalid, label, required, ids, description, errorMessage } = field;
343
+ const hasValue = value !== "" && value != null;
344
+ const variants = styling.resolve(inputVariants, {
345
+ clearable,
346
+ disabled,
347
+ filled: hasValue,
348
+ invalid,
349
+ number: type === "number",
350
+ password: type === "password",
351
+ size
118
352
  });
119
- const clearValue = () => {
120
- resetField(name, { defaultValue: null });
353
+ const classNames = styling.variantsToClassNames(variants, className, "base");
354
+ const handleFocus = () => {
355
+ controlRef.current?.focus();
356
+ };
357
+ const handleTogglePassword = () => {
358
+ setPasswordVisible((visible) => {
359
+ return !visible;
360
+ });
361
+ };
362
+ const handleClear = () => {
363
+ setPasswordVisible(false);
364
+ onReset();
121
365
  onClear?.();
366
+ handleFocus();
122
367
  };
123
- const clearableProps = clearable ? {
124
- isClearable: true,
125
- onClear: clearValue
126
- } : {};
127
- const variants = inputVariants();
128
- const classNames = variantsToClassNames(variants, _className, "base");
129
- const commonProps = {
130
- ref,
131
- "aria-label": !placeholder || placeholder.trim() === "" ? ariaLabel : void 0,
132
- autoComplete: "off",
133
- classNames: {
134
- base: classNames.base,
135
- clearButton: classNames.clearButton,
136
- helperWrapper: "p-0",
137
- input: classNames.input,
138
- inputWrapper: classNames.inputWrapper
368
+ return /* @__PURE__ */ jsx(FieldLayout, {
369
+ baseAs: InputField,
370
+ baseProps: {
371
+ field,
372
+ focused,
373
+ hasValue,
374
+ isFocusVisible,
375
+ type: displayType
139
376
  },
140
- "data-testid": testId,
141
- endContent,
377
+ className: classNames,
378
+ description,
142
379
  errorMessage,
143
- id: testId,
144
- isDisabled: disabled,
145
- isInvalid: invalid,
146
- isRequired: required,
380
+ ids,
381
+ invalid,
147
382
  label,
148
- labelPlacement: "outside",
383
+ required,
384
+ children: /* @__PURE__ */ jsx(InputWrapper, {
385
+ ...props,
386
+ className: classNames,
387
+ focusProps,
388
+ focused,
389
+ hasValue,
390
+ inputRef: controlRef,
391
+ onClear: handleClear,
392
+ onFocusControl: handleFocus,
393
+ onTogglePassword: handleTogglePassword,
394
+ passwordVisible
395
+ })
396
+ });
397
+ };
398
+ //#endregion
399
+ //#region src/Input/Input.tsx
400
+ /** Form input field for text, passwords or numbers */
401
+ const Input$1 = ({ className = void 0, clearable = false, debounceDelay = 300, endContent = void 0, startContent = void 0, size = "md", type = void 0, hidePasswordToggle = false, name, onClear = void 0, placeholder = " ", ...uniformProps }) => {
402
+ const { field, formReset } = useUniformField({
403
+ ...uniformProps,
149
404
  name,
150
- onBlur,
151
405
  placeholder,
152
- radius: "sm",
153
- size,
154
- startContent,
155
- variant: "bordered"
156
- };
157
- if (type === "number") {
158
- const numberValue = value !== "" && value != null && !Number.isNaN(Number(value)) ? Number(value) : null;
159
- return /* @__PURE__ */ jsx(NumberInput, {
160
- ...commonProps,
161
- ...clearableProps,
162
- formatOptions: { useGrouping: false },
163
- onChange: (e) => {
164
- if (typeof e === "number") onChange({ target: { value: String(e) } });
165
- else onChange(e);
166
- },
167
- value: numberValue
168
- });
169
- }
170
- if (type === "password") return /* @__PURE__ */ jsx(InputPassword, {
171
- ...commonProps,
172
- clearable,
173
- hidePasswordToggle,
174
- onChange,
175
- onClear: clearValue,
176
- testId,
177
- value
406
+ type
178
407
  });
179
- return /* @__PURE__ */ jsx(Input, {
180
- ...commonProps,
181
- ...clearableProps,
182
- onChange,
183
- type,
184
- value
408
+ const { value, onChange, onBlur, clear } = useInputValueDebounce({
409
+ debounceDelay,
410
+ emptyValue: "",
411
+ name,
412
+ onBlur: field.onBlur,
413
+ onChange: field.onChange,
414
+ value: field.value
185
415
  });
416
+ return /* @__PURE__ */ jsx(InputControl, {
417
+ hidePasswordToggle,
418
+ className,
419
+ clearable,
420
+ endContent,
421
+ field: {
422
+ ...field,
423
+ onBlur,
424
+ onChange,
425
+ value
426
+ },
427
+ onClear,
428
+ onReset: clear,
429
+ placeholder,
430
+ size,
431
+ startContent,
432
+ subscribeReset: formReset.subscribe,
433
+ type
434
+ }, `${name}-${type}-${hidePasswordToggle}`);
186
435
  };
187
436
  //#endregion
188
437
  //#region src/Input/index.ts
189
438
  var Input_default = Input$1;
190
439
  //#endregion
191
- export { Input_default as default };
440
+ export { Input_default as default, inputVariants };
192
441
 
193
442
  //# sourceMappingURL=index.mjs.map