@brightlocal/ui-components 1.3.0 → 1.4.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.
package/README.md CHANGED
@@ -24,7 +24,7 @@ pnpm add @brightlocal/tokens
24
24
 
25
25
  ## Components
26
26
 
27
- This package includes 62 components built on Radix UI primitives and other React libraries. All components are fully typed with TypeScript and follow BrightLocal's design system patterns.
27
+ This package includes 62 components and 3 blocks built on Radix UI primitives and other React libraries. All components are fully typed with TypeScript and follow BrightLocal's design system patterns.
28
28
 
29
29
  ### Layout Components
30
30
 
@@ -89,6 +89,12 @@ This package includes 62 components built on Radix UI primitives and other React
89
89
  - **Progress** - Progress indicators
90
90
  - **Sonner** - Toast notifications
91
91
 
92
+ ### Block Components
93
+
94
+ - **DataTable** - Complex data table with sorting, filtering, and pagination
95
+ - **InputList** - Editable list of text items with add/remove, paste support, and validation
96
+ - **Sidebar** - Complex sidebar navigation with collapsible support
97
+
92
98
  ### Display Components
93
99
 
94
100
  - **Accordion** - Expandable/collapsible sections
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@brightlocal/ui-components",
3
- "version": "1.3.0",
3
+ "version": "1.4.1",
4
4
  "description": "Machine-readable registry of all components in the BrightLocal Design System",
