@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/index15.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const d=require("react/jsx-runtime"),c=require("react"),T=require("@radix-ui/react-dialog"),r=require("./index17.cjs");;/* empty css */function j(a){const e=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(a){for(const t in a)if(t!=="default"){const i=Object.getOwnPropertyDescriptor(a,t);Object.defineProperty(e,t,i.get?i:{enumerable:!0,get:()=>a[t]})}}return e.default=a,Object.freeze(e)}const o=j(T),v=o.Root,C=o.Trigger,y=o.Portal,x=o.Close,g=c.forwardRef(({className:a,"data-cy":e,"data-testid":t,...i},l)=>{const s=e||"dialog-overlay",n=t||"dialog-overlay";return d.jsx(o.Overlay,{ref:l,className:r.cn("dialog-overlay",a),"data-cy":s,"data-testid":n,...i})});g.displayName=o.Overlay.displayName;const D=c.forwardRef(({className:a,children:e,"data-cy":t,"data-testid":i,...l},s)=>{const n=t||"dialog-content",N=i||"dialog-content";return d.jsxs(y,{children:[d.jsx(g,{}),d.jsx(o.Content,{ref:s,className:r.cn("dialog-content",a),"data-cy":n,"data-testid":N,...l,children:e})]})});D.displayName=o.Content.displayName;const f=({className:a,"data-cy":e,"data-testid":t,...i})=>{const l=e||"dialog-header",s=t||"dialog-header";return d.jsx("div",{className:r.cn("dialog-header",a),"data-cy":l,"data-testid":s,...i})};f.displayName="DialogHeader";const u=({className:a,"data-cy":e,"data-testid":t,...i})=>{const l=e||"dialog-footer",s=t||"dialog-footer";return d.jsx("div",{className:r.cn("dialog-footer",a),"data-cy":l,"data-testid":s,...i})};u.displayName="DialogFooter";const m=c.forwardRef(({className:a,"data-cy":e,"data-testid":t,...i},l)=>{const s=e||"dialog-title",n=t||"dialog-title";return d.jsx(o.Title,{ref:l,className:r.cn("dialog-title",a),"data-cy":s,"data-testid":n,...i})});m.displayName=o.Title.displayName;const p=c.forwardRef(({className:a,"data-cy":e,"data-testid":t,...i},l)=>{const s=e||"dialog-description",n=t||"dialog-description";return d.jsx(o.Description,{ref:l,className:r.cn("dialog-description",a),"data-cy":s,"data-testid":n,...i})});p.displayName=o.Description.displayName;exports.Dialog=v;exports.DialogClose=x;exports.DialogContent=D;exports.DialogDescription=p;exports.DialogFooter=u;exports.DialogHeader=f;exports.DialogOverlay=g;exports.DialogPortal=y;exports.DialogTitle=m;exports.DialogTrigger=C;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),a=require("react"),t=require("@radix-ui/react-dialog"),o=require("./index17.cjs");function i(e){const a=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e)for(const t in e)if("default"!==t){const o=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(a,t,o.get?o:{enumerable:!0,get:()=>e[t]})}return a.default=e,Object.freeze(a)};/* empty css */const r=i(t),s=r.Root,d=r.Trigger,l=r.Portal,c=r.Close,n=a.forwardRef(({className:a,"data-cy":t,"data-testid":i,...s},d)=>{const l=t||"dialog-overlay",c=i||"dialog-overlay";return e.jsx(r.Overlay,{ref:d,className:o.cn("dialog-overlay",a),"data-cy":l,"data-testid":c,...s})});n.displayName=r.Overlay.displayName;const g=a.forwardRef(({className:a,children:t,"data-cy":i,"data-testid":s,...d},c)=>{const g=i||"dialog-content",y=s||"dialog-content";return e.jsxs(l,{children:[e.jsx(n,{}),e.jsx(r.Content,{ref:c,className:o.cn("dialog-content",a),"data-cy":g,"data-testid":y,...d,children:t})]})});g.displayName=r.Content.displayName;const y=({className:a,"data-cy":t,"data-testid":i,...r})=>{const s=t||"dialog-header",d=i||"dialog-header";return e.jsx("div",{className:o.cn("dialog-header",a),"data-cy":s,"data-testid":d,...r})};y.displayName="DialogHeader";const p=({className:a,"data-cy":t,"data-testid":i,...r})=>{const s=t||"dialog-footer",d=i||"dialog-footer";return e.jsx("div",{className:o.cn("dialog-footer",a),"data-cy":s,"data-testid":d,...r})};p.displayName="DialogFooter";const m=a.forwardRef(({className:a,"data-cy":t,"data-testid":i,...s},d)=>{const l=t||"dialog-title",c=i||"dialog-title";return e.jsx(r.Title,{ref:d,className:o.cn("dialog-title",a),"data-cy":l,"data-testid":c,...s})});m.displayName=r.Title.displayName;const f=a.forwardRef(({className:a,"data-cy":t,"data-testid":i,...s},d)=>{const l=t||"dialog-description",c=i||"dialog-description";return e.jsx(r.Description,{ref:d,className:o.cn("dialog-description",a),"data-cy":l,"data-testid":c,...s})});f.displayName=r.Description.displayName,exports.Dialog=s,exports.DialogClose=c,exports.DialogContent=g,exports.DialogDescription=f,exports.DialogFooter=p,exports.DialogHeader=y,exports.DialogOverlay=n,exports.DialogPortal=l,exports.DialogTitle=m,exports.DialogTrigger=d;
package/dist/index15.js CHANGED
@@ -1,115 +1,125 @@
1
- import { jsxs as m, jsx as n } from "react/jsx-runtime";
2
- import { forwardRef as c } from "react";
3
- import * as a from "@radix-ui/react-dialog";
4
- import { cn as r } from "./index17.js";
1
+ import { jsxs, jsx } from "react/jsx-runtime";
2
+ import { forwardRef } from "react";
3
+ import * as DialogPrimitive from "@radix-ui/react-dialog";
4
+ import { cn } from "./index17.js";
5
5
  /* empty css */
