@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/index6.js CHANGED
@@ -1,169 +1,112 @@
1
- import { jsxs as U, jsx as b } from "react/jsx-runtime";
2
- import { forwardRef as L, useState as x, useId as g } from "react";
3
- import { cn as z } from "./index17.js";
4
- /* empty css */
5
- const y = L(
1
+ import { jsx } from "react/jsx-runtime";
2
+ import { forwardRef, useRef, useMemo, useCallback, useState, useEffect } from "react";
3
+ import { Input } from "./index20.js";
4
+ import { useMergedRef } from "./index21.js";
5
+ const AlphanumericInput = forwardRef(
6
6
  ({
7
- allowHyphen: u = !1,
8
- allowUnderscore: c = !1,
9
- allowSpace: f = !1,
10
- minLength: h,
11
- maxLength: p,
12
- invalidFormatMessage: F = "Only letters and numbers are allowed",
13
- minLengthMessage: M,
14
- maxLengthMessage: O,
15
- onValidationChange: a,
16
- error: Z,
17
- onChange: v,
18
- onKeyDown: t,
19
- label: _,
20
- helperText: I,
21
- fullWidth: E = !1,
22
- className: T,
23
- id: q,
24
- "data-cy": G,
25
- "data-testid": J,
26
- ...m
27
- }, P) => {
28
- const [Q, A] = x(), [X, Y] = x(!1), W = g(), $ = q || W, N = `${$}-error`, B = `${$}-helper`, d = G || "alphanumeric-input", l = J || "alphanumeric-input", j = (r) => {
29
- if (!r) return { isValid: !0 };
30
- let s = "^[a-zA-Z0-9";
31
- if (u && (s += "\\-"), c && (s += "_"), f && (s += " "), s += "]+$", !new RegExp(s).test(r)) {
32
- let R = F;
33
- if (u || c || f) {
34
- const k = ["letters", "numbers"];
35
- u && k.push("hyphens"), c && k.push("underscores"), f && k.push("spaces"), R = `Only ${k.join(", ")} are allowed`;
7
+ allowHyphen = false,
8
+ allowUnderscore = false,
9
+ allowSpace = false,
10
+ minLength,
11
+ maxLength,
12
+ validate,
13
+ onChange,
14
+ "data-cy": dataCy,
15
+ "data-testid": dataTestId,
16
+ ...props
17
+ }, ref) => {
18
+ const inputRef = useRef(null);
19
+ const mergedRef = useMergedRef(ref, inputRef);
20
+ const alphanumericRegex = useMemo(() => {
21
+ let pattern = "^[a-zA-Z0-9";
22
+ if (allowHyphen) pattern += "\\-";
23
+ if (allowUnderscore) pattern += "_";
24
+ if (allowSpace) pattern += " ";
25
+ pattern += "]*$";
26
+ return new RegExp(pattern);
27
+ }, [allowHyphen, allowUnderscore, allowSpace]);
28
+ const characterRegex = useMemo(() => {
29
+ let pattern = "[a-zA-Z0-9";
30
+ if (allowHyphen) pattern += "\\-";
31
+ if (allowUnderscore) pattern += "_";
32
+ if (allowSpace) pattern += " ";
33
+ pattern += "]";
34
+ return new RegExp(pattern);
35
+ }, [allowHyphen, allowUnderscore, allowSpace]);
36
+ const alphanumericValidation = useCallback(
37
+ (value) => {
38
+ if (!value) return void 0;
39
+ if (!alphanumericRegex.test(value)) {
40
+ let allowedChars = "letters and numbers";
41
+ const extras = [];
42
+ if (allowHyphen) extras.push("hyphens");
43
+ if (allowUnderscore) extras.push("underscores");
44
+ if (allowSpace) extras.push("spaces");
45
+ if (extras.length > 0) {
46
+ allowedChars += `, ${extras.join(", ")}`;
47
+ }
48
+ return `Only ${allowedChars} are allowed`;
36
49
  }
37
- return { isValid: !1, error: R };
38
- }
39
- return h !== void 0 && r.length < h ? {
40
- isValid: !1,
41
- error: M || `Must be at least ${h} characters`
42
- } : p !== void 0 && r.length > p ? {
43
- isValid: !1,
44
- error: O || `Must be at most ${p} characters`
45
- } : { isValid: !0 };
46
- }, H = (r) => {
47
- const s = [
48
- "Backspace",
49
- "Delete",
50
- "Tab",
51
- "Escape",
52
- "Enter",
53
- "ArrowLeft",
54
- "ArrowRight",
55
- "Home",
56
- "End"
57
- ];
58
- if (r.ctrlKey || r.metaKey) {
59
- t == null || t(r);
60
- return;
61
- }
62
- if (s.includes(r.key)) {
63
- t == null || t(r);
64
- return;
65
- }
66
- if (f && r.key === " ") {
67
- t == null || t(r);
68
- return;
69
- }
70
- if (u && r.key === "-") {
71
- t == null || t(r);
72
- return;
73
- }
74
- if (c && r.key === "_") {
75
- t == null || t(r);
76
- return;
77
- }
78
- if (r.key >= "a" && r.key <= "z" || r.key >= "A" && r.key <= "Z") {
79
- t == null || t(r);
80
- return;
81
- }
82
- if (r.key >= "0" && r.key <= "9") {
83
- t == null || t(r);
84
- return;
85
- }
86
- r.preventDefault();
87
- }, S = (r) => {
88
- const s = r.target.value;
89
- if (X) {
90
- const i = j(s);
91
- A(i.error), a == null || a(i.isValid);
50
+ if (minLength !== void 0 && value.length < minLength) {
51
+ return `Must be at least ${minLength} characters`;
52
+ }
53
+ if (maxLength !== void 0 && value.length > maxLength) {
54
+ return `Must be at most ${maxLength} characters`;
55
+ }
56
+ return void 0;
57
+ },
58
+ [alphanumericRegex, minLength, maxLength, allowHyphen, allowUnderscore, allowSpace]
59
+ );
60
+ const combinedValidation = useCallback(
61
+ (value) => {
62
+ if (!validate) return alphanumericValidation(value);
63
+ return alphanumericValidation(value) || validate(value);
64
+ },
65
+ [alphanumericValidation, validate]
66
+ );
67
+ const [pendingCursorPosition, setPendingCursorPosition] = useState(null);
68
+ useEffect(() => {
69
+ if (pendingCursorPosition !== null && inputRef.current) {
70
+ inputRef.current.setSelectionRange(pendingCursorPosition, pendingCursorPosition);
71
+ setPendingCursorPosition(null);
92
72
  }
93
- v == null || v(r);
94
- }, V = (r) => {
95
- var i;
96
- Y(!0);
97
- const s = j(r.target.value);
98
- A(s.error), a == null || a(s.isValid), (i = m.onBlur) == null || i.call(m, r);
99
- }, e = Z || Q;
100
- return /* @__PURE__ */ U(
101
- "div",
73
+ }, [props.value, pendingCursorPosition]);
74
+ const handleChange = useCallback(
75
+ (e) => {
76
+ const input = e.target;
77
+ const value = input.value;
78
+ const cursorPosition = input.selectionStart || 0;
79
+ const filteredValue = value.split("").filter((char) => characterRegex.test(char)).join("");
80
+ const removedBeforeCursor = value.slice(0, cursorPosition).split("").filter((char) => !characterRegex.test(char)).length;
81
+ const newPosition = cursorPosition - removedBeforeCursor;
82
+ input.value = filteredValue;
83
+ const isControlled = props.value !== void 0;
84
+ if (isControlled) {
85
+ setPendingCursorPosition(newPosition);
86
+ } else {
87
+ input.setSelectionRange(newPosition, newPosition);
88
+ }
89
+ onChange == null ? void 0 : onChange(e);
90
+ },
91
+ [characterRegex, onChange, props.value]
92
+ );
93
+ return /* @__PURE__ */ jsx(
94
+ Input,
102
95
  {
103
- className: z("input-wrapper", E && "input-wrapper--full-width"),
104
- "data-cy": `${d}-wrapper`,
105
- "data-testid": `${l}-wrapper`,
106
- children: [
107
- _ && /* @__PURE__ */ b(
108
- "label",
109
- {
110
- htmlFor: $,
111
- className: "input__label",
112
- "data-cy": `${d}-label`,
113
- "data-testid": `${l}-label`,
114
- children: _
115
- }
116
- ),
117
- /* @__PURE__ */ b(
118
- "input",
119
- {
120
- ref: P,
121
- id: $,
122
- type: "text",
123
- className: z(
124
- "input",
125
- e && "input--error",
126
- E && "input--full-width",
127
- T
128
- ),
129
- "aria-invalid": e ? "true" : "false",
130
- "aria-describedby": e ? N : I ? B : void 0,
131
- "data-cy": d,
132
- "data-testid": l,
133
- onChange: S,
134
- onBlur: V,
135
- onKeyDown: H,
136
- maxLength: p,
137
- ...m
138
- }
139
- ),
140
- e && /* @__PURE__ */ b(
141
- "span",
142
- {
143
- id: N,
144
- className: "input__error",
145
- role: "alert",
146
- "data-cy": `${d}-error`,
147
- "data-testid": `${l}-error`,
148
- children: e
149
- }
150
- ),
151
- I && !e && /* @__PURE__ */ b(
152
- "span",
153
- {
154
- id: B,
155
- className: "input__helper",
156
- "data-cy": `${d}-helper`,
157
- "data-testid": `${l}-helper`,
158
- children: I
159
- }
160
- )
161
- ]
96
+ ref: mergedRef,
97
+ type: "text",
98
+ minLength,
99
+ maxLength,
100
+ validate: combinedValidation,
101
+ onChange: handleChange,
102
+ "data-cy": dataCy || "alphanumeric-input",
103
+ "data-testid": dataTestId || "alphanumeric-input",
104
+ ...props
162
105
  }
163
106
  );
164
107
  }
165
108
  );
166
- y.displayName = "AlphanumericInput";
109
+ AlphanumericInput.displayName = "AlphanumericInput";
167
110
  export {
168
- y as AlphanumericInput
111
+ AlphanumericInput
169
112
  };
package/dist/index7.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const a=require("react/jsx-runtime"),i=require("react"),k=require("./index17.cjs");;/* empty css */const f=i.forwardRef(({label:t,error:e,helperText:n,indeterminate:o=!1,className:y,id:_,required:l,disabled:b,checked:$,"data-cy":m,"data-testid":j,...v},c)=>{const N=i.useId(),d=_||N,p=`${d}-error`,x=`${d}-helper`,s=m||"checkbox",r=j||"checkbox",u=i.useRef(null),w=i.useCallback(h=>{u.current=h,c&&(typeof c=="function"?c(h):"current"in c&&(c.current=h))},[c]);i.useEffect(()=>{u.current&&(u.current.indeterminate=o)},[o]);const C=t&&l&&!t.includes("*")?`${t} *`:t;return a.jsxs("div",{className:k.cn("checkbox-wrapper",b&&"checkbox-wrapper--disabled"),"data-cy":`${s}-wrapper`,"data-testid":`${r}-wrapper`,children:[a.jsxs("div",{className:"checkbox__container",children:[a.jsx("input",{ref:w,id:d,type:"checkbox",checked:$,className:k.cn("checkbox__input",e&&"checkbox__input--error",y),"aria-invalid":e?"true":"false","aria-required":l?"true":void 0,"aria-describedby":e?p:n?x:void 0,"data-cy":s,"data-testid":r,"data-indeterminate":o?"true":void 0,disabled:b,required:l,...v}),t&&a.jsx("label",{htmlFor:d,className:"checkbox__label","data-cy":`${s}-label`,"data-testid":`${r}-label`,children:C})]}),e&&a.jsx("span",{id:p,className:"checkbox__error",role:"alert","data-cy":`${s}-error`,"data-testid":`${r}-error`,children:e}),n&&!e&&a.jsx("span",{id:x,className:"checkbox__helper","data-cy":`${s}-helper`,"data-testid":`${r}-helper`,children:n})]})});f.displayName="Checkbox";exports.Checkbox=f;
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 c=r.forwardRef(({label:c,error:t,helperText:d,indeterminate:i=!1,className:s,id:l,required:n,disabled:o,checked:u,"data-cy":b,"data-testid":h,...x},p)=>{const k=r.useId(),m=l||k,y=`${m}-error`,_=`${m}-helper`,$=b||"checkbox",f=h||"checkbox",j=r.useRef(null),N=r.useCallback(e=>{j.current=e,p&&("function"==typeof p?p(e):"current"in p&&(p.current=e))},[p]);r.useEffect(()=>{j.current&&(j.current.indeterminate=i)},[i]);const q=c&&n&&!c.includes("*")?`${c} *`:c;return e.jsxs("div",{className:a.cn("checkbox-wrapper",o&&"checkbox-wrapper--disabled"),"data-cy":`${$}-wrapper`,"data-testid":`${f}-wrapper`,children:[e.jsxs("div",{className:"checkbox__container",children:[e.jsx("input",{ref:N,id:m,type:"checkbox",checked:u,className:a.cn("checkbox__input",t&&"checkbox__input--error",s),"aria-invalid":t?"true":"false","aria-required":n?"true":void 0,"aria-describedby":t?y:d?_:void 0,"data-cy":$,"data-testid":f,"data-indeterminate":i?"true":void 0,disabled:o,required:n,...x}),c&&e.jsx("label",{htmlFor:m,className:"checkbox__label","data-cy":`${$}-label`,"data-testid":`${f}-label`,children:q})]}),t&&e.jsx("span",{id:y,className:"checkbox__error",role:"alert","data-cy":`${$}-error`,"data-testid":`${f}-error`,children:t}),d&&!t&&e.jsx("span",{id:_,className:"checkbox__helper","data-cy":`${$}-helper`,"data-testid":`${f}-helper`,children:d})]})});c.displayName="Checkbox",exports.Checkbox=c;
package/dist/index7.js CHANGED
@@ -1,89 +1,104 @@
1
- import { jsxs as f, jsx as i } from "react/jsx-runtime";
2
- import { forwardRef as C, useId as R, useRef as j, useCallback as g, useEffect as D } from "react";
3
- import { cn as k } from "./index17.js";
1
+ import { jsxs, jsx } from "react/jsx-runtime";
2
+ import { forwardRef, useId, useRef, useCallback, useEffect } from "react";
3
+ import { cn } from "./index17.js";
4
4
  /* empty css */
5
- const E = C(
5
+ const Checkbox = forwardRef(
6
6
  ({
7
- label: c,
8
- error: a,
9
- helperText: s,
10
- indeterminate: o = !1,
11
- className: m,
12
- id: x,
13
- required: n,
14
- disabled: h,
15
- checked: y,
16
- "data-cy": _,
17
- "data-testid": $,
18
- ...N
19
- }, e) => {
20
- const v = R(), d = x || v, u = `${d}-error`, b = `${d}-helper`, t = _ || "checkbox", r = $ || "checkbox", l = j(null), w = g(
21
- (p) => {
22
- l.current = p, e && (typeof e == "function" ? e(p) : "current" in e && (e.current = p));
7
+ label,
8
+ error,
9
+ helperText,
10
+ indeterminate = false,
11
+ className,
12
+ id: providedId,
13
+ required,
14
+ disabled,
15
+ checked,
16
+ "data-cy": dataCy,
17
+ "data-testid": dataTestId,
18
+ ...props
19
+ }, ref) => {
20
+ const generatedId = useId();
21
+ const id = providedId || generatedId;
22
+ const errorId = `${id}-error`;
23
+ const helperId = `${id}-helper`;
24
+ const finalDataCy = dataCy || "checkbox";
25
+ const finalTestId = dataTestId || "checkbox";
26
+ const internalRef = useRef(null);
27
+ const combinedRef = useCallback(
28
+ (element) => {
29
+ internalRef.current = element;
30
+ if (!ref) return;
31
+ if (typeof ref === "function") {
32
+ ref(element);
33
+ } else if ("current" in ref) {
34
+ ref.current = element;
35
+ }
23
36
  },
24
- [e]
37
+ [ref]
25
38
  );
26
- D(() => {
27
- l.current && (l.current.indeterminate = o);
28
- }, [o]);
29
- const I = c && n && !c.includes("*") ? `${c} *` : c;
30
- return /* @__PURE__ */ f(
39
+ useEffect(() => {
40
+ if (internalRef.current) {
41
+ internalRef.current.indeterminate = indeterminate;
42
+ }
43
+ }, [indeterminate]);
44
+ const displayLabel = label && required && !label.includes("*") ? `${label} *` : label;
45
+ return /* @__PURE__ */ jsxs(
31
46
  "div",
32
47
  {
33
- className: k("checkbox-wrapper", h && "checkbox-wrapper--disabled"),
34
- "data-cy": `${t}-wrapper`,
35
- "data-testid": `${r}-wrapper`,
48
+ className: cn("checkbox-wrapper", disabled && "checkbox-wrapper--disabled"),
49
+ "data-cy": `${finalDataCy}-wrapper`,
50
+ "data-testid": `${finalTestId}-wrapper`,
36
51
  children: [
37
- /* @__PURE__ */ f("div", { className: "checkbox__container", children: [
38
- /* @__PURE__ */ i(
52
+ /* @__PURE__ */ jsxs("div", { className: "checkbox__container", children: [
53
+ /* @__PURE__ */ jsx(
39
54
  "input",
40
55
  {
41
- ref: w,
42
- id: d,
56
+ ref: combinedRef,
57
+ id,
43
58
  type: "checkbox",
44
- checked: y,
45
- className: k("checkbox__input", a && "checkbox__input--error", m),
46
- "aria-invalid": a ? "true" : "false",
47
- "aria-required": n ? "true" : void 0,
48
- "aria-describedby": a ? u : s ? b : void 0,
49
- "data-cy": t,
50
- "data-testid": r,
51
- "data-indeterminate": o ? "true" : void 0,
52
- disabled: h,
53
- required: n,
54
- ...N
59
+ checked,
60
+ className: cn("checkbox__input", error && "checkbox__input--error", className),
61
+ "aria-invalid": error ? "true" : "false",
62
+ "aria-required": required ? "true" : void 0,
63
+ "aria-describedby": error ? errorId : helperText ? helperId : void 0,
64
+ "data-cy": finalDataCy,
65
+ "data-testid": finalTestId,
66
+ "data-indeterminate": indeterminate ? "true" : void 0,
67
+ disabled,
68
+ required,
69
+ ...props
55
70
  }
56
71
  ),
57
- c && /* @__PURE__ */ i(
72
+ label && /* @__PURE__ */ jsx(
58
73
  "label",
59
74
  {
60
- htmlFor: d,
75
+ htmlFor: id,
61
76
  className: "checkbox__label",
62
- "data-cy": `${t}-label`,
63
- "data-testid": `${r}-label`,
64
- children: I
77
+ "data-cy": `${finalDataCy}-label`,
78
+ "data-testid": `${finalTestId}-label`,
79
+ children: displayLabel
65
80
  }
66
81
  )
67
82
  ] }),
68
- a && /* @__PURE__ */ i(
83
+ error && /* @__PURE__ */ jsx(
69
84
  "span",
70
85
  {
71
- id: u,
86
+ id: errorId,
72
87
  className: "checkbox__error",
73
88
  role: "alert",
74
- "data-cy": `${t}-error`,
75
- "data-testid": `${r}-error`,
76
- children: a
89
+ "data-cy": `${finalDataCy}-error`,
90
+ "data-testid": `${finalTestId}-error`,
91
+ children: error
77
92
  }
78
93
  ),
79
- s && !a && /* @__PURE__ */ i(
94
+ helperText && !error && /* @__PURE__ */ jsx(
80
95
  "span",
81
96
  {
82
- id: b,
97
+ id: helperId,
83
98
  className: "checkbox__helper",
84
- "data-cy": `${t}-helper`,
85
- "data-testid": `${r}-helper`,
86
- children: s
99
+ "data-cy": `${finalDataCy}-helper`,
100
+ "data-testid": `${finalTestId}-helper`,
101
+ children: helperText
87
102
  }
88
103
  )
89
104
  ]
@@ -91,7 +106,7 @@ const E = C(
91
106
  );
92
107
  }
93
108
  );
94
- E.displayName = "Checkbox";
109
+ Checkbox.displayName = "Checkbox";
95
110
  export {
96
- E as Checkbox
111
+ Checkbox
97
112
  };
package/dist/index8.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),n=require("react"),_=require("./index17.cjs");;/* empty css */const $=n.forwardRef(({label:r,error:d,helperText:c,className:f,id:h,required:l,disabled:p,checked:m,"data-cy":j,"data-testid":R,...b},a)=>{const N=n.useId(),s=h||N,u=`${s}-error`,y=`${s}-helper`,t=j||"radio",i=R||"radio",x=n.useRef(null),w=n.useCallback(o=>{x.current=o,a&&(typeof a=="function"?a(o):"current"in a&&(a.current=o))},[a]),I=r&&l&&!r.includes("*")?`${r} *`:r;return e.jsxs("div",{className:_.cn("radio-wrapper",p&&"radio-wrapper--disabled"),"data-cy":`${t}-wrapper`,"data-testid":`${i}-wrapper`,children:[e.jsxs("div",{className:"radio__container",children:[e.jsx("input",{ref:w,id:s,type:"radio",checked:m,className:_.cn("radio__input",d&&"radio__input--error",f),"aria-describedby":d?u:c?y:void 0,"data-cy":t,"data-testid":i,disabled:p,required:l,...b}),r&&e.jsx("label",{htmlFor:s,className:"radio__label","data-cy":`${t}-label`,"data-testid":`${i}-label`,children:I})]}),d&&e.jsx("span",{id:u,className:"radio__error",role:"alert","data-cy":`${t}-error`,"data-testid":`${i}-error`,children:d}),c&&!d&&e.jsx("span",{id:y,className:"radio__helper","data-cy":`${t}-helper`,"data-testid":`${i}-helper`,children:c})]})});$.displayName="Radio";exports.Radio=$;
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 d=r.forwardRef(({label:d,error:i,helperText:t,className:s,id:l,required:c,disabled:o,checked:n,"data-cy":p,"data-testid":u,...b},h)=>{const x=r.useId(),y=l||x,_=`${y}-error`,m=`${y}-helper`,$=p||"radio",j=u||"radio",N=r.useRef(null),f=r.useCallback(e=>{N.current=e,h&&("function"==typeof h?h(e):"current"in h&&(h.current=e))},[h]),q=d&&c&&!d.includes("*")?`${d} *`:d;return e.jsxs("div",{className:a.cn("radio-wrapper",o&&"radio-wrapper--disabled"),"data-cy":`${$}-wrapper`,"data-testid":`${j}-wrapper`,children:[e.jsxs("div",{className:"radio__container",children:[e.jsx("input",{ref:f,id:y,type:"radio",checked:n,className:a.cn("radio__input",i&&"radio__input--error",s),"aria-describedby":i?_:t?m:void 0,"data-cy":$,"data-testid":j,disabled:o,required:c,...b}),d&&e.jsx("label",{htmlFor:y,className:"radio__label","data-cy":`${$}-label`,"data-testid":`${j}-label`,children:q})]}),i&&e.jsx("span",{id:_,className:"radio__error",role:"alert","data-cy":`${$}-error`,"data-testid":`${j}-error`,children:i}),t&&!i&&e.jsx("span",{id:m,className:"radio__helper","data-cy":`${$}-helper`,"data-testid":`${j}-helper`,children:t})]})});d.displayName="Radio",exports.Radio=d;
package/dist/index8.js CHANGED
@@ -1,81 +1,95 @@
1
- import { jsxs as u, jsx as s } from "react/jsx-runtime";
2
- import { forwardRef as j, useId as C, useRef as g, useCallback as k } from "react";
3
- import { cn as y } from "./index17.js";
1
+ import { jsxs, jsx } from "react/jsx-runtime";
2
+ import { forwardRef, useId, useRef, useCallback } from "react";
3
+ import { cn } from "./index17.js";
4
4
  /* empty css */
5
- const x = j(
5
+ const Radio = forwardRef(
6
6
  ({
7
- label: d,
8
- error: r,
9
- helperText: o,
10
- className: _,
11
- id: f,
12
- required: n,
13
- disabled: l,
14
- checked: $,
15
- "data-cy": h,
16
- "data-testid": N,
17
- ...R
18
- }, a) => {
19
- const b = C(), e = f || b, p = `${e}-error`, m = `${e}-helper`, t = h || "radio", i = N || "radio", w = g(null), I = k(
20
- (c) => {
21
- w.current = c, a && (typeof a == "function" ? a(c) : "current" in a && (a.current = c));
7
+ label,
8
+ error,
9
+ helperText,
10
+ className,
11
+ id: providedId,
12
+ required,
13
+ disabled,
14
+ checked,
15
+ "data-cy": dataCy,
16
+ "data-testid": dataTestId,
17
+ ...props
18
+ }, ref) => {
19
+ const generatedId = useId();
20
+ const id = providedId || generatedId;
21
+ const errorId = `${id}-error`;
22
+ const helperId = `${id}-helper`;
23
+ const finalDataCy = dataCy || "radio";
24
+ const finalTestId = dataTestId || "radio";
25
+ const internalRef = useRef(null);
26
+ const combinedRef = useCallback(
27
+ (element) => {
28
+ internalRef.current = element;
29
+ if (!ref) return;
30
+ if (typeof ref === "function") {
31
+ ref(element);
32
+ } else if ("current" in ref) {
33
+ ref.current = element;
34
+ }
22
35
  },
23
- [a]
24
- ), v = d && n && !d.includes("*") ? `${d} *` : d;
25
- return /* @__PURE__ */ u(
36
+ [ref]
37
+ );
38
+ const displayLabel = label && required && !label.includes("*") ? `${label} *` : label;
39
+ return /* @__PURE__ */ jsxs(
26
40
  "div",
27
41
  {
28
- className: y("radio-wrapper", l && "radio-wrapper--disabled"),
29
- "data-cy": `${t}-wrapper`,
30
- "data-testid": `${i}-wrapper`,
42
+ className: cn("radio-wrapper", disabled && "radio-wrapper--disabled"),
43
+ "data-cy": `${finalDataCy}-wrapper`,
44
+ "data-testid": `${finalTestId}-wrapper`,
31
45
  children: [
32
- /* @__PURE__ */ u("div", { className: "radio__container", children: [
33
- /* @__PURE__ */ s(
46
+ /* @__PURE__ */ jsxs("div", { className: "radio__container", children: [
47
+ /* @__PURE__ */ jsx(
34
48
  "input",
35
49
  {
36
- ref: I,
37
- id: e,
50
+ ref: combinedRef,
51
+ id,
38
52
  type: "radio",
39
- checked: $,
40
- className: y("radio__input", r && "radio__input--error", _),
41
- "aria-describedby": r ? p : o ? m : void 0,
42
- "data-cy": t,
43
- "data-testid": i,
44
- disabled: l,
45
- required: n,
46
- ...R
53
+ checked,
54
+ className: cn("radio__input", error && "radio__input--error", className),
55
+ "aria-describedby": error ? errorId : helperText ? helperId : void 0,
56
+ "data-cy": finalDataCy,
57
+ "data-testid": finalTestId,
58
+ disabled,
59
+ required,
60
+ ...props
47
61
  }
48
62
  ),
49
- d && /* @__PURE__ */ s(
63
+ label && /* @__PURE__ */ jsx(
50
64
  "label",
51
65
  {
52
- htmlFor: e,
66
+ htmlFor: id,
53
67
  className: "radio__label",
54
- "data-cy": `${t}-label`,
55
- "data-testid": `${i}-label`,
56
- children: v
68
+ "data-cy": `${finalDataCy}-label`,
69
+ "data-testid": `${finalTestId}-label`,
70
+ children: displayLabel
57
71
  }
58
72
  )
59
73
  ] }),
60
- r && /* @__PURE__ */ s(
74
+ error && /* @__PURE__ */ jsx(
61
75
  "span",
62
76
  {
63
- id: p,
77
+ id: errorId,
64
78
  className: "radio__error",
65
79
  role: "alert",
66
- "data-cy": `${t}-error`,
67
- "data-testid": `${i}-error`,
68
- children: r
80
+ "data-cy": `${finalDataCy}-error`,
81
+ "data-testid": `${finalTestId}-error`,
82
+ children: error
69
83
  }
70
84
  ),
71
- o && !r && /* @__PURE__ */ s(
85
+ helperText && !error && /* @__PURE__ */ jsx(
72
86
  "span",
73
87
  {
74
- id: m,
88
+ id: helperId,
75
89
  className: "radio__helper",
76
- "data-cy": `${t}-helper`,
77
- "data-testid": `${i}-helper`,
78
- children: o
90
+ "data-cy": `${finalDataCy}-helper`,
91
+ "data-testid": `${finalTestId}-helper`,
92
+ children: helperText
79
93
  }
80
94
  )
81
95
  ]
@@ -83,7 +97,7 @@ const x = j(
83
97
  );
84
98
  }
85
99
  );
86
- x.displayName = "Radio";
100
+ Radio.displayName = "Radio";
87
101
  export {
88
- x as Radio
102
+ Radio
89
103
  };
package/dist/index9.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const d=require("react/jsx-runtime"),b=require("react"),T=require("@radix-ui/react-tabs"),g=require("./index17.cjs");;/* empty css */function m(a){const t=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(a){for(const e in a)if(e!=="default"){const s=Object.getOwnPropertyDescriptor(a,e);Object.defineProperty(t,e,s.get?s:{enumerable:!0,get:()=>a[e]})}}return t.default=a,Object.freeze(t)}const n=m(T),u=n.Root,f=b.forwardRef(({className:a,"data-cy":t,"data-testid":e,...s},r)=>{const i=t||"tabs-list",c=e||"tabs-list";return d.jsx(n.List,{ref:r,className:g.cn("tabs-list",a),"data-cy":i,"data-testid":c,...s})});f.displayName=n.List.displayName;const l=b.forwardRef(({className:a,value:t,"data-cy":e,"data-testid":s,...r},i)=>{const c=e||(t?`tabs-trigger-${t}`:"tabs-trigger"),o=s||(t?`tabs-trigger-${t}`:"tabs-trigger");return d.jsx(n.Trigger,{ref:i,className:g.cn("tabs-trigger",a),value:t,"data-cy":c,"data-testid":o,...r})});l.displayName=n.Trigger.displayName;const y=b.forwardRef(({className:a,value:t,"data-cy":e,"data-testid":s,...r},i)=>{const c=e||(t?`tabs-content-${t}`:"tabs-content"),o=s||(t?`tabs-content-${t}`:"tabs-content");return d.jsx(n.Content,{ref:i,className:g.cn("tabs-content",a),value:t,"data-cy":c,"data-testid":o,...r})});y.displayName=n.Content.displayName;exports.Tabs=u;exports.TabsContent=y;exports.TabsList=f;exports.TabsTrigger=l;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const t=require("react/jsx-runtime"),e=require("react"),a=require("@radix-ui/react-tabs"),s=require("./index17.cjs");function r(t){const e=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(t)for(const a in t)if("default"!==a){const s=Object.getOwnPropertyDescriptor(t,a);Object.defineProperty(e,a,s.get?s:{enumerable:!0,get:()=>t[a]})}return e.default=t,Object.freeze(e)};/* empty css */const i=r(a),n=i.Root,c=e.forwardRef(({className:e,"data-cy":a,"data-testid":r,...n},c)=>{const o=a||"tabs-list",d=r||"tabs-list";return t.jsx(i.List,{ref:c,className:s.cn("tabs-list",e),"data-cy":o,"data-testid":d,...n})});c.displayName=i.List.displayName;const o=e.forwardRef(({className:e,value:a,"data-cy":r,"data-testid":n,...c},o)=>{const d=r||(a?`tabs-trigger-${a}`:"tabs-trigger"),l=n||(a?`tabs-trigger-${a}`:"tabs-trigger");return t.jsx(i.Trigger,{ref:o,className:s.cn("tabs-trigger",e),value:a,"data-cy":d,"data-testid":l,...c})});o.displayName=i.Trigger.displayName;const d=e.forwardRef(({className:e,value:a,"data-cy":r,"data-testid":n,...c},o)=>{const d=r||(a?`tabs-content-${a}`:"tabs-content"),l=n||(a?`tabs-content-${a}`:"tabs-content");return t.jsx(i.Content,{ref:o,className:s.cn("tabs-content",e),value:a,"data-cy":d,"data-testid":l,...c})});d.displayName=i.Content.displayName,exports.Tabs=n,exports.TabsContent=d,exports.TabsList=c,exports.TabsTrigger=o;