5
5
  "components": [
6
6
  {
@@ -1426,23 +1426,22 @@
1426
1426
  "import": "@brightlocal/ui-components/blocks/input-list",
1427
1427
  "category": "block",
1428
1428
  "exports": [
1429
- "InputList"
1429
+ "InputList",
1430
+ "InputListItems",
1431
+ "InputListInput",
1432
+ "InputListAddButton",
1433
+ "useInputListContext"
1430
1434
  ],
1431
- "compound": false,
1435
+ "compound": true,
1432
1436
  "dataHookRequired": true,
1433
1437
  "variants": {},
1434
1438
  "props": [
1435
1439
  "value",
1436
1440
  "onValueChange",
1437
- "placeholder",
1438
- "addButtonLabel",
1439
- "loading",
1440
- "disabled",
1441
- "error",
1442
- "errorMessage",
1443
- "description"
1441
+ "children",
1442
+ "className"
1444
1443
  ],
1445
- "description": "Editable list of text items with add/remove"
1444
+ "description": "Editable list of text items with add/remove, paste support, and validation"
1446
1445
  },
1447
1446
  {
1448
1447
  "name": "Sidebar",
@@ -1,2 +1,2 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const n=require("react/jsx-runtime"),E=require("react"),I=require("framer-motion"),L=require("@brightlocal/icons"),N=require("@brightlocal/ui-components/lib/utils"),T=require("../button.cjs"),D=require("../field.cjs"),z=require("../input.cjs"),d=require("../list.cjs");function B(e){const a=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e){for(const r in e)if(r!=="default"){const c=Object.getOwnPropertyDescriptor(e,r);Object.defineProperty(a,r,c.get?c:{enumerable:!0,get:()=>e[r]})}}return a.default=e,Object.freeze(a)}const o=B(E);function k({value:e,onValueChange:a,placeholder:r="Add item",addButtonLabel:c="Add",skeletonCount:$=3,disabled:u=!1,loading:f=!1,error:g=!1,errorMessage:b,description:j,dataHook:l,trackingEl:q,trackingLabel:A,className:S}){const[p,y]=o.useState(""),m=o.useRef(e.length),[_,x]=o.useState(()=>e.map((t,s)=>s));o.useEffect(()=>{x(t=>t.length===e.length?t:e.length>t.length?[...t,...Array.from({length:e.length-t.length},()=>m.current++)]:e.map(()=>m.current++))},[e]);const O=u||f,P=u||f,h=o.useCallback(t=>{const s=t.map(i=>i.trim()).filter(Boolean);s.length&&(x(i=>[...i,...s.map(()=>m.current++)]),a([...e,...s]),y(""))},[e,a]),R=o.useCallback(t=>{x(s=>s.filter((i,C)=>C!==t)),a(e.filter((s,i)=>i!==t))},[e,a]),w=t=>{t.key==="Enter"&&(t.preventDefault(),h([p]))},K=t=>{const i=t.clipboardData.getData("text").split(`
2
- `);i.length>1&&(t.preventDefault(),h(i))};return n.jsxs("div",{className:N.cn("flex flex-col gap-4",S),"data-hook":l,"data-slot":"input-list","data-tracking-el":q,"data-tracking-label":A,children:[f?n.jsx("ul",{className:"flex flex-col gap-2","data-slot":"input-list-skeleton",children:Array.from({length:$}).map((t,s)=>n.jsx(d.Item,{variant:"loading"},s))}):n.jsx("ul",{className:"flex flex-col gap-2","data-hook":`${l}-list`,"data-slot":"list",children:n.jsx(I.AnimatePresence,{initial:!1,children:e.map((t,s)=>n.jsx(I.motion.li,{layout:!0,animate:{opacity:1,scale:1},"data-hook":`${l}-item-${s}`,"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(d.ItemContent,{children:n.jsx(d.ItemTitle,{children:t})}),n.jsx(d.ItemActions,{children:n.jsx("button",{"aria-label":`Remove ${t}`,className:N.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-${s}`,disabled:u,type:"button",onClick:()=>R(s),children:n.jsx(L.X,{})})})]})},_[s]))})}),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(z.Input,{className:"flex-1",dataHook:`${l}-input`,disabled:O,error:g,placeholder:r,value:p,onChange:t=>y(t.target.value),onKeyDown:w,onPaste:K}),n.jsx(T.Button,{dataHook:`${l}-add`,disabled:P,onClick:()=>h([p]),children:c})]}),g&&b?n.jsx(D.FieldError,{className:"text-left","data-slot":"input-list-error",dataHook:`${l}-error`,children:b}):j&&n.jsx(D.FieldDescription,{className:"text-left","data-slot":"input-list-description",dataHook:`${l}-description`,children:j})]})]})}k.displayName="InputList";exports.InputList=k;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),_=require("react"),k=require("framer-motion"),K=require("@brightlocal/icons"),x=require("@brightlocal/ui-components/lib/utils"),O=require("../button.cjs"),$=require("../input.cjs"),g=require("../list.cjs");function B(t){const s=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(t){for(const a in t)if(a!=="default"){const o=Object.getOwnPropertyDescriptor(t,a);Object.defineProperty(s,a,o.get?o:{enumerable:!0,get:()=>t[a]})}}return s.default=t,Object.freeze(s)}const r=B(_),A=r.createContext(null);function y(){const t=r.useContext(A);if(!t)throw new Error("InputList components must be used within an <InputList>");return t}function w({value:t,onValueChange:s,children:a,className:o,dataHook:c,trackingEl:u,trackingLabel:I}){const[m,d]=r.useState(""),l=r.useRef(t.length),i=r.useRef(t.length),[b,h]=r.useState(()=>t.map((p,n)=>n)),[N,q]=r.useState(0);r.useEffect(()=>{const p=l.current;l.current=t.length,t.length>p&&d(""),h(n=>n.length===t.length?n:t.length>n.length?[...n,...Array.from({length:t.length-n.length},()=>i.current++)]:t.length===p?n.slice(0,t.length):t.map(()=>i.current++))},[t,N]);const j=r.useCallback(p=>{const n=p.map(f=>f.trim()).filter(Boolean);n.length&&(h(f=>[...f,...n.map(()=>i.current++)]),s([...t,...n]),q(f=>f+1))},[t,s]),L=r.useCallback(p=>{h(n=>n.filter((f,S)=>S!==p)),s(t.filter((n,f)=>f!==p))},[t,s]),P=r.useMemo(()=>({value:t,inputValue:m,setInputValue:d,addItems:j,removeItem:L,stableKeys:b}),[t,m,j,L,b]);return e.jsx(A.Provider,{value:P,children:e.jsx("div",{className:x.cn("flex flex-col gap-4",o),"data-hook":c,"data-slot":"input-list","data-tracking-el":u,"data-tracking-label":I,children:a})})}w.displayName="InputList";function C({dataHook:t="input-list",loading:s=!1,skeletonCount:a=5,disabled:o=!1,className:c}){const{value:u,removeItem:I,stableKeys:m}=y();return s?e.jsx("ul",{className:x.cn("flex flex-col gap-2",c),"data-slot":"input-list-skeleton",children:Array.from({length:a}).map((d,l)=>e.jsx(g.Item,{variant:"loading"},l))}):e.jsx("ul",{className:x.cn("flex flex-col gap-2",c),"data-hook":`${t}-list`,"data-slot":"list",children:e.jsx(k.AnimatePresence,{initial:!1,children:u.map((d,l)=>e.jsx(k.motion.li,{layout:!0,animate:{opacity:1,scale:1},"data-hook":`${t}-item-${l}`,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:e.jsx(g.Item,{asChild:!0,variant:"filled",children:e.jsxs("div",{children:[e.jsx(g.ItemContent,{children:e.jsx(g.ItemTitle,{children:d})}),e.jsx(g.ItemActions,{children:e.jsx("button",{"aria-label":`Remove ${d}`,className:x.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":`${t}-remove-${l}`,disabled:o,type:"button",onClick:()=>I(l),children:e.jsx(K.X,{})})})]})})},m[l]))})})}C.displayName="InputListItems";const R=r.forwardRef(({dataHook:t,error:s=!1,className:a,...o},c)=>{const{inputValue:u,setInputValue:I,addItems:m}=y(),d=i=>{i.key==="Enter"&&(i.preventDefault(),m([u])),o.onKeyDown?.(i)},l=i=>{const h=i.clipboardData.getData("text").split(`
2
+ `);h.length>1&&(i.preventDefault(),m(h)),o.onPaste?.(i)};return e.jsx($.Input,{ref:c,...o,className:x.cn("flex-1",a),dataHook:t,error:s,value:u,onChange:i=>{I(i.target.value),o.onChange?.(i)},onKeyDown:d,onPaste:l})});R.displayName="InputListInput";const D=r.forwardRef(({dataHook:t,children:s,...a},o)=>{const{inputValue:c,addItems:u}=y();return e.jsx(O.Button,{ref:o,...a,dataHook:t,onClick:()=>u([c]),children:s})});D.displayName="InputListAddButton";exports.InputList=w;exports.InputListAddButton=D;exports.InputListInput=R;exports.InputListItems=C;exports.useInputListContext=y;
@@ -1,6 +1,18 @@
1
+ import { ButtonProps } from '../button';
2
+ import * as React from "react";
3
+ interface InputListContextValue {
4
+ value: string[];
5
+ inputValue: string;
6
+ setInputValue: (value: string) => void;
7
+ addItems: (items: string[]) => void;
8
+ removeItem: (index: number) => void;
9
+ /** Stable keys for AnimatePresence tracking */
10
+ stableKeys: number[];
11
+ }
12
+ declare function useInputListContext(): InputListContextValue;
1
13
  /**
2
- * Props for the InputList block component.
3
- * Manages a list of text items with add-input, per-row remove controls, and validation states.
14
+ * Props for the InputList context provider.
15
+ * Manages a list of text items with add/remove logic and validation.
4
16
  */
