@brightlocal/ui-components 1.2.4 → 1.3.0

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.
@@ -0,0 +1,315 @@
1
+ import { jsx as m, jsxs as I } from "react/jsx-runtime";
2
+ import * as V from "react";
3
+ import { useId as gt, useRef as R, useState as Ct, useCallback as yt, useEffect as Z } from "react";
4
+ import { animate as X } from "framer-motion";
5
+ import { interpolate as bt } from "flubber";
6
+ import { cn as wt } from "@brightlocal/ui-components/lib/utils";
7
+ import { usePrefersReducedMotion as vt } from "./hooks/use-prefers-reduced-motion.js";
8
+ const Y = "M250 500C388.071 500 500 388.071 500 250C500 111.929 388.071 0 250 0C111.929 0 0 111.929 0 250C0 388.071 111.929 500 250 500Z", tt = "M492.425 259.355C332.265 293.145 293.145 332.265 259.355 492.425C257.225 502.525 242.775 502.525 240.645 492.425C206.855 332.265 167.735 293.145 7.575 259.355C-2.525 257.225 -2.525 242.775 7.575 240.645C167.735 206.855 206.855 167.735 240.645 7.575C242.775 -2.525 257.225 -2.525 259.355 7.575C293.145 167.735 332.265 206.855 492.425 240.645C502.525 242.775 502.525 257.225 492.425 259.355Z", et = "M258.366 5.58795L296.379 97.3854C298.509 102.526 304.729 104.546 309.47 101.636L394.177 49.7215C401.057 45.5112 409.598 51.7117 407.708 59.5523L384.506 156.16C383.206 161.571 387.046 166.861 392.596 167.301L491.645 175.092C499.685 175.722 502.945 185.763 496.815 191.003L421.259 255.528C417.029 259.138 417.029 265.679 421.259 269.299L496.815 333.824C502.945 339.065 499.685 349.106 491.645 349.736L392.596 357.526C387.046 357.966 383.206 363.257 384.506 368.667L407.708 465.275C409.588 473.116 401.047 479.326 394.177 475.106L309.47 423.192C304.729 420.282 298.509 422.302 296.379 427.442L258.366 519.24C255.275 526.69 244.725 526.69 241.634 519.24L203.621 427.442C201.491 422.302 195.271 420.282 190.53 423.192L105.823 475.106C98.9428 479.316 90.4021 473.116 92.2922 465.275L115.494 368.667C116.794 363.257 112.954 357.966 107.403 357.526L8.35543 349.736C0.314784 349.106 -2.94548 339.065 3.18502 333.824L78.7411 269.299C82.9715 265.689 82.9715 259.148 78.7411 255.528L3.18502 191.003C-2.94548 185.763 0.314784 175.722 8.35543 175.092L107.403 167.301C112.954 166.861 116.794 161.571 115.494 156.16L92.2922 59.5523C90.4121 51.7117 98.9528 45.5012 105.823 49.7215L190.53 101.636C195.271 104.546 201.491 102.526 203.621 97.3854L241.634 5.58795C244.725 -1.86265 255.275 -1.86265 258.366 5.58795Z", L = (A) => A < 0 ? 0 : A > 1 ? 1 : A, xt = [
9
+ Y,
10
+ tt,
11
+ et,
12
+ Y,
13
+ et,
14
+ tt
15
+ ], Mt = V.forwardRef(
16
+ ({
17
+ className: A,
18
+ dataHook: nt,
19
+ holdTime: S = 1300,
20
+ shimmer: j = !0,
21
+ gradientFrom: rt = "var(--loading-gradient-from)",
22
+ gradientTo: st = "var(--loading-gradient-to)",
23
+ trackingEl: at,
24
+ trackingLabel: ot,
25
+ children: it,
26
+ ...lt
27
+ }, ct) => {
28
+ const o = xt, T = 0.8, F = 180, z = 24, H = 1, k = vt(), D = `text-reveal-gradient-${gt().replace(/:/g, "")}`, N = R(null), U = R(null), B = R(null), _ = R(null), G = R(null), C = R(/* @__PURE__ */ new Map()), P = V.Children.toArray(it), [ft, pt] = Ct({ widths: [], ballSize: 0 }), { widths: b, ballSize: i } = ft, dt = yt(
29
+ (e) => (t) => {
30
+ t ? C.current.set(e, t) : C.current.delete(e);
31
+ },
32
+ []
33
+ );
34
+ Z(() => {
35
+ if (C.current.size === 0) return;
36
+ const e = requestAnimationFrame(() => {
37
+ const t = [];
38
+ let c = 32;
39
+ C.current.forEach((p, n) => {
40
+ if (t[n] = p.scrollWidth, n === 0) {
41
+ const w = p.firstElementChild ?? p, h = parseFloat(getComputedStyle(w).fontSize) || 16;
42
+ c = Math.round(h * 1.5);
43
+ }
44
+ }), pt({ widths: t, ballSize: c });
45
+ });
46
+ return () => cancelAnimationFrame(e);
47
+ }, [P.length]), Z(() => {
48
+ if (k) return;
49
+ const e = G.current;
50
+ if (!e) return;
51
+ const t = e;
52
+ let c, p = null;
53
+ const n = 0.12 + Math.random() * 0.06, w = 0.08 + Math.random() * 0.04, h = Math.random() * Math.PI * 2, q = Math.random() * Math.PI * 2;
54
+ let s = -1 / 0;
55
+ function a(l) {
56
+ p || (p = l);
57
+ const v = (l - p) / 1e3, f = Math.sin(v * n + h) * Math.PI + Math.sin(v * w + q) * 0.5;
58
+ if (Math.abs(f - s) > 0.01) {
59
+ s = f;
60
+ const u = Math.cos(f), x = Math.sin(f);
61
+ t.setAttribute("x1", `${50 + 45 * u}%`), t.setAttribute("y1", `${50 + 45 * x}%`), t.setAttribute("x2", `${50 - 45 * u}%`), t.setAttribute("y2", `${50 - 45 * x}%`);
62
+ }
63
+ c = requestAnimationFrame(a);
64
+ }
65
+ return c = requestAnimationFrame(a), () => cancelAnimationFrame(c);
66
+ }, [k]);
67
+ function mt(e) {
68
+ e.style.opacity = "1", X(0, 1, {
69
+ duration: 1.2,
70
+ ease: [0.25, 1, 0.5, 1],
71
+ onUpdate: (t) => {
72
+ e.style.transform = `translateX(${-100 + t * 200}%)`;
73
+ },
74
+ onComplete: () => {
75
+ e.style.opacity = "0";
76
+ }
77
+ });
78
+ }
79
+ Z(() => {
80
+ if (!B.current || !_.current || !N.current || !U.current || b.length === 0 || i === 0)
81
+ return;
82
+ const e = B.current, t = _.current, c = N.current, p = U.current;
83
+ if (k) {
84
+ e.setAttribute("d", o[0]), t.style.opacity = "1";
85
+ const s = C.current.get(0);
86
+ s && (s.style.visibility = "visible", s.style.clipPath = "none");
87
+ const a = i * 0.5, l = (b[0] ?? 0) + a + i / 2;
88
+ c.style.transform = `translateX(${l}px)`;
89
+ return;
90
+ }
91
+ let n = !1;
92
+ const w = i * 0.5, h = [];
93
+ for (let s = 0; s < o.length; s++)
94
+ h.push(
95
+ bt(o[s], o[(s + 1) % o.length])
96
+ );
97
+ async function q() {
98
+ t.style.opacity = "1";
99
+ let s = 0, a = 0, l = 0;
100
+ for (; !n; ) {
101
+ const v = s % P.length, f = b[v] ?? 0, u = -(w + i / 2), x = f + w + i / 2, J = x - u, W = C.current.get(v);
102
+ if (!W) break;
103
+ C.current.forEach((r, y) => {
104
+ r.style.visibility = y === v ? "visible" : "hidden", r.style.clipPath = "inset(0 100% 0 0)";
105
+ });
106
+ const ht = h[a % o.length], $ = 360, K = l;
107
+ if (await new Promise((r) => {
108
+ if (n) {
109
+ r();
110
+ return;
111
+ }
112
+ const y = X(u, x, {
113
+ type: "spring",
114
+ stiffness: F * T,
115
+ damping: z,
116
+ mass: H,
117
+ onUpdate: (d) => {
118
+ if (n) {
119
+ y.stop(), r();
120
+ return;
121
+ }
122
+ c.style.transform = `translateX(${d}px)`;
123
+ const M = f > 0 ? 100 - L(d / f) * 100 : 100;
124
+ W.style.clipPath = `inset(0 ${M}% 0 0)`;
125
+ const g = (d - u) / J;
126
+ t.style.transform = `rotate(${K + g * $}deg)`, e.setAttribute("d", ht(L(g)));
127
+ },
128
+ onComplete: () => {
129
+ l = K + $, a = (a + 1) % o.length, r();
130
+ }
131
+ });
132
+ }), n) break;
133
+ if (j && mt(p), S > 0) {
134
+ const r = performance.now();
135
+ for (; !n && performance.now() - r < S && (await new Promise((E) => setTimeout(E, 300)), !(n || performance.now() - r >= S)); ) {
136
+ const y = (a + 1) % o.length, d = h[a % o.length], M = l, g = l + 360;
137
+ await X(0, 1, {
138
+ type: "spring",
139
+ stiffness: 30,
140
+ damping: 9,
141
+ mass: 0.5,
142
+ onUpdate: (E) => {
143
+ e.setAttribute("d", d(L(E))), t.style.transform = `rotate(${M + E * (g - M)}deg)`;
144
+ }
145
+ }), l = g, a = y;
146
+ }
147
+ }
148
+ if (n) break;
149
+ const ut = h[a % o.length], Q = l;
150
+ if (await new Promise((r) => {
151
+ if (n) {
152
+ r();
153
+ return;
154
+ }
155
+ const y = X(x, u, {
156
+ type: "spring",
157
+ stiffness: F * T,
158
+ damping: z,
159
+ mass: H,
160
+ onUpdate: (d) => {
161
+ if (n) {
162
+ y.stop(), r();
163
+ return;
164
+ }
165
+ c.style.transform = `translateX(${d}px)`;
166
+ const M = f > 0 ? 100 - L(d / f) * 100 : 100;
167
+ W.style.clipPath = `inset(0 ${M}% 0 0)`;
168
+ const g = 1 - (d - u) / J;
169
+ t.style.transform = `rotate(${Q - g * $}deg)`, e.setAttribute("d", ut(L(g)));
170
+ },
171
+ onComplete: () => {
172
+ l = Q - $, a = (a + 1) % o.length, r();
173
+ }
174
+ });
175
+ }), n) break;
176
+ await new Promise((r) => setTimeout(r, 300)), s++;
177
+ }
178
+ }
179
+ return q(), () => {
180
+ n = !0;
181
+ };
182
+ }, [
183
+ b,
184
+ i,
185
+ P.length,
186
+ k,
187
+ T,
188
+ S,
189
+ j,
190
+ F,
191
+ z,
192
+ H,
193
+ o
194
+ ]);
195
+ const O = b.length > 0 ? Math.max(...b) : 0;
196
+ return /* @__PURE__ */ m(
197
+ "div",
198
+ {
199
+ ref: ct,
200
+ className: wt("relative inline-flex items-center", A),
201
+ "data-hook": nt,
202
+ "data-slot": "text-reveal",
203
+ "data-tracking-el": at,
204
+ "data-tracking-label": ot,
205
+ ...lt,
206
+ children: /* @__PURE__ */ I(
207
+ "div",
208
+ {
209
+ className: "relative flex items-center",
210
+ style: { width: O || void 0 },
211
+ children: [
212
+ /* @__PURE__ */ I(
213
+ "span",
214
+ {
215
+ className: "relative inline-block overflow-hidden",
216
+ style: { width: O || void 0 },
217
+ children: [
218
+ P.map((e, t) => /* @__PURE__ */ m(
219
+ "span",
220
+ {
221
+ ref: dt(t),
222
+ style: {
223
+ display: "block",
224
+ whiteSpace: "nowrap",
225
+ visibility: "hidden",
226
+ clipPath: "inset(0 100% 0 0)",
227
+ willChange: "clip-path, visibility",
228
+ ...t > 0 ? { position: "absolute", top: 0, left: 0 } : {}
229
+ },
230
+ children: e
231
+ },
232
+ t
233
+ )),
234
+ /* @__PURE__ */ m(
235
+ "div",
236
+ {
237
+ ref: U,
238
+ className: "pointer-events-none absolute inset-0",
239
+ style: {
240
+ opacity: 0,
241
+ transform: "translateX(-100%)",
242
+ willChange: "transform, opacity",
243
+ background: "linear-gradient(90deg, transparent 0%, color-mix(in srgb, var(--background) 40%, transparent) 40%, color-mix(in srgb, var(--background) 70%, transparent) 50%, color-mix(in srgb, var(--background) 40%, transparent) 60%, transparent 100%)"
244
+ }
245
+ }
246
+ )
247
+ ]
248
+ }
249
+ ),
250
+ /* @__PURE__ */ m(
251
+ "div",
252
+ {
253
+ ref: N,
254
+ className: "absolute",
255
+ style: {
256
+ left: -i / 2,
257
+ top: "50%",
258
+ marginTop: -i / 2,
259
+ width: i,
260
+ height: i,
261
+ transform: "translateX(0px)",
262
+ willChange: "transform"
263
+ },
264
+ children: /* @__PURE__ */ I(
265
+ "svg",
266
+ {
267
+ "aria-label": "Loading",
268
+ "data-slot": "text-reveal-ball",
269
+ fill: "none",
270
+ height: i,
271
+ role: "img",
272
+ style: { overflow: "visible" },
273
+ viewBox: "-30 -30 560 560",
274
+ width: i,
275
+ xmlns: "http://www.w3.org/2000/svg",
276
+ children: [
277
+ /* @__PURE__ */ m("defs", { children: /* @__PURE__ */ I("linearGradient", { ref: G, id: D, children: [
278
+ /* @__PURE__ */ m("stop", { offset: "-20%", stopColor: rt }),
279
+ /* @__PURE__ */ m("stop", { offset: "120%", stopColor: st })
280
+ ] }) }),
281
+ /* @__PURE__ */ m(
282
+ "g",
283
+ {
284
+ ref: _,
285
+ style: {
286
+ opacity: 0,
287
+ transformOrigin: "250px 250px",
288
+ willChange: "transform"
289
+ },
290
+ children: /* @__PURE__ */ m(
291
+ "path",
292
+ {
293
+ ref: B,
294
+ d: o[0],
295
+ fill: `url(#${D})`
296
+ }
297
+ )
298
+ }
299
+ )
300
+ ]
301
+ }
302
+ )
303
+ }
304
+ )
305
+ ]
306
+ }
307
+ )
308
+ }
309
+ );
310
+ }
311
+ );
312
+ Mt.displayName = "TextRevealMotion";
313
+ export {
314
+ Mt as TextRevealMotion
315
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@brightlocal/ui-components",
3
- "version": "1.2.4",
3
+ "version": "1.3.0",
4
4
  "description": "BrightLocal Design System UI Components",
5
5
  "type": "module",
6
6
  "private": false,
@@ -95,6 +95,7 @@
95
95
  },
