@brightlocal/ui-components 1.2.2 → 1.2.4
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/component-meta.json +474 -112
- package/dist/blocks/input-list.cjs +2 -2
- package/dist/blocks/input-list.d.ts.map +1 -1
- package/dist/blocks/input-list.js +142 -166
- package/dist/combobox.cjs +1 -1
- package/dist/combobox.d.ts.map +1 -1
- package/dist/combobox.js +77 -73
- package/package.json +3 -3
- package/src/blocks/input-list.tsx +94 -124
- package/src/components/combobox.tsx +6 -2
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const n=require("react/jsx-runtime"),
|
|
2
|
-
`);
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const n=require("react/jsx-runtime"),T=require("react"),q=require("framer-motion"),z=require("@brightlocal/icons"),A=require("@brightlocal/ui-components/lib/utils"),B=require("../button.cjs"),b=require("../field.cjs"),M=require("../input.cjs"),u=require("../list.cjs");function v(e){const a=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e){for(const s in e)if(s!=="default"){const d=Object.getOwnPropertyDescriptor(e,s);Object.defineProperty(a,s,d.get?d:{enumerable:!0,get:()=>e[s]})}}return a.default=e,Object.freeze(a)}const o=v(T);function I({value:e,onValueChange:a,maxItems:s,placeholder:d="Add item",addButtonLabel:S="Add",skeletonCount:_=3,disabled:p=!1,loading:f=!1,error:y=!1,errorMessage:D,description:$,dataHook:l,trackingEl:O,trackingLabel:P,className:R}){const[h,k]=o.useState(""),g=o.useRef(e.length),[w,m]=o.useState(()=>e.map((t,i)=>i));o.useEffect(()=>{m(t=>t.length===e.length?t:e.length>t.length?[...t,...Array.from({length:e.length-t.length},()=>g.current++)]:e.map(()=>g.current++))},[e]);const N=s!==void 0&&e.length>=s,F=p||N||f,K=p||N||f,j=o.useCallback(t=>{const i=t.map(x=>x.trim()).filter(Boolean);if(!i.length)return;const r=s!==void 0?s-e.length:1/0,c=i.slice(0,r);c.length&&(m(x=>[...x,...c.map(()=>g.current++)]),a([...e,...c]),k(""))},[e,s,a]),L=o.useCallback(t=>{m(i=>i.filter((r,c)=>c!==t)),a(e.filter((i,r)=>r!==t))},[e,a]),C=t=>{t.key==="Enter"&&(t.preventDefault(),j([h]))},E=t=>{const r=t.clipboardData.getData("text").split(`
|
|
2
|
+
`);r.length>1&&(t.preventDefault(),j(r))};return n.jsxs("div",{className:A.cn("flex flex-col gap-4",R),"data-hook":l,"data-slot":"input-list","data-tracking-el":O,"data-tracking-label":P,children:[f?n.jsx("ul",{className:"flex flex-col gap-2","data-slot":"input-list-skeleton",children:Array.from({length:_}).map((t,i)=>n.jsx(u.Item,{variant:"loading"},i))}):e.length>0?n.jsx("ul",{className:"flex flex-col gap-2","data-hook":`${l}-list`,"data-slot":"list",children:n.jsx(q.AnimatePresence,{initial:!1,children:e.map((t,i)=>n.jsx(q.motion.li,{layout:!0,animate:{opacity:1,scale:1},"data-hook":`${l}-item-${i}`,"data-slot":"item",exit:{opacity:0,scale:.8,transition:{opacity:{duration:.15},scale:{duration:.12}}},initial:{opacity:0,scale:.8},transition:{opacity:{duration:.15},scale:{duration:.15},layout:{type:"spring",stiffness:500,damping:35}},children:n.jsxs("div",{className:"bg-card flex items-center gap-4 rounded-lg py-2 pr-2 pl-4",children:[n.jsx(u.ItemContent,{children:n.jsx(u.ItemTitle,{children:t})}),n.jsx(u.ItemActions,{children:n.jsx("button",{"aria-label":`Remove ${t}`,className:A.cn("inline-flex size-9 cursor-pointer items-center justify-center rounded-full","text-muted-foreground","focus-visible:shadow-default outline-none","transition-colors duration-150 ease-in-out","disabled:pointer-events-none disabled:opacity-50"),"data-hook":`${l}-remove-${i}`,disabled:p,type:"button",onClick:()=>L(i),children:n.jsx(z.X,{})})})]})},w[i]))})}):null,n.jsxs("div",{className:"flex flex-col gap-2","data-slot":"input-list-input-area",children:[n.jsxs("div",{className:"flex gap-2",children:[n.jsx(M.Input,{className:"flex-1",dataHook:`${l}-input`,disabled:F,error:y,placeholder:d,value:h,onChange:t=>k(t.target.value),onKeyDown:C,onPaste:E}),n.jsx(B.Button,{dataHook:`${l}-add`,disabled:K,onClick:()=>j([h]),children:S})]}),y&&D?n.jsx(b.FieldError,{"data-slot":"input-list-error",dataHook:`${l}-error`,children:D}):n.jsxs(n.Fragment,{children:[$&&n.jsx(b.FieldDescription,{"data-slot":"input-list-description",dataHook:`${l}-description`,children:$}),s!==void 0&&n.jsxs(b.FieldDescription,{"data-slot":"input-list-count",dataHook:`${l}-count`,children:[e.length,"/",s]})]})]})]})}I.displayName="InputList";exports.InputList=I;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"input-list.d.ts","sourceRoot":"","sources":["../../src/blocks/input-list.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"input-list.d.ts","sourceRoot":"","sources":["../../src/blocks/input-list.tsx"],"names":[],"mappings":"AAgBA;;;GAGG;AACH,MAAM,WAAW,cAAc;IAC7B;;OAEG;IACH,KAAK,EAAE,MAAM,EAAE,CAAC;IAChB;;OAEG;IACH,aAAa,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,IAAI,CAAC;IACzC;;;OAGG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB;;;OAGG;IACH,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB;;;OAGG;IACH,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB;;;OAGG;IACH,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB;;OAEG;IACH,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB;;OAEG;IACH,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB;;OAEG;IACH,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB;;OAEG;IACH,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB;;OAEG;IACH,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB;;OAEG;IACH,QAAQ,EAAE,MAAM,CAAC;IACjB;;OAEG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB;;OAEG;IACH,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB;;OAEG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,iBAAS,SAAS,CAAC,EACjB,KAAK,EACL,aAAa,EACb,QAAQ,EACR,WAAwB,EACxB,cAAsB,EACtB,aAAiB,EACjB,QAAgB,EAChB,OAAe,EACf,KAAa,EACb,YAAY,EACZ,WAAW,EACX,QAAQ,EACR,UAAU,EACV,aAAa,EACb,SAAS,GACV,EAAE,cAAc,2CAmNhB;kBAnOQ,SAAS;;;AAuOlB,OAAO,EAAE,SAAS,EAAE,CAAC"}
|
|
@@ -1,215 +1,191 @@
|
|
|
1
|
-
import { jsxs as
|
|
2
|
-
import * as
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
|
|
1
|
+
import { jsxs as r, jsx as i, Fragment as B } from "react/jsx-runtime";
|
|
2
|
+
import * as s from "react";
|
|
3
|
+
import { AnimatePresence as z, motion as T } from "framer-motion";
|
|
4
|
+
import { X } from "@brightlocal/icons";
|
|
5
|
+
import { cn as N } from "@brightlocal/ui-components/lib/utils";
|
|
6
|
+
import { Button as q } from "../button.js";
|
|
7
|
+
import { FieldError as G, FieldDescription as A } from "../field.js";
|
|
8
|
+
import { Input as J } from "../input.js";
|
|
9
|
+
import { Item as O, ItemContent as Q, ItemTitle as U, ItemActions as W } from "../list.js";
|
|
10
|
+
function Y({
|
|
10
11
|
value: e,
|
|
11
|
-
onValueChange:
|
|
12
|
-
maxItems:
|
|
13
|
-
placeholder:
|
|
14
|
-
addButtonLabel:
|
|
15
|
-
skeletonCount:
|
|
12
|
+
onValueChange: d,
|
|
13
|
+
maxItems: a,
|
|
14
|
+
placeholder: I = "Add item",
|
|
15
|
+
addButtonLabel: K = "Add",
|
|
16
|
+
skeletonCount: R = 3,
|
|
16
17
|
disabled: p = !1,
|
|
17
|
-
loading:
|
|
18
|
-
error:
|
|
19
|
-
errorMessage:
|
|
20
|
-
description:
|
|
18
|
+
loading: f = !1,
|
|
19
|
+
error: b = !1,
|
|
20
|
+
errorMessage: $,
|
|
21
|
+
description: k,
|
|
21
22
|
dataHook: l,
|
|
22
|
-
trackingEl:
|
|
23
|
+
trackingEl: _,
|
|
23
24
|
trackingLabel: j,
|
|
24
|
-
className:
|
|
25
|
+
className: w
|
|
25
26
|
}) {
|
|
26
|
-
const [
|
|
27
|
-
() => /* @__PURE__ */ new Set()
|
|
28
|
-
), [b, D] = o.useState(
|
|
29
|
-
() => /* @__PURE__ */ new Set()
|
|
30
|
-
);
|
|
31
|
-
o.useEffect(() => {
|
|
32
|
-
if (b.size === 0) return;
|
|
33
|
-
const t = requestAnimationFrame(() => {
|
|
34
|
-
D(/* @__PURE__ */ new Set());
|
|
35
|
-
});
|
|
36
|
-
return () => cancelAnimationFrame(t);
|
|
37
|
-
}, [b]);
|
|
38
|
-
const w = o.useRef(e);
|
|
39
|
-
o.useEffect(() => {
|
|
40
|
-
w.current = e;
|
|
41
|
-
}, [e]);
|
|
42
|
-
const y = o.useRef(/* @__PURE__ */ new Set());
|
|
43
|
-
o.useEffect(() => {
|
|
44
|
-
const t = y.current;
|
|
45
|
-
return () => {
|
|
46
|
-
t.forEach(clearTimeout), t.clear();
|
|
47
|
-
};
|
|
48
|
-
}, []);
|
|
49
|
-
const v = o.useRef(e.length), [T, m] = o.useState(
|
|
27
|
+
const [m, x] = s.useState(""), u = s.useRef(e.length), [C, h] = s.useState(
|
|
50
28
|
() => e.map((t, n) => n)
|
|
51
29
|
);
|
|
52
|
-
|
|
53
|
-
|
|
30
|
+
s.useEffect(() => {
|
|
31
|
+
h((t) => t.length === e.length ? t : e.length > t.length ? [
|
|
32
|
+
...t,
|
|
33
|
+
...Array.from(
|
|
34
|
+
{ length: e.length - t.length },
|
|
35
|
+
() => u.current++
|
|
36
|
+
)
|
|
37
|
+
] : e.map(() => u.current++));
|
|
54
38
|
}, [e]);
|
|
55
|
-
const
|
|
39
|
+
const D = a !== void 0 && e.length >= a, E = p || D || f, F = p || D || f, g = s.useCallback(
|
|
56
40
|
(t) => {
|
|
57
|
-
const n = t.map((
|
|
41
|
+
const n = t.map((y) => y.trim()).filter(Boolean);
|
|
58
42
|
if (!n.length) return;
|
|
59
|
-
const
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
const d = e.length;
|
|
65
|
-
D(new Set(i.map((tt, G) => d + G)));
|
|
66
|
-
}
|
|
67
|
-
m((d) => [
|
|
68
|
-
...d,
|
|
69
|
-
...i.map(() => v.current++)
|
|
70
|
-
]), f([...e, ...i]), A("");
|
|
71
|
-
}
|
|
43
|
+
const o = a !== void 0 ? a - e.length : 1 / 0, c = n.slice(0, o);
|
|
44
|
+
c.length && (h((y) => [
|
|
45
|
+
...y,
|
|
46
|
+
...c.map(() => u.current++)
|
|
47
|
+
]), d([...e, ...c]), x(""));
|
|
72
48
|
},
|
|
73
|
-
[e,
|
|
74
|
-
),
|
|
49
|
+
[e, a, d]
|
|
50
|
+
), L = s.useCallback(
|
|
75
51
|
(t) => {
|
|
76
|
-
|
|
77
|
-
"(prefers-reduced-motion: reduce)"
|
|
78
|
-
).matches) {
|
|
79
|
-
m((i) => i.filter((s, d) => d !== t)), f(w.current.filter((i, s) => s !== t));
|
|
80
|
-
return;
|
|
81
|
-
}
|
|
82
|
-
k((i) => new Set(i).add(t));
|
|
83
|
-
const a = setTimeout(() => {
|
|
84
|
-
y.current.delete(a), k((i) => {
|
|
85
|
-
const s = new Set(i);
|
|
86
|
-
return s.delete(t), s;
|
|
87
|
-
}), m((i) => i.filter((s, d) => d !== t)), f(w.current.filter((i, s) => s !== t));
|
|
88
|
-
}, 200);
|
|
89
|
-
y.current.add(a);
|
|
52
|
+
h((n) => n.filter((o, c) => c !== t)), d(e.filter((n, o) => o !== t));
|
|
90
53
|
},
|
|
91
|
-
[
|
|
92
|
-
),
|
|
93
|
-
t.key === "Enter" && (t.preventDefault(),
|
|
94
|
-
},
|
|
95
|
-
const
|
|
54
|
+
[e, d]
|
|
55
|
+
), P = (t) => {
|
|
56
|
+
t.key === "Enter" && (t.preventDefault(), g([m]));
|
|
57
|
+
}, S = (t) => {
|
|
58
|
+
const o = t.clipboardData.getData("text").split(`
|
|
96
59
|
`);
|
|
97
|
-
|
|
60
|
+
o.length > 1 && (t.preventDefault(), g(o));
|
|
98
61
|
};
|
|
99
|
-
return /* @__PURE__ */
|
|
62
|
+
return /* @__PURE__ */ r(
|
|
100
63
|
"div",
|
|
101
64
|
{
|
|
102
|
-
className:
|
|
65
|
+
className: N("flex flex-col gap-4", w),
|
|
103
66
|
"data-hook": l,
|
|
104
67
|
"data-slot": "input-list",
|
|
105
|
-
"data-tracking-el":
|
|
68
|
+
"data-tracking-el": _,
|
|
106
69
|
"data-tracking-label": j,
|
|
107
70
|
children: [
|
|
108
|
-
|
|
71
|
+
f ? /* @__PURE__ */ i("ul", { className: "flex flex-col gap-2", "data-slot": "input-list-skeleton", children: Array.from({ length: R }).map((t, n) => /* @__PURE__ */ i(O, { variant: "loading" }, n)) }) : e.length > 0 ? /* @__PURE__ */ i(
|
|
109
72
|
"ul",
|
|
110
73
|
{
|
|
111
|
-
className: "flex flex-col",
|
|
74
|
+
className: "flex flex-col gap-2",
|
|
112
75
|
"data-hook": `${l}-list`,
|
|
113
76
|
"data-slot": "list",
|
|
114
|
-
children: e.map((t, n) =>
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
{
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
),
|
|
139
|
-
"data-hook": `${l}-remove-${n}`,
|
|
140
|
-
disabled: p || a,
|
|
141
|
-
type: "button",
|
|
142
|
-
onClick: () => P(n),
|
|
143
|
-
children: /* @__PURE__ */ r(J, {})
|
|
144
|
-
}
|
|
145
|
-
) })
|
|
146
|
-
] }) })
|
|
77
|
+
children: /* @__PURE__ */ i(z, { initial: !1, children: e.map((t, n) => /* @__PURE__ */ i(
|
|
78
|
+
T.li,
|
|
79
|
+
{
|
|
80
|
+
layout: !0,
|
|
81
|
+
animate: { opacity: 1, scale: 1 },
|
|
82
|
+
"data-hook": `${l}-item-${n}`,
|
|
83
|
+
"data-slot": "item",
|
|
84
|
+
exit: {
|
|
85
|
+
opacity: 0,
|
|
86
|
+
scale: 0.8,
|
|
87
|
+
transition: {
|
|
88
|
+
opacity: { duration: 0.15 },
|
|
89
|
+
scale: { duration: 0.12 }
|
|
90
|
+
}
|
|
91
|
+
},
|
|
92
|
+
initial: { opacity: 0, scale: 0.8 },
|
|
93
|
+
transition: {
|
|
94
|
+
opacity: { duration: 0.15 },
|
|
95
|
+
scale: { duration: 0.15 },
|
|
96
|
+
layout: {
|
|
97
|
+
type: "spring",
|
|
98
|
+
stiffness: 500,
|
|
99
|
+
damping: 35
|
|
100
|
+
}
|
|
147
101
|
},
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
102
|
+
children: /* @__PURE__ */ r("div", { className: "bg-card flex items-center gap-4 rounded-lg py-2 pr-2 pl-4", children: [
|
|
103
|
+
/* @__PURE__ */ i(Q, { children: /* @__PURE__ */ i(U, { children: t }) }),
|
|
104
|
+
/* @__PURE__ */ i(W, { children: /* @__PURE__ */ i(
|
|
105
|
+
"button",
|
|
106
|
+
{
|
|
107
|
+
"aria-label": `Remove ${t}`,
|
|
108
|
+
className: N(
|
|
109
|
+
"inline-flex size-9 cursor-pointer items-center justify-center rounded-full",
|
|
110
|
+
"text-muted-foreground",
|
|
111
|
+
"focus-visible:shadow-default outline-none",
|
|
112
|
+
"transition-colors duration-150 ease-in-out",
|
|
113
|
+
"disabled:pointer-events-none disabled:opacity-50"
|
|
114
|
+
),
|
|
115
|
+
"data-hook": `${l}-remove-${n}`,
|
|
116
|
+
disabled: p,
|
|
117
|
+
type: "button",
|
|
118
|
+
onClick: () => L(n),
|
|
119
|
+
children: /* @__PURE__ */ i(X, {})
|
|
120
|
+
}
|
|
121
|
+
) })
|
|
122
|
+
] })
|
|
123
|
+
},
|
|
124
|
+
C[n]
|
|
125
|
+
)) })
|
|
151
126
|
}
|
|
152
127
|
) : null,
|
|
153
|
-
/* @__PURE__ */
|
|
154
|
-
/* @__PURE__ */
|
|
155
|
-
/* @__PURE__ */
|
|
156
|
-
|
|
128
|
+
/* @__PURE__ */ r("div", { className: "flex flex-col gap-2", "data-slot": "input-list-input-area", children: [
|
|
129
|
+
/* @__PURE__ */ r("div", { className: "flex gap-2", children: [
|
|
130
|
+
/* @__PURE__ */ i(
|
|
131
|
+
J,
|
|
157
132
|
{
|
|
158
133
|
className: "flex-1",
|
|
159
134
|
dataHook: `${l}-input`,
|
|
160
|
-
disabled:
|
|
161
|
-
error:
|
|
162
|
-
placeholder:
|
|
163
|
-
value:
|
|
164
|
-
onChange: (t) =>
|
|
165
|
-
onKeyDown:
|
|
166
|
-
onPaste:
|
|
135
|
+
disabled: E,
|
|
136
|
+
error: b,
|
|
137
|
+
placeholder: I,
|
|
138
|
+
value: m,
|
|
139
|
+
onChange: (t) => x(t.target.value),
|
|
140
|
+
onKeyDown: P,
|
|
141
|
+
onPaste: S
|
|
167
142
|
}
|
|
168
143
|
),
|
|
169
|
-
/* @__PURE__ */
|
|
170
|
-
|
|
144
|
+
/* @__PURE__ */ i(
|
|
145
|
+
q,
|
|
171
146
|
{
|
|
172
147
|
dataHook: `${l}-add`,
|
|
173
|
-
disabled:
|
|
174
|
-
onClick: () =>
|
|
175
|
-
children:
|
|
148
|
+
disabled: F,
|
|
149
|
+
onClick: () => g([m]),
|
|
150
|
+
children: K
|
|
176
151
|
}
|
|
177
152
|
)
|
|
178
153
|
] }),
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
{
|
|
182
|
-
"data-slot": "input-list-description",
|
|
183
|
-
dataHook: `${l}-description`,
|
|
184
|
-
children: $
|
|
185
|
-
}
|
|
186
|
-
),
|
|
187
|
-
c !== void 0 && /* @__PURE__ */ u(
|
|
188
|
-
_,
|
|
189
|
-
{
|
|
190
|
-
"data-slot": "input-list-count",
|
|
191
|
-
dataHook: `${l}-count`,
|
|
192
|
-
children: [
|
|
193
|
-
e.length,
|
|
194
|
-
"/",
|
|
195
|
-
c
|
|
196
|
-
]
|
|
197
|
-
}
|
|
198
|
-
),
|
|
199
|
-
I && N && /* @__PURE__ */ r(
|
|
200
|
-
Q,
|
|
154
|
+
b && $ ? /* @__PURE__ */ i(
|
|
155
|
+
G,
|
|
201
156
|
{
|
|
202
157
|
"data-slot": "input-list-error",
|
|
203
158
|
dataHook: `${l}-error`,
|
|
204
|
-
children:
|
|
159
|
+
children: $
|
|
205
160
|
}
|
|
206
|
-
)
|
|
161
|
+
) : /* @__PURE__ */ r(B, { children: [
|
|
162
|
+
k && /* @__PURE__ */ i(
|
|
163
|
+
A,
|
|
164
|
+
{
|
|
165
|
+
"data-slot": "input-list-description",
|
|
166
|
+
dataHook: `${l}-description`,
|
|
167
|
+
children: k
|
|
168
|
+
}
|
|
169
|
+
),
|
|
170
|
+
a !== void 0 && /* @__PURE__ */ r(
|
|
171
|
+
A,
|
|
172
|
+
{
|
|
173
|
+
"data-slot": "input-list-count",
|
|
174
|
+
dataHook: `${l}-count`,
|
|
175
|
+
children: [
|
|
176
|
+
e.length,
|
|
177
|
+
"/",
|
|
178
|
+
a
|
|
179
|
+
]
|
|
180
|
+
}
|
|
181
|
+
)
|
|
182
|
+
] })
|
|
207
183
|
] })
|
|
208
184
|
]
|
|
209
185
|
}
|
|
210
186
|
);
|
|
211
187
|
}
|
|
212
|
-
|
|
188
|
+
Y.displayName = "InputList";
|
|
213
189
|
export {
|
|
214
|
-
|
|
190
|
+
Y as InputList
|
|
215
191
|
};
|
package/dist/combobox.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const n=require("react/jsx-runtime"),U=require("react"),
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const n=require("react/jsx-runtime"),U=require("react"),q=require("@brightlocal/icons"),V=require("class-variance-authority"),$=require("cmdk"),k=require("@brightlocal/ui-components/lib/utils"),T=require("@brightlocal/ui-components/popover"),y=require("@brightlocal/ui-components/command");function z(e){const o=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e){for(const a in e)if(a!=="default"){const r=Object.getOwnPropertyDescriptor(e,a);Object.defineProperty(o,a,r.get?r:{enumerable:!0,get:()=>e[a]})}}return o.default=e,Object.freeze(o)}const t=z(U),E=t.createContext(null);function R(){const e=t.useContext(E);if(!e)throw new Error("Combobox components must be used within a <Combobox>");return e}function H({value:e,onValueChange:o,open:a,onOpenChange:r,shouldFilter:u=!0,disabled:c=!1,itemToStringValue:d,children:b}){const[h,C]=t.useState(""),[f,w]=t.useState(!1),[v,i]=t.useState(()=>new Map),x=e!==void 0,p=a!==void 0,s=x?e:h,m=p?a:f,g=t.useCallback(l=>{p||w(l),r?.(l)},[p,r]),j=t.useCallback(l=>{x||C(l),o?.(l)},[x,o]),N=t.useCallback((l,L)=>{i(I=>{if(I.get(l)===L)return I;const O=new Map(I);return O.set(l,L),O})},[]),S=t.useMemo(()=>({open:m,setOpen:g,value:s,onValueChange:j,shouldFilter:u,disabled:c,itemLabels:v,registerItem:N,itemToStringValue:d}),[m,g,s,j,u,c,v,N,d]);return n.jsx(E.Provider,{value:S,children:n.jsx(T.Popover,{open:m,onOpenChange:g,children:b})})}const B=V.cva(["relative flex w-full items-center justify-between gap-2","px-4 py-2 h-9","border border-input rounded-md outline-none","bg-neutral-50 shadow-xs","dark:bg-white/5 dark:border-white/15","text-sm font-normal font-sans text-foreground","data-[placeholder=true]:text-muted-foreground","focus-visible:outline-none focus-visible:border-ring dark:focus-visible:border-neutral-500 focus-visible:bg-background","focus-visible:shadow-default","data-[state=open]:border-ring","disabled:cursor-not-allowed disabled:opacity-50","disabled:hover:bg-neutral-50","transition-[background-color,border-color,box-shadow] duration-200 ease-out","[&_svg]:pointer-events-none [&_svg]:shrink-0"],{variants:{variant:{default:[]}},defaultVariants:{variant:"default"}}),F=t.forwardRef(({className:e,variant:o,dataHook:a,error:r,trackingEl:u,trackingLabel:c,children:d,...b},h)=>{const{open:C,disabled:f,value:w}=R(),v=t.useId(),i=!w,x=r||b["aria-invalid"]===!0||b["aria-invalid"]==="true";return n.jsx(T.PopoverTrigger,{asChild:!0,children:n.jsxs("button",{ref:h,"aria-controls":C?v:void 0,"aria-expanded":C,"aria-haspopup":"listbox","aria-invalid":x?"true":void 0,className:k.cn(B({variant:o}),x&&"border-destructive-40 focus-visible:border-destructive-40 dark:focus-visible:border-destructive-40 focus-visible:shadow-destructive data-[state=open]:border-destructive-40 dark:data-[state=open]:border-destructive-40 data-[state=open]:shadow-destructive",e),"data-hook":a,"data-placeholder":i,"data-slot":"combobox-trigger","data-state":C?"open":"closed","data-tracking-el":u||"combobox-trigger","data-tracking-label":c,disabled:f||b.disabled,role:"combobox",type:"button",...b,children:[d,n.jsx(q.ChevronsUpDown,{"aria-hidden":"true",className:"text-muted-foreground ml-auto shrink-0"})]})})});F.displayName="ComboboxTrigger";function J({placeholder:e,className:o}){const{value:a,itemLabels:r}=R(),u=a?r.get(a)||a:e;return n.jsx("span",{className:k.cn("text-foreground overflow-hidden text-sm leading-normal font-medium text-ellipsis whitespace-nowrap",o),"data-slot":"combobox-value",children:u})}function K({dataHook:e,className:o,children:a,align:r="start",side:u="bottom",sideOffset:c,avoidCollisions:d,hideList:b=!1}){const{open:h,shouldFilter:C,itemToStringValue:f}=R(),[w,v]=t.useState(null),i=t.useRef(null),x=t.useCallback(s=>{if(i.current?.(),i.current=null,!s)return;let m=!1;const g=l=>{m||(l==="top"||l==="bottom")&&(m=!0,j.disconnect(),v(l))},j=new MutationObserver(()=>{g(s.getAttribute("data-side"))});j.observe(s,{attributes:!0,attributeFilter:["data-side"]});let N=0,S=0;N=requestAnimationFrame(()=>{S=requestAnimationFrame(()=>{g(s.getAttribute("data-side"))})}),i.current=()=>{m=!0,j.disconnect(),cancelAnimationFrame(N),cancelAnimationFrame(S)}},[]);t.useEffect(()=>{if(!h){i.current?.(),i.current=null;const s=setTimeout(()=>v(null),150);return()=>clearTimeout(s)}},[h]);const p=t.useMemo(()=>{if(f)return(s,m,g)=>$.defaultFilter(f(s),m,g)},[f]);return n.jsx(T.PopoverContent,{ref:x,align:r,"aria-label":"Options",avoidCollisions:d,className:k.cn("w-[var(--radix-popover-trigger-width)] p-0",o),"data-slot":"combobox-popover",side:w??u,sideOffset:c,children:n.jsx(y.Command,{className:k.cn("border-0 shadow-none",b&&"[&_[data-slot='command-input-wrapper']]:border-b-0"),"data-slot":"combobox-command",dataHook:e||"combobox-command",filter:p,shouldFilter:C,children:a})})}const M=t.forwardRef((e,o)=>n.jsx(y.CommandInput,{ref:o,"data-slot":"combobox-input",...e}));M.displayName="ComboboxInput";const P=t.forwardRef((e,o)=>n.jsx(y.CommandList,{ref:o,"data-slot":"combobox-list",...e}));P.displayName="ComboboxList";const A=t.forwardRef((e,o)=>n.jsx(y.CommandEmpty,{ref:o,"data-slot":"combobox-empty",...e}));A.displayName="ComboboxEmpty";const _=t.forwardRef((e,o)=>n.jsx(y.CommandGroup,{ref:o,"data-slot":"combobox-group",...e}));_.displayName="ComboboxGroup";function Q(e,o,a){if(!o||!o.trim())return e;const r=new RegExp(`(${o.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")})`,"gi"),u=e.split(r);return n.jsx("span",{children:u.map((c,d)=>d%2===1?n.jsx("span",{className:a,children:c},d):n.jsx(t.Fragment,{children:c},d))})}const G=t.forwardRef(({value:e,label:o,dataHook:a,children:r,className:u,highlight:c,highlightClassName:d,keywords:b,...h},C)=>{const{value:f,onValueChange:w,setOpen:v,registerItem:i}=R(),x=f===e,p=t.useMemo(()=>o||(typeof r=="string"?r:typeof r=="number"?String(r):e),[o,r,e]),s=t.useRef(i);t.useEffect(()=>{s.current=i},[i]),t.useEffect(()=>{s.current(e,p)},[e,p]);const m=()=>{w(e===f?"":e),v(!1)},g=()=>c&&typeof r=="string"?Q(r,c,d||"text-sm leading-normal font-semibold"):r;return n.jsxs(y.CommandItem,{ref:C,className:k.cn("justify-between",u),"data-slot":"combobox-item",dataHook:a,keywords:b?[p,...b]:[p],value:e,onSelect:m,...h,children:[g(),x&&n.jsx(q.Check,{"aria-hidden":"true",className:"text-muted-foreground shrink-0"})]})});G.displayName="ComboboxItem";const D=t.forwardRef((e,o)=>n.jsx(y.CommandSeparator,{ref:o,"data-slot":"combobox-separator",...e}));D.displayName="ComboboxSeparator";function W({className:e,children:o}){return n.jsx("div",{"aria-disabled":"true","aria-selected":"false",className:k.cn("text-muted-foreground flex items-center justify-center gap-2 py-6 text-sm",e),"data-slot":"combobox-loading",role:"option",children:o||n.jsxs(n.Fragment,{children:[n.jsx("div",{"aria-hidden":"true",className:"size-4 animate-spin rounded-full border-2 border-current border-t-transparent [animation-duration:0.6s]"}),"Loading..."]})})}exports.Combobox=H;exports.ComboboxContent=K;exports.ComboboxEmpty=A;exports.ComboboxGroup=_;exports.ComboboxInput=M;exports.ComboboxItem=G;exports.ComboboxList=P;exports.ComboboxLoading=W;exports.ComboboxSeparator=D;exports.ComboboxTrigger=F;exports.ComboboxValue=J;
|
package/dist/combobox.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"combobox.d.ts","sourceRoot":"","sources":["../../src/components/combobox.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;A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