@adam-milo/ui 1.0.20 → 1.0.21
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/dist/index.cjs +1 -1
- package/dist/index.js +53 -53
- package/dist/index10.cjs +1 -1
- package/dist/index10.js +38 -36
- package/dist/index11.cjs +1 -1
- package/dist/index11.js +82 -76
- package/dist/index12.cjs +1 -1
- package/dist/index12.js +50 -49
- package/dist/index13.cjs +1 -1
- package/dist/index13.js +30 -30
- package/dist/index14.cjs +1 -1
- package/dist/index14.js +348 -209
- package/dist/index15.cjs +1 -1
- package/dist/index15.js +92 -82
- package/dist/index16.cjs +1 -1
- package/dist/index16.js +32 -31
- package/dist/index17.cjs +1 -1
- package/dist/index17.js +10 -7
- package/dist/index2.cjs +1 -1
- package/dist/index2.js +26 -26
- package/dist/index3.cjs +1 -1
- package/dist/index3.js +84 -66
- package/dist/index31.cjs +1 -0
- package/dist/index31.js +9 -0
- package/dist/index4.cjs +1 -1
- package/dist/index4.js +71 -64
- package/dist/index5.cjs +1 -1
- package/dist/index5.js +130 -104
- package/dist/index6.cjs +1 -1
- package/dist/index6.js +136 -107
- package/dist/index7.cjs +1 -1
- package/dist/index7.js +76 -61
- package/dist/index8.cjs +1 -1
- package/dist/index8.js +68 -54
- package/dist/index9.cjs +1 -1
- package/dist/index9.js +47 -43
- package/dist/src/lib/dev-utils.d.ts +41 -0
- package/dist/src/lib/dev-utils.d.ts.map +1 -0
- package/dist/src/lib/index.d.ts +13 -2
- package/dist/src/lib/index.d.ts.map +1 -1
- package/package.json +4 -2
package/dist/index4.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),r=require("react"),t=require("./index17.cjs");;/* empty css */const s=r.forwardRef(({showToggle:s=!0,label:a,error:i,helperText:o,fullWidth:d=!1,className:l,id:n,"data-cy":p,"data-testid":c,...u},h)=>{const[w,x]=r.useState(!1),j=r.useId(),g=n||j,k=`${g}-error`,y=`${g}-helper`,f=p||"password-input",m=c||"password-input";return e.jsxs("div",{className:"password-input-wrapper",children:[e.jsxs("div",{className:t.cn("input-wrapper",d&&"input-wrapper--full-width"),"data-cy":`${f}-wrapper`,"data-testid":`${m}-wrapper`,children:[a&&e.jsx("label",{htmlFor:g,className:"input__label","data-cy":`${f}-label`,"data-testid":`${m}-label`,children:a}),e.jsx("input",{ref:h,id:g,type:w?"text":"password",className:t.cn("input","password-input",i&&"input--error",d&&"input--full-width",l),"aria-invalid":i?"true":"false","aria-describedby":i?k:o?y:void 0,"data-cy":f,"data-testid":m,...u}),i&&e.jsx("span",{id:k,className:"input__error",role:"alert","data-cy":`${f}-error`,"data-testid":`${m}-error`,children:i}),o&&!i&&e.jsx("span",{id:y,className:"input__helper","data-cy":`${f}-helper`,"data-testid":`${m}-helper`,children:o})]}),s&&e.jsx("button",{type:"button",className:"password-input__toggle",onClick:()=>{x(e=>!e)},"aria-label":w?"Hide password":"Show password","data-cy":`${f}-toggle`,"data-testid":`${m}-toggle`,children:w?e.jsxs("svg",{width:"20",height:"20",viewBox:"0 0 20 20",fill:"none",xmlns:"http://www.w3.org/2000/svg","aria-hidden":"true",children:[e.jsx("path",{d:"M10 4C5.5 4 2 10 2 10s3.5 6 8 6 8-6 8-6-3.5-6-8-6z",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round",fill:"none"}),e.jsx("circle",{cx:"10",cy:"10",r:"2.5",stroke:"currentColor",strokeWidth:"1.5",fill:"none"})]}):e.jsxs("svg",{width:"20",height:"20",viewBox:"0 0 20 20",fill:"none",xmlns:"http://www.w3.org/2000/svg","aria-hidden":"true",children:[e.jsx("path",{d:"M10 4C5.5 4 2 10 2 10s3.5 6 8 6 8-6 8-6-3.5-6-8-6z",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round",fill:"none"}),e.jsx("circle",{cx:"10",cy:"10",r:"2.5",stroke:"currentColor",strokeWidth:"1.5",fill:"none"}),e.jsx("path",{d:"M3 3l14 14",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round"})]})})]})});s.displayName="PasswordInput",exports.PasswordInput=s;
|
package/dist/index4.js
CHANGED
|
@@ -1,95 +1,102 @@
|
|
|
1
|
-
import { jsxs
|
|
2
|
-
import { forwardRef
|
|
3
|
-
import { cn
|
|
1
|
+
import { jsxs, jsx } from "react/jsx-runtime";
|
|
2
|
+
import { forwardRef, useState, useId } from "react";
|
|
3
|
+
import { cn } from "./index17.js";
|
|
4
4
|
/* empty css */
|
|
5
|
-
const
|
|
5
|
+
const PasswordInput = forwardRef(
|
|
6
6
|
({
|
|
7
|
-
showToggle
|
|
8
|
-
label
|
|
9
|
-
error
|
|
10
|
-
helperText
|
|
11
|
-
fullWidth
|
|
12
|
-
className
|
|
13
|
-
id:
|
|
14
|
-
"data-cy":
|
|
15
|
-
"data-testid":
|
|
16
|
-
...
|
|
17
|
-
},
|
|
18
|
-
const [
|
|
19
|
-
|
|
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);
|
|
20
27
|
};
|
|
21
|
-
return /* @__PURE__ */
|
|
22
|
-
/* @__PURE__ */
|
|
28
|
+
return /* @__PURE__ */ jsxs("div", { className: "password-input-wrapper", children: [
|
|
29
|
+
/* @__PURE__ */ jsxs(
|
|
23
30
|
"div",
|
|
24
31
|
{
|
|
25
|
-
className:
|
|
26
|
-
"data-cy": `${
|
|
27
|
-
"data-testid": `${
|
|
32
|
+
className: cn("input-wrapper", fullWidth && "input-wrapper--full-width"),
|
|
33
|
+
"data-cy": `${finalDataCy}-wrapper`,
|
|
34
|
+
"data-testid": `${finalTestId}-wrapper`,
|
|
28
35
|
children: [
|
|
29
|
-
|
|
36
|
+
label && /* @__PURE__ */ jsx(
|
|
30
37
|
"label",
|
|
31
38
|
{
|
|
32
|
-
htmlFor:
|
|
39
|
+
htmlFor: id,
|
|
33
40
|
className: "input__label",
|
|
34
|
-
"data-cy": `${
|
|
35
|
-
"data-testid": `${
|
|
36
|
-
children:
|
|
41
|
+
"data-cy": `${finalDataCy}-label`,
|
|
42
|
+
"data-testid": `${finalTestId}-label`,
|
|
43
|
+
children: label
|
|
37
44
|
}
|
|
38
45
|
),
|
|
39
|
-
/* @__PURE__ */
|
|
46
|
+
/* @__PURE__ */ jsx(
|
|
40
47
|
"input",
|
|
41
48
|
{
|
|
42
|
-
ref
|
|
43
|
-
id
|
|
44
|
-
type:
|
|
45
|
-
className:
|
|
49
|
+
ref,
|
|
50
|
+
id,
|
|
51
|
+
type: isPasswordVisible ? "text" : "password",
|
|
52
|
+
className: cn(
|
|
46
53
|
"input",
|
|
47
54
|
"password-input",
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
55
|
+
error && "input--error",
|
|
56
|
+
fullWidth && "input--full-width",
|
|
57
|
+
className
|
|
51
58
|
),
|
|
52
|
-
"aria-invalid":
|
|
53
|
-
"aria-describedby":
|
|
54
|
-
"data-cy":
|
|
55
|
-
"data-testid":
|
|
56
|
-
...
|
|
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
|
|
57
64
|
}
|
|
58
65
|
),
|
|
59
|
-
|
|
66
|
+
error && /* @__PURE__ */ jsx(
|
|
60
67
|
"span",
|
|
61
68
|
{
|
|
62
|
-
id:
|
|
69
|
+
id: errorId,
|
|
63
70
|
className: "input__error",
|
|
64
71
|
role: "alert",
|
|
65
|
-
"data-cy": `${
|
|
66
|
-
"data-testid": `${
|
|
67
|
-
children:
|
|
72
|
+
"data-cy": `${finalDataCy}-error`,
|
|
73
|
+
"data-testid": `${finalTestId}-error`,
|
|
74
|
+
children: error
|
|
68
75
|
}
|
|
69
76
|
),
|
|
70
|
-
|
|
77
|
+
helperText && !error && /* @__PURE__ */ jsx(
|
|
71
78
|
"span",
|
|
72
79
|
{
|
|
73
|
-
id:
|
|
80
|
+
id: helperId,
|
|
74
81
|
className: "input__helper",
|
|
75
|
-
"data-cy": `${
|
|
76
|
-
"data-testid": `${
|
|
77
|
-
children:
|
|
82
|
+
"data-cy": `${finalDataCy}-helper`,
|
|
83
|
+
"data-testid": `${finalTestId}-helper`,
|
|
84
|
+
children: helperText
|
|
78
85
|
}
|
|
79
86
|
)
|
|
80
87
|
]
|
|
81
88
|
}
|
|
82
89
|
),
|
|
83
|
-
|
|
90
|
+
showToggle && /* @__PURE__ */ jsx(
|
|
84
91
|
"button",
|
|
85
92
|
{
|
|
86
93
|
type: "button",
|
|
87
94
|
className: "password-input__toggle",
|
|
88
|
-
onClick:
|
|
89
|
-
"aria-label":
|
|
90
|
-
"data-cy": `${
|
|
91
|
-
"data-testid": `${
|
|
92
|
-
children:
|
|
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(
|
|
93
100
|
"svg",
|
|
94
101
|
{
|
|
95
102
|
width: "20",
|
|
@@ -99,7 +106,7 @@ const _ = x(
|
|
|
99
106
|
xmlns: "http://www.w3.org/2000/svg",
|
|
100
107
|
"aria-hidden": "true",
|
|
101
108
|
children: [
|
|
102
|
-
/* @__PURE__ */
|
|
109
|
+
/* @__PURE__ */ jsx(
|
|
103
110
|
"path",
|
|
104
111
|
{
|
|
105
112
|
d: "M10 4C5.5 4 2 10 2 10s3.5 6 8 6 8-6 8-6-3.5-6-8-6z",
|
|
@@ -110,7 +117,7 @@ const _ = x(
|
|
|
110
117
|
fill: "none"
|
|
111
118
|
}
|
|
112
119
|
),
|
|
113
|
-
/* @__PURE__ */
|
|
120
|
+
/* @__PURE__ */ jsx(
|
|
114
121
|
"circle",
|
|
115
122
|
{
|
|
116
123
|
cx: "10",
|
|
@@ -123,7 +130,7 @@ const _ = x(
|
|
|
123
130
|
)
|
|
124
131
|
]
|
|
125
132
|
}
|
|
126
|
-
) : /* @__PURE__ */
|
|
133
|
+
) : /* @__PURE__ */ jsxs(
|
|
127
134
|
"svg",
|
|
128
135
|
{
|
|
129
136
|
width: "20",
|
|
@@ -133,7 +140,7 @@ const _ = x(
|
|
|
133
140
|
xmlns: "http://www.w3.org/2000/svg",
|
|
134
141
|
"aria-hidden": "true",
|
|
135
142
|
children: [
|
|
136
|
-
/* @__PURE__ */
|
|
143
|
+
/* @__PURE__ */ jsx(
|
|
137
144
|
"path",
|
|
138
145
|
{
|
|
139
146
|
d: "M10 4C5.5 4 2 10 2 10s3.5 6 8 6 8-6 8-6-3.5-6-8-6z",
|
|
@@ -144,7 +151,7 @@ const _ = x(
|
|
|
144
151
|
fill: "none"
|
|
145
152
|
}
|
|
146
153
|
),
|
|
147
|
-
/* @__PURE__ */
|
|
154
|
+
/* @__PURE__ */ jsx(
|
|
148
155
|
"circle",
|
|
149
156
|
{
|
|
150
157
|
cx: "10",
|
|
@@ -155,7 +162,7 @@ const _ = x(
|
|
|
155
162
|
fill: "none"
|
|
156
163
|
}
|
|
157
164
|
),
|
|
158
|
-
/* @__PURE__ */
|
|
165
|
+
/* @__PURE__ */ jsx(
|
|
159
166
|
"path",
|
|
160
167
|
{
|
|
161
168
|
d: "M3 3l14 14",
|
|
@@ -172,7 +179,7 @@ const _ = x(
|
|
|
172
179
|
] });
|
|
173
180
|
}
|
|
174
181
|
);
|
|
175
|
-
|
|
182
|
+
PasswordInput.displayName = "PasswordInput";
|
|
176
183
|
export {
|
|
177
|
-
|
|
184
|
+
PasswordInput
|
|
178
185
|
};
|
package/dist/index5.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
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;
|
package/dist/index5.js
CHANGED
|
@@ -1,45 +1,63 @@
|
|
|
1
|
-
import { jsxs
|
|
2
|
-
import { forwardRef
|
|
3
|
-
import { cn
|
|
1
|
+
import { jsxs, jsx } from "react/jsx-runtime";
|
|
2
|
+
import { forwardRef, useState, useId } from "react";
|
|
3
|
+
import { cn } from "./index17.js";
|
|
4
4
|
/* empty css */
|
|
5
|
-
const
|
|
5
|
+
const NumericInput = forwardRef(
|
|
6
6
|
({
|
|
7
|
-
allowDecimal
|
|
8
|
-
allowNegative
|
|
9
|
-
min
|
|
10
|
-
max
|
|
11
|
-
decimalPlaces
|
|
12
|
-
invalidNumberMessage
|
|
13
|
-
minValueMessage
|
|
14
|
-
maxValueMessage
|
|
15
|
-
onValidationChange
|
|
16
|
-
error:
|
|
17
|
-
onChange
|
|
18
|
-
onKeyDown
|
|
19
|
-
label
|
|
20
|
-
helperText
|
|
21
|
-
fullWidth
|
|
22
|
-
className
|
|
23
|
-
id:
|
|
24
|
-
"data-cy":
|
|
25
|
-
"data-testid":
|
|
26
|
-
...
|
|
27
|
-
},
|
|
28
|
-
const [
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
7
|
+
allowDecimal = false,
|
|
8
|
+
allowNegative = false,
|
|
9
|
+
min,
|
|
10
|
+
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,
|
|
24
|
+
"data-cy": dataCy,
|
|
25
|
+
"data-testid": dataTestId,
|
|
26
|
+
...props
|
|
27
|
+
}, 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 = [
|
|
43
61
|
"Backspace",
|
|
44
62
|
"Delete",
|
|
45
63
|
"Tab",
|
|
@@ -50,108 +68,116 @@ const W = Z(
|
|
|
50
68
|
"Home",
|
|
51
69
|
"End"
|
|
52
70
|
];
|
|
53
|
-
if (
|
|
54
|
-
|
|
71
|
+
if (e.ctrlKey || e.metaKey) {
|
|
72
|
+
onKeyDown == null ? void 0 : onKeyDown(e);
|
|
55
73
|
return;
|
|
56
74
|
}
|
|
57
|
-
if (
|
|
58
|
-
|
|
75
|
+
if (allowedKeys.includes(e.key)) {
|
|
76
|
+
onKeyDown == null ? void 0 : onKeyDown(e);
|
|
59
77
|
return;
|
|
60
78
|
}
|
|
61
|
-
if (
|
|
62
|
-
|
|
63
|
-
|
|
79
|
+
if (allowDecimal && e.key === ".") {
|
|
80
|
+
const value = e.currentTarget.value;
|
|
81
|
+
if (value.includes(".")) {
|
|
82
|
+
e.preventDefault();
|
|
64
83
|
return;
|
|
65
84
|
}
|
|
66
|
-
|
|
85
|
+
onKeyDown == null ? void 0 : onKeyDown(e);
|
|
67
86
|
return;
|
|
68
87
|
}
|
|
69
|
-
if (
|
|
70
|
-
const
|
|
71
|
-
|
|
72
|
-
|
|
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();
|
|
73
93
|
return;
|
|
74
94
|
}
|
|
75
|
-
|
|
95
|
+
onKeyDown == null ? void 0 : onKeyDown(e);
|
|
76
96
|
return;
|
|
77
97
|
}
|
|
78
|
-
if (
|
|
79
|
-
|
|
98
|
+
if (e.key >= "0" && e.key <= "9") {
|
|
99
|
+
onKeyDown == null ? void 0 : onKeyDown(e);
|
|
80
100
|
return;
|
|
81
101
|
}
|
|
82
|
-
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
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);
|
|
88
110
|
}
|
|
89
|
-
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
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(
|
|
97
123
|
"div",
|
|
98
124
|
{
|
|
99
|
-
className:
|
|
100
|
-
"data-cy": `${
|
|
101
|
-
"data-testid": `${
|
|
125
|
+
className: cn("input-wrapper", fullWidth && "input-wrapper--full-width"),
|
|
126
|
+
"data-cy": `${finalDataCy}-wrapper`,
|
|
127
|
+
"data-testid": `${finalTestId}-wrapper`,
|
|
102
128
|
children: [
|
|
103
|
-
|
|
129
|
+
label && /* @__PURE__ */ jsx(
|
|
104
130
|
"label",
|
|
105
131
|
{
|
|
106
|
-
htmlFor:
|
|
132
|
+
htmlFor: id,
|
|
107
133
|
className: "input__label",
|
|
108
|
-
"data-cy": `${
|
|
109
|
-
"data-testid": `${
|
|
110
|
-
children:
|
|
134
|
+
"data-cy": `${finalDataCy}-label`,
|
|
135
|
+
"data-testid": `${finalTestId}-label`,
|
|
136
|
+
children: label
|
|
111
137
|
}
|
|
112
138
|
),
|
|
113
|
-
/* @__PURE__ */
|
|
139
|
+
/* @__PURE__ */ jsx(
|
|
114
140
|
"input",
|
|
115
141
|
{
|
|
116
|
-
ref
|
|
117
|
-
id
|
|
142
|
+
ref,
|
|
143
|
+
id,
|
|
118
144
|
type: "text",
|
|
119
145
|
inputMode: "numeric",
|
|
120
|
-
className:
|
|
146
|
+
className: cn(
|
|
121
147
|
"input",
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
148
|
+
displayError && "input--error",
|
|
149
|
+
fullWidth && "input--full-width",
|
|
150
|
+
className
|
|
125
151
|
),
|
|
126
|
-
"aria-invalid":
|
|
127
|
-
"aria-describedby":
|
|
128
|
-
"data-cy":
|
|
129
|
-
"data-testid":
|
|
130
|
-
onChange:
|
|
131
|
-
onBlur:
|
|
132
|
-
onKeyDown:
|
|
133
|
-
...
|
|
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
|
|
134
160
|
}
|
|
135
161
|
),
|
|
136
|
-
|
|
162
|
+
displayError && /* @__PURE__ */ jsx(
|
|
137
163
|
"span",
|
|
138
164
|
{
|
|
139
|
-
id:
|
|
165
|
+
id: errorId,
|
|
140
166
|
className: "input__error",
|
|
141
167
|
role: "alert",
|
|
142
|
-
"data-cy": `${
|
|
143
|
-
"data-testid": `${
|
|
144
|
-
children:
|
|
168
|
+
"data-cy": `${finalDataCy}-error`,
|
|
169
|
+
"data-testid": `${finalTestId}-error`,
|
|
170
|
+
children: displayError
|
|
145
171
|
}
|
|
146
172
|
),
|
|
147
|
-
|
|
173
|
+
helperText && !displayError && /* @__PURE__ */ jsx(
|
|
148
174
|
"span",
|
|
149
175
|
{
|
|
150
|
-
id:
|
|
176
|
+
id: helperId,
|
|
151
177
|
className: "input__helper",
|
|
152
|
-
"data-cy": `${
|
|
153
|
-
"data-testid": `${
|
|
154
|
-
children:
|
|
178
|
+
"data-cy": `${finalDataCy}-helper`,
|
|
179
|
+
"data-testid": `${finalTestId}-helper`,
|
|
180
|
+
children: helperText
|
|
155
181
|
}
|
|
156
182
|
)
|
|
157
183
|
]
|
|
@@ -159,7 +185,7 @@ const W = Z(
|
|
|
159
185
|
);
|
|
160
186
|
}
|
|
161
187
|
);
|
|
162
|
-
|
|
188
|
+
NumericInput.displayName = "NumericInput";
|
|
163
189
|
export {
|
|
164
|
-
|
|
190
|
+
NumericInput
|
|
165
191
|
};
|
package/dist/index6.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
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;
|