5
17
  export interface InputListProps {
6
18
  /**
@@ -12,75 +24,126 @@ export interface InputListProps {
12
24
  */
13
25
  onValueChange: (value: string[]) => void;
14
26
  /**
15
- * Placeholder text for the text input.
16
- * @default "Add item"
27
+ * Children — compose with InputListItems and InputListInput.
17
28
  */
18
- placeholder?: string;
29
+ children: React.ReactNode;
19
30
  /**
20
- * Label for the add button.
21
- * @default "Add"
31
+ * Additional CSS classes applied to the root element.
22
32
  */
23
- addButtonLabel?: string;
33
+ className?: string;
24
34
  /**
25
- * Number of skeleton rows to render in the loading state.
26
- * @default 3
35
+ * Data hook for automated testing (required).
27
36
  */
28
- skeletonCount?: number;
37
+ dataHook: string;
29
38
  /**
30
- * Fully disables the component — input and all remove buttons become non-interactive.
39
+ * Tracking element identifier for analytics.
31
40
  */
32
- disabled?: boolean;
41
+ trackingEl?: string;
33
42
  /**
34
- * Shows skeleton placeholder rows instead of the item list.
43
+ * Tracking label for analytics context.
35
44
  */
36
- loading?: boolean;
45
+ trackingLabel?: string;
46
+ }
47
+ /**
48
+ * InputList context provider — manages state for a list of text items
49
+ * with add, remove, paste, and validation support.
50
+ *
51
+ * @example
52
+ * ```tsx
53
+ * <InputList value={keywords} onValueChange={setKeywords} dataHook="keywords">
54
+ * <InputListItems />
55
+ * <InputListInput placeholder="Add keyword" />
56
+ * </InputList>
57
+ * ```
58
+ */
59
+ declare function InputList({ value, onValueChange, children, className, dataHook, trackingEl, trackingLabel, }: InputListProps): import("react/jsx-runtime").JSX.Element;
60
+ declare namespace InputList {
61
+ var displayName: string;
62
+ }
63
+ /**
64
+ * Props for the InputListItems sub-component.
65
+ */
66
+ export interface InputListItemsProps {
37
67
  /**
38
- * Applies an error style to the input.
68
+ * Data hook prefix for item elements.
69
+ * @default "input-list"
39
70
  */
40
- error?: boolean;
71
+ dataHook?: string;
41
72
  /**
42
- * Optional validation message shown below the input when `error` is true.
73
+ * Shows skeleton placeholder rows instead of the item list.
43
74
  */
44
- errorMessage?: string;
75
+ loading?: boolean;
45
76
  /**
46
- * Optional description text shown below the input.
77
+ * Number of skeleton rows to render in the loading state.
78
+ * @default 5
47
79
  */
48
- description?: string;
80
+ skeletonCount?: number;
49
81
  /**
50
- * Data hook for automated testing (required).
82
+ * Disables all remove buttons in the list.
51
83
  */
52
- dataHook: string;
84
+ disabled?: boolean;
53
85
  /**
54
- * Tracking element identifier for analytics.
86
+ * Additional CSS classes applied to the list element.
55
87
  */
56
- trackingEl?: string;
88
+ className?: string;
89
+ }
90
+ /**
91
+ * Renders the animated item list or loading skeletons.
92
+ * Must be used within an `<InputList>` component.
93
+ *
94
+ * @example
95
+ * ```tsx
96
+ * <InputList value={items} onValueChange={setItems} dataHook="my-list">
97
+ * <InputListItems skeletonCount={5} />
98
+ * <InputListInput placeholder="Add item" />
99
+ * </InputList>
100
+ * ```
101
+ */
102
+ declare function InputListItems({ dataHook, loading, skeletonCount, disabled, className, }: InputListItemsProps): import("react/jsx-runtime").JSX.Element;
103
+ declare namespace InputListItems {
104
+ var displayName: string;
105
+ }
106
+ /**
107
+ * Props for the InputListInput sub-component.
108
+ *
109
+ * Inherits native input props except `value` and `type` (managed by InputList context).
110
+ * `onChange` fires as a notification only — the input value is controlled by context,
111
+ * so it cannot be used to filter or transform input.
112
+ */
113
+ export interface InputListInputProps extends Omit<React.ComponentPropsWithoutRef<"input">, "value" | "type"> {
57
114
  /**
58
- * Tracking label for analytics context.
115
+ * Data hook for the input element.
59
116
  */
60
- trackingLabel?: string;
117
+ dataHook: string;
61
118
  /**
62
- * Additional CSS classes applied to the root element.
119
+ * Applies an error style to the input.
63
120
  */
64
- className?: string;
121
+ error?: boolean;
65
122
  }
