@designa8/vibedesign-v6 1.15.3 → 1.20.13
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 +6 -32
- package/dist/index.cjs +3232 -2143
- package/dist/index.js +3242 -2153
- package/dist/styles.css +266 -28
- package/package.json +52 -2
- 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/ExportDesignMdModal/ExportDesignMdModal.tsx +46 -185
- package/src/atoms/ExportDesignMdModal/preview.tsx +24 -8
- 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 +53 -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
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
import React from "react";
|
|
2
2
|
import { ChatScreen, ChatMessage } from "./ChatScreen";
|
|
3
|
+
import { PromptInputBarModel } from "../PromptInputBar";
|
|
4
|
+
|
|
5
|
+
const DEMO_MODELS: PromptInputBarModel[] = [
|
|
6
|
+
{ id: "fast", name: "Fast", tier: "Standard", description: "Quick responses for everyday edits" },
|
|
7
|
+
{ id: "pro", name: "Pro", tier: "Pro", description: "Deeper reasoning for complex components" },
|
|
8
|
+
];
|
|
3
9
|
|
|
4
10
|
const messagesWithTimeline: ChatMessage[] = [
|
|
5
11
|
{
|
|
@@ -47,10 +53,125 @@ const messagesWithTimeline: ChatMessage[] = [
|
|
|
47
53
|
},
|
|
48
54
|
];
|
|
49
55
|
|
|
56
|
+
const messagesWithImages: ChatMessage[] = [
|
|
57
|
+
{
|
|
58
|
+
id: "1",
|
|
59
|
+
role: "user",
|
|
60
|
+
content: "Here's the hero shot for the landing page, can you match this look?",
|
|
61
|
+
userInitials: "ME",
|
|
62
|
+
images: [{ src: "https://picsum.photos/seed/hero1/800/500", alt: "Landing page hero reference" }],
|
|
63
|
+
},
|
|
64
|
+
{
|
|
65
|
+
id: "2",
|
|
66
|
+
role: "ai",
|
|
67
|
+
content: "Got it — matching the crop and spacing from that reference now.",
|
|
68
|
+
},
|
|
69
|
+
{
|
|
70
|
+
id: "3",
|
|
71
|
+
role: "user",
|
|
72
|
+
content: "",
|
|
73
|
+
userInitials: "ME",
|
|
74
|
+
images: [
|
|
75
|
+
{ src: "https://picsum.photos/seed/mosaic1/600/600", alt: "Screenshot 1" },
|
|
76
|
+
{ src: "https://picsum.photos/seed/mosaic2/600/600", alt: "Screenshot 2" },
|
|
77
|
+
{ src: "https://picsum.photos/seed/mosaic3/600/400", alt: "Screenshot 3" },
|
|
78
|
+
{ src: "https://picsum.photos/seed/mosaic4/600/400", alt: "Screenshot 4" },
|
|
79
|
+
],
|
|
80
|
+
},
|
|
81
|
+
{
|
|
82
|
+
id: "4",
|
|
83
|
+
role: "ai",
|
|
84
|
+
content: "Here are a few more style directions to compare side by side.",
|
|
85
|
+
images: [
|
|
86
|
+
{ src: "https://picsum.photos/seed/style1/600/600", alt: "Style 1" },
|
|
87
|
+
{ src: "https://picsum.photos/seed/style2/600/600", alt: "Style 2" },
|
|
88
|
+
{ src: "https://picsum.photos/seed/style3/600/400", alt: "Style 3" },
|
|
89
|
+
{ src: "https://picsum.photos/seed/style4/600/400", alt: "Style 4" },
|
|
90
|
+
{ src: "https://picsum.photos/seed/style5/600/400", alt: "Style 5" },
|
|
91
|
+
{ src: "https://picsum.photos/seed/style6/600/400", alt: "Style 6" },
|
|
92
|
+
],
|
|
93
|
+
},
|
|
94
|
+
];
|
|
95
|
+
|
|
96
|
+
const messagesWithSuggestions: ChatMessage[] = [
|
|
97
|
+
{
|
|
98
|
+
id: "1",
|
|
99
|
+
role: "user",
|
|
100
|
+
content: "Can you suggest a design for our new pricing page?",
|
|
101
|
+
userInitials: "ME",
|
|
102
|
+
},
|
|
103
|
+
{
|
|
104
|
+
id: "2",
|
|
105
|
+
role: "ai",
|
|
106
|
+
content: "Here's a mockup I put together for the pricing page:",
|
|
107
|
+
suggestedImage: {
|
|
108
|
+
src: "https://picsum.photos/seed/mockup1/900/600",
|
|
109
|
+
alt: "Pricing page mockup",
|
|
110
|
+
ctaLabel: "Create this design",
|
|
111
|
+
onCta: () => console.log("create single design"),
|
|
112
|
+
},
|
|
113
|
+
},
|
|
114
|
+
{
|
|
115
|
+
id: "3",
|
|
116
|
+
role: "user",
|
|
117
|
+
content: "Can I see a few options for the dashboard layout?",
|
|
118
|
+
userInitials: "ME",
|
|
119
|
+
},
|
|
120
|
+
{
|
|
121
|
+
id: "4",
|
|
122
|
+
role: "ai",
|
|
123
|
+
content: "Sure — here are three directions, tap the thumbnail to compare them full-screen:",
|
|
124
|
+
suggestedImage: {
|
|
125
|
+
src: "https://picsum.photos/seed/board1/900/600",
|
|
126
|
+
alt: "Dashboard layout options",
|
|
127
|
+
ctaLabel: "Create this design",
|
|
128
|
+
options: [
|
|
129
|
+
{ id: "opt-a", src: "https://picsum.photos/seed/optA/900/700", label: "Option A — Card grid" },
|
|
130
|
+
{ id: "opt-b", src: "https://picsum.photos/seed/optB/900/700", label: "Option B — Sidebar nav" },
|
|
131
|
+
{ id: "opt-c", src: "https://picsum.photos/seed/optC/900/700", label: "Option C — Split view" },
|
|
132
|
+
],
|
|
133
|
+
onSelectOption: (id) => console.log("selected design option", id),
|
|
134
|
+
},
|
|
135
|
+
},
|
|
136
|
+
];
|
|
137
|
+
|
|
50
138
|
export default function Preview() {
|
|
139
|
+
const [suggestDesigns1, setSuggestDesigns1] = React.useState(false);
|
|
140
|
+
const [suggestDesigns2, setSuggestDesigns2] = React.useState(false);
|
|
141
|
+
const [suggestDesigns3, setSuggestDesigns3] = React.useState(true);
|
|
142
|
+
|
|
51
143
|
return (
|
|
52
|
-
<div className="w-full max-w-3xl mx-auto"
|
|
53
|
-
<
|
|
144
|
+
<div className="w-full max-w-3xl mx-auto space-y-xl">
|
|
145
|
+
<div style={{ height: 640 }}>
|
|
146
|
+
<ChatScreen
|
|
147
|
+
messages={messagesWithTimeline}
|
|
148
|
+
placeholder="Ask anything…"
|
|
149
|
+
models={DEMO_MODELS}
|
|
150
|
+
selectedModelId="fast"
|
|
151
|
+
suggestDesigns={suggestDesigns1}
|
|
152
|
+
onSuggestDesignsChange={setSuggestDesigns1}
|
|
153
|
+
/>
|
|
154
|
+
</div>
|
|
155
|
+
<div style={{ height: 640 }}>
|
|
156
|
+
<ChatScreen
|
|
157
|
+
messages={messagesWithImages}
|
|
158
|
+
placeholder="Ask anything…"
|
|
159
|
+
models={DEMO_MODELS}
|
|
160
|
+
selectedModelId="pro"
|
|
161
|
+
suggestDesigns={suggestDesigns2}
|
|
162
|
+
onSuggestDesignsChange={setSuggestDesigns2}
|
|
163
|
+
/>
|
|
164
|
+
</div>
|
|
165
|
+
<div style={{ height: 640 }}>
|
|
166
|
+
<ChatScreen
|
|
167
|
+
messages={messagesWithSuggestions}
|
|
168
|
+
placeholder="Ask anything…"
|
|
169
|
+
models={DEMO_MODELS}
|
|
170
|
+
selectedModelId="fast"
|
|
171
|
+
suggestDesigns={suggestDesigns3}
|
|
172
|
+
onSuggestDesignsChange={setSuggestDesigns3}
|
|
173
|
+
/>
|
|
174
|
+
</div>
|
|
54
175
|
</div>
|
|
55
176
|
);
|
|
56
177
|
}
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import { Icon } from "../Icon";
|
|
3
|
+
|
|
4
|
+
export interface CheckboxProps
|
|
5
|
+
extends Omit<React.ComponentPropsWithoutRef<"input">, "size" | "type"> {
|
|
6
|
+
/** Visual size of the checkbox box. */
|
|
7
|
+
size?: "sm" | "md" | "lg";
|
|
8
|
+
/** Label text rendered next to the box. Omit for a bare checkbox. */
|
|
9
|
+
label?: string;
|
|
10
|
+
/** Additional helper/description text under the label. */
|
|
11
|
+
description?: string;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
const SIZE_BOX: Record<NonNullable<CheckboxProps["size"]>, string> = {
|
|
15
|
+
sm: "size-4",
|
|
16
|
+
md: "size-5",
|
|
17
|
+
lg: "size-6",
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
const SIZE_ICON: Record<NonNullable<CheckboxProps["size"]>, string> = {
|
|
21
|
+
sm: "size-3",
|
|
22
|
+
md: "size-3.5",
|
|
23
|
+
lg: "size-4",
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
const SIZE_LABEL: Record<NonNullable<CheckboxProps["size"]>, string> = {
|
|
27
|
+
sm: "text-body-sm",
|
|
28
|
+
md: "text-body-md",
|
|
29
|
+
lg: "text-body-md",
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
export const Checkbox = React.forwardRef<HTMLInputElement, CheckboxProps>(
|
|
33
|
+
(
|
|
34
|
+
{
|
|
35
|
+
size = "md",
|
|
36
|
+
label,
|
|
37
|
+
description,
|
|
38
|
+
className,
|
|
39
|
+
disabled,
|
|
40
|
+
id,
|
|
41
|
+
...props
|
|
42
|
+
},
|
|
43
|
+
ref
|
|
44
|
+
) => {
|
|
45
|
+
const generatedId = React.useId();
|
|
46
|
+
const inputId = id ?? generatedId;
|
|
47
|
+
|
|
48
|
+
return (
|
|
49
|
+
<label
|
|
50
|
+
htmlFor={inputId}
|
|
51
|
+
className={`inline-flex items-start gap-sm ${
|
|
52
|
+
disabled ? "cursor-not-allowed opacity-disabled" : "cursor-pointer"
|
|
53
|
+
} ${className ?? ""}`}
|
|
54
|
+
>
|
|
55
|
+
<span className="relative inline-flex shrink-0 items-center justify-center">
|
|
56
|
+
<input
|
|
57
|
+
ref={ref}
|
|
58
|
+
id={inputId}
|
|
59
|
+
type="checkbox"
|
|
60
|
+
disabled={disabled}
|
|
61
|
+
className="peer sr-only"
|
|
62
|
+
{...props}
|
|
63
|
+
/>
|
|
64
|
+
<span
|
|
65
|
+
aria-hidden="true"
|
|
66
|
+
className={`${SIZE_BOX[size]} inline-flex items-center justify-center rounded-xs border border-hairline-strong bg-canvas transition-colors peer-checked:border-primary peer-checked:bg-primary peer-focus-visible:outline peer-focus-visible:outline-2 peer-focus-visible:outline-offset-2 peer-focus-visible:outline-primary-focus peer-disabled:border-hairline peer-disabled:bg-surface-soft`}
|
|
67
|
+
>
|
|
68
|
+
<Icon
|
|
69
|
+
name="check-checkmark"
|
|
70
|
+
className={`${SIZE_ICON[size]} text-on-primary opacity-0 peer-checked:opacity-100 [.peer:checked~span_&]:opacity-100 scale-90 peer-checked:scale-100 transition-all`}
|
|
71
|
+
/>
|
|
72
|
+
</span>
|
|
73
|
+
</span>
|
|
74
|
+
{(label || description) && (
|
|
75
|
+
<span className="flex flex-col gap-xxs">
|
|
76
|
+
{label && (
|
|
77
|
+
<span className={`${SIZE_LABEL[size]} text-ink`}>{label}</span>
|
|
78
|
+
)}
|
|
79
|
+
{description && (
|
|
80
|
+
<span className="text-body-sm text-muted">{description}</span>
|
|
81
|
+
)}
|
|
82
|
+
</span>
|
|
83
|
+
)}
|
|
84
|
+
</label>
|
|
85
|
+
);
|
|
86
|
+
}
|
|
87
|
+
);
|
|
88
|
+
|
|
89
|
+
Checkbox.displayName = "Checkbox";
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import { Checkbox } from "./Checkbox";
|
|
3
|
+
|
|
4
|
+
export default function CheckboxPreview() {
|
|
5
|
+
const [subscribe, setSubscribe] = React.useState(true);
|
|
6
|
+
const [terms, setTerms] = React.useState(false);
|
|
7
|
+
const [notify, setNotify] = React.useState(false);
|
|
8
|
+
|
|
9
|
+
return (
|
|
10
|
+
<div className="w-full max-w-3xl mx-auto p-lg space-y-lg">
|
|
11
|
+
<div className="space-y-md">
|
|
12
|
+
<p className="text-caption uppercase tracking-wide text-muted">
|
|
13
|
+
Sizes
|
|
14
|
+
</p>
|
|
15
|
+
<div className="flex items-center gap-xl">
|
|
16
|
+
<Checkbox
|
|
17
|
+
size="sm"
|
|
18
|
+
label="Small"
|
|
19
|
+
checked={subscribe}
|
|
20
|
+
onChange={(e) => setSubscribe(e.target.checked)}
|
|
21
|
+
/>
|
|
22
|
+
<Checkbox
|
|
23
|
+
size="md"
|
|
24
|
+
label="Medium"
|
|
25
|
+
checked={terms}
|
|
26
|
+
onChange={(e) => setTerms(e.target.checked)}
|
|
27
|
+
/>
|
|
28
|
+
<Checkbox
|
|
29
|
+
size="lg"
|
|
30
|
+
label="Large"
|
|
31
|
+
checked={notify}
|
|
32
|
+
onChange={(e) => setNotify(e.target.checked)}
|
|
33
|
+
/>
|
|
34
|
+
</div>
|
|
35
|
+
</div>
|
|
36
|
+
|
|
37
|
+
<div className="space-y-md">
|
|
38
|
+
<p className="text-caption uppercase tracking-wide text-muted">
|
|
39
|
+
With description
|
|
40
|
+
</p>
|
|
41
|
+
<Checkbox
|
|
42
|
+
label="Email notifications"
|
|
43
|
+
description="Get notified when someone comments on your posts."
|
|
44
|
+
checked={notify}
|
|
45
|
+
onChange={(e) => setNotify(e.target.checked)}
|
|
46
|
+
/>
|
|
47
|
+
</div>
|
|
48
|
+
|
|
49
|
+
<div className="space-y-md">
|
|
50
|
+
<p className="text-caption uppercase tracking-wide text-muted">
|
|
51
|
+
Disabled
|
|
52
|
+
</p>
|
|
53
|
+
<div className="flex items-center gap-xl">
|
|
54
|
+
<Checkbox label="Disabled unchecked" disabled />
|
|
55
|
+
<Checkbox label="Disabled checked" disabled defaultChecked />
|
|
56
|
+
</div>
|
|
57
|
+
</div>
|
|
58
|
+
</div>
|
|
59
|
+
);
|
|
60
|
+
}
|
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import { Icon } from "../Icon";
|
|
3
|
+
import { Button } from "../Button";
|
|
4
|
+
|
|
5
|
+
export interface DropdownOption {
|
|
6
|
+
label: string;
|
|
7
|
+
value: string;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export interface DropdownProps {
|
|
11
|
+
/** Options rendered in the floating list. */
|
|
12
|
+
options: DropdownOption[];
|
|
13
|
+
/** Currently selected value. */
|
|
14
|
+
value?: string;
|
|
15
|
+
/** Placeholder shown when nothing is selected. */
|
|
16
|
+
placeholder?: string;
|
|
17
|
+
/** Called with the newly selected value. */
|
|
18
|
+
onChange?: (value: string) => void;
|
|
19
|
+
/** Disables the control entirely. */
|
|
20
|
+
disabled?: boolean;
|
|
21
|
+
/** Optional label rendered above the trigger. */
|
|
22
|
+
label?: string;
|
|
23
|
+
/** Extra classes on the root element. */
|
|
24
|
+
className?: string;
|
|
25
|
+
id?: string;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export const Dropdown = React.forwardRef<HTMLDivElement, DropdownProps>(
|
|
29
|
+
(
|
|
30
|
+
{
|
|
31
|
+
options,
|
|
32
|
+
value,
|
|
33
|
+
placeholder = "Selected option",
|
|
34
|
+
onChange,
|
|
35
|
+
disabled = false,
|
|
36
|
+
label,
|
|
37
|
+
className = "",
|
|
38
|
+
id,
|
|
39
|
+
},
|
|
40
|
+
ref
|
|
41
|
+
) => {
|
|
42
|
+
const [open, setOpen] = React.useState(false);
|
|
43
|
+
const [highlighted, setHighlighted] = React.useState<number>(-1);
|
|
44
|
+
const rootRef = React.useRef<HTMLDivElement>(null);
|
|
45
|
+
const listRef = React.useRef<HTMLUListElement>(null);
|
|
46
|
+
const reactId = React.useId();
|
|
47
|
+
const triggerId = id ?? `dropdown-${reactId}`;
|
|
48
|
+
const listboxId = `${triggerId}-listbox`;
|
|
49
|
+
|
|
50
|
+
const selectedOption = options.find((o) => o.value === value);
|
|
51
|
+
|
|
52
|
+
React.useImperativeHandle(ref, () => rootRef.current as HTMLDivElement);
|
|
53
|
+
|
|
54
|
+
React.useEffect(() => {
|
|
55
|
+
if (!open) return;
|
|
56
|
+
const handlePointerDown = (e: PointerEvent) => {
|
|
57
|
+
if (!rootRef.current?.contains(e.target as Node)) {
|
|
58
|
+
setOpen(false);
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
document.addEventListener("pointerdown", handlePointerDown);
|
|
62
|
+
return () => document.removeEventListener("pointerdown", handlePointerDown);
|
|
63
|
+
}, [open]);
|
|
64
|
+
|
|
65
|
+
const openList = () => {
|
|
66
|
+
if (disabled) return;
|
|
67
|
+
const idx = options.findIndex((o) => o.value === value);
|
|
68
|
+
setHighlighted(idx >= 0 ? idx : 0);
|
|
69
|
+
setOpen(true);
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
const closeList = () => setOpen(false);
|
|
73
|
+
|
|
74
|
+
const commit = (idx: number) => {
|
|
75
|
+
const opt = options[idx];
|
|
76
|
+
if (!opt) return;
|
|
77
|
+
onChange?.(opt.value);
|
|
78
|
+
closeList();
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
const handleTriggerKeyDown = (e: React.KeyboardEvent) => {
|
|
82
|
+
if (disabled) return;
|
|
83
|
+
if (!open && (e.key === "ArrowDown" || e.key === "ArrowUp" || e.key === "Enter" || e.key === " ")) {
|
|
84
|
+
e.preventDefault();
|
|
85
|
+
openList();
|
|
86
|
+
return;
|
|
87
|
+
}
|
|
88
|
+
if (open) {
|
|
89
|
+
if (e.key === "ArrowDown") {
|
|
90
|
+
e.preventDefault();
|
|
91
|
+
setHighlighted((h) => Math.min(h + 1, options.length - 1));
|
|
92
|
+
} else if (e.key === "ArrowUp") {
|
|
93
|
+
e.preventDefault();
|
|
94
|
+
setHighlighted((h) => Math.max(h - 1, 0));
|
|
95
|
+
} else if (e.key === "Enter" || e.key === " ") {
|
|
96
|
+
e.preventDefault();
|
|
97
|
+
commit(highlighted);
|
|
98
|
+
} else if (e.key === "Escape") {
|
|
99
|
+
e.preventDefault();
|
|
100
|
+
closeList();
|
|
101
|
+
} else if (e.key === "Tab") {
|
|
102
|
+
closeList();
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
};
|
|
106
|
+
|
|
107
|
+
return (
|
|
108
|
+
<div ref={rootRef} className={`relative w-full ${className}`}>
|
|
109
|
+
{label ? (
|
|
110
|
+
<label
|
|
111
|
+
htmlFor={triggerId}
|
|
112
|
+
className="mb-xs block text-caption font-weight-caption uppercase tracking-wide text-muted"
|
|
113
|
+
>
|
|
114
|
+
{label}
|
|
115
|
+
</label>
|
|
116
|
+
) : null}
|
|
117
|
+
|
|
118
|
+
<Button
|
|
119
|
+
type="button"
|
|
120
|
+
id={triggerId}
|
|
121
|
+
role="combobox"
|
|
122
|
+
aria-haspopup="listbox"
|
|
123
|
+
aria-expanded={open}
|
|
124
|
+
aria-controls={listboxId}
|
|
125
|
+
disabled={disabled}
|
|
126
|
+
onClick={() => (open ? closeList() : openList())}
|
|
127
|
+
onKeyDown={handleTriggerKeyDown}
|
|
128
|
+
variant="bare"
|
|
129
|
+
size="auto"
|
|
130
|
+
pushEffect={false}
|
|
131
|
+
className={[
|
|
132
|
+
"w-full justify-between rounded-lg border px-base py-sm text-body-md",
|
|
133
|
+
disabled
|
|
134
|
+
? "cursor-not-allowed border-hairline-soft bg-surface-soft text-muted-soft"
|
|
135
|
+
: open
|
|
136
|
+
? "border-primary bg-surface-soft text-ink ring-2 ring-primary-focus"
|
|
137
|
+
: "border-hairline bg-surface-soft text-ink hover:border-hairline-strong",
|
|
138
|
+
].join(" ")}
|
|
139
|
+
>
|
|
140
|
+
<span className={selectedOption ? "text-ink" : "text-muted"}>
|
|
141
|
+
{selectedOption ? selectedOption.label : placeholder}
|
|
142
|
+
</span>
|
|
143
|
+
<span
|
|
144
|
+
className={[
|
|
145
|
+
"flex size-7 shrink-0 items-center justify-center rounded-full",
|
|
146
|
+
disabled ? "bg-surface-strong" : open ? "bg-primary-focus/15" : "bg-surface-strong",
|
|
147
|
+
].join(" ")}
|
|
148
|
+
>
|
|
149
|
+
<Icon
|
|
150
|
+
name="chevron-down"
|
|
151
|
+
className={[
|
|
152
|
+
"size-4 shrink-0 transition-transform duration-150",
|
|
153
|
+
disabled ? "text-muted-soft" : "text-ink",
|
|
154
|
+
open ? "rotate-180" : "rotate-0",
|
|
155
|
+
].join(" ")}
|
|
156
|
+
/>
|
|
157
|
+
</span>
|
|
158
|
+
</Button>
|
|
159
|
+
|
|
160
|
+
{open && !disabled ? (
|
|
161
|
+
<ul
|
|
162
|
+
ref={listRef}
|
|
163
|
+
id={listboxId}
|
|
164
|
+
role="listbox"
|
|
165
|
+
aria-labelledby={triggerId}
|
|
166
|
+
className="absolute left-0 right-0 top-[calc(100%+8px)] z-10 max-h-64 overflow-auto rounded-lg border border-hairline-soft bg-canvas p-xs shadow-card"
|
|
167
|
+
>
|
|
168
|
+
{options.map((opt, idx) => {
|
|
169
|
+
const isSelected = opt.value === value;
|
|
170
|
+
const isHighlighted = idx === highlighted;
|
|
171
|
+
return (
|
|
172
|
+
<li
|
|
173
|
+
key={opt.value}
|
|
174
|
+
role="option"
|
|
175
|
+
aria-selected={isSelected}
|
|
176
|
+
onMouseEnter={() => setHighlighted(idx)}
|
|
177
|
+
onClick={() => commit(idx)}
|
|
178
|
+
className={[
|
|
179
|
+
"flex cursor-pointer items-center justify-between gap-sm rounded-md px-sm py-sm text-body-md text-ink transition-colors",
|
|
180
|
+
isHighlighted ? "bg-surface-soft" : "bg-transparent",
|
|
181
|
+
].join(" ")}
|
|
182
|
+
>
|
|
183
|
+
<span>{opt.label}</span>
|
|
184
|
+
{isSelected ? <Icon name="check-checkmark" className="size-4 shrink-0 text-primary" /> : null}
|
|
185
|
+
</li>
|
|
186
|
+
);
|
|
187
|
+
})}
|
|
188
|
+
</ul>
|
|
189
|
+
) : null}
|
|
190
|
+
</div>
|
|
191
|
+
);
|
|
192
|
+
}
|
|
193
|
+
);
|
|
194
|
+
|
|
195
|
+
Dropdown.displayName = "Dropdown";
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import { Dropdown } from "./Dropdown";
|
|
3
|
+
|
|
4
|
+
const OPTIONS = [
|
|
5
|
+
{ label: "Option one", value: "one" },
|
|
6
|
+
{ label: "Option two", value: "two" },
|
|
7
|
+
{ label: "Option three", value: "three" },
|
|
8
|
+
{ label: "Option four", value: "four" },
|
|
9
|
+
];
|
|
10
|
+
|
|
11
|
+
const CREDIT_OPTIONS = [
|
|
12
|
+
{ label: "100 credits", value: "100", meta: "$25 /mo" },
|
|
13
|
+
{ label: "200 credits", value: "200", meta: "$50 /mo" },
|
|
14
|
+
{ label: "1,200 credits", value: "1200", meta: "$294 /mo", badge: "Save 2%" },
|
|
15
|
+
{ label: "2,000 credits", value: "2000", meta: "$480 /mo", badge: "Save 4%" },
|
|
16
|
+
];
|
|
17
|
+
|
|
18
|
+
export default function DropdownPreview() {
|
|
19
|
+
const [defaultValue, setDefaultValue] = React.useState<string | undefined>(undefined);
|
|
20
|
+
const [openValue, setOpenValue] = React.useState<string | undefined>("two");
|
|
21
|
+
const [selectedValue, setSelectedValue] = React.useState<string | undefined>("three");
|
|
22
|
+
const [creditValue, setCreditValue] = React.useState<string>("100");
|
|
23
|
+
|
|
24
|
+
return (
|
|
25
|
+
<div className="w-full max-w-3xl mx-auto p-lg space-y-xl">
|
|
26
|
+
<div>
|
|
27
|
+
<p className="mb-xs text-caption font-weight-caption uppercase tracking-wide text-muted">Default</p>
|
|
28
|
+
<Dropdown options={OPTIONS} value={defaultValue} onChange={setDefaultValue} />
|
|
29
|
+
</div>
|
|
30
|
+
|
|
31
|
+
<div>
|
|
32
|
+
<p className="mb-xs text-caption font-weight-caption uppercase tracking-wide text-muted">
|
|
33
|
+
Interactive (try selecting an option)
|
|
34
|
+
</p>
|
|
35
|
+
<Dropdown options={OPTIONS} value={openValue} onChange={setOpenValue} />
|
|
36
|
+
</div>
|
|
37
|
+
|
|
38
|
+
<div>
|
|
39
|
+
<p className="mb-xs text-caption font-weight-caption uppercase tracking-wide text-muted">Pre-selected</p>
|
|
40
|
+
<Dropdown options={OPTIONS} value={selectedValue} onChange={setSelectedValue} />
|
|
41
|
+
</div>
|
|
42
|
+
|
|
43
|
+
<div>
|
|
44
|
+
<p className="mb-xs text-caption font-weight-caption uppercase tracking-wide text-muted">
|
|
45
|
+
Rich rows (badge + meta), e.g. a credits picker
|
|
46
|
+
</p>
|
|
47
|
+
<Dropdown options={CREDIT_OPTIONS} value={creditValue} onChange={setCreditValue} />
|
|
48
|
+
</div>
|
|
49
|
+
|
|
50
|
+
<div>
|
|
51
|
+
<p className="mb-xs text-caption font-weight-caption uppercase tracking-wide text-muted">Disabled</p>
|
|
52
|
+
<Dropdown options={OPTIONS} value={undefined} disabled />
|
|
53
|
+
</div>
|
|
54
|
+
</div>
|
|
55
|
+
);
|
|
56
|
+
}
|