@adam-milo/ui 1.0.21 → 1.0.23

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 (40) hide show
  1. package/dist/index14.cjs +1 -1
  2. package/dist/index14.js +1 -1
  3. package/dist/index19.cjs +1 -0
  4. package/dist/index19.js +22 -0
  5. package/dist/index20.cjs +1 -0
  6. package/dist/index20.js +301 -0
  7. package/dist/index21.cjs +1 -0
  8. package/dist/index21.js +16 -0
  9. package/dist/index3.cjs +1 -1
  10. package/dist/index3.js +28 -104
  11. package/dist/index33.cjs +1 -0
  12. package/dist/index33.js +21 -0
  13. package/dist/index4.cjs +1 -1
  14. package/dist/index4.js +15 -178
  15. package/dist/index5.cjs +1 -1
  16. package/dist/index5.js +42 -172
  17. package/dist/index6.cjs +1 -1
  18. package/dist/index6.js +85 -171
  19. package/dist/src/components/forms/alphanumeric-input/AlphanumericInput.component.d.ts +23 -38
  20. package/dist/src/components/forms/alphanumeric-input/AlphanumericInput.component.d.ts.map +1 -1
  21. package/dist/src/components/forms/email-input/EmailInput.component.d.ts +17 -20
  22. package/dist/src/components/forms/email-input/EmailInput.component.d.ts.map +1 -1
  23. package/dist/src/components/forms/input/Input.component.d.ts +105 -0
  24. package/dist/src/components/forms/input/Input.component.d.ts.map +1 -0
  25. package/dist/src/components/forms/numeric-input/NumericInput.component.d.ts +30 -48
  26. package/dist/src/components/forms/numeric-input/NumericInput.component.d.ts.map +1 -1
  27. package/dist/src/components/forms/password-input/PasswordInput.component.d.ts +19 -16
  28. package/dist/src/components/forms/password-input/PasswordInput.component.d.ts.map +1 -1
  29. package/dist/src/lib/debounce.d.ts +12 -0
  30. package/dist/src/lib/debounce.d.ts.map +1 -0
  31. package/dist/src/lib/debounce.spec.d.ts +2 -0
  32. package/dist/src/lib/debounce.spec.d.ts.map +1 -0
  33. package/dist/src/lib/index.d.ts +2 -0
  34. package/dist/src/lib/index.d.ts.map +1 -1
  35. package/dist/src/lib/useMergedRef.d.ts +19 -0
  36. package/dist/src/lib/useMergedRef.d.ts.map +1 -0
  37. package/dist/style.css +1 -1
  38. package/package.json +2 -1
  39. /package/dist/{index31.cjs → index30.cjs} +0 -0
  40. /package/dist/{index31.js → index30.js} +0 -0
package/dist/index4.js CHANGED
@@ -1,182 +1,19 @@
1
- import { jsxs, jsx } from "react/jsx-runtime";
2
- import { forwardRef, useState, useId } from "react";
3
- import { cn } from "./index17.js";
4
- /* empty css */
1
+ import { jsx } from "react/jsx-runtime";
2
+ import { forwardRef } from "react";
3
+ import { Input } from "./index20.js";
5
4
  const PasswordInput = forwardRef(
6
- ({
7
- showToggle = true,
8
- label,
9
- error,
10
- helperText,
11
- fullWidth = false,
12
- className,
13
- id: providedId,
14
- "data-cy": dataCy,
15
- "data-testid": dataTestId,
16
- ...props
17
- }, ref) => {
18
- const [isPasswordVisible, setIsPasswordVisible] = useState(false);
19
- const generatedId = useId();
20
- const id = providedId || generatedId;
21
- const errorId = `${id}-error`;
22
- const helperId = `${id}-helper`;
23
- const finalDataCy = dataCy || "password-input";
24
- const finalTestId = dataTestId || "password-input";
25
- const togglePasswordVisibility = () => {
26
- setIsPasswordVisible((prev) => !prev);
27
- };
28
- return /* @__PURE__ */ jsxs("div", { className: "password-input-wrapper", children: [
29
- /* @__PURE__ */ jsxs(
30
- "div",
31
- {
32
- className: cn("input-wrapper", fullWidth && "input-wrapper--full-width"),
33
- "data-cy": `${finalDataCy}-wrapper`,
34
- "data-testid": `${finalTestId}-wrapper`,
35
- children: [
36
- label && /* @__PURE__ */ jsx(
37
- "label",
38
- {
39
- htmlFor: id,
40
- className: "input__label",
41
- "data-cy": `${finalDataCy}-label`,
42
- "data-testid": `${finalTestId}-label`,
43
- children: label
44
- }
45
- ),
46
- /* @__PURE__ */ jsx(
47
- "input",
48
- {
49
- ref,
50
- id,
51
- type: isPasswordVisible ? "text" : "password",
52
- className: cn(
53
- "input",
54
- "password-input",
55
- error && "input--error",
56
- fullWidth && "input--full-width",
57
- className
58
- ),
59
- "aria-invalid": error ? "true" : "false",
60
- "aria-describedby": error ? errorId : helperText ? helperId : void 0,
61
- "data-cy": finalDataCy,
62
- "data-testid": finalTestId,
63
- ...props
64
- }
65
- ),
66
- error && /* @__PURE__ */ jsx(
67
- "span",
68
- {
69
- id: errorId,
70
- className: "input__error",
71
- role: "alert",
72
- "data-cy": `${finalDataCy}-error`,
73
- "data-testid": `${finalTestId}-error`,
74
- children: error
75
- }
76
- ),
77
- helperText && !error && /* @__PURE__ */ jsx(
78
- "span",
79
- {
80
- id: helperId,
81
- className: "input__helper",
82
- "data-cy": `${finalDataCy}-helper`,
83
- "data-testid": `${finalTestId}-helper`,
84
- children: helperText
85
- }
86
- )
87
- ]
88
- }
89
- ),
90
- showToggle && /* @__PURE__ */ jsx(
91
- "button",
92
- {
93
- type: "button",
94
- className: "password-input__toggle",
95
- onClick: togglePasswordVisibility,
96
- "aria-label": isPasswordVisible ? "Hide password" : "Show password",
97
- "data-cy": `${finalDataCy}-toggle`,
98
- "data-testid": `${finalTestId}-toggle`,
99
- children: isPasswordVisible ? /* @__PURE__ */ jsxs(
100
- "svg",
101
- {
102
- width: "20",
103
- height: "20",
104
- viewBox: "0 0 20 20",
105
- fill: "none",
106
- xmlns: "http://www.w3.org/2000/svg",
107
- "aria-hidden": "true",
108
- children: [
109
- /* @__PURE__ */ jsx(
110
- "path",
111
- {
112
- d: "M10 4C5.5 4 2 10 2 10s3.5 6 8 6 8-6 8-6-3.5-6-8-6z",
113
- stroke: "currentColor",
114
- strokeWidth: "1.5",
115
- strokeLinecap: "round",
116
- strokeLinejoin: "round",
117
- fill: "none"
118
- }
119
- ),
120
- /* @__PURE__ */ jsx(
121
- "circle",
122
- {
123
- cx: "10",
124
- cy: "10",
125
- r: "2.5",
126
- stroke: "currentColor",
127
- strokeWidth: "1.5",
128
- fill: "none"
129
- }
130
- )
131
- ]
132
- }
133
- ) : /* @__PURE__ */ jsxs(
134
- "svg",
135
- {
136
- width: "20",
137
- height: "20",
138
- viewBox: "0 0 20 20",
139
- fill: "none",
140
- xmlns: "http://www.w3.org/2000/svg",
141
- "aria-hidden": "true",
142
- children: [
143
- /* @__PURE__ */ jsx(
144
- "path",
145
- {
146
- d: "M10 4C5.5 4 2 10 2 10s3.5 6 8 6 8-6 8-6-3.5-6-8-6z",
147
- stroke: "currentColor",
148
- strokeWidth: "1.5",
149
- strokeLinecap: "round",
150
- strokeLinejoin: "round",
151
- fill: "none"
152
- }
153
- ),
154
- /* @__PURE__ */ jsx(
155
- "circle",
156
- {
157
- cx: "10",
158
- cy: "10",
159
- r: "2.5",
160
- stroke: "currentColor",
161
- strokeWidth: "1.5",
162
- fill: "none"
163
- }
164
- ),
165
- /* @__PURE__ */ jsx(
166
- "path",
167
- {
168
- d: "M3 3l14 14",
169
- stroke: "currentColor",
170
- strokeWidth: "1.5",
171
- strokeLinecap: "round"
172
- }
173
- )
174
- ]
175
- }
176
- )
177
- }
178
- )
179
- ] });
5
+ ({ showToggle = true, "data-cy": dataCy, "data-testid": dataTestId, ...props }, ref) => {
6
+ return /* @__PURE__ */ jsx(
7
+ Input,
8
+ {
9
+ ref,
10
+ type: "password",
11
+ showPasswordToggle: showToggle,
12
+ "data-cy": dataCy || "password-input",
13
+ "data-testid": dataTestId || "password-input",
14
+ ...props
15
+ }
16
+ );
180
17
  }
181
18
  );
182
19
  PasswordInput.displayName = "PasswordInput";
package/dist/index5.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),r=require("react"),a=require("./index17.cjs");;/* empty css */const t=r.forwardRef(({allowDecimal:t=!1,allowNegative:l=!1,min:i,max:n,decimalPlaces:s=2,invalidNumberMessage:u="Please enter a valid number",minValueMessage:d,maxValueMessage:o,onValidationChange:c,error:p,onChange:m,onKeyDown:v,label:y,helperText:f,fullWidth:h=!1,className:g,id:$,"data-cy":x,"data-testid":b,...w},V)=>{const[N,j]=r.useState(),[D,k]=r.useState(!1),T=r.useId(),_=$||T,M=`${_}-error`,S=`${_}-helper`,q=x||"numeric-input",E=b||"numeric-input",K=e=>{if(!e)return{isValid:!0};if(!new RegExp(`^${l?"-?":""}\\d+${t?`(\\.\\d{0,${s}})?`:""}$`).test(e))return{isValid:!1,error:u};const r=parseFloat(e);return void 0!==i&&r<i?{isValid:!1,error:d||`Value must be at least ${i}`}:void 0!==n&&r>n?{isValid:!1,error:o||`Value must be at most ${n}`}:{isValid:!0}},B=p||N;return e.jsxs("div",{className:a.cn("input-wrapper",h&&"input-wrapper--full-width"),"data-cy":`${q}-wrapper`,"data-testid":`${E}-wrapper`,children:[y&&e.jsx("label",{htmlFor:_,className:"input__label","data-cy":`${q}-label`,"data-testid":`${E}-label`,children:y}),e.jsx("input",{ref:V,id:_,type:"text",inputMode:"numeric",className:a.cn("input",B&&"input--error",h&&"input--full-width",g),"aria-invalid":B?"true":"false","aria-describedby":B?M:f?S:void 0,"data-cy":q,"data-testid":E,onChange:e=>{const r=e.target.value;if(D){const e=K(r);j(e.error),null==c||c(e.isValid)}null==m||m(e)},onBlur:e=>{var r;k(!0);const a=K(e.target.value);j(a.error),null==c||c(a.isValid),null==(r=w.onBlur)||r.call(w,e)},onKeyDown:e=>{if(e.ctrlKey||e.metaKey)null==v||v(e);else if(["Backspace","Delete","Tab","Escape","Enter","ArrowLeft","ArrowRight","Home","End"].includes(e.key))null==v||v(e);else{if(t&&"."===e.key){return e.currentTarget.value.includes(".")?void e.preventDefault():void(null==v||v(e))}if(l&&"-"===e.key){const r=e.currentTarget.value;return 0!==(e.currentTarget.selectionStart||0)||r.includes("-")?void e.preventDefault():void(null==v||v(e))}e.key>="0"&&e.key<="9"?null==v||v(e):e.preventDefault()}},...w}),B&&e.jsx("span",{id:M,className:"input__error",role:"alert","data-cy":`${q}-error`,"data-testid":`${E}-error`,children:B}),f&&!B&&e.jsx("span",{id:S,className:"input__helper","data-cy":`${q}-helper`,"data-testid":`${E}-helper`,children:f})]})});t.displayName="NumericInput",exports.NumericInput=t;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),t=require("react"),a=require("./index20.cjs"),r=t.forwardRef(({min:r,max:i,step:s=1,allowDecimals:u=!1,validate:n,"data-cy":l,"data-testid":c,...d},o)=>{const m=t.useCallback(e=>{if(!e)return;const t=parseFloat(e);return isNaN(t)?"Please enter a valid number":u||Number.isInteger(t)?void 0!==r&&t<r?`Must be at least ${r}`:void 0!==i&&t>i?`Must be at most ${i}`:void 0:"Decimals are not allowed"},[r,i,u]),p=t.useCallback(e=>n?m(e)||n(e):m(e),[m,n]);return e.jsx(a.Input,{ref:o,type:"number",min:r,max:i,validate:p,"data-cy":l||"numeric-input","data-testid":c||"numeric-input",...d,step:u?"any":s})});r.displayName="NumericInput",exports.NumericInput=r;
package/dist/index5.js CHANGED
@@ -1,186 +1,56 @@
1
- import { jsxs, jsx } from "react/jsx-runtime";
2
- import { forwardRef, useState, useId } from "react";
3
- import { cn } from "./index17.js";
4
- /* empty css */
1
+ import { jsx } from "react/jsx-runtime";
2
+ import { forwardRef, useCallback } from "react";
3
+ import { Input } from "./index20.js";
5
4
  const NumericInput = forwardRef(
6
5
  ({
7
- allowDecimal = false,
8
- allowNegative = false,
9
6
  min,
10
7
  max,
11
- decimalPlaces = 2,
12
- invalidNumberMessage = "Please enter a valid number",
13
- minValueMessage,
14
- maxValueMessage,
15
- onValidationChange,
16
- error: externalError,
17
- onChange,
18
- onKeyDown,
19
- label,
20
- helperText,
21
- fullWidth = false,
22
- className,
23
- id: providedId,
8
+ step = 1,
9
+ allowDecimals = false,
10
+ validate,
24
11
  "data-cy": dataCy,
25
12
  "data-testid": dataTestId,
26
13
  ...props
27
14
  }, ref) => {
28
- const [internalError, setInternalError] = useState();
29
- const [touched, setTouched] = useState(false);
30
- const generatedId = useId();
31
- const id = providedId || generatedId;
32
- const errorId = `${id}-error`;
33
- const helperId = `${id}-helper`;
34
- const finalDataCy = dataCy || "numeric-input";
35
- const finalTestId = dataTestId || "numeric-input";
36
- const validateNumber = (value) => {
37
- if (!value) return { isValid: true };
38
- const isNegativeAllowed = allowNegative ? "-?" : "";
39
- const decimalPattern = allowDecimal ? `(\\.\\d{0,${decimalPlaces}})?` : "";
40
- const regex = new RegExp(`^${isNegativeAllowed}\\d+${decimalPattern}$`);
41
- if (!regex.test(value)) {
42
- return { isValid: false, error: invalidNumberMessage };
43
- }
44
- const numValue = parseFloat(value);
45
- if (min !== void 0 && numValue < min) {
46
- return {
47
- isValid: false,
48
- error: minValueMessage || `Value must be at least ${min}`
49
- };
50
- }
51
- if (max !== void 0 && numValue > max) {
52
- return {
53
- isValid: false,
54
- error: maxValueMessage || `Value must be at most ${max}`
55
- };
56
- }
57
- return { isValid: true };
58
- };
59
- const handleKeyDown = (e) => {
60
- const allowedKeys = [
61
- "Backspace",
62
- "Delete",
63
- "Tab",
64
- "Escape",
65
- "Enter",
66
- "ArrowLeft",
67
- "ArrowRight",
68
- "Home",
69
- "End"
70
- ];
71
- if (e.ctrlKey || e.metaKey) {
72
- onKeyDown == null ? void 0 : onKeyDown(e);
73
- return;
74
- }
75
- if (allowedKeys.includes(e.key)) {
76
- onKeyDown == null ? void 0 : onKeyDown(e);
77
- return;
78
- }
79
- if (allowDecimal && e.key === ".") {
80
- const value = e.currentTarget.value;
81
- if (value.includes(".")) {
82
- e.preventDefault();
83
- return;
15
+ const numericValidation = useCallback(
16
+ (value) => {
17
+ if (!value) return void 0;
18
+ const numValue = parseFloat(value);
19
+ if (isNaN(numValue)) {
20
+ return "Please enter a valid number";
84
21
  }
85
- onKeyDown == null ? void 0 : onKeyDown(e);
86
- return;
87
- }
88
- if (allowNegative && e.key === "-") {
89
- const value = e.currentTarget.value;
90
- const selectionStart = e.currentTarget.selectionStart || 0;
91
- if (selectionStart !== 0 || value.includes("-")) {
92
- e.preventDefault();
93
- return;
22
+ if (!allowDecimals && !Number.isInteger(numValue)) {
23
+ return "Decimals are not allowed";
94
24
  }
95
- onKeyDown == null ? void 0 : onKeyDown(e);
96
- return;
97
- }
98
- if (e.key >= "0" && e.key <= "9") {
99
- onKeyDown == null ? void 0 : onKeyDown(e);
100
- return;
101
- }
102
- e.preventDefault();
103
- };
104
- const handleChange = (e) => {
105
- const value = e.target.value;
106
- if (touched) {
107
- const validation = validateNumber(value);
108
- setInternalError(validation.error);
109
- onValidationChange == null ? void 0 : onValidationChange(validation.isValid);
110
- }
111
- onChange == null ? void 0 : onChange(e);
112
- };
113
- const handleBlur = (e) => {
114
- var _a;
115
- setTouched(true);
116
- const validation = validateNumber(e.target.value);
117
- setInternalError(validation.error);
118
- onValidationChange == null ? void 0 : onValidationChange(validation.isValid);
119
- (_a = props.onBlur) == null ? void 0 : _a.call(props, e);
120
- };
121
- const displayError = externalError || internalError;
122
- return /* @__PURE__ */ jsxs(
123
- "div",
25
+ if (min !== void 0 && numValue < min) {
26
+ return `Must be at least ${min}`;
27
+ }
28
+ if (max !== void 0 && numValue > max) {
29
+ return `Must be at most ${max}`;
30
+ }
31
+ return void 0;
32
+ },
33
+ [min, max, allowDecimals]
34
+ );
35
+ const combinedValidation = useCallback(
36
+ (value) => {
37
+ if (!validate) return numericValidation(value);
38
+ return numericValidation(value) || validate(value);
39
+ },
40
+ [numericValidation, validate]
41
+ );
42
+ return /* @__PURE__ */ jsx(
43
+ Input,
124
44
  {
125
- className: cn("input-wrapper", fullWidth && "input-wrapper--full-width"),
126
- "data-cy": `${finalDataCy}-wrapper`,
127
- "data-testid": `${finalTestId}-wrapper`,
128
- children: [
129
- label && /* @__PURE__ */ jsx(
130
- "label",
131
- {
132
- htmlFor: id,
133
- className: "input__label",
134
- "data-cy": `${finalDataCy}-label`,
135
- "data-testid": `${finalTestId}-label`,
136
- children: label
137
- }
138
- ),
139
- /* @__PURE__ */ jsx(
140
- "input",
141
- {
142
- ref,
143
- id,
144
- type: "text",
145
- inputMode: "numeric",
146
- className: cn(
147
- "input",
148
- displayError && "input--error",
149
- fullWidth && "input--full-width",
150
- className
151
- ),
152
- "aria-invalid": displayError ? "true" : "false",
153
- "aria-describedby": displayError ? errorId : helperText ? helperId : void 0,
154
- "data-cy": finalDataCy,
155
- "data-testid": finalTestId,
156
- onChange: handleChange,
157
- onBlur: handleBlur,
158
- onKeyDown: handleKeyDown,
159
- ...props
160
- }
161
- ),
162
- displayError && /* @__PURE__ */ jsx(
163
- "span",
164
- {
165
- id: errorId,
166
- className: "input__error",
167
- role: "alert",
168
- "data-cy": `${finalDataCy}-error`,
169
- "data-testid": `${finalTestId}-error`,
170
- children: displayError
171
- }
172
- ),
173
- helperText && !displayError && /* @__PURE__ */ jsx(
174
- "span",
175
- {
176
- id: helperId,
177
- className: "input__helper",
178
- "data-cy": `${finalDataCy}-helper`,
179
- "data-testid": `${finalTestId}-helper`,
180
- children: helperText
181
- }
182
- )
183
- ]
45
+ ref,
46
+ type: "number",
47
+ min,
48
+ max,
49
+ validate: combinedValidation,
50
+ "data-cy": dataCy || "numeric-input",
51
+ "data-testid": dataTestId || "numeric-input",
52
+ ...props,
53
+ step: allowDecimals ? "any" : step
184
54
  }
185
55
  );
186
56
  }
package/dist/index6.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),a=require("react"),r=require("./index17.cjs");;/* empty css */const t=a.forwardRef(({allowHyphen:t=!1,allowUnderscore:l=!1,allowSpace:n=!1,minLength:s,maxLength:i,invalidFormatMessage:d="Only letters and numbers are allowed",minLengthMessage:u,maxLengthMessage:o,onValidationChange:c,error:p,onChange:h,onKeyDown:y,label:m,helperText:g,fullWidth:w=!1,className:x,id:b,"data-cy":f,"data-testid":$,...k},v)=>{const[j,V]=a.useState(),[_,N]=a.useState(!1),A=a.useId(),L=b||A,M=`${L}-error`,S=`${L}-helper`,q=f||"alphanumeric-input",D=$||"alphanumeric-input",E=e=>{if(!e)return{isValid:!0};let a="^[a-zA-Z0-9";t&&(a+="\\-"),l&&(a+="_"),n&&(a+=" "),a+="]+$";if(!new RegExp(a).test(e)){let e=d;if(t||l||n){const a=["letters","numbers"];t&&a.push("hyphens"),l&&a.push("underscores"),n&&a.push("spaces"),e=`Only ${a.join(", ")} are allowed`}return{isValid:!1,error:e}}return void 0!==s&&e.length<s?{isValid:!1,error:u||`Must be at least ${s} characters`}:void 0!==i&&e.length>i?{isValid:!1,error:o||`Must be at most ${i} characters`}:{isValid:!0}},K=p||j;return e.jsxs("div",{className:r.cn("input-wrapper",w&&"input-wrapper--full-width"),"data-cy":`${q}-wrapper`,"data-testid":`${D}-wrapper`,children:[m&&e.jsx("label",{htmlFor:L,className:"input__label","data-cy":`${q}-label`,"data-testid":`${D}-label`,children:m}),e.jsx("input",{ref:v,id:L,type:"text",className:r.cn("input",K&&"input--error",w&&"input--full-width",x),"aria-invalid":K?"true":"false","aria-describedby":K?M:g?S:void 0,"data-cy":q,"data-testid":D,onChange:e=>{const a=e.target.value;if(_){const e=E(a);V(e.error),null==c||c(e.isValid)}null==h||h(e)},onBlur:e=>{var a;N(!0);const r=E(e.target.value);V(r.error),null==c||c(r.isValid),null==(a=k.onBlur)||a.call(k,e)},onKeyDown:e=>{e.ctrlKey||e.metaKey||["Backspace","Delete","Tab","Escape","Enter","ArrowLeft","ArrowRight","Home","End"].includes(e.key)||n&&" "===e.key||t&&"-"===e.key||l&&"_"===e.key||e.key>="a"&&e.key<="z"||e.key>="A"&&e.key<="Z"||e.key>="0"&&e.key<="9"?null==y||y(e):e.preventDefault()},maxLength:i,...k}),K&&e.jsx("span",{id:M,className:"input__error",role:"alert","data-cy":`${q}-error`,"data-testid":`${D}-error`,children:K}),g&&!K&&e.jsx("span",{id:S,className:"input__helper","data-cy":`${q}-helper`,"data-testid":`${D}-helper`,children:g})]})});t.displayName="AlphanumericInput",exports.AlphanumericInput=t;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),t=require("react"),a=require("./index20.cjs"),n=require("./index21.cjs"),l=t.forwardRef(({allowHyphen:l=!1,allowUnderscore:r=!1,allowSpace:s=!1,minLength:u,maxLength:i,validate:c,onChange:o,"data-cy":p,"data-testid":d,...h},g)=>{const m=t.useRef(null),f=n.useMergedRef(g,m),v=t.useMemo(()=>{let e="^[a-zA-Z0-9";return l&&(e+="\\-"),r&&(e+="_"),s&&(e+=" "),e+="]*$",new RegExp(e)},[l,r,s]),x=t.useMemo(()=>{let e="[a-zA-Z0-9";return l&&(e+="\\-"),r&&(e+="_"),s&&(e+=" "),e+="]",new RegExp(e)},[l,r,s]),y=t.useCallback(e=>{if(e){if(!v.test(e)){let e="letters and numbers";const t=[];return l&&t.push("hyphens"),r&&t.push("underscores"),s&&t.push("spaces"),t.length>0&&(e+=`, ${t.join(", ")}`),`Only ${e} are allowed`}return void 0!==u&&e.length<u?`Must be at least ${u} characters`:void 0!==i&&e.length>i?`Must be at most ${i} characters`:void 0}},[v,u,i,l,r,s]),b=t.useCallback(e=>c?y(e)||c(e):y(e),[y,c]),[j,w]=t.useState(null);t.useEffect(()=>{null!==j&&m.current&&(m.current.setSelectionRange(j,j),w(null))},[h.value,j]);const R=t.useCallback(e=>{const t=e.target,a=t.value,n=t.selectionStart||0,l=a.split("").filter(e=>x.test(e)).join(""),r=n-a.slice(0,n).split("").filter(e=>!x.test(e)).length;t.value=l;void 0!==h.value?w(r):t.setSelectionRange(r,r),null==o||o(e)},[x,o,h.value]);return e.jsx(a.Input,{ref:f,type:"text",minLength:u,maxLength:i,validate:b,onChange:R,"data-cy":p||"alphanumeric-input","data-testid":d||"alphanumeric-input",...h})});l.displayName="AlphanumericInput",exports.AlphanumericInput=l;