@platned/ui 0.10.3 → 1.0.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.
- package/README.md +42 -98
- package/dist/blocks-charts.cjs +459 -0
- package/dist/blocks-charts.cjs.map +1 -0
- package/dist/blocks-charts.d.cts +64 -0
- package/dist/blocks-charts.d.ts +64 -0
- package/dist/blocks-charts.js +440 -0
- package/dist/blocks-charts.js.map +1 -0
- package/dist/blocks.cjs +8007 -0
- package/dist/blocks.cjs.map +1 -0
- package/dist/blocks.d.cts +3082 -0
- package/dist/blocks.d.ts +3082 -0
- package/dist/blocks.js +8223 -0
- package/dist/blocks.js.map +1 -0
- package/dist/chart.cjs +226 -0
- package/dist/chart.cjs.map +1 -0
- package/dist/chart.d.ts +66 -0
- package/dist/chart.js +183 -0
- package/dist/chart.js.map +1 -0
- package/dist/chunk-2L5XAYNK.js +11 -0
- package/dist/chunk-2L5XAYNK.js.map +1 -0
- package/dist/chunk-327NSKZW.js +3176 -0
- package/dist/chunk-327NSKZW.js.map +1 -0
- package/dist/chunk-GJJWRZ4B.js +200 -0
- package/dist/chunk-GJJWRZ4B.js.map +1 -0
- package/dist/chunk-WGCAQEZ4.js +178 -0
- package/dist/chunk-WGCAQEZ4.js.map +1 -0
- package/dist/code-block-BgEiLXpO.d.ts +111 -0
- package/dist/code-block-highlight.cjs +489 -0
- package/dist/code-block-highlight.cjs.map +1 -0
- package/dist/code-block-highlight.d.ts +28 -0
- package/dist/code-block-highlight.js +120 -0
- package/dist/code-block-highlight.js.map +1 -0
- package/dist/data-table-Dec6t8NO.d.ts +729 -0
- package/dist/data-table.cjs +3506 -2219
- package/dist/data-table.cjs.map +1 -1
- package/dist/data-table.d.ts +2 -1
- package/dist/data-table.js +1396 -246
- package/dist/data-table.js.map +1 -1
- package/dist/index.cjs +8932 -11975
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +2524 -5312
- package/dist/index.js +4681 -9560
- package/dist/index.js.map +1 -1
- package/dist/map.cjs +432 -0
- package/dist/map.cjs.map +1 -0
- package/dist/map.d.cts +294 -0
- package/dist/map.d.ts +294 -0
- package/dist/map.js +422 -0
- package/dist/map.js.map +1 -0
- package/dist/theme.css +1897 -0
- package/package.json +65 -24
- package/dist/chunk-OVIRTNT4.js +0 -2787
- package/dist/chunk-OVIRTNT4.js.map +0 -1
- package/dist/data-table-JX-vnL0F.d.ts +0 -464
- package/dist/sidebar.cjs +0 -108
- package/dist/sidebar.cjs.map +0 -1
- package/dist/sidebar.d.cts +0 -257
- package/dist/sidebar.d.ts +0 -257
- package/dist/sidebar.js +0 -70
- package/dist/sidebar.js.map +0 -1
- package/dist/styles.css +0 -1
- package/dist/tokens.css +0 -1
- package/tailwind-preset.cjs +0 -446
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Button
|
|
3
|
+
} from "./chunk-WGCAQEZ4.js";
|
|
4
|
+
import {
|
|
5
|
+
cn
|
|
6
|
+
} from "./chunk-2L5XAYNK.js";
|
|
7
|
+
|
|
8
|
+
// src/components/ai/code-block.tsx
|
|
9
|
+
import { forwardRef, useEffect, useState } from "react";
|
|
10
|
+
import { CheckIcon, CopyIcon } from "lucide-react";
|
|
11
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
12
|
+
var VARIANT = {
|
|
13
|
+
default: "bg-muted text-foreground ring-1 ring-foreground/5 dark:ring-foreground/10",
|
|
14
|
+
destructive: "bg-destructive/5 text-destructive ring-1 ring-destructive/15 dark:bg-destructive/10 dark:ring-destructive/20"
|
|
15
|
+
};
|
|
16
|
+
var LINE_VARIANT = {
|
|
17
|
+
default: "",
|
|
18
|
+
highlighted: "bg-foreground/5",
|
|
19
|
+
added: "bg-foreground/5 after:content-['+']",
|
|
20
|
+
removed: "bg-destructive/10 after:text-destructive after:content-['\u2212']"
|
|
21
|
+
};
|
|
22
|
+
var CodeBlock = forwardRef(function CodeBlock2({
|
|
23
|
+
variant = "default",
|
|
24
|
+
size = "default",
|
|
25
|
+
code,
|
|
26
|
+
lines,
|
|
27
|
+
title,
|
|
28
|
+
copyable = false,
|
|
29
|
+
lineNumbers = false,
|
|
30
|
+
wrap = false,
|
|
31
|
+
startLine = 1,
|
|
32
|
+
highlightLines,
|
|
33
|
+
language,
|
|
34
|
+
className,
|
|
35
|
+
children,
|
|
36
|
+
...props
|
|
37
|
+
}, ref) {
|
|
38
|
+
const shorthand = code != null || lines != null;
|
|
39
|
+
const source = code ?? "";
|
|
40
|
+
const rows = lines ?? source.replace(/\n$/, "").split("\n");
|
|
41
|
+
const copy = copyable ? /* @__PURE__ */ jsx(CodeBlockCopyButton, { value: source }) : null;
|
|
42
|
+
return /* @__PURE__ */ jsx(
|
|
43
|
+
"div",
|
|
44
|
+
{
|
|
45
|
+
ref,
|
|
46
|
+
"data-slot": "code-block",
|
|
47
|
+
"data-variant": variant,
|
|
48
|
+
"data-size": size,
|
|
49
|
+
"data-language": language,
|
|
50
|
+
className: cn(
|
|
51
|
+
"group/code-block relative flex w-full min-w-0 flex-col overflow-hidden rounded-2xl text-sm has-[>[data-slot=code-block-content]:focus-visible]:ring-3 has-[>[data-slot=code-block-content]:focus-visible]:ring-ring/30 data-[size=sm]:rounded-xl data-[size=sm]:text-xs",
|
|
52
|
+
VARIANT[variant],
|
|
53
|
+
className
|
|
54
|
+
),
|
|
55
|
+
...props,
|
|
56
|
+
children: shorthand ? /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
57
|
+
title != null ? /* @__PURE__ */ jsxs(CodeBlockHeader, { children: [
|
|
58
|
+
/* @__PURE__ */ jsx(CodeBlockTitle, { children: title }),
|
|
59
|
+
copy && /* @__PURE__ */ jsx(CodeBlockActions, { children: copy })
|
|
60
|
+
] }) : copy && /* @__PURE__ */ jsx(CodeBlockActions, { children: copy }),
|
|
61
|
+
/* @__PURE__ */ jsx(CodeBlockContent, { lineNumbers, wrap, startLine, children: rows.map((line, index) => /* @__PURE__ */ jsx(CodeBlockLine, { variant: highlightLines?.includes(startLine + index) ? "highlighted" : "default", children: line }, index)) }),
|
|
62
|
+
children
|
|
63
|
+
] }) : children
|
|
64
|
+
}
|
|
65
|
+
);
|
|
66
|
+
});
|
|
67
|
+
function CodeBlockHeader({ className, ...props }) {
|
|
68
|
+
return /* @__PURE__ */ jsx(
|
|
69
|
+
"div",
|
|
70
|
+
{
|
|
71
|
+
"data-slot": "code-block-header",
|
|
72
|
+
className: cn(
|
|
73
|
+
"flex min-w-0 shrink-0 items-center gap-2 px-4 pt-4 text-muted-foreground group-data-[size=sm]/code-block:px-3 group-data-[size=sm]/code-block:pt-3 group-data-[variant=destructive]/code-block:text-destructive *:has-[>[data-slot=code-block-title]]:min-w-0",
|
|
74
|
+
className
|
|
75
|
+
),
|
|
76
|
+
...props
|
|
77
|
+
}
|
|
78
|
+
);
|
|
79
|
+
}
|
|
80
|
+
function CodeBlockTitle({ className, ...props }) {
|
|
81
|
+
return /* @__PURE__ */ jsx(
|
|
82
|
+
"div",
|
|
83
|
+
{
|
|
84
|
+
"data-slot": "code-block-title",
|
|
85
|
+
className: cn(
|
|
86
|
+
"min-w-0 truncate font-sans text-sm font-medium text-foreground group-data-[size=sm]/code-block:text-xs group-data-[variant=destructive]/code-block:text-destructive *:[svg]:me-1.5 [&_svg]:pointer-events-none [&_svg]:inline-block [&_svg]:align-middle [&_svg:not([class*='size-'])]:size-4 group-data-[size=sm]/code-block:[&_svg:not([class*='size-'])]:size-3.5",
|
|
87
|
+
className
|
|
88
|
+
),
|
|
89
|
+
...props
|
|
90
|
+
}
|
|
91
|
+
);
|
|
92
|
+
}
|
|
93
|
+
function CodeBlockActions({ className, ...props }) {
|
|
94
|
+
return /* @__PURE__ */ jsx(
|
|
95
|
+
"div",
|
|
96
|
+
{
|
|
97
|
+
"data-slot": "code-block-actions",
|
|
98
|
+
className: cn(
|
|
99
|
+
"-my-1 -me-1.5 ms-auto flex shrink-0 items-center gap-1 *:data-[slot=button]:hover:bg-foreground/5 dark:*:data-[slot=button]:hover:bg-foreground/10",
|
|
100
|
+
"[[data-slot=code-block]>&]:absolute [[data-slot=code-block]>&]:end-3 [[data-slot=code-block]>&]:top-3 [[data-slot=code-block]>&]:z-10 [[data-slot=code-block]>&]:m-0 [[data-slot=code-block]>&]:opacity-0 [[data-slot=code-block]>&]:transition-opacity [[data-slot=code-block]>&]:group-focus-within/code-block:opacity-100 [[data-slot=code-block]>&]:group-hover/code-block:opacity-100 [[data-slot=code-block]>&]:pointer-coarse:opacity-100 [[data-slot=code-block]>&]:*:[button]:bg-background [[data-slot=code-block]>&]:*:[button]:ring-1 [[data-slot=code-block]>&]:*:[button]:ring-foreground/10 group-data-[size=sm]/code-block:[[data-slot=code-block]>&]:end-2 group-data-[size=sm]/code-block:[[data-slot=code-block]>&]:top-2",
|
|
101
|
+
className
|
|
102
|
+
),
|
|
103
|
+
...props
|
|
104
|
+
}
|
|
105
|
+
);
|
|
106
|
+
}
|
|
107
|
+
function CodeBlockCopyButton({ value, variant = "ghost", size = "icon-xs", className, onClick, ...props }) {
|
|
108
|
+
const [copied, setCopied] = useState(false);
|
|
109
|
+
useEffect(() => {
|
|
110
|
+
if (!copied) return;
|
|
111
|
+
const timeout = setTimeout(() => setCopied(false), 2e3);
|
|
112
|
+
return () => clearTimeout(timeout);
|
|
113
|
+
}, [copied]);
|
|
114
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
115
|
+
/* @__PURE__ */ jsx(
|
|
116
|
+
Button,
|
|
117
|
+
{
|
|
118
|
+
"data-slot": "code-block-copy-button",
|
|
119
|
+
"data-copied": copied || void 0,
|
|
120
|
+
variant,
|
|
121
|
+
size,
|
|
122
|
+
"aria-label": copied ? "Copied" : "Copy",
|
|
123
|
+
className: cn("hover:bg-foreground/5 dark:hover:bg-foreground/10", className),
|
|
124
|
+
onClick: (event) => {
|
|
125
|
+
onClick?.(event);
|
|
126
|
+
navigator.clipboard?.writeText(value).then(() => setCopied(true)).catch(() => {
|
|
127
|
+
});
|
|
128
|
+
},
|
|
129
|
+
...props,
|
|
130
|
+
children: copied ? /* @__PURE__ */ jsx(CheckIcon, {}) : /* @__PURE__ */ jsx(CopyIcon, {})
|
|
131
|
+
}
|
|
132
|
+
),
|
|
133
|
+
/* @__PURE__ */ jsx("span", { "aria-live": "polite", className: "sr-only", children: copied ? "Copied" : "" })
|
|
134
|
+
] });
|
|
135
|
+
}
|
|
136
|
+
function CodeBlockContent({ className, children, style, wrap = false, lineNumbers = false, startLine = 1, ...props }) {
|
|
137
|
+
return /* @__PURE__ */ jsx(
|
|
138
|
+
"pre",
|
|
139
|
+
{
|
|
140
|
+
"data-slot": "code-block-content",
|
|
141
|
+
"data-wrap": wrap || void 0,
|
|
142
|
+
"data-numbered": lineNumbers || void 0,
|
|
143
|
+
dir: "ltr",
|
|
144
|
+
tabIndex: 0,
|
|
145
|
+
style: { counterReset: `line ${startLine - 1}`, ...style },
|
|
146
|
+
className: cn(
|
|
147
|
+
"min-h-0 min-w-0 overflow-auto px-4 py-4 text-start font-mono leading-relaxed outline-none scrollbar-thin scroll-fade-x group-has-data-[slot=code-block-footer]/code-block:pb-2 group-has-data-[slot=code-block-header]/code-block:pt-2 group-data-[size=sm]/code-block:px-3 group-data-[size=sm]/code-block:py-3 group-data-[size=sm]/code-block:group-has-data-[slot=code-block-header]/code-block:pt-1.5 data-wrap:scroll-fade-y data-wrap:whitespace-pre-wrap data-wrap:wrap-break-word",
|
|
148
|
+
className
|
|
149
|
+
),
|
|
150
|
+
...props,
|
|
151
|
+
children: /* @__PURE__ */ jsx(
|
|
152
|
+
"code",
|
|
153
|
+
{
|
|
154
|
+
"data-slot": "code-block-code",
|
|
155
|
+
className: "grid min-h-lh min-w-max content-start in-data-numbered:grid-cols-[auto_1fr] in-data-wrap:min-w-0",
|
|
156
|
+
children: lineNumbers && typeof children === "string" ? children.replace(/\n$/, "").split("\n").map((line, index) => /* @__PURE__ */ jsx(CodeBlockLine, { children: line }, index)) : children
|
|
157
|
+
}
|
|
158
|
+
)
|
|
159
|
+
}
|
|
160
|
+
);
|
|
161
|
+
}
|
|
162
|
+
function CodeBlockLine({ className, variant = "default", children, ...props }) {
|
|
163
|
+
const empty = children === void 0 || children === null || children === "" || Array.isArray(children) && children.length === 0;
|
|
164
|
+
return /* @__PURE__ */ jsx(
|
|
165
|
+
"span",
|
|
166
|
+
{
|
|
167
|
+
"data-slot": "code-block-line",
|
|
168
|
+
"data-variant": variant,
|
|
169
|
+
className: cn(
|
|
170
|
+
"relative -mx-4 block min-h-lh px-4 group-data-[size=sm]/code-block:-mx-3 group-data-[size=sm]/code-block:px-3 before:min-w-6 before:text-end before:text-muted-foreground after:absolute after:start-1 after:top-0 after:text-muted-foreground after:select-none in-data-numbered:col-span-2 in-data-numbered:grid in-data-numbered:grid-cols-subgrid in-data-numbered:gap-x-3 in-data-numbered:[counter-increment:line] in-data-numbered:before:content-[counter(line)] in-data-numbered:before:select-none in-data-numbered:supports-[content:counter(line)_/_'']:before:content-[counter(line)_/_'']",
|
|
171
|
+
LINE_VARIANT[variant],
|
|
172
|
+
className
|
|
173
|
+
),
|
|
174
|
+
...props,
|
|
175
|
+
children: /* @__PURE__ */ jsx("span", { "data-slot": "code-block-line-content", className: "min-w-0", children: empty ? "\n" : children })
|
|
176
|
+
}
|
|
177
|
+
);
|
|
178
|
+
}
|
|
179
|
+
function CodeBlockFooter({ className, ...props }) {
|
|
180
|
+
return /* @__PURE__ */ jsx(
|
|
181
|
+
"div",
|
|
182
|
+
{
|
|
183
|
+
"data-slot": "code-block-footer",
|
|
184
|
+
className: cn("flex min-w-0 shrink-0 items-center gap-2 px-4 pb-4 text-muted-foreground group-data-[size=sm]/code-block:px-3 group-data-[size=sm]/code-block:pb-3", className),
|
|
185
|
+
...props
|
|
186
|
+
}
|
|
187
|
+
);
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
export {
|
|
191
|
+
CodeBlock,
|
|
192
|
+
CodeBlockHeader,
|
|
193
|
+
CodeBlockTitle,
|
|
194
|
+
CodeBlockActions,
|
|
195
|
+
CodeBlockCopyButton,
|
|
196
|
+
CodeBlockContent,
|
|
197
|
+
CodeBlockLine,
|
|
198
|
+
CodeBlockFooter
|
|
199
|
+
};
|
|
200
|
+
//# sourceMappingURL=chunk-GJJWRZ4B.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/components/ai/code-block.tsx"],"sourcesContent":["import { forwardRef, useEffect, useState, type ComponentProps, type HTMLAttributes, type ReactNode } from 'react';\nimport { CheckIcon, CopyIcon } from 'lucide-react';\nimport { cn } from '../../lib/cn';\nimport { Button, type ButtonProps } from '../forms/button';\n\n/**\n * CodeBlock: displays code with an optional header, line numbers, diff and highlighted lines.\n *\n * Composition: `CodeBlockHeader` (`CodeBlockTitle`, `CodeBlockActions` with a\n * `CodeBlockCopyButton`), `CodeBlockContent` (a `pre` > `code`; `lineNumbers`, `wrap`,\n * `startLine`) holding `CodeBlockLine`s (`variant` `default` / `added` / `removed` /\n * `highlighted`), and `CodeBlockFooter`. `CodeBlockActions` placed directly in the block floats in\n * the corner and shows on hover or focus.\n *\n * Shorthand: `code` (with `title`, `copyable`, `lineNumbers`, `wrap`, `startLine`,\n * `highlightLines`) renders all of that. Syntax colours come from `@platned/ui/code-block-highlight`\n * (Shiki, an optional peer): pass its lines as `lines`, or use its `HighlightedCodeBlock`.\n */\n\nexport type CodeBlockVariant = 'default' | 'destructive';\nexport type CodeBlockSize = 'default' | 'sm';\nexport type CodeBlockLineVariant = 'default' | 'added' | 'removed' | 'highlighted';\n\nconst VARIANT: Record<CodeBlockVariant, string> = {\n default: 'bg-muted text-foreground ring-1 ring-foreground/5 dark:ring-foreground/10',\n destructive: 'bg-destructive/5 text-destructive ring-1 ring-destructive/15 dark:bg-destructive/10 dark:ring-destructive/20',\n};\n\nconst LINE_VARIANT: Record<CodeBlockLineVariant, string> = {\n default: '',\n highlighted: 'bg-foreground/5',\n added: \"bg-foreground/5 after:content-['+']\",\n removed: \"bg-destructive/10 after:text-destructive after:content-['−']\",\n};\n\nexport interface CodeBlockProps extends Omit<HTMLAttributes<HTMLDivElement>, 'title'> {\n /** Default `default`. */\n variant?: CodeBlockVariant;\n /** `sm` has tighter padding and `text-xs` code, for tool output. Default `default`. */\n size?: CodeBlockSize;\n /** Shorthand: the code. Renders the header (with `title` / `copyable`) and the content. */\n code?: string;\n /** Shorthand: one node per line (e.g. from `useHighlightedCode`); defaults to `code` split by line. */\n lines?: readonly ReactNode[];\n /** Shorthand: the header title, e.g. a file name. */\n title?: ReactNode;\n /** Shorthand: a copy button in the header (or floating, without a title). */\n copyable?: boolean;\n /** Shorthand: number the lines. */\n lineNumbers?: boolean;\n /** Shorthand: wrap long lines instead of scrolling. */\n wrap?: boolean;\n /** Shorthand: the first line number. Default 1. */\n startLine?: number;\n /** Shorthand: 1-based line numbers to highlight. */\n highlightLines?: readonly number[];\n /** Shorthand: the language, as a `data-language` attribute (colours come from the highlight entry). */\n language?: string;\n}\n\nexport const CodeBlock = forwardRef<HTMLDivElement, CodeBlockProps>(function CodeBlock(\n {\n variant = 'default',\n size = 'default',\n code,\n lines,\n title,\n copyable = false,\n lineNumbers = false,\n wrap = false,\n startLine = 1,\n highlightLines,\n language,\n className,\n children,\n ...props\n },\n ref,\n) {\n const shorthand = code != null || lines != null;\n const source = code ?? '';\n const rows = lines ?? source.replace(/\\n$/, '').split('\\n');\n const copy = copyable ? <CodeBlockCopyButton value={source} /> : null;\n return (\n <div\n ref={ref}\n data-slot=\"code-block\"\n data-variant={variant}\n data-size={size}\n data-language={language}\n className={cn(\n 'group/code-block relative flex w-full min-w-0 flex-col overflow-hidden rounded-2xl text-sm has-[>[data-slot=code-block-content]:focus-visible]:ring-3 has-[>[data-slot=code-block-content]:focus-visible]:ring-ring/30 data-[size=sm]:rounded-xl data-[size=sm]:text-xs',\n VARIANT[variant],\n className,\n )}\n {...props}\n >\n {shorthand ? (\n <>\n {title != null ? (\n <CodeBlockHeader>\n <CodeBlockTitle>{title}</CodeBlockTitle>\n {copy && <CodeBlockActions>{copy}</CodeBlockActions>}\n </CodeBlockHeader>\n ) : (\n copy && <CodeBlockActions>{copy}</CodeBlockActions>\n )}\n <CodeBlockContent lineNumbers={lineNumbers} wrap={wrap} startLine={startLine}>\n {rows.map((line, index) => (\n <CodeBlockLine key={index} variant={highlightLines?.includes(startLine + index) ? 'highlighted' : 'default'}>\n {line}\n </CodeBlockLine>\n ))}\n </CodeBlockContent>\n {children}\n </>\n ) : (\n children\n )}\n </div>\n );\n});\n\n/** A row above the content for a title and actions. */\nexport function CodeBlockHeader({ className, ...props }: HTMLAttributes<HTMLDivElement>) {\n return (\n <div\n data-slot=\"code-block-header\"\n className={cn(\n 'flex min-w-0 shrink-0 items-center gap-2 px-4 pt-4 text-muted-foreground group-data-[size=sm]/code-block:px-3 group-data-[size=sm]/code-block:pt-3 group-data-[variant=destructive]/code-block:text-destructive *:has-[>[data-slot=code-block-title]]:min-w-0',\n className,\n )}\n {...props}\n />\n );\n}\n\n/** The header title, e.g. a file name. Icons sit inline before the text. */\nexport function CodeBlockTitle({ className, ...props }: HTMLAttributes<HTMLDivElement>) {\n return (\n <div\n data-slot=\"code-block-title\"\n className={cn(\n \"min-w-0 truncate font-sans text-sm font-medium text-foreground group-data-[size=sm]/code-block:text-xs group-data-[variant=destructive]/code-block:text-destructive *:[svg]:me-1.5 [&_svg]:pointer-events-none [&_svg]:inline-block [&_svg]:align-middle [&_svg:not([class*='size-'])]:size-4 group-data-[size=sm]/code-block:[&_svg:not([class*='size-'])]:size-3.5\",\n className,\n )}\n {...props}\n />\n );\n}\n\n/** Buttons for the block. In the header they sit at the end; directly in the block they float. */\nexport function CodeBlockActions({ className, ...props }: HTMLAttributes<HTMLDivElement>) {\n return (\n <div\n data-slot=\"code-block-actions\"\n className={cn(\n '-my-1 -me-1.5 ms-auto flex shrink-0 items-center gap-1 *:data-[slot=button]:hover:bg-foreground/5 dark:*:data-[slot=button]:hover:bg-foreground/10',\n '[[data-slot=code-block]>&]:absolute [[data-slot=code-block]>&]:end-3 [[data-slot=code-block]>&]:top-3 [[data-slot=code-block]>&]:z-10 [[data-slot=code-block]>&]:m-0 [[data-slot=code-block]>&]:opacity-0 [[data-slot=code-block]>&]:transition-opacity [[data-slot=code-block]>&]:group-focus-within/code-block:opacity-100 [[data-slot=code-block]>&]:group-hover/code-block:opacity-100 [[data-slot=code-block]>&]:pointer-coarse:opacity-100 [[data-slot=code-block]>&]:*:[button]:bg-background [[data-slot=code-block]>&]:*:[button]:ring-1 [[data-slot=code-block]>&]:*:[button]:ring-foreground/10 group-data-[size=sm]/code-block:[[data-slot=code-block]>&]:end-2 group-data-[size=sm]/code-block:[[data-slot=code-block]>&]:top-2',\n className,\n )}\n {...props}\n />\n );\n}\n\nexport interface CodeBlockCopyButtonProps extends ButtonProps {\n /** The text to copy. */\n value: string;\n}\n\n/** Copies `value`; shows a check for two seconds and announces \"Copied\". */\nexport function CodeBlockCopyButton({ value, variant = 'ghost', size = 'icon-xs', className, onClick, ...props }: CodeBlockCopyButtonProps) {\n const [copied, setCopied] = useState(false);\n useEffect(() => {\n if (!copied) return;\n const timeout = setTimeout(() => setCopied(false), 2000);\n return () => clearTimeout(timeout);\n }, [copied]);\n\n return (\n <>\n <Button\n data-slot=\"code-block-copy-button\"\n data-copied={copied || undefined}\n variant={variant}\n size={size}\n aria-label={copied ? 'Copied' : 'Copy'}\n className={cn('hover:bg-foreground/5 dark:hover:bg-foreground/10', className)}\n onClick={(event) => {\n onClick?.(event);\n navigator.clipboard\n ?.writeText(value)\n .then(() => setCopied(true))\n .catch(() => {});\n }}\n {...props}\n >\n {copied ? <CheckIcon /> : <CopyIcon />}\n </Button>\n <span aria-live=\"polite\" className=\"sr-only\">\n {copied ? 'Copied' : ''}\n </span>\n </>\n );\n}\n\nexport interface CodeBlockContentProps extends ComponentProps<'pre'> {\n /** Wrap long lines instead of scrolling. */\n wrap?: boolean;\n /** Number the lines (CodeBlockLine children, or a string split into lines). */\n lineNumbers?: boolean;\n /** The first line number. Default 1. */\n startLine?: number;\n}\n\n/** The scrolling `pre` > `code`. Always left to right; focusable so the keyboard can scroll it. */\nexport function CodeBlockContent({ className, children, style, wrap = false, lineNumbers = false, startLine = 1, ...props }: CodeBlockContentProps) {\n return (\n <pre\n data-slot=\"code-block-content\"\n data-wrap={wrap || undefined}\n data-numbered={lineNumbers || undefined}\n dir=\"ltr\"\n // A scroll container: keyboard users focus it to scroll long code (WCAG 2.1.1). Pass\n // tabIndex={-1} to drop the tab stop.\n // eslint-disable-next-line jsx-a11y/no-noninteractive-tabindex\n tabIndex={0}\n style={{ counterReset: `line ${startLine - 1}`, ...style }}\n className={cn(\n 'min-h-0 min-w-0 overflow-auto px-4 py-4 text-start font-mono leading-relaxed outline-none scrollbar-thin scroll-fade-x group-has-data-[slot=code-block-footer]/code-block:pb-2 group-has-data-[slot=code-block-header]/code-block:pt-2 group-data-[size=sm]/code-block:px-3 group-data-[size=sm]/code-block:py-3 group-data-[size=sm]/code-block:group-has-data-[slot=code-block-header]/code-block:pt-1.5 data-wrap:scroll-fade-y data-wrap:whitespace-pre-wrap data-wrap:wrap-break-word',\n className,\n )}\n {...props}\n >\n <code\n data-slot=\"code-block-code\"\n className=\"grid min-h-lh min-w-max content-start in-data-numbered:grid-cols-[auto_1fr] in-data-wrap:min-w-0\"\n >\n {lineNumbers && typeof children === 'string'\n ? children\n .replace(/\\n$/, '')\n .split('\\n')\n .map((line, index) => <CodeBlockLine key={index}>{line}</CodeBlockLine>)\n : children}\n </code>\n </pre>\n );\n}\n\nexport interface CodeBlockLineProps extends HTMLAttributes<HTMLSpanElement> {\n /** Default `default`. `added` / `removed` also carry a `+` / `−` marker. */\n variant?: CodeBlockLineVariant;\n}\n\n/** One line. Numbered by CSS when the content has `lineNumbers`; the number is hidden from readers. */\nexport function CodeBlockLine({ className, variant = 'default', children, ...props }: CodeBlockLineProps) {\n // An empty line holds a newline so copying a selection keeps blank lines.\n const empty = children === undefined || children === null || children === '' || (Array.isArray(children) && children.length === 0);\n return (\n <span\n data-slot=\"code-block-line\"\n data-variant={variant}\n className={cn(\n \"relative -mx-4 block min-h-lh px-4 group-data-[size=sm]/code-block:-mx-3 group-data-[size=sm]/code-block:px-3 before:min-w-6 before:text-end before:text-muted-foreground after:absolute after:start-1 after:top-0 after:text-muted-foreground after:select-none in-data-numbered:col-span-2 in-data-numbered:grid in-data-numbered:grid-cols-subgrid in-data-numbered:gap-x-3 in-data-numbered:[counter-increment:line] in-data-numbered:before:content-[counter(line)] in-data-numbered:before:select-none in-data-numbered:supports-[content:counter(line)_/_'']:before:content-[counter(line)_/_'']\",\n LINE_VARIANT[variant],\n className,\n )}\n {...props}\n >\n <span data-slot=\"code-block-line-content\" className=\"min-w-0\">\n {empty ? '\\n' : children}\n </span>\n </span>\n );\n}\n\n/** A row under the content, e.g. a language label or a Show more button. */\nexport function CodeBlockFooter({ className, ...props }: HTMLAttributes<HTMLDivElement>) {\n return (\n <div\n data-slot=\"code-block-footer\"\n className={cn('flex min-w-0 shrink-0 items-center gap-2 px-4 pb-4 text-muted-foreground group-data-[size=sm]/code-block:px-3 group-data-[size=sm]/code-block:pb-3', className)}\n {...props}\n />\n );\n}\n"],"mappings":";;;;;;;;AAAA,SAAS,YAAY,WAAW,gBAA0E;AAC1G,SAAS,WAAW,gBAAgB;AAiFV,SAgBlB,UAhBkB,KAkBd,YAlBc;AA3D1B,IAAM,UAA4C;AAAA,EAChD,SAAS;AAAA,EACT,aAAa;AACf;AAEA,IAAM,eAAqD;AAAA,EACzD,SAAS;AAAA,EACT,aAAa;AAAA,EACb,OAAO;AAAA,EACP,SAAS;AACX;AA2BO,IAAM,YAAY,WAA2C,SAASA,WAC3E;AAAA,EACE,UAAU;AAAA,EACV,OAAO;AAAA,EACP;AAAA,EACA;AAAA,EACA;AAAA,EACA,WAAW;AAAA,EACX,cAAc;AAAA,EACd,OAAO;AAAA,EACP,YAAY;AAAA,EACZ;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA,GAA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AAY,CAAC,IAAI,GAAG,MAAM;AAAA,MACzD,WAAW;AAAA,QACT;AAAA,QACA;AAAA,MACF;AAAA,MACC,GAAG;AAAA,MAEJ;AAAA,QAAC;AAAA;AAAA,UACC,aAAU;AAAA,UACV,WAAU;AAAA,UAET,yBAAe,OAAO,aAAa,WAChC,SACG,QAAQ,OAAO,EAAE,EACjB,MAAM,IAAI,EACV,IAAI,CAAC,MAAM,UAAU,oBAAC,iBAA2B,kBAAR,KAAa,CAAgB,IACzE;AAAA;AAAA,MACN;AAAA;AAAA,EACF;AAEJ;AAQO,SAAS,cAAc,EAAE,WAAW,UAAU,WAAW,UAAU,GAAG,MAAM,GAAuB;AAExG,QAAM,QAAQ,aAAa,UAAa,aAAa,QAAQ,aAAa,MAAO,MAAM,QAAQ,QAAQ,KAAK,SAAS,WAAW;AAChI,SACE;AAAA,IAAC;AAAA;AAAA,MACC,aAAU;AAAA,MACV,gBAAc;AAAA,MACd,WAAW;AAAA,QACT;AAAA,QACA,aAAa,OAAO;AAAA,QACpB;AAAA,MACF;AAAA,MACC,GAAG;AAAA,MAEJ,8BAAC,UAAK,aAAU,2BAA0B,WAAU,WACjD,kBAAQ,OAAO,UAClB;AAAA;AAAA,EACF;AAEJ;AAGO,SAAS,gBAAgB,EAAE,WAAW,GAAG,MAAM,GAAmC;AACvF,SACE;AAAA,IAAC;AAAA;AAAA,MACC,aAAU;AAAA,MACV,WAAW,GAAG,sJAAsJ,SAAS;AAAA,MAC5K,GAAG;AAAA;AAAA,EACN;AAEJ;","names":["CodeBlock"]}
|
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
import {
|
|
2
|
+
cn
|
|
3
|
+
} from "./chunk-2L5XAYNK.js";
|
|
4
|
+
|
|
5
|
+
// src/lib/slot.tsx
|
|
6
|
+
import {
|
|
7
|
+
cloneElement,
|
|
8
|
+
forwardRef,
|
|
9
|
+
isValidElement
|
|
10
|
+
} from "react";
|
|
11
|
+
import clsx from "clsx";
|
|
12
|
+
var Slot = forwardRef(function Slot2({ children, wrapChildren, ...slotProps }, forwardedRef) {
|
|
13
|
+
if (!isValidElement(children)) return null;
|
|
14
|
+
const child = children;
|
|
15
|
+
const merged = {
|
|
16
|
+
...mergeProps(slotProps, child.props),
|
|
17
|
+
ref: composeRefs(forwardedRef, getElementRef(child))
|
|
18
|
+
};
|
|
19
|
+
return wrapChildren ? cloneElement(child, merged, wrapChildren(child.props.children)) : cloneElement(child, merged);
|
|
20
|
+
});
|
|
21
|
+
function mergeProps(slotProps, childProps) {
|
|
22
|
+
const merged = { ...slotProps };
|
|
23
|
+
for (const key in childProps) {
|
|
24
|
+
const slotValue = slotProps[key];
|
|
25
|
+
const childValue = childProps[key];
|
|
26
|
+
if (/^on[A-Z]/.test(key)) {
|
|
27
|
+
if (typeof slotValue === "function" && typeof childValue === "function") {
|
|
28
|
+
merged[key] = (...args) => {
|
|
29
|
+
slotValue(...args);
|
|
30
|
+
childValue(...args);
|
|
31
|
+
};
|
|
32
|
+
} else {
|
|
33
|
+
merged[key] = childValue ?? slotValue;
|
|
34
|
+
}
|
|
35
|
+
} else if (key === "className") {
|
|
36
|
+
merged[key] = clsx(slotValue, childValue);
|
|
37
|
+
} else if (key === "style") {
|
|
38
|
+
merged[key] = { ...slotValue, ...childValue };
|
|
39
|
+
} else {
|
|
40
|
+
merged[key] = childValue;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
return merged;
|
|
44
|
+
}
|
|
45
|
+
function getElementRef(element) {
|
|
46
|
+
const asRecord = element;
|
|
47
|
+
return asRecord.props?.ref ?? asRecord.ref;
|
|
48
|
+
}
|
|
49
|
+
function composeRefs(...refs) {
|
|
50
|
+
return (node) => {
|
|
51
|
+
for (const ref of refs) {
|
|
52
|
+
if (!ref) continue;
|
|
53
|
+
if (typeof ref === "function") {
|
|
54
|
+
ref(node);
|
|
55
|
+
} else {
|
|
56
|
+
ref.current = node;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
// src/components/feedback/spinner.tsx
|
|
63
|
+
import { forwardRef as forwardRef2 } from "react";
|
|
64
|
+
import { Loader2Icon } from "lucide-react";
|
|
65
|
+
import { jsx } from "react/jsx-runtime";
|
|
66
|
+
var Spinner = forwardRef2(function Spinner2({ className, ...props }, ref) {
|
|
67
|
+
return /* @__PURE__ */ jsx(
|
|
68
|
+
Loader2Icon,
|
|
69
|
+
{
|
|
70
|
+
ref,
|
|
71
|
+
"data-slot": "spinner",
|
|
72
|
+
role: "status",
|
|
73
|
+
"aria-label": "Loading",
|
|
74
|
+
className: cn("size-4 animate-spin", className),
|
|
75
|
+
...props
|
|
76
|
+
}
|
|
77
|
+
);
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
// src/components/forms/button.tsx
|
|
81
|
+
import {
|
|
82
|
+
cloneElement as cloneElement2,
|
|
83
|
+
forwardRef as forwardRef3,
|
|
84
|
+
isValidElement as isValidElement2
|
|
85
|
+
} from "react";
|
|
86
|
+
import { Fragment, jsx as jsx2, jsxs } from "react/jsx-runtime";
|
|
87
|
+
var BASE = "group/button inline-flex shrink-0 items-center justify-center rounded-lg border border-transparent bg-clip-padding text-sm font-medium whitespace-nowrap transition-all outline-none select-none focus-visible:border-ring focus-visible:ring-3 focus-visible:ring-ring/50 active:not-aria-[haspopup]:translate-y-px disabled:pointer-events-none disabled:opacity-50 aria-disabled:pointer-events-none aria-disabled:opacity-50 aria-invalid:border-destructive aria-invalid:ring-3 aria-invalid:ring-destructive/20 dark:aria-invalid:border-destructive/50 dark:aria-invalid:ring-destructive/40 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4";
|
|
88
|
+
var VARIANT = {
|
|
89
|
+
default: "bg-primary text-primary-foreground hover:bg-primary/80",
|
|
90
|
+
outline: "border-border bg-background hover:bg-muted hover:text-foreground aria-expanded:bg-muted aria-expanded:text-foreground dark:border-input dark:bg-input/30 dark:hover:bg-input/50",
|
|
91
|
+
secondary: "bg-secondary text-secondary-foreground hover:bg-[color-mix(in_oklch,var(--secondary),var(--foreground)_5%)] aria-expanded:bg-secondary aria-expanded:text-secondary-foreground",
|
|
92
|
+
ghost: "hover:bg-muted hover:text-foreground aria-expanded:bg-muted aria-expanded:text-foreground dark:hover:bg-muted/50",
|
|
93
|
+
destructive: "bg-destructive/10 text-destructive hover:bg-destructive/20 focus-visible:border-destructive/40 focus-visible:ring-destructive/20 dark:bg-destructive/20 dark:hover:bg-destructive/30 dark:focus-visible:ring-destructive/40",
|
|
94
|
+
link: "text-primary underline-offset-4 hover:underline"
|
|
95
|
+
};
|
|
96
|
+
var SIZE = {
|
|
97
|
+
default: "h-8 gap-1.5 px-2.5 has-data-[icon=inline-end]:pe-2 has-data-[icon=inline-start]:ps-2",
|
|
98
|
+
xs: "h-6 gap-1 rounded-[min(var(--radius-md),10px)] px-2 text-xs in-data-[slot=button-group]:rounded-lg has-data-[icon=inline-end]:pe-1.5 has-data-[icon=inline-start]:ps-1.5 [&_svg:not([class*='size-'])]:size-3",
|
|
99
|
+
sm: "h-7 gap-1 rounded-[min(var(--radius-md),12px)] px-2.5 text-[0.8rem] in-data-[slot=button-group]:rounded-lg has-data-[icon=inline-end]:pe-1.5 has-data-[icon=inline-start]:ps-1.5 [&_svg:not([class*='size-'])]:size-3.5",
|
|
100
|
+
lg: "h-9 gap-1.5 px-2.5 has-data-[icon=inline-end]:pe-2 has-data-[icon=inline-start]:ps-2",
|
|
101
|
+
icon: "size-8",
|
|
102
|
+
"icon-xs": "size-6 rounded-[min(var(--radius-md),10px)] in-data-[slot=button-group]:rounded-lg [&_svg:not([class*='size-'])]:size-3",
|
|
103
|
+
"icon-sm": "size-7 rounded-[min(var(--radius-md),12px)] in-data-[slot=button-group]:rounded-lg",
|
|
104
|
+
"icon-lg": "size-9"
|
|
105
|
+
};
|
|
106
|
+
function buttonVariants({
|
|
107
|
+
variant = "default",
|
|
108
|
+
size = "default"
|
|
109
|
+
} = {}) {
|
|
110
|
+
return cn(BASE, VARIANT[variant], SIZE[size]);
|
|
111
|
+
}
|
|
112
|
+
function withDataIcon(icon, side) {
|
|
113
|
+
if (isValidElement2(icon)) {
|
|
114
|
+
return cloneElement2(icon, { "data-icon": side, "aria-hidden": true });
|
|
115
|
+
}
|
|
116
|
+
return /* @__PURE__ */ jsx2("span", { "data-icon": side, "aria-hidden": true, className: "inline-flex shrink-0", children: icon });
|
|
117
|
+
}
|
|
118
|
+
var Button = forwardRef3(function Button2({
|
|
119
|
+
variant = "default",
|
|
120
|
+
size = "default",
|
|
121
|
+
asChild = false,
|
|
122
|
+
leadingIcon,
|
|
123
|
+
trailingIcon,
|
|
124
|
+
loading = false,
|
|
125
|
+
loadingLabel,
|
|
126
|
+
disabled,
|
|
127
|
+
type,
|
|
128
|
+
children,
|
|
129
|
+
className,
|
|
130
|
+
onClick,
|
|
131
|
+
...props
|
|
132
|
+
}, ref) {
|
|
133
|
+
const softDisabled = loading || asChild && Boolean(disabled);
|
|
134
|
+
const handleClick = (event) => {
|
|
135
|
+
if (softDisabled) {
|
|
136
|
+
event.preventDefault();
|
|
137
|
+
event.stopPropagation();
|
|
138
|
+
return;
|
|
139
|
+
}
|
|
140
|
+
onClick?.(event);
|
|
141
|
+
};
|
|
142
|
+
const small = size === "xs" || size === "icon-xs";
|
|
143
|
+
const decorate = (content) => /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
144
|
+
loading ? /* @__PURE__ */ jsx2(
|
|
145
|
+
Spinner,
|
|
146
|
+
{
|
|
147
|
+
"data-icon": "inline-start",
|
|
148
|
+
className: small ? "size-3" : void 0,
|
|
149
|
+
...loadingLabel ? { "aria-label": loadingLabel } : { role: void 0, "aria-label": void 0, "aria-hidden": true }
|
|
150
|
+
}
|
|
151
|
+
) : leadingIcon !== void 0 && leadingIcon !== null ? withDataIcon(leadingIcon, "inline-start") : null,
|
|
152
|
+
content,
|
|
153
|
+
trailingIcon !== void 0 && trailingIcon !== null ? withDataIcon(trailingIcon, "inline-end") : null
|
|
154
|
+
] });
|
|
155
|
+
const rootProps = {
|
|
156
|
+
className: cn(BASE, VARIANT[variant], SIZE[size], className),
|
|
157
|
+
"data-slot": "button",
|
|
158
|
+
"data-variant": variant,
|
|
159
|
+
"data-size": size,
|
|
160
|
+
"aria-busy": loading || void 0,
|
|
161
|
+
"aria-disabled": softDisabled || void 0,
|
|
162
|
+
onClick: handleClick,
|
|
163
|
+
...props
|
|
164
|
+
};
|
|
165
|
+
if (asChild) {
|
|
166
|
+
return /* @__PURE__ */ jsx2(Slot, { ref, wrapChildren: decorate, tabIndex: disabled ? -1 : void 0, ...rootProps, children });
|
|
167
|
+
}
|
|
168
|
+
return /* @__PURE__ */ jsx2("button", { ref, type: type ?? "button", disabled, ...rootProps, children: decorate(children) });
|
|
169
|
+
});
|
|
170
|
+
|
|
171
|
+
export {
|
|
172
|
+
Slot,
|
|
173
|
+
composeRefs,
|
|
174
|
+
Spinner,
|
|
175
|
+
buttonVariants,
|
|
176
|
+
Button
|
|
177
|
+
};
|
|
178
|
+
//# sourceMappingURL=chunk-WGCAQEZ4.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/lib/slot.tsx","../src/components/feedback/spinner.tsx","../src/components/forms/button.tsx"],"sourcesContent":["import {\n cloneElement,\n forwardRef,\n isValidElement,\n type CSSProperties,\n type HTMLAttributes,\n type ReactElement,\n type ReactNode,\n type Ref,\n} from 'react';\nimport clsx from 'clsx';\n\n/**\n * `Slot` renders its own props onto its single child element instead of emitting a\n * wrapper of its own. It is what makes `asChild` work.\n *\n * Why the library needs it: before 0.4.0 there was no way to render a `Button` as a\n * router `<Link>`, or to use any component as a tooltip/popover anchor, because every\n * component hardcoded its host element. The usual workaround — a `component`/`as` prop —\n * multiplies generics across the whole surface and still cannot forward a ref through\n * two levels. Delegating to the child instead keeps the type surface flat.\n *\n * <Button asChild><Link to=\"/x\">Go</Link></Button>\n *\n * Merge rules, in order of who wins:\n * - `className` — concatenated, slot first, so the child's classes come last\n * - `style` — shallow-merged, child wins on conflicting keys\n * - `on*` — both run, slot's handler first; the child's runs even if the slot's\n * called `preventDefault`, matching normal DOM listener behaviour\n * - everything else — child wins, so a child's explicit `type` or `role` is never\n * clobbered by a default the slot happens to carry\n */\nexport interface SlotProps extends HTMLAttributes<HTMLElement> {\n /** The single element to merge into. */\n children?: ReactNode;\n /**\n * Rebuilds the child's children, so a component that decorates its content can keep\n * doing so through `asChild`.\n *\n * `Button` renders `leadingIcon`, a padded label span and `trailingIcon` around whatever\n * it is given. Without this, `<Button asChild><Link>Go</Link></Button>` would either drop\n * the icons (cloning the Link untouched) or drop \"Go\" (replacing the Link's children\n * outright). It receives the child's own children — \"Go\" — and returns the decorated\n * tree to place inside the child.\n */\n wrapChildren?: (childChildren: ReactNode) => ReactNode;\n}\n\nexport const Slot = forwardRef<HTMLElement, SlotProps>(function Slot(\n { children, wrapChildren, ...slotProps },\n forwardedRef,\n) {\n // A bare string, an array, or nothing at all — there is no element to merge into.\n // Rendering the children plain would silently drop every prop the slot carries\n // (including the ref and the ARIA wiring a trigger depends on), so this renders\n // nothing rather than something subtly broken.\n if (!isValidElement(children)) return null;\n\n const child = children as ReactElement<{ children?: ReactNode }>;\n\n const merged = {\n ...mergeProps(slotProps, child.props as Record<string, unknown>),\n ref: composeRefs(forwardedRef, getElementRef(child)),\n } as Record<string, unknown>;\n\n return wrapChildren\n ? cloneElement(child, merged, wrapChildren(child.props.children))\n : cloneElement(child, merged);\n});\n\nfunction mergeProps(\n slotProps: Record<string, unknown>,\n childProps: Record<string, unknown>,\n): Record<string, unknown> {\n const merged: Record<string, unknown> = { ...slotProps };\n\n for (const key in childProps) {\n const slotValue = slotProps[key];\n const childValue = childProps[key];\n\n if (/^on[A-Z]/.test(key)) {\n // Both handlers run. The slot's fires first so a component can set up state\n // before the consumer's own handler observes it.\n if (typeof slotValue === 'function' && typeof childValue === 'function') {\n merged[key] = (...args: unknown[]) => {\n (slotValue as (...a: unknown[]) => void)(...args);\n (childValue as (...a: unknown[]) => void)(...args);\n };\n } else {\n merged[key] = childValue ?? slotValue;\n }\n } else if (key === 'className') {\n merged[key] = clsx(slotValue as string, childValue as string);\n } else if (key === 'style') {\n merged[key] = { ...(slotValue as CSSProperties), ...(childValue as CSSProperties) };\n } else {\n merged[key] = childValue;\n }\n }\n\n return merged;\n}\n\n/**\n * React 19 exposes a `ref` on `props`; React 18 kept it on the element. The peer range is\n * `>=19` from 0.11; the element fallback stays for elements created by older copies of React.\n */\nfunction getElementRef(element: ReactElement): Ref<unknown> | undefined {\n const asRecord = element as unknown as {\n ref?: Ref<unknown>;\n props?: { ref?: Ref<unknown> };\n };\n return asRecord.props?.ref ?? asRecord.ref;\n}\n\n/** Fan one node out to several refs, callback or object. */\nexport function composeRefs<T>(...refs: (Ref<T> | undefined)[]) {\n return (node: T | null) => {\n for (const ref of refs) {\n if (!ref) continue;\n if (typeof ref === 'function') {\n ref(node);\n } else {\n (ref as { current: T | null }).current = node;\n }\n }\n };\n}\n","import { forwardRef, type SVGProps } from 'react';\nimport { Loader2Icon } from 'lucide-react';\n\nimport { cn } from '../../lib/cn';\n\nexport type SpinnerProps = SVGProps<SVGSVGElement>;\n\n/**\n * Spinner: an indicator that can be used to show a loading state. `Progress` is the determinate\n * counterpart.\n *\n * A spinning `role=\"status\"` icon named \"Loading\" (pass `aria-label` for another name). Size it\n * with `className` (`size-6`); it takes the text colour.\n */\nexport const Spinner = forwardRef<SVGSVGElement, SpinnerProps>(function Spinner({ className, ...props }, ref) {\n return (\n <Loader2Icon\n ref={ref}\n data-slot=\"spinner\"\n role=\"status\"\n aria-label=\"Loading\"\n className={cn('size-4 animate-spin', className)}\n {...props}\n />\n );\n});\n","import {\n cloneElement,\n forwardRef,\n isValidElement,\n type ButtonHTMLAttributes,\n type MouseEvent,\n type ReactElement,\n type ReactNode,\n} from 'react';\nimport { cn } from '../../lib/cn';\nimport { Slot } from '../../lib/slot';\nimport { Spinner } from '../feedback/spinner';\n\n/**\n * Button: displays a button or a component that looks like a button.\n *\n * Variants `default`, `outline`, `secondary`, `ghost`, `destructive`, `link`; sizes `xs` (24px),\n * `sm` (28px), `default` (32px), `lg` (36px), and the square `icon-xs`, `icon-sm`, `icon`,\n * `icon-lg` for icon-only buttons (name them with `aria-label`). Icons are children with\n * `data-icon=\"inline-start\"` / `\"inline-end\"`, which tighten the padding on that side.\n *\n * Shorthand: `leadingIcon` / `trailingIcon` render the same as those icon children, and\n * `loading` swaps the leading icon for a spinner, sets `aria-busy` and ignores presses while\n * keeping focus (`aria-disabled`, not `disabled`).\n */\n\nexport type ButtonVariant = 'default' | 'outline' | 'secondary' | 'ghost' | 'destructive' | 'link';\nexport type ButtonSize = 'default' | 'xs' | 'sm' | 'lg' | 'icon' | 'icon-xs' | 'icon-sm' | 'icon-lg';\n\nexport interface ButtonProps extends ButtonHTMLAttributes<HTMLButtonElement> {\n /** Default `default`. */\n variant?: ButtonVariant;\n /** Default `default`. */\n size?: ButtonSize;\n /** Render the single child element instead of a `<button>`, e.g. a router `Link`. */\n asChild?: boolean;\n /** Shorthand: a leading icon (as `data-icon=\"inline-start\"`). */\n leadingIcon?: ReactNode;\n /** Shorthand: a trailing icon (as `data-icon=\"inline-end\"`). */\n trailingIcon?: ReactNode;\n /**\n * A request is in flight: a spinner replaces the leading icon, `aria-busy` is set, and\n * presses are ignored. The button keeps focus (`aria-disabled`, not `disabled`).\n */\n loading?: boolean;\n /** Announced while `loading`. Default: the button's own content. */\n loadingLabel?: string;\n}\n\nconst BASE =\n \"group/button inline-flex shrink-0 items-center justify-center rounded-lg border border-transparent bg-clip-padding text-sm font-medium whitespace-nowrap transition-all outline-none select-none focus-visible:border-ring focus-visible:ring-3 focus-visible:ring-ring/50 active:not-aria-[haspopup]:translate-y-px disabled:pointer-events-none disabled:opacity-50 aria-disabled:pointer-events-none aria-disabled:opacity-50 aria-invalid:border-destructive aria-invalid:ring-3 aria-invalid:ring-destructive/20 dark:aria-invalid:border-destructive/50 dark:aria-invalid:ring-destructive/40 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4\";\n\nconst VARIANT: Record<ButtonVariant, string> = {\n default: 'bg-primary text-primary-foreground hover:bg-primary/80',\n outline:\n 'border-border bg-background hover:bg-muted hover:text-foreground aria-expanded:bg-muted aria-expanded:text-foreground dark:border-input dark:bg-input/30 dark:hover:bg-input/50',\n secondary:\n 'bg-secondary text-secondary-foreground hover:bg-[color-mix(in_oklch,var(--secondary),var(--foreground)_5%)] aria-expanded:bg-secondary aria-expanded:text-secondary-foreground',\n ghost:\n 'hover:bg-muted hover:text-foreground aria-expanded:bg-muted aria-expanded:text-foreground dark:hover:bg-muted/50',\n destructive:\n 'bg-destructive/10 text-destructive hover:bg-destructive/20 focus-visible:border-destructive/40 focus-visible:ring-destructive/20 dark:bg-destructive/20 dark:hover:bg-destructive/30 dark:focus-visible:ring-destructive/40',\n link: 'text-primary underline-offset-4 hover:underline',\n};\n\nconst SIZE: Record<ButtonSize, string> = {\n default: 'h-8 gap-1.5 px-2.5 has-data-[icon=inline-end]:pe-2 has-data-[icon=inline-start]:ps-2',\n xs: \"h-6 gap-1 rounded-[min(var(--radius-md),10px)] px-2 text-xs in-data-[slot=button-group]:rounded-lg has-data-[icon=inline-end]:pe-1.5 has-data-[icon=inline-start]:ps-1.5 [&_svg:not([class*='size-'])]:size-3\",\n sm: \"h-7 gap-1 rounded-[min(var(--radius-md),12px)] px-2.5 text-[0.8rem] in-data-[slot=button-group]:rounded-lg has-data-[icon=inline-end]:pe-1.5 has-data-[icon=inline-start]:ps-1.5 [&_svg:not([class*='size-'])]:size-3.5\",\n lg: 'h-9 gap-1.5 px-2.5 has-data-[icon=inline-end]:pe-2 has-data-[icon=inline-start]:ps-2',\n icon: 'size-8',\n 'icon-xs':\n \"size-6 rounded-[min(var(--radius-md),10px)] in-data-[slot=button-group]:rounded-lg [&_svg:not([class*='size-'])]:size-3\",\n 'icon-sm': 'size-7 rounded-[min(var(--radius-md),12px)] in-data-[slot=button-group]:rounded-lg',\n 'icon-lg': 'size-9',\n};\n\n/** The classes of a Button, for an element another library renders (e.g. Calendar's nav). */\nexport function buttonVariants({\n variant = 'default',\n size = 'default',\n}: { variant?: ButtonVariant; size?: ButtonSize } = {}) {\n return cn(BASE, VARIANT[variant], SIZE[size]);\n}\n\n/** An icon shorthand, rendered exactly as an icon child with `data-icon`. */\nfunction withDataIcon(icon: ReactNode, side: 'inline-start' | 'inline-end') {\n if (isValidElement(icon)) {\n return cloneElement(icon as ReactElement<Record<string, unknown>>, { 'data-icon': side, 'aria-hidden': true });\n }\n return (\n <span data-icon={side} aria-hidden className=\"inline-flex shrink-0\">\n {icon}\n </span>\n );\n}\n\nexport const Button = forwardRef<HTMLButtonElement, ButtonProps>(function Button(\n {\n variant = 'default',\n size = 'default',\n asChild = false,\n leadingIcon,\n trailingIcon,\n loading = false,\n loadingLabel,\n disabled,\n type,\n children,\n className,\n onClick,\n ...props\n },\n ref,\n) {\n // Inert to a press but still focusable: a loading button, or any disabled `asChild`\n // element (an `<a>` has no `disabled` attribute to fall back on).\n const softDisabled = loading || (asChild && Boolean(disabled));\n\n const handleClick = (event: MouseEvent<HTMLButtonElement>) => {\n if (softDisabled) {\n // Stops a router `<Link>` too: it skips navigation when the event is prevented.\n event.preventDefault();\n event.stopPropagation();\n return;\n }\n onClick?.(event);\n };\n\n const small = size === 'xs' || size === 'icon-xs';\n const decorate = (content: ReactNode) => (\n <>\n {loading ? (\n <Spinner\n data-icon=\"inline-start\"\n className={small ? 'size-3' : undefined}\n // Named by loadingLabel; otherwise the busy button announces its own content.\n {...(loadingLabel\n ? { 'aria-label': loadingLabel }\n : { role: undefined, 'aria-label': undefined, 'aria-hidden': true })}\n />\n ) : leadingIcon !== undefined && leadingIcon !== null ? (\n withDataIcon(leadingIcon, 'inline-start')\n ) : null}\n {content}\n {trailingIcon !== undefined && trailingIcon !== null ? withDataIcon(trailingIcon, 'inline-end') : null}\n </>\n );\n\n const rootProps = {\n className: cn(BASE, VARIANT[variant], SIZE[size], className),\n 'data-slot': 'button',\n 'data-variant': variant,\n 'data-size': size,\n 'aria-busy': loading || undefined,\n 'aria-disabled': softDisabled || undefined,\n onClick: handleClick,\n ...props,\n };\n\n if (asChild) {\n // `aria-disabled`, not `disabled`: the child may be an `<a>`, which has no disabled\n // attribute. A disabled link also leaves the tab order, as a disabled `<button>` does.\n return (\n <Slot ref={ref} wrapChildren={decorate} tabIndex={disabled ? -1 : undefined} {...rootProps}>\n {children}\n </Slot>\n );\n }\n\n return (\n <button ref={ref} type={type ?? 'button'} disabled={disabled} {...rootProps}>\n {decorate(children)}\n </button>\n );\n});\n"],"mappings":";;;;;AAAA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,OAMK;AACP,OAAO,UAAU;AAsCV,IAAM,OAAO,WAAmC,SAASA,MAC9D,EAAE,UAAU,cAAc,GAAG,UAAU,GACvC,cACA;AAKA,MAAI,CAAC,eAAe,QAAQ,EAAG,QAAO;AAEtC,QAAM,QAAQ;AAEd,QAAM,SAAS;AAAA,IACb,GAAG,WAAW,WAAW,MAAM,KAAgC;AAAA,IAC/D,KAAK,YAAY,cAAc,cAAc,KAAK,CAAC;AAAA,EACrD;AAEA,SAAO,eACH,aAAa,OAAO,QAAQ,aAAa,MAAM,MAAM,QAAQ,CAAC,IAC9D,aAAa,OAAO,MAAM;AAChC,CAAC;AAED,SAAS,WACP,WACA,YACyB;AACzB,QAAM,SAAkC,EAAE,GAAG,UAAU;AAEvD,aAAW,OAAO,YAAY;AAC5B,UAAM,YAAY,UAAU,GAAG;AAC/B,UAAM,aAAa,WAAW,GAAG;AAEjC,QAAI,WAAW,KAAK,GAAG,GAAG;AAGxB,UAAI,OAAO,cAAc,cAAc,OAAO,eAAe,YAAY;AACvE,eAAO,GAAG,IAAI,IAAI,SAAoB;AACpC,UAAC,UAAwC,GAAG,IAAI;AAChD,UAAC,WAAyC,GAAG,IAAI;AAAA,QACnD;AAAA,MACF,OAAO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AA,IACA,iBAAiB,UAAa,iBAAiB,OAAO,aAAa,cAAc,YAAY,IAAI;AAAA,KACpG;AAGF,QAAM,YAAY;AAAA,IAChB,WAAW,GAAG,MAAM,QAAQ,OAAO,GAAG,KAAK,IAAI,GAAG,SAAS;AAAA,IAC3D,aAAa;AAAA,IACb,gBAAgB;AAAA,IAChB,aAAa;AAAA,IACb,aAAa,WAAW;AAAA,IACxB,iBAAiB,gBAAgB;AAAA,IACjC,SAAS;AAAA,IACT,GAAG;AAAA,EACL;AAEA,MAAI,SAAS;AAGX,WACE,gBAAAA,KAAC,QAAK,KAAU,cAAc,UAAU,UAAU,WAAW,KAAK,QAAY,GAAG,WAC9E,UACH;AAAA,EAEJ;AAEA,SACE,gBAAAA,KAAC,YAAO,KAAU,MAAM,QAAQ,UAAU,UAAqB,GAAG,WAC/D,mBAAS,QAAQ,GACpB;AAEJ,CAAC;","names":["Slot","forwardRef","forwardRef","Spinner","cloneElement","forwardRef","isValidElement","jsx","isValidElement","cloneElement","forwardRef","Button"]}
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import * as react from 'react';
|
|
2
|
+
import { ButtonHTMLAttributes, ReactNode, HTMLAttributes, ComponentProps } from 'react';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Button: displays a button or a component that looks like a button.
|
|
6
|
+
*
|
|
7
|
+
* Variants `default`, `outline`, `secondary`, `ghost`, `destructive`, `link`; sizes `xs` (24px),
|
|
8
|
+
* `sm` (28px), `default` (32px), `lg` (36px), and the square `icon-xs`, `icon-sm`, `icon`,
|
|
9
|
+
* `icon-lg` for icon-only buttons (name them with `aria-label`). Icons are children with
|
|
10
|
+
* `data-icon="inline-start"` / `"inline-end"`, which tighten the padding on that side.
|
|
11
|
+
*
|
|
12
|
+
* Shorthand: `leadingIcon` / `trailingIcon` render the same as those icon children, and
|
|
13
|
+
* `loading` swaps the leading icon for a spinner, sets `aria-busy` and ignores presses while
|
|
14
|
+
* keeping focus (`aria-disabled`, not `disabled`).
|
|
15
|
+
*/
|
|
16
|
+
type ButtonVariant = 'default' | 'outline' | 'secondary' | 'ghost' | 'destructive' | 'link';
|
|
17
|
+
type ButtonSize = 'default' | 'xs' | 'sm' | 'lg' | 'icon' | 'icon-xs' | 'icon-sm' | 'icon-lg';
|
|
18
|
+
interface ButtonProps extends ButtonHTMLAttributes<HTMLButtonElement> {
|
|
19
|
+
/** Default `default`. */
|
|
20
|
+
variant?: ButtonVariant;
|
|
21
|
+
/** Default `default`. */
|
|
22
|
+
size?: ButtonSize;
|
|
23
|
+
/** Render the single child element instead of a `<button>`, e.g. a router `Link`. */
|
|
24
|
+
asChild?: boolean;
|
|
25
|
+
/** Shorthand: a leading icon (as `data-icon="inline-start"`). */
|
|
26
|
+
leadingIcon?: ReactNode;
|
|
27
|
+
/** Shorthand: a trailing icon (as `data-icon="inline-end"`). */
|
|
28
|
+
trailingIcon?: ReactNode;
|
|
29
|
+
/**
|
|
30
|
+
* A request is in flight: a spinner replaces the leading icon, `aria-busy` is set, and
|
|
31
|
+
* presses are ignored. The button keeps focus (`aria-disabled`, not `disabled`).
|
|
32
|
+
*/
|
|
33
|
+
loading?: boolean;
|
|
34
|
+
/** Announced while `loading`. Default: the button's own content. */
|
|
35
|
+
loadingLabel?: string;
|
|
36
|
+
}
|
|
37
|
+
declare const Button: react.ForwardRefExoticComponent<ButtonProps & react.RefAttributes<HTMLButtonElement>>;
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* CodeBlock: displays code with an optional header, line numbers, diff and highlighted lines.
|
|
41
|
+
*
|
|
42
|
+
* Composition: `CodeBlockHeader` (`CodeBlockTitle`, `CodeBlockActions` with a
|
|
43
|
+
* `CodeBlockCopyButton`), `CodeBlockContent` (a `pre` > `code`; `lineNumbers`, `wrap`,
|
|
44
|
+
* `startLine`) holding `CodeBlockLine`s (`variant` `default` / `added` / `removed` /
|
|
45
|
+
* `highlighted`), and `CodeBlockFooter`. `CodeBlockActions` placed directly in the block floats in
|
|
46
|
+
* the corner and shows on hover or focus.
|
|
47
|
+
*
|
|
48
|
+
* Shorthand: `code` (with `title`, `copyable`, `lineNumbers`, `wrap`, `startLine`,
|
|
49
|
+
* `highlightLines`) renders all of that. Syntax colours come from `@platned/ui/code-block-highlight`
|
|
50
|
+
* (Shiki, an optional peer): pass its lines as `lines`, or use its `HighlightedCodeBlock`.
|
|
51
|
+
*/
|
|
52
|
+
type CodeBlockVariant = 'default' | 'destructive';
|
|
53
|
+
type CodeBlockSize = 'default' | 'sm';
|
|
54
|
+
type CodeBlockLineVariant = 'default' | 'added' | 'removed' | 'highlighted';
|
|
55
|
+
interface CodeBlockProps extends Omit<HTMLAttributes<HTMLDivElement>, 'title'> {
|
|
56
|
+
/** Default `default`. */
|
|
57
|
+
variant?: CodeBlockVariant;
|
|
58
|
+
/** `sm` has tighter padding and `text-xs` code, for tool output. Default `default`. */
|
|
59
|
+
size?: CodeBlockSize;
|
|
60
|
+
/** Shorthand: the code. Renders the header (with `title` / `copyable`) and the content. */
|
|
61
|
+
code?: string;
|
|
62
|
+
/** Shorthand: one node per line (e.g. from `useHighlightedCode`); defaults to `code` split by line. */
|
|
63
|
+
lines?: readonly ReactNode[];
|
|
64
|
+
/** Shorthand: the header title, e.g. a file name. */
|
|
65
|
+
title?: ReactNode;
|
|
66
|
+
/** Shorthand: a copy button in the header (or floating, without a title). */
|
|
67
|
+
copyable?: boolean;
|
|
68
|
+
/** Shorthand: number the lines. */
|
|
69
|
+
lineNumbers?: boolean;
|
|
70
|
+
/** Shorthand: wrap long lines instead of scrolling. */
|
|
71
|
+
wrap?: boolean;
|
|
72
|
+
/** Shorthand: the first line number. Default 1. */
|
|
73
|
+
startLine?: number;
|
|
74
|
+
/** Shorthand: 1-based line numbers to highlight. */
|
|
75
|
+
highlightLines?: readonly number[];
|
|
76
|
+
/** Shorthand: the language, as a `data-language` attribute (colours come from the highlight entry). */
|
|
77
|
+
language?: string;
|
|
78
|
+
}
|
|
79
|
+
declare const CodeBlock: react.ForwardRefExoticComponent<CodeBlockProps & react.RefAttributes<HTMLDivElement>>;
|
|
80
|
+
/** A row above the content for a title and actions. */
|
|
81
|
+
declare function CodeBlockHeader({ className, ...props }: HTMLAttributes<HTMLDivElement>): react.JSX.Element;
|
|
82
|
+
/** The header title, e.g. a file name. Icons sit inline before the text. */
|
|
83
|
+
declare function CodeBlockTitle({ className, ...props }: HTMLAttributes<HTMLDivElement>): react.JSX.Element;
|
|
84
|
+
/** Buttons for the block. In the header they sit at the end; directly in the block they float. */
|
|
85
|
+
declare function CodeBlockActions({ className, ...props }: HTMLAttributes<HTMLDivElement>): react.JSX.Element;
|
|
86
|
+
interface CodeBlockCopyButtonProps extends ButtonProps {
|
|
87
|
+
/** The text to copy. */
|
|
88
|
+
value: string;
|
|
89
|
+
}
|
|
90
|
+
/** Copies `value`; shows a check for two seconds and announces "Copied". */
|
|
91
|
+
declare function CodeBlockCopyButton({ value, variant, size, className, onClick, ...props }: CodeBlockCopyButtonProps): react.JSX.Element;
|
|
92
|
+
interface CodeBlockContentProps extends ComponentProps<'pre'> {
|
|
93
|
+
/** Wrap long lines instead of scrolling. */
|
|
94
|
+
wrap?: boolean;
|
|
95
|
+
/** Number the lines (CodeBlockLine children, or a string split into lines). */
|
|
96
|
+
lineNumbers?: boolean;
|
|
97
|
+
/** The first line number. Default 1. */
|
|
98
|
+
startLine?: number;
|
|
99
|
+
}
|
|
100
|
+
/** The scrolling `pre` > `code`. Always left to right; focusable so the keyboard can scroll it. */
|
|
101
|
+
declare function CodeBlockContent({ className, children, style, wrap, lineNumbers, startLine, ...props }: CodeBlockContentProps): react.JSX.Element;
|
|
102
|
+
interface CodeBlockLineProps extends HTMLAttributes<HTMLSpanElement> {
|
|
103
|
+
/** Default `default`. `added` / `removed` also carry a `+` / `−` marker. */
|
|
104
|
+
variant?: CodeBlockLineVariant;
|
|
105
|
+
}
|
|
106
|
+
/** One line. Numbered by CSS when the content has `lineNumbers`; the number is hidden from readers. */
|
|
107
|
+
declare function CodeBlockLine({ className, variant, children, ...props }: CodeBlockLineProps): react.JSX.Element;
|
|
108
|
+
/** A row under the content, e.g. a language label or a Show more button. */
|
|
109
|
+
declare function CodeBlockFooter({ className, ...props }: HTMLAttributes<HTMLDivElement>): react.JSX.Element;
|
|
110
|
+
|
|
111
|
+
export { type ButtonProps as B, type CodeBlockProps as C, type ButtonVariant as a, type ButtonSize as b, Button as c, CodeBlock as d, CodeBlockActions as e, CodeBlockContent as f, type CodeBlockContentProps as g, CodeBlockCopyButton as h, type CodeBlockCopyButtonProps as i, CodeBlockFooter as j, CodeBlockHeader as k, CodeBlockLine as l, type CodeBlockLineProps as m, type CodeBlockLineVariant as n, type CodeBlockSize as o, CodeBlockTitle as p, type CodeBlockVariant as q };
|