96
96
  "devDependencies": {
97
97
  "@size-limit/file": "^12.0.0",
98
+ "@types/flubber": "^0.4.0",
98
99
  "@types/node": "^25.0.10",
99
100
  "@types/react": "^19.2.10",
100
101
  "@types/react-dom": "^19.2.3",
@@ -105,8 +106,8 @@
105
106
  "vite-bundle-visualizer": "^1.2.1",
106
107
  "vite-plugin-dts": "^4.5.4",
107
108
  "vite-plugin-lib-inject-css": "^2.2.2",
108
- "@workspace/typescript-config": "0.0.0",
109
- "@workspace/eslint-config": "0.0.0"
109
+ "@workspace/eslint-config": "0.0.0",
110
+ "@workspace/typescript-config": "0.0.0"
110
111
  },
111
112
  "publishConfig": {
112
113
  "access": "public",
@@ -150,6 +151,7 @@
150
151
  "cmdk": "^1.1.1",
151
152
  "date-fns": "^4.1.0",
152
153
  "embla-carousel-react": "^8.6.0",
154
+ "flubber": "^0.4.2",
153
155
  "framer-motion": "^12.29.2",
154
156
  "input-otp": "^1.4.2",
155
157
  "lucide-react": "^0.475.0",
@@ -27,11 +27,6 @@ export interface InputListProps {
27
27
  * Called when the list of items changes.
28
28
  */
29
29
  onValueChange: (value: string[]) => void;
30
- /**
31
- * Maximum number of items allowed.
32
- * When reached, the input and add button are disabled and a count indicator is shown.
33
- */
34
- maxItems?: number;
35
30
  /**
36
31
  * Placeholder text for the text input.
37
32
  * @default "Add item"
@@ -88,8 +83,7 @@ export interface InputListProps {
88
83
  /**
89
84
  * InputList block — a managed list of text items with an add-input and per-row remove controls.
90
85
  *
91
- * Supports a maximum item limit with count indicator,
92
- * multi-line paste (each line becomes a separate item), loading skeletons, disabled state,
86
+ * Supports multi-line paste (each line becomes a separate item), loading skeletons, disabled state,
93
87
  * and input error/validation state.
94
88
  *
95
89
  * @example
@@ -97,7 +91,6 @@ export interface InputListProps {
97
91
  * <InputList
98
92
  * value={keywords}
99
93
  * onValueChange={setKeywords}
100
- * maxItems={10}
101
94
  * dataHook="keywords"
102
95
  * />
103
96
  * ```
@@ -105,7 +98,6 @@ export interface InputListProps {
105
98
  function InputList({
106
99
  value,
107
100
  onValueChange,
108
- maxItems,
109
101
  placeholder = "Add item",
110
102
  addButtonLabel = "Add",
111
103
  skeletonCount = 3,
@@ -148,27 +140,21 @@ function InputList({
148
140
  });
149
141
  }, [value]);
150
142
 
151
- const atLimit = maxItems !== undefined && value.length >= maxItems;
152
- const inputDisabled = disabled || atLimit || loading;
153
- const buttonDisabled = disabled || atLimit || loading;
143
+ const inputDisabled = disabled || loading;
144
+ const buttonDisabled = disabled || loading;
154
145
 
155
146
  const addItems = React.useCallback(
156
147
  (items: string[]) => {
157
- const trimmed = items.map((s) => s.trim()).filter(Boolean);
158
- if (!trimmed.length) return;
159
- const available =
160
- maxItems !== undefined ? maxItems - value.length : Infinity;
161
- const toAdd = trimmed.slice(0, available);
162
- if (toAdd.length) {
163
- setStableKeys((prev) => [
164
- ...prev,
165
- ...toAdd.map(() => nextIdRef.current++),
166
- ]);
167
- onValueChange([...value, ...toAdd]);
168
- setInputValue("");
169
- }
148
+ const toAdd = items.map((s) => s.trim()).filter(Boolean);
149
+ if (!toAdd.length) return;
150
+ setStableKeys((prev) => [
151
+ ...prev,
152
+ ...toAdd.map(() => nextIdRef.current++),
153
+ ]);
154
+ onValueChange([...value, ...toAdd]);
155
+ setInputValue("");
170
156
  },
171
- [value, maxItems, onValueChange]
157
+ [value, onValueChange]
172
158
  );
173
159
 
174
160
  const removeItem = React.useCallback(
@@ -210,7 +196,7 @@ function InputList({
210
196
  <Item key={i} variant="loading" />
211
197
  ))}
212
198
  </ul>
213
- ) : value.length > 0 ? (
199
+ ) : (
214
200
  <ul
215
201
  className="flex flex-col gap-2"
216
202
  data-hook={`${dataHook}-list`}
@@ -270,7 +256,7 @@ function InputList({
270
256
  ))}
271
257
  </AnimatePresence>
272
258
  </ul>
273
- ) : null}
259
+ )}
274
260
 
275
261
  {/* Input row */}
276
262
  <div className="flex flex-col gap-2" data-slot="input-list-input-area">
@@ -295,36 +281,25 @@ function InputList({
295
281
  </Button>
296
282
  </div>
297
283
 
298
- {/* Error message replaces description and counter */}
284
+ {/* Error message replaces description */}
299
285
  {error && errorMessage ? (
300
286
  <FieldError
287
+ className="text-left"
301
288
  data-slot="input-list-error"
302
289
  dataHook={`${dataHook}-error`}
303
290
  >
304
291
  {errorMessage}
305
292
  </FieldError>
306
293
  ) : (
307
- <>
308
- {/* Description */}
309
- {description && (
310
- <FieldDescription
311
- data-slot="input-list-description"
312
- dataHook={`${dataHook}-description`}
313
- >
314
- {description}
315
- </FieldDescription>
316
- )}
317
-
318
- {/* Count indicator — always shown when maxItems is set */}
319
- {maxItems !== undefined && (
320
- <FieldDescription
321
- data-slot="input-list-count"
322
- dataHook={`${dataHook}-count`}
323
- >
324
- {value.length}/{maxItems}
325
- </FieldDescription>
326
- )}
327
- </>
294
+ description && (
295
+ <FieldDescription
296
+ className="text-left"
297
+ data-slot="input-list-description"
298
+ dataHook={`${dataHook}-description`}
299
+ >
300
+ {description}
301
+ </FieldDescription>
302
+ )
328
303
  )}
329
304
  </div>
330
305
  </div>