@brightlocal/ui-components 0.2.0 → 0.3.1

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 (78) hide show
  1. package/dist/alert.cjs +1 -1
  2. package/dist/alert.d.ts +10 -1
  3. package/dist/alert.d.ts.map +1 -1
  4. package/dist/alert.js +6 -2
  5. package/dist/card.cjs +1 -1
  6. package/dist/card.d.ts +6 -2
  7. package/dist/card.d.ts.map +1 -1
  8. package/dist/card.js +89 -73
  9. package/dist/centred-layout.cjs +1 -1
  10. package/dist/centred-layout.d.ts +49 -25
  11. package/dist/centred-layout.d.ts.map +1 -1
  12. package/dist/centred-layout.js +57 -32
  13. package/dist/checkbox.d.ts.map +1 -1
  14. package/dist/chip.cjs +1 -0
  15. package/dist/chip.d.ts +61 -0
  16. package/dist/chip.d.ts.map +1 -0
  17. package/dist/chip.js +165 -0
  18. package/dist/combobox.cjs +1 -1
  19. package/dist/combobox.d.ts.map +1 -1
  20. package/dist/combobox.js +5 -2
  21. package/dist/date-picker.cjs +1 -1
  22. package/dist/date-picker.d.ts +89 -52
  23. package/dist/date-picker.d.ts.map +1 -1
  24. package/dist/date-picker.js +228 -210
  25. package/dist/dropdown-menu.d.ts.map +1 -1
  26. package/dist/header.cjs +1 -0
  27. package/dist/header.d.ts +42 -0
  28. package/dist/header.d.ts.map +1 -0
  29. package/dist/header.js +22 -0
  30. package/dist/index.cjs +1 -1
  31. package/dist/index.d.ts +3 -0
  32. package/dist/index.d.ts.map +1 -1
  33. package/dist/index.js +426 -396
  34. package/dist/input-chip.cjs +1 -0
  35. package/dist/input-chip.d.ts +117 -0
  36. package/dist/input-chip.d.ts.map +1 -0
  37. package/dist/input-chip.js +284 -0
  38. package/dist/input-group.d.ts.map +1 -1
  39. package/dist/input-otp.cjs +1 -1
  40. package/dist/input-otp.d.ts +43 -36
  41. package/dist/input-otp.d.ts.map +1 -1
  42. package/dist/input-otp.js +140 -119
  43. package/dist/input-password.cjs +1 -1
  44. package/dist/input-password.d.ts +147 -19
  45. package/dist/input-password.d.ts.map +1 -1
  46. package/dist/input-password.js +197 -92
  47. package/dist/input.cjs +1 -1
  48. package/dist/input.js +1 -1
  49. package/dist/progress.cjs +1 -1
  50. package/dist/progress.d.ts +10 -0
  51. package/dist/progress.d.ts.map +1 -1
  52. package/dist/progress.js +45 -36
  53. package/dist/select.d.ts.map +1 -1
  54. package/dist/slider.cjs +1 -1
  55. package/dist/slider.d.ts +31 -3
  56. package/dist/slider.d.ts.map +1 -1
  57. package/dist/slider.js +53 -43
  58. package/dist/textarea.d.ts.map +1 -1
  59. package/package.json +23 -24
  60. package/src/components/alert.tsx +10 -1
  61. package/src/components/card.tsx +66 -38
  62. package/src/components/centred-layout.tsx +115 -38
  63. package/src/components/checkbox.tsx +2 -2
  64. package/src/components/chip.tsx +249 -0
  65. package/src/components/combobox.tsx +17 -13
  66. package/src/components/date-picker.tsx +410 -266
  67. package/src/components/dropdown-menu.tsx +6 -1
  68. package/src/components/header.tsx +69 -0
  69. package/src/components/input-chip.tsx +548 -0
  70. package/src/components/input-group.tsx +4 -1
  71. package/src/components/input-otp.tsx +159 -91
  72. package/src/components/input-password.tsx +469 -129
  73. package/src/components/input.tsx +1 -1
  74. package/src/components/progress.tsx +21 -2
  75. package/src/components/select.tsx +1 -3
  76. package/src/components/slider.tsx +85 -15
  77. package/src/components/textarea.tsx +4 -1
  78. package/src/index.ts +3 -0
package/dist/input-otp.js CHANGED
@@ -1,52 +1,72 @@
1
- import { jsx as t, jsxs as v } from "react/jsx-runtime";
1
+ import { jsx as e, jsxs as h } from "react/jsx-runtime";
2
2
  import * as s from "react";
