@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,243 @@
|
|
|
1
|
+
import React, { useState, useId } from "react";
|
|
2
|
+
import { Button } from "../Button";
|
|
3
|
+
import { Input } from "../Input";
|
|
4
|
+
import { Icon } from "../Icon";
|
|
5
|
+
|
|
6
|
+
export interface AuthSignUpProps {
|
|
7
|
+
onSignup?: (values: { email: string; password: string }) => void;
|
|
8
|
+
onGoogleAuth?: () => void;
|
|
9
|
+
onSwitchToLogin?: () => void;
|
|
10
|
+
loading?: boolean;
|
|
11
|
+
/** Server-side error (e.g. duplicate email). When set, takes precedence over local validation messages. */
|
|
12
|
+
error?: string;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
interface FieldErrors {
|
|
16
|
+
email?: string;
|
|
17
|
+
password?: string;
|
|
18
|
+
confirm?: string;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
const EMAIL_PATTERN = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Google's brand mark is a fixed four-color logo — it cannot be represented by the
|
|
25
|
+
* design system's single-color Icon registry, so it is intentionally inlined here
|
|
26
|
+
* rather than resolved via `<Icon name="google" />`.
|
|
27
|
+
*/
|
|
28
|
+
const GoogleLogo = () => (
|
|
29
|
+
<svg aria-hidden="true" width="18" height="18" viewBox="0 0 24 24" className="shrink-0">
|
|
30
|
+
<path
|
|
31
|
+
d="M22.56 12.25c0-.78-.07-1.53-.2-2.25H12v4.26h5.92c-.26 1.37-1.04 2.53-2.21 3.31v2.77h3.57c2.08-1.92 3.28-4.74 3.28-8.09z"
|
|
32
|
+
fill="var(--color-google-blue)"
|
|
33
|
+
/>
|
|
34
|
+
<path
|
|
35
|
+
d="M12 23c2.97 0 5.46-.98 7.28-2.66l-3.57-2.77c-.98.66-2.23 1.06-3.71 1.06-2.86 0-5.29-1.93-6.16-4.53H2.18v2.84C3.99 20.53 7.7 23 12 23z"
|
|
36
|
+
fill="var(--color-google-green)"
|
|
37
|
+
/>
|
|
38
|
+
<path
|
|
39
|
+
d="M5.84 14.09c-.22-.66-.35-1.36-.35-2.09s.13-1.43.35-2.09V7.07H2.18C1.43 8.55 1 10.22 1 12s.43 3.45 1.18 4.93l3.66-2.84z"
|
|
40
|
+
fill="var(--color-google-yellow)"
|
|
41
|
+
/>
|
|
42
|
+
<path
|
|
43
|
+
d="M12 5.38c1.62 0 3.06.56 4.21 1.64l3.15-3.15C17.45 2.09 14.97 1 12 1 7.7 1 3.99 3.47 2.18 7.07l3.66 2.84c.87-2.6 3.3-4.53 6.16-4.53z"
|
|
44
|
+
fill="var(--color-google-red)"
|
|
45
|
+
/>
|
|
46
|
+
</svg>
|
|
47
|
+
);
|
|
48
|
+
|
|
49
|
+
export const AuthSignUp = React.forwardRef<HTMLDivElement, AuthSignUpProps>(
|
|
50
|
+
({ onSignup, onGoogleAuth, onSwitchToLogin, loading = false, error }, ref) => {
|
|
51
|
+
const [email, setEmail] = useState("");
|
|
52
|
+
const [password, setPassword] = useState("");
|
|
53
|
+
const [confirm, setConfirm] = useState("");
|
|
54
|
+
const [showPassword, setShowPassword] = useState(false);
|
|
55
|
+
const [fieldErrors, setFieldErrors] = useState<FieldErrors>({});
|
|
56
|
+
|
|
57
|
+
const emailId = useId();
|
|
58
|
+
const passwordId = useId();
|
|
59
|
+
const confirmId = useId();
|
|
60
|
+
|
|
61
|
+
const labelCls = "block text-body-sm font-weight-heading-sm text-ink mb-xs";
|
|
62
|
+
|
|
63
|
+
const validate = (): FieldErrors => {
|
|
64
|
+
const errors: FieldErrors = {};
|
|
65
|
+
const trimmedEmail = email.trim();
|
|
66
|
+
|
|
67
|
+
if (!trimmedEmail) {
|
|
68
|
+
errors.email = "Email is required.";
|
|
69
|
+
} else if (trimmedEmail.length > 320) {
|
|
70
|
+
errors.email = "Email must be 320 characters or fewer.";
|
|
71
|
+
} else if (!EMAIL_PATTERN.test(trimmedEmail)) {
|
|
72
|
+
errors.email = "Enter a valid email address.";
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
if (!password) {
|
|
76
|
+
errors.password = "Password is required.";
|
|
77
|
+
} else if (password.length < 8) {
|
|
78
|
+
errors.password = "Password must be at least 8 characters.";
|
|
79
|
+
} else if (password.length > 200) {
|
|
80
|
+
errors.password = "Password must be 200 characters or fewer.";
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
if (!confirm) {
|
|
84
|
+
errors.confirm = "Please confirm your password.";
|
|
85
|
+
} else if (confirm !== password) {
|
|
86
|
+
errors.confirm = "Passwords do not match.";
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
return errors;
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
const handleSubmit = (e: React.FormEvent) => {
|
|
93
|
+
e.preventDefault();
|
|
94
|
+
const errors = validate();
|
|
95
|
+
setFieldErrors(errors);
|
|
96
|
+
if (Object.keys(errors).length > 0) return;
|
|
97
|
+
onSignup?.({ email: email.trim(), password });
|
|
98
|
+
};
|
|
99
|
+
|
|
100
|
+
const passwordToggle = (
|
|
101
|
+
<Button
|
|
102
|
+
type="button"
|
|
103
|
+
variant="ghost"
|
|
104
|
+
size="sm"
|
|
105
|
+
aria-label={showPassword ? "Hide password" : "Show password"}
|
|
106
|
+
aria-pressed={showPassword}
|
|
107
|
+
onClick={() => setShowPassword((v) => !v)}
|
|
108
|
+
className="pointer-events-auto p-0 h-auto min-w-0 border-transparent bg-transparent text-muted hover:text-ink hover:bg-transparent"
|
|
109
|
+
>
|
|
110
|
+
<Icon name={showPassword ? "eye-off-hide-password" : "eye-show-password"} size={18} />
|
|
111
|
+
</Button>
|
|
112
|
+
);
|
|
113
|
+
|
|
114
|
+
return (
|
|
115
|
+
/* Full-width page background — fills the column height, form block centered vertically */
|
|
116
|
+
<div ref={ref} className="min-h-full w-full bg-surface p-xl flex flex-col justify-center">
|
|
117
|
+
{/* Center column — limits content width on ultra-wide screens */}
|
|
118
|
+
<div className="w-full max-w-3xl mx-auto flex justify-center">
|
|
119
|
+
{/* Signup card */}
|
|
120
|
+
<div style={{ width: "min(100%, 24rem)" }} className="text-center">
|
|
121
|
+
{/* Heading */}
|
|
122
|
+
<h1 className="mb-xs text-heading-lg text-ink font-weight-heading-lg">
|
|
123
|
+
Create an account
|
|
124
|
+
</h1>
|
|
125
|
+
<p className="mb-xl text-body-md text-muted">
|
|
126
|
+
Start building amazing systems.
|
|
127
|
+
</p>
|
|
128
|
+
|
|
129
|
+
{/* OAuth */}
|
|
130
|
+
<div className="space-y-sm text-left">
|
|
131
|
+
<Button
|
|
132
|
+
type="button"
|
|
133
|
+
variant="secondary"
|
|
134
|
+
size="lg"
|
|
135
|
+
className="w-full justify-center"
|
|
136
|
+
onClick={onGoogleAuth}
|
|
137
|
+
>
|
|
138
|
+
<GoogleLogo />
|
|
139
|
+
Continue with Google
|
|
140
|
+
</Button>
|
|
141
|
+
</div>
|
|
142
|
+
|
|
143
|
+
{/* Divider */}
|
|
144
|
+
<div className="my-xl flex items-center gap-base">
|
|
145
|
+
<div className="h-px flex-1 bg-hairline" />
|
|
146
|
+
<span className="text-body-sm text-muted-soft">or</span>
|
|
147
|
+
<div className="h-px flex-1 bg-hairline" />
|
|
148
|
+
</div>
|
|
149
|
+
|
|
150
|
+
{/* Form */}
|
|
151
|
+
<form onSubmit={handleSubmit} noValidate className="space-y-base text-left">
|
|
152
|
+
<div>
|
|
153
|
+
<label htmlFor={emailId} className={labelCls}>Email</label>
|
|
154
|
+
<Input
|
|
155
|
+
id={emailId}
|
|
156
|
+
type="email"
|
|
157
|
+
autoComplete="email"
|
|
158
|
+
required
|
|
159
|
+
size="lg"
|
|
160
|
+
placeholder="you@company.com"
|
|
161
|
+
value={email}
|
|
162
|
+
onChange={(e) => setEmail(e.target.value)}
|
|
163
|
+
leadingIcon={<Icon name="inbox-mail-tray" size={18} />}
|
|
164
|
+
error={fieldErrors.email}
|
|
165
|
+
fullWidth
|
|
166
|
+
/>
|
|
167
|
+
</div>
|
|
168
|
+
|
|
169
|
+
<div>
|
|
170
|
+
<label htmlFor={passwordId} className={labelCls}>Password</label>
|
|
171
|
+
<Input
|
|
172
|
+
id={passwordId}
|
|
173
|
+
type={showPassword ? "text" : "password"}
|
|
174
|
+
required
|
|
175
|
+
size="lg"
|
|
176
|
+
autoComplete="new-password"
|
|
177
|
+
placeholder="••••••••"
|
|
178
|
+
value={password}
|
|
179
|
+
onChange={(e) => setPassword(e.target.value)}
|
|
180
|
+
leadingIcon={<Icon name="lock-padlock" size={18} />}
|
|
181
|
+
trailingIcon={passwordToggle}
|
|
182
|
+
error={fieldErrors.password}
|
|
183
|
+
fullWidth
|
|
184
|
+
/>
|
|
185
|
+
</div>
|
|
186
|
+
|
|
187
|
+
<div>
|
|
188
|
+
<label htmlFor={confirmId} className={labelCls}>Confirm password</label>
|
|
189
|
+
<Input
|
|
190
|
+
id={confirmId}
|
|
191
|
+
type={showPassword ? "text" : "password"}
|
|
192
|
+
autoComplete="new-password"
|
|
193
|
+
required
|
|
194
|
+
size="lg"
|
|
195
|
+
placeholder="••••••••"
|
|
196
|
+
value={confirm}
|
|
197
|
+
onChange={(e) => setConfirm(e.target.value)}
|
|
198
|
+
leadingIcon={<Icon name="lock-padlock" size={18} />}
|
|
199
|
+
trailingIcon={passwordToggle}
|
|
200
|
+
error={fieldErrors.confirm}
|
|
201
|
+
fullWidth
|
|
202
|
+
/>
|
|
203
|
+
</div>
|
|
204
|
+
|
|
205
|
+
{error && (
|
|
206
|
+
<p role="alert" className="rounded-md px-base py-sm text-body-sm text-semantic-error">
|
|
207
|
+
{error}
|
|
208
|
+
</p>
|
|
209
|
+
)}
|
|
210
|
+
|
|
211
|
+
<Button
|
|
212
|
+
type="submit"
|
|
213
|
+
variant="primary"
|
|
214
|
+
size="lg"
|
|
215
|
+
loading={loading}
|
|
216
|
+
disabled={loading}
|
|
217
|
+
className="w-full border-none"
|
|
218
|
+
style={{
|
|
219
|
+
backgroundImage: "linear-gradient(135deg, var(--color-primary), var(--color-primary-hover))",
|
|
220
|
+
}}
|
|
221
|
+
>
|
|
222
|
+
{loading ? "Please wait…" : "Create account"}
|
|
223
|
+
</Button>
|
|
224
|
+
</form>
|
|
225
|
+
|
|
226
|
+
{/* Footer */}
|
|
227
|
+
<p className="mt-xl text-body-sm text-muted">
|
|
228
|
+
Already have an account?{" "}
|
|
229
|
+
<Button type="button" variant="ghost" size="sm"
|
|
230
|
+
onClick={onSwitchToLogin}
|
|
231
|
+
style={{ whiteSpace: "normal" }}
|
|
232
|
+
className="text-primary hover:underline bg-transparent border-transparent p-0 h-auto">
|
|
233
|
+
Log in
|
|
234
|
+
</Button>
|
|
235
|
+
</p>
|
|
236
|
+
</div>
|
|
237
|
+
</div>
|
|
238
|
+
</div>
|
|
239
|
+
);
|
|
240
|
+
}
|
|
241
|
+
);
|
|
242
|
+
|
|
243
|
+
AuthSignUp.displayName = "AuthSignUp";
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import React, { useState } from "react";
|
|
2
|
+
import { AuthSignUp } from "./AuthSignUp";
|
|
3
|
+
|
|
4
|
+
export default function AuthSignUpPreview() {
|
|
5
|
+
const [loading, setLoading] = useState(false);
|
|
6
|
+
|
|
7
|
+
const handleSignup = () => {
|
|
8
|
+
setLoading(true);
|
|
9
|
+
setTimeout(() => setLoading(false), 1200);
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
return (
|
|
13
|
+
<div className="w-full max-w-3xl mx-auto">
|
|
14
|
+
<AuthSignUp
|
|
15
|
+
loading={loading}
|
|
16
|
+
onSignup={handleSignup}
|
|
17
|
+
onGoogleAuth={() => alert("Continue with Google")}
|
|
18
|
+
onSwitchToLogin={() => alert("Navigate to log in")}
|
|
19
|
+
/>
|
|
20
|
+
</div>
|
|
21
|
+
);
|
|
22
|
+
}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { Chip } from "../Chip";
|
|
3
|
+
|
|
4
|
+
export type BillingPeriod = "monthly" | "yearly";
|
|
5
|
+
|
|
6
|
+
export interface BillingToggleProps
|
|
7
|
+
extends Omit<React.HTMLAttributes<HTMLDivElement>, "onChange"> {
|
|
8
|
+
/** Currently selected billing period. */
|
|
9
|
+
value: BillingPeriod;
|
|
10
|
+
/** Called when the user picks a different period. */
|
|
11
|
+
onChange: (value: BillingPeriod) => void;
|
|
12
|
+
/** Label shown on the yearly savings chip. Set to null to hide it. */
|
|
13
|
+
savingsLabel?: string | null;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export const BillingToggle = React.forwardRef<HTMLDivElement, BillingToggleProps>(
|
|
17
|
+
({ value, onChange, savingsLabel = "Save 20%", className, ...rest }, ref) => {
|
|
18
|
+
const options: { id: BillingPeriod; label: string }[] = [
|
|
19
|
+
{ id: "monthly", label: "Pay monthly" },
|
|
20
|
+
{ id: "yearly", label: "Pay yearly" },
|
|
21
|
+
];
|
|
22
|
+
|
|
23
|
+
return (
|
|
24
|
+
<div
|
|
25
|
+
ref={ref}
|
|
26
|
+
className={["inline-flex items-center gap-sm", className].filter(Boolean).join(" ")}
|
|
27
|
+
{...rest}
|
|
28
|
+
>
|
|
29
|
+
<div
|
|
30
|
+
role="radiogroup"
|
|
31
|
+
aria-label="Billing period"
|
|
32
|
+
className="inline-flex items-center gap-xxs rounded-xl border border-hairline bg-surface p-xxs"
|
|
33
|
+
>
|
|
34
|
+
{options.map((opt) => {
|
|
35
|
+
const active = value === opt.id;
|
|
36
|
+
return (
|
|
37
|
+
<button
|
|
38
|
+
key={opt.id}
|
|
39
|
+
type="button"
|
|
40
|
+
role="radio"
|
|
41
|
+
aria-checked={active}
|
|
42
|
+
onClick={() => onChange(opt.id)}
|
|
43
|
+
className={[
|
|
44
|
+
"rounded-lg px-lg py-sm text-body-sm font-weight-heading-sm transition-colors duration-150",
|
|
45
|
+
"focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary-focus focus-visible:ring-offset-2",
|
|
46
|
+
active
|
|
47
|
+
? "bg-canvas text-ink shadow-sm"
|
|
48
|
+
: "text-muted hover:text-ink",
|
|
49
|
+
].join(" ")}
|
|
50
|
+
>
|
|
51
|
+
{opt.label}
|
|
52
|
+
</button>
|
|
53
|
+
);
|
|
54
|
+
})}
|
|
55
|
+
</div>
|
|
56
|
+
|
|
57
|
+
{savingsLabel && (
|
|
58
|
+
<Chip label={savingsLabel} variant="primary" size="sm" />
|
|
59
|
+
)}
|
|
60
|
+
</div>
|
|
61
|
+
);
|
|
62
|
+
},
|
|
63
|
+
);
|
|
64
|
+
|
|
65
|
+
BillingToggle.displayName = "BillingToggle";
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import React, { useState } from "react";
|
|
2
|
+
import { BillingToggle } from "./BillingToggle";
|
|
3
|
+
import type { BillingPeriod } from "./BillingToggle";
|
|
4
|
+
|
|
5
|
+
export default function BillingTogglePreview() {
|
|
6
|
+
const [period, setPeriod] = useState<BillingPeriod>("monthly");
|
|
7
|
+
|
|
8
|
+
return (
|
|
9
|
+
<div className="w-full max-w-3xl mx-auto p-lg space-y-lg">
|
|
10
|
+
<div className="flex flex-col items-center gap-sm">
|
|
11
|
+
<BillingToggle value={period} onChange={setPeriod} />
|
|
12
|
+
<p className="text-body-sm text-muted">
|
|
13
|
+
Selected: <span className="text-ink font-weight-heading-sm">{period}</span>
|
|
14
|
+
</p>
|
|
15
|
+
</div>
|
|
16
|
+
|
|
17
|
+
<div className="flex flex-col items-center gap-sm">
|
|
18
|
+
<BillingToggle value={period} onChange={setPeriod} savingsLabel={null} />
|
|
19
|
+
<p className="text-caption text-muted-soft">Without savings chip</p>
|
|
20
|
+
</div>
|
|
21
|
+
</div>
|
|
22
|
+
);
|
|
23
|
+
}
|
|
@@ -1,30 +1,43 @@
|
|
|
1
1
|
import React from "react";
|
|
2
|
+
import { Icon } from "../Icon";
|
|
2
3
|
|
|
3
|
-
export type ButtonVariant = "primary" | "secondary" | "ghost" | "destructive";
|
|
4
|
-
export type ButtonSize = "sm" | "md" | "lg";
|
|
4
|
+
export type ButtonVariant = "primary" | "secondary" | "ghost" | "destructive" | "bare";
|
|
5
|
+
export type ButtonSize = "sm" | "md" | "lg" | "auto";
|
|
5
6
|
|
|
6
7
|
export interface ButtonProps
|
|
7
8
|
extends React.ComponentPropsWithoutRef<"button"> {
|
|
8
9
|
variant?: ButtonVariant;
|
|
9
10
|
size?: ButtonSize;
|
|
10
11
|
loading?: boolean;
|
|
12
|
+
/** Adds a subtle depress (scale + dim) on click. Defaults to true; set false to disable. */
|
|
13
|
+
pushEffect?: boolean;
|
|
11
14
|
}
|
|
12
15
|
|
|
13
16
|
const variantClasses: Record<ButtonVariant, string> = {
|
|
14
17
|
primary:
|
|
15
|
-
"bg-primary text-on-primary hover:bg-primary-hover active:bg-primary-active disabled:bg-primary-disabled disabled:text-on-primary disabled:cursor-not-allowed border border-transparent",
|
|
18
|
+
"justify-center bg-primary text-on-primary hover:bg-primary-hover active:bg-primary-active disabled:bg-primary-disabled disabled:text-on-primary disabled:cursor-not-allowed border border-transparent",
|
|
16
19
|
secondary:
|
|
17
|
-
"bg-canvas text-ink hover:bg-surface-soft active:bg-surface-strong disabled:opacity-50 disabled:cursor-not-allowed border border-hairline",
|
|
20
|
+
"justify-center bg-canvas text-ink hover:bg-surface-soft active:bg-surface-strong disabled:opacity-50 disabled:cursor-not-allowed border border-hairline",
|
|
18
21
|
ghost:
|
|
19
|
-
"bg-transparent text-ink hover:bg-surface-soft active:bg-surface-strong disabled:opacity-50 disabled:cursor-not-allowed border border-transparent",
|
|
22
|
+
"justify-center bg-transparent text-ink hover:bg-surface-soft active:bg-surface-strong disabled:opacity-50 disabled:cursor-not-allowed border border-transparent",
|
|
20
23
|
destructive:
|
|
21
|
-
"bg-semantic-error text-on-primary hover:brightness-90 active:brightness-75 disabled:opacity-50 disabled:cursor-not-allowed border border-transparent",
|
|
24
|
+
"justify-center bg-semantic-error text-on-primary hover:brightness-90 active:brightness-75 disabled:opacity-50 disabled:cursor-not-allowed border border-transparent",
|
|
25
|
+
/**
|
|
26
|
+
* Fully unstyled — no background, text color, or border utilities of its own, so it never
|
|
27
|
+
* fights a caller's own classes at equal CSS specificity. Tailwind's preflight already zeroes
|
|
28
|
+
* a native <button>'s border/background, so nothing extra is needed here. Only non-visual
|
|
29
|
+
* behavior (disabled affordance) lives on this variant. Use with size="auto" so padding/
|
|
30
|
+
* rounding also come entirely from the caller's className (e.g. a custom combobox trigger).
|
|
31
|
+
*/
|
|
32
|
+
bare: "disabled:opacity-50 disabled:cursor-not-allowed",
|
|
22
33
|
};
|
|
23
34
|
|
|
24
35
|
const sizeClasses: Record<ButtonSize, string> = {
|
|
25
36
|
sm: "px-md py-xs text-body-sm rounded-md",
|
|
26
37
|
md: "px-lg py-sm text-body-md rounded-xl",
|
|
27
38
|
lg: "px-xl py-md text-body-lg rounded-xl",
|
|
39
|
+
/** No padding/rounding — the caller supplies sizing via className (used with variant="bare"). */
|
|
40
|
+
auto: "",
|
|
28
41
|
};
|
|
29
42
|
|
|
30
43
|
export const Button = React.forwardRef<HTMLButtonElement, ButtonProps>(
|
|
@@ -33,6 +46,7 @@ export const Button = React.forwardRef<HTMLButtonElement, ButtonProps>(
|
|
|
33
46
|
variant = "primary",
|
|
34
47
|
size = "md",
|
|
35
48
|
loading = false,
|
|
49
|
+
pushEffect = true,
|
|
36
50
|
disabled,
|
|
37
51
|
children,
|
|
38
52
|
className,
|
|
@@ -43,24 +57,26 @@ export const Button = React.forwardRef<HTMLButtonElement, ButtonProps>(
|
|
|
43
57
|
const isDisabled = disabled || loading;
|
|
44
58
|
|
|
45
59
|
const base =
|
|
46
|
-
"inline-flex items-center
|
|
60
|
+
"inline-flex items-center gap-sm font-weight-heading-sm select-none whitespace-nowrap focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary-focus focus-visible:ring-offset-2";
|
|
47
61
|
|
|
48
|
-
const
|
|
62
|
+
const motionClasses = pushEffect
|
|
63
|
+
? "transition-[background-color,color,transform,filter] duration-150 ease-out active:scale-[0.97] active:brightness-95"
|
|
64
|
+
: "transition-colors duration-150";
|
|
65
|
+
|
|
66
|
+
const classes = [
|
|
67
|
+
base,
|
|
68
|
+
motionClasses,
|
|
69
|
+
variantClasses[variant],
|
|
70
|
+
sizeClasses[size],
|
|
71
|
+
className,
|
|
72
|
+
]
|
|
49
73
|
.filter(Boolean)
|
|
50
74
|
.join(" ");
|
|
51
75
|
|
|
52
76
|
return (
|
|
53
77
|
<button ref={ref} disabled={isDisabled} className={classes} {...rest}>
|
|
54
78
|
{loading && (
|
|
55
|
-
<
|
|
56
|
-
aria-hidden="true"
|
|
57
|
-
className="size-4 animate-spin"
|
|
58
|
-
viewBox="0 0 24 24"
|
|
59
|
-
fill="none"
|
|
60
|
-
>
|
|
61
|
-
<circle className="opacity-25" cx="12" cy="12" r="10" stroke="currentColor" strokeWidth="4" />
|
|
62
|
-
<path className="opacity-75" fill="currentColor" d="M4 12a8 8 0 018-8v4a4 4 0 00-4 4H4z" />
|
|
63
|
-
</svg>
|
|
79
|
+
<Icon name="loading-spinner" className="size-4 animate-spin" aria-hidden="true" />
|
|
64
80
|
)}
|
|
65
81
|
{children}
|
|
66
82
|
</button>
|
|
@@ -56,6 +56,22 @@ export default function ButtonPreview() {
|
|
|
56
56
|
</div>
|
|
57
57
|
</div>
|
|
58
58
|
|
|
59
|
+
{/* Push effect: click-and-hold to compare */}
|
|
60
|
+
<div className="mt-lg">
|
|
61
|
+
<h3 className="text-heading-sm text-ink mb-md">Push effect (optional)</h3>
|
|
62
|
+
<p className="text-body-sm text-muted mb-md">Click and hold each button to feel the difference.</p>
|
|
63
|
+
<div className="flex flex-wrap items-center gap-md">
|
|
64
|
+
<div className="flex flex-col items-center gap-sm">
|
|
65
|
+
<span className="text-body-sm text-muted">pushEffect (default)</span>
|
|
66
|
+
<Button variant="primary">Press me</Button>
|
|
67
|
+
</div>
|
|
68
|
+
<div className="flex flex-col items-center gap-sm">
|
|
69
|
+
<span className="text-body-sm text-muted">pushEffect={"{false}"}</span>
|
|
70
|
+
<Button variant="primary" pushEffect={false}>Press me</Button>
|
|
71
|
+
</div>
|
|
72
|
+
</div>
|
|
73
|
+
</div>
|
|
74
|
+
|
|
59
75
|
{/* States */}
|
|
60
76
|
<div className="mt-lg">
|
|
61
77
|
<h3 className="text-heading-sm text-ink mb-md">States</h3>
|