@brightlocal/ui-components 2.8.0 → 2.9.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/component-meta.json +1 -1
- package/dist/alert.cjs +1 -1
- package/dist/alert.js +1 -1
- package/dist/blocks/sidebar.cjs +1 -1
- package/dist/blocks/sidebar.d.ts +39 -21
- package/dist/blocks/sidebar.d.ts.map +1 -1
- package/dist/blocks/sidebar.js +379 -425
- package/dist/callout.cjs +1 -1
- package/dist/callout.js +1 -1
- package/dist/card.cjs +1 -1
- package/dist/card.js +11 -11
- package/dist/combobox.cjs +3 -3
- package/dist/combobox.d.ts +24 -3
- package/dist/combobox.d.ts.map +1 -1
- package/dist/combobox.js +327 -302
- package/dist/global-layout.cjs +1 -1
- package/dist/global-layout.d.ts +3 -7
- package/dist/global-layout.d.ts.map +1 -1
- package/dist/global-layout.js +85 -81
- package/dist/hooks/use-breakpoint.cjs +1 -0
- package/dist/hooks/use-breakpoint.d.ts +15 -0
- package/dist/hooks/use-breakpoint.d.ts.map +1 -0
- package/dist/hooks/use-breakpoint.js +30 -0
- package/dist/hooks/use-mobile.d.ts +13 -3
- package/dist/hooks/use-mobile.d.ts.map +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +124 -121
- package/dist/scroll-area.cjs +1 -1
- package/dist/scroll-area.d.ts +5 -0
- package/dist/scroll-area.d.ts.map +1 -1
- package/dist/scroll-area.js +34 -25
- package/package.json +1 -1
- package/src/blocks/sidebar.tsx +134 -148
- package/src/components/alert.tsx +1 -1
- package/src/components/callout.tsx +1 -1
- package/src/components/card.tsx +1 -1
- package/src/components/combobox.tsx +72 -11
- package/src/components/global-layout.tsx +46 -45
- package/src/components/scroll-area.tsx +15 -1
- package/src/hooks/use-breakpoint.ts +58 -0
- package/src/hooks/use-mobile.ts +20 -40
- package/src/index.ts +1 -0
- package/dist/hooks/use-mobile.cjs +0 -1
- package/dist/hooks/use-mobile.js +0 -26
package/dist/callout.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const r=require("react/jsx-runtime"),
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const r=require("react/jsx-runtime"),b=require("react"),C=require("class-variance-authority"),n=require("@brightlocal/ui-components/lib/utils");function v(e){const t=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e){for(const a in e)if(a!=="default"){const o=Object.getOwnPropertyDescriptor(e,a);Object.defineProperty(t,a,o.get?o:{enumerable:!0,get:()=>e[a]})}}return t.default=e,Object.freeze(t)}const l=v(b),s=C.cva("relative rounded-2xl p-12 shadow-lg",{variants:{variant:{primary:"bg-primary text-primary-foreground",purple:"bg-violet-300 text-violet-950",blue:"bg-sky-300 text-sky-950",green:"bg-green-200 text-green-950"}},defaultVariants:{variant:"primary"}}),j={primary:"text-primary-foreground/80",purple:"text-violet-800",blue:"text-sky-900",green:"text-green-900"},h={primary:"bg-primary",purple:"bg-violet-300",blue:"bg-sky-300",green:"bg-green-200"},k={bottom:"left-1/2 -bottom-2 -translate-x-1/2",top:"left-1/2 -top-2 -translate-x-1/2",left:"top-1/2 -left-2 -translate-y-1/2",right:"top-1/2 -right-2 -translate-y-1/2"},c=l.createContext({variant:"primary"}),u=l.forwardRef(({className:e,variant:t="primary",pointer:a="bottom",children:o,dataHook:i,trackingEl:g,trackingLabel:m,...f},x)=>{const y=l.useMemo(()=>({variant:t}),[t]);return r.jsx(c.Provider,{value:y,children:r.jsxs("div",{ref:x,className:n.cn(s({variant:t}),e),"data-hook":i,"data-slot":"callout","data-tracking-el":g||`callout-${t}`,"data-tracking-label":m,...f,children:[r.jsx("div",{className:"flex flex-col gap-8",children:o}),a!=="none"&&r.jsx("span",{"aria-hidden":"true",className:n.cn("pointer-events-none absolute size-4 rotate-45",k[a],h[t]),"data-slot":"callout-pointer"})]})})});u.displayName="Callout";const d=l.forwardRef(({className:e,dataHook:t,...a},o)=>r.jsx("div",{ref:o,className:n.cn("font-display text-4xl font-semibold",e),"data-hook":t,"data-slot":"callout-heading",...a}));d.displayName="CalloutHeading";const p=l.forwardRef(({className:e,dataHook:t,...a},o)=>{const{variant:i}=l.useContext(c);return r.jsx("div",{ref:o,className:n.cn("text-xs font-medium",j[i],e),"data-hook":t,"data-slot":"callout-citation",...a})});p.displayName="CalloutCitation";exports.Callout=u;exports.CalloutCitation=p;exports.CalloutHeading=d;exports.calloutVariants=s;
|
package/dist/callout.js
CHANGED
package/dist/card.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const s=require("react/jsx-runtime"),
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const s=require("react/jsx-runtime"),w=require("react"),h=require("class-variance-authority"),d=require("@brightlocal/ui-components/lib/utils");function R(t){const e=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(t){for(const r in t)if(r!=="default"){const o=Object.getOwnPropertyDescriptor(t,r);Object.defineProperty(e,r,o.get?o:{enumerable:!0,get:()=>t[r]})}}return e.default=t,Object.freeze(e)}const a=R(w),c=a.createContext({flush:!1}),O=h.cva(["flex","flex-col","gap-8","rounded-xl","py-section-md","transition-colors","w-full"],{variants:{variant:{filled:["bg-card","text-card-foreground","border","border-card-border"],transparent:["bg-transparent","text-foreground"],border:["bg-transparent","text-foreground","border","border-border"],"transparent-flush":["bg-transparent","text-foreground"]}},defaultVariants:{variant:"filled"}}),l=a.forwardRef(({className:t,variant:e="filled",dataHook:r,trackingEl:o,trackingLabel:C,maxWidth:n="400px",children:g,style:b,...y},j)=>{const v=e==="transparent-flush",N=n!==void 0?{maxWidth:typeof n=="number"?`${n}px`:n}:void 0;return s.jsx(c.Provider,{value:{flush:v},children:s.jsx("div",{ref:j,className:d.cn(O({variant:e}),t),"data-hook":r,"data-slot":"card","data-tracking-el":o||`card-${e}`,"data-tracking-label":C,style:{...N,...b},...y,children:g})})});l.displayName="Card";const i=a.forwardRef(({className:t,...e},r)=>{const{flush:o}=a.useContext(c);return s.jsx("div",{ref:r,className:d.cn("@container/card-header grid auto-rows-min grid-rows-[auto_auto] items-start gap-1.5 has-data-[slot=card-action]:grid-cols-[1fr_auto]",!o&&"px-section-md",t),"data-slot":"card-header",...e})});i.displayName="CardHeader";const f=a.forwardRef(({className:t,...e},r)=>s.jsx("div",{ref:r,className:d.cn("font-display text-2xl font-medium",t),"data-slot":"card-title",...e}));f.displayName="CardTitle";const u=a.forwardRef(({className:t,...e},r)=>s.jsx("div",{ref:r,className:d.cn("text-muted-foreground text-sm leading-normal font-normal",t),"data-slot":"card-description",...e}));u.displayName="CardDescription";const p=a.forwardRef(({className:t,...e},r)=>s.jsx("div",{ref:r,className:d.cn("col-start-2 row-span-2 row-start-1 self-start justify-self-end",t),"data-slot":"card-action",...e}));p.displayName="CardAction";const m=a.forwardRef(({className:t,...e},r)=>{const{flush:o}=a.useContext(c);return s.jsx("div",{ref:r,className:d.cn(!o&&"px-section-md",t),"data-slot":"card-content",...e})});m.displayName="CardContent";const x=a.forwardRef(({className:t,...e},r)=>{const{flush:o}=a.useContext(c);return s.jsx("div",{ref:r,className:d.cn("flex items-center",!o&&"px-section-md",t),"data-slot":"card-footer",...e})});x.displayName="CardFooter";exports.Card=l;exports.CardAction=p;exports.CardContent=m;exports.CardDescription=u;exports.CardFooter=x;exports.CardHeader=i;exports.CardTitle=f;
|
package/dist/card.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { jsx as o } from "react/jsx-runtime";
|
|
2
2
|
import * as e from "react";
|
|
3
|
-
import { cva as
|
|
3
|
+
import { cva as C } from "class-variance-authority";
|
|
4
4
|
import { cn as s } from "@brightlocal/ui-components/lib/utils";
|
|
5
|
-
const l = e.createContext({ flush: !1 }), g =
|
|
5
|
+
const l = e.createContext({ flush: !1 }), g = C(
|
|
6
6
|
[
|
|
7
7
|
"flex",
|
|
8
8
|
"flex-col",
|
|
@@ -47,7 +47,7 @@ const l = e.createContext({ flush: !1 }), g = x(
|
|
|
47
47
|
style: f,
|
|
48
48
|
...m
|
|
49
49
|
}, p) => {
|
|
50
|
-
const u = a === "transparent-flush",
|
|
50
|
+
const u = a === "transparent-flush", x = n !== void 0 ? {
|
|
51
51
|
maxWidth: typeof n == "number" ? `${n}px` : n
|
|
52
52
|
} : void 0;
|
|
53
53
|
return /* @__PURE__ */ o(l.Provider, { value: { flush: u }, children: /* @__PURE__ */ o(
|
|
@@ -59,7 +59,7 @@ const l = e.createContext({ flush: !1 }), g = x(
|
|
|
59
59
|
"data-slot": "card",
|
|
60
60
|
"data-tracking-el": d || `card-${a}`,
|
|
61
61
|
"data-tracking-label": c,
|
|
62
|
-
style: { ...
|
|
62
|
+
style: { ...x, ...f },
|
|
63
63
|
...m,
|
|
64
64
|
children: i
|
|
65
65
|
}
|
|
@@ -91,14 +91,14 @@ const v = e.forwardRef(
|
|
|
91
91
|
"div",
|
|
92
92
|
{
|
|
93
93
|
ref: t,
|
|
94
|
-
className: s("
|
|
94
|
+
className: s("font-display text-2xl font-medium", r),
|
|
95
95
|
"data-slot": "card-title",
|
|
96
96
|
...a
|
|
97
97
|
}
|
|
98
98
|
)
|
|
99
99
|
);
|
|
100
100
|
v.displayName = "CardTitle";
|
|
101
|
-
const
|
|
101
|
+
const y = e.forwardRef(
|
|
102
102
|
({ className: r, ...a }, t) => /* @__PURE__ */ o(
|
|
103
103
|
"div",
|
|
104
104
|
{
|
|
@@ -112,7 +112,7 @@ const h = e.forwardRef(
|
|
|
112
112
|
}
|
|
113
113
|
)
|
|
114
114
|
);
|
|
115
|
-
|
|
115
|
+
y.displayName = "CardDescription";
|
|
116
116
|
const w = e.forwardRef(
|
|
117
117
|
({ className: r, ...a }, t) => /* @__PURE__ */ o(
|
|
118
118
|
"div",
|
|
@@ -128,7 +128,7 @@ const w = e.forwardRef(
|
|
|
128
128
|
)
|
|
129
129
|
);
|
|
130
130
|
w.displayName = "CardAction";
|
|
131
|
-
const
|
|
131
|
+
const h = e.forwardRef(
|
|
132
132
|
({ className: r, ...a }, t) => {
|
|
133
133
|
const { flush: d } = e.useContext(l);
|
|
134
134
|
return /* @__PURE__ */ o(
|
|
@@ -142,7 +142,7 @@ const y = e.forwardRef(
|
|
|
142
142
|
);
|
|
143
143
|
}
|
|
144
144
|
);
|
|
145
|
-
|
|
145
|
+
h.displayName = "CardContent";
|
|
146
146
|
const R = e.forwardRef(
|
|
147
147
|
({ className: r, ...a }, t) => {
|
|
148
148
|
const { flush: d } = e.useContext(l);
|
|
@@ -165,8 +165,8 @@ R.displayName = "CardFooter";
|
|
|
165
165
|
export {
|
|
166
166
|
N as Card,
|
|
167
167
|
w as CardAction,
|
|
168
|
-
|
|
169
|
-
|
|
168
|
+
h as CardContent,
|
|
169
|
+
y as CardDescription,
|
|
170
170
|
R as CardFooter,
|
|
171
171
|
b as CardHeader,
|
|
172
172
|
v as CardTitle
|
package/dist/combobox.cjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const i=require("react/jsx-runtime"),re=require("react"),Y=require("@brightlocal/icons"),ne=require("@tanstack/react-virtual"),se=require("class-variance-authority"),U=require("cmdk"),M=require("@brightlocal/ui-components/lib/utils"),W=require("@brightlocal/ui-components/lib/use-dev-warning"),B=require("@brightlocal/ui-components/popover"),O=require("@brightlocal/ui-components/command");function ae(t){const o=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(t){for(const n in t)if(n!=="default"){const r=Object.getOwnPropertyDescriptor(t,n);Object.defineProperty(o,n,r.get?r:{enumerable:!0,get:()=>t[n]})}}return o.default=t,Object.freeze(o)}const e=ae(re),J=e.createContext(null),K=e.createContext(null);function _(){const t=e.useContext(J);if(!t)throw new Error("Combobox components must be used within a <Combobox>");return t}function ie({value:t,onValueChange:o,open:n,onOpenChange:r,shouldFilter:u=!0,disabled:f=!1,itemToStringValue:c,children:p}){const[x,v]=e.useState(""),[P,C]=e.useState(!1),[S,y]=e.useState(()=>new Map),[k,j]=e.useState(""),[w,h]=e.useState(void 0),E=t!==void 0,I=n!==void 0,R=E?t:x,b=I?n:P,g=e.useCallback(m=>{m||j(""),I||C(m),r?.(m)},[I,r]),N=e.useCallback(m=>{E||v(m),o?.(m)},[E,o]),a=e.useRef(new Map),D=e.useRef(!1),T=e.useRef(!0);e.useEffect(()=>()=>{T.current=!1},[]);const q=e.useCallback(()=>{D.current||(D.current=!0,queueMicrotask(()=>{D.current=!1,T.current&&y(new Map(a.current))}))},[]),L=e.useCallback((m,s)=>{a.current.get(m)!==s&&(a.current.set(m,s),q())},[q]),A=e.useCallback(m=>{for(const[s,d]of m)a.current.set(s,d);y(new Map(a.current))},[]),$=e.useRef(R);e.useLayoutEffect(()=>{$.current=R},[R]);const z=e.useCallback(m=>{m!==$.current&&a.current.has(m)&&(a.current.delete(m),q())},[q]),G=e.useMemo(()=>c?(m,s,d)=>U.defaultFilter(c(m),s,d):U.defaultFilter,[c]),H=e.useMemo(()=>({open:b,setOpen:g,value:R,onValueChange:N,shouldFilter:u,disabled:f,itemLabels:S,registerItem:L,registerItemsSync:A,unregisterItem:z,itemToStringValue:c,filterFn:G,searchValue:k,setSearchValue:j,activeDescendantId:w,setActiveDescendantId:h}),[b,g,R,N,u,f,S,L,A,z,c,G,k,w,h]);return i.jsx(J.Provider,{value:H,children:i.jsx(B.Popover,{open:b,onOpenChange:g,children:p})})}const ce=se.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-base 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","transition-[background-color,border-color,box-shadow] duration-200 ease-out","[&_svg]:pointer-events-none [&_svg]:shrink-0"]),Q=e.forwardRef(({className:t,dataHook:o,error:n,trackingEl:r,trackingLabel:u,children:f,...c},p)=>{const{open:x,disabled:v,value:P}=_(),C=e.useId(),S=!P,y=n||c["aria-invalid"]===!0||c["aria-invalid"]==="true";return i.jsx(B.PopoverTrigger,{asChild:!0,children:i.jsxs("button",{ref:p,"aria-controls":x?C:void 0,"aria-expanded":x,"aria-haspopup":"listbox","aria-invalid":y?"true":void 0,className:M.cn(ce(),y&&"border-destructive-40 dark: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",t),"data-hook":o,"data-placeholder":S,"data-slot":"combobox-trigger","data-state":x?"open":"closed","data-tracking-el":r||"combobox-trigger","data-tracking-label":u,disabled:v||c.disabled,role:"combobox",type:"button",...c,children:[f,i.jsx(Y.ChevronsUpDown,{"aria-hidden":"true",className:"text-muted-foreground ml-auto shrink-0"})]})})});Q.displayName="ComboboxTrigger";function ue({placeholder:t,className:o,displayValue:n,items:r,getItemValue:u,getItemLabel:f}){const{value:c,itemLabels:p}=_();W.useDevWarning(()=>!!r&&!u,"ComboboxValue: `items` was provided without `getItemValue`. Pass `getItemValue` (and optionally `getItemLabel`) to enable item-based label resolution.",[r,u]);const x=e.useMemo(()=>{if(!r||!u)return null;const P=f??u;return new Map(r.map(C=>[u(C),P(C)]))},[r,u,f]),v=c?x?.get(c)||p.get(c)||n?.(c)||c:t;return i.jsx("span",{className:M.cn("text-foreground overflow-hidden text-base leading-normal font-medium text-ellipsis whitespace-nowrap",o),"data-slot":"combobox-value",children:v})}function le({dataHook:t,className:o,children:n,align:r="start",side:u="bottom",sideOffset:f,avoidCollisions:c,hideList:p=!1}){const{open:x,shouldFilter:v,filterFn:P,itemToStringValue:C}=_(),[S,y]=e.useState(null),k=e.useRef(null),j=e.useCallback(h=>{if(k.current?.(),k.current=null,!h)return;let E=!1;const I=N=>{E||(N==="top"||N==="bottom")&&(E=!0,R.disconnect(),y(N))},R=new MutationObserver(()=>{I(h.getAttribute("data-side"))});R.observe(h,{attributes:!0,attributeFilter:["data-side"]});let b=0,g=0;b=requestAnimationFrame(()=>{g=requestAnimationFrame(()=>{I(h.getAttribute("data-side"))})}),k.current=()=>{E=!0,R.disconnect(),cancelAnimationFrame(b),cancelAnimationFrame(g)}},[]);e.useEffect(()=>{if(!x){k.current?.(),k.current=null;const h=setTimeout(()=>y(null),150);return()=>clearTimeout(h)}},[x]);const w=C?P:void 0;return i.jsx(B.PopoverContent,{ref:j,align:r,"aria-label":"Options",avoidCollisions:c,className:M.cn("flex max-h-[var(--radix-popover-content-available-height)] w-[var(--radix-popover-trigger-width)] flex-col overflow-hidden p-0",o),collisionPadding:4,"data-slot":"combobox-popover",side:S??u,sideOffset:f,children:i.jsx(O.Command,{className:M.cn("min-h-0 flex-1 border-0 shadow-none","[&_[data-slot='command-input-wrapper']]:shrink-0",p&&"[&_[data-slot='command-input-wrapper']]:border-b-0"),"data-slot":"combobox-command",dataHook:t||"combobox-command",filter:w,shouldFilter:v,children:n})})}const X=e.forwardRef(({debounceMs:t,onValueChange:o,...n},r)=>{const{setSearchValue:u,shouldFilter:f,activeDescendantId:c}=_(),p=e.useRef(void 0);W.useDevWarning(()=>!!(t&&t>0&&f),`debounceMs is set on <ComboboxInput> but shouldFilter is true (default).
|
|
2
2
|
Debounce is designed for async/server-driven search where the consumer controls the items list.
|
|
3
|
-
Set shouldFilter={false} on <Combobox> for async search, or remove debounceMs for client-side filtering.`,[
|
|
4
|
-
Import: import { ComboboxVirtualList } from "@brightlocal/ui-components/combobox"`,[
|
|
3
|
+
Set shouldFilter={false} on <Combobox> for async search, or remove debounceMs for client-side filtering.`,[t,f]),W.useDevWarning(()=>!!(t&&t>0&&n.value!==void 0),"debounceMs is set on <ComboboxInput> together with a controlled `value` prop.\nThe debounced onValueChange callback cannot update the controlled value synchronously, so the input will appear to lag behind typing.\nRemove `value` to let the input manage its own display, or remove debounceMs if you need a controlled input.",[t,n.value]),e.useEffect(()=>()=>{p.current&&clearTimeout(p.current)},[]);const x=e.useCallback(v=>{u(v),t&&t>0?(clearTimeout(p.current),p.current=setTimeout(()=>{o?.(v)},t)):o?.(v)},[t,o,u]);return i.jsx(O.CommandInput,{ref:r,"aria-activedescendant":c,"data-slot":"combobox-input",onValueChange:x,...n})});X.displayName="ComboboxInput";const Z=e.forwardRef(({className:t,...o},n)=>i.jsx(O.CommandList,{ref:n,className:M.cn("min-h-0 flex-1",t),"data-slot":"combobox-list",...o}));Z.displayName="ComboboxList";function de({items:t,getItemValue:o,getItemLabel:n,getItemKeywords:r,estimateSize:u=36,overscan:f=5,children:c,renderEmpty:p,className:x,dataHook:v},P){const C=e.useRef(null),{value:S,onValueChange:y,setOpen:k,shouldFilter:j,searchValue:w,filterFn:h,setActiveDescendantId:E,registerItemsSync:I,unregisterItem:R}=_(),[b,g]=e.useState(0),N=e.useId();e.useImperativeHandle(P,()=>C.current,[]),e.useLayoutEffect(()=>{const s=n??o,d=t.map(l=>[o(l),s(l)]);return I(d),()=>{for(const l of t)R(o(l))}},[t,o,n,I,R]);const a=e.useMemo(()=>{if(!j||!w.trim())return t;const s=[];for(const d of t){let l=n?U.defaultFilter(n(d),w):h(o(d),w);if(r)for(const F of r(d))l=Math.max(l,U.defaultFilter(F,w));l>0&&s.push({item:d,score:l})}return s.sort((d,l)=>l.score-d.score),s.map(d=>d.item)},[t,j,w,o,n,r,h]),D=ne.useVirtualizer({count:a.length,getScrollElement:()=>C.current,estimateSize:()=>u,overscan:f}),T=b>=0&&b<a.length?o(a[b]):null;e.useEffect(()=>{g(0)},[w,a.length]);const q=e.useRef(!1);e.useEffect(()=>{if(q.current||!S)return;const s=a.findIndex(d=>o(d)===S);s>=0&&(g(s),D.scrollToIndex(s,{align:"center"}),q.current=!0)},[S,a,o,D]);const L=e.useRef(!1);e.useEffect(()=>{L.current&&b>=0&&b<a.length&&D.scrollToIndex(b,{align:"auto"}),L.current=!1},[b,a.length,D]),e.useEffect(()=>{const s=C.current?.closest('[data-slot="combobox-command"]');if(!s)return;const d=l=>{switch(l.key){case"ArrowDown":l.preventDefault(),l.stopPropagation(),L.current=!0,g(F=>F<a.length-1?F+1:F);break;case"ArrowUp":l.preventDefault(),l.stopPropagation(),L.current=!0,g(F=>F>0?F-1:F);break;case"Enter":if(l.preventDefault(),l.stopPropagation(),b>=0&&b<a.length){const F=o(a[b]);y(F===S?"":F),k(!1)}break;case"Home":l.preventDefault(),l.stopPropagation(),L.current=!0,g(0);break;case"End":l.preventDefault(),l.stopPropagation(),L.current=!0,g(a.length-1);break}};return s.addEventListener("keydown",d,{capture:!0}),()=>s.removeEventListener("keydown",d,{capture:!0})},[a,b,S,y,k,o]);const A=e.useMemo(()=>{const s=new Map;return a.forEach((d,l)=>{s.set(o(d),l)}),s},[a,o]),$=e.useCallback(s=>{const d=A.get(s);d!==void 0&&g(d)},[A]),z=e.useCallback(s=>(A.get(s)??0)+1,[A]),G=a.length,H=e.useMemo(()=>({activeValue:T,onItemPointerMove:$,idPrefix:N,filteredCount:G,getItemPosition:z}),[T,$,N,G,z]),m=T!=null?`${N}item-${T}`:void 0;return e.useEffect(()=>(E(m),()=>E(void 0)),[m,E]),a.length===0?i.jsx("div",{ref:C,className:M.cn("max-h-[300px] min-h-0 flex-1 scroll-py-1 overflow-x-hidden overflow-y-auto py-1",x),"data-hook":v,"data-slot":"combobox-virtual-list",role:"listbox",children:p}):i.jsx(K.Provider,{value:H,children:i.jsx("div",{ref:C,className:M.cn("max-h-[300px] min-h-0 flex-1 scroll-py-1 overflow-x-hidden overflow-y-auto py-1",x),"data-hook":v,"data-slot":"combobox-virtual-list",role:"listbox",children:i.jsx("div",{className:"relative w-full",style:{height:`${D.getTotalSize()}px`},children:D.getVirtualItems().map(s=>i.jsx("div",{ref:D.measureElement,className:"absolute top-0 left-0 w-full px-2","data-index":s.index,style:{transform:`translateY(${s.start}px)`},children:c(a[s.index],s.index,w)},s.key))})})})}const be=e.forwardRef(de),V=e.forwardRef((t,o)=>i.jsx(O.CommandEmpty,{ref:o,"data-slot":"combobox-empty",...t}));V.displayName="ComboboxEmpty";const ee=e.forwardRef(({children:t,...o},n)=>{const r=e.useRef(null);return W.useDevWarning(()=>r.current?r.current.querySelectorAll('[data-slot="combobox-item"]').length>=100:!1,`ComboboxGroup contains 100+ items. Use <ComboboxVirtualList> for large datasets to avoid DOM bloat and slow renders.
|
|
4
|
+
Import: import { ComboboxVirtualList } from "@brightlocal/ui-components/combobox"`,[t]),i.jsx(O.CommandGroup,{ref:u=>{r.current=u,typeof n=="function"?n(u):n&&(n.current=u)},"data-slot":"combobox-group",...o,children:t})});ee.displayName="ComboboxGroup";function fe(t,o,n){if(!o||!o.trim())return t;const r=new RegExp(`(${o.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")})`,"gi"),u=t.split(r);return i.jsx("span",{children:u.map((f,c)=>c%2===1?i.jsx("span",{className:n,children:f},c):i.jsx(e.Fragment,{children:f},c))})}const te=e.forwardRef(({value:t,label:o,dataHook:n,children:r,className:u,highlight:f,highlightClassName:c,keywords:p,...x},v)=>{const{value:P,onValueChange:C,setOpen:S,registerItem:y,unregisterItem:k}=_(),j=e.useContext(K),w=P===t,h=e.useMemo(()=>o||(typeof r=="string"?r:typeof r=="number"?String(r):t),[o,r,t]),E=e.useRef(y),I=e.useRef(k);e.useEffect(()=>{E.current=y,I.current=k},[y,k]);const R=!!j;e.useEffect(()=>{if(!R)return E.current(t,h),()=>I.current(t)},[t,h,R]);const b=()=>{C(t===P?"":t),S(!1)},g=()=>f&&typeof r=="string"?fe(r,f,c||"text-sm leading-normal font-semibold"):r;if(j){const N=j.activeValue===t,a=!!x.disabled;return i.jsxs("div",{ref:v,"aria-disabled":a||void 0,"aria-posinset":j.getItemPosition(t),"aria-selected":w,"aria-setsize":j.filteredCount,className:M.cn("data-[highlighted=true]:bg-accent data-[highlighted=true]:text-accent-foreground relative flex cursor-default items-center justify-between gap-2 rounded-sm px-2 py-3 text-sm outline-hidden select-none","[&_svg]:pointer-events-none [&_svg]:shrink-0",a&&"pointer-events-none opacity-50",u),"data-highlighted":N||void 0,"data-hook":n,"data-slot":"combobox-item",id:`${j.idPrefix}item-${t}`,role:"option",tabIndex:-1,onClick:a?void 0:b,onKeyDown:a?void 0:D=>{(D.key==="Enter"||D.key===" ")&&b()},onPointerMove:a?void 0:()=>j.onItemPointerMove(t),children:[g(),w&&i.jsx(Y.Check,{"aria-hidden":"true",className:"text-muted-foreground shrink-0"})]})}return i.jsxs(O.CommandItem,{ref:v,className:M.cn("justify-between",u),"data-slot":"combobox-item",dataHook:n,keywords:p?[h,...p]:[h],value:t,onSelect:b,...x,children:[g(),w&&i.jsx(Y.Check,{"aria-hidden":"true",className:"text-muted-foreground shrink-0"})]})});te.displayName="ComboboxItem";const oe=e.forwardRef((t,o)=>i.jsx(O.CommandSeparator,{ref:o,"data-slot":"combobox-separator",...t}));oe.displayName="ComboboxSeparator";function me({className:t,children:o}){return i.jsx("div",{"aria-live":"polite",className:M.cn("text-muted-foreground flex items-center justify-center gap-2 py-6 text-sm",t),"data-slot":"combobox-loading",role:"status",children:o||i.jsxs(i.Fragment,{children:[i.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=ie;exports.ComboboxContent=le;exports.ComboboxEmpty=V;exports.ComboboxGroup=ee;exports.ComboboxInput=X;exports.ComboboxItem=te;exports.ComboboxList=Z;exports.ComboboxLoading=me;exports.ComboboxSeparator=oe;exports.ComboboxTrigger=Q;exports.ComboboxValue=ue;exports.ComboboxVirtualList=be;
|
package/dist/combobox.d.ts
CHANGED
|
@@ -73,7 +73,7 @@ export interface ComboboxTriggerProps extends React.ButtonHTMLAttributes<HTMLBut
|
|
|
73
73
|
trackingLabel?: string;
|
|
74
74
|
}
|
|
75
75
|
declare const ComboboxTrigger: React.ForwardRefExoticComponent<ComboboxTriggerProps & React.RefAttributes<HTMLButtonElement>>;
|
|
76
|
-
export interface ComboboxValueProps {
|
|
76
|
+
export interface ComboboxValueProps<T = unknown> {
|
|
77
77
|
/** Placeholder text when no value is selected */
|
|
78
78
|
placeholder?: string;
|
|
79
79
|
/** Custom className */
|
|
@@ -92,8 +92,29 @@ export interface ComboboxValueProps {
|
|
|
92
92
|
* ```
|
|
93
93
|
*/
|
|
94
94
|
displayValue?: (value: string) => string | undefined;
|
|
95
|
+
/**
|
|
96
|
+
* Items array for auto-resolving display labels. When provided alongside
|
|
97
|
+
* `getItemValue` (and optionally `getItemLabel`), ComboboxValue builds an
|
|
98
|
+
* internal lookup map — eliminating the need for a manual `displayValue`
|
|
99
|
+
* callback. Typically the same array passed to `ComboboxVirtualList`.
|
|
100
|
+
*
|
|
101
|
+
* @example
|
|
102
|
+
* ```tsx
|
|
103
|
+
* <ComboboxValue
|
|
104
|
+
* placeholder="Select country..."
|
|
105
|
+
* items={countries}
|
|
106
|
+
* getItemValue={(c) => c.code}
|
|
107
|
+
* getItemLabel={(c) => c.name}
|
|
108
|
+
* />
|
|
109
|
+
* ```
|
|
110
|
+
*/
|
|
111
|
+
items?: readonly T[];
|
|
112
|
+
/** Extract the value string from an item. Required when `items` is provided. */
|
|
113
|
+
getItemValue?: (item: T) => string;
|
|
114
|
+
/** Extract the display label from an item. Falls back to `getItemValue` when not provided. */
|
|
115
|
+
getItemLabel?: (item: T) => string;
|
|
95
116
|
}
|
|
96
|
-
declare function ComboboxValue({ placeholder, className, displayValue, }: ComboboxValueProps): import("react/jsx-runtime").JSX.Element;
|
|
117
|
+
declare function ComboboxValue<T>({ placeholder, className, displayValue, items, getItemValue, getItemLabel, }: ComboboxValueProps<T>): import("react/jsx-runtime").JSX.Element;
|
|
97
118
|
export interface ComboboxContentProps {
|
|
98
119
|
/** Data hook for automated testing */
|
|
99
120
|
dataHook?: string;
|
|
@@ -139,7 +160,7 @@ export type ComboboxListProps = React.ComponentProps<typeof CommandList>;
|
|
|
139
160
|
declare const ComboboxList: React.ForwardRefExoticComponent<Omit<Omit<import('@brightlocal/ui-components/command').CommandListProps, "ref"> & React.RefAttributes<HTMLDivElement>, "ref"> & React.RefAttributes<HTMLDivElement>>;
|
|
140
161
|
export interface ComboboxVirtualListProps<T> {
|
|
141
162
|
/** Array of items to virtualise. Memoize with useMemo to avoid re-registering labels on every render. */
|
|
142
|
-
items: T[];
|
|
163
|
+
items: readonly T[];
|
|
143
164
|
/** Extract the string value for each item (used for selection and keyboard navigation) */
|
|
144
165
|
getItemValue: (item: T) => string;
|
|
145
166
|
/**
|
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;AAa/B,OAAO,EAEL,YAAY,EACZ,YAAY,EACZ,YAAY,EACZ,WAAW,EACX,WAAW,EACX,gBAAgB,EACjB,MAAM,oCAAoC,CAAC;
|
|
1
|
+
{"version":3,"file":"combobox.d.ts","sourceRoot":"","sources":["../../src/components/combobox.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAa/B,OAAO,EAEL,YAAY,EACZ,YAAY,EACZ,YAAY,EACZ,WAAW,EACX,WAAW,EACX,gBAAgB,EACjB,MAAM,oCAAoC,CAAC;AA0E5C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AACH,MAAM,WAAW,aAAa;IAC5B,gCAAgC;IAChC,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,kCAAkC;IAClC,aAAa,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;IACxC,4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