@designa8/vibedesign-v6 1.20.20 → 2.1.2
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 +1 -1
- package/dist/fonts/plusjakartasans/PlusJakartaSans-Italic[wght].ttf +0 -0
- package/dist/fonts/plusjakartasans/PlusJakartaSans[wght].ttf +0 -0
- package/dist/index.cjs +12027 -4942
- package/dist/index.js +12089 -5004
- package/dist/styles.css +1393 -97
- package/package.json +116 -1
- package/src/atoms/AgentQuestionCard/AgentQuestionCard.tsx +567 -0
- package/src/atoms/AgentQuestionCard/index.ts +6 -0
- package/src/atoms/AgentQuestionCard/preview.tsx +199 -0
- package/src/atoms/AppLayout/AppLayout.tsx +85 -22
- package/src/atoms/AppLayout/preview.tsx +4 -0
- package/src/atoms/AppSidebar/AppSidebar.tsx +224 -138
- package/src/atoms/AppSidebar/index.ts +1 -1
- package/src/atoms/AppSidebar/preview.tsx +61 -8
- package/src/atoms/AppSidebarMobile/AppSidebarMobile.tsx +242 -173
- package/src/atoms/AppSidebarMobile/preview.tsx +59 -89
- package/src/atoms/AuthLogin/AuthLogin.tsx +86 -49
- package/src/atoms/AuthLogin/preview.tsx +16 -0
- package/src/atoms/AuthSignUp/AuthSignUp.tsx +206 -126
- package/src/atoms/AuthSignUp/preview.tsx +10 -0
- package/src/atoms/BottomSheet/BottomSheet.tsx +199 -0
- package/src/atoms/BottomSheet/index.ts +2 -0
- package/src/atoms/BottomSheet/preview.tsx +50 -0
- package/src/atoms/Button/Button.tsx +19 -3
- package/src/atoms/Button/preview.tsx +2 -1
- package/src/atoms/ChatHistorySidebar/ChatHistorySidebar.tsx +160 -84
- package/src/atoms/ChatHistorySidebar/preview.tsx +81 -42
- package/src/atoms/ChatScreen/ChatScreen.tsx +298 -33
- package/src/atoms/ChatScreen/preview.tsx +54 -90
- package/src/atoms/Chip/Chip.tsx +81 -33
- package/src/atoms/Chip/preview.tsx +39 -21
- package/src/atoms/CodeEditor/CodeEditor.tsx +10 -4
- package/src/atoms/ComponentActionsSheet/ComponentActionsSheet.tsx +165 -0
- package/src/atoms/ComponentActionsSheet/index.ts +7 -0
- package/src/atoms/ComponentActionsSheet/preview.tsx +67 -0
- package/src/atoms/ComponentCard/ComponentCard.tsx +17 -35
- package/src/atoms/ComponentCard/preview.tsx +9 -9
- package/src/atoms/DesignSystemLoader/DesignSystemLoader.tsx +153 -0
- package/src/atoms/DesignSystemLoader/index.ts +2 -0
- package/src/atoms/DesignSystemLoader/preview.tsx +19 -0
- package/src/atoms/DesignSystemShowcase/DesignSystemShowcase.tsx +410 -0
- package/src/atoms/DesignSystemShowcase/index.ts +6 -0
- package/src/atoms/DesignSystemShowcase/preview.tsx +22 -0
- package/src/atoms/DesignTokensPanel/DesignTokensPanel.data.ts +254 -0
- package/src/atoms/DesignTokensPanel/DesignTokensPanel.tsx +946 -0
- package/src/atoms/DesignTokensPanel/index.ts +9 -0
- package/src/atoms/DesignTokensPanel/preview.tsx +39 -0
- package/src/atoms/ExpandableMessage/ExpandableMessage.tsx +239 -0
- package/src/atoms/ExpandableMessage/fix-link-note.txt +3 -0
- package/src/atoms/ExpandableMessage/index.ts +2 -0
- package/src/atoms/ExpandableMessage/markdown.tsx +310 -0
- package/src/atoms/ExpandableMessage/preview.tsx +83 -0
- package/src/atoms/ExportDesignMdModal/ExportDesignMdModal.tsx +6 -1
- package/src/atoms/FilterTabBar/FilterTabBar.tsx +2 -2
- package/src/atoms/FontCombobox/FontCombobox.tsx +655 -0
- package/src/atoms/FontCombobox/index.ts +6 -0
- package/src/atoms/FontCombobox/preview.tsx +111 -0
- package/src/atoms/HomePageTemplate/HomePageTemplate.tsx +894 -96
- package/src/atoms/HomePageTemplate/preview.tsx +4 -0
- package/src/atoms/Icon/Icon.tsx +17 -11
- package/src/atoms/Icon/icons.data.ts +34 -0
- package/src/atoms/Input/Input.tsx +37 -21
- package/src/atoms/LandingHero/LandingHero.tsx +545 -0
- package/src/atoms/LandingHero/index.ts +6 -0
- package/src/atoms/LandingHero/preview.tsx +88 -0
- package/src/atoms/MarketingFooter/MarketingFooter.tsx +215 -0
- package/src/atoms/MarketingFooter/index.ts +7 -0
- package/src/atoms/MarketingFooter/preview.tsx +28 -0
- package/src/atoms/MarketingNavbar/MarketingNavbar.tsx +451 -0
- package/src/atoms/MarketingNavbar/index.ts +7 -0
- package/src/atoms/MarketingNavbar/preview.tsx +109 -0
- package/src/atoms/Menu/Menu.tsx +1 -1
- package/src/atoms/MobileActionsDrawer/MobileActionsDrawer.tsx +548 -0
- package/src/atoms/MobileActionsDrawer/index.ts +9 -0
- package/src/atoms/MobileActionsDrawer/preview.tsx +109 -0
- package/src/atoms/Modal/Modal.tsx +77 -28
- package/src/atoms/PreviewDock/PreviewDock.tsx +119 -0
- package/src/atoms/PreviewDock/index.ts +2 -0
- package/src/atoms/PreviewDock/preview.tsx +30 -0
- package/src/atoms/PreviewToolbar/PreviewToolbar.tsx +47 -30
- package/src/atoms/PricingCard/PricingCard.tsx +15 -4
- package/src/atoms/PricingPageTemplate/PricingPageTemplate.tsx +109 -89
- package/src/atoms/ProjectSettingsModal/ProjectSettingsModal.tsx +314 -0
- package/src/atoms/ProjectSettingsModal/index.ts +2 -0
- package/src/atoms/ProjectSettingsModal/preview.tsx +130 -0
- package/src/atoms/ProjectSettingsModal/switch.snippet.txt +8 -0
- package/src/atoms/PromptInputBar/PromptInputBar.tsx +750 -302
- package/src/atoms/PromptInputBar/preview.tsx +64 -64
- package/src/atoms/SettingsPageTemplate/SettingsPageTemplate.tsx +272 -0
- package/src/atoms/SettingsPageTemplate/index.ts +2 -0
- package/src/atoms/SettingsPageTemplate/preview.tsx +29 -0
- package/src/atoms/SidebarUpgradeBanner/SidebarUpgradeBanner.tsx +178 -0
- package/src/atoms/SidebarUpgradeBanner/index.ts +2 -0
- package/src/atoms/SidebarUpgradeBanner/preview.tsx +47 -0
- package/src/atoms/SkeletonChip/SkeletonChip.tsx +198 -0
- package/src/atoms/SkeletonChip/index.ts +2 -0
- package/src/atoms/SkeletonChip/preview.tsx +44 -0
- package/src/atoms/TemplateHeader/TemplateHeader.tsx +129 -0
- package/src/atoms/TemplateHeader/index.ts +2 -0
- package/src/atoms/TemplateHeader/preview.tsx +39 -0
- package/src/atoms/TemplateHero/TemplateHero.tsx +286 -0
- package/src/atoms/TemplateHero/index.ts +2 -0
- package/src/atoms/TemplateHero/preview.tsx +32 -0
- package/src/atoms/TemplateSummary/TemplateSummary.tsx +85 -0
- package/src/atoms/TemplateSummary/index.ts +2 -0
- package/src/atoms/TemplateSummary/preview.tsx +10 -0
- package/src/atoms/Toast/Toast.tsx +178 -0
- package/src/atoms/Toast/index.ts +2 -0
- package/src/atoms/Toast/preview.tsx +100 -0
- package/src/atoms/TopNavbar/TopNavbar.tsx +145 -67
- package/src/atoms/TopNavbar/preview.tsx +13 -7
- package/src/atoms/TopupModal/TopupModal.tsx +94 -0
- package/src/atoms/TopupModal/index.ts +2 -0
- package/src/atoms/TopupModal/preview.tsx +22 -0
- package/src/atoms/UpgradeCard/UpgradeCard.tsx +124 -43
- package/src/atoms/UpgradeCard/index.ts +1 -1
- package/src/atoms/UpgradeCard/preview.tsx +7 -14
- package/src/atoms/UpgradeModal/UpgradeModal.tsx +192 -0
- package/src/atoms/UpgradeModal/index.ts +2 -0
- package/src/atoms/UpgradeModal/preview.tsx +41 -0
- package/src/index.ts +23 -0
- package/src/tokens.css +45 -7
- package/dist/fonts/inter/Inter-Italic[opsz,wght].ttf +0 -0
- package/dist/fonts/inter/Inter[opsz,wght].ttf +0 -0
|
@@ -76,7 +76,12 @@ const defaultLines: ExportDesignMdLine[] = [
|
|
|
76
76
|
|
|
77
77
|
const SOURCE_INFO: Record<
|
|
78
78
|
ExportDesignMdSource,
|
|
79
|
-
{
|
|
79
|
+
{
|
|
80
|
+
icon: React.ComponentProps<typeof Icon>["name"];
|
|
81
|
+
title: string;
|
|
82
|
+
description: string;
|
|
83
|
+
helper: string;
|
|
84
|
+
}
|
|
80
85
|
> = {
|
|
81
86
|
production: {
|
|
82
87
|
icon: "cloud",
|
|
@@ -51,7 +51,7 @@ export const FilterTabBar = React.forwardRef<HTMLDivElement, FilterTabBarProps>(
|
|
|
51
51
|
onClick={() => onChange(tab.value)}
|
|
52
52
|
className={
|
|
53
53
|
isIconOnly
|
|
54
|
-
? "!w-
|
|
54
|
+
? "!w-8 !h-8 !min-w-8 !max-w-8 !rounded-full shrink-0 justify-center !p-0 !px-0 !py-0 leading-none"
|
|
55
55
|
: "gap-xs !rounded-lg"
|
|
56
56
|
}
|
|
57
57
|
>
|
|
@@ -89,4 +89,4 @@ export const FilterTabBar = React.forwardRef<HTMLDivElement, FilterTabBarProps>(
|
|
|
89
89
|
}
|
|
90
90
|
);
|
|
91
91
|
|
|
92
|
-
FilterTabBar.displayName = "FilterTabBar";
|
|
92
|
+
FilterTabBar.displayName = "FilterTabBar";
|
|
@@ -0,0 +1,655 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { createPortal } from "react-dom";
|
|
3
|
+
import { Icon } from "../Icon";
|
|
4
|
+
import { Input } from "../Input";
|
|
5
|
+
|
|
6
|
+
export type FontCategory =
|
|
7
|
+
| "SANS_SERIF"
|
|
8
|
+
| "SERIF"
|
|
9
|
+
| "DISPLAY"
|
|
10
|
+
| "HANDWRITING"
|
|
11
|
+
| "MONOSPACE"
|
|
12
|
+
| "OTHER";
|
|
13
|
+
|
|
14
|
+
export interface FontOption {
|
|
15
|
+
name: string;
|
|
16
|
+
category: FontCategory;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export interface FontComboboxProps
|
|
20
|
+
extends Omit<
|
|
21
|
+
React.ComponentPropsWithoutRef<"button">,
|
|
22
|
+
"value" | "onChange" | "children"
|
|
23
|
+
> {
|
|
24
|
+
/** Visible label rendered above the trigger */
|
|
25
|
+
label?: string;
|
|
26
|
+
/** Primary family name of the current font (e.g. "Inter") */
|
|
27
|
+
value: string;
|
|
28
|
+
/** Full list of selectable fonts */
|
|
29
|
+
fonts: FontOption[];
|
|
30
|
+
/** Called with the picked family name */
|
|
31
|
+
onChange: (name: string) => void;
|
|
32
|
+
/** Called when a row (or the selected trigger) is rendered, so the host can lazy-load its webfont */
|
|
33
|
+
onRowVisible?: (name: string) => void;
|
|
34
|
+
/** Trigger text when no value is set */
|
|
35
|
+
placeholder?: string;
|
|
36
|
+
/** Placeholder inside the search field */
|
|
37
|
+
searchPlaceholder?: string;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
type Filter = FontCategory | "ALL";
|
|
41
|
+
|
|
42
|
+
const FILTERS: ReadonlyArray<{ id: Filter; label: string }> = [
|
|
43
|
+
{ id: "ALL", label: "All" },
|
|
44
|
+
{ id: "SANS_SERIF", label: "Sans Serif" },
|
|
45
|
+
{ id: "SERIF", label: "Serif" },
|
|
46
|
+
{ id: "DISPLAY", label: "Display" },
|
|
47
|
+
{ id: "HANDWRITING", label: "Handwriting" },
|
|
48
|
+
{ id: "MONOSPACE", label: "Monospace" },
|
|
49
|
+
];
|
|
50
|
+
|
|
51
|
+
const CATEGORY_LABELS: Record<FontCategory, string> = {
|
|
52
|
+
SANS_SERIF: "Sans Serif",
|
|
53
|
+
SERIF: "Serif",
|
|
54
|
+
DISPLAY: "Display",
|
|
55
|
+
HANDWRITING: "Handwriting",
|
|
56
|
+
MONOSPACE: "Monospace",
|
|
57
|
+
OTHER: "",
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
const ROW_HEIGHT = 40;
|
|
61
|
+
const LIST_MAX = 320;
|
|
62
|
+
const OVERSCAN = 4;
|
|
63
|
+
const CHROME = 136;
|
|
64
|
+
const GAP = 4;
|
|
65
|
+
const MARGIN = 8;
|
|
66
|
+
const MIN_PANEL_W = 280;
|
|
67
|
+
|
|
68
|
+
interface Position {
|
|
69
|
+
left: number;
|
|
70
|
+
width: number;
|
|
71
|
+
top?: number;
|
|
72
|
+
bottom?: number;
|
|
73
|
+
maxList: number;
|
|
74
|
+
above: boolean;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
const INITIAL_POS: Position = {
|
|
78
|
+
left: 0,
|
|
79
|
+
width: MIN_PANEL_W,
|
|
80
|
+
top: 0,
|
|
81
|
+
maxList: LIST_MAX,
|
|
82
|
+
above: false,
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
function genericFor(category: FontCategory | undefined): string {
|
|
86
|
+
switch (category) {
|
|
87
|
+
case "SERIF":
|
|
88
|
+
return "serif";
|
|
89
|
+
case "MONOSPACE":
|
|
90
|
+
return "monospace";
|
|
91
|
+
case "HANDWRITING":
|
|
92
|
+
return "cursive";
|
|
93
|
+
default:
|
|
94
|
+
return "sans-serif";
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
function stackFor(name: string, category: FontCategory | undefined): string {
|
|
99
|
+
return `"${name.replace(/"/g, '\\"')}", ${genericFor(category)}`;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
export const FontCombobox = React.forwardRef<HTMLButtonElement, FontComboboxProps>(
|
|
103
|
+
(
|
|
104
|
+
{
|
|
105
|
+
label,
|
|
106
|
+
value,
|
|
107
|
+
fonts,
|
|
108
|
+
onChange,
|
|
109
|
+
onRowVisible,
|
|
110
|
+
placeholder = "Select a font…",
|
|
111
|
+
searchPlaceholder,
|
|
112
|
+
id,
|
|
113
|
+
disabled,
|
|
114
|
+
className = "",
|
|
115
|
+
onKeyDown,
|
|
116
|
+
...rest
|
|
117
|
+
},
|
|
118
|
+
ref
|
|
119
|
+
) => {
|
|
120
|
+
const uid = React.useId();
|
|
121
|
+
const triggerId = id ?? `${uid}-trigger`;
|
|
122
|
+
const panelId = `${uid}-panel`;
|
|
123
|
+
const listId = `${uid}-list`;
|
|
124
|
+
|
|
125
|
+
const [open, setOpen] = React.useState(false);
|
|
126
|
+
const [rendered, setRendered] = React.useState(false);
|
|
127
|
+
const [search, setSearch] = React.useState("");
|
|
128
|
+
const [category, setCategory] = React.useState<Filter>("ALL");
|
|
129
|
+
const [highlighted, setHighlighted] = React.useState(0);
|
|
130
|
+
const [scrollTop, setScrollTop] = React.useState(0);
|
|
131
|
+
const [pos, setPos] = React.useState<Position>(INITIAL_POS);
|
|
132
|
+
const [indicator, setIndicator] = React.useState({ x: 0, w: 0 });
|
|
133
|
+
|
|
134
|
+
const triggerRef = React.useRef<HTMLButtonElement | null>(null);
|
|
135
|
+
const panelRef = React.useRef<HTMLDivElement>(null);
|
|
136
|
+
const searchRef = React.useRef<HTMLInputElement>(null);
|
|
137
|
+
const listRef = React.useRef<HTMLDivElement>(null);
|
|
138
|
+
const chipsRef = React.useRef<HTMLDivElement>(null);
|
|
139
|
+
const chipRefs = React.useRef<Record<string, HTMLButtonElement | null>>({});
|
|
140
|
+
|
|
141
|
+
const setTriggerRef = React.useCallback(
|
|
142
|
+
(node: HTMLButtonElement | null) => {
|
|
143
|
+
triggerRef.current = node;
|
|
144
|
+
if (typeof ref === "function") ref(node);
|
|
145
|
+
else if (ref) (ref as React.MutableRefObject<HTMLButtonElement | null>).current = node;
|
|
146
|
+
},
|
|
147
|
+
[ref]
|
|
148
|
+
);
|
|
149
|
+
|
|
150
|
+
const visibleCb = React.useRef(onRowVisible);
|
|
151
|
+
visibleCb.current = onRowVisible;
|
|
152
|
+
const notifyVisible = React.useCallback((name: string) => {
|
|
153
|
+
visibleCb.current?.(name);
|
|
154
|
+
}, []);
|
|
155
|
+
|
|
156
|
+
// ---- Data -------------------------------------------------------------
|
|
157
|
+
|
|
158
|
+
const selectedEntry = React.useMemo(() => {
|
|
159
|
+
const needle = value.trim().toLowerCase();
|
|
160
|
+
if (!needle) return undefined;
|
|
161
|
+
return fonts.find((f) => f.name.toLowerCase() === needle);
|
|
162
|
+
}, [fonts, value]);
|
|
163
|
+
|
|
164
|
+
React.useEffect(() => {
|
|
165
|
+
if (value) notifyVisible(value);
|
|
166
|
+
}, [value, notifyVisible]);
|
|
167
|
+
|
|
168
|
+
const filtered = React.useMemo(() => {
|
|
169
|
+
const needle = search.trim().toLowerCase();
|
|
170
|
+
return fonts.filter((f) => {
|
|
171
|
+
if (category !== "ALL" && f.category !== category) return false;
|
|
172
|
+
if (needle && !f.name.toLowerCase().includes(needle)) return false;
|
|
173
|
+
return true;
|
|
174
|
+
});
|
|
175
|
+
}, [fonts, search, category]);
|
|
176
|
+
|
|
177
|
+
const selectedIdx = React.useMemo(
|
|
178
|
+
() =>
|
|
179
|
+
selectedEntry
|
|
180
|
+
? filtered.findIndex((f) => f.name === selectedEntry.name)
|
|
181
|
+
: -1,
|
|
182
|
+
[filtered, selectedEntry]
|
|
183
|
+
);
|
|
184
|
+
|
|
185
|
+
// ---- Open / close lifecycle --------------------------------------------
|
|
186
|
+
|
|
187
|
+
React.useEffect(() => {
|
|
188
|
+
if (open) {
|
|
189
|
+
setRendered(true);
|
|
190
|
+
return;
|
|
191
|
+
}
|
|
192
|
+
const t = window.setTimeout(() => setRendered(false), 260);
|
|
193
|
+
return () => window.clearTimeout(t);
|
|
194
|
+
}, [open]);
|
|
195
|
+
|
|
196
|
+
const openPanel = () => {
|
|
197
|
+
if (disabled) return;
|
|
198
|
+
setSearch("");
|
|
199
|
+
setCategory("ALL");
|
|
200
|
+
setScrollTop(0);
|
|
201
|
+
setOpen(true);
|
|
202
|
+
};
|
|
203
|
+
|
|
204
|
+
const closePanel = React.useCallback((refocus: boolean) => {
|
|
205
|
+
setOpen(false);
|
|
206
|
+
if (refocus) window.setTimeout(() => triggerRef.current?.focus(), 0);
|
|
207
|
+
}, []);
|
|
208
|
+
|
|
209
|
+
// ---- Overlay positioning (fixed, rendered in a portal) ------------------
|
|
210
|
+
|
|
211
|
+
const updatePosition = React.useCallback(() => {
|
|
212
|
+
const el = triggerRef.current;
|
|
213
|
+
if (!el) return;
|
|
214
|
+
const r = el.getBoundingClientRect();
|
|
215
|
+
const vw = window.innerWidth;
|
|
216
|
+
const vh = window.innerHeight;
|
|
217
|
+
const width = Math.min(Math.max(r.width, MIN_PANEL_W), vw - MARGIN * 2);
|
|
218
|
+
const left = Math.min(Math.max(r.left, MARGIN), vw - width - MARGIN);
|
|
219
|
+
const below = vh - r.bottom - GAP - MARGIN;
|
|
220
|
+
const aboveSpace = r.top - GAP - MARGIN;
|
|
221
|
+
const above = below < CHROME + LIST_MAX && aboveSpace > below;
|
|
222
|
+
const avail = above ? aboveSpace : below;
|
|
223
|
+
const maxList = Math.max(ROW_HEIGHT * 3, Math.min(LIST_MAX, avail - CHROME));
|
|
224
|
+
const next: Position = above
|
|
225
|
+
? { left, width, bottom: vh - r.top + GAP, maxList, above }
|
|
226
|
+
: { left, width, top: r.bottom + GAP, maxList, above };
|
|
227
|
+
setPos((prev) =>
|
|
228
|
+
prev.left === next.left &&
|
|
229
|
+
prev.width === next.width &&
|
|
230
|
+
prev.top === next.top &&
|
|
231
|
+
prev.bottom === next.bottom &&
|
|
232
|
+
prev.maxList === next.maxList &&
|
|
233
|
+
prev.above === next.above
|
|
234
|
+
? prev
|
|
235
|
+
: next
|
|
236
|
+
);
|
|
237
|
+
}, []);
|
|
238
|
+
|
|
239
|
+
React.useLayoutEffect(() => {
|
|
240
|
+
if (!open) return;
|
|
241
|
+
updatePosition();
|
|
242
|
+
const onScroll = (e: Event) => {
|
|
243
|
+
if (panelRef.current?.contains(e.target as Node)) return;
|
|
244
|
+
updatePosition();
|
|
245
|
+
};
|
|
246
|
+
window.addEventListener("resize", updatePosition);
|
|
247
|
+
window.addEventListener("scroll", onScroll, true);
|
|
248
|
+
return () => {
|
|
249
|
+
window.removeEventListener("resize", updatePosition);
|
|
250
|
+
window.removeEventListener("scroll", onScroll, true);
|
|
251
|
+
};
|
|
252
|
+
}, [open, updatePosition]);
|
|
253
|
+
|
|
254
|
+
// ---- Outside click + Escape --------------------------------------------
|
|
255
|
+
|
|
256
|
+
React.useEffect(() => {
|
|
257
|
+
if (!open) return;
|
|
258
|
+
const onPointerDown = (e: PointerEvent) => {
|
|
259
|
+
const target = e.target as Node | null;
|
|
260
|
+
if (!target) return;
|
|
261
|
+
if (
|
|
262
|
+
panelRef.current?.contains(target) ||
|
|
263
|
+
triggerRef.current?.contains(target)
|
|
264
|
+
) {
|
|
265
|
+
return;
|
|
266
|
+
}
|
|
267
|
+
closePanel(false);
|
|
268
|
+
};
|
|
269
|
+
const onKey = (e: KeyboardEvent) => {
|
|
270
|
+
if (e.key === "Escape") {
|
|
271
|
+
e.stopPropagation();
|
|
272
|
+
closePanel(true);
|
|
273
|
+
}
|
|
274
|
+
};
|
|
275
|
+
document.addEventListener("pointerdown", onPointerDown);
|
|
276
|
+
document.addEventListener("keydown", onKey, true);
|
|
277
|
+
return () => {
|
|
278
|
+
document.removeEventListener("pointerdown", onPointerDown);
|
|
279
|
+
document.removeEventListener("keydown", onKey, true);
|
|
280
|
+
};
|
|
281
|
+
}, [open, closePanel]);
|
|
282
|
+
|
|
283
|
+
React.useEffect(() => {
|
|
284
|
+
if (!open) return;
|
|
285
|
+
const t = window.setTimeout(
|
|
286
|
+
() => searchRef.current?.focus({ preventScroll: true }),
|
|
287
|
+
30
|
|
288
|
+
);
|
|
289
|
+
return () => window.clearTimeout(t);
|
|
290
|
+
}, [open]);
|
|
291
|
+
|
|
292
|
+
// ---- Highlight + virtual window ----------------------------------------
|
|
293
|
+
|
|
294
|
+
React.useEffect(() => {
|
|
295
|
+
if (!open) return;
|
|
296
|
+
setHighlighted(selectedIdx >= 0 ? selectedIdx : 0);
|
|
297
|
+
}, [open, filtered, selectedIdx]);
|
|
298
|
+
|
|
299
|
+
const listHeight = Math.min(
|
|
300
|
+
pos.maxList,
|
|
301
|
+
Math.max(filtered.length, 1) * ROW_HEIGHT
|
|
302
|
+
);
|
|
303
|
+
|
|
304
|
+
React.useEffect(() => {
|
|
305
|
+
const el = listRef.current;
|
|
306
|
+
if (!open || !el) return;
|
|
307
|
+
const rowTop = highlighted * ROW_HEIGHT;
|
|
308
|
+
const rowBottom = rowTop + ROW_HEIGHT;
|
|
309
|
+
if (rowTop < el.scrollTop) el.scrollTop = rowTop;
|
|
310
|
+
else if (rowBottom > el.scrollTop + listHeight)
|
|
311
|
+
el.scrollTop = rowBottom - listHeight;
|
|
312
|
+
}, [highlighted, open, rendered, listHeight, filtered]);
|
|
313
|
+
|
|
314
|
+
const first = Math.max(0, Math.floor(scrollTop / ROW_HEIGHT) - OVERSCAN);
|
|
315
|
+
const last = Math.min(
|
|
316
|
+
filtered.length,
|
|
317
|
+
Math.ceil((scrollTop + listHeight) / ROW_HEIGHT) + OVERSCAN
|
|
318
|
+
);
|
|
319
|
+
const windowRows = filtered.slice(first, last);
|
|
320
|
+
const padTop = first * ROW_HEIGHT;
|
|
321
|
+
const padBottom = Math.max(0, (filtered.length - last) * ROW_HEIGHT);
|
|
322
|
+
|
|
323
|
+
const resetScroll = () => {
|
|
324
|
+
if (listRef.current) listRef.current.scrollTop = 0;
|
|
325
|
+
setScrollTop(0);
|
|
326
|
+
};
|
|
327
|
+
|
|
328
|
+
// ---- Sliding category indicator ----------------------------------------
|
|
329
|
+
|
|
330
|
+
React.useLayoutEffect(() => {
|
|
331
|
+
if (!rendered) return;
|
|
332
|
+
const el = chipRefs.current[category];
|
|
333
|
+
if (el) setIndicator({ x: el.offsetLeft, w: el.offsetWidth });
|
|
334
|
+
}, [category, rendered]);
|
|
335
|
+
|
|
336
|
+
const pickCategory = (id: Filter) => {
|
|
337
|
+
setCategory(id);
|
|
338
|
+
resetScroll();
|
|
339
|
+
const el = chipRefs.current[id];
|
|
340
|
+
if (el && chipsRef.current) {
|
|
341
|
+
chipsRef.current.scrollTo({
|
|
342
|
+
left: Math.max(0, el.offsetLeft - MARGIN),
|
|
343
|
+
behavior: "smooth",
|
|
344
|
+
});
|
|
345
|
+
}
|
|
346
|
+
};
|
|
347
|
+
|
|
348
|
+
// ---- Commit + keyboard -------------------------------------------------
|
|
349
|
+
|
|
350
|
+
const commit = (entry: FontOption) => {
|
|
351
|
+
onChange(entry.name);
|
|
352
|
+
closePanel(true);
|
|
353
|
+
};
|
|
354
|
+
|
|
355
|
+
const onSearchKeyDown = (e: React.KeyboardEvent<HTMLInputElement>) => {
|
|
356
|
+
const max = filtered.length - 1;
|
|
357
|
+
if (e.key === "ArrowDown") {
|
|
358
|
+
e.preventDefault();
|
|
359
|
+
setHighlighted((h) => Math.min(max, h + 1));
|
|
360
|
+
} else if (e.key === "ArrowUp") {
|
|
361
|
+
e.preventDefault();
|
|
362
|
+
setHighlighted((h) => Math.max(0, h - 1));
|
|
363
|
+
} else if (e.key === "PageDown") {
|
|
364
|
+
e.preventDefault();
|
|
365
|
+
setHighlighted((h) => Math.min(max, h + 7));
|
|
366
|
+
} else if (e.key === "PageUp") {
|
|
367
|
+
e.preventDefault();
|
|
368
|
+
setHighlighted((h) => Math.max(0, h - 7));
|
|
369
|
+
} else if (e.key === "Enter") {
|
|
370
|
+
e.preventDefault();
|
|
371
|
+
const entry = filtered[highlighted];
|
|
372
|
+
if (entry) commit(entry);
|
|
373
|
+
}
|
|
374
|
+
};
|
|
375
|
+
|
|
376
|
+
const onTriggerKeyDown = (e: React.KeyboardEvent<HTMLButtonElement>) => {
|
|
377
|
+
onKeyDown?.(e);
|
|
378
|
+
if (e.defaultPrevented) return;
|
|
379
|
+
if (e.key === "ArrowDown" || e.key === "ArrowUp") {
|
|
380
|
+
e.preventDefault();
|
|
381
|
+
if (!open) openPanel();
|
|
382
|
+
}
|
|
383
|
+
};
|
|
384
|
+
|
|
385
|
+
// ---- Render ------------------------------------------------------------
|
|
386
|
+
|
|
387
|
+
const triggerLabel = value || placeholder;
|
|
388
|
+
const activeId =
|
|
389
|
+
open && filtered[highlighted] ? `${listId}-opt-${highlighted}` : undefined;
|
|
390
|
+
|
|
391
|
+
const panelClasses = [
|
|
392
|
+
"fixed flex flex-col overflow-hidden rounded-lg border border-hairline bg-canvas shadow-md",
|
|
393
|
+
"transition-[opacity,transform,translate,scale,visibility] duration-200 ease-out",
|
|
394
|
+
pos.above ? "origin-bottom" : "origin-top",
|
|
395
|
+
"data-[state=open]:visible data-[state=open]:translate-y-0 data-[state=open]:scale-100 data-[state=open]:opacity-100",
|
|
396
|
+
"data-[state=closed]:invisible data-[state=closed]:pointer-events-none data-[state=closed]:scale-95 data-[state=closed]:opacity-0",
|
|
397
|
+
pos.above
|
|
398
|
+
? "data-[state=closed]:translate-y-1"
|
|
399
|
+
: "data-[state=closed]:-translate-y-1",
|
|
400
|
+
].join(" ");
|
|
401
|
+
|
|
402
|
+
const panel = (
|
|
403
|
+
<div
|
|
404
|
+
ref={panelRef}
|
|
405
|
+
id={panelId}
|
|
406
|
+
role="dialog"
|
|
407
|
+
aria-label={label ? `Choose ${label.toLowerCase()}` : "Choose a font"}
|
|
408
|
+
aria-hidden={!open}
|
|
409
|
+
data-state={open ? "open" : "closed"}
|
|
410
|
+
className={panelClasses}
|
|
411
|
+
style={{
|
|
412
|
+
left: pos.left,
|
|
413
|
+
width: pos.width,
|
|
414
|
+
top: pos.top,
|
|
415
|
+
bottom: pos.bottom,
|
|
416
|
+
zIndex: "var(--z-tooltip, 1400)",
|
|
417
|
+
}}
|
|
418
|
+
>
|
|
419
|
+
<div className="flex flex-col gap-sm border-b border-hairline-soft p-sm">
|
|
420
|
+
<Input
|
|
421
|
+
ref={searchRef}
|
|
422
|
+
size="sm"
|
|
423
|
+
fullWidth
|
|
424
|
+
type="text"
|
|
425
|
+
role="combobox"
|
|
426
|
+
aria-label="Search fonts"
|
|
427
|
+
aria-expanded={open}
|
|
428
|
+
aria-controls={listId}
|
|
429
|
+
aria-activedescendant={activeId}
|
|
430
|
+
aria-autocomplete="list"
|
|
431
|
+
autoComplete="off"
|
|
432
|
+
spellCheck={false}
|
|
433
|
+
leadingIcon={<Icon name="search-magnifier" className="h-4 w-4" />}
|
|
434
|
+
placeholder={
|
|
435
|
+
searchPlaceholder ?? `Search ${fonts.length.toLocaleString()} fonts…`
|
|
436
|
+
}
|
|
437
|
+
value={search}
|
|
438
|
+
onChange={(e) => {
|
|
439
|
+
setSearch(e.target.value);
|
|
440
|
+
resetScroll();
|
|
441
|
+
}}
|
|
442
|
+
onKeyDown={onSearchKeyDown}
|
|
443
|
+
/>
|
|
444
|
+
<div
|
|
445
|
+
ref={chipsRef}
|
|
446
|
+
role="group"
|
|
447
|
+
aria-label="Filter by category"
|
|
448
|
+
className="relative flex gap-xs overflow-x-auto p-xxs"
|
|
449
|
+
>
|
|
450
|
+
<span
|
|
451
|
+
aria-hidden="true"
|
|
452
|
+
className="pointer-events-none absolute left-0 top-xxs h-7 rounded-full bg-primary transition-[transform,width] duration-200 ease-out"
|
|
453
|
+
style={{
|
|
454
|
+
width: indicator.w,
|
|
455
|
+
transform: `translateX(${indicator.x}px)`,
|
|
456
|
+
}}
|
|
457
|
+
/>
|
|
458
|
+
{FILTERS.map((f) => {
|
|
459
|
+
const active = f.id === category;
|
|
460
|
+
return (
|
|
461
|
+
<button
|
|
462
|
+
key={f.id}
|
|
463
|
+
ref={(node) => {
|
|
464
|
+
chipRefs.current[f.id] = node;
|
|
465
|
+
}}
|
|
466
|
+
type="button"
|
|
467
|
+
aria-pressed={active}
|
|
468
|
+
onMouseDown={(e) => e.preventDefault()}
|
|
469
|
+
onClick={() => pickCategory(f.id)}
|
|
470
|
+
className={[
|
|
471
|
+
"relative z-10 h-7 shrink-0 cursor-pointer whitespace-nowrap rounded-full border px-md text-caption",
|
|
472
|
+
"transition duration-150 ease-out active:scale-[0.98]",
|
|
473
|
+
"focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-focus-blue",
|
|
474
|
+
active
|
|
475
|
+
? "border-transparent text-on-primary"
|
|
476
|
+
: "border-hairline text-muted hover:bg-surface-soft hover:text-ink",
|
|
477
|
+
].join(" ")}
|
|
478
|
+
>
|
|
479
|
+
{f.label}
|
|
480
|
+
</button>
|
|
481
|
+
);
|
|
482
|
+
})}
|
|
483
|
+
</div>
|
|
484
|
+
</div>
|
|
485
|
+
|
|
486
|
+
{rendered && filtered.length === 0 ? (
|
|
487
|
+
<div
|
|
488
|
+
role="status"
|
|
489
|
+
className="px-md py-lg text-center text-body-sm text-muted"
|
|
490
|
+
>
|
|
491
|
+
{fonts.length === 0
|
|
492
|
+
? "No fonts available."
|
|
493
|
+
: `No fonts match “${search}”.`}
|
|
494
|
+
</div>
|
|
495
|
+
) : null}
|
|
496
|
+
|
|
497
|
+
{rendered && filtered.length > 0 ? (
|
|
498
|
+
<div
|
|
499
|
+
ref={listRef}
|
|
500
|
+
id={listId}
|
|
501
|
+
role="listbox"
|
|
502
|
+
aria-label="Fonts"
|
|
503
|
+
onScroll={(e) => setScrollTop(e.currentTarget.scrollTop)}
|
|
504
|
+
className="overflow-y-auto"
|
|
505
|
+
style={{ height: listHeight }}
|
|
506
|
+
>
|
|
507
|
+
<div style={{ height: padTop }} aria-hidden="true" />
|
|
508
|
+
{windowRows.map((entry, i) => {
|
|
509
|
+
const idx = first + i;
|
|
510
|
+
return (
|
|
511
|
+
<FontRow
|
|
512
|
+
key={entry.name}
|
|
513
|
+
id={`${listId}-opt-${idx}`}
|
|
514
|
+
entry={entry}
|
|
515
|
+
index={idx}
|
|
516
|
+
total={filtered.length}
|
|
517
|
+
selected={selectedEntry?.name === entry.name}
|
|
518
|
+
highlighted={idx === highlighted}
|
|
519
|
+
onSelect={() => commit(entry)}
|
|
520
|
+
onHover={() => setHighlighted(idx)}
|
|
521
|
+
onVisible={notifyVisible}
|
|
522
|
+
/>
|
|
523
|
+
);
|
|
524
|
+
})}
|
|
525
|
+
<div style={{ height: padBottom }} aria-hidden="true" />
|
|
526
|
+
</div>
|
|
527
|
+
) : null}
|
|
528
|
+
|
|
529
|
+
<div className="flex items-center justify-between gap-sm border-t border-hairline-soft bg-surface px-md py-xs text-caption text-muted">
|
|
530
|
+
<span className="truncate">
|
|
531
|
+
{filtered.length.toLocaleString()} of {fonts.length.toLocaleString()} fonts
|
|
532
|
+
</span>
|
|
533
|
+
<span className="shrink-0">↑↓ · ↵ · esc</span>
|
|
534
|
+
</div>
|
|
535
|
+
</div>
|
|
536
|
+
);
|
|
537
|
+
|
|
538
|
+
return (
|
|
539
|
+
<div className={`flex w-full flex-col gap-xs ${className}`}>
|
|
540
|
+
{label ? (
|
|
541
|
+
<label htmlFor={triggerId} className="text-body-sm font-medium text-ink">
|
|
542
|
+
{label}
|
|
543
|
+
</label>
|
|
544
|
+
) : null}
|
|
545
|
+
|
|
546
|
+
<button
|
|
547
|
+
{...rest}
|
|
548
|
+
ref={setTriggerRef}
|
|
549
|
+
id={triggerId}
|
|
550
|
+
type="button"
|
|
551
|
+
disabled={disabled}
|
|
552
|
+
aria-haspopup="dialog"
|
|
553
|
+
aria-expanded={open}
|
|
554
|
+
aria-controls={panelId}
|
|
555
|
+
onKeyDown={onTriggerKeyDown}
|
|
556
|
+
onClick={(e) => {
|
|
557
|
+
rest.onClick?.(e);
|
|
558
|
+
if (open) closePanel(false);
|
|
559
|
+
else openPanel();
|
|
560
|
+
}}
|
|
561
|
+
className="flex h-10 w-full cursor-pointer items-center justify-between gap-sm rounded-md border border-hairline bg-surface px-md text-left text-body-sm text-ink transition duration-150 ease-out hover:border-hairline-strong hover:bg-surface-soft active:scale-[0.98] focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-focus-blue disabled:cursor-not-allowed disabled:opacity-50"
|
|
562
|
+
>
|
|
563
|
+
<span
|
|
564
|
+
className={`truncate ${value ? "" : "text-muted-soft"}`}
|
|
565
|
+
style={
|
|
566
|
+
value
|
|
567
|
+
? { fontFamily: stackFor(value, selectedEntry?.category) }
|
|
568
|
+
: undefined
|
|
569
|
+
}
|
|
570
|
+
>
|
|
571
|
+
{triggerLabel}
|
|
572
|
+
</span>
|
|
573
|
+
<Icon
|
|
574
|
+
name="chevron-down"
|
|
575
|
+
className={`h-4 w-4 shrink-0 text-muted transition duration-200 ease-out ${
|
|
576
|
+
open ? "rotate-180" : ""
|
|
577
|
+
}`}
|
|
578
|
+
/>
|
|
579
|
+
</button>
|
|
580
|
+
|
|
581
|
+
{typeof document !== "undefined"
|
|
582
|
+
? createPortal(panel, document.body)
|
|
583
|
+
: null}
|
|
584
|
+
</div>
|
|
585
|
+
);
|
|
586
|
+
}
|
|
587
|
+
);
|
|
588
|
+
|
|
589
|
+
FontCombobox.displayName = "FontCombobox";
|
|
590
|
+
|
|
591
|
+
interface FontRowProps {
|
|
592
|
+
id: string;
|
|
593
|
+
entry: FontOption;
|
|
594
|
+
index: number;
|
|
595
|
+
total: number;
|
|
596
|
+
selected: boolean;
|
|
597
|
+
highlighted: boolean;
|
|
598
|
+
onSelect: () => void;
|
|
599
|
+
onHover: () => void;
|
|
600
|
+
onVisible: (name: string) => void;
|
|
601
|
+
}
|
|
602
|
+
|
|
603
|
+
function FontRow({
|
|
604
|
+
id,
|
|
605
|
+
entry,
|
|
606
|
+
index,
|
|
607
|
+
total,
|
|
608
|
+
selected,
|
|
609
|
+
highlighted,
|
|
610
|
+
onSelect,
|
|
611
|
+
onHover,
|
|
612
|
+
onVisible,
|
|
613
|
+
}: FontRowProps) {
|
|
614
|
+
React.useEffect(() => {
|
|
615
|
+
onVisible(entry.name);
|
|
616
|
+
}, [entry.name, onVisible]);
|
|
617
|
+
|
|
618
|
+
return (
|
|
619
|
+
<button
|
|
620
|
+
id={id}
|
|
621
|
+
type="button"
|
|
622
|
+
role="option"
|
|
623
|
+
tabIndex={-1}
|
|
624
|
+
aria-selected={selected}
|
|
625
|
+
aria-posinset={index + 1}
|
|
626
|
+
aria-setsize={total}
|
|
627
|
+
onMouseDown={(e) => e.preventDefault()}
|
|
628
|
+
onClick={onSelect}
|
|
629
|
+
onMouseEnter={onHover}
|
|
630
|
+
style={{ height: ROW_HEIGHT }}
|
|
631
|
+
className={[
|
|
632
|
+
"flex w-full cursor-pointer items-center gap-sm px-md text-left text-body-sm text-ink",
|
|
633
|
+
"transition duration-150 ease-out active:scale-[0.98]",
|
|
634
|
+
"focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-focus-blue",
|
|
635
|
+
highlighted ? "bg-primary-soft" : "bg-transparent hover:bg-surface-soft",
|
|
636
|
+
selected ? "font-weight-body-md" : "",
|
|
637
|
+
].join(" ")}
|
|
638
|
+
>
|
|
639
|
+
<span
|
|
640
|
+
className="min-w-0 flex-1 truncate"
|
|
641
|
+
style={{ fontFamily: stackFor(entry.name, entry.category) }}
|
|
642
|
+
>
|
|
643
|
+
{entry.name}
|
|
644
|
+
</span>
|
|
645
|
+
{CATEGORY_LABELS[entry.category] ? (
|
|
646
|
+
<span className="shrink-0 text-caption text-muted">
|
|
647
|
+
{CATEGORY_LABELS[entry.category]}
|
|
648
|
+
</span>
|
|
649
|
+
) : null}
|
|
650
|
+
<span className="flex h-4 w-4 shrink-0 items-center justify-center text-primary">
|
|
651
|
+
{selected ? <Icon name="check-checkmark" className="h-4 w-4" /> : null}
|
|
652
|
+
</span>
|
|
653
|
+
</button>
|
|
654
|
+
);
|
|
655
|
+
}
|