@designa8/vibedesign-linear-internal-v1-b737 0.3.0 → 0.5.0

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.
@@ -0,0 +1,135 @@
1
+ import * as React from "react";
2
+ import { CodeEditor, type CodeEditorFile } from "./CodeEditor";
3
+
4
+ const SHELL_TSX = `import * as React from "react";
5
+
6
+ export interface CardShellProps {
7
+ title: string;
8
+ count?: number;
9
+ }
10
+
11
+ // Composed panel used across the gallery.
12
+ export const CardShell = ({ title, count = 0 }: CardShellProps) => {
13
+ const label = \`\${title} (\${count})\`;
14
+ return (
15
+ <div className="rounded-lg border border-hairline p-base">
16
+ <header>{label}</header>
17
+ </div>
18
+ );
19
+ };
20
+ CardShell.displayName = "CardShell";`;
21
+
22
+ const TOKENS_CSS = `/* Generated from the token source of truth. */
23
+ :root {
24
+ --color-primary: var(--brand-core);
25
+ --color-canvas: var(--neutral-0);
26
+ --radius-md: 8px;
27
+ --space-md: 12px;
28
+ }
29
+
30
+ [data-theme="dark"] {
31
+ --color-canvas: var(--neutral-1000);
32
+ --color-primary: var(--brand-core-light);
33
+ }`;
34
+
35
+ const MANIFEST_JSON = `{
36
+ "name": "atoms",
37
+ "version": "2.4.0",
38
+ "components": 94,
39
+ "stable": true,
40
+ "registry": null
41
+ }`;
42
+
43
+ const NOTES_MD = `# CardShell
44
+
45
+ The default panel in the system. \`title\` renders the header and
46
+ \`count\` renders a muted tally beside it.
47
+
48
+ ## States
49
+ - enabled
50
+ - hover
51
+ - disabled`;
52
+
53
+ const FILES: CodeEditorFile[] = [
54
+ { name: "CardShell.tsx", language: "tsx", source: SHELL_TSX },
55
+ { name: "tokens.css", language: "css", source: TOKENS_CSS },
56
+ { name: "manifest.json", language: "json", source: MANIFEST_JSON },
57
+ { name: "NOTES.md", language: "md", source: NOTES_MD },
58
+ ];
59
+
60
+ export default function CodeEditorPreview() {
61
+ const [active, setActive] = React.useState("CardShell.tsx");
62
+ const [copies, setCopies] = React.useState(0);
63
+ const [draft, setDraft] = React.useState<Record<string, string>>(() =>
64
+ Object.fromEntries(FILES.map((file) => [file.name, file.source])),
65
+ );
66
+
67
+ const files = FILES.map((file) => ({
68
+ ...file,
69
+ source: draft[file.name] ?? file.source,
70
+ }));
71
+
72
+ return (
73
+ <div className="mx-auto w-full max-w-3xl space-y-lg p-lg">
74
+ <section className="space-y-sm">
75
+ <p className="text-overline text-muted-soft">Read-only viewer</p>
76
+ <CodeEditor
77
+ files={files}
78
+ activeFile={active}
79
+ onActiveFileChange={setActive}
80
+ folderLabel="atoms"
81
+ pathPrefix="atoms / CardShell"
82
+ onCopy={() => setCopies((count) => count + 1)}
83
+ className="h-96 max-h-96 min-h-0"
84
+ />
85
+ <p className="text-caption text-muted" aria-live="polite">
86
+ {copies === 0
87
+ ? "Pick a file, then copy it — the button flips to Copied."
88
+ : `Copied ${copies} ${copies === 1 ? "time" : "times"} to the clipboard.`}
89
+ </p>
90
+ </section>
91
+
92
+ <section className="space-y-sm">
93
+ <p className="text-overline text-muted-soft">Writing (streaming) state</p>
94
+ <CodeEditor
95
+ files={files}
96
+ activeFile="tokens.css"
97
+ onActiveFileChange={() => {}}
98
+ folderLabel="tokens"
99
+ pathPrefix="tokens / generated"
100
+ streamingFileNames={["tokens.css"]}
101
+ className="h-80 max-h-80 min-h-0"
102
+ />
103
+ </section>
104
+
105
+ <section className="space-y-sm">
106
+ <p className="text-overline text-muted-soft">Editable with line gutter</p>
107
+ <CodeEditor
108
+ files={files}
109
+ activeFile={active}
110
+ onActiveFileChange={setActive}
111
+ folderLabel="atoms"
112
+ pathPrefix="atoms / CardShell"
113
+ readOnly={false}
114
+ onChange={(name, source) =>
115
+ setDraft((prev) => ({ ...prev, [name]: source }))
116
+ }
117
+ className="h-80 max-h-80 min-h-0"
118
+ />
119
+ </section>
120
+
121
+ <section className="space-y-sm">
122
+ <p className="text-overline text-muted-soft">Scoped dark theme</p>
123
+ <CodeEditor
124
+ files={files}
125
+ activeFile="manifest.json"
126
+ onActiveFileChange={() => {}}
127
+ folderLabel="config"
128
+ pathPrefix="config / manifest"
129
+ dark
130
+ className="h-80 max-h-80 min-h-0"
131
+ />
132
+ </section>
133
+ </div>
134
+ );
135
+ }
@@ -0,0 +1,161 @@
1
+ import * as React from "react";
2
+ import { Button } from "../Button";
3
+ import { Icon } from "../Icon";
4
+ import { Spinner } from "../Spinner";
5
+
6
+ export interface CodePreviewLine {
7
+ /** The raw text of the line, rendered verbatim (no syntax highlighting). */
8
+ text: string;
9
+ /**
10
+ * `heading` is an emphasised line — brand color at medium weight, used for
11
+ * section titles inside a rendered document. `default` is body text.
12
+ */
13
+ tone?: "heading" | "default";
14
+ }
15
+
16
+ export interface CodePreviewProps
17
+ extends Omit<React.HTMLAttributes<HTMLDivElement>, "onCopy"> {
18
+ /** Lines to render. Pass `text` instead for a plain block. */
19
+ lines?: CodePreviewLine[];
20
+ /** Convenience alternative to `lines`: split on newlines. */
21
+ text?: string;
22
+ /** Right-aligned, muted line numbers in a fixed gutter. */
23
+ lineNumbers?: boolean;
24
+ /** Shows the Copy button in the top-right corner. */
25
+ copyable?: boolean;
26
+ /** Called after the text was copied successfully. */
27
+ onCopy?: () => void;
28
+ /** Lays a canvas overlay with a spinner and `loadingLabel` over the panel. */
29
+ loading?: boolean;
30
+ /** Message shown by the loading overlay. Also its accessible name. */
31
+ loadingLabel?: string;
32
+ /** Caps the height of the panel and scrolls vertically. Default true. */
33
+ capped?: boolean;
34
+ /** Wrap long lines instead of scrolling horizontally. */
35
+ wrap?: boolean;
36
+ }
37
+
38
+ const cn = (...parts: Array<string | false | null | undefined>) =>
39
+ parts.filter(Boolean).join(" ");
40
+
41
+ export const CodePreview = React.forwardRef<HTMLDivElement, CodePreviewProps>(
42
+ (
43
+ {
44
+ lines,
45
+ text,
46
+ lineNumbers = false,
47
+ copyable = false,
48
+ onCopy,
49
+ loading = false,
50
+ loadingLabel = "Loading preview…",
51
+ capped = true,
52
+ wrap = false,
53
+ className,
54
+ "aria-label": ariaLabel = "Code preview",
55
+ ...rest
56
+ },
57
+ ref,
58
+ ) => {
59
+ const rows = React.useMemo<CodePreviewLine[]>(
60
+ () => lines ?? (text ?? "").split("\n").map((line) => ({ text: line })),
61
+ [lines, text],
62
+ );
63
+
64
+ const [copied, setCopied] = React.useState(false);
65
+ const resetTimer = React.useRef<number | undefined>(undefined);
66
+
67
+ React.useEffect(
68
+ () => () => {
69
+ if (resetTimer.current) window.clearTimeout(resetTimer.current);
70
+ },
71
+ [],
72
+ );
73
+
74
+ const handleCopy = () => {
75
+ const value = rows.map((row) => row.text).join("\n");
76
+ if (typeof navigator === "undefined" || !navigator.clipboard) return;
77
+ navigator.clipboard
78
+ .writeText(value)
79
+ .then(() => {
80
+ setCopied(true);
81
+ if (resetTimer.current) window.clearTimeout(resetTimer.current);
82
+ resetTimer.current = window.setTimeout(() => setCopied(false), 1600);
83
+ onCopy?.();
84
+ })
85
+ .catch(() => {
86
+ /* clipboard unavailable — leave the label unchanged */
87
+ });
88
+ };
89
+
90
+ return (
91
+ <div
92
+ ref={ref}
93
+ aria-label={ariaLabel}
94
+ aria-busy={loading || undefined}
95
+ className={cn(
96
+ "relative w-full overflow-hidden rounded-md border border-hairline bg-surface-soft",
97
+ className,
98
+ )}
99
+ {...rest}
100
+ >
101
+ {copyable ? (
102
+ <div className="flex items-center justify-end px-sm pt-sm">
103
+ <Button
104
+ variant="ghost"
105
+ size="sm"
106
+ onClick={handleCopy}
107
+ aria-label={copied ? "Copied to clipboard" : "Copy to clipboard"}
108
+ leadingIcon={<Icon name={copied ? "check" : "copy"} size={14} />}
109
+ >
110
+ <span aria-hidden="true">{copied ? "Copied" : "Copy"}</span>
111
+ </Button>
112
+ </div>
113
+ ) : null}
114
+
115
+ <div
116
+ tabIndex={capped ? 0 : undefined}
117
+ role={capped ? "region" : undefined}
118
+ aria-label={capped ? ariaLabel : undefined}
119
+ className={cn(
120
+ "px-md py-sm font-mono text-caption focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-focus-blue",
121
+ capped && "max-h-64 overflow-y-auto overscroll-contain",
122
+ !wrap && "overflow-x-auto",
123
+ )}
124
+ >
125
+ {rows.map((line, index) => (
126
+ <div key={index} className="flex gap-md">
127
+ {lineNumbers ? (
128
+ <span
129
+ aria-hidden="true"
130
+ className="w-lg shrink-0 select-none text-right text-muted-soft"
131
+ >
132
+ {index + 1}
133
+ </span>
134
+ ) : null}
135
+ <span
136
+ className={cn(
137
+ wrap ? "min-w-0 whitespace-pre-wrap break-words" : "whitespace-pre",
138
+ line.tone === "heading"
139
+ ? "font-weight-label text-primary"
140
+ : "text-body",
141
+ )}
142
+ >
143
+ {line.text || "\u00A0"}
144
+ </span>
145
+ </div>
146
+ ))}
147
+ </div>
148
+
149
+ {/* Stays mounted so the overlay can fade in and out. */}
150
+ <div
151
+ aria-hidden={loading ? undefined : "true"}
152
+ data-state={loading ? "open" : "closed"}
153
+ className="pointer-events-none absolute inset-0 flex items-center justify-center bg-canvas/90 transition-opacity duration-200 ease-out data-[state=open]:opacity-100 data-[state=closed]:opacity-0"
154
+ >
155
+ <Spinner size="sm" label={loading ? loadingLabel : undefined} />
156
+ </div>
157
+ </div>
158
+ );
159
+ },
160
+ );
161
+ CodePreview.displayName = "CodePreview";
@@ -0,0 +1,2 @@
1
+ export { CodePreview } from "./CodePreview";
2
+ export type { CodePreviewProps, CodePreviewLine } from "./CodePreview";
@@ -0,0 +1,74 @@
1
+ import * as React from "react";
2
+ import { CodePreview } from "./CodePreview";
3
+ import type { CodePreviewLine } from "./CodePreview";
4
+ import { Button } from "../Button";
5
+
6
+ const installLines: CodePreviewLine[] = [
7
+ { text: "npm install @acme/design-system", tone: "heading" },
8
+ { text: 'import { Button } from "@acme/design-system";' },
9
+ ];
10
+
11
+ const documentLines: CodePreviewLine[] = [
12
+ { text: "## Surface", tone: "heading" },
13
+ { text: "Cards sit on `canvas` and lift with `surface` plus a hairline border." },
14
+ { text: "" },
15
+ { text: "## Typography", tone: "heading" },
16
+ { text: "Body copy uses the `body-md` role; captions use `caption`." },
17
+ ];
18
+
19
+ const pathLines: CodePreviewLine[] = [
20
+ { text: "design-system/" },
21
+ { text: " tokens.json" },
22
+ { text: " components/" },
23
+ { text: " Button.tsx" },
24
+ { text: " CodePreview.tsx" },
25
+ ];
26
+
27
+ export default function CodePreviewPreview() {
28
+ const [loading, setLoading] = React.useState(false);
29
+ const [copyCount, setCopyCount] = React.useState(0);
30
+
31
+ return (
32
+ <div className="w-full max-w-3xl mx-auto p-lg space-y-lg bg-canvas text-ink">
33
+ <section className="space-y-sm">
34
+ <p className="text-label text-muted">Install command with copy</p>
35
+ <CodePreview lines={installLines} copyable onCopy={() => setCopyCount((n) => n + 1)} />
36
+ <p className="text-caption text-muted-soft">Copy events: {copyCount}</p>
37
+ </section>
38
+
39
+ <section className="space-y-sm">
40
+ <p className="text-label text-muted">Numbered, wrapped document</p>
41
+ <CodePreview text={documentLines.map((l) => l.text).join("\n")} lineNumbers wrap />
42
+ </section>
43
+
44
+ <section className="space-y-sm">
45
+ <p className="text-label text-muted">Capped and scrolling (no wrap)</p>
46
+ <CodePreview
47
+ lines={[
48
+ ...pathLines,
49
+ ...pathLines,
50
+ ...pathLines,
51
+ { text: "This line is intentionally long so the horizontal scroll engages: design-system/components/CodePreview/CodePreview.tsx" },
52
+ ]}
53
+ lineNumbers
54
+ capped
55
+ />
56
+ </section>
57
+
58
+ <section className="space-y-sm">
59
+ <div className="flex items-center justify-between gap-sm">
60
+ <p className="text-label text-muted">Loading overlay</p>
61
+ <Button variant="secondary" size="sm" onClick={() => setLoading((v) => !v)}>
62
+ {loading ? "Hide overlay" : "Show overlay"}
63
+ </Button>
64
+ </div>
65
+ <CodePreview
66
+ text={"# DESIGN.md\nname: Acme design system\nbrand: #5E6AD2\nradius: 8px"}
67
+ lineNumbers
68
+ loading={loading}
69
+ loadingLabel="Loading preview…"
70
+ />
71
+ </section>
72
+ </div>
73
+ );
74
+ }
@@ -97,6 +97,7 @@ export const ICON_REGISTRY = {
97
97
  "chart-bar": { viewBox: "0 0 24 24", nodes: [{ tag: "path", d: "M3 3v16a2 2 0 0 0 2 2h16" }, { tag: "path", d: "M7 16h8" }, { tag: "path", d: "M7 11h12" }, { tag: "path", d: "M7 6h3" }] },
98
98
  "layout-grid": { viewBox: "0 0 24 24", nodes: [{ tag: "rect", width: "7", height: "7", x: "3", y: "3", rx: "1" }, { tag: "rect", width: "7", height: "7", x: "14", y: "3", rx: "1" }, { tag: "rect", width: "7", height: "7", x: "14", y: "14", rx: "1" }, { tag: "rect", width: "7", height: "7", x: "3", y: "14", rx: "1" }] },
99
99
  "smartphone": { viewBox: "0 0 24 24", nodes: [{ tag: "rect", width: "14", height: "20", x: "5", y: "2", rx: "2", ry: "2" }, { tag: "path", d: "M12 18h.01" }] },
100
+ "folder": { viewBox: "0 0 24 24", nodes: [{ tag: "path", d: "M20 20a2 2 0 0 0 2-2V8a2 2 0 0 0-2-2h-7.9a2 2 0 0 1-1.69-.9L9.6 3.9A2 2 0 0 0 7.93 3H4a2 2 0 0 0-2 2v13a2 2 0 0 0 2 2Z" }] },
100
101
  } as const;
101
102
 
102
103
  export type IconName = keyof typeof ICON_REGISTRY;
package/src/index.ts CHANGED
@@ -20,6 +20,8 @@ export * from "./atoms/Carousel";
20
20
  export * from "./atoms/ChatWindow";
21
21
  export * from "./atoms/Checkbox";
22
22
  export * from "./atoms/Chip";
23
+ export * from "./atoms/CodeEditor";
24
+ export * from "./atoms/CodePreview";
23
25
  export * from "./atoms/Combobox";
24
26
  export * from "./atoms/CommentThread";
25
27
  export * from "./atoms/DataTable";