@designa8/vibedesign-v6 1.12.17 → 1.15.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/index.cjs +771 -289
- package/dist/index.js +762 -280
- package/dist/styles.css +161 -0
- package/package.json +16 -1
- package/src/atoms/AppLayout/AppLayout.tsx +15 -3
- package/src/atoms/AppLayout/preview.tsx +4 -3
- package/src/atoms/CodeEditor/CodeEditor.tsx +367 -0
- package/src/atoms/CodeEditor/index.ts +2 -0
- package/src/atoms/CodeEditor/preview.tsx +104 -0
- package/src/atoms/FilterTabBar/FilterTabBar.tsx +6 -1
- package/src/atoms/FilterTabBar/preview.tsx +22 -53
- package/src/atoms/Icon/Icon.tsx +35 -0
- package/src/atoms/Icon/icons.data.ts +13 -0
- package/src/atoms/Icon/index.ts +4 -0
- package/src/atoms/Icon/preview.tsx +19 -0
- package/src/atoms/StatusBar/StatusBar.tsx +127 -0
- package/src/atoms/StatusBar/index.ts +2 -0
- package/src/atoms/StatusBar/preview.tsx +52 -0
- package/src/index.ts +3 -0
- package/src/tokens.css +21 -0
|
@@ -0,0 +1,367 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { Icon } from "../Icon";
|
|
3
|
+
import { Button } from "../Button";
|
|
4
|
+
|
|
5
|
+
export type CodeEditorLanguage = "tsx" | "ts" | "css" | "json" | "md" | "txt";
|
|
6
|
+
|
|
7
|
+
export interface CodeEditorFile {
|
|
8
|
+
name: string;
|
|
9
|
+
language: CodeEditorLanguage;
|
|
10
|
+
source: string;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export interface CodeEditorProps {
|
|
14
|
+
files: CodeEditorFile[];
|
|
15
|
+
activeFile?: string;
|
|
16
|
+
onActiveFileChange?: (name: string) => void;
|
|
17
|
+
folderLabel?: string;
|
|
18
|
+
pathPrefix?: string;
|
|
19
|
+
dark?: boolean;
|
|
20
|
+
readOnly?: boolean;
|
|
21
|
+
streamingFileNames?: string[];
|
|
22
|
+
onChange?: (filename: string, source: string) => void;
|
|
23
|
+
onCopy?: () => void;
|
|
24
|
+
className?: string;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const LANG_LABEL: Record<CodeEditorLanguage, string> = {
|
|
28
|
+
tsx: "TSX",
|
|
29
|
+
ts: "TS",
|
|
30
|
+
css: "CSS",
|
|
31
|
+
json: "JSON",
|
|
32
|
+
md: "MD",
|
|
33
|
+
txt: "TXT",
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
function LangBadge({ language }: { language: CodeEditorLanguage }) {
|
|
37
|
+
return (
|
|
38
|
+
<span className="inline-flex h-lg min-w-[1.6rem] items-center justify-center rounded-xs bg-surface-strong px-xxs text-caption text-muted">
|
|
39
|
+
{LANG_LABEL[language]}
|
|
40
|
+
</span>
|
|
41
|
+
);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/* ---------------------------------------------------------------------- */
|
|
45
|
+
/* Syntax highlighting — vivid, VS Code-style token coloring. */
|
|
46
|
+
/* Presentational only: a small line-scoped regex tokenizer per language. */
|
|
47
|
+
/* ---------------------------------------------------------------------- */
|
|
48
|
+
|
|
49
|
+
type SyntaxTokenType =
|
|
50
|
+
| "plain"
|
|
51
|
+
| "comment"
|
|
52
|
+
| "string"
|
|
53
|
+
| "number"
|
|
54
|
+
| "keyword"
|
|
55
|
+
| "function"
|
|
56
|
+
| "type"
|
|
57
|
+
| "tag"
|
|
58
|
+
| "property"
|
|
59
|
+
| "punctuation";
|
|
60
|
+
|
|
61
|
+
const SYNTAX_CLASS: Record<SyntaxTokenType, string> = {
|
|
62
|
+
plain: "text-ink",
|
|
63
|
+
comment: "text-syntax-comment italic",
|
|
64
|
+
string: "text-syntax-string",
|
|
65
|
+
number: "text-syntax-number",
|
|
66
|
+
keyword: "text-syntax-keyword",
|
|
67
|
+
function: "text-syntax-function",
|
|
68
|
+
type: "text-syntax-type",
|
|
69
|
+
tag: "text-syntax-tag",
|
|
70
|
+
property: "text-syntax-property",
|
|
71
|
+
punctuation: "text-muted",
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
type SyntaxToken = { text: string; type: SyntaxTokenType };
|
|
75
|
+
|
|
76
|
+
const JS_KEYWORDS = new Set([
|
|
77
|
+
"import", "export", "default", "from", "const", "let", "var", "function",
|
|
78
|
+
"return", "interface", "type", "extends", "implements", "class", "new",
|
|
79
|
+
"this", "if", "else", "for", "while", "switch", "case", "break", "continue",
|
|
80
|
+
"true", "false", "null", "undefined", "void", "async", "await", "of", "in",
|
|
81
|
+
"as", "public", "private", "protected", "readonly", "static", "enum",
|
|
82
|
+
"namespace", "declare", "try", "catch", "finally", "throw", "yield",
|
|
83
|
+
"typeof", "instanceof", "super",
|
|
84
|
+
]);
|
|
85
|
+
|
|
86
|
+
const TS_TYPES = new Set([
|
|
87
|
+
"string", "number", "boolean", "any", "unknown", "never", "object",
|
|
88
|
+
"React", "Record", "Partial", "Readonly", "Promise", "HTMLDivElement",
|
|
89
|
+
"HTMLButtonElement",
|
|
90
|
+
]);
|
|
91
|
+
|
|
92
|
+
const JS_TOKEN_RE =
|
|
93
|
+
/(\/\/.*)|('(?:\\.|[^'\\])*'|"(?:\\.|[^"\\])*"|`(?:\\.|[^`\\])*`)|(\b\d+(?:\.\d+)?\b)|(<\/?[A-Za-z][\w.]*)|([A-Za-z_$][\w$]*)/g;
|
|
94
|
+
|
|
95
|
+
function tokenizeJs(line: string): SyntaxToken[] {
|
|
96
|
+
const tokens: SyntaxToken[] = [];
|
|
97
|
+
let lastIndex = 0;
|
|
98
|
+
let match: RegExpExecArray | null;
|
|
99
|
+
JS_TOKEN_RE.lastIndex = 0;
|
|
100
|
+
while ((match = JS_TOKEN_RE.exec(line)) !== null) {
|
|
101
|
+
if (match.index > lastIndex) {
|
|
102
|
+
tokens.push({ text: line.slice(lastIndex, match.index), type: "plain" });
|
|
103
|
+
}
|
|
104
|
+
if (match[1] !== undefined) {
|
|
105
|
+
tokens.push({ text: match[1], type: "comment" });
|
|
106
|
+
} else if (match[2] !== undefined) {
|
|
107
|
+
tokens.push({ text: match[2], type: "string" });
|
|
108
|
+
} else if (match[3] !== undefined) {
|
|
109
|
+
tokens.push({ text: match[3], type: "number" });
|
|
110
|
+
} else if (match[4] !== undefined) {
|
|
111
|
+
tokens.push({ text: match[4], type: "tag" });
|
|
112
|
+
} else if (match[5] !== undefined) {
|
|
113
|
+
const word = match[5];
|
|
114
|
+
const after = line.slice(JS_TOKEN_RE.lastIndex).match(/^\s*\(/);
|
|
115
|
+
if (JS_KEYWORDS.has(word)) {
|
|
116
|
+
tokens.push({ text: word, type: "keyword" });
|
|
117
|
+
} else if (TS_TYPES.has(word)) {
|
|
118
|
+
tokens.push({ text: word, type: "type" });
|
|
119
|
+
} else if (after) {
|
|
120
|
+
tokens.push({ text: word, type: "function" });
|
|
121
|
+
} else {
|
|
122
|
+
tokens.push({ text: word, type: "plain" });
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
lastIndex = JS_TOKEN_RE.lastIndex;
|
|
126
|
+
}
|
|
127
|
+
if (lastIndex < line.length) tokens.push({ text: line.slice(lastIndex), type: "plain" });
|
|
128
|
+
return tokens;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
const CSS_TOKEN_RE =
|
|
132
|
+
/(\/\*[\s\S]*?\*\/)|('(?:\\.|[^'\\])*'|"(?:\\.|[^"\\])*")|(@[a-zA-Z-]+)|(#[0-9a-fA-F]{3,8}\b)|(-?\d+\.?\d*(?:px|em|rem|%|deg|s|ms|vh|vw)?\b)|([a-zA-Z-]+)(?=\s*:)/g;
|
|
133
|
+
|
|
134
|
+
function tokenizeCss(line: string): SyntaxToken[] {
|
|
135
|
+
const tokens: SyntaxToken[] = [];
|
|
136
|
+
let lastIndex = 0;
|
|
137
|
+
let match: RegExpExecArray | null;
|
|
138
|
+
CSS_TOKEN_RE.lastIndex = 0;
|
|
139
|
+
while ((match = CSS_TOKEN_RE.exec(line)) !== null) {
|
|
140
|
+
if (match.index > lastIndex) {
|
|
141
|
+
tokens.push({ text: line.slice(lastIndex, match.index), type: "plain" });
|
|
142
|
+
}
|
|
143
|
+
if (match[1] !== undefined) tokens.push({ text: match[1], type: "comment" });
|
|
144
|
+
else if (match[2] !== undefined) tokens.push({ text: match[2], type: "string" });
|
|
145
|
+
else if (match[3] !== undefined) tokens.push({ text: match[3], type: "keyword" });
|
|
146
|
+
else if (match[4] !== undefined) tokens.push({ text: match[4], type: "number" });
|
|
147
|
+
else if (match[5] !== undefined) tokens.push({ text: match[5], type: "number" });
|
|
148
|
+
else if (match[6] !== undefined) tokens.push({ text: match[6], type: "property" });
|
|
149
|
+
lastIndex = CSS_TOKEN_RE.lastIndex;
|
|
150
|
+
}
|
|
151
|
+
if (lastIndex < line.length) tokens.push({ text: line.slice(lastIndex), type: "plain" });
|
|
152
|
+
return tokens;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
const JSON_TOKEN_RE = /("(?:\\.|[^"\\])*")(\s*:)?|(-?\d+(?:\.\d+)?)|\b(true|false|null)\b/g;
|
|
156
|
+
|
|
157
|
+
function tokenizeJson(line: string): SyntaxToken[] {
|
|
158
|
+
const tokens: SyntaxToken[] = [];
|
|
159
|
+
let lastIndex = 0;
|
|
160
|
+
let match: RegExpExecArray | null;
|
|
161
|
+
JSON_TOKEN_RE.lastIndex = 0;
|
|
162
|
+
while ((match = JSON_TOKEN_RE.exec(line)) !== null) {
|
|
163
|
+
if (match.index > lastIndex) {
|
|
164
|
+
tokens.push({ text: line.slice(lastIndex, match.index), type: "plain" });
|
|
165
|
+
}
|
|
166
|
+
if (match[1] !== undefined) {
|
|
167
|
+
const hasColon = match[2] !== undefined;
|
|
168
|
+
tokens.push({ text: match[1], type: hasColon ? "property" : "string" });
|
|
169
|
+
if (hasColon) tokens.push({ text: match[2] as string, type: "punctuation" });
|
|
170
|
+
} else if (match[3] !== undefined) {
|
|
171
|
+
tokens.push({ text: match[3], type: "number" });
|
|
172
|
+
} else if (match[4] !== undefined) {
|
|
173
|
+
tokens.push({ text: match[4], type: "keyword" });
|
|
174
|
+
}
|
|
175
|
+
lastIndex = JSON_TOKEN_RE.lastIndex;
|
|
176
|
+
}
|
|
177
|
+
if (lastIndex < line.length) tokens.push({ text: line.slice(lastIndex), type: "plain" });
|
|
178
|
+
return tokens;
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
const MD_TOKEN_RE = /(^#{1,6}\s.*)|(`[^`]*`)/g;
|
|
182
|
+
|
|
183
|
+
function tokenizeMd(line: string): SyntaxToken[] {
|
|
184
|
+
const tokens: SyntaxToken[] = [];
|
|
185
|
+
let lastIndex = 0;
|
|
186
|
+
let match: RegExpExecArray | null;
|
|
187
|
+
MD_TOKEN_RE.lastIndex = 0;
|
|
188
|
+
while ((match = MD_TOKEN_RE.exec(line)) !== null) {
|
|
189
|
+
if (match.index > lastIndex) {
|
|
190
|
+
tokens.push({ text: line.slice(lastIndex, match.index), type: "plain" });
|
|
191
|
+
}
|
|
192
|
+
if (match[1] !== undefined) tokens.push({ text: match[1], type: "keyword" });
|
|
193
|
+
else if (match[2] !== undefined) tokens.push({ text: match[2], type: "string" });
|
|
194
|
+
lastIndex = MD_TOKEN_RE.lastIndex;
|
|
195
|
+
}
|
|
196
|
+
if (lastIndex < line.length) tokens.push({ text: line.slice(lastIndex), type: "plain" });
|
|
197
|
+
return tokens;
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
function tokenizeLine(line: string, language: CodeEditorLanguage): SyntaxToken[] {
|
|
201
|
+
if (line.length === 0) return [{ text: " ", type: "plain" }];
|
|
202
|
+
switch (language) {
|
|
203
|
+
case "tsx":
|
|
204
|
+
case "ts":
|
|
205
|
+
return tokenizeJs(line);
|
|
206
|
+
case "css":
|
|
207
|
+
return tokenizeCss(line);
|
|
208
|
+
case "json":
|
|
209
|
+
return tokenizeJson(line);
|
|
210
|
+
case "md":
|
|
211
|
+
return tokenizeMd(line);
|
|
212
|
+
default:
|
|
213
|
+
return [{ text: line, type: "plain" }];
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
export const CodeEditor = React.forwardRef<HTMLDivElement, CodeEditorProps>(
|
|
218
|
+
(
|
|
219
|
+
{
|
|
220
|
+
files,
|
|
221
|
+
activeFile,
|
|
222
|
+
onActiveFileChange,
|
|
223
|
+
folderLabel = "atoms",
|
|
224
|
+
pathPrefix,
|
|
225
|
+
dark = false,
|
|
226
|
+
readOnly = true,
|
|
227
|
+
streamingFileNames = [],
|
|
228
|
+
onChange,
|
|
229
|
+
onCopy,
|
|
230
|
+
className = "",
|
|
231
|
+
},
|
|
232
|
+
ref,
|
|
233
|
+
) => {
|
|
234
|
+
const [copied, setCopied] = React.useState(false);
|
|
235
|
+
const [openRoot, setOpenRoot] = React.useState(true);
|
|
236
|
+
const current = files.find((f) => f.name === activeFile) ?? files[0] ?? null;
|
|
237
|
+
const streaming = current ? streamingFileNames.includes(current.name) : false;
|
|
238
|
+
const path = [pathPrefix, current?.name].filter(Boolean).join(" / ");
|
|
239
|
+
|
|
240
|
+
async function copy() {
|
|
241
|
+
if (!current) return;
|
|
242
|
+
try {
|
|
243
|
+
await navigator.clipboard.writeText(current.source);
|
|
244
|
+
} catch {
|
|
245
|
+
// clipboard may be unavailable in sandboxed contexts; ignore
|
|
246
|
+
}
|
|
247
|
+
setCopied(true);
|
|
248
|
+
window.setTimeout(() => setCopied(false), 1200);
|
|
249
|
+
onCopy?.();
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
const lines = (current?.source ?? "").split("\n");
|
|
253
|
+
const statusLabel = streaming ? "Writing" : readOnly ? "Read-only" : "Editing";
|
|
254
|
+
|
|
255
|
+
return (
|
|
256
|
+
<div
|
|
257
|
+
ref={ref}
|
|
258
|
+
data-theme={dark ? "dark" : undefined}
|
|
259
|
+
className={["flex w-full overflow-hidden rounded-lg border border-hairline bg-canvas text-ink", className].join(" ")}
|
|
260
|
+
>
|
|
261
|
+
<aside className="flex w-56 shrink-0 flex-col overflow-y-auto border-r border-hairline bg-canvas">
|
|
262
|
+
<div className="flex items-center justify-between px-lg py-md">
|
|
263
|
+
<span className="text-caption font-weight-heading-sm uppercase tracking-widest text-muted-soft">
|
|
264
|
+
Files
|
|
265
|
+
</span>
|
|
266
|
+
</div>
|
|
267
|
+
<nav className="flex flex-col gap-xxs px-sm pb-lg">
|
|
268
|
+
<Button
|
|
269
|
+
type="button"
|
|
270
|
+
variant="ghost"
|
|
271
|
+
size="sm"
|
|
272
|
+
className="w-full justify-start gap-xs px-sm py-xs text-body-sm text-muted"
|
|
273
|
+
onClick={() => setOpenRoot((o) => !o)}
|
|
274
|
+
>
|
|
275
|
+
<Icon
|
|
276
|
+
name="chevron-down"
|
|
277
|
+
className={["h-3 w-3 shrink-0 transition-transform", openRoot ? "rotate-0" : "-rotate-90"].join(" ")}
|
|
278
|
+
/>
|
|
279
|
+
{folderLabel}
|
|
280
|
+
</Button>
|
|
281
|
+
{openRoot &&
|
|
282
|
+
files.map((f) => (
|
|
283
|
+
<Button
|
|
284
|
+
key={f.name}
|
|
285
|
+
type="button"
|
|
286
|
+
variant="ghost"
|
|
287
|
+
size="sm"
|
|
288
|
+
onClick={() => onActiveFileChange?.(f.name)}
|
|
289
|
+
aria-current={f.name === current?.name ? "true" : undefined}
|
|
290
|
+
className={[
|
|
291
|
+
"w-full justify-start gap-sm py-xs pr-sm pl-lg text-body-sm",
|
|
292
|
+
f.name === current?.name ? "bg-primary-disabled text-primary" : "text-body",
|
|
293
|
+
].join(" ")}
|
|
294
|
+
>
|
|
295
|
+
<LangBadge language={f.language} />
|
|
296
|
+
<span className="truncate">{f.name}</span>
|
|
297
|
+
</Button>
|
|
298
|
+
))}
|
|
299
|
+
</nav>
|
|
300
|
+
</aside>
|
|
301
|
+
|
|
302
|
+
<div className="flex min-w-0 flex-1 flex-col overflow-hidden bg-canvas">
|
|
303
|
+
<div className="flex items-center justify-between border-b border-hairline bg-surface-soft px-lg py-sm">
|
|
304
|
+
<div className="flex min-w-0 items-center gap-sm font-mono text-caption text-muted">
|
|
305
|
+
{current ? <LangBadge language={current.language} /> : null}
|
|
306
|
+
<span className="truncate">{path}</span>
|
|
307
|
+
<span className="rounded-xs bg-surface-strong px-sm py-xxs text-caption font-weight-heading-sm uppercase tracking-wide text-muted">
|
|
308
|
+
{statusLabel}
|
|
309
|
+
</span>
|
|
310
|
+
</div>
|
|
311
|
+
<Button
|
|
312
|
+
type="button"
|
|
313
|
+
variant="secondary"
|
|
314
|
+
size="sm"
|
|
315
|
+
onClick={() => void copy()}
|
|
316
|
+
disabled={!current || streaming}
|
|
317
|
+
>
|
|
318
|
+
<Icon name={copied ? "check-checkmark" : "copy-clipboard"} className="h-3 w-3" />
|
|
319
|
+
{copied ? "Copied" : "Copy"}
|
|
320
|
+
</Button>
|
|
321
|
+
</div>
|
|
322
|
+
|
|
323
|
+
<div className="flex-1 overflow-auto bg-canvas">
|
|
324
|
+
{readOnly || streaming ? (
|
|
325
|
+
<pre className="m-0 p-0 text-body-sm leading-[1.55] text-ink">
|
|
326
|
+
{lines.map((line, i) => (
|
|
327
|
+
<div key={i} className="flex">
|
|
328
|
+
<span className="select-none px-md text-right text-caption text-muted-soft">
|
|
329
|
+
<span className="inline-block min-w-[2ch]">{i + 1}</span>
|
|
330
|
+
</span>
|
|
331
|
+
<span className="flex-1 whitespace-pre pr-xl font-mono">
|
|
332
|
+
{current
|
|
333
|
+
? tokenizeLine(line, current.language).map((tok, ti) => (
|
|
334
|
+
<span key={ti} className={SYNTAX_CLASS[tok.type]}>
|
|
335
|
+
{tok.text}
|
|
336
|
+
</span>
|
|
337
|
+
))
|
|
338
|
+
: line || " "}
|
|
339
|
+
</span>
|
|
340
|
+
</div>
|
|
341
|
+
))}
|
|
342
|
+
</pre>
|
|
343
|
+
) : (
|
|
344
|
+
<div className="flex min-h-full">
|
|
345
|
+
<div className="select-none px-md py-sm text-right text-caption text-muted-soft">
|
|
346
|
+
{lines.map((_, i) => (
|
|
347
|
+
<div key={i}>{i + 1}</div>
|
|
348
|
+
))}
|
|
349
|
+
</div>
|
|
350
|
+
<textarea
|
|
351
|
+
className="min-h-full flex-1 resize-none bg-transparent p-sm font-mono text-body-sm leading-[1.55] text-ink outline-none"
|
|
352
|
+
value={current?.source ?? ""}
|
|
353
|
+
spellCheck={false}
|
|
354
|
+
onChange={(e) => {
|
|
355
|
+
if (current) onChange?.(current.name, e.target.value);
|
|
356
|
+
}}
|
|
357
|
+
/>
|
|
358
|
+
</div>
|
|
359
|
+
)}
|
|
360
|
+
</div>
|
|
361
|
+
</div>
|
|
362
|
+
</div>
|
|
363
|
+
);
|
|
364
|
+
},
|
|
365
|
+
);
|
|
366
|
+
|
|
367
|
+
CodeEditor.displayName = "CodeEditor";
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { CodeEditor, type CodeEditorFile } from "./CodeEditor";
|
|
3
|
+
|
|
4
|
+
const files: CodeEditorFile[] = [
|
|
5
|
+
{
|
|
6
|
+
name: "Widget.tsx",
|
|
7
|
+
language: "tsx",
|
|
8
|
+
source: `import React from "react";
|
|
9
|
+
|
|
10
|
+
export function Widget(props: { label: string }) {
|
|
11
|
+
return <div className="bg-primary text-on-primary">{props.label}</div>;
|
|
12
|
+
}
|
|
13
|
+
`,
|
|
14
|
+
},
|
|
15
|
+
{
|
|
16
|
+
name: "index.ts",
|
|
17
|
+
language: "ts",
|
|
18
|
+
source: `export { Widget } from "./Widget";
|
|
19
|
+
`,
|
|
20
|
+
},
|
|
21
|
+
{
|
|
22
|
+
name: "styles.css",
|
|
23
|
+
language: "css",
|
|
24
|
+
source: `.widget {
|
|
25
|
+
border-radius: var(--radius-md);
|
|
26
|
+
padding: var(--spacing-sm) var(--spacing-md);
|
|
27
|
+
}
|
|
28
|
+
`,
|
|
29
|
+
},
|
|
30
|
+
{
|
|
31
|
+
name: "README.md",
|
|
32
|
+
language: "md",
|
|
33
|
+
source: `# Widget
|
|
34
|
+
|
|
35
|
+
A small display element.
|
|
36
|
+
`,
|
|
37
|
+
},
|
|
38
|
+
];
|
|
39
|
+
|
|
40
|
+
export default function CodeEditorPreview() {
|
|
41
|
+
const [active, setActive] = React.useState("Widget.tsx");
|
|
42
|
+
const [source, setSource] = React.useState(files[0].source);
|
|
43
|
+
|
|
44
|
+
return (
|
|
45
|
+
<div className="w-full max-w-3xl mx-auto p-lg space-y-lg">
|
|
46
|
+
<div>
|
|
47
|
+
<p className="mb-sm text-caption font-weight-heading-sm uppercase tracking-widest text-muted-soft">
|
|
48
|
+
Read-only, light
|
|
49
|
+
</p>
|
|
50
|
+
<CodeEditor
|
|
51
|
+
className="min-h-[22rem]"
|
|
52
|
+
files={files}
|
|
53
|
+
activeFile={active}
|
|
54
|
+
onActiveFileChange={setActive}
|
|
55
|
+
pathPrefix="src/components"
|
|
56
|
+
readOnly
|
|
57
|
+
/>
|
|
58
|
+
</div>
|
|
59
|
+
|
|
60
|
+
<div>
|
|
61
|
+
<p className="mb-sm text-caption font-weight-heading-sm uppercase tracking-widest text-muted-soft">
|
|
62
|
+
Streaming (writing)
|
|
63
|
+
</p>
|
|
64
|
+
<CodeEditor
|
|
65
|
+
className="min-h-[17rem]"
|
|
66
|
+
files={files}
|
|
67
|
+
activeFile="Widget.tsx"
|
|
68
|
+
pathPrefix="src/components"
|
|
69
|
+
readOnly
|
|
70
|
+
streamingFileNames={["Widget.tsx"]}
|
|
71
|
+
/>
|
|
72
|
+
</div>
|
|
73
|
+
|
|
74
|
+
<div>
|
|
75
|
+
<p className="mb-sm text-caption font-weight-heading-sm uppercase tracking-widest text-muted-soft">
|
|
76
|
+
Editable
|
|
77
|
+
</p>
|
|
78
|
+
<CodeEditor
|
|
79
|
+
className="min-h-[17rem]"
|
|
80
|
+
files={[{ name: "Widget.tsx", language: "tsx", source }]}
|
|
81
|
+
activeFile="Widget.tsx"
|
|
82
|
+
pathPrefix="src/components"
|
|
83
|
+
readOnly={false}
|
|
84
|
+
onChange={(_, next) => setSource(next)}
|
|
85
|
+
/>
|
|
86
|
+
</div>
|
|
87
|
+
|
|
88
|
+
<div>
|
|
89
|
+
<p className="mb-sm text-caption font-weight-heading-sm uppercase tracking-widest text-muted-soft">
|
|
90
|
+
Dark mode
|
|
91
|
+
</p>
|
|
92
|
+
<CodeEditor
|
|
93
|
+
className="min-h-[22rem]"
|
|
94
|
+
files={files}
|
|
95
|
+
activeFile={active}
|
|
96
|
+
onActiveFileChange={setActive}
|
|
97
|
+
pathPrefix="src/components"
|
|
98
|
+
readOnly
|
|
99
|
+
dark
|
|
100
|
+
/>
|
|
101
|
+
</div>
|
|
102
|
+
</div>
|
|
103
|
+
);
|
|
104
|
+
}
|
|
@@ -38,6 +38,7 @@ export const FilterTabBar = React.forwardRef<HTMLDivElement, FilterTabBarProps>(
|
|
|
38
38
|
>
|
|
39
39
|
{tabs.map((tab) => {
|
|
40
40
|
const isActive = tab.value === value;
|
|
41
|
+
const isIconOnly = Boolean(tab.icon) && !tab.label;
|
|
41
42
|
|
|
42
43
|
return (
|
|
43
44
|
<Button
|
|
@@ -48,7 +49,11 @@ export const FilterTabBar = React.forwardRef<HTMLDivElement, FilterTabBarProps>(
|
|
|
48
49
|
variant={isActive ? "primary" : "ghost"}
|
|
49
50
|
size="sm"
|
|
50
51
|
onClick={() => onChange(tab.value)}
|
|
51
|
-
className=
|
|
52
|
+
className={
|
|
53
|
+
isIconOnly
|
|
54
|
+
? "gap-xs p-xs aspect-square leading-none"
|
|
55
|
+
: "gap-xs"
|
|
56
|
+
}
|
|
52
57
|
>
|
|
53
58
|
{tab.icon && (
|
|
54
59
|
<span className="inline-flex items-center justify-center shrink-0" aria-hidden="true">
|
|
@@ -1,46 +1,6 @@
|
|
|
1
1
|
import React, { useState } from "react";
|
|
2
2
|
import { FilterTabBar } from "./FilterTabBar";
|
|
3
|
-
|
|
4
|
-
/* Minimal inline SVG icons — no external deps */
|
|
5
|
-
const IconGrid = () => (
|
|
6
|
-
<svg width="14" height="14" viewBox="0 0 16 16" fill="none" aria-hidden="true">
|
|
7
|
-
<rect x="1" y="1" width="6" height="6" rx="1.5" fill="currentColor" />
|
|
8
|
-
<rect x="9" y="1" width="6" height="6" rx="1.5" fill="currentColor" />
|
|
9
|
-
<rect x="1" y="9" width="6" height="6" rx="1.5" fill="currentColor" />
|
|
10
|
-
<rect x="9" y="9" width="6" height="6" rx="1.5" fill="currentColor" />
|
|
11
|
-
</svg>
|
|
12
|
-
);
|
|
13
|
-
|
|
14
|
-
const IconAtom = () => (
|
|
15
|
-
<svg width="14" height="14" viewBox="0 0 16 16" fill="none" aria-hidden="true">
|
|
16
|
-
<circle cx="8" cy="8" r="2" fill="currentColor" />
|
|
17
|
-
<ellipse cx="8" cy="8" rx="7" ry="3" stroke="currentColor" strokeWidth="1.25" fill="none" />
|
|
18
|
-
<ellipse cx="8" cy="8" rx="7" ry="3" stroke="currentColor" strokeWidth="1.25" fill="none" transform="rotate(60 8 8)" />
|
|
19
|
-
<ellipse cx="8" cy="8" rx="7" ry="3" stroke="currentColor" strokeWidth="1.25" fill="none" transform="rotate(120 8 8)" />
|
|
20
|
-
</svg>
|
|
21
|
-
);
|
|
22
|
-
|
|
23
|
-
const IconLayers = () => (
|
|
24
|
-
<svg width="14" height="14" viewBox="0 0 16 16" fill="none" aria-hidden="true">
|
|
25
|
-
<path d="M8 1L15 5L8 9L1 5L8 1Z" fill="currentColor" opacity="0.4" />
|
|
26
|
-
<path d="M1 8L8 12L15 8" stroke="currentColor" strokeWidth="1.5" strokeLinecap="round" fill="none" />
|
|
27
|
-
<path d="M1 11L8 15L15 11" stroke="currentColor" strokeWidth="1.5" strokeLinecap="round" fill="none" />
|
|
28
|
-
</svg>
|
|
29
|
-
);
|
|
30
|
-
|
|
31
|
-
const IconStar = () => (
|
|
32
|
-
<svg width="14" height="14" viewBox="0 0 16 16" fill="currentColor" aria-hidden="true">
|
|
33
|
-
<path d="M8 1l1.854 4.146H14l-3.427 2.708 1.31 4.146L8 9.764l-3.883 2.236 1.31-4.146L2 5.146h4.146L8 1z" />
|
|
34
|
-
</svg>
|
|
35
|
-
);
|
|
36
|
-
|
|
37
|
-
const IconArchive = () => (
|
|
38
|
-
<svg width="14" height="14" viewBox="0 0 16 16" fill="none" aria-hidden="true">
|
|
39
|
-
<rect x="1" y="1" width="14" height="3" rx="1" fill="currentColor" opacity="0.5" />
|
|
40
|
-
<path d="M2 5h12v8a1 1 0 01-1 1H3a1 1 0 01-1-1V5z" fill="currentColor" opacity="0.3" />
|
|
41
|
-
<path d="M6 8h4" stroke="currentColor" strokeWidth="1.5" strokeLinecap="round" />
|
|
42
|
-
</svg>
|
|
43
|
-
);
|
|
3
|
+
import { Icon } from "../Icon";
|
|
44
4
|
|
|
45
5
|
const tabsWithCounts = [
|
|
46
6
|
{ value: "all", label: "All", count: 15 },
|
|
@@ -50,15 +10,9 @@ const tabsWithCounts = [
|
|
|
50
10
|
];
|
|
51
11
|
|
|
52
12
|
const tabsWithIcons = [
|
|
53
|
-
{ value: "all", label: "All", icon: <
|
|
54
|
-
{ value: "atoms", label: "Atoms", icon: <
|
|
55
|
-
{ value: "molecules", label: "Molecules", icon: <
|
|
56
|
-
];
|
|
57
|
-
|
|
58
|
-
const tabsIconOnly = [
|
|
59
|
-
{ value: "all", icon: <IconGrid />, label: "All" },
|
|
60
|
-
{ value: "starred", icon: <IconStar />, label: "Starred" },
|
|
61
|
-
{ value: "archived", icon: <IconArchive />, label: "Archived" },
|
|
13
|
+
{ value: "all", label: "All", icon: <Icon name="grid" size={14} /> },
|
|
14
|
+
{ value: "atoms", label: "Atoms", icon: <Icon name="atom" size={14} />, count: 8 },
|
|
15
|
+
{ value: "molecules", label: "Molecules", icon: <Icon name="layers" size={14} />, count: 2 },
|
|
62
16
|
];
|
|
63
17
|
|
|
64
18
|
export default function FilterTabBarPreview() {
|
|
@@ -66,6 +20,7 @@ export default function FilterTabBarPreview() {
|
|
|
66
20
|
const [active2, setActive2] = useState("all");
|
|
67
21
|
const [active3, setActive3] = useState("all");
|
|
68
22
|
const [active4, setActive4] = useState("all");
|
|
23
|
+
const [active5, setActive5] = useState("all");
|
|
69
24
|
|
|
70
25
|
return (
|
|
71
26
|
<div className="w-full max-w-3xl mx-auto p-xl flex flex-col items-start gap-xl bg-canvas py-xxl">
|
|
@@ -86,9 +41,9 @@ export default function FilterTabBarPreview() {
|
|
|
86
41
|
<p className="text-caption text-muted uppercase tracking-wide">Icon + label + count</p>
|
|
87
42
|
<FilterTabBar
|
|
88
43
|
tabs={[
|
|
89
|
-
{ value: "all", label: "All", icon: <
|
|
90
|
-
{ value: "atoms", label: "Atoms", icon: <
|
|
91
|
-
{ value: "molecules", label: "Molecules", icon: <
|
|
44
|
+
{ value: "all", label: "All", icon: <Icon name="grid" size={14} />, count: 15 },
|
|
45
|
+
{ value: "atoms", label: "Atoms", icon: <Icon name="atom" size={14} />, count: 8 },
|
|
46
|
+
{ value: "molecules", label: "Molecules", icon: <Icon name="layers" size={14} />, count: 2 },
|
|
92
47
|
]}
|
|
93
48
|
value={active3}
|
|
94
49
|
onChange={setActive3}
|
|
@@ -108,6 +63,20 @@ export default function FilterTabBarPreview() {
|
|
|
108
63
|
onChange={setActive4}
|
|
109
64
|
/>
|
|
110
65
|
</div>
|
|
66
|
+
|
|
67
|
+
{/* Icon only, no label (compact square tabs — matches labeled tab height) */}
|
|
68
|
+
<div className="flex flex-col gap-sm w-full">
|
|
69
|
+
<p className="text-caption text-muted uppercase tracking-wide">Icon only (compact)</p>
|
|
70
|
+
<FilterTabBar
|
|
71
|
+
tabs={[
|
|
72
|
+
{ value: "all", icon: <Icon name="grid" size={14} /> },
|
|
73
|
+
{ value: "starred", icon: <Icon name="star" size={14} /> },
|
|
74
|
+
{ value: "archived", icon: <Icon name="archive" size={14} /> },
|
|
75
|
+
]}
|
|
76
|
+
value={active5}
|
|
77
|
+
onChange={setActive5}
|
|
78
|
+
/>
|
|
79
|
+
</div>
|
|
111
80
|
</div>
|
|
112
81
|
);
|
|
113
82
|
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import { ICON_REGISTRY, type IconName } from "./icons.data";
|
|
3
|
+
|
|
4
|
+
export interface IconProps extends React.SVGProps<SVGSVGElement> {
|
|
5
|
+
name: IconName;
|
|
6
|
+
size?: number;
|
|
7
|
+
strokeWidth?: number;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export const Icon = React.forwardRef<SVGSVGElement, IconProps>(
|
|
11
|
+
({ name, size = 20, strokeWidth = 2, className, ...props }, ref) => {
|
|
12
|
+
const glyph = ICON_REGISTRY[name];
|
|
13
|
+
return (
|
|
14
|
+
<svg
|
|
15
|
+
ref={ref}
|
|
16
|
+
viewBox={glyph.viewBox}
|
|
17
|
+
width={size}
|
|
18
|
+
height={size}
|
|
19
|
+
fill="none"
|
|
20
|
+
stroke="currentColor"
|
|
21
|
+
strokeWidth={strokeWidth}
|
|
22
|
+
strokeLinecap="round"
|
|
23
|
+
strokeLinejoin="round"
|
|
24
|
+
className={className}
|
|
25
|
+
aria-hidden="true"
|
|
26
|
+
{...props}
|
|
27
|
+
>
|
|
28
|
+
{glyph.paths.map((d, i) => (
|
|
29
|
+
<path key={i} d={d} />
|
|
30
|
+
))}
|
|
31
|
+
</svg>
|
|
32
|
+
);
|
|
33
|
+
},
|
|
34
|
+
);
|
|
35
|
+
Icon.displayName = "Icon";
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export const ICON_REGISTRY = {
|
|
2
|
+
"close": { viewBox: "0 0 24 24", paths: ["M18 6 6 18", "M6 6l12 12"] },
|
|
3
|
+
"chevron-down": { viewBox: "0 0 24 24", paths: ["M6 9l6 6 6-6"] },
|
|
4
|
+
"copy-clipboard": { viewBox: "0 0 24 24", paths: ["M9 9h10v10H9z", "M5 15V5h10"] },
|
|
5
|
+
"check-checkmark": { viewBox: "0 0 24 24", paths: ["M5 13l4 4L19 7"] },
|
|
6
|
+
"grid": { viewBox: "0 0 24 24", paths: ["M4 4h6v6H4z", "M14 4h6v6h-6z", "M4 14h6v6H4z", "M14 14h6v6h-6z"] },
|
|
7
|
+
"atom": { viewBox: "0 0 24 24", paths: ["M12 12m-1.5 0a1.5 1.5 0 1 0 3 0a1.5 1.5 0 1 0 -3 0", "M12 3.5c4 0 8 3.6 8 8.5s-4 8.5-8 8.5", "M12 3.5c-4 1.8-8 5.6-8 8.5s4 6.7 8 8.5", "M4 8.5c1.8-4 5.6-5 8-5s6.2 1 8 5"] },
|
|
8
|
+
"layers": { viewBox: "0 0 24 24", paths: ["M12 3l8 4.5-8 4.5-8-4.5 8-4.5z", "M4 12l8 4.5 8-4.5", "M4 16.5l8 4.5 8-4.5"] },
|
|
9
|
+
"star": { viewBox: "0 0 24 24", paths: ["M12 3l2.6 5.6 6.1.7-4.5 4.2 1.2 6-5.4-3-5.4 3 1.2-6-4.5-4.2 6.1-.7L12 3z"] },
|
|
10
|
+
"archive": { viewBox: "0 0 24 24", paths: ["M3 4h18v4H3z", "M4.5 8v11a1 1 0 0 0 1 1h13a1 1 0 0 0 1-1V8", "M10 12.5h4"] },
|
|
11
|
+
} as const;
|
|
12
|
+
|
|
13
|
+
export type IconName = keyof typeof ICON_REGISTRY;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import { Icon } from "./Icon";
|
|
3
|
+
import { ICON_REGISTRY } from "./icons.data";
|
|
4
|
+
|
|
5
|
+
export default function IconPreview() {
|
|
6
|
+
const names = Object.keys(ICON_REGISTRY) as (keyof typeof ICON_REGISTRY)[];
|
|
7
|
+
return (
|
|
8
|
+
<div className="w-full max-w-3xl mx-auto p-lg">
|
|
9
|
+
<div className="grid grid-cols-4 gap-md">
|
|
10
|
+
{names.map((name) => (
|
|
11
|
+
<div key={name} className="flex flex-col items-center gap-xs">
|
|
12
|
+
<Icon name={name} size={24} />
|
|
13
|
+
<span className="text-body-sm text-muted">{name}</span>
|
|
14
|
+
</div>
|
|
15
|
+
))}
|
|
16
|
+
</div>
|
|
17
|
+
</div>
|
|
18
|
+
);
|
|
19
|
+
}
|