@designa8/vibedesign-v6 1.15.3 → 1.20.12
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/index.cjs +3232 -1994
- package/dist/index.js +3242 -2004
- package/dist/styles.css +266 -28
- package/package.json +51 -1
- package/src/atoms/AppLayout/AppLayout.tsx +401 -395
- package/src/atoms/AppLayout/preview.tsx +29 -0
- package/src/atoms/AppSidebar/AppSidebar.tsx +182 -94
- package/src/atoms/AppSidebar/preview.tsx +20 -59
- package/src/atoms/AppSidebarMobile/AppSidebarMobile.tsx +27 -73
- package/src/atoms/AppSidebarMobile/preview.tsx +18 -18
- package/src/atoms/AuthLogin/AuthLogin.tsx +200 -0
- package/src/atoms/AuthLogin/index.ts +2 -0
- package/src/atoms/AuthLogin/preview.tsx +22 -0
- package/src/atoms/AuthScreen/AuthScreen.tsx +7 -7
- package/src/atoms/AuthSignUp/AuthSignUp.tsx +243 -0
- package/src/atoms/AuthSignUp/index.ts +2 -0
- package/src/atoms/AuthSignUp/preview.tsx +22 -0
- package/src/atoms/BillingToggle/BillingToggle.tsx +65 -0
- package/src/atoms/BillingToggle/index.ts +2 -0
- package/src/atoms/BillingToggle/preview.tsx +23 -0
- package/src/atoms/Button/Button.tsx +33 -17
- package/src/atoms/Button/preview.tsx +16 -0
- package/src/atoms/ChatHistorySidebar/ChatHistorySidebar.tsx +370 -0
- package/src/atoms/ChatHistorySidebar/index.ts +2 -0
- package/src/atoms/ChatHistorySidebar/preview.tsx +60 -0
- package/src/atoms/ChatScreen/ChatScreen.tsx +331 -134
- package/src/atoms/ChatScreen/preview.tsx +123 -2
- package/src/atoms/Checkbox/Checkbox.tsx +89 -0
- package/src/atoms/Checkbox/index.ts +2 -0
- package/src/atoms/Checkbox/preview.tsx +60 -0
- package/src/atoms/Dropdown/Dropdown.tsx +195 -0
- package/src/atoms/Dropdown/index.ts +2 -0
- package/src/atoms/Dropdown/preview.tsx +56 -0
- package/src/atoms/FaqAccordionItem/FaqAccordionItem.tsx +60 -0
- package/src/atoms/FaqAccordionItem/index.ts +2 -0
- package/src/atoms/FaqAccordionItem/preview.tsx +26 -0
- package/src/atoms/FilterTabBar/FilterTabBar.tsx +8 -22
- package/src/atoms/HomePageTemplate/HomePageTemplate.tsx +20 -33
- package/src/atoms/HomePageTemplate/preview.tsx +2 -2
- package/src/atoms/Icon/Icon.tsx +7 -5
- package/src/atoms/Icon/icons.data.ts +51 -0
- package/src/atoms/Input/Input.tsx +17 -9
- package/src/atoms/Input/preview.tsx +24 -25
- package/src/atoms/Menu/Menu.tsx +320 -0
- package/src/atoms/Menu/index.ts +2 -0
- package/src/atoms/Menu/preview.tsx +63 -0
- package/src/atoms/Modal/Modal.tsx +43 -37
- package/src/atoms/Modal/preview.tsx +13 -0
- package/src/atoms/NavItem/NavItem.tsx +33 -45
- package/src/atoms/NavItem/preview.tsx +21 -26
- package/src/atoms/PreviewToolbar/PreviewToolbar.tsx +144 -192
- package/src/atoms/PreviewToolbar/preview.tsx +24 -4
- package/src/atoms/PricingCard/PricingCard.tsx +164 -0
- package/src/atoms/PricingCard/index.ts +2 -0
- package/src/atoms/PricingCard/preview.tsx +45 -0
- package/src/atoms/PricingPageTemplate/PricingPageTemplate.tsx +219 -0
- package/src/atoms/PricingPageTemplate/index.ts +2 -0
- package/src/atoms/PricingPageTemplate/preview.tsx +10 -0
- package/src/atoms/PromptInputBar/PromptInputBar.tsx +117 -158
- package/src/atoms/WorkspaceMenu/WorkspaceMenu.tsx +41 -167
- package/src/index.ts +10 -0
- package/src/tokens.css +5 -0
|
@@ -0,0 +1,320 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { createPortal } from "react-dom";
|
|
3
|
+
import { Button } from "../Button";
|
|
4
|
+
import { Icon } from "../Icon";
|
|
5
|
+
|
|
6
|
+
export interface MenuItem {
|
|
7
|
+
/** Stable identifier, also used as the React key */
|
|
8
|
+
id: string;
|
|
9
|
+
/** Visible label */
|
|
10
|
+
label: string;
|
|
11
|
+
/** Optional icon name resolved through the shared Icon atom, rendered as a leading prefix */
|
|
12
|
+
icon?: string;
|
|
13
|
+
/** Called when the item is chosen (click or Enter/Space while focused) */
|
|
14
|
+
onSelect?: () => void;
|
|
15
|
+
/** Disables the item */
|
|
16
|
+
disabled?: boolean;
|
|
17
|
+
/** Renders the item in the destructive (error) color */
|
|
18
|
+
destructive?: boolean;
|
|
19
|
+
/** Renders a hairline divider above this item */
|
|
20
|
+
withDividerBefore?: boolean;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export interface MenuProps extends React.HTMLAttributes<HTMLDivElement> {
|
|
24
|
+
/** Items rendered in the floating list, top to bottom */
|
|
25
|
+
items: MenuItem[];
|
|
26
|
+
/** Custom trigger element. When omitted, a default Button with `triggerLabel` is rendered */
|
|
27
|
+
trigger?: React.ReactNode;
|
|
28
|
+
/** Label for the default trigger button (ignored when `trigger` is provided) */
|
|
29
|
+
triggerLabel?: string;
|
|
30
|
+
/** Which edge of the trigger the menu is anchored to */
|
|
31
|
+
align?: "left" | "right";
|
|
32
|
+
/** Controlled open state */
|
|
33
|
+
open?: boolean;
|
|
34
|
+
/** Called whenever the menu requests an open/close state change */
|
|
35
|
+
onOpenChange?: (open: boolean) => void;
|
|
36
|
+
/** Uncontrolled initial open state (useful for previews) */
|
|
37
|
+
defaultOpen?: boolean;
|
|
38
|
+
/** Accessible label for the default trigger button */
|
|
39
|
+
"aria-label"?: string;
|
|
40
|
+
/**
|
|
41
|
+
* Renders the floating item list through a portal into `document.body`,
|
|
42
|
+
* positioned with `position: fixed` against the trigger's viewport
|
|
43
|
+
* coordinates instead of being absolutely positioned inside this
|
|
44
|
+
* component. Use this whenever the trigger lives inside an ancestor that
|
|
45
|
+
* clips overflow (`overflow-hidden`) or that animates/transforms — the
|
|
46
|
+
* default `absolute` list would otherwise be clipped or mis-positioned.
|
|
47
|
+
* Defaults to false.
|
|
48
|
+
*/
|
|
49
|
+
portal?: boolean;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
const CLOSE_ANIMATION_MS = 200;
|
|
53
|
+
|
|
54
|
+
export const Menu = React.forwardRef<HTMLDivElement, MenuProps>(
|
|
55
|
+
(
|
|
56
|
+
{
|
|
57
|
+
items,
|
|
58
|
+
trigger,
|
|
59
|
+
triggerLabel = "Options",
|
|
60
|
+
align = "left",
|
|
61
|
+
open: controlledOpen,
|
|
62
|
+
onOpenChange,
|
|
63
|
+
defaultOpen = false,
|
|
64
|
+
className,
|
|
65
|
+
"aria-label": ariaLabel,
|
|
66
|
+
portal = false,
|
|
67
|
+
...rest
|
|
68
|
+
},
|
|
69
|
+
ref
|
|
70
|
+
) => {
|
|
71
|
+
const isControlled = controlledOpen !== undefined;
|
|
72
|
+
const [uncontrolledOpen, setUncontrolledOpen] = React.useState(defaultOpen);
|
|
73
|
+
const open = isControlled ? (controlledOpen as boolean) : uncontrolledOpen;
|
|
74
|
+
|
|
75
|
+
// `mounted` keeps the list in the DOM through the close transition;
|
|
76
|
+
// `visible` drives the opacity/scale classes — mirrors the Modal pattern.
|
|
77
|
+
const [mounted, setMounted] = React.useState(open);
|
|
78
|
+
const [visible, setVisible] = React.useState(false);
|
|
79
|
+
|
|
80
|
+
const rootRef = React.useRef<HTMLDivElement>(null);
|
|
81
|
+
const triggerWrapRef = React.useRef<HTMLSpanElement>(null);
|
|
82
|
+
const listRef = React.useRef<HTMLDivElement>(null);
|
|
83
|
+
const itemRefs = React.useRef<Array<HTMLButtonElement | null>>([]);
|
|
84
|
+
const [highlighted, setHighlighted] = React.useState(-1);
|
|
85
|
+
const [coords, setCoords] = React.useState<{ top: number; left: number; right: number } | null>(null);
|
|
86
|
+
|
|
87
|
+
const setRefs = React.useCallback(
|
|
88
|
+
(node: HTMLDivElement | null) => {
|
|
89
|
+
(rootRef as React.MutableRefObject<HTMLDivElement | null>).current = node;
|
|
90
|
+
if (typeof ref === "function") ref(node);
|
|
91
|
+
else if (ref) (ref as React.MutableRefObject<HTMLDivElement | null>).current = node;
|
|
92
|
+
},
|
|
93
|
+
[ref]
|
|
94
|
+
);
|
|
95
|
+
|
|
96
|
+
const setOpen = React.useCallback(
|
|
97
|
+
(next: boolean) => {
|
|
98
|
+
if (!isControlled) setUncontrolledOpen(next);
|
|
99
|
+
onOpenChange?.(next);
|
|
100
|
+
},
|
|
101
|
+
[isControlled, onOpenChange]
|
|
102
|
+
);
|
|
103
|
+
|
|
104
|
+
const updateCoords = React.useCallback(() => {
|
|
105
|
+
const el = triggerWrapRef.current;
|
|
106
|
+
if (!el) return;
|
|
107
|
+
const rect = el.getBoundingClientRect();
|
|
108
|
+
setCoords({ top: rect.bottom + 4, left: rect.left, right: window.innerWidth - rect.right });
|
|
109
|
+
}, []);
|
|
110
|
+
|
|
111
|
+
// Mount-then-paint-then-fade, same double-rAF technique as Modal so the
|
|
112
|
+
// browser doesn't batch the initial + final opacity into one frame.
|
|
113
|
+
React.useEffect(() => {
|
|
114
|
+
if (open) {
|
|
115
|
+
if (portal) updateCoords();
|
|
116
|
+
setMounted(true);
|
|
117
|
+
const raf = requestAnimationFrame(() => {
|
|
118
|
+
requestAnimationFrame(() => setVisible(true));
|
|
119
|
+
});
|
|
120
|
+
return () => cancelAnimationFrame(raf);
|
|
121
|
+
}
|
|
122
|
+
setVisible(false);
|
|
123
|
+
const timer = window.setTimeout(() => setMounted(false), CLOSE_ANIMATION_MS);
|
|
124
|
+
return () => window.clearTimeout(timer);
|
|
125
|
+
}, [open, portal, updateCoords]);
|
|
126
|
+
|
|
127
|
+
React.useEffect(() => {
|
|
128
|
+
if (!open) return;
|
|
129
|
+
setHighlighted(-1);
|
|
130
|
+
const handlePointerDown = (e: PointerEvent) => {
|
|
131
|
+
const target = e.target as Node;
|
|
132
|
+
if (rootRef.current?.contains(target)) return;
|
|
133
|
+
if (portal && listRef.current?.contains(target)) return;
|
|
134
|
+
setOpen(false);
|
|
135
|
+
};
|
|
136
|
+
const handleKey = (e: KeyboardEvent) => {
|
|
137
|
+
if (e.key === "Escape") setOpen(false);
|
|
138
|
+
};
|
|
139
|
+
document.addEventListener("pointerdown", handlePointerDown);
|
|
140
|
+
document.addEventListener("keydown", handleKey);
|
|
141
|
+
if (portal) {
|
|
142
|
+
window.addEventListener("resize", updateCoords);
|
|
143
|
+
window.addEventListener("scroll", updateCoords, true);
|
|
144
|
+
}
|
|
145
|
+
return () => {
|
|
146
|
+
document.removeEventListener("pointerdown", handlePointerDown);
|
|
147
|
+
document.removeEventListener("keydown", handleKey);
|
|
148
|
+
if (portal) {
|
|
149
|
+
window.removeEventListener("resize", updateCoords);
|
|
150
|
+
window.removeEventListener("scroll", updateCoords, true);
|
|
151
|
+
}
|
|
152
|
+
};
|
|
153
|
+
}, [open, setOpen, portal, updateCoords]);
|
|
154
|
+
|
|
155
|
+
React.useEffect(() => {
|
|
156
|
+
if (highlighted >= 0) itemRefs.current[highlighted]?.focus();
|
|
157
|
+
}, [highlighted]);
|
|
158
|
+
|
|
159
|
+
const enabledIndexes = items
|
|
160
|
+
.map((item, idx) => (item.disabled ? -1 : idx))
|
|
161
|
+
.filter((idx) => idx >= 0);
|
|
162
|
+
|
|
163
|
+
const moveHighlight = (dir: 1 | -1) => {
|
|
164
|
+
if (enabledIndexes.length === 0) return;
|
|
165
|
+
const pos = enabledIndexes.indexOf(highlighted);
|
|
166
|
+
const nextPos =
|
|
167
|
+
pos === -1
|
|
168
|
+
? dir === 1
|
|
169
|
+
? 0
|
|
170
|
+
: enabledIndexes.length - 1
|
|
171
|
+
: (pos + dir + enabledIndexes.length) % enabledIndexes.length;
|
|
172
|
+
setHighlighted(enabledIndexes[nextPos]);
|
|
173
|
+
};
|
|
174
|
+
|
|
175
|
+
const handleTriggerKeyDown = (e: React.KeyboardEvent) => {
|
|
176
|
+
if (e.key === "ArrowDown" || e.key === "ArrowUp") {
|
|
177
|
+
e.preventDefault();
|
|
178
|
+
if (!open) setOpen(true);
|
|
179
|
+
moveHighlight(e.key === "ArrowDown" ? 1 : -1);
|
|
180
|
+
}
|
|
181
|
+
};
|
|
182
|
+
|
|
183
|
+
const handleListKeyDown = (e: React.KeyboardEvent) => {
|
|
184
|
+
if (e.key === "ArrowDown") {
|
|
185
|
+
e.preventDefault();
|
|
186
|
+
moveHighlight(1);
|
|
187
|
+
} else if (e.key === "ArrowUp") {
|
|
188
|
+
e.preventDefault();
|
|
189
|
+
moveHighlight(-1);
|
|
190
|
+
} else if (e.key === "Tab") {
|
|
191
|
+
setOpen(false);
|
|
192
|
+
}
|
|
193
|
+
};
|
|
194
|
+
|
|
195
|
+
const commit = (item: MenuItem) => {
|
|
196
|
+
if (item.disabled) return;
|
|
197
|
+
setOpen(false);
|
|
198
|
+
item.onSelect?.();
|
|
199
|
+
};
|
|
200
|
+
|
|
201
|
+
const listClassName = [
|
|
202
|
+
"z-10 mt-xs min-w-52 origin-top overflow-hidden rounded-md border border-hairline-soft bg-surface p-xxs shadow-card",
|
|
203
|
+
"transition-all duration-200 ease-in-out will-change-transform",
|
|
204
|
+
visible
|
|
205
|
+
? "pointer-events-auto opacity-100 translate-y-0 scale-100"
|
|
206
|
+
: "pointer-events-none opacity-0 -translate-y-1 scale-95",
|
|
207
|
+
].join(" ");
|
|
208
|
+
|
|
209
|
+
const listContent = mounted && (
|
|
210
|
+
<div
|
|
211
|
+
ref={(node) => {
|
|
212
|
+
(listRef as React.MutableRefObject<HTMLDivElement | null>).current = node;
|
|
213
|
+
setRefs(node);
|
|
214
|
+
}}
|
|
215
|
+
role="menu"
|
|
216
|
+
aria-label={ariaLabel ?? triggerLabel}
|
|
217
|
+
aria-hidden={!open}
|
|
218
|
+
onKeyDown={handleListKeyDown}
|
|
219
|
+
className={
|
|
220
|
+
portal
|
|
221
|
+
? ["fixed", listClassName, "!mt-0"].join(" ")
|
|
222
|
+
: ["absolute", listClassName, align === "right" ? "right-0" : "left-0"].join(" ")
|
|
223
|
+
}
|
|
224
|
+
style={
|
|
225
|
+
portal && coords
|
|
226
|
+
? {
|
|
227
|
+
top: coords.top,
|
|
228
|
+
...(align === "right" ? { right: coords.right } : { left: coords.left }),
|
|
229
|
+
zIndex: "var(--z-dropdown, 9999)",
|
|
230
|
+
}
|
|
231
|
+
: undefined
|
|
232
|
+
}
|
|
233
|
+
>
|
|
234
|
+
{items.map((item, idx) => (
|
|
235
|
+
<React.Fragment key={item.id}>
|
|
236
|
+
{item.withDividerBefore && <div className="my-xxs h-px bg-hairline-soft" />}
|
|
237
|
+
<Button
|
|
238
|
+
ref={(node) => {
|
|
239
|
+
itemRefs.current[idx] = node;
|
|
240
|
+
}}
|
|
241
|
+
type="button"
|
|
242
|
+
role="menuitem"
|
|
243
|
+
variant="bare"
|
|
244
|
+
size="auto"
|
|
245
|
+
pushEffect={false}
|
|
246
|
+
disabled={item.disabled}
|
|
247
|
+
tabIndex={-1}
|
|
248
|
+
onMouseEnter={() => setHighlighted(idx)}
|
|
249
|
+
onClick={() => commit(item)}
|
|
250
|
+
className={[
|
|
251
|
+
"!flex !w-full items-center !justify-start gap-sm rounded-sm px-sm py-sm text-left text-body-sm transition-colors",
|
|
252
|
+
item.disabled
|
|
253
|
+
? "cursor-not-allowed text-muted-soft"
|
|
254
|
+
: item.destructive
|
|
255
|
+
? "text-[var(--color-semantic-error)] hover:bg-surface-soft"
|
|
256
|
+
: "text-ink hover:bg-surface-soft",
|
|
257
|
+
idx === highlighted && !item.disabled ? "bg-surface-soft" : "",
|
|
258
|
+
].join(" ")}
|
|
259
|
+
>
|
|
260
|
+
{item.icon && (
|
|
261
|
+
<Icon
|
|
262
|
+
name={item.icon}
|
|
263
|
+
className={[
|
|
264
|
+
"size-4 shrink-0",
|
|
265
|
+
item.disabled ? "text-muted-soft" : item.destructive ? "text-[var(--color-semantic-error)]" : "text-muted",
|
|
266
|
+
].join(" ")}
|
|
267
|
+
/>
|
|
268
|
+
)}
|
|
269
|
+
<span className="flex-1 truncate">{item.label}</span>
|
|
270
|
+
</Button>
|
|
271
|
+
</React.Fragment>
|
|
272
|
+
))}
|
|
273
|
+
</div>
|
|
274
|
+
);
|
|
275
|
+
|
|
276
|
+
return (
|
|
277
|
+
<div
|
|
278
|
+
ref={portal ? rootRef : setRefs}
|
|
279
|
+
className={["relative inline-block", className].filter(Boolean).join(" ")}
|
|
280
|
+
{...rest}
|
|
281
|
+
>
|
|
282
|
+
<span ref={triggerWrapRef} onKeyDown={handleTriggerKeyDown}>
|
|
283
|
+
{trigger ? (
|
|
284
|
+
<span
|
|
285
|
+
onClick={() => setOpen(!open)}
|
|
286
|
+
aria-haspopup="menu"
|
|
287
|
+
aria-expanded={open}
|
|
288
|
+
role="button"
|
|
289
|
+
tabIndex={0}
|
|
290
|
+
>
|
|
291
|
+
{trigger}
|
|
292
|
+
</span>
|
|
293
|
+
) : (
|
|
294
|
+
<Button
|
|
295
|
+
type="button"
|
|
296
|
+
variant="secondary"
|
|
297
|
+
size="sm"
|
|
298
|
+
aria-haspopup="menu"
|
|
299
|
+
aria-expanded={open}
|
|
300
|
+
aria-label={ariaLabel ?? triggerLabel}
|
|
301
|
+
onClick={() => setOpen(!open)}
|
|
302
|
+
className="!gap-sm"
|
|
303
|
+
>
|
|
304
|
+
<span>{triggerLabel}</span>
|
|
305
|
+
<Icon
|
|
306
|
+
name="chevron-down"
|
|
307
|
+
className="size-4 shrink-0 transition-transform duration-180 ease-in-out"
|
|
308
|
+
style={{ transform: open ? "rotate(180deg)" : "rotate(0deg)" }}
|
|
309
|
+
/>
|
|
310
|
+
</Button>
|
|
311
|
+
)}
|
|
312
|
+
</span>
|
|
313
|
+
|
|
314
|
+
{portal ? (mounted && typeof document !== "undefined" ? createPortal(listContent, document.body) : null) : listContent}
|
|
315
|
+
</div>
|
|
316
|
+
);
|
|
317
|
+
}
|
|
318
|
+
);
|
|
319
|
+
|
|
320
|
+
Menu.displayName = "Menu";
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { Menu, type MenuItem } from "./Menu";
|
|
3
|
+
import { Button } from "../Button";
|
|
4
|
+
import { Icon } from "../Icon";
|
|
5
|
+
|
|
6
|
+
export default function MenuPreview() {
|
|
7
|
+
const [lastAction, setLastAction] = React.useState<string>("—");
|
|
8
|
+
|
|
9
|
+
const accountItems: MenuItem[] = [
|
|
10
|
+
{ id: "profile", label: "Profile", icon: "two-people-users-group", onSelect: () => setLastAction("Profile") },
|
|
11
|
+
{ id: "settings", label: "Settings", icon: "settings-gear", onSelect: () => setLastAction("Settings") },
|
|
12
|
+
{ id: "rename", label: "Rename", icon: "pencil-edit", onSelect: () => setLastAction("Rename") },
|
|
13
|
+
{ id: "logout", label: "Log out", icon: "logout-sign-out", onSelect: () => setLastAction("Log out"), withDividerBefore: true },
|
|
14
|
+
];
|
|
15
|
+
|
|
16
|
+
const fileItems: MenuItem[] = [
|
|
17
|
+
{ id: "open", label: "Open", icon: "folder", onSelect: () => setLastAction("Open") },
|
|
18
|
+
{ id: "star", label: "Star", icon: "star", onSelect: () => setLastAction("Star") },
|
|
19
|
+
{ id: "archive", label: "Archive", icon: "archive", disabled: true },
|
|
20
|
+
{ id: "delete", label: "Delete", icon: "trash-delete", destructive: true, onSelect: () => setLastAction("Delete"), withDividerBefore: true },
|
|
21
|
+
];
|
|
22
|
+
|
|
23
|
+
const [controlledOpen, setControlledOpen] = React.useState(false);
|
|
24
|
+
|
|
25
|
+
return (
|
|
26
|
+
<div className="w-full max-w-3xl mx-auto p-lg space-y-xl">
|
|
27
|
+
<p className="text-body-sm text-muted">
|
|
28
|
+
Last action: <span className="text-ink font-weight-heading-sm">{lastAction}</span>
|
|
29
|
+
</p>
|
|
30
|
+
|
|
31
|
+
<div className="flex flex-wrap items-start gap-xl">
|
|
32
|
+
<div className="space-y-sm">
|
|
33
|
+
<p className="text-caption uppercase tracking-wide text-muted-soft">Default trigger</p>
|
|
34
|
+
<Menu triggerLabel="Account" items={accountItems} />
|
|
35
|
+
</div>
|
|
36
|
+
|
|
37
|
+
<div className="space-y-sm">
|
|
38
|
+
<p className="text-caption uppercase tracking-wide text-muted-soft">Right-aligned, custom trigger</p>
|
|
39
|
+
<Menu
|
|
40
|
+
align="right"
|
|
41
|
+
items={fileItems}
|
|
42
|
+
aria-label="File actions"
|
|
43
|
+
trigger={
|
|
44
|
+
<Button variant="ghost" size="sm" aria-label="File actions" className="!px-xs">
|
|
45
|
+
<Icon name="more-options-vertical-dots" className="size-5" />
|
|
46
|
+
</Button>
|
|
47
|
+
}
|
|
48
|
+
/>
|
|
49
|
+
</div>
|
|
50
|
+
|
|
51
|
+
<div className="space-y-sm">
|
|
52
|
+
<p className="text-caption uppercase tracking-wide text-muted-soft">Controlled</p>
|
|
53
|
+
<Menu
|
|
54
|
+
triggerLabel={controlledOpen ? "Close menu" : "Open menu"}
|
|
55
|
+
items={accountItems}
|
|
56
|
+
open={controlledOpen}
|
|
57
|
+
onOpenChange={setControlledOpen}
|
|
58
|
+
/>
|
|
59
|
+
</div>
|
|
60
|
+
</div>
|
|
61
|
+
</div>
|
|
62
|
+
);
|
|
63
|
+
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import React, { useEffect, useRef, useState } from "react";
|
|
2
2
|
import { Button } from "../Button";
|
|
3
|
+
import { Icon } from "../Icon";
|
|
3
4
|
|
|
4
5
|
export interface ModalProps {
|
|
5
6
|
/** Controls whether the modal is visible */
|
|
@@ -12,11 +13,13 @@ export interface ModalProps {
|
|
|
12
13
|
children?: React.ReactNode;
|
|
13
14
|
/** Optional footer actions */
|
|
14
15
|
footer?: React.ReactNode;
|
|
15
|
-
/** Max-width variant
|
|
16
|
-
|
|
16
|
+
/** Max-width variant. "full" fills almost the entire viewport (e.g. for
|
|
17
|
+
* media/image viewers) and always shows a close control even without a
|
|
18
|
+
* title. */
|
|
19
|
+
size?: "sm" | "md" | "lg" | "xl" | "full";
|
|
17
20
|
}
|
|
18
21
|
|
|
19
|
-
const sizeMap: Record<
|
|
22
|
+
const sizeMap: Record<"sm" | "md" | "lg" | "xl", string> = {
|
|
20
23
|
sm: "max-w-sm",
|
|
21
24
|
md: "max-w-lg",
|
|
22
25
|
lg: "max-w-2xl",
|
|
@@ -29,6 +32,7 @@ export const Modal = React.forwardRef<HTMLDivElement, ModalProps>(
|
|
|
29
32
|
const [mounted, setMounted] = useState(false);
|
|
30
33
|
const [visible, setVisible] = useState(false);
|
|
31
34
|
const overlayRef = useRef<HTMLDivElement>(null);
|
|
35
|
+
const isFull = size === "full";
|
|
32
36
|
|
|
33
37
|
// Open: mount first, then trigger transition on the next frame
|
|
34
38
|
useEffect(() => {
|
|
@@ -64,6 +68,18 @@ export const Modal = React.forwardRef<HTMLDivElement, ModalProps>(
|
|
|
64
68
|
if (e.target === overlayRef.current) onClose();
|
|
65
69
|
};
|
|
66
70
|
|
|
71
|
+
const closeButton = (
|
|
72
|
+
<Button
|
|
73
|
+
variant="ghost"
|
|
74
|
+
size="sm"
|
|
75
|
+
aria-label="Close modal"
|
|
76
|
+
onClick={onClose}
|
|
77
|
+
className="!px-xs !py-xs"
|
|
78
|
+
>
|
|
79
|
+
<Icon name="close" />
|
|
80
|
+
</Button>
|
|
81
|
+
);
|
|
82
|
+
|
|
67
83
|
return (
|
|
68
84
|
<div
|
|
69
85
|
ref={overlayRef}
|
|
@@ -83,56 +99,46 @@ export const Modal = React.forwardRef<HTMLDivElement, ModalProps>(
|
|
|
83
99
|
from the page behind the scrim, especially in dark mode where
|
|
84
100
|
canvas and scrim are both near-black. A hairline border adds a
|
|
85
101
|
crisp edge since box-shadow alone reads as nearly invisible on
|
|
86
|
-
dark backgrounds. max-h-
|
|
87
|
-
|
|
88
|
-
|
|
102
|
+
dark backgrounds. Non-full sizes cap at max-h-full — since the
|
|
103
|
+
overlay is a fixed, viewport-sized flex container, a percentage
|
|
104
|
+
max-height resolves against its definite height, so content-heavy
|
|
105
|
+
modals never overflow. "full" instead drops the max-w/max-h caps
|
|
106
|
+
and takes almost the entire overlay so a high-resolution
|
|
107
|
+
object-contain image (or other full-bleed content) can fill the
|
|
108
|
+
viewport. The body's overflow-y-auto lets long content scroll
|
|
109
|
+
within whichever height applies. */}
|
|
89
110
|
<div
|
|
90
111
|
ref={ref}
|
|
91
112
|
className={[
|
|
92
|
-
"relative
|
|
113
|
+
"relative bg-surface border border-hairline rounded-lg",
|
|
93
114
|
"shadow-[0_8px_40px_0_rgba(0,0,0,0.18)]",
|
|
94
115
|
"flex flex-col overflow-hidden",
|
|
95
|
-
|
|
116
|
+
isFull
|
|
117
|
+
? "w-[calc(100%-2*var(--spacing-base))] h-[calc(100%-2*var(--spacing-base))] max-w-none max-h-none"
|
|
118
|
+
: `w-full max-h-full ${sizeMap[size as "sm" | "md" | "lg" | "xl"]}`,
|
|
96
119
|
"transition-all duration-250 ease-in-out",
|
|
97
120
|
visible
|
|
98
121
|
? "opacity-100 translate-y-0 scale-100"
|
|
99
122
|
: "opacity-0 translate-y-2 scale-95",
|
|
100
123
|
].join(" ")}
|
|
101
124
|
>
|
|
102
|
-
{/* Header
|
|
103
|
-
|
|
125
|
+
{/* Header — always shown for size="full" (even without a title)
|
|
126
|
+
so there's always a way to dismiss a near-viewport panel. */}
|
|
127
|
+
{(title || isFull) && (
|
|
104
128
|
<div className="flex items-center justify-between px-lg py-base border-b border-hairline">
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
className="!px-xs !py-xs"
|
|
114
|
-
>
|
|
115
|
-
<svg
|
|
116
|
-
xmlns="http://www.w3.org/2000/svg"
|
|
117
|
-
width="16"
|
|
118
|
-
height="16"
|
|
119
|
-
viewBox="0 0 24 24"
|
|
120
|
-
fill="none"
|
|
121
|
-
stroke="currentColor"
|
|
122
|
-
strokeWidth="2"
|
|
123
|
-
strokeLinecap="round"
|
|
124
|
-
strokeLinejoin="round"
|
|
125
|
-
aria-hidden="true"
|
|
126
|
-
>
|
|
127
|
-
<line x1="18" y1="6" x2="6" y2="18" />
|
|
128
|
-
<line x1="6" y1="6" x2="18" y2="18" />
|
|
129
|
-
</svg>
|
|
130
|
-
</Button>
|
|
129
|
+
{title ? (
|
|
130
|
+
<h2 id="modal-title" className="text-heading-sm text-ink">
|
|
131
|
+
{title}
|
|
132
|
+
</h2>
|
|
133
|
+
) : (
|
|
134
|
+
<span />
|
|
135
|
+
)}
|
|
136
|
+
{closeButton}
|
|
131
137
|
</div>
|
|
132
138
|
)}
|
|
133
139
|
|
|
134
140
|
{/* Body */}
|
|
135
|
-
<div className="flex-1 px-lg py-base text-body-md text-body overflow-y-auto">
|
|
141
|
+
<div className="flex-1 min-h-0 px-lg py-base text-body-md text-body overflow-y-auto">
|
|
136
142
|
{children}
|
|
137
143
|
</div>
|
|
138
144
|
|
|
@@ -6,6 +6,7 @@ export default function ModalPreview() {
|
|
|
6
6
|
const [basicOpen, setBasicOpen] = useState(false);
|
|
7
7
|
const [confirmOpen, setConfirmOpen] = useState(false);
|
|
8
8
|
const [largeOpen, setLargeOpen] = useState(false);
|
|
9
|
+
const [fullOpen, setFullOpen] = useState(false);
|
|
9
10
|
|
|
10
11
|
return (
|
|
11
12
|
<div className="w-full max-w-3xl mx-auto p-lg space-y-xl">
|
|
@@ -29,6 +30,9 @@ export default function ModalPreview() {
|
|
|
29
30
|
<Button variant="ghost" onClick={() => setLargeOpen(true)}>
|
|
30
31
|
Open large modal
|
|
31
32
|
</Button>
|
|
33
|
+
<Button variant="ghost" onClick={() => setFullOpen(true)}>
|
|
34
|
+
Open full-viewport modal
|
|
35
|
+
</Button>
|
|
32
36
|
</div>
|
|
33
37
|
|
|
34
38
|
{/* ── Basic modal ── */}
|
|
@@ -106,6 +110,15 @@ export default function ModalPreview() {
|
|
|
106
110
|
</div>
|
|
107
111
|
</div>
|
|
108
112
|
</Modal>
|
|
113
|
+
|
|
114
|
+
{/* ── Full-viewport modal (no title — close control still shows) ── */}
|
|
115
|
+
<Modal isOpen={fullOpen} onClose={() => setFullOpen(false)} size="full">
|
|
116
|
+
<div className="w-full h-full rounded-md bg-surface-soft border border-hairline flex items-center justify-center">
|
|
117
|
+
<span className="text-body-sm text-muted">
|
|
118
|
+
High-resolution image (object-contain) fills the viewer
|
|
119
|
+
</span>
|
|
120
|
+
</div>
|
|
121
|
+
</Modal>
|
|
109
122
|
</div>
|
|
110
123
|
);
|
|
111
124
|
}
|