3
- import { REGEXP_ONLY_DIGITS as N, OTPInputContext as y, OTPInput as w } from "input-otp";
4
- import { REGEXP_ONLY_CHARS as M, REGEXP_ONLY_DIGITS as j, REGEXP_ONLY_DIGITS_AND_CHARS as W } from "input-otp";
5
- import { MinusIcon as S } from "@brightlocal/icons";
6
- import { cn as g } from "@brightlocal/ui-components/lib/utils";
7
- import { Label as _ } from "@brightlocal/ui-components/label";
8
- const O = s.forwardRef(
9
- ({ trackingEl: e, trackingLabel: a, dataHook: n, containerClassName: d, error: i, ...r }, o) => {
10
- const m = r.id || r["aria-label"] ? r["aria-label"] : "One-time password", c = i || r["aria-invalid"] === !0 || r["aria-invalid"] === "true";
11
- return /* @__PURE__ */ t(
12
- w,
3
+ import { OTPInput as v, OTPInputContext as x, REGEXP_ONLY_DIGITS as N } from "input-otp";
4
+ import { REGEXP_ONLY_CHARS as W, REGEXP_ONLY_DIGITS as X, REGEXP_ONLY_DIGITS_AND_CHARS as Y } from "input-otp";
5
+ import { MinusIcon as b } from "@brightlocal/icons";
6
+ import { cn as I } from "@brightlocal/ui-components/lib/utils";
7
+ import { Label as w } from "@brightlocal/ui-components/label";
8
+ const P = s.createContext(null);
9
+ function y() {
10
+ const t = s.useContext(P);
11
+ if (!t)
12
+ throw new Error("InputOTP components must be used within an <InputOTP>");
13
+ return t;
14
+ }
15
+ const T = s.forwardRef(
16
+ ({
17
+ dataHook: t,
18
+ trackingEl: r,
19
+ trackingLabel: n,
20
+ containerClassName: o,
21
+ error: a,
22
+ disabled: u,
23
+ children: i,
24
+ ...d
25
+ }, l) => {
26
+ const c = s.useMemo(
27
+ () => ({ error: a, disabled: u }),
28
+ [a, u]
29
+ );
30
+ return /* @__PURE__ */ e(P.Provider, { value: c, children: /* @__PURE__ */ e(
31
+ v,
13
32
  {
14
- ref: o,
15
- "aria-invalid": c ? "true" : void 0,
16
- "aria-label": m,
33
+ ref: l,
34
+ "aria-invalid": a ? "true" : void 0,
17
35
  className: "disabled:cursor-not-allowed",
18
- containerClassName: g(
36
+ containerClassName: I(
19
37
  "group flex items-center gap-2 has-disabled:opacity-50 w-fit",
20
- d
38
+ o
21
39
  ),
22
- "data-hook": n,
40
+ "data-hook": t,
23
41
  "data-slot": "input-otp",
24
- "data-tracking-el": e,
25
- "data-tracking-label": a,
26
- ...r
42
+ "data-tracking-el": r,
43
+ "data-tracking-label": n,
44
+ disabled: u,
45
+ ...d,
46
+ children: i
27
47
  }
28
- );
48
+ ) });
29
49
  }
30
50
  );
31
- O.displayName = "InputOTP";
32
- function h({ className: e, ...a }) {
33
- return /* @__PURE__ */ t(
51
+ T.displayName = "InputOTP";
52
+ function f({ className: t, ...r }) {
53
+ return /* @__PURE__ */ e(
34
54
  "div",
35
55
  {
36
- className: g("flex items-center rounded-md shadow-xs", e),
56
+ className: I("flex items-center rounded-md shadow-xs", t),
37
57
  "data-slot": "input-otp-group",
38
- ...a
58
+ ...r
39
59
  }
40
60
  );
41
61
  }
42
- function u({ index: e, className: a, ...n }) {
43
- const d = s.useContext(
44
- y
45
- ), { char: i, hasFakeCaret: r, isActive: o } = d?.slots[e] ?? {};
46
- return /* @__PURE__ */ v(
62
+ function p({ index: t, className: r, ...n }) {
63
+ const { error: o } = y(), a = s.useContext(
64
+ x
65
+ ), { char: u, hasFakeCaret: i, isActive: d } = a?.slots[t] ?? {};
66
+ return /* @__PURE__ */ h(
47
67
  "div",
48
68
  {
49
- className: g(
69
+ className: I(
50
70
  // Base styles
51
71
  "relative flex h-9 w-9 items-center justify-center",
52
72
  "border-input bg-background border-y border-r",
@@ -56,134 +76,135 @@ function u({ index: e, className: a, ...n }) {
56
76
  "data-[active=true]:border-ring data-[active=true]:z-10",
57
77
  "data-[active=true]:shadow-default",
58
78
  // Error state
59
- "group-has-[input[aria-invalid=true]]:border-destructive",
60
- "group-has-[input[aria-invalid=true]]:data-[active=true]:shadow-destructive",
61
- "group-has-[input[aria-invalid=true]]:data-[active=true]:border-destructive",
79
+ o && "border-destructive",
80
+ o && d && "shadow-destructive",
62
81
  // Dark mode
63
82
  "dark:bg-input/30",
64
- a
83
+ r
65
84
  ),
66
- "data-active": o,
85
+ "data-active": d,
86
+ "data-error": o,
67
87
  "data-slot": "input-otp-slot",
68
88
  ...n,
69
89
  children: [
70
- i,
71
- r && /* @__PURE__ */ t("div", { className: "pointer-events-none absolute inset-0 flex items-center justify-center", children: /* @__PURE__ */ t("div", { className: "animate-caret-blink bg-foreground h-4 w-px duration-1000" }) })
90
+ u,
91
+ i && /* @__PURE__ */ e("div", { className: "pointer-events-none absolute inset-0 flex items-center justify-center", children: /* @__PURE__ */ e("div", { className: "animate-caret-blink bg-foreground h-4 w-px duration-1000" }) })
72
92
  ]
73
93
  }
74
94
  );
75
95
  }
76
- function P({ ...e }) {
77
- return /* @__PURE__ */ t("div", { "data-slot": "input-otp-separator", role: "separator", ...e, children: /* @__PURE__ */ t(S, {}) });
96
+ function g({ ...t }) {
97
+ return /* @__PURE__ */ e("div", { "data-slot": "input-otp-separator", role: "separator", ...t, children: /* @__PURE__ */ e(b, {}) });
78
98
  }
79
- const p = s.forwardRef(
80
- ({
81
- label: e,
82
- id: a,
83
- dataHook: n,
84
- trackingEl: d,
85
- trackingLabel: i,
86
- containerClassName: r,
87
- children: o,
88
- error: l,
89
- "aria-label": m,
90
- ...c
91
- }, b) => {
92
- const f = s.useId(), I = a || f, T = m || (e ? void 0 : "One-time password");
93
- return /* @__PURE__ */ v("div", { className: "w-fit", children: [
94
- e && /* @__PURE__ */ t(
95
- _,
99
+ function S({ dataHook: t, className: r, ...n }) {
100
+ return /* @__PURE__ */ e(
101
+ w,
102
+ {
103
+ className: I("mb-2", r),
104
+ "data-hook": t,
105
+ "data-slot": "input-otp-label",
106
+ ...n
107
+ }
108
+ );
109
+ }
110
+ const m = s.forwardRef(
111
+ ({ label: t, id: r, dataHook: n, "aria-label": o, children: a, ...u }, i) => {
112
+ const d = s.useId(), l = r || d, c = o || (t ? void 0 : "One-time password");
113
+ return /* @__PURE__ */ h("div", { className: "w-fit", "data-slot": "input-otp-field", children: [
114
+ t && /* @__PURE__ */ e(
115
+ S,
96
116
  {
97
- className: "mb-2",
98
- "data-hook": n ? `${n}-label` : void 0,
99
- htmlFor: I,
100
- children: e
117
+ dataHook: n ? `${n}-label` : void 0,
118
+ htmlFor: l,
119
+ children: t
101
120
  }
102
121
  ),
103
- /* @__PURE__ */ t(
104
- O,
122
+ /* @__PURE__ */ e(
123
+ T,
105
124
  {
106
- ref: b,
107
- "aria-label": T,
108
- containerClassName: r,
125
+ ref: i,
126
+ "aria-label": c,
109
127
  dataHook: n,
110
- error: l,
111
- id: e ? I : void 0,
112
- trackingEl: d,
113
- trackingLabel: i,
114
- ...c,
115
- children: o
128
+ id: t ? l : void 0,
129
+ ...u,
130
+ children: a
116
131
  }
117
132
  )
118
133
  ] });
119
134
  }
120
135
  );
121
- p.displayName = "InputOTPField";
122
- const x = s.forwardRef(({ maxLength: e = 6, pattern: a = N, ...n }, d) => /* @__PURE__ */ t(
123
- p,
136
+ m.displayName = "InputOTPField";
137
+ const _ = s.forwardRef(({ maxLength: t = 6, ...r }, n) => /* @__PURE__ */ e(
138
+ m,
124
139
  {
125
- ref: d,
140
+ ref: n,
126
141
  inputMode: "numeric",
127
- maxLength: e,
128
- pasteTransformer: (i) => i.replace(/\D+/g, "").slice(0, e),
129
- pattern: a,
130
- ...n,
131
- children: /* @__PURE__ */ t(h, { children: Array.from({ length: e }, (i, r) => /* @__PURE__ */ t(u, { index: r }, r)) })
142
+ maxLength: t,
143
+ pasteTransformer: (o) => o.replace(/\D+/g, "").slice(0, t),
144
+ pattern: N,
145
+ ...r,
146
+ children: /* @__PURE__ */ e(f, { children: Array.from({ length: t }, (o, a) => /* @__PURE__ */ e(p, { index: a }, a)) })
132
147
  }
133
148
  ));
134
- x.displayName = "InputOTPDigitsOnly";
135
- const A = s.forwardRef(({ maxLength: e = 4, ...a }, n) => /* @__PURE__ */ t(
136
- p,
149
+ _.displayName = "InputOTPDigitsOnly";
150
+ const R = s.forwardRef(({ maxLength: t = 4, ...r }, n) => /* @__PURE__ */ e(
151
+ m,
137
152
  {
138
153
  ref: n,
139
154
  containerClassName: "gap-2",
140
- maxLength: e,
141
- ...a,
142
- children: Array.from({ length: e }, (d, i) => /* @__PURE__ */ t(
143
- u,
155
+ maxLength: t,
156
+ ...r,
157
+ children: Array.from({ length: t }, (o, a) => /* @__PURE__ */ e(
158
+ p,
144
159
  {
145
160
  className: "rounded-md border-l shadow-xs",
146
- index: i
161
+ index: a
147
162
  },
148
- i
163
+ a
149
164
  ))
150
165
  }
151
166
  ));
152
- A.displayName = "InputOTPWithSpacing";
153
- const R = s.forwardRef(
154
- ({ maxLength: e = 6, ...a }, n) => {
155
- const d = Math.ceil(e / 2), i = e - d;
156
- return /* @__PURE__ */ v(p, { ref: n, maxLength: e, ...a, children: [
157
- /* @__PURE__ */ t(h, { children: Array.from({ length: d }, (r, o) => /* @__PURE__ */ t(u, { index: o }, o)) }),
158
- /* @__PURE__ */ t(P, {}),
159
- /* @__PURE__ */ t(h, { children: Array.from({ length: i }, (r, o) => /* @__PURE__ */ t(
160
- u,
167
+ R.displayName = "InputOTPWithSpacing";
168
+ const C = s.forwardRef(
169
+ ({ maxLength: t = 6, ...r }, n) => {
170
+ const o = Math.ceil(t / 2), a = t - o;
171
+ return /* @__PURE__ */ h(m, { ref: n, maxLength: t, ...r, children: [
172
+ /* @__PURE__ */ e(f, { children: Array.from({ length: o }, (u, i) => /* @__PURE__ */ e(p, { index: i }, i)) }),
173
+ /* @__PURE__ */ e(g, {}),
174
+ /* @__PURE__ */ e(f, { children: Array.from({ length: a }, (u, i) => /* @__PURE__ */ e(
175
+ p,
161
176
  {
162
- index: o + d
177
+ index: i + o
163
178
  },
164
- o + d
179
+ i + o
165
180
  )) })
166
181
  ] });
167
182
  }
168
183
  );
169
- R.displayName = "InputOTPSimple";
170
- const G = s.forwardRef(({ maxLength: e = 6, ...a }, n) => {
171
- const i = Math.ceil(e / 2);
172
- return /* @__PURE__ */ t(p, { ref: n, maxLength: e, ...a, children: Array.from({ length: i }, (r, o) => {
173
- const l = o * 2, c = Math.min(l + 2, e) - l;
174
- return /* @__PURE__ */ v(s.Fragment, { children: [
175
- o > 0 && /* @__PURE__ */ t(P, {}),
176
- /* @__PURE__ */ t(h, { children: Array.from({ length: c }, (b, f) => /* @__PURE__ */ t(u, { index: l + f }, l + f)) })
177
- ] }, o);
184
+ C.displayName = "InputOTPSimple";
185
+ const A = s.forwardRef(({ maxLength: t = 6, ...r }, n) => {
186
+ const a = Math.ceil(t / 2);
187
+ return /* @__PURE__ */ e(m, { ref: n, maxLength: t, ...r, children: Array.from({ length: a }, (u, i) => {
188
+ const d = i * 2, c = Math.min(d + 2, t) - d;
189
+ return /* @__PURE__ */ h(s.Fragment, { children: [
190
+ i > 0 && /* @__PURE__ */ e(g, {}),
191
+ /* @__PURE__ */ e(f, { children: Array.from({ length: c }, (G, O) => /* @__PURE__ */ e(p, { index: d + O }, d + O)) })
192
+ ] }, i);
178
193
  }) });
179
194
  });
180
- G.displayName = "InputOTPWithSeparator";
195
+ A.displayName = "InputOTPWithSeparator";
181
196
  export {
182
- x as InputOTPDigitsOnly,
183
- R as InputOTPSimple,
184
- G as InputOTPWithSeparator,
185
- A as InputOTPWithSpacing,
186
- M as REGEXP_ONLY_CHARS,
187
- j as REGEXP_ONLY_DIGITS,
188
- W as REGEXP_ONLY_DIGITS_AND_CHARS
197
+ T as InputOTP,
198
+ _ as InputOTPDigitsOnly,
199
+ m as InputOTPField,
200
+ f as InputOTPGroup,
201
+ S as InputOTPLabel,
202
+ g as InputOTPSeparator,
203
+ C as InputOTPSimple,
204
+ p as InputOTPSlot,
205
+ A as InputOTPWithSeparator,
206
+ R as InputOTPWithSpacing,
207
+ W as REGEXP_ONLY_CHARS,
208
+ X as REGEXP_ONLY_DIGITS,
209
+ Y as REGEXP_ONLY_DIGITS_AND_CHARS
189
210
  };
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const r=require("react/jsx-runtime"),A=require("react"),h=require("@brightlocal/icons"),E=require("@brightlocal/ui-components/progress"),_=require("@brightlocal/ui-components/lib/utils"),l=require("@brightlocal/ui-components/input-group");function z(e){const t=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e){for(const n in e)if(n!=="default"){const s=Object.getOwnPropertyDescriptor(e,n);Object.defineProperty(t,n,s.get?s:{enumerable:!0,get:()=>e[n]})}}return t.default=e,Object.freeze(t)}const a=z(A),p={meter:{label:"Meter",value:0,color:"bg-muted"},weak:{label:"Weak",value:25,color:"bg-red-500"},ok:{label:"Ok",value:50,color:"bg-orange-500"},good:{label:"Good",value:75,color:"bg-green-500"},great:{label:"Great",value:100,color:"bg-green-600"}};function m(e){if(!e||e.length===0)return"meter";let t=0;return e.length>=8&&(t+=1),e.length>=12&&(t+=1),/[a-z]/.test(e)&&(t+=1),/[A-Z]/.test(e)&&(t+=1),/[0-9]/.test(e)&&(t+=1),/[^a-zA-Z0-9]/.test(e)&&(t+=1),t<=2?"weak":t<=3?"ok":t<=4?"good":"great"}const b=a.forwardRef(({className:e,showStrength:t=!0,onStrengthChange:n,dataHook:s,trackingEl:w,trackingLabel:S,onChange:x,value:i,id:j,error:v,...u},P)=>{const[c,I]=a.useState(!1),[y,N]=a.useState("meter"),[O,G]=a.useState(""),R=a.useId(),T=j||R,g=i!==void 0?String(i):O;a.useEffect(()=>{const o=setTimeout(()=>{const f=m(g);N(f),n?.(f)},180);return()=>clearTimeout(o)},[g,n]);const k=o=>{G(o.target.value),x?.(o)},q=()=>{I(o=>!o)},d=p[y];return r.jsxs("div",{className:"w-full",children:[r.jsxs(l.InputGroup,{className:e,dataHook:s,error:v,children:[r.jsx(l.InputGroupInput,{ref:P,id:T,trackingEl:w,trackingLabel:S,type:c?"text":"password",value:i,onChange:k,...u}),r.jsx(l.InputGroupAddon,{align:"inline-end",children:r.jsx(l.InputGroupButton,{"aria-label":c?"Hide password":"Show password","data-hook":s?`${s}-toggle`:void 0,disabled:u.disabled,size:"icon",variant:"ghost",onClick:q,children:c?r.jsx(h.EyeOff,{className:"h-4 w-4"}):r.jsx(h.Eye,{className:"h-4 w-4"})})})]}),t&&r.jsx("div",{className:"mt-1 space-y-2",children:r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx(E.Progress,{className:_.cn("h-2 flex-1"),dataHook:s?`${s}-strength-progress`:"password-strength-progress",value:d.value}),r.jsx("span",{className:"text-foreground w-10 shrink-0 text-right text-sm font-medium whitespace-nowrap","data-hook":s?`${s}-strength-label`:void 0,children:d.label})]})})]})});b.displayName="InputPassword";exports.InputPassword=b;exports.PASSWORD_STRENGTH=p;exports.calculatePasswordStrength=m;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const s=require("react/jsx-runtime"),D=require("react"),P=require("@brightlocal/icons"),M=require("@brightlocal/ui-components/progress"),S=require("@brightlocal/ui-components/lib/utils"),w=require("@brightlocal/ui-components/input-group");function $(e){const t=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e){for(const o in e)if(o!=="default"){const a=Object.getOwnPropertyDescriptor(e,o);Object.defineProperty(t,o,a.get?a:{enumerable:!0,get:()=>e[o]})}}return t.default=e,Object.freeze(t)}const r=$(D),C={meter:{label:"Meter",value:0,color:"bg-green-500"},weak:{label:"Weak",value:25,color:"bg-green-500"},ok:{label:"Ok",value:50,color:"bg-green-500"},good:{label:"Good",value:75,color:"bg-green-500"},great:{label:"Great",value:100,color:"bg-green-500"}};function O(e){if(!e||e.length===0)return"meter";if(e.length<12)return"weak";let t=0;return e.length>=16&&(t+=1),/[a-z]/.test(e)&&(t+=1),/[A-Z]/.test(e)&&(t+=1),/[0-9]/.test(e)&&(t+=1),/[^a-zA-Z0-9]/.test(e)&&(t+=1),t<=1?"ok":t<=3?"good":"great"}const L=r.createContext(null);function v(){const e=r.useContext(L);if(!e)throw new Error("InputPassword compound components must be used within InputPasswordRoot");return e}function H({children:e,dataHook:t,trackingEl:o,trackingLabel:a,disabled:c,value:n,onChange:l,onStrengthChange:u,strengthLevels:p,calculateStrength:d,error:i,id:x,className:I}){const[h,f]=r.useState(!1),[j,m]=r.useState(""),[y,A]=r.useState("meter"),F=r.useId(),k=x||F,b=n!==void 0?n:j,N=p??C,E=d??O,T=r.useCallback(g=>{n===void 0&&m(g),l?.(g)},[n,l]),R=r.useCallback(()=>{f(g=>!g)},[]);r.useEffect(()=>{const g=setTimeout(()=>{const G=E(b);A(G),u?.(G)},180);return()=>clearTimeout(g)},[b,E,u]);const z=r.useMemo(()=>({showPassword:h,setShowPassword:f,toggleVisibility:R,password:b,setPassword:T,strength:y,strengthLevels:N,disabled:c,dataHook:t,trackingEl:o,trackingLabel:a,inputId:k,error:i}),[h,R,b,T,y,N,c,t,o,a,k,i]);return s.jsx(L.Provider,{value:z,children:s.jsx("div",{className:S.cn("w-full",I),children:e})})}H.displayName="InputPasswordRoot";const _=r.forwardRef(({className:e,groupClassName:t,onChange:o,...a},c)=>{const{showPassword:n,toggleVisibility:l,password:u,setPassword:p,disabled:d,dataHook:i,trackingEl:x,trackingLabel:I,inputId:h,error:f}=v(),j=m=>{p(m.target.value),o?.(m)};return s.jsxs(w.InputGroup,{className:t,dataHook:i,error:f,children:[s.jsx(w.InputGroupInput,{ref:c,className:e,disabled:d,id:h,trackingEl:x,trackingLabel:I,type:n?"text":"password",value:u,onChange:j,...a}),s.jsx(w.InputGroupAddon,{align:"inline-end",children:s.jsx(w.InputGroupButton,{"aria-label":n?"Hide password":"Show password","data-hook":`${i}-toggle`,disabled:d,size:"icon",variant:"ghost",onClick:l,children:n?s.jsx(P.EyeOff,{className:"h-4 w-4"}):s.jsx(P.Eye,{className:"h-4 w-4"})})})]})});_.displayName="InputPasswordField";const q=r.forwardRef(({className:e,showLabel:t="Show password",hideLabel:o="Hide password",size:a="icon",variant:c="ghost",...n},l)=>{const{showPassword:u,toggleVisibility:p,disabled:d,dataHook:i}=v();return s.jsx(w.InputGroupButton,{ref:l,"aria-label":u?o:t,className:e,"data-hook":`${i}-toggle`,disabled:d,size:a,variant:c,onClick:p,...n,children:u?s.jsx(P.EyeOff,{className:"h-4 w-4"}):s.jsx(P.Eye,{className:"h-4 w-4"})})});q.displayName="InputPasswordToggle";function V({className:e,showLabel:t=!0}){const{strength:o,strengthLevels:a,dataHook:c,disabled:n}=v(),l=a[o]??{label:o,value:0,color:"bg-muted"};return s.jsx("div",{className:S.cn("mt-1 space-y-2",e),children:s.jsxs("div",{className:S.cn("flex items-center gap-2",n&&"opacity-50"),children:[s.jsx(M.Progress,{className:"h-2 flex-1",dataHook:`${c}-strength-progress`,indicatorClassName:l.color,value:l.value}),t&&s.jsx("span",{className:"text-foreground w-10 shrink-0 text-right text-sm font-medium whitespace-nowrap","data-hook":`${c}-strength-label`,children:l.label})]})})}V.displayName="InputPasswordStrength";exports.DEFAULT_STRENGTH_LEVELS=C;exports.InputPasswordField=_;exports.InputPasswordRoot=H;exports.InputPasswordStrength=V;exports.InputPasswordToggle=q;exports.calculatePasswordStrength=O;
@@ -1,42 +1,170 @@
1
+ import { InputGroupInput, InputGroupButton } from '../input-group';
1
2
  import * as React from "react";
2
- type PasswordStrength = "meter" | "weak" | "ok" | "good" | "great";
3
- interface PasswordStrengthConfig {
3
+ /**
4
+ * Default password strength levels (industry standard)
5
+ */
6
+ type DefaultPasswordStrength = "meter" | "weak" | "ok" | "good" | "great";
7
+ /**
8
+ * Configuration for a single strength level
9
+ */
10
+ interface StrengthLevelConfig {
4
11
  label: string;
5
12
  value: number;
6
13
  color: string;
7
14
  }
8
- declare const PASSWORD_STRENGTH: Record<PasswordStrength, PasswordStrengthConfig>;
9
- interface InputPasswordProps extends Omit<React.ComponentProps<"input">, "type"> {
15
+ /**
16
+ * Default strength levels configuration
17
+ */
18
+ declare const DEFAULT_STRENGTH_LEVELS: Record<DefaultPasswordStrength, StrengthLevelConfig>;
19
+ /**
20
+ * Calculate password strength based on various criteria (default implementation)
21
+ * - Minimum 12 characters required for "ok" or better
22
+ */
23
+ declare function calculatePasswordStrength(password: string): DefaultPasswordStrength;
24
+ export interface InputPasswordRootProps<T extends string = DefaultPasswordStrength> {
10
25
  /**
11
- * Show password strength indicator below the input
26
+ * Data hook for automated testing (REQUIRED)
12
27
  */
13
- showStrength?: boolean;
28
+ dataHook: string;
14
29
  /**
15
- * Callback when password strength changes
30
+ * Tracking element identifier for analytics
16
31
  */
17
- onStrengthChange?: (strength: PasswordStrength) => void;
32
+ trackingEl?: string;
18
33
  /**
19
- * Required data-hook attribute for testing
34
+ * Tracking label for analytics context
20
35
  */
21
- dataHook: string;
36
+ trackingLabel?: string;
22
37
  /**
23
- * Optional tracking element identifier
38
+ * Disabled state
24
39
  */
25
- trackingEl?: string;
40
+ disabled?: boolean;
26
41
  /**
27
- * Optional tracking label
42
+ * Controlled password value
28
43
  */
29
- trackingLabel?: string;
44
+ value?: string;
45
+ /**
46
+ * Callback fired when password changes
47
+ */
48
+ onChange?: (value: string) => void;
49
+ /**
50
+ * Callback fired when password strength changes
51
+ */
52
+ onStrengthChange?: (strength: T) => void;
53
+ /**
54
+ * Custom strength levels configuration.
55
+ * Define your own levels with custom keys, labels, values, and colors.
56
+ * @example
57
+ * strengthLevels={{
58
+ * empty: { label: "Enter password", value: 0, color: "bg-muted" },
59
+ * slow: { label: "Slow", value: 33, color: "bg-red-500" },
60
+ * medium: { label: "Medium", value: 66, color: "bg-yellow-500" },
61
+ * fast: { label: "Fast", value: 100, color: "bg-green-500" },
62
+ * }}
63
+ */
64
+ strengthLevels?: Record<T, StrengthLevelConfig>;
65
+ /**
66
+ * Custom function to calculate password strength.
67
+ * Must return a key from strengthLevels (or default levels if not provided).
68
+ * @default calculatePasswordStrength (built-in)
69
+ */
70
+ calculateStrength?: (password: string) => T;
30
71
  /**
31
72
  * Whether the input has an error state
32
73
  */
33
74
  error?: boolean;
75
+ /**
76
+ * ID for the input element (for label association)
77
+ */
78
+ id?: string;
79
+ /**
80
+ * Children components
81
+ */
82
+ children: React.ReactNode;
83
+ /**
84
+ * Additional class name for the root container
85
+ */
86
+ className?: string;
87
+ }
88
+ /**
89
+ * InputPasswordRoot - Root component that provides context for all InputPassword parts
90
+ *
91
+ * Generic type parameter T allows custom strength levels:
92
+ * @example
93
+ * // Using default levels
94
+ * <InputPasswordRoot dataHook="password">...</InputPasswordRoot>
95
+ *
96
+ * // Using custom levels
97
+ * type MyStrength = "empty" | "slow" | "medium" | "fast";
98
+ * <InputPasswordRoot<MyStrength>
99
+ * dataHook="password"
100
+ * strengthLevels={{
101
+ * empty: { label: "Enter password", value: 0, color: "bg-muted" },
102
+ * slow: { label: "Slow", value: 33, color: "bg-red-500" },
103
+ * medium: { label: "Medium", value: 66, color: "bg-yellow-500" },
104
+ * fast: { label: "Fast", value: 100, color: "bg-green-500" },
105
+ * }}
106
+ * calculateStrength={(password) => {
107
+ * if (!password) return "empty";
108
+ * if (password.length < 8) return "slow";
109
+ * if (password.length < 12) return "medium";
110
+ * return "fast";
111
+ * }}
112
+ * >
113
+ * ...
114
+ * </InputPasswordRoot>
115
+ */
116
+ declare function InputPasswordRoot<T extends string = DefaultPasswordStrength>({ children, dataHook, trackingEl, trackingLabel, disabled, value, onChange, onStrengthChange, strengthLevels, calculateStrength, error, id, className, }: InputPasswordRootProps<T>): import("react/jsx-runtime").JSX.Element;
117
+ declare namespace InputPasswordRoot {
118
+ var displayName: string;
119
+ }
120
+ export interface InputPasswordFieldProps extends Omit<React.ComponentProps<typeof InputGroupInput>, "type"> {
121
+ /**
122
+ * Additional class name for the InputGroup wrapper
123
+ */
124
+ groupClassName?: string;
125
+ }
126
+ /**
127
+ * InputPasswordField - The password input field with toggle button
128
+ * Wraps InputGroup with InputGroupInput and InputGroupAddon for the toggle
129
+ */
130
+ declare const InputPasswordField: React.ForwardRefExoticComponent<Omit<InputPasswordFieldProps, "ref"> & React.RefAttributes<HTMLInputElement>>;
131
+ export interface InputPasswordToggleProps extends Omit<React.ComponentProps<typeof InputGroupButton>, "onClick" | "aria-label"> {
132
+ /**
133
+ * Custom aria-label for show state
134
+ * @default "Show password"
135
+ */
136
+ showLabel?: string;
137
+ /**
138
+ * Custom aria-label for hide state
139
+ * @default "Hide password"
140
+ */
141
+ hideLabel?: string;
142
+ }
143
+ /**
144
+ * InputPasswordToggle - Standalone toggle button for password visibility
145
+ * Use this when you need custom placement of the toggle button
146
+ */
147
+ declare const InputPasswordToggle: React.ForwardRefExoticComponent<Omit<InputPasswordToggleProps, "ref"> & React.RefAttributes<HTMLButtonElement>>;
148
+ export interface InputPasswordStrengthProps {
149
+ /**
150
+ * Additional class name
151
+ */
152
+ className?: string;
153
+ /**
154
+ * Whether to show the label next to the progress bar
155
+ * @default true
156
+ */
157
+ showLabel?: boolean;
34
158
  }
35
159
  /**
36
- * Calculate password strength based on various criteria
160
+ * InputPasswordStrength - Password strength indicator
161
+ * Displays a progress bar and optional label showing password strength.
162
+ * Automatically uses the strength levels configured on InputPasswordRoot.
37
163
  */
38
- declare function calculatePasswordStrength(password: string): PasswordStrength;
39
- declare const InputPassword: React.ForwardRefExoticComponent<Omit<InputPasswordProps, "ref"> & React.RefAttributes<HTMLInputElement>>;
40
- export { InputPassword, calculatePasswordStrength, PASSWORD_STRENGTH };
41
- export type { InputPasswordProps, PasswordStrength };
164
+ declare function InputPasswordStrength({ className, showLabel, }: InputPasswordStrengthProps): import("react/jsx-runtime").JSX.Element;
165
+ declare namespace InputPasswordStrength {
166
+ var displayName: string;
167
+ }
168
+ export { InputPasswordRoot, InputPasswordField, InputPasswordToggle, InputPasswordStrength, calculatePasswordStrength, DEFAULT_STRENGTH_LEVELS, };
169
+ export type { DefaultPasswordStrength, StrengthLevelConfig };
42
170
  //# sourceMappingURL=input-password.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"input-password.d.ts","sourceRoot":"","sources":["../../src/components/input-password.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAY/B,KAAK,gBAAgB,GAAG,OAAO,GAAG,MAAM,GAAG,IAAI,GAAG,MAAM,GAAG,OAAO,CAAC;AAEnE,UAAU,sBAAsB;IAC9B,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,MAAM,CAAC;CACf;AAED,QAAA,MAAM,iBAAiB,EAAE,MAAM,CAAC,gBAAgB,EAAE,s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