66
123
  /**
67
- * InputList block — a managed list of text items with an add-input and per-row remove controls.
124
+ * Text input that adds items on Enter and supports multi-line paste.
125
+ * Must be used within an `<InputList>` component.
68
126
  *
69
- * Supports multi-line paste (each line becomes a separate item), loading skeletons, disabled state,
70
- * and input error/validation state.
127
+ * @example
128
+ * ```tsx
129
+ * <InputListInput dataHook="keywords-input" placeholder="Add keyword" />
130
+ * ```
131
+ */
132
+ declare const InputListInput: React.ForwardRefExoticComponent<InputListInputProps & React.RefAttributes<HTMLInputElement>>;
133
+ /**
134
+ * Props for the InputListAddButton sub-component.
135
+ * Inherits all Button props except `onClick` (wired internally to add items).
136
+ */
137
+ export type InputListAddButtonProps = Omit<ButtonProps, "onClick">;
138
+ /**
139
+ * Button that adds the current input value to the list.
140
+ * Must be used within an `<InputList>` component.
71
141
  *
72
142
  * @example
73
143
  * ```tsx
74
- * <InputList
75
- * value={keywords}
76
- * onValueChange={setKeywords}
77
- * dataHook="keywords"
78
- * />
144
+ * <InputListAddButton dataHook="keywords-add">Add</InputListAddButton>
79
145
  * ```
80
146
  */
