@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/index4.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const t=require("react/jsx-runtime"),d=require("react"),u=require("./index17.cjs");;/* empty css */const w=d.forwardRef(({showToggle:h=!0,label:o,error:e,helperText:i,fullWidth:l=!1,className:x,id:g,"data-cy":j,"data-testid":y,...k},f)=>{const[n,b]=d.useState(!1),m=d.useId(),a=g||m,c=`${a}-error`,p=`${a}-helper`,s=j||"password-input",r=y||"password-input",$=()=>{b(v=>!v)};return t.jsxs("div",{className:"password-input-wrapper",children:[t.jsxs("div",{className:u.cn("input-wrapper",l&&"input-wrapper--full-width"),"data-cy":`${s}-wrapper`,"data-testid":`${r}-wrapper`,children:[o&&t.jsx("label",{htmlFor:a,className:"input__label","data-cy":`${s}-label`,"data-testid":`${r}-label`,children:o}),t.jsx("input",{ref:f,id:a,type:n?"text":"password",className:u.cn("input","password-input",e&&"input--error",l&&"input--full-width",x),"aria-invalid":e?"true":"false","aria-describedby":e?c:i?p:void 0,"data-cy":s,"data-testid":r,...k}),e&&t.jsx("span",{id:c,className:"input__error",role:"alert","data-cy":`${s}-error`,"data-testid":`${r}-error`,children:e}),i&&!e&&t.jsx("span",{id:p,className:"input__helper","data-cy":`${s}-helper`,"data-testid":`${r}-helper`,children:i})]}),h&&t.jsx("button",{type:"button",className:"password-input__toggle",onClick:$,"aria-label":n?"Hide password":"Show password","data-cy":`${s}-toggle`,"data-testid":`${r}-toggle`,children:n?t.jsxs("svg",{width:"20",height:"20",viewBox:"0 0 20 20",fill:"none",xmlns:"http://www.w3.org/2000/svg","aria-hidden":"true",children:[t.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"}),t.jsx("circle",{cx:"10",cy:"10",r:"2.5",stroke:"currentColor",strokeWidth:"1.5",fill:"none"})]}):t.jsxs("svg",{width:"20",height:"20",viewBox:"0 0 20 20",fill:"none",xmlns:"http://www.w3.org/2000/svg","aria-hidden":"true",children:[t.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"}),t.jsx("circle",{cx:"10",cy:"10",r:"2.5",stroke:"currentColor",strokeWidth:"1.5",fill:"none"}),t.jsx("path",{d:"M3 3l14 14",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round"})]})})]})});w.displayName="PasswordInput";exports.PasswordInput=w;
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 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";
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 _ = x(
5
+ const PasswordInput = forwardRef(
6
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);
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__ */ i("div", { className: "password-input-wrapper", children: [
22
- /* @__PURE__ */ i(
28
+ return /* @__PURE__ */ jsxs("div", { className: "password-input-wrapper", children: [
29
+ /* @__PURE__ */ jsxs(
23
30
  "div",
24
31
  {
25
- className: u("input-wrapper", l && "input-wrapper--full-width"),
26
- "data-cy": `${r}-wrapper`,
27
- "data-testid": `${s}-wrapper`,
32
+ className: cn("input-wrapper", fullWidth && "input-wrapper--full-width"),
33
+ "data-cy": `${finalDataCy}-wrapper`,
34
+ "data-testid": `${finalTestId}-wrapper`,
28
35
  children: [
29
- n && /* @__PURE__ */ t(
36
+ label && /* @__PURE__ */ jsx(
30
37
  "label",
31
38
  {
32
- htmlFor: a,
39
+ htmlFor: id,
33
40
  className: "input__label",
34
- "data-cy": `${r}-label`,
35
- "data-testid": `${s}-label`,
36
- children: n
41
+ "data-cy": `${finalDataCy}-label`,
42
+ "data-testid": `${finalTestId}-label`,
43
+ children: label
37
44
  }
38
45
  ),
39
- /* @__PURE__ */ t(
46
+ /* @__PURE__ */ jsx(
40
47
  "input",
41
48
  {
42
- ref: y,
43
- id: a,
44
- type: d ? "text" : "password",
45
- className: u(
49
+ ref,
50
+ id,
51
+ type: isPasswordVisible ? "text" : "password",
52
+ className: cn(
46
53
  "input",
47
54
  "password-input",
48
- e && "input--error",
49
- l && "input--full-width",
50
- h
55
+ error && "input--error",
56
+ fullWidth && "input--full-width",
57
+ className
51
58
  ),
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
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
- e && /* @__PURE__ */ t(
66
+ error && /* @__PURE__ */ jsx(
60
67
  "span",
61
68
  {
62
- id: p,
69
+ id: errorId,
63
70
  className: "input__error",
64
71
  role: "alert",
65
- "data-cy": `${r}-error`,
66
- "data-testid": `${s}-error`,
67
- children: e
72
+ "data-cy": `${finalDataCy}-error`,
73
+ "data-testid": `${finalTestId}-error`,
74
+ children: error
68
75
  }
69
76
  ),
70
- o && !e && /* @__PURE__ */ t(
77
+ helperText && !error && /* @__PURE__ */ jsx(
71
78
  "span",
72
79
  {
73
- id: c,
80
+ id: helperId,
74
81
  className: "input__helper",
75
- "data-cy": `${r}-helper`,
76
- "data-testid": `${s}-helper`,
77
- children: o
82
+ "data-cy": `${finalDataCy}-helper`,
83
+ "data-testid": `${finalTestId}-helper`,
84
+ children: helperText
78
85
  }
79
86
  )
80
87
  ]
81
88
  }
82
89
  ),
83
- w && /* @__PURE__ */ t(
90
+ showToggle && /* @__PURE__ */ jsx(
84
91
  "button",
85
92
  {
86
93
  type: "button",
87
94
  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(
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__ */ t(
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__ */ t(
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__ */ i(
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__ */ t(
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__ */ t(
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__ */ t(
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
- _.displayName = "PasswordInput";
182
+ PasswordInput.displayName = "PasswordInput";
176
183
  export {
177
- _ as PasswordInput
184
+ PasswordInput
178
185
  };
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"),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 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";
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 W = Z(
5
+ const NumericInput = forwardRef(
6
6
  ({
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 = [
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 (r.ctrlKey || r.metaKey) {
54
- t == null || t(r);
71
+ if (e.ctrlKey || e.metaKey) {
72
+ onKeyDown == null ? void 0 : onKeyDown(e);
55
73
  return;
56
74
  }
57
- if (a.includes(r.key)) {
58
- t == null || t(r);
75
+ if (allowedKeys.includes(e.key)) {
76
+ onKeyDown == null ? void 0 : onKeyDown(e);
59
77
  return;
60
78
  }
61
- if ($ && r.key === ".") {
62
- if (r.currentTarget.value.includes(".")) {
63
- r.preventDefault();
79
+ if (allowDecimal && e.key === ".") {
80
+ const value = e.currentTarget.value;
81
+ if (value.includes(".")) {
82
+ e.preventDefault();
64
83
  return;
65
84
  }
66
- t == null || t(r);
85
+ onKeyDown == null ? void 0 : onKeyDown(e);
67
86
  return;
68
87
  }
69
- if (b && r.key === "-") {
70
- const e = r.currentTarget.value;
71
- if ((r.currentTarget.selectionStart || 0) !== 0 || e.includes("-")) {
72
- r.preventDefault();
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
- t == null || t(r);
95
+ onKeyDown == null ? void 0 : onKeyDown(e);
76
96
  return;
77
97
  }
78
- if (r.key >= "0" && r.key <= "9") {
79
- t == null || t(r);
98
+ if (e.key >= "0" && e.key <= "9") {
99
+ onKeyDown == null ? void 0 : onKeyDown(e);
80
100
  return;
81
101
  }
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);
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
- 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(
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: T("input-wrapper", I && "input-wrapper--full-width"),
100
- "data-cy": `${l}-wrapper`,
101
- "data-testid": `${u}-wrapper`,
125
+ className: cn("input-wrapper", fullWidth && "input-wrapper--full-width"),
126
+ "data-cy": `${finalDataCy}-wrapper`,
127
+ "data-testid": `${finalTestId}-wrapper`,
102
128
  children: [
103
- N && /* @__PURE__ */ f(
129
+ label && /* @__PURE__ */ jsx(
104
130
  "label",
105
131
  {
106
- htmlFor: d,
132
+ htmlFor: id,
107
133
  className: "input__label",
108
- "data-cy": `${l}-label`,
109
- "data-testid": `${u}-label`,
110
- children: N
134
+ "data-cy": `${finalDataCy}-label`,
135
+ "data-testid": `${finalTestId}-label`,
136
+ children: label
111
137
  }
112
138
  ),
113
- /* @__PURE__ */ f(
139
+ /* @__PURE__ */ jsx(
114
140
  "input",
115
141
  {
116
- ref: V,
117
- id: d,
142
+ ref,
143
+ id,
118
144
  type: "text",
119
145
  inputMode: "numeric",
120
- className: T(
146
+ className: cn(
121
147
  "input",
122
- i && "input--error",
123
- I && "input--full-width",
124
- P
148
+ displayError && "input--error",
149
+ fullWidth && "input--full-width",
150
+ className
125
151
  ),
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
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
- i && /* @__PURE__ */ f(
162
+ displayError && /* @__PURE__ */ jsx(
137
163
  "span",
138
164
  {
139
- id: k,
165
+ id: errorId,
140
166
  className: "input__error",
141
167
  role: "alert",
142
- "data-cy": `${l}-error`,
143
- "data-testid": `${u}-error`,
144
- children: i
168
+ "data-cy": `${finalDataCy}-error`,
169
+ "data-testid": `${finalTestId}-error`,
170
+ children: displayError
145
171
  }
146
172
  ),
147
- n && !i && /* @__PURE__ */ f(
173
+ helperText && !displayError && /* @__PURE__ */ jsx(
148
174
  "span",
149
175
  {
150
- id: _,
176
+ id: helperId,
151
177
  className: "input__helper",
152
- "data-cy": `${l}-helper`,
153
- "data-testid": `${u}-helper`,
154
- children: n
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
- W.displayName = "NumericInput";
188
+ NumericInput.displayName = "NumericInput";
163
189
  export {
164
- W as NumericInput
190
+ NumericInput
165
191
  };
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"),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;