@brightlocal/ui-components 2.9.1 → 2.10.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.
- package/component-meta.json +1 -1
- package/dist/browser-entry.d.ts +17 -0
- package/dist/browser-entry.d.ts.map +1 -0
- package/dist/combobox.cjs +3 -3
- package/dist/combobox.d.ts +3 -3
- package/dist/combobox.d.ts.map +1 -1
- package/dist/combobox.js +480 -440
- package/dist/global-layout.cjs +1 -1
- package/dist/global-layout.d.ts.map +1 -1
- package/dist/global-layout.js +17 -16
- package/package.json +6 -3
- package/src/browser-entry.ts +89 -0
- package/src/browser-tokens.css +1 -0
- package/src/components/combobox.tsx +106 -28
- package/src/components/global-layout.tsx +7 -6
package/dist/global-layout.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const s=require("react/jsx-runtime"),g=require("react"),d=require("@brightlocal/ui-components/lib/utils"),h=require("./header.cjs"),
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const s=require("react/jsx-runtime"),g=require("react"),d=require("@brightlocal/ui-components/lib/utils"),h=require("./header.cjs"),k=require("./scroll-area.cjs");function w(e){const a=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e){for(const t in e)if(t!=="default"){const o=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(a,t,o.get?o:{enumerable:!0,get:()=>e[t]})}}return a.default=e,Object.freeze(a)}const c=w(g),i=c.forwardRef(({className:e,maxWidth:a="var(--ds-breakpoint-xl)",dataHook:t,trackingEl:o,trackingLabel:l,children:n,...r},x)=>{const p=typeof a=="number"?`${a}px`:a;return s.jsx(k.ScrollArea,{className:d.cn("h-dvh w-full",e),dataHook:`${t}-scroll`,scrollOrientation:"both",children:s.jsx("div",{ref:x,className:"p-section-sm flex min-h-dvh w-full flex-col","data-hook":t,"data-slot":"global-layout","data-tracking-el":o,"data-tracking-label":l,...r,children:s.jsx("div",{className:"mx-auto flex w-full flex-1","data-slot":"global-container",style:{maxWidth:p},children:n})})})});i.displayName="GlobalLayout";const G="224px",u=c.forwardRef(({className:e,width:a=G,dataHook:t,children:o,...l},n)=>{const r=typeof a=="number"?`${a}px`:a;return s.jsx("aside",{ref:n,className:d.cn("sticky hidden shrink-0 self-start outline-none lg:block",e),"data-hook":t,"data-slot":"sidebar-container",style:{width:r,top:"var(--ds-section-padding-y-sm)"},...l,children:o})});u.displayName="GlobalLayoutSidebar";const b=c.forwardRef(({className:e,maxWidth:a="var(--ds-breakpoint-lg)",dataHook:t,children:o,...l},n)=>{const r=typeof a=="number"?`${a}px`:a;return s.jsx("div",{ref:n,className:d.cn("px-section-xs flex min-w-0 flex-1 flex-col",e),"data-hook":t,"data-slot":"content-wrapper",style:{"--content-max-width":r},...l,children:o})});b.displayName="GlobalLayoutContent";const y=c.forwardRef(({className:e,dataHook:a,trackingEl:t,trackingLabel:o,children:l,...n},r)=>s.jsx(h.Header,{ref:r,className:d.cn("mx-auto w-full justify-between",e),"data-slot":"content-header",dataHook:a,style:{maxWidth:"var(--ds-breakpoint-lg)"},trackingEl:t,trackingLabel:o,...n,children:l}));y.displayName="GlobalLayoutContentHeader";const f=c.forwardRef(({className:e,dataHook:a,trackingEl:t,trackingLabel:o,children:l,...n},r)=>s.jsx("div",{ref:r,className:d.cn("mx-auto mt-6 flex w-full flex-1 flex-col gap-6",e),"data-hook":a,"data-slot":"content-body","data-tracking-el":t,"data-tracking-label":o,style:{maxWidth:"var(--content-max-width)"},...n,children:l}));f.displayName="GlobalLayoutContentBody";const m=c.forwardRef(({className:e,dataHook:a,trackingEl:t,trackingLabel:o,children:l,...n},r)=>s.jsx("div",{ref:r,"aria-label":"Mobile navigation",className:d.cn("flex w-full items-center justify-start gap-2.5 py-2 lg:hidden",e),"data-hook":a,"data-slot":"mobile-header","data-tracking-el":t,"data-tracking-label":o,role:"toolbar",...n,children:l}));m.displayName="GlobalLayoutMobileHeader";exports.GlobalLayout=i;exports.GlobalLayoutContent=b;exports.GlobalLayoutContentBody=f;exports.GlobalLayoutContentHeader=y;exports.GlobalLayoutMobileHeader=m;exports.GlobalLayoutSidebar=u;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"global-layout.d.ts","sourceRoot":"","sources":["../../src/components/global-layout.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAM/B,UAAU,iBAAkB,SAAQ,KAAK,CAAC,cAAc,CAAC,KAAK,CAAC;IAC7D;;OAEG;IACH,QAAQ,EAAE,MAAM,CAAC;IACjB;;OAEG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB;;OAEG;IACH,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB;;;OAGG;IACH,QAAQ,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;CAC5B;AAED,QAAA,MAAM,YAAY,uGA0CjB,CAAC;AAMF,UAAU,wBAAyB,SAAQ,KAAK,CAAC,cAAc,CAAC,OAAO,CAAC;IACtE;;OAEG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB;;OAEG;IACH,KAAK,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;CACzB;AAED,QAAA,MAAM,mBAAmB,2GAwBvB,CAAC;AAIH,UAAU,wBAAyB,SAAQ,KAAK,CAAC,cAAc,CAAC,KAAK,CAAC;IACpE;;OAEG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB;;;OAGG;IACH,QAAQ,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;CAC5B;AAED,QAAA,MAAM,mBAAmB,
|
|
1
|
+
{"version":3,"file":"global-layout.d.ts","sourceRoot":"","sources":["../../src/components/global-layout.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAM/B,UAAU,iBAAkB,SAAQ,KAAK,CAAC,cAAc,CAAC,KAAK,CAAC;IAC7D;;OAEG;IACH,QAAQ,EAAE,MAAM,CAAC;IACjB;;OAEG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB;;OAEG;IACH,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB;;;OAGG;IACH,QAAQ,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;CAC5B;AAED,QAAA,MAAM,YAAY,uGA0CjB,CAAC;AAMF,UAAU,wBAAyB,SAAQ,KAAK,CAAC,cAAc,CAAC,OAAO,CAAC;IACtE;;OAEG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB;;OAEG;IACH,KAAK,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;CACzB;AAED,QAAA,MAAM,mBAAmB,2GAwBvB,CAAC;AAIH,UAAU,wBAAyB,SAAQ,KAAK,CAAC,cAAc,CAAC,KAAK,CAAC;IACpE;;OAEG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB;;;OAGG;IACH,QAAQ,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;CAC5B;AAED,QAAA,MAAM,mBAAmB,8GAgCxB,CAAC;AAIF,UAAU,8BAA+B,SAAQ,KAAK,CAAC,cAAc,CAAC,QAAQ,CAAC;IAC7E;;OAEG;IACH,QAAQ,EAAE,MAAM,CAAC;IACjB;;OAEG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB;;OAEG;IACH,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB;AAED,QAAA,MAAM,yBAAyB,iHAuB9B,CAAC;AAIF,UAAU,4BAA6B,SAAQ,KAAK,CAAC,cAAc,CAAC,KAAK,CAAC;IACxE;;OAEG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB;;OAEG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB;;OAEG;IACH,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB;AAED,QAAA,MAAM,uBAAuB,kHA0B5B,CAAC;AAIF,UAAU,6BAA8B,SAAQ,KAAK,CAAC,cAAc,CAAC,KAAK,CAAC;IACzE;;OAEG;IACH,QAAQ,EAAE,MAAM,CAAC;IACjB;;OAEG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB;;OAEG;IACH,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB;AAED,QAAA,MAAM,wBAAwB,mHA2B7B,CAAC;AAIF,OAAO,EACL,YAAY,EACZ,mBAAmB,EACnB,mBAAmB,EACnB,yBAAyB,EACzB,uBAAuB,EACvB,wBAAwB,GACzB,CAAC;AAEF,YAAY,EACV,iBAAiB,EACjB,wBAAwB,EACxB,wBAAwB,EACxB,8BAA8B,EAC9B,4BAA4B,EAC5B,6BAA6B,GAC9B,CAAC"}
|
package/dist/global-layout.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { jsx as s } from "react/jsx-runtime";
|
|
2
2
|
import * as d from "react";
|
|
3
3
|
import { cn as i } from "@brightlocal/ui-components/lib/utils";
|
|
4
|
-
import { Header as
|
|
5
|
-
import { ScrollArea as
|
|
4
|
+
import { Header as m } from "./header.js";
|
|
5
|
+
import { ScrollArea as b } from "./scroll-area.js";
|
|
6
6
|
const y = d.forwardRef(
|
|
7
7
|
({
|
|
8
8
|
className: o,
|
|
@@ -15,7 +15,7 @@ const y = d.forwardRef(
|
|
|
15
15
|
}, c) => {
|
|
16
16
|
const f = typeof a == "number" ? `${a}px` : a;
|
|
17
17
|
return /* @__PURE__ */ s(
|
|
18
|
-
|
|
18
|
+
b,
|
|
19
19
|
{
|
|
20
20
|
className: i("h-dvh w-full", o),
|
|
21
21
|
dataHook: `${t}-scroll`,
|
|
@@ -81,10 +81,7 @@ const x = d.forwardRef(
|
|
|
81
81
|
"div",
|
|
82
82
|
{
|
|
83
83
|
ref: r,
|
|
84
|
-
className: i(
|
|
85
|
-
"px-section-xs flex min-w-0 flex-1 flex-col gap-6",
|
|
86
|
-
o
|
|
87
|
-
),
|
|
84
|
+
className: i("px-section-xs flex min-w-0 flex-1 flex-col", o),
|
|
88
85
|
"data-hook": t,
|
|
89
86
|
"data-slot": "content-wrapper",
|
|
90
87
|
style: { "--content-max-width": n },
|
|
@@ -97,12 +94,13 @@ const x = d.forwardRef(
|
|
|
97
94
|
x.displayName = "GlobalLayoutContent";
|
|
98
95
|
const h = d.forwardRef(
|
|
99
96
|
({ className: o, dataHook: a, trackingEl: t, trackingLabel: e, children: l, ...r }, n) => /* @__PURE__ */ s(
|
|
100
|
-
|
|
97
|
+
m,
|
|
101
98
|
{
|
|
102
99
|
ref: n,
|
|
103
|
-
className: i("w-full justify-between", o),
|
|
100
|
+
className: i("mx-auto w-full justify-between", o),
|
|
104
101
|
"data-slot": "content-header",
|
|
105
102
|
dataHook: a,
|
|
103
|
+
style: { maxWidth: "var(--ds-breakpoint-lg)" },
|
|
106
104
|
trackingEl: t,
|
|
107
105
|
trackingLabel: e,
|
|
108
106
|
...r,
|
|
@@ -111,12 +109,15 @@ const h = d.forwardRef(
|
|
|
111
109
|
)
|
|
112
110
|
);
|
|
113
111
|
h.displayName = "GlobalLayoutContentHeader";
|
|
114
|
-
const
|
|
112
|
+
const k = d.forwardRef(
|
|
115
113
|
({ className: o, dataHook: a, trackingEl: t, trackingLabel: e, children: l, ...r }, n) => /* @__PURE__ */ s(
|
|
116
114
|
"div",
|
|
117
115
|
{
|
|
118
116
|
ref: n,
|
|
119
|
-
className: i(
|
|
117
|
+
className: i(
|
|
118
|
+
"mx-auto mt-6 flex w-full flex-1 flex-col gap-6",
|
|
119
|
+
o
|
|
120
|
+
),
|
|
120
121
|
"data-hook": a,
|
|
121
122
|
"data-slot": "content-body",
|
|
122
123
|
"data-tracking-el": t,
|
|
@@ -127,8 +128,8 @@ const w = d.forwardRef(
|
|
|
127
128
|
}
|
|
128
129
|
)
|
|
129
130
|
);
|
|
130
|
-
|
|
131
|
-
const
|
|
131
|
+
k.displayName = "GlobalLayoutContentBody";
|
|
132
|
+
const w = d.forwardRef(
|
|
132
133
|
({ className: o, dataHook: a, trackingEl: t, trackingLabel: e, children: l, ...r }, n) => /* @__PURE__ */ s(
|
|
133
134
|
"div",
|
|
134
135
|
{
|
|
@@ -148,12 +149,12 @@ const g = d.forwardRef(
|
|
|
148
149
|
}
|
|
149
150
|
)
|
|
150
151
|
);
|
|
151
|
-
|
|
152
|
+
w.displayName = "GlobalLayoutMobileHeader";
|
|
152
153
|
export {
|
|
153
154
|
y as GlobalLayout,
|
|
154
155
|
x as GlobalLayoutContent,
|
|
155
|
-
|
|
156
|
+
k as GlobalLayoutContentBody,
|
|
156
157
|
h as GlobalLayoutContentHeader,
|
|
157
|
-
|
|
158
|
+
w as GlobalLayoutMobileHeader,
|
|
158
159
|
p as GlobalLayoutSidebar
|
|
159
160
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@brightlocal/ui-components",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.10.0",
|
|
4
4
|
"description": "BrightLocal Design System UI Components",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"private": false,
|
|
@@ -130,8 +130,8 @@
|
|
|
130
130
|
"vite-bundle-visualizer": "^1.2.1",
|
|
131
131
|
"vite-plugin-dts": "^4.5.4",
|
|
132
132
|
"vite-plugin-lib-inject-css": "^2.2.2",
|
|
133
|
-
"@workspace/
|
|
134
|
-
"@workspace/
|
|
133
|
+
"@workspace/typescript-config": "0.0.0",
|
|
134
|
+
"@workspace/eslint-config": "0.0.0"
|
|
135
135
|
},
|
|
136
136
|
"publishConfig": {
|
|
137
137
|
"access": "public",
|
|
@@ -211,10 +211,13 @@
|
|
|
211
211
|
"typecheck": "tsc --noEmit",
|
|
212
212
|
"clean": "rm -rf dist",
|
|
213
213
|
"build": "pnpm run clean && vite build",
|
|
214
|
+
"build:browser": "vite build --config vite.config.browser.ts && node scripts/audit-browser-demos.mjs",
|
|
214
215
|
"size": "size-limit",
|
|
215
216
|
"analyze": "vite-bundle-visualizer",
|
|
216
217
|
"sync-meta": "node scripts/sync-component-meta.mjs",
|
|
217
218
|
"sync-meta:check": "node scripts/sync-component-meta.mjs --check",
|
|
219
|
+
"audit-demos": "node scripts/audit-browser-demos.mjs",
|
|
220
|
+
"audit-demos:check": "node scripts/audit-browser-demos.mjs --check",
|
|
218
221
|
"build:changelog": "node scripts/generate-changelog.js",
|
|
219
222
|
"rel:patch": "node scripts/changeset-create.mjs patch",
|
|
220
223
|
"rel:minor": "node scripts/changeset-create.mjs minor",
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import "./browser-tokens.css";
|
|
2
|
+
|
|
3
|
+
import * as React from "react";
|
|
4
|
+
import * as ReactDOM from "react-dom";
|
|
5
|
+
import { createRoot, type Root } from "react-dom/client";
|
|
6
|
+
import * as allExports from "./index";
|
|
7
|
+
|
|
8
|
+
// Re-export everything from the barrel
|
|
9
|
+
export * from "./index";
|
|
10
|
+
|
|
11
|
+
export { React, ReactDOM };
|
|
12
|
+
|
|
13
|
+
export const h = React.createElement;
|
|
14
|
+
export const useState = React.useState;
|
|
15
|
+
export const useEffect = React.useEffect;
|
|
16
|
+
export const useMemo = React.useMemo;
|
|
17
|
+
export const useCallback = React.useCallback;
|
|
18
|
+
export const useRef = React.useRef;
|
|
19
|
+
export const useContext = React.useContext;
|
|
20
|
+
export const useReducer = React.useReducer;
|
|
21
|
+
export const useLayoutEffect = React.useLayoutEffect;
|
|
22
|
+
export const Fragment = React.Fragment;
|
|
23
|
+
|
|
24
|
+
// --- Mount API for IIFE consumers ---
|
|
25
|
+
|
|
26
|
+
const roots = new WeakMap<HTMLElement, Root>();
|
|
27
|
+
|
|
28
|
+
const PASCAL_CASE = /^[A-Z][a-zA-Z0-9]+$/;
|
|
29
|
+
|
|
30
|
+
function isComponent(
|
|
31
|
+
key: string,
|
|
32
|
+
value: unknown
|
|
33
|
+
): value is React.ComponentType<Record<string, unknown>> {
|
|
34
|
+
if (!PASCAL_CASE.test(key)) return false;
|
|
35
|
+
if (typeof value === "function") return true;
|
|
36
|
+
if (typeof value === "object" && value !== null && "$$typeof" in value)
|
|
37
|
+
return true;
|
|
38
|
+
return false;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export function mount(
|
|
42
|
+
name: string,
|
|
43
|
+
container: HTMLElement,
|
|
44
|
+
props: Record<string, unknown> = {}
|
|
45
|
+
): () => void {
|
|
46
|
+
const Component = (allExports as Record<string, unknown>)[name] as
|
|
47
|
+
| React.ComponentType<Record<string, unknown>>
|
|
48
|
+
| undefined;
|
|
49
|
+
|
|
50
|
+
if (!Component || !isComponent(name, Component)) {
|
|
51
|
+
const available = Object.keys(allExports)
|
|
52
|
+
.filter((k) => isComponent(k, (allExports as Record<string, unknown>)[k]))
|
|
53
|
+
.join(", ");
|
|
54
|
+
throw new Error(
|
|
55
|
+
`BrightLocalDS: Unknown component "${name}". Available: ${available}`
|
|
56
|
+
);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
let root = roots.get(container);
|
|
60
|
+
if (!root) {
|
|
61
|
+
root = createRoot(container);
|
|
62
|
+
roots.set(container, root);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
root.render(React.createElement(Component, props));
|
|
66
|
+
|
|
67
|
+
return () => {
|
|
68
|
+
root!.unmount();
|
|
69
|
+
roots.delete(container);
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
export function render(
|
|
74
|
+
element: React.ReactNode,
|
|
75
|
+
container: HTMLElement
|
|
76
|
+
): () => void {
|
|
77
|
+
let root = roots.get(container);
|
|
78
|
+
if (!root) {
|
|
79
|
+
root = createRoot(container);
|
|
80
|
+
roots.set(container, root);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
root.render(element);
|
|
84
|
+
|
|
85
|
+
return () => {
|
|
86
|
+
root!.unmount();
|
|
87
|
+
roots.delete(container);
|
|
88
|
+
};
|
|
89
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
@import "../../../packages/tokens/src/styles/tailwind-preset.css";
|
|
@@ -436,6 +436,57 @@ const ComboboxTrigger = React.forwardRef<
|
|
|
436
436
|
);
|
|
437
437
|
ComboboxTrigger.displayName = "ComboboxTrigger";
|
|
438
438
|
|
|
439
|
+
/* -------------------------------------------------------------------------------------------------
|
|
440
|
+
* Accessor inference
|
|
441
|
+
* -----------------------------------------------------------------------------------------------*/
|
|
442
|
+
|
|
443
|
+
type ValueLabelItem = { value: string; label?: string };
|
|
444
|
+
|
|
445
|
+
function hasValueKey(item: unknown): item is ValueLabelItem {
|
|
446
|
+
return (
|
|
447
|
+
item != null &&
|
|
448
|
+
typeof item === "object" &&
|
|
449
|
+
"value" in item &&
|
|
450
|
+
typeof (item as ValueLabelItem).value === "string"
|
|
451
|
+
);
|
|
452
|
+
}
|
|
453
|
+
|
|
454
|
+
function resolveAccessors<T>(
|
|
455
|
+
items: readonly T[],
|
|
456
|
+
getItemValue: ((item: T) => string) | undefined,
|
|
457
|
+
getItemLabel: ((item: T) => string) | undefined
|
|
458
|
+
): {
|
|
459
|
+
getValue: (item: T) => string;
|
|
460
|
+
getLabel: (item: T) => string;
|
|
461
|
+
hasDistinctLabel: boolean;
|
|
462
|
+
} | null {
|
|
463
|
+
if (getItemValue) {
|
|
464
|
+
return {
|
|
465
|
+
getValue: getItemValue,
|
|
466
|
+
getLabel: getItemLabel ?? getItemValue,
|
|
467
|
+
hasDistinctLabel: !!getItemLabel,
|
|
468
|
+
};
|
|
469
|
+
}
|
|
470
|
+
|
|
471
|
+
const sample = items[0];
|
|
472
|
+
if (!hasValueKey(sample)) return null;
|
|
473
|
+
|
|
474
|
+
const getValue = (item: T) => (item as unknown as ValueLabelItem).value;
|
|
475
|
+
|
|
476
|
+
const hasLabel =
|
|
477
|
+
"label" in sample &&
|
|
478
|
+
typeof (sample as { label?: unknown }).label === "string";
|
|
479
|
+
const getLabel = hasLabel
|
|
480
|
+
? (item: T) => String((item as unknown as { label: string }).label)
|
|
481
|
+
: getValue;
|
|
482
|
+
|
|
483
|
+
return {
|
|
484
|
+
getValue,
|
|
485
|
+
getLabel: getItemLabel ?? getLabel,
|
|
486
|
+
hasDistinctLabel: hasLabel || !!getItemLabel,
|
|
487
|
+
};
|
|
488
|
+
}
|
|
489
|
+
|
|
439
490
|
/* -------------------------------------------------------------------------------------------------
|
|
440
491
|
* Combobox Value
|
|
441
492
|
* -----------------------------------------------------------------------------------------------*/
|
|
@@ -476,7 +527,7 @@ export interface ComboboxValueProps<T = unknown> {
|
|
|
476
527
|
* ```
|
|
477
528
|
*/
|
|
478
529
|
items?: readonly T[];
|
|
479
|
-
/** Extract the value string from an item.
|
|
530
|
+
/** Extract the value string from an item. Auto-inferred for items with a `value` string property. */
|
|
480
531
|
getItemValue?: (item: T) => string;
|
|
481
532
|
/** Extract the display label from an item. Falls back to `getItemValue` when not provided. */
|
|
482
533
|
getItemLabel?: (item: T) => string;
|
|
@@ -492,20 +543,24 @@ function ComboboxValue<T>({
|
|
|
492
543
|
}: ComboboxValueProps<T>) {
|
|
493
544
|
const { value, itemLabels } = useComboboxContext();
|
|
494
545
|
|
|
546
|
+
const accessors = React.useMemo(
|
|
547
|
+
() => (items ? resolveAccessors(items, getItemValue, getItemLabel) : null),
|
|
548
|
+
[items, getItemValue, getItemLabel]
|
|
549
|
+
);
|
|
550
|
+
|
|
495
551
|
useDevWarning(
|
|
496
|
-
() => !!items && !
|
|
497
|
-
"ComboboxValue: `
|
|
498
|
-
"Pass `getItemValue`
|
|
499
|
-
[items,
|
|
552
|
+
() => !!items && items.length > 0 && !accessors,
|
|
553
|
+
"ComboboxValue: could not infer `getItemValue` from item shape. " +
|
|
554
|
+
"Pass `getItemValue` explicitly, or use items with a `value` string property.",
|
|
555
|
+
[items, accessors]
|
|
500
556
|
);
|
|
501
557
|
|
|
502
558
|
const itemsMap = React.useMemo(() => {
|
|
503
|
-
if (!items || !
|
|
504
|
-
const resolveLabel = getItemLabel ?? getItemValue;
|
|
559
|
+
if (!items || !accessors) return null;
|
|
505
560
|
return new Map(
|
|
506
|
-
items.map((item) => [
|
|
561
|
+
items.map((item) => [accessors.getValue(item), accessors.getLabel(item)])
|
|
507
562
|
);
|
|
508
|
-
}, [items,
|
|
563
|
+
}, [items, accessors]);
|
|
509
564
|
|
|
510
565
|
const displayText = value
|
|
511
566
|
? itemsMap?.get(value) ||
|
|
@@ -801,7 +856,7 @@ const ComboboxList = React.forwardRef<
|
|
|
801
856
|
return (
|
|
802
857
|
<CommandList
|
|
803
858
|
ref={ref}
|
|
804
|
-
className={cn("min-h-0 flex-1", className)}
|
|
859
|
+
className={cn("scrollbar min-h-0 flex-1", className)}
|
|
805
860
|
data-slot="combobox-list"
|
|
806
861
|
{...props}
|
|
807
862
|
/>
|
|
@@ -816,8 +871,8 @@ ComboboxList.displayName = "ComboboxList";
|
|
|
816
871
|
export interface ComboboxVirtualListProps<T> {
|
|
817
872
|
/** Array of items to virtualise. Memoize with useMemo to avoid re-registering labels on every render. */
|
|
818
873
|
items: readonly T[];
|
|
819
|
-
/** Extract the string value for each item (used for selection and keyboard navigation) */
|
|
820
|
-
getItemValue
|
|
874
|
+
/** Extract the string value for each item (used for selection and keyboard navigation). Auto-inferred for items with a `value` string property. */
|
|
875
|
+
getItemValue?: (item: T) => string;
|
|
821
876
|
/**
|
|
822
877
|
* Extract a display label for filtering and trigger display. Defaults to `getItemValue`.
|
|
823
878
|
* Only used when `shouldFilter` is true on the parent Combobox.
|
|
@@ -859,8 +914,8 @@ export interface ComboboxVirtualListProps<T> {
|
|
|
859
914
|
function ComboboxVirtualListInner<T>(
|
|
860
915
|
{
|
|
861
916
|
items,
|
|
862
|
-
getItemValue,
|
|
863
|
-
getItemLabel,
|
|
917
|
+
getItemValue: getItemValueProp,
|
|
918
|
+
getItemLabel: getItemLabelProp,
|
|
864
919
|
getItemKeywords,
|
|
865
920
|
estimateSize = 36,
|
|
866
921
|
overscan = 5,
|
|
@@ -871,6 +926,35 @@ function ComboboxVirtualListInner<T>(
|
|
|
871
926
|
}: ComboboxVirtualListProps<T>,
|
|
872
927
|
ref: React.ForwardedRef<HTMLDivElement>
|
|
873
928
|
) {
|
|
929
|
+
const accessors = React.useMemo(
|
|
930
|
+
() => resolveAccessors(items, getItemValueProp, getItemLabelProp),
|
|
931
|
+
[items, getItemValueProp, getItemLabelProp]
|
|
932
|
+
);
|
|
933
|
+
|
|
934
|
+
const getItemValue = React.useMemo(
|
|
935
|
+
() =>
|
|
936
|
+
accessors?.getValue ??
|
|
937
|
+
((item: T) => {
|
|
938
|
+
if (typeof item === "string" || typeof item === "number")
|
|
939
|
+
return String(item);
|
|
940
|
+
throw new Error(
|
|
941
|
+
"[BrightLocal DS] ComboboxVirtualList: `getItemValue` is required for non-primitive items without a `value` property."
|
|
942
|
+
);
|
|
943
|
+
}),
|
|
944
|
+
[accessors]
|
|
945
|
+
);
|
|
946
|
+
const getItemLabel = React.useMemo(
|
|
947
|
+
() => accessors?.getLabel ?? getItemValue,
|
|
948
|
+
[accessors, getItemValue]
|
|
949
|
+
);
|
|
950
|
+
|
|
951
|
+
useDevWarning(
|
|
952
|
+
() => !accessors && items.length > 0,
|
|
953
|
+
"ComboboxVirtualList: could not infer `getItemValue` from item shape. " +
|
|
954
|
+
"Pass `getItemValue` explicitly, or use items with a `value` string property.",
|
|
955
|
+
[accessors, items.length]
|
|
956
|
+
);
|
|
957
|
+
|
|
874
958
|
const parentRef = React.useRef<HTMLDivElement>(null);
|
|
875
959
|
const {
|
|
876
960
|
value,
|
|
@@ -889,18 +973,10 @@ function ComboboxVirtualListInner<T>(
|
|
|
889
973
|
// Merge forwarded ref with internal ref
|
|
890
974
|
React.useImperativeHandle(ref, () => parentRef.current!, []);
|
|
891
975
|
|
|
892
|
-
// Bulk-register all item labels upfront so ComboboxValue can always resolve
|
|
893
|
-
// the display label — even for items outside the virtualised viewport.
|
|
894
|
-
// Uses useLayoutEffect + synchronous flush so labels are available before
|
|
895
|
-
// the browser paints (no flash of raw values when a value is pre-selected).
|
|
896
|
-
// Cleanup unregisters stale labels when `items` changes (e.g. server-driven
|
|
897
|
-
// filtering/pagination). The selected value's label survives because
|
|
898
|
-
// unregisterItem has a guard that preserves the currently selected value.
|
|
899
976
|
React.useLayoutEffect(() => {
|
|
900
|
-
const resolveLabel = getItemLabel ?? getItemValue;
|
|
901
977
|
const entries: [string, string][] = items.map((item) => [
|
|
902
978
|
getItemValue(item),
|
|
903
|
-
|
|
979
|
+
getItemLabel(item),
|
|
904
980
|
]);
|
|
905
981
|
registerItemsSync(entries);
|
|
906
982
|
return () => {
|
|
@@ -918,9 +994,10 @@ function ComboboxVirtualListInner<T>(
|
|
|
918
994
|
|
|
919
995
|
const scored: { item: T; score: number }[] = [];
|
|
920
996
|
for (const item of items) {
|
|
921
|
-
//
|
|
922
|
-
//
|
|
923
|
-
|
|
997
|
+
// When a distinct label accessor exists (explicit getItemLabel or
|
|
998
|
+
// inferred `label` key), filter by label text. Otherwise delegate to
|
|
999
|
+
// the shared filterFn which respects itemToStringValue.
|
|
1000
|
+
let score = accessors?.hasDistinctLabel
|
|
924
1001
|
? defaultFilter(getItemLabel(item), searchValue)
|
|
925
1002
|
: filterFn(getItemValue(item), searchValue);
|
|
926
1003
|
|
|
@@ -946,6 +1023,7 @@ function ComboboxVirtualListInner<T>(
|
|
|
946
1023
|
getItemLabel,
|
|
947
1024
|
getItemKeywords,
|
|
948
1025
|
filterFn,
|
|
1026
|
+
accessors?.hasDistinctLabel,
|
|
949
1027
|
]);
|
|
950
1028
|
|
|
951
1029
|
// eslint-disable-next-line react-hooks/incompatible-library -- compiler already skips this component; virtualizer is not passed to memoized consumers
|
|
@@ -1104,7 +1182,7 @@ function ComboboxVirtualListInner<T>(
|
|
|
1104
1182
|
<div
|
|
1105
1183
|
ref={parentRef}
|
|
1106
1184
|
className={cn(
|
|
1107
|
-
"max-h-[300px] min-h-0 flex-1 scroll-py-1 overflow-x-hidden overflow-y-auto py-1",
|
|
1185
|
+
"scrollbar max-h-[300px] min-h-0 flex-1 scroll-py-1 overflow-x-hidden overflow-y-auto py-1",
|
|
1108
1186
|
className
|
|
1109
1187
|
)}
|
|
1110
1188
|
data-hook={dataHook}
|
|
@@ -1121,7 +1199,7 @@ function ComboboxVirtualListInner<T>(
|
|
|
1121
1199
|
<div
|
|
1122
1200
|
ref={parentRef}
|
|
1123
1201
|
className={cn(
|
|
1124
|
-
"max-h-[300px] min-h-0 flex-1 scroll-py-1 overflow-x-hidden overflow-y-auto py-1",
|
|
1202
|
+
"scrollbar max-h-[300px] min-h-0 flex-1 scroll-py-1 overflow-x-hidden overflow-y-auto py-1",
|
|
1125
1203
|
className
|
|
1126
1204
|
)}
|
|
1127
1205
|
data-hook={dataHook}
|
|
@@ -143,10 +143,7 @@ const GlobalLayoutContent = React.forwardRef<
|
|
|
143
143
|
return (
|
|
144
144
|
<div
|
|
145
145
|
ref={ref}
|
|
146
|
-
className={cn(
|
|
147
|
-
"px-section-xs flex min-w-0 flex-1 flex-col gap-6",
|
|
148
|
-
className
|
|
149
|
-
)}
|
|
146
|
+
className={cn("px-section-xs flex min-w-0 flex-1 flex-col", className)}
|
|
150
147
|
data-hook={dataHook}
|
|
151
148
|
data-slot="content-wrapper"
|
|
152
149
|
style={
|
|
@@ -188,9 +185,10 @@ const GlobalLayoutContentHeader = React.forwardRef<
|
|
|
188
185
|
return (
|
|
189
186
|
<Header
|
|
190
187
|
ref={ref}
|
|
191
|
-
className={cn("w-full justify-between", className)}
|
|
188
|
+
className={cn("mx-auto w-full justify-between", className)}
|
|
192
189
|
data-slot="content-header"
|
|
193
190
|
dataHook={dataHook}
|
|
191
|
+
style={{ maxWidth: "var(--ds-breakpoint-lg)" }}
|
|
194
192
|
trackingEl={trackingEl}
|
|
195
193
|
trackingLabel={trackingLabel}
|
|
196
194
|
{...props}
|
|
@@ -229,7 +227,10 @@ const GlobalLayoutContentBody = React.forwardRef<
|
|
|
229
227
|
return (
|
|
230
228
|
<div
|
|
231
229
|
ref={ref}
|
|
232
|
-
className={cn(
|
|
230
|
+
className={cn(
|
|
231
|
+
"mx-auto mt-6 flex w-full flex-1 flex-col gap-6",
|
|
232
|
+
className
|
|
233
|
+
)}
|
|
233
234
|
data-hook={dataHook}
|
|
234
235
|
data-slot="content-body"
|
|
235
236
|
data-tracking-el={trackingEl}
|