@designa8/vibedesign-v6 1.20.20 → 2.1.1
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 +222 -137
- package/src/atoms/AppSidebar/preview.tsx +61 -8
- package/src/atoms/AppSidebarMobile/AppSidebarMobile.tsx +241 -169
- 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/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/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
|
@@ -0,0 +1,946 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import { Icon } from "../Icon";
|
|
3
|
+
import { Input } from "../Input";
|
|
4
|
+
import { Dropdown } from "../Dropdown";
|
|
5
|
+
import { FontCombobox } from "../FontCombobox";
|
|
6
|
+
import { Modal } from "../Modal";
|
|
7
|
+
import {
|
|
8
|
+
COLOR_GROUPS,
|
|
9
|
+
DEFAULT_TYPE_SCALE,
|
|
10
|
+
FONT_OPTIONS,
|
|
11
|
+
clamp,
|
|
12
|
+
contrastRating,
|
|
13
|
+
contrastRatio,
|
|
14
|
+
hexToHsv,
|
|
15
|
+
hsvToHex,
|
|
16
|
+
parseHex,
|
|
17
|
+
readThemeColors,
|
|
18
|
+
type ColorTokenDef,
|
|
19
|
+
type Hsv,
|
|
20
|
+
type ThemeColors,
|
|
21
|
+
type ThemeId,
|
|
22
|
+
type TypeScale,
|
|
23
|
+
type TypeStyle,
|
|
24
|
+
} from "./DesignTokensPanel.data";
|
|
25
|
+
|
|
26
|
+
export type { ThemeColors, ThemeId, TypeScale, TypeStyle };
|
|
27
|
+
|
|
28
|
+
/* ------------------------------------------------------------------ */
|
|
29
|
+
/* Public types */
|
|
30
|
+
/* ------------------------------------------------------------------ */
|
|
31
|
+
|
|
32
|
+
export interface DesignTokensDraft {
|
|
33
|
+
colors: ThemeColors;
|
|
34
|
+
typeScale: TypeScale;
|
|
35
|
+
bodyFont: string;
|
|
36
|
+
headingFont: string | null;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export interface DesignTokensFont {
|
|
40
|
+
name: string;
|
|
41
|
+
category: "SANS_SERIF" | "SERIF" | "DISPLAY" | "HANDWRITING" | "MONOSPACE" | "OTHER";
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
const FONT_CATEGORY_BY_NAME: Record<string, DesignTokensFont["category"]> = {
|
|
45
|
+
Lora: "SERIF",
|
|
46
|
+
"Playfair Display": "SERIF",
|
|
47
|
+
"JetBrains Mono": "MONOSPACE",
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
const DEFAULT_FONTS: DesignTokensFont[] = FONT_OPTIONS.map((f) => ({
|
|
51
|
+
name: f.value,
|
|
52
|
+
category: FONT_CATEGORY_BY_NAME[f.value] ?? "SANS_SERIF",
|
|
53
|
+
}));
|
|
54
|
+
|
|
55
|
+
export interface DesignTokensPanelProps
|
|
56
|
+
extends Omit<React.ComponentPropsWithoutRef<"section">, "onChange"> {
|
|
57
|
+
/** Starting colors for both themes. Defaults to the live project tokens. */
|
|
58
|
+
colors?: ThemeColors;
|
|
59
|
+
typeScale?: TypeScale;
|
|
60
|
+
bodyFont?: string;
|
|
61
|
+
headingFont?: string | null;
|
|
62
|
+
/** Fonts offered by the body / heading font pickers. */
|
|
63
|
+
fonts?: DesignTokensFont[];
|
|
64
|
+
/** Called when a font row (or the selected font) renders, so the host can lazy-load its webfont. */
|
|
65
|
+
onFontRowVisible?: (name: string) => void;
|
|
66
|
+
defaultSection?: "colors" | "fonts";
|
|
67
|
+
/** Token row that starts expanded. */
|
|
68
|
+
defaultExpandedId?: string | null;
|
|
69
|
+
onColorChange?: (theme: ThemeId, id: string, hex: string) => void;
|
|
70
|
+
onFontChange?: (draft: DesignTokensDraft) => void;
|
|
71
|
+
onSave?: (draft: DesignTokensDraft) => void;
|
|
72
|
+
onDiscard?: () => void;
|
|
73
|
+
/** @deprecated The header no longer renders a collapse control. */
|
|
74
|
+
onCollapse?: () => void;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/* ------------------------------------------------------------------ */
|
|
78
|
+
/* Slider (shared by hue + type-scale controls) */
|
|
79
|
+
/* ------------------------------------------------------------------ */
|
|
80
|
+
|
|
81
|
+
interface SliderProps {
|
|
82
|
+
label: string;
|
|
83
|
+
value: number;
|
|
84
|
+
min: number;
|
|
85
|
+
max: number;
|
|
86
|
+
step?: number;
|
|
87
|
+
variant?: "range" | "hue";
|
|
88
|
+
onChange: (value: number) => void;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
const Slider = ({ label, value, min, max, step = 1, variant = "range", onChange }: SliderProps) => {
|
|
92
|
+
const trackRef = React.useRef<HTMLDivElement>(null);
|
|
93
|
+
const [dragging, setDragging] = React.useState(false);
|
|
94
|
+
const decimals = (String(step).split(".")[1] ?? "").length;
|
|
95
|
+
const ratio = clamp((value - min) / (max - min), 0, 1);
|
|
96
|
+
|
|
97
|
+
const emit = (raw: number) => {
|
|
98
|
+
const snapped = Math.round(raw / step) * step;
|
|
99
|
+
onChange(clamp(Number(snapped.toFixed(decimals)), min, max));
|
|
100
|
+
};
|
|
101
|
+
|
|
102
|
+
const fromPointer = (clientX: number) => {
|
|
103
|
+
const rect = trackRef.current?.getBoundingClientRect();
|
|
104
|
+
if (!rect) return;
|
|
105
|
+
const t = clamp((clientX - rect.left) / rect.width, 0, 1);
|
|
106
|
+
emit(min + t * (max - min));
|
|
107
|
+
};
|
|
108
|
+
|
|
109
|
+
const onKeyDown = (e: React.KeyboardEvent) => {
|
|
110
|
+
const big = e.shiftKey ? 10 : 1;
|
|
111
|
+
if (e.key === "ArrowRight" || e.key === "ArrowUp") {
|
|
112
|
+
e.preventDefault();
|
|
113
|
+
emit(value + step * big);
|
|
114
|
+
} else if (e.key === "ArrowLeft" || e.key === "ArrowDown") {
|
|
115
|
+
e.preventDefault();
|
|
116
|
+
emit(value - step * big);
|
|
117
|
+
} else if (e.key === "Home") {
|
|
118
|
+
e.preventDefault();
|
|
119
|
+
emit(min);
|
|
120
|
+
} else if (e.key === "End") {
|
|
121
|
+
e.preventDefault();
|
|
122
|
+
emit(max);
|
|
123
|
+
}
|
|
124
|
+
};
|
|
125
|
+
|
|
126
|
+
return (
|
|
127
|
+
<div
|
|
128
|
+
ref={trackRef}
|
|
129
|
+
role="slider"
|
|
130
|
+
tabIndex={0}
|
|
131
|
+
aria-label={label}
|
|
132
|
+
aria-valuemin={min}
|
|
133
|
+
aria-valuemax={max}
|
|
134
|
+
aria-valuenow={value}
|
|
135
|
+
onKeyDown={onKeyDown}
|
|
136
|
+
onPointerDown={(e) => {
|
|
137
|
+
e.currentTarget.setPointerCapture(e.pointerId);
|
|
138
|
+
setDragging(true);
|
|
139
|
+
fromPointer(e.clientX);
|
|
140
|
+
}}
|
|
141
|
+
onPointerMove={(e) => {
|
|
142
|
+
if (dragging) fromPointer(e.clientX);
|
|
143
|
+
}}
|
|
144
|
+
onPointerUp={() => setDragging(false)}
|
|
145
|
+
onPointerCancel={() => setDragging(false)}
|
|
146
|
+
className="relative h-6 w-full cursor-pointer touch-none rounded-full focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-focus-blue"
|
|
147
|
+
>
|
|
148
|
+
<span
|
|
149
|
+
aria-hidden="true"
|
|
150
|
+
className={[
|
|
151
|
+
"absolute inset-x-0 top-1/2 -translate-y-1/2 rounded-full",
|
|
152
|
+
variant === "hue" ? "h-3" : "h-1.5 bg-surface-strong",
|
|
153
|
+
].join(" ")}
|
|
154
|
+
style={
|
|
155
|
+
variant === "hue"
|
|
156
|
+
? {
|
|
157
|
+
backgroundImage:
|
|
158
|
+
"linear-gradient(to right, hsl(0 100% 50%), hsl(60 100% 50%), hsl(120 100% 50%), hsl(180 100% 50%), hsl(240 100% 50%), hsl(300 100% 50%), hsl(360 100% 50%))",
|
|
159
|
+
}
|
|
160
|
+
: undefined
|
|
161
|
+
}
|
|
162
|
+
/>
|
|
163
|
+
{variant === "range" ? (
|
|
164
|
+
<span
|
|
165
|
+
aria-hidden="true"
|
|
166
|
+
className="absolute left-0 top-1/2 h-1.5 -translate-y-1/2 rounded-full bg-primary"
|
|
167
|
+
style={{ width: `${ratio * 100}%` }}
|
|
168
|
+
/>
|
|
169
|
+
) : null}
|
|
170
|
+
<span
|
|
171
|
+
aria-hidden="true"
|
|
172
|
+
data-dragging={dragging}
|
|
173
|
+
className="absolute top-1/2 size-4 -translate-x-1/2 -translate-y-1/2 rounded-full border-2 border-canvas bg-primary shadow-md transition-transform duration-150 ease-out data-[dragging=true]:scale-110"
|
|
174
|
+
style={{
|
|
175
|
+
left: `${ratio * 100}%`,
|
|
176
|
+
backgroundColor: variant === "hue" ? `hsl(${value} 100% 50%)` : undefined,
|
|
177
|
+
}}
|
|
178
|
+
/>
|
|
179
|
+
</div>
|
|
180
|
+
);
|
|
181
|
+
};
|
|
182
|
+
|
|
183
|
+
/* ------------------------------------------------------------------ */
|
|
184
|
+
/* Saturation / brightness square */
|
|
185
|
+
/* ------------------------------------------------------------------ */
|
|
186
|
+
|
|
187
|
+
interface SvPickerProps {
|
|
188
|
+
label: string;
|
|
189
|
+
hsv: Hsv;
|
|
190
|
+
onChange: (next: { s: number; v: number }) => void;
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
const SvPicker = ({ label, hsv, onChange }: SvPickerProps) => {
|
|
194
|
+
const areaRef = React.useRef<HTMLDivElement>(null);
|
|
195
|
+
const [dragging, setDragging] = React.useState(false);
|
|
196
|
+
|
|
197
|
+
const fromPointer = (x: number, y: number) => {
|
|
198
|
+
const rect = areaRef.current?.getBoundingClientRect();
|
|
199
|
+
if (!rect) return;
|
|
200
|
+
onChange({
|
|
201
|
+
s: clamp(((x - rect.left) / rect.width) * 100, 0, 100),
|
|
202
|
+
v: clamp((1 - (y - rect.top) / rect.height) * 100, 0, 100),
|
|
203
|
+
});
|
|
204
|
+
};
|
|
205
|
+
|
|
206
|
+
const onKeyDown = (e: React.KeyboardEvent) => {
|
|
207
|
+
const d = e.shiftKey ? 10 : 1;
|
|
208
|
+
let { s, v } = hsv;
|
|
209
|
+
if (e.key === "ArrowRight") s += d;
|
|
210
|
+
else if (e.key === "ArrowLeft") s -= d;
|
|
211
|
+
else if (e.key === "ArrowUp") v += d;
|
|
212
|
+
else if (e.key === "ArrowDown") v -= d;
|
|
213
|
+
else return;
|
|
214
|
+
e.preventDefault();
|
|
215
|
+
onChange({ s: clamp(s, 0, 100), v: clamp(v, 0, 100) });
|
|
216
|
+
};
|
|
217
|
+
|
|
218
|
+
return (
|
|
219
|
+
<div
|
|
220
|
+
ref={areaRef}
|
|
221
|
+
role="slider"
|
|
222
|
+
tabIndex={0}
|
|
223
|
+
aria-label={label}
|
|
224
|
+
aria-valuemin={0}
|
|
225
|
+
aria-valuemax={100}
|
|
226
|
+
aria-valuenow={Math.round(hsv.s)}
|
|
227
|
+
aria-valuetext={`Saturation ${Math.round(hsv.s)}%, brightness ${Math.round(hsv.v)}%`}
|
|
228
|
+
onKeyDown={onKeyDown}
|
|
229
|
+
onPointerDown={(e) => {
|
|
230
|
+
e.currentTarget.setPointerCapture(e.pointerId);
|
|
231
|
+
setDragging(true);
|
|
232
|
+
fromPointer(e.clientX, e.clientY);
|
|
233
|
+
}}
|
|
234
|
+
onPointerMove={(e) => {
|
|
235
|
+
if (dragging) fromPointer(e.clientX, e.clientY);
|
|
236
|
+
}}
|
|
237
|
+
onPointerUp={() => setDragging(false)}
|
|
238
|
+
onPointerCancel={() => setDragging(false)}
|
|
239
|
+
className="relative h-24 w-28 shrink-0 cursor-crosshair touch-none rounded-md focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-focus-blue"
|
|
240
|
+
>
|
|
241
|
+
<span
|
|
242
|
+
aria-hidden="true"
|
|
243
|
+
className="absolute inset-0 rounded-md"
|
|
244
|
+
style={{ backgroundColor: `hsl(${hsv.h} 100% 50%)` }}
|
|
245
|
+
/>
|
|
246
|
+
<span aria-hidden="true" className="absolute inset-0 rounded-md bg-linear-to-r from-contrast-light to-transparent" />
|
|
247
|
+
<span aria-hidden="true" className="absolute inset-0 rounded-md bg-linear-to-t from-contrast-dark to-transparent" />
|
|
248
|
+
<span
|
|
249
|
+
aria-hidden="true"
|
|
250
|
+
data-dragging={dragging}
|
|
251
|
+
className="absolute size-4 -translate-x-1/2 -translate-y-1/2 rounded-full border-2 border-contrast-light shadow-md transition-transform duration-150 ease-out data-[dragging=true]:scale-110"
|
|
252
|
+
style={{ left: `${hsv.s}%`, top: `${100 - hsv.v}%` }}
|
|
253
|
+
/>
|
|
254
|
+
</div>
|
|
255
|
+
);
|
|
256
|
+
};
|
|
257
|
+
|
|
258
|
+
/* ------------------------------------------------------------------ */
|
|
259
|
+
/* Color row (collapsed row + inline editor) */
|
|
260
|
+
/* ------------------------------------------------------------------ */
|
|
261
|
+
|
|
262
|
+
const HEX_ERROR = "Enter a valid 6-digit hex value";
|
|
263
|
+
|
|
264
|
+
interface ColorRowProps {
|
|
265
|
+
token: ColorTokenDef;
|
|
266
|
+
value: string;
|
|
267
|
+
text: string;
|
|
268
|
+
changed: boolean;
|
|
269
|
+
invalid: boolean;
|
|
270
|
+
expanded: boolean;
|
|
271
|
+
against: string;
|
|
272
|
+
panelId: string;
|
|
273
|
+
onToggle: () => void;
|
|
274
|
+
onText: (text: string) => void;
|
|
275
|
+
onBlurText: () => void;
|
|
276
|
+
onPick: (hex: string) => void;
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
const ContrastChip = ({ hex, against }: { hex: string; against: string }) => {
|
|
280
|
+
const rating = contrastRating(contrastRatio(hex, against));
|
|
281
|
+
const tone =
|
|
282
|
+
rating.tone === "pass"
|
|
283
|
+
? "bg-semantic-success-soft text-semantic-success"
|
|
284
|
+
: rating.tone === "large"
|
|
285
|
+
? "bg-semantic-warning-soft text-semantic-warning"
|
|
286
|
+
: "bg-semantic-error-soft text-semantic-error";
|
|
287
|
+
return (
|
|
288
|
+
<span
|
|
289
|
+
aria-label={`Contrast ${rating.label}`}
|
|
290
|
+
className={`inline-flex h-8 shrink-0 items-center whitespace-nowrap rounded-md px-sm text-caption transition-colors duration-150 ${tone}`}
|
|
291
|
+
>
|
|
292
|
+
{rating.label}
|
|
293
|
+
</span>
|
|
294
|
+
);
|
|
295
|
+
};
|
|
296
|
+
|
|
297
|
+
const ColorRow = ({
|
|
298
|
+
token,
|
|
299
|
+
value,
|
|
300
|
+
text,
|
|
301
|
+
changed,
|
|
302
|
+
invalid,
|
|
303
|
+
expanded,
|
|
304
|
+
against,
|
|
305
|
+
panelId,
|
|
306
|
+
onToggle,
|
|
307
|
+
onText,
|
|
308
|
+
onBlurText,
|
|
309
|
+
onPick,
|
|
310
|
+
}: ColorRowProps) => {
|
|
311
|
+
const [hsv, setHsv] = React.useState<Hsv>(() => hexToHsv(value));
|
|
312
|
+
|
|
313
|
+
React.useEffect(() => {
|
|
314
|
+
if (hsvToHex(hsv) !== value) setHsv(hexToHsv(value));
|
|
315
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
316
|
+
}, [value]);
|
|
317
|
+
|
|
318
|
+
const updateHsv = (patch: Partial<Hsv>) => {
|
|
319
|
+
const next = { ...hsv, ...patch };
|
|
320
|
+
setHsv(next);
|
|
321
|
+
onPick(hsvToHex(next));
|
|
322
|
+
};
|
|
323
|
+
|
|
324
|
+
return (
|
|
325
|
+
<div
|
|
326
|
+
data-state={expanded ? "open" : "closed"}
|
|
327
|
+
onKeyDown={(e) => {
|
|
328
|
+
if (e.key === "Escape" && expanded) onToggle();
|
|
329
|
+
}}
|
|
330
|
+
className="rounded-lg transition-colors duration-200 ease-out hover:bg-surface-soft data-[state=open]:bg-primary-soft"
|
|
331
|
+
>
|
|
332
|
+
<div className="relative flex items-start gap-md px-sm py-xs">
|
|
333
|
+
<button
|
|
334
|
+
type="button"
|
|
335
|
+
aria-expanded={expanded}
|
|
336
|
+
aria-controls={panelId}
|
|
337
|
+
aria-label={`Edit ${token.label} color, currently ${value}`}
|
|
338
|
+
onClick={onToggle}
|
|
339
|
+
className="flex h-8 min-w-0 flex-1 cursor-pointer items-center gap-md rounded-md text-left transition duration-150 ease-out active:scale-[0.98] focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-focus-blue"
|
|
340
|
+
>
|
|
341
|
+
<span
|
|
342
|
+
aria-hidden="true"
|
|
343
|
+
className="size-8 shrink-0 rounded-sm border border-hairline"
|
|
344
|
+
style={{ backgroundColor: value }}
|
|
345
|
+
/>
|
|
346
|
+
<span className="truncate text-body-sm text-ink">{token.label}</span>
|
|
347
|
+
</button>
|
|
348
|
+
<div className="w-32 shrink-0">
|
|
349
|
+
<Input
|
|
350
|
+
size="sm"
|
|
351
|
+
fullWidth
|
|
352
|
+
aria-label={`${token.label} hex value`}
|
|
353
|
+
value={text}
|
|
354
|
+
maxLength={7}
|
|
355
|
+
spellCheck={false}
|
|
356
|
+
autoComplete="off"
|
|
357
|
+
error={invalid ? HEX_ERROR : undefined}
|
|
358
|
+
onChange={(e) => onText(e.target.value)}
|
|
359
|
+
onBlur={onBlurText}
|
|
360
|
+
className="bg-canvas! font-mono uppercase"
|
|
361
|
+
/>
|
|
362
|
+
</div>
|
|
363
|
+
{changed || invalid ? (
|
|
364
|
+
<span
|
|
365
|
+
aria-hidden="true"
|
|
366
|
+
className={`absolute right-xs top-sm size-1.5 rounded-full ${invalid ? "bg-semantic-error" : "bg-primary"}`}
|
|
367
|
+
/>
|
|
368
|
+
) : null}
|
|
369
|
+
</div>
|
|
370
|
+
|
|
371
|
+
<div
|
|
372
|
+
id={panelId}
|
|
373
|
+
data-state={expanded ? "open" : "closed"}
|
|
374
|
+
inert={!expanded}
|
|
375
|
+
className="grid grid-rows-[0fr] opacity-0 transition-[grid-template-rows,opacity] duration-200 ease-out data-[state=open]:grid-rows-[1fr] data-[state=open]:opacity-100"
|
|
376
|
+
>
|
|
377
|
+
<div className="overflow-hidden">
|
|
378
|
+
<div className="flex flex-col gap-md px-sm pb-base pt-xs">
|
|
379
|
+
<div className="flex gap-md">
|
|
380
|
+
<SvPicker
|
|
381
|
+
label={`${token.label} saturation and brightness`}
|
|
382
|
+
hsv={hsv}
|
|
383
|
+
onChange={(next) => updateHsv(next)}
|
|
384
|
+
/>
|
|
385
|
+
<div className="flex min-w-0 flex-1 flex-col justify-between">
|
|
386
|
+
<Slider
|
|
387
|
+
label={`${token.label} hue`}
|
|
388
|
+
variant="hue"
|
|
389
|
+
value={Math.round(hsv.h)}
|
|
390
|
+
min={0}
|
|
391
|
+
max={360}
|
|
392
|
+
onChange={(h) => updateHsv({ h })}
|
|
393
|
+
/>
|
|
394
|
+
<div className="flex items-center gap-sm">
|
|
395
|
+
<div className="w-24 shrink-0">
|
|
396
|
+
<Input
|
|
397
|
+
size="sm"
|
|
398
|
+
fullWidth
|
|
399
|
+
aria-label={`${token.label} hex in picker`}
|
|
400
|
+
value={text}
|
|
401
|
+
maxLength={7}
|
|
402
|
+
spellCheck={false}
|
|
403
|
+
autoComplete="off"
|
|
404
|
+
onChange={(e) => onText(e.target.value)}
|
|
405
|
+
onBlur={onBlurText}
|
|
406
|
+
className="bg-canvas! font-mono uppercase"
|
|
407
|
+
/>
|
|
408
|
+
</div>
|
|
409
|
+
<ContrastChip hex={value} against={against} />
|
|
410
|
+
</div>
|
|
411
|
+
</div>
|
|
412
|
+
</div>
|
|
413
|
+
<p className="text-caption text-muted">{token.description}</p>
|
|
414
|
+
</div>
|
|
415
|
+
</div>
|
|
416
|
+
</div>
|
|
417
|
+
</div>
|
|
418
|
+
);
|
|
419
|
+
};
|
|
420
|
+
|
|
421
|
+
/* ------------------------------------------------------------------ */
|
|
422
|
+
/* Number field (type-scale values) */
|
|
423
|
+
/* ------------------------------------------------------------------ */
|
|
424
|
+
|
|
425
|
+
interface NumberFieldProps {
|
|
426
|
+
label: string;
|
|
427
|
+
value: number;
|
|
428
|
+
min: number;
|
|
429
|
+
max: number;
|
|
430
|
+
onChange: (n: number) => void;
|
|
431
|
+
}
|
|
432
|
+
|
|
433
|
+
const NumberField = ({ label, value, min, max, onChange }: NumberFieldProps) => {
|
|
434
|
+
const [text, setText] = React.useState(String(value));
|
|
435
|
+
|
|
436
|
+
React.useEffect(() => {
|
|
437
|
+
if (parseFloat(text) !== value) setText(String(value));
|
|
438
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
439
|
+
}, [value]);
|
|
440
|
+
|
|
441
|
+
return (
|
|
442
|
+
<div className="w-20 shrink-0">
|
|
443
|
+
<Input
|
|
444
|
+
size="sm"
|
|
445
|
+
fullWidth
|
|
446
|
+
inputMode="decimal"
|
|
447
|
+
aria-label={label}
|
|
448
|
+
value={text}
|
|
449
|
+
onChange={(e) => {
|
|
450
|
+
setText(e.target.value);
|
|
451
|
+
const n = parseFloat(e.target.value);
|
|
452
|
+
if (!Number.isNaN(n)) onChange(clamp(n, min, max));
|
|
453
|
+
}}
|
|
454
|
+
onBlur={() => setText(String(value))}
|
|
455
|
+
className="bg-canvas! text-right font-mono"
|
|
456
|
+
/>
|
|
457
|
+
</div>
|
|
458
|
+
);
|
|
459
|
+
};
|
|
460
|
+
|
|
461
|
+
/* ------------------------------------------------------------------ */
|
|
462
|
+
/* Fonts pane */
|
|
463
|
+
/* ------------------------------------------------------------------ */
|
|
464
|
+
|
|
465
|
+
interface FontsPaneProps {
|
|
466
|
+
draft: DesignTokensDraft;
|
|
467
|
+
role: string;
|
|
468
|
+
fonts: DesignTokensFont[];
|
|
469
|
+
onFontRowVisible?: (name: string) => void;
|
|
470
|
+
onRole: (role: string) => void;
|
|
471
|
+
onBodyFont: (font: string) => void;
|
|
472
|
+
onHeadingFont: (font: string | null) => void;
|
|
473
|
+
onStyle: (role: string, patch: Partial<TypeStyle>) => void;
|
|
474
|
+
}
|
|
475
|
+
|
|
476
|
+
const SLIDER_FIELDS: {
|
|
477
|
+
key: "fontSize" | "fontWeight" | "lineHeight" | "letterSpacing";
|
|
478
|
+
label: string;
|
|
479
|
+
min: number;
|
|
480
|
+
max: number;
|
|
481
|
+
step: number;
|
|
482
|
+
}[] = [
|
|
483
|
+
{ key: "fontSize", label: "Font size", min: 8, max: 72, step: 1 },
|
|
484
|
+
{ key: "fontWeight", label: "Font weight", min: 100, max: 900, step: 100 },
|
|
485
|
+
{ key: "lineHeight", label: "Line height", min: 0.8, max: 2.2, step: 0.05 },
|
|
486
|
+
{ key: "letterSpacing", label: "Letter spacing", min: -2, max: 4, step: 0.05 },
|
|
487
|
+
];
|
|
488
|
+
|
|
489
|
+
const cardClass = "rounded-xl border border-hairline-soft bg-surface p-base";
|
|
490
|
+
const eyebrow = "text-caption uppercase tracking-[0.08em] text-muted";
|
|
491
|
+
|
|
492
|
+
const FontsPane = ({
|
|
493
|
+
draft,
|
|
494
|
+
role,
|
|
495
|
+
fonts,
|
|
496
|
+
onFontRowVisible,
|
|
497
|
+
onRole,
|
|
498
|
+
onBodyFont,
|
|
499
|
+
onHeadingFont,
|
|
500
|
+
onStyle,
|
|
501
|
+
}: FontsPaneProps) => {
|
|
502
|
+
const style = draft.typeScale[role];
|
|
503
|
+
const family = style.slot === "heading" && draft.headingFont ? draft.headingFont : draft.bodyFont;
|
|
504
|
+
const fontCount = draft.headingFont ? 2 : 1;
|
|
505
|
+
const roleOptions = Object.keys(draft.typeScale).map((r) => ({ label: r, value: r }));
|
|
506
|
+
|
|
507
|
+
return (
|
|
508
|
+
<div className="flex flex-col gap-base px-lg py-base">
|
|
509
|
+
<div className={cardClass}>
|
|
510
|
+
<div className="flex items-baseline justify-between">
|
|
511
|
+
<h3 className="text-body-sm font-weight-body-md text-ink">Font families</h3>
|
|
512
|
+
<span className={eyebrow}>
|
|
513
|
+
{fontCount} {fontCount === 1 ? "font" : "fonts"}
|
|
514
|
+
</span>
|
|
515
|
+
</div>
|
|
516
|
+
<p className="mb-md mt-xs text-caption text-muted">
|
|
517
|
+
Use one font for everything. Add a second only for editorial or display headings — every other role
|
|
518
|
+
inherits the body font.
|
|
519
|
+
</p>
|
|
520
|
+
<FontCombobox
|
|
521
|
+
label="Body font (workhorse)"
|
|
522
|
+
fonts={fonts}
|
|
523
|
+
value={draft.bodyFont}
|
|
524
|
+
onChange={onBodyFont}
|
|
525
|
+
onRowVisible={onFontRowVisible}
|
|
526
|
+
/>
|
|
527
|
+
<div className="mt-md">
|
|
528
|
+
{draft.headingFont ? (
|
|
529
|
+
<div className="flex items-end gap-sm">
|
|
530
|
+
<div className="min-w-0 flex-1">
|
|
531
|
+
<FontCombobox
|
|
532
|
+
label="Heading font"
|
|
533
|
+
fonts={fonts}
|
|
534
|
+
value={draft.headingFont}
|
|
535
|
+
onChange={(v) => onHeadingFont(v)}
|
|
536
|
+
onRowVisible={onFontRowVisible}
|
|
537
|
+
/>
|
|
538
|
+
</div>
|
|
539
|
+
<button
|
|
540
|
+
type="button"
|
|
541
|
+
aria-label="Remove heading font"
|
|
542
|
+
onClick={() => onHeadingFont(null)}
|
|
543
|
+
className="flex size-10 shrink-0 cursor-pointer items-center justify-center rounded-md text-muted transition duration-150 ease-out hover:bg-surface-soft active:scale-[0.98] focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-focus-blue"
|
|
544
|
+
>
|
|
545
|
+
<Icon name="close" className="size-4" />
|
|
546
|
+
</button>
|
|
547
|
+
</div>
|
|
548
|
+
) : (
|
|
549
|
+
<button
|
|
550
|
+
type="button"
|
|
551
|
+
onClick={() => onHeadingFont(draft.bodyFont)}
|
|
552
|
+
className="flex h-10 w-full cursor-pointer items-center justify-center gap-sm rounded-md border border-dashed border-hairline-strong text-body-sm text-body transition duration-150 ease-out hover:bg-surface-soft active:scale-[0.98] focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-focus-blue"
|
|
553
|
+
>
|
|
554
|
+
<Icon name="plus-add" className="size-4" />
|
|
555
|
+
Add a heading font
|
|
556
|
+
</button>
|
|
557
|
+
)}
|
|
558
|
+
</div>
|
|
559
|
+
</div>
|
|
560
|
+
|
|
561
|
+
<div className={cardClass}>
|
|
562
|
+
<div className="flex items-baseline justify-between">
|
|
563
|
+
<h3 className="text-body-sm font-weight-body-md text-ink">Type scale</h3>
|
|
564
|
+
<span className={eyebrow}>{roleOptions.length} sizes</span>
|
|
565
|
+
</div>
|
|
566
|
+
<div className="mt-md">
|
|
567
|
+
<Dropdown label="Editing" options={roleOptions} value={role} onChange={onRole} />
|
|
568
|
+
</div>
|
|
569
|
+
|
|
570
|
+
<div className="mt-md rounded-lg border border-hairline-soft bg-canvas p-md">
|
|
571
|
+
<div className="mb-xs flex items-baseline justify-between">
|
|
572
|
+
<span className="font-mono text-caption text-ink">{role}</span>
|
|
573
|
+
<span className="font-mono text-caption text-muted">
|
|
574
|
+
{style.fontSize} / {style.lineHeight}
|
|
575
|
+
</span>
|
|
576
|
+
</div>
|
|
577
|
+
<div className="flex min-h-16 items-center overflow-hidden">
|
|
578
|
+
<p
|
|
579
|
+
className="truncate text-ink"
|
|
580
|
+
style={{
|
|
581
|
+
fontFamily: `"${family}", ui-sans-serif, system-ui, sans-serif`,
|
|
582
|
+
fontSize: style.fontSize,
|
|
583
|
+
fontWeight: style.fontWeight,
|
|
584
|
+
lineHeight: style.lineHeight,
|
|
585
|
+
letterSpacing: `${style.letterSpacing}px`,
|
|
586
|
+
}}
|
|
587
|
+
>
|
|
588
|
+
The quick brown fox
|
|
589
|
+
</p>
|
|
590
|
+
</div>
|
|
591
|
+
</div>
|
|
592
|
+
|
|
593
|
+
<div className="mt-md flex flex-col gap-md rounded-lg border border-hairline-soft bg-canvas p-md">
|
|
594
|
+
{SLIDER_FIELDS.map((f) => (
|
|
595
|
+
<div key={f.key} className="flex flex-col gap-xs">
|
|
596
|
+
<div className="flex items-center justify-between gap-md">
|
|
597
|
+
<span className={eyebrow}>{f.label}</span>
|
|
598
|
+
<NumberField
|
|
599
|
+
label={`${f.label} for ${role}`}
|
|
600
|
+
value={style[f.key]}
|
|
601
|
+
min={f.min}
|
|
602
|
+
max={f.max}
|
|
603
|
+
onChange={(n) => onStyle(role, { [f.key]: n } as Partial<TypeStyle>)}
|
|
604
|
+
/>
|
|
605
|
+
</div>
|
|
606
|
+
<Slider
|
|
607
|
+
label={`${f.label} for ${role}`}
|
|
608
|
+
value={style[f.key]}
|
|
609
|
+
min={f.min}
|
|
610
|
+
max={f.max}
|
|
611
|
+
step={f.step}
|
|
612
|
+
onChange={(n) => onStyle(role, { [f.key]: n } as Partial<TypeStyle>)}
|
|
613
|
+
/>
|
|
614
|
+
</div>
|
|
615
|
+
))}
|
|
616
|
+
</div>
|
|
617
|
+
</div>
|
|
618
|
+
</div>
|
|
619
|
+
);
|
|
620
|
+
};
|
|
621
|
+
|
|
622
|
+
/* ------------------------------------------------------------------ */
|
|
623
|
+
/* Panel */
|
|
624
|
+
/* ------------------------------------------------------------------ */
|
|
625
|
+
|
|
626
|
+
type SectionId = "colors" | "fonts";
|
|
627
|
+
|
|
628
|
+
const warningButtonClass =
|
|
629
|
+
"h-10 cursor-pointer rounded-md bg-semantic-warning px-lg text-body-sm text-contrast-dark transition duration-150 ease-out hover:brightness-95 active:scale-[0.98] active:brightness-90 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-focus-blue disabled:cursor-not-allowed disabled:opacity-50";
|
|
630
|
+
|
|
631
|
+
const ghostButtonClass =
|
|
632
|
+
"h-10 cursor-pointer rounded-md px-md text-body-sm text-ink transition duration-150 ease-out hover:bg-surface-strong active:scale-[0.98] focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-focus-blue disabled:cursor-not-allowed disabled:opacity-50";
|
|
633
|
+
|
|
634
|
+
export const DesignTokensPanel = React.forwardRef<HTMLElement, DesignTokensPanelProps>(
|
|
635
|
+
(
|
|
636
|
+
{
|
|
637
|
+
colors: colorsProp,
|
|
638
|
+
typeScale = DEFAULT_TYPE_SCALE,
|
|
639
|
+
bodyFont = "Plus Jakarta Sans",
|
|
640
|
+
headingFont = null,
|
|
641
|
+
fonts = DEFAULT_FONTS,
|
|
642
|
+
onFontRowVisible,
|
|
643
|
+
defaultSection = "colors",
|
|
644
|
+
defaultExpandedId = "primary",
|
|
645
|
+
className = "",
|
|
646
|
+
onColorChange,
|
|
647
|
+
onFontChange,
|
|
648
|
+
onSave,
|
|
649
|
+
onDiscard,
|
|
650
|
+
// Accepted for backward compatibility; the header renders no collapse control.
|
|
651
|
+
onCollapse: _onCollapse,
|
|
652
|
+
...rest
|
|
653
|
+
},
|
|
654
|
+
ref,
|
|
655
|
+
) => {
|
|
656
|
+
const uid = React.useId();
|
|
657
|
+
const [initial] = React.useState<DesignTokensDraft>(() => ({
|
|
658
|
+
colors: colorsProp ?? readThemeColors(),
|
|
659
|
+
typeScale,
|
|
660
|
+
bodyFont,
|
|
661
|
+
headingFont,
|
|
662
|
+
}));
|
|
663
|
+
const [draft, setDraft] = React.useState<DesignTokensDraft>(initial);
|
|
664
|
+
const [saved, setSaved] = React.useState<DesignTokensDraft>(initial);
|
|
665
|
+
const [section, setSection] = React.useState<SectionId>(defaultSection);
|
|
666
|
+
const [theme, setTheme] = React.useState<ThemeId>("light");
|
|
667
|
+
const [expandedId, setExpandedId] = React.useState<string | null>(defaultExpandedId);
|
|
668
|
+
const [hexDrafts, setHexDrafts] = React.useState<Record<string, string>>({});
|
|
669
|
+
const [role, setRole] = React.useState("display-lg");
|
|
670
|
+
const [confirmOpen, setConfirmOpen] = React.useState(false);
|
|
671
|
+
|
|
672
|
+
const dirty = React.useMemo(() => JSON.stringify(draft) !== JSON.stringify(saved), [draft, saved]);
|
|
673
|
+
const invalid = Object.keys(hexDrafts).length > 0;
|
|
674
|
+
const canSave = dirty && !invalid;
|
|
675
|
+
|
|
676
|
+
const clearHexDraft = (id: string) =>
|
|
677
|
+
setHexDrafts((prev) => {
|
|
678
|
+
if (!(id in prev)) return prev;
|
|
679
|
+
const next = { ...prev };
|
|
680
|
+
delete next[id];
|
|
681
|
+
return next;
|
|
682
|
+
});
|
|
683
|
+
|
|
684
|
+
const setColor = (id: string, hex: string) => {
|
|
685
|
+
setDraft((d) => ({
|
|
686
|
+
...d,
|
|
687
|
+
colors: { ...d.colors, [theme]: { ...d.colors[theme], [id]: hex } },
|
|
688
|
+
}));
|
|
689
|
+
clearHexDraft(id);
|
|
690
|
+
onColorChange?.(theme, id, hex);
|
|
691
|
+
};
|
|
692
|
+
|
|
693
|
+
const handleText = (id: string, text: string) => {
|
|
694
|
+
const hex = parseHex(text, false);
|
|
695
|
+
if (hex) {
|
|
696
|
+
setColor(id, hex);
|
|
697
|
+
} else {
|
|
698
|
+
setHexDrafts((prev) => ({ ...prev, [id]: text }));
|
|
699
|
+
}
|
|
700
|
+
};
|
|
701
|
+
|
|
702
|
+
const handleBlur = (id: string) => {
|
|
703
|
+
const text = hexDrafts[id];
|
|
704
|
+
if (text === undefined) return;
|
|
705
|
+
const hex = parseHex(text, true);
|
|
706
|
+
if (hex) setColor(id, hex);
|
|
707
|
+
};
|
|
708
|
+
|
|
709
|
+
const updateFonts = (patch: Partial<DesignTokensDraft>) => {
|
|
710
|
+
setDraft((d) => {
|
|
711
|
+
const next = { ...d, ...patch };
|
|
712
|
+
onFontChange?.(next);
|
|
713
|
+
return next;
|
|
714
|
+
});
|
|
715
|
+
};
|
|
716
|
+
|
|
717
|
+
const handleStyle = (r: string, patch: Partial<TypeStyle>) =>
|
|
718
|
+
updateFonts({ typeScale: { ...draft.typeScale, [r]: { ...draft.typeScale[r], ...patch } } });
|
|
719
|
+
|
|
720
|
+
const requestSave = () => {
|
|
721
|
+
if (!canSave) return;
|
|
722
|
+
setConfirmOpen(true);
|
|
723
|
+
};
|
|
724
|
+
|
|
725
|
+
const confirmSave = () => {
|
|
726
|
+
setConfirmOpen(false);
|
|
727
|
+
if (!canSave) return;
|
|
728
|
+
setSaved(draft);
|
|
729
|
+
onSave?.(draft);
|
|
730
|
+
};
|
|
731
|
+
|
|
732
|
+
const handleDiscard = () => {
|
|
733
|
+
setDraft(saved);
|
|
734
|
+
setHexDrafts({});
|
|
735
|
+
onDiscard?.();
|
|
736
|
+
};
|
|
737
|
+
|
|
738
|
+
const switchTheme = (next: ThemeId) => {
|
|
739
|
+
setTheme(next);
|
|
740
|
+
setHexDrafts({});
|
|
741
|
+
};
|
|
742
|
+
|
|
743
|
+
const sections: { id: SectionId; label: string }[] = [
|
|
744
|
+
{ id: "colors", label: "Colors" },
|
|
745
|
+
{ id: "fonts", label: "Fonts" },
|
|
746
|
+
];
|
|
747
|
+
|
|
748
|
+
const onTabKeyDown = (e: React.KeyboardEvent) => {
|
|
749
|
+
if (e.key !== "ArrowRight" && e.key !== "ArrowLeft") return;
|
|
750
|
+
e.preventDefault();
|
|
751
|
+
setSection((s) => (s === "colors" ? "fonts" : "colors"));
|
|
752
|
+
};
|
|
753
|
+
|
|
754
|
+
const status = invalid ? "Fix invalid values" : dirty ? "Unsaved changes" : "All changes saved";
|
|
755
|
+
const values = draft.colors[theme];
|
|
756
|
+
const savedValues = saved.colors[theme];
|
|
757
|
+
|
|
758
|
+
return (
|
|
759
|
+
<>
|
|
760
|
+
<section
|
|
761
|
+
ref={ref}
|
|
762
|
+
aria-label="Design tokens"
|
|
763
|
+
className={`flex h-full max-h-full min-h-0 w-full flex-col overflow-hidden rounded-none border border-hairline bg-canvas shadow-card ${className}`}
|
|
764
|
+
{...rest}
|
|
765
|
+
>
|
|
766
|
+
{/* Header */}
|
|
767
|
+
<header className="flex shrink-0 items-center gap-md border-b border-hairline px-lg py-base">
|
|
768
|
+
<div className="min-w-0 flex-1">
|
|
769
|
+
<h2 className="truncate text-heading-sm font-weight-body-md text-ink">Design Tokens</h2>
|
|
770
|
+
<p
|
|
771
|
+
aria-live="polite"
|
|
772
|
+
className={`text-caption transition-colors duration-150 ${invalid ? "text-semantic-error" : "text-muted"}`}
|
|
773
|
+
>
|
|
774
|
+
{status}
|
|
775
|
+
</p>
|
|
776
|
+
</div>
|
|
777
|
+
</header>
|
|
778
|
+
|
|
779
|
+
{/* Section switcher */}
|
|
780
|
+
<div
|
|
781
|
+
role="tablist"
|
|
782
|
+
aria-label="Token sections"
|
|
783
|
+
onKeyDown={onTabKeyDown}
|
|
784
|
+
className="relative grid shrink-0 grid-cols-2 border-b border-hairline"
|
|
785
|
+
>
|
|
786
|
+
{sections.map((s) => (
|
|
787
|
+
<button
|
|
788
|
+
key={s.id}
|
|
789
|
+
type="button"
|
|
790
|
+
role="tab"
|
|
791
|
+
id={`${uid}-tab-${s.id}`}
|
|
792
|
+
aria-selected={section === s.id}
|
|
793
|
+
aria-controls={`${uid}-pane-${s.id}`}
|
|
794
|
+
tabIndex={section === s.id ? 0 : -1}
|
|
795
|
+
onClick={() => setSection(s.id)}
|
|
796
|
+
className={[
|
|
797
|
+
"h-11 cursor-pointer text-body-sm transition duration-150 ease-out hover:bg-surface-soft active:scale-[0.98] focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-focus-blue",
|
|
798
|
+
section === s.id ? "text-primary" : "text-muted",
|
|
799
|
+
].join(" ")}
|
|
800
|
+
>
|
|
801
|
+
{s.label}
|
|
802
|
+
</button>
|
|
803
|
+
))}
|
|
804
|
+
<span
|
|
805
|
+
aria-hidden="true"
|
|
806
|
+
className="pointer-events-none absolute bottom-0 left-0 h-0.5 w-1/2 bg-primary transition-transform duration-[220ms] ease-out"
|
|
807
|
+
style={{ transform: section === "colors" ? "translateX(0)" : "translateX(100%)" }}
|
|
808
|
+
/>
|
|
809
|
+
</div>
|
|
810
|
+
|
|
811
|
+
{/* Panes: both share one grid cell; each pane scrolls on its own */}
|
|
812
|
+
<div className="grid min-h-0 flex-1 grid-cols-1 grid-rows-[minmax(0,1fr)] overflow-hidden">
|
|
813
|
+
<div
|
|
814
|
+
role="tabpanel"
|
|
815
|
+
id={`${uid}-pane-colors`}
|
|
816
|
+
aria-labelledby={`${uid}-tab-colors`}
|
|
817
|
+
data-state={section === "colors" ? "open" : "closed"}
|
|
818
|
+
className="col-start-1 row-start-1 min-h-0 overflow-y-auto transition-opacity duration-200 ease-out data-[state=closed]:pointer-events-none data-[state=closed]:invisible data-[state=closed]:opacity-0"
|
|
819
|
+
>
|
|
820
|
+
<div className="px-lg py-base">
|
|
821
|
+
<div className="flex items-center justify-between gap-md border-b border-hairline-soft pb-base">
|
|
822
|
+
<div className="min-w-0">
|
|
823
|
+
<p className="text-body-sm text-ink">Theme</p>
|
|
824
|
+
<p className="text-caption text-muted">Edit tokens for the selected theme</p>
|
|
825
|
+
</div>
|
|
826
|
+
<div
|
|
827
|
+
role="group"
|
|
828
|
+
aria-label="Theme"
|
|
829
|
+
className="relative grid shrink-0 grid-cols-2 rounded-full bg-primary-soft p-xxs"
|
|
830
|
+
>
|
|
831
|
+
<span
|
|
832
|
+
aria-hidden="true"
|
|
833
|
+
className="absolute inset-y-xxs left-xxs w-[calc(50%-2px)] rounded-full bg-primary transition-transform duration-[220ms] ease-out"
|
|
834
|
+
style={{ transform: theme === "light" ? "translateX(0)" : "translateX(100%)" }}
|
|
835
|
+
/>
|
|
836
|
+
{(["light", "dark"] as ThemeId[]).map((t) => (
|
|
837
|
+
<button
|
|
838
|
+
key={t}
|
|
839
|
+
type="button"
|
|
840
|
+
aria-pressed={theme === t}
|
|
841
|
+
onClick={() => switchTheme(t)}
|
|
842
|
+
className={[
|
|
843
|
+
"relative h-7 w-16 cursor-pointer rounded-full text-caption capitalize transition-colors duration-150 ease-out active:scale-[0.98] focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-focus-blue",
|
|
844
|
+
theme === t ? "text-on-primary" : "text-muted",
|
|
845
|
+
].join(" ")}
|
|
846
|
+
>
|
|
847
|
+
{t}
|
|
848
|
+
</button>
|
|
849
|
+
))}
|
|
850
|
+
</div>
|
|
851
|
+
</div>
|
|
852
|
+
|
|
853
|
+
{COLOR_GROUPS.map((group) => (
|
|
854
|
+
<section key={group.id} aria-labelledby={`${uid}-g-${group.id}`} className="mt-lg">
|
|
855
|
+
<h3 id={`${uid}-g-${group.id}`} className={`${eyebrow} mb-sm`}>
|
|
856
|
+
{group.label}
|
|
857
|
+
</h3>
|
|
858
|
+
<div className="flex flex-col gap-xxs">
|
|
859
|
+
{group.tokens.map((token) => {
|
|
860
|
+
const value = values[token.id];
|
|
861
|
+
const against = values[token.against ?? group.against];
|
|
862
|
+
return (
|
|
863
|
+
<ColorRow
|
|
864
|
+
key={token.id}
|
|
865
|
+
token={token}
|
|
866
|
+
value={value}
|
|
867
|
+
text={hexDrafts[token.id] ?? value}
|
|
868
|
+
changed={value !== savedValues[token.id]}
|
|
869
|
+
invalid={token.id in hexDrafts}
|
|
870
|
+
expanded={expandedId === token.id}
|
|
871
|
+
against={against}
|
|
872
|
+
panelId={`${uid}-editor-${token.id}`}
|
|
873
|
+
onToggle={() => setExpandedId((cur) => (cur === token.id ? null : token.id))}
|
|
874
|
+
onText={(text) => handleText(token.id, text)}
|
|
875
|
+
onBlurText={() => handleBlur(token.id)}
|
|
876
|
+
onPick={(hex) => setColor(token.id, hex)}
|
|
877
|
+
/>
|
|
878
|
+
);
|
|
879
|
+
})}
|
|
880
|
+
</div>
|
|
881
|
+
</section>
|
|
882
|
+
))}
|
|
883
|
+
</div>
|
|
884
|
+
</div>
|
|
885
|
+
|
|
886
|
+
<div
|
|
887
|
+
role="tabpanel"
|
|
888
|
+
id={`${uid}-pane-fonts`}
|
|
889
|
+
aria-labelledby={`${uid}-tab-fonts`}
|
|
890
|
+
data-state={section === "fonts" ? "open" : "closed"}
|
|
891
|
+
className="col-start-1 row-start-1 min-h-0 overflow-y-auto transition-opacity duration-200 ease-out data-[state=closed]:pointer-events-none data-[state=closed]:invisible data-[state=closed]:opacity-0"
|
|
892
|
+
>
|
|
893
|
+
<FontsPane
|
|
894
|
+
draft={draft}
|
|
895
|
+
role={role}
|
|
896
|
+
fonts={fonts}
|
|
897
|
+
onFontRowVisible={onFontRowVisible}
|
|
898
|
+
onRole={setRole}
|
|
899
|
+
onBodyFont={(font) => updateFonts({ bodyFont: font })}
|
|
900
|
+
onHeadingFont={(font) => updateFonts({ headingFont: font })}
|
|
901
|
+
onStyle={handleStyle}
|
|
902
|
+
/>
|
|
903
|
+
</div>
|
|
904
|
+
</div>
|
|
905
|
+
|
|
906
|
+
{/* Footer — always fully visible, pinned below the scrolling body */}
|
|
907
|
+
<footer
|
|
908
|
+
className="sticky bottom-0 z-10 flex shrink-0 items-center justify-between gap-md border-t border-hairline bg-canvas px-lg pt-md"
|
|
909
|
+
style={{ paddingBottom: "calc(var(--spacing-md) + env(safe-area-inset-bottom, 0px))" }}
|
|
910
|
+
>
|
|
911
|
+
<button type="button" disabled={!dirty} onClick={handleDiscard} className={ghostButtonClass}>
|
|
912
|
+
Discard
|
|
913
|
+
</button>
|
|
914
|
+
<button type="button" disabled={!canSave} onClick={requestSave} className={warningButtonClass}>
|
|
915
|
+
Save changes
|
|
916
|
+
</button>
|
|
917
|
+
</footer>
|
|
918
|
+
</section>
|
|
919
|
+
|
|
920
|
+
<Modal
|
|
921
|
+
isOpen={confirmOpen}
|
|
922
|
+
onClose={() => setConfirmOpen(false)}
|
|
923
|
+
title="Apply to the entire design system?"
|
|
924
|
+
size="sm"
|
|
925
|
+
footer={
|
|
926
|
+
<>
|
|
927
|
+
<button type="button" onClick={() => setConfirmOpen(false)} className={ghostButtonClass}>
|
|
928
|
+
Cancel
|
|
929
|
+
</button>
|
|
930
|
+
<button type="button" onClick={confirmSave} className={warningButtonClass}>
|
|
931
|
+
Save changes
|
|
932
|
+
</button>
|
|
933
|
+
</>
|
|
934
|
+
}
|
|
935
|
+
>
|
|
936
|
+
<p className="text-left text-body-sm text-ink">
|
|
937
|
+
These color and font changes affect the entire design system and every component that uses
|
|
938
|
+
these tokens. Make sure you want to apply them before saving.
|
|
939
|
+
</p>
|
|
940
|
+
</Modal>
|
|
941
|
+
</>
|
|
942
|
+
);
|
|
943
|
+
},
|
|
944
|
+
);
|
|
945
|
+
|
|
946
|
+
DesignTokensPanel.displayName = "DesignTokensPanel";
|