81
- declare function InputList({ value, onValueChange, placeholder, addButtonLabel, skeletonCount, disabled, loading, error, errorMessage, description, dataHook, trackingEl, trackingLabel, className, }: InputListProps): import("react/jsx-runtime").JSX.Element;
82
- declare namespace InputList {
83
- var displayName: string;
84
- }
85
- export { InputList };
147
+ declare const InputListAddButton: React.ForwardRefExoticComponent<Omit<InputListAddButtonProps, "ref"> & React.RefAttributes<HTMLButtonElement>>;
148
+ export { InputList, InputListItems, InputListInput, InputListAddButton, useInputListContext, };
86
149
  //# sourceMappingURL=input-list.d.ts.map
@@ -1 +1 @@
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,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;;;;;;;;;;;;;;GAcG;AACH,iBAAS,SAAS,CAAC,EACjB,KAAK,EACL,aAAa,EACb,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,2CAkMhB;kBAjNQ,SAAS;;;AAqNlB,OAAO,EAAE,SAAS,EAAE,CAAC"}
1
+ {"version":3,"file":"input-list.d.ts","sourceRoot":"","sources":["../../src/blocks/input-list.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAK/B,OAAO,EAAU,KAAK,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAQhE,UAAU,qBAAqB;IAC7B,KAAK,EAAE,MAAM,EAAE,CAAC;IAChB,UAAU,EAAE,MAAM,CAAC;IACnB,aAAa,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;IACvC,QAAQ,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,IAAI,CAAC;IACpC,UAAU,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;IACpC,+CAA+C;IAC/C,UAAU,EAAE,MAAM,EAAE,CAAC;CACtB;AAMD,iBAAS,mBAAmB,0BAM3B;AAMD;;;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;;OAEG;IACH,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAC;IAC1B;;OAEG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB;;OAEG;IACH,QAAQ,EAAE,MAAM,CAAC;IACjB;;OAEG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB;;OAEG;IACH,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB;AAED;;;;;;;;;;;GAWG;AACH,iBAAS,SAAS,CAAC,EACjB,KAAK,EACL,aAAa,EACb,QAAQ,EACR,SAAS,EACT,QAAQ,EACR,UAAU,EACV,aAAa,GACd,EAAE,cAAc,2CA6FhB;kBArGQ,SAAS;;;AA6GlB;;GAEG;AACH,MAAM,WAAW,mBAAmB;IAClC;;;OAGG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB;;OAEG;IACH,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB;;;OAGG;IACH,aAAa,CAAC,EAAE,MAAM,CAAC;IAEvB;;OAEG;IACH,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB;;OAEG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED;;;;;;;;;;;GAWG;AACH,iBAAS,cAAc,CAAC,EACtB,QAAuB,EACvB,OAAe,EACf,aAAiB,EACjB,QAAgB,EAChB,SAAS,GACV,EAAE,mBAAmB,2CA8ErB;kBApFQ,cAAc;;;AA4FvB;;;;;;GAMG;AACH,MAAM,WAAW,mBAAoB,SAAQ,IAAI,CAC/C,KAAK,CAAC,wBAAwB,CAAC,OAAO,CAAC,EACvC,OAAO,GAAG,MAAM,CACjB;IACC;;OAEG;IACH,QAAQ,EAAE,MAAM,CAAC;IACjB;;OAEG;IACH,KAAK,CAAC,EAAE,OAAO,CAAC;CACjB;AAED;;;;;;;;GAQG;AACH,QAAA,MAAM,cAAc,8FAuCnB,CAAC;AAOF;;;GAGG;AACH,MAAM,MAAM,uBAAuB,GAAG,IAAI,CAAC,WAAW,EAAE,SAAS,CAAC,CAAC;AAEnE;;;;;;;;GAQG;AACH,QAAA,MAAM,kBAAkB,gHAgBtB,CAAC;AAOH,OAAO,EACL,SAAS,EACT,cAAc,EACd,cAAc,EACd,kBAAkB,EAClB,mBAAmB,GACpB,CAAC"}
@@ -1,176 +1,199 @@
1
- import { jsxs as r, jsx as a } from "react/jsx-runtime";
1
+ import { jsx as n, jsxs as D } from "react/jsx-runtime";
2
2
  import * as s from "react";
3
- import { AnimatePresence as P, motion as S } from "framer-motion";
4
- import { X as B } from "@brightlocal/icons";
5
- import { cn as b } from "@brightlocal/ui-components/lib/utils";
6
- import { Button as F } from "../button.js";
7
- import { FieldError as L, FieldDescription as z } from "../field.js";
8
- import { Input as T } from "../input.js";
9
- import { Item as X, ItemContent as q, ItemTitle as G, ItemActions as J } from "../list.js";
10
- function O({
11
- value: i,
12
- onValueChange: o,
13
- placeholder: I = "Add item",
14
- addButtonLabel: N = "Add",
15
- skeletonCount: $ = 3,
16
- disabled: c = !1,
17
- loading: d = !1,
18
- error: h = !1,
19
- errorMessage: g,
20
- description: y,
3
+ import { AnimatePresence as K, motion as $ } from "framer-motion";
4
+ import { X as P } from "@brightlocal/icons";
5
+ import { cn as g } from "@brightlocal/ui-components/lib/utils";
6
+ import { Button as B } from "../button.js";
7
+ import { Input as S } from "../input.js";
8
+ import { Item as k, ItemContent as V, ItemTitle as _, ItemActions as j } from "../list.js";
9
+ const A = s.createContext(
10
+ null
11
+ );
12
+ function x() {
13
+ const t = s.useContext(A);
14
+ if (!t)
15
+ throw new Error("InputList components must be used within an <InputList>");
16
+ return t;
17
+ }
18
+ function E({
19
+ value: t,
20
+ onValueChange: a,
21
+ children: f,
22
+ className: r,
21
23
  dataHook: l,
22
- trackingEl: k,
23
- trackingLabel: D,
24
- className: A
24
+ trackingEl: c,
25
+ trackingLabel: I
25
26
  }) {
26
- const [m, x] = s.useState(""), p = s.useRef(i.length), [K, f] = s.useState(
27
- () => i.map((t, e) => e)
28
- );
27
+ const [p, u] = s.useState(""), o = s.useRef(t.length), i = s.useRef(t.length), [y, h] = s.useState(
28
+ () => t.map((d, e) => e)
29
+ ), [w, C] = s.useState(0);
29
30
  s.useEffect(() => {
30
- f((t) => t.length === i.length ? t : i.length > t.length ? [
31
- ...t,
31
+ const d = o.current;
32
+ o.current = t.length, t.length > d && u(""), h((e) => e.length === t.length ? e : t.length > e.length ? [
33
+ ...e,
32
34
  ...Array.from(
33
- { length: i.length - t.length },
34
- () => p.current++
35
+ { length: t.length - e.length },
36
+ () => i.current++
35
37
  )
36
- ] : i.map(() => p.current++));
37
- }, [i]);
38
- const R = c || d, _ = c || d, u = s.useCallback(
39
- (t) => {
40
- const e = t.map((n) => n.trim()).filter(Boolean);
41
- e.length && (f((n) => [
42
- ...n,
43
- ...e.map(() => p.current++)
44
- ]), o([...i, ...e]), x(""));
38
+ ] : t.length === d ? e.slice(0, t.length) : t.map(() => i.current++));
39
+ }, [t, w]);
40
+ const b = s.useCallback(
41
+ (d) => {
42
+ const e = d.map((m) => m.trim()).filter(Boolean);
43
+ e.length && (h((m) => [
44
+ ...m,
45
+ ...e.map(() => i.current++)
46
+ ]), a([...t, ...e]), C((m) => m + 1));
45
47
  },
46
- [i, o]
47
- ), j = s.useCallback(
48
- (t) => {
49
- f((e) => e.filter((n, E) => E !== t)), o(i.filter((e, n) => n !== t));
48
+ [t, a]
49
+ ), L = s.useCallback(
50
+ (d) => {
51
+ h((e) => e.filter((m, R) => R !== d)), a(t.filter((e, m) => m !== d));
50
52
  },
51
- [i, o]
52
- ), w = (t) => {
53
- t.key === "Enter" && (t.preventDefault(), u([m]));
54
- }, C = (t) => {
55
- const n = t.clipboardData.getData("text").split(`
56
- `);
57
- n.length > 1 && (t.preventDefault(), u(n));
58
- };
59
- return /* @__PURE__ */ r(
53
+ [t, a]
54
+ ), N = s.useMemo(
55
+ () => ({
56
+ value: t,
57
+ inputValue: p,
58
+ setInputValue: u,
59
+ addItems: b,
60
+ removeItem: L,
61
+ stableKeys: y
62
+ }),
63
+ [t, p, b, L, y]
64
+ );
65
+ return /* @__PURE__ */ n(A.Provider, { value: N, children: /* @__PURE__ */ n(
60
66
  "div",
61
67
  {
62
- className: b("flex flex-col gap-4", A),
68
+ className: g("flex flex-col gap-4", r),
63
69
  "data-hook": l,
64
70
  "data-slot": "input-list",
65
- "data-tracking-el": k,
66
- "data-tracking-label": D,
67
- children: [
68
- d ? /* @__PURE__ */ a("ul", { className: "flex flex-col gap-2", "data-slot": "input-list-skeleton", children: Array.from({ length: $ }).map((t, e) => /* @__PURE__ */ a(X, { variant: "loading" }, e)) }) : /* @__PURE__ */ a(
69
- "ul",
70
- {
71
- className: "flex flex-col gap-2",
72
- "data-hook": `${l}-list`,
73
- "data-slot": "list",
74
- children: /* @__PURE__ */ a(P, { initial: !1, children: i.map((t, e) => /* @__PURE__ */ a(
75
- S.li,
76
- {
77
- layout: !0,
78
- animate: { opacity: 1, scale: 1 },
79
- "data-hook": `${l}-item-${e}`,
80
- "data-slot": "item",
81
- exit: {
82
- opacity: 0,
83
- scale: 0.8,
84
- transition: {
85
- opacity: { duration: 0.15 },
86
- scale: { duration: 0.12 }
87
- }
88
- },
89
- initial: { opacity: 0, scale: 0.8 },
90
- transition: {
91
- opacity: { duration: 0.15 },
92
- scale: { duration: 0.15 },
93
- layout: {
94
- type: "spring",
95
- stiffness: 500,
96
- damping: 35
97
- }
98
- },
99
- children: /* @__PURE__ */ r("div", { className: "bg-card flex items-center gap-4 rounded-lg py-2 pr-2 pl-4", children: [
100
- /* @__PURE__ */ a(q, { children: /* @__PURE__ */ a(G, { children: t }) }),
101
- /* @__PURE__ */ a(J, { children: /* @__PURE__ */ a(
102
- "button",
103
- {
104
- "aria-label": `Remove ${t}`,
105
- className: b(
106
- "inline-flex size-9 cursor-pointer items-center justify-center rounded-full",
107
- "text-muted-foreground",
108
- "focus-visible:shadow-default outline-none",
109
- "transition-colors duration-150 ease-in-out",
110
- "disabled:pointer-events-none disabled:opacity-50"
111
- ),
112
- "data-hook": `${l}-remove-${e}`,
113
- disabled: c,
114
- type: "button",
115
- onClick: () => j(e),
116
- children: /* @__PURE__ */ a(B, {})
117
- }
118
- ) })
119
- ] })
120
- },
121
- K[e]
122
- )) })
123
- }
124
- ),
125
- /* @__PURE__ */ r("div", { className: "flex flex-col gap-2", "data-slot": "input-list-input-area", children: [
126
- /* @__PURE__ */ r("div", { className: "flex gap-2", children: [
127
- /* @__PURE__ */ a(
128
- T,
129
- {
130
- className: "flex-1",
131
- dataHook: `${l}-input`,
132
- disabled: R,
133
- error: h,
134
- placeholder: I,
135
- value: m,
136
- onChange: (t) => x(t.target.value),
137
- onKeyDown: w,
138
- onPaste: C
139
- }
140
- ),
141
- /* @__PURE__ */ a(
142
- F,
143
- {
144
- dataHook: `${l}-add`,
145
- disabled: _,
146
- onClick: () => u([m]),
147
- children: N
148
- }
149
- )
150
- ] }),
151
- h && g ? /* @__PURE__ */ a(
152
- L,
153
- {
154
- className: "text-left",
155
- "data-slot": "input-list-error",
156
- dataHook: `${l}-error`,
157
- children: g
71
+ "data-tracking-el": c,
72
+ "data-tracking-label": I,
73
+ children: f
74
+ }
75
+ ) });
76
+ }
77
+ E.displayName = "InputList";
78
+ function z({
79
+ dataHook: t = "input-list",
80
+ loading: a = !1,
81
+ skeletonCount: f = 5,
82
+ disabled: r = !1,
83
+ className: l
84
+ }) {
85
+ const { value: c, removeItem: I, stableKeys: p } = x();
86
+ return a ? /* @__PURE__ */ n(
87
+ "ul",
88
+ {
89
+ className: g("flex flex-col gap-2", l),
90
+ "data-slot": "input-list-skeleton",
91
+ children: Array.from({ length: f }).map((u, o) => /* @__PURE__ */ n(k, { variant: "loading" }, o))
92
+ }
93
+ ) : /* @__PURE__ */ n(
94
+ "ul",
95
+ {
96
+ className: g("flex flex-col gap-2", l),
97
+ "data-hook": `${t}-list`,
98
+ "data-slot": "list",
99
+ children: /* @__PURE__ */ n(K, { initial: !1, children: c.map((u, o) => /* @__PURE__ */ n(
100
+ $.li,
101
+ {
102
+ layout: !0,
103
+ animate: { opacity: 1, scale: 1 },
104
+ "data-hook": `${t}-item-${o}`,
105
+ exit: {
106
+ opacity: 0,
107
+ scale: 0.8,
108
+ transition: {
109
+ opacity: { duration: 0.15 },
110
+ scale: { duration: 0.12 }
158
111
  }
159
- ) : y && /* @__PURE__ */ a(
160
- z,
161
- {
162
- className: "text-left",
163
- "data-slot": "input-list-description",
164
- dataHook: `${l}-description`,
165
- children: y
112
+ },
113
+ initial: { opacity: 0, scale: 0.8 },
114
+ transition: {
115
+ opacity: { duration: 0.15 },
116
+ scale: { duration: 0.15 },
117
+ layout: {
118
+ type: "spring",
119
+ stiffness: 500,
120
+ damping: 35
166
121
  }
167
- )
168
- ] })
169
- ]
122
+ },
123
+ children: /* @__PURE__ */ n(k, { asChild: !0, variant: "filled", children: /* @__PURE__ */ D("div", { children: [
124
+ /* @__PURE__ */ n(V, { children: /* @__PURE__ */ n(_, { children: u }) }),
125
+ /* @__PURE__ */ n(j, { children: /* @__PURE__ */ n(
126
+ "button",
127
+ {
128
+ "aria-label": `Remove ${u}`,
129
+ className: g(
130
+ "inline-flex size-9 cursor-pointer items-center justify-center rounded-full",
131
+ "text-muted-foreground",
132
+ "focus-visible:shadow-default outline-none",
133
+ "transition-colors duration-150 ease-in-out",
134
+ "disabled:pointer-events-none disabled:opacity-50"
135
+ ),
136
+ "data-hook": `${t}-remove-${o}`,
137
+ disabled: r,
138
+ type: "button",
139
+ onClick: () => I(o),
140
+ children: /* @__PURE__ */ n(P, {})
141
+ }
142
+ ) })
143
+ ] }) })
144
+ },
145
+ p[o]
146
+ )) })
170
147
  }
171
148
  );
172
149
  }
173
- O.displayName = "InputList";
150
+ z.displayName = "InputListItems";
151
+ const M = s.forwardRef(
152
+ ({ dataHook: t, error: a = !1, className: f, ...r }, l) => {
153
+ const { inputValue: c, setInputValue: I, addItems: p } = x(), u = (i) => {
154
+ i.key === "Enter" && (i.preventDefault(), p([c])), r.onKeyDown?.(i);
155
+ }, o = (i) => {
156
+ const h = i.clipboardData.getData("text").split(`
157
+ `);
158
+ h.length > 1 && (i.preventDefault(), p(h)), r.onPaste?.(i);
159
+ };
160
+ return /* @__PURE__ */ n(
161
+ S,
162
+ {
163
+ ref: l,
164
+ ...r,
165
+ className: g("flex-1", f),
166
+ dataHook: t,
167
+ error: a,
168
+ value: c,
169
+ onChange: (i) => {
170
+ I(i.target.value), r.onChange?.(i);
171
+ },
172
+ onKeyDown: u,
173
+ onPaste: o
174
+ }
175
+ );
176
+ }
177
+ );
178
+ M.displayName = "InputListInput";
179
+ const T = s.forwardRef(({ dataHook: t, children: a, ...f }, r) => {
180
+ const { inputValue: l, addItems: c } = x();
181
+ return /* @__PURE__ */ n(
182
+ B,
183
+ {
184
+ ref: r,
185
+ ...f,
186
+ dataHook: t,
187
+ onClick: () => c([l]),
188
+ children: a
189
+ }
190
+ );
191
+ });
192
+ T.displayName = "InputListAddButton";
174
193
  export {
175
- O as InputList
194
+ E as InputList,
195
+ T as InputListAddButton,
196
+ M as InputListInput,
197
+ z as InputListItems,
198
+ x as useInputListContext
176
199
  };