@adam-milo/ui 1.0.20 → 1.0.22

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