6
- const x = a.Root, O = a.Trigger, p = a.Portal, P = a.Close, g = c(({ className: t, "data-cy": i, "data-testid": o, ...e }, d) => {
7
- const l = i || "dialog-overlay", s = o || "dialog-overlay";
8
- return /* @__PURE__ */ n(
9
- a.Overlay,
6
+ const Dialog = DialogPrimitive.Root;
7
+ const DialogTrigger = DialogPrimitive.Trigger;
8
+ const DialogPortal = DialogPrimitive.Portal;
9
+ const DialogClose = DialogPrimitive.Close;
10
+ const DialogOverlay = forwardRef(({ className, "data-cy": dataCy, "data-testid": dataTestId, ...props }, ref) => {
11
+ const finalDataCy = dataCy || "dialog-overlay";
12
+ const finalTestId = dataTestId || "dialog-overlay";
13
+ return /* @__PURE__ */ jsx(
14
+ DialogPrimitive.Overlay,
10
15
  {
11
- ref: d,
12
- className: r("dialog-overlay", t),
13
- "data-cy": l,
14
- "data-testid": s,
15
- ...e
16
+ ref,
17
+ className: cn("dialog-overlay", className),
18
+ "data-cy": finalDataCy,
19
+ "data-testid": finalTestId,
20
+ ...props
16
21
  }
17
22
  );
18
23
  });
19
- g.displayName = a.Overlay.displayName;
20
- const D = c(({ className: t, children: i, "data-cy": o, "data-testid": e, ...d }, l) => {
21
- const s = o || "dialog-content", y = e || "dialog-content";
22
- return /* @__PURE__ */ m(p, { children: [
23
- /* @__PURE__ */ n(g, {}),
24
- /* @__PURE__ */ n(
25
- a.Content,
24
+ DialogOverlay.displayName = DialogPrimitive.Overlay.displayName;
25
+ const DialogContent = forwardRef(({ className, children, "data-cy": dataCy, "data-testid": dataTestId, ...props }, ref) => {
26
+ const finalDataCy = dataCy || "dialog-content";
27
+ const finalTestId = dataTestId || "dialog-content";
28
+ return /* @__PURE__ */ jsxs(DialogPortal, { children: [
29
+ /* @__PURE__ */ jsx(DialogOverlay, {}),
30
+ /* @__PURE__ */ jsx(
31
+ DialogPrimitive.Content,
26
32
  {
27
- ref: l,
28
- className: r("dialog-content", t),
29
- "data-cy": s,
30
- "data-testid": y,
31
- ...d,
32
- children: i
33
+ ref,
34
+ className: cn("dialog-content", className),
35
+ "data-cy": finalDataCy,
36
+ "data-testid": finalTestId,
37
+ ...props,
38
+ children
33
39
  }
34
40
  )
35
41
  ] });
36
42
  });
37
- D.displayName = a.Content.displayName;
38
- const f = ({
39
- className: t,
40
- "data-cy": i,
41
- "data-testid": o,
42
- ...e
43
+ DialogContent.displayName = DialogPrimitive.Content.displayName;
44
+ const DialogHeader = ({
45
+ className,
46
+ "data-cy": dataCy,
47
+ "data-testid": dataTestId,
48
+ ...props
43
49
  }) => {
44
- const d = i || "dialog-header", l = o || "dialog-header";
45
- return /* @__PURE__ */ n(
50
+ const finalDataCy = dataCy || "dialog-header";
51
+ const finalTestId = dataTestId || "dialog-header";
52
+ return /* @__PURE__ */ jsx(
46
53
  "div",
47
54
  {
48
- className: r("dialog-header", t),
49
- "data-cy": d,
50
- "data-testid": l,
51
- ...e
55
+ className: cn("dialog-header", className),
56
+ "data-cy": finalDataCy,
57
+ "data-testid": finalTestId,
58
+ ...props
52
59
  }
53
60
  );
54
61
  };
55
- f.displayName = "DialogHeader";
56
- const N = ({
57
- className: t,
58
- "data-cy": i,
59
- "data-testid": o,
60
- ...e
62
+ DialogHeader.displayName = "DialogHeader";
63
+ const DialogFooter = ({
64
+ className,
65
+ "data-cy": dataCy,
66
+ "data-testid": dataTestId,
67
+ ...props
61
68
  }) => {
62
- const d = i || "dialog-footer", l = o || "dialog-footer";
63
- return /* @__PURE__ */ n(
69
+ const finalDataCy = dataCy || "dialog-footer";
70
+ const finalTestId = dataTestId || "dialog-footer";
71
+ return /* @__PURE__ */ jsx(
64
72
  "div",
65
73
  {
66
- className: r("dialog-footer", t),
67
- "data-cy": d,
68
- "data-testid": l,
69
- ...e
74
+ className: cn("dialog-footer", className),
75
+ "data-cy": finalDataCy,
76
+ "data-testid": finalTestId,
77
+ ...props
70
78
  }
71
79
  );
72
80
  };
73
- N.displayName = "DialogFooter";
74
- const C = c(
75
- ({ className: t, "data-cy": i, "data-testid": o, ...e }, d) => {
76
- const l = i || "dialog-title", s = o || "dialog-title";
77
- return /* @__PURE__ */ n(
78
- a.Title,
81
+ DialogFooter.displayName = "DialogFooter";
82
+ const DialogTitle = forwardRef(
83
+ ({ className, "data-cy": dataCy, "data-testid": dataTestId, ...props }, ref) => {
84
+ const finalDataCy = dataCy || "dialog-title";
85
+ const finalTestId = dataTestId || "dialog-title";
86
+ return /* @__PURE__ */ jsx(
87
+ DialogPrimitive.Title,
79
88
  {
80
- ref: d,
81
- className: r("dialog-title", t),
82
- "data-cy": l,
83
- "data-testid": s,
84
- ...e
89
+ ref,
90
+ className: cn("dialog-title", className),
91
+ "data-cy": finalDataCy,
92
+ "data-testid": finalTestId,
93
+ ...props
85
94
  }
86
95
  );
87
96
  }
88
97
  );
89
- C.displayName = a.Title.displayName;
90
- const T = c(({ className: t, "data-cy": i, "data-testid": o, ...e }, d) => {
91
- const l = i || "dialog-description", s = o || "dialog-description";
92
- return /* @__PURE__ */ n(
93
- a.Description,
98
+ DialogTitle.displayName = DialogPrimitive.Title.displayName;
99
+ const DialogDescription = forwardRef(({ className, "data-cy": dataCy, "data-testid": dataTestId, ...props }, ref) => {
100
+ const finalDataCy = dataCy || "dialog-description";
101
+ const finalTestId = dataTestId || "dialog-description";
102
+ return /* @__PURE__ */ jsx(
103
+ DialogPrimitive.Description,
94
104
  {
95
- ref: d,
96
- className: r("dialog-description", t),
97
- "data-cy": l,
98
- "data-testid": s,
99
- ...e
105
+ ref,
106
+ className: cn("dialog-description", className),
107
+ "data-cy": finalDataCy,
108
+ "data-testid": finalTestId,
109
+ ...props
100
110
  }
101
111
  );
102
112
  });
103
- T.displayName = a.Description.displayName;
113
+ DialogDescription.displayName = DialogPrimitive.Description.displayName;
104
114
  export {
105
- x as Dialog,
106
- P as DialogClose,
107
- D as DialogContent,
108
- T as DialogDescription,
109
- N as DialogFooter,
110
- f as DialogHeader,
111
- g as DialogOverlay,
112
- p as DialogPortal,
113
- C as DialogTitle,
114
- O as DialogTrigger
115
+ Dialog,
116
+ DialogClose,
117
+ DialogContent,
118
+ DialogDescription,
119
+ DialogFooter,
120
+ DialogHeader,
121
+ DialogOverlay,
122
+ DialogPortal,
123
+ DialogTitle,
124
+ DialogTrigger
115
125
  };
package/dist/index16.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const y=require("react/jsx-runtime"),$=require("react"),S=require("./index17.cjs");;/* empty css */const a=$.forwardRef(({direction:t="vertical",spacing:s="4",align:e="stretch",justify:c="start",wrap:r=!1,className:i,children:n,"data-cy":d,"data-testid":k,...l},u)=>{const o=d||`stack-${t}`,f=k||`stack-${t}`;return y.jsx("div",{ref:u,className:S.cn("stack",`stack--${t}`,`stack--spacing-${s}`,`stack--align-${e}`,`stack--justify-${c}`,r&&"stack--wrap",i),"data-cy":o,"data-testid":f,...l,children:n})});a.displayName="Stack";exports.Stack=a;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const t=require("react/jsx-runtime"),a=require("react"),e=require("./index17.cjs");;/* empty css */const s=a.forwardRef(({direction:a="vertical",spacing:s="4",align:c="stretch",justify:r="start",wrap:i=!1,className:n,children:d,"data-cy":l,"data-testid":o,...u},k)=>{const p=l||`stack-${a}`,j=o||`stack-${a}`;return t.jsx("div",{ref:k,className:e.cn("stack",`stack--${a}`,`stack--spacing-${s}`,`stack--align-${c}`,`stack--justify-${r}`,i&&"stack--wrap",n),"data-cy":p,"data-testid":j,...u,children:d})});s.displayName="Stack",exports.Stack=s;
package/dist/index16.js CHANGED
@@ -1,43 +1,44 @@
1
- import { jsx as l } from "react/jsx-runtime";
2
- import { forwardRef as n } from "react";
3
- import { cn as $ } from "./index17.js";
1
+ import { jsx } from "react/jsx-runtime";
2
+ import { forwardRef } from "react";
3
+ import { cn } from "./index17.js";
4
4
  /* empty css */
5
- const y = n(
5
+ const Stack = forwardRef(
6
6
  ({
7
- direction: a = "vertical",
8
- spacing: t = "4",
9
- align: s = "stretch",
10
- justify: c = "start",
11
- wrap: r = !1,
12
- className: i,
13
- children: k,
14
- "data-cy": o,
15
- "data-testid": e,
16
- ...f
17
- }, m) => {
18
- const d = o || `stack-${a}`, p = e || `stack-${a}`;
19
- return /* @__PURE__ */ l(
7
+ direction = "vertical",
8
+ spacing = "4",
9
+ align = "stretch",
10
+ justify = "start",
11
+ wrap = false,
12
+ className,
13
+ children,
14
+ "data-cy": dataCy,
15
+ "data-testid": dataTestId,
16
+ ...props
17
+ }, ref) => {
18
+ const finalDataCy = dataCy || `stack-${direction}`;
19
+ const finalTestId = dataTestId || `stack-${direction}`;
20
+ return /* @__PURE__ */ jsx(
20
21
  "div",
21
22
  {
22
- ref: m,
23
- className: $(
23
+ ref,
24
+ className: cn(
24
25
  "stack",
25
- `stack--${a}`,
26
- `stack--spacing-${t}`,
27
- `stack--align-${s}`,
28
- `stack--justify-${c}`,
29
- r && "stack--wrap",
30
- i
26
+ `stack--${direction}`,
27
+ `stack--spacing-${spacing}`,
28
+ `stack--align-${align}`,
29
+ `stack--justify-${justify}`,
30
+ wrap && "stack--wrap",
31
+ className
31
32
  ),
32
- "data-cy": d,
33
- "data-testid": p,
34
- ...f,
35
- children: k
33
+ "data-cy": finalDataCy,
34
+ "data-testid": finalTestId,
35
+ ...props,
36
+ children
36
37
  }
37
38
  );
38
39
  }
39
40
  );
40
- y.displayName = "Stack";
41
+ Stack.displayName = "Stack";
41
42
  export {
42
- y as Stack
43
+ Stack
43
44
  };
package/dist/index17.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});function t(...e){return e.filter(Boolean).join(" ")}let n=0;function r(e="id"){return n+=1,`${e}-${n}`}exports.cn=t;exports.generateId=r;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("clsx"),r=require("tailwind-merge");let t=0;exports.cn=function(...t){return r.twMerge(e.clsx(t))},exports.generateId=function(e="id"){return t+=1,`${e}-${t}`};
package/dist/index17.js CHANGED
@@ -1,11 +1,14 @@
1
- function t(...n) {
2
- return n.filter(Boolean).join(" ");
1
+ import { clsx } from "clsx";
2
+ import { twMerge } from "tailwind-merge";
3
+ function cn(...inputs) {
4
+ return twMerge(clsx(inputs));
3
5
  }
4
- let e = 0;
5
- function r(n = "id") {
6
- return e += 1, `${n}-${e}`;
6
+ let idCounter = 0;
7
+ function generateId(prefix = "id") {
8
+ idCounter += 1;
9
+ return `${prefix}-${idCounter}`;
7
10
  }
8
11
  export {
9
- t as cn,
10
- r as generateId
12
+ cn,
13
+ generateId
11
14
  };
package/dist/index2.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const s=require("react/jsx-runtime"),m=require("react"),y=require("./index17.cjs");;/* empty css */const n=m.forwardRef(({variant:t="primary-workspace",fullWidth:r=!1,icon:e,className:a,children:c,disabled:o,"data-testid":u,"data-cy":d,...i},l)=>{const b=y.cn("btn",`btn--${t}`,r&&"btn--full-width",a);return s.jsxs("button",{ref:l,disabled:o,className:b,"data-testid":u||`button-${t}`,"data-cy":d||`button-${t}`,...i,children:[e&&s.jsx("span",{className:"btn__icon",children:e}),c]})});n.displayName="Button";exports.Button=n;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const t=require("react/jsx-runtime"),e=require("react"),r=require("./index17.cjs");;/* empty css */const a=e.forwardRef(({variant:e="primary-workspace",fullWidth:a=!1,icon:n,className:s,children:i,disabled:c,"data-testid":d,"data-cy":o,...l},u)=>{const b=r.cn("btn",`btn--${e}`,a&&"btn--full-width",s);return t.jsxs("button",{ref:u,disabled:c,className:b,"data-testid":d||`button-${e}`,"data-cy":o||`button-${e}`,...l,children:[n&&t.jsx("span",{className:"btn__icon",children:n}),i]})});a.displayName="Button",exports.Button=a;
package/dist/index2.js CHANGED
@@ -1,38 +1,38 @@
1
- import { jsxs as l, jsx as p } from "react/jsx-runtime";
2
- import { forwardRef as b } from "react";
3
- import { cn as f } from "./index17.js";
1
+ import { jsxs, jsx } from "react/jsx-runtime";
2
+ import { forwardRef } from "react";
3
+ import { cn } from "./index17.js";
4
4
  /* empty css */
5
- const u = b(
5
+ const Button = forwardRef(
6
6
  ({
7
- variant: t = "primary-workspace",
8
- fullWidth: o = !1,
9
- icon: s,
10
- className: a,
11
- children: r,
12
- disabled: n,
13
- "data-testid": e,
14
- "data-cy": c,
15
- ...d
16
- }, m) => {
17
- const i = f("btn", `btn--${t}`, o && "btn--full-width", a);
18
- return /* @__PURE__ */ l(
7
+ variant = "primary-workspace",
8
+ fullWidth = false,
9
+ icon,
10
+ className,
11
+ children,
12
+ disabled,
13
+ "data-testid": dataTestId,
14
+ "data-cy": dataCy,
15
+ ...props
16
+ }, ref) => {
17
+ const classes = cn("btn", `btn--${variant}`, fullWidth && "btn--full-width", className);
18
+ return /* @__PURE__ */ jsxs(
19
19
  "button",
20
20
  {
21
- ref: m,
22
- disabled: n,
23
- className: i,
24
- "data-testid": e || `button-${t}`,
25
- "data-cy": c || `button-${t}`,
26
- ...d,
21
+ ref,
22
+ disabled,
23
+ className: classes,
24
+ "data-testid": dataTestId || `button-${variant}`,
25
+ "data-cy": dataCy || `button-${variant}`,
26
+ ...props,
27
27
  children: [
28
- s && /* @__PURE__ */ p("span", { className: "btn__icon", children: s }),
29
- r
28
+ icon && /* @__PURE__ */ jsx("span", { className: "btn__icon", children: icon }),
29
+ children
30
30
  ]
31
31
  }
32
32
  );
33
33
  }
34
34
  );
35
- u.displayName = "Button";
35
+ Button.displayName = "Button";
36
36
  export {
37
- u as Button
37
+ Button
38
38
  };
package/dist/index3.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const c=require("react/jsx-runtime"),n=require("react"),j=require("./index17.cjs");;/* empty css */const L=/^[^\s@]+@[^\s@]+\.[^\s@]+$/,w=n.forwardRef(({validateEmail:m=!0,invalidEmailMessage:y="Not a valid email address",onValidationChange:r,error:N,onChange:p,label:f,helperText:o,fullWidth:$=!1,className:_,id:x,"data-cy":q,"data-testid":S,...i},B)=>{const[R,I]=n.useState(),[h,F]=n.useState(!1),A=n.useId(),l=x||A,v=`${l}-error`,E=`${l}-helper`,s=q||"email-input",a=S||"email-input",b=t=>t?L.test(t):!0,D=t=>{const u=t.target.value;if(m&&h){const d=b(u);I(d?void 0:y),r==null||r(d)}p==null||p(t)},G=t=>{var u;if(F(!0),m){const d=b(t.target.value);I(d?void 0:y),r==null||r(d)}(u=i.onBlur)==null||u.call(i,t)},e=N||R;return c.jsxs("div",{className:j.cn("input-wrapper",$&&"input-wrapper--full-width"),"data-cy":`${s}-wrapper`,"data-testid":`${a}-wrapper`,children:[f&&c.jsx("label",{htmlFor:l,className:"input__label","data-cy":`${s}-label`,"data-testid":`${a}-label`,children:f}),c.jsx("input",{ref:B,id:l,type:"email",className:j.cn("input",e&&"input--error",$&&"input--full-width",_),"aria-invalid":e?"true":"false","aria-describedby":e?v:o?E:void 0,"data-cy":s,"data-testid":a,onChange:D,onBlur:G,...i}),e&&c.jsx("span",{id:v,className:"input__error",role:"alert","data-cy":`${s}-error`,"data-testid":`${a}-error`,children:e}),o&&!e&&c.jsx("span",{id:E,className:"input__helper","data-cy":`${s}-helper`,"data-testid":`${a}-helper`,children:o})]})});w.displayName="EmailInput";exports.EmailInput=w;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),a=require("react"),t=require("./index17.cjs");;/* empty css */const r=/^[^\s@]+@[^\s@]+\.[^\s@]+$/,l=a.forwardRef(({validateEmail:l=!0,invalidEmailMessage:i="Not a valid email address",onValidationChange:s,error:d,onChange:n,label:u,helperText:p,fullWidth:c=!1,className:o,id:m,"data-cy":h,"data-testid":v,...x},y)=>{const[$,f]=a.useState(),[b,j]=a.useState(!1),g=a.useId(),N=m||g,w=`${N}-error`,_=`${N}-helper`,q=h||"email-input",E=v||"email-input",S=e=>!e||r.test(e),C=d||$;return e.jsxs("div",{className:t.cn("input-wrapper",c&&"input-wrapper--full-width"),"data-cy":`${q}-wrapper`,"data-testid":`${E}-wrapper`,children:[u&&e.jsx("label",{htmlFor:N,className:"input__label","data-cy":`${q}-label`,"data-testid":`${E}-label`,children:u}),e.jsx("input",{ref:y,id:N,type:"email",className:t.cn("input",C&&"input--error",c&&"input--full-width",o),"aria-invalid":C?"true":"false","aria-describedby":C?w:p?_:void 0,"data-cy":q,"data-testid":E,onChange:e=>{const a=e.target.value;if(l&&b){const e=S(a);f(e?void 0:i),null==s||s(e)}null==n||n(e)},onBlur:e=>{var a;if(j(!0),l){const a=S(e.target.value);f(a?void 0:i),null==s||s(a)}null==(a=x.onBlur)||a.call(x,e)},...x}),C&&e.jsx("span",{id:w,className:"input__error",role:"alert","data-cy":`${q}-error`,"data-testid":`${E}-error`,children:C}),p&&!C&&e.jsx("span",{id:_,className:"input__helper","data-cy":`${q}-helper`,"data-testid":`${E}-helper`,children:p})]})});l.displayName="EmailInput",exports.EmailInput=l;
package/dist/index3.js CHANGED
@@ -1,95 +1,113 @@
1
- import { jsxs as S, jsx as u } from "react/jsx-runtime";
2
- import { forwardRef as X, useState as E, useId as k } from "react";
3
- import { cn as N } 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 q = /^[^\s@]+@[^\s@]+\.[^\s@]+$/, z = X(
5
+ const EMAIL_REGEX = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
6
+ const EmailInput = forwardRef(
6
7
  ({
7
- validateEmail: m = !0,
8
- invalidEmailMessage: n = "Not a valid email address",
9
- onValidationChange: r,
10
- error: _,
11
- onChange: p,
12
- label: f,
13
- helperText: o,
14
- fullWidth: y = !1,
15
- className: b,
16
- id: B,
17
- "data-cy": h,
18
- "data-testid": j,
19
- ...l
20
- }, F) => {
21
- const [R, $] = E(), [x, A] = E(!1), D = k(), i = B || D, I = `${i}-error`, v = `${i}-helper`, a = h || "email-input", s = j || "email-input", w = (t) => t ? q.test(t) : !0, G = (t) => {
22
- const c = t.target.value;
23
- if (m && x) {
24
- const d = w(c);
25
- $(d ? void 0 : n), r == null || r(d);
8
+ validateEmail = true,
9
+ invalidEmailMessage = "Not a valid email address",
10
+ onValidationChange,
11
+ error: externalError,
12
+ onChange,
13
+ label,
14
+ helperText,
15
+ fullWidth = false,
16
+ className,
17
+ id: providedId,
18
+ "data-cy": dataCy,
19
+ "data-testid": dataTestId,
20
+ ...props
21
+ }, ref) => {
22
+ const [internalError, setInternalError] = useState();
23
+ const [touched, setTouched] = useState(false);
24
+ const generatedId = useId();
25
+ const id = providedId || generatedId;
26
+ const errorId = `${id}-error`;
27
+ const helperId = `${id}-helper`;
28
+ const finalDataCy = dataCy || "email-input";
29
+ const finalTestId = dataTestId || "email-input";
30
+ const validateEmailFormat = (value) => {
31
+ if (!value) return true;
32
+ return EMAIL_REGEX.test(value);
33
+ };
34
+ const handleChange = (e) => {
35
+ const value = e.target.value;
36
+ if (validateEmail && touched) {
37
+ const isValid = validateEmailFormat(value);
38
+ setInternalError(isValid ? void 0 : invalidEmailMessage);
39
+ onValidationChange == null ? void 0 : onValidationChange(isValid);
26
40
  }
27
- p == null || p(t);
28
- }, L = (t) => {
29
- var c;
30
- if (A(!0), m) {
31
- const d = w(t.target.value);
32
- $(d ? void 0 : n), r == null || r(d);
41
+ onChange == null ? void 0 : onChange(e);
42
+ };
43
+ const handleBlur = (e) => {
44
+ var _a;
45
+ setTouched(true);
46
+ if (validateEmail) {
47
+ const isValid = validateEmailFormat(e.target.value);
48
+ setInternalError(isValid ? void 0 : invalidEmailMessage);
49
+ onValidationChange == null ? void 0 : onValidationChange(isValid);
33
50
  }
34
- (c = l.onBlur) == null || c.call(l, t);
35
- }, e = _ || R;
36
- return /* @__PURE__ */ S(
51
+ (_a = props.onBlur) == null ? void 0 : _a.call(props, e);
52
+ };
53
+ const displayError = externalError || internalError;
54
+ return /* @__PURE__ */ jsxs(
37
55
  "div",
38
56
  {
39
- className: N("input-wrapper", y && "input-wrapper--full-width"),
40
- "data-cy": `${a}-wrapper`,
41
- "data-testid": `${s}-wrapper`,
57
+ className: cn("input-wrapper", fullWidth && "input-wrapper--full-width"),
58
+ "data-cy": `${finalDataCy}-wrapper`,
59
+ "data-testid": `${finalTestId}-wrapper`,
42
60
  children: [
43
- f && /* @__PURE__ */ u(
61
+ label && /* @__PURE__ */ jsx(
44
62
  "label",
45
63
  {
46
- htmlFor: i,
64
+ htmlFor: id,
47
65
  className: "input__label",
48
- "data-cy": `${a}-label`,
49
- "data-testid": `${s}-label`,
50
- children: f
66
+ "data-cy": `${finalDataCy}-label`,
67
+ "data-testid": `${finalTestId}-label`,
68
+ children: label
51
69
  }
52
70
  ),
53
- /* @__PURE__ */ u(
71
+ /* @__PURE__ */ jsx(
54
72
  "input",
55
73
  {
56
- ref: F,
57
- id: i,
74
+ ref,
75
+ id,
58
76
  type: "email",
59
- className: N(
77
+ className: cn(
60
78
  "input",
61
- e && "input--error",
62
- y && "input--full-width",
63
- b
79
+ displayError && "input--error",
80
+ fullWidth && "input--full-width",
81
+ className
64
82
  ),
65
- "aria-invalid": e ? "true" : "false",
66
- "aria-describedby": e ? I : o ? v : void 0,
67
- "data-cy": a,
68
- "data-testid": s,
69
- onChange: G,
70
- onBlur: L,
71
- ...l
83
+ "aria-invalid": displayError ? "true" : "false",
84
+ "aria-describedby": displayError ? errorId : helperText ? helperId : void 0,
85
+ "data-cy": finalDataCy,
86
+ "data-testid": finalTestId,
87
+ onChange: handleChange,
88
+ onBlur: handleBlur,
89
+ ...props
72
90
  }
73
91
  ),
74
- e && /* @__PURE__ */ u(
92
+ displayError && /* @__PURE__ */ jsx(
75
93
  "span",
76
94
  {
77
- id: I,
95
+ id: errorId,
78
96
  className: "input__error",
79
97
  role: "alert",
80
- "data-cy": `${a}-error`,
81
- "data-testid": `${s}-error`,
82
- children: e
98
+ "data-cy": `${finalDataCy}-error`,
99
+ "data-testid": `${finalTestId}-error`,
100
+ children: displayError
83
101
  }
84
102
  ),
85
- o && !e && /* @__PURE__ */ u(
103
+ helperText && !displayError && /* @__PURE__ */ jsx(
86
104
  "span",
87
105
  {
88
- id: v,
106
+ id: helperId,
89
107
  className: "input__helper",
90
- "data-cy": `${a}-helper`,
91
- "data-testid": `${s}-helper`,
92
- children: o
108
+ "data-cy": `${finalDataCy}-helper`,
109
+ "data-testid": `${finalTestId}-helper`,
110
+ children: helperText
93
111
  }
94
112
  )
95
113
  ]
@@ -97,7 +115,7 @@ const q = /^[^\s@]+@[^\s@]+\.[^\s@]+$/, z = X(
97
115
  );
98
116
  }
99
117
  );
100
- z.displayName = "EmailInput";
118
+ EmailInput.displayName = "EmailInput";
101
119
  export {
102
- z as EmailInput
120
+ EmailInput
103
121
  };
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});process.env.NODE_ENV;exports.devWarn=e=>{};
@@ -0,0 +1,9 @@
1
+ const isDev = process.env.NODE_ENV !== "production";
2
+ const devWarn = (message) => {
3
+ if (isDev) {
4
+ console.warn(message);
5
+ }
6
+ };
7
+ export {
8
+ devWarn
9
+ };