@vvedantb/ui 0.12.1 → 0.13.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 +51 -2
- package/app/README.md +259 -0
- package/package.json +17 -11
- package/src/artifacts/artifact-card.tsx +211 -0
- package/src/artifacts/artifact-dialogs.tsx +153 -0
- package/src/artifacts/artifact-file.ts +26 -0
- package/src/artifacts/artifact-frame.tsx +195 -0
- package/src/artifacts/artifact-list-toolbar.tsx +110 -0
- package/src/artifacts/artifact-list.tsx +54 -0
- package/src/artifacts/artifact-render.tsx +50 -0
- package/src/artifacts/artifact-type-icon.tsx +61 -0
- package/src/artifacts/artifact-versions-menu.tsx +103 -0
- package/src/artifacts/artifact-viewer.tsx +133 -0
- package/src/artifacts/index.ts +11 -0
- package/src/artifacts/types.ts +18 -0
- package/src/index.ts +4 -0
- package/tokens/README.md +98 -0
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import { IconCheck, IconChevronDown, IconHistory, IconRestore } from "@tabler/icons-react";
|
|
2
|
+
import { toast } from "sonner";
|
|
3
|
+
import { formatCompactRelativeTime } from "../../app/src/time/compactRelativeTime";
|
|
4
|
+
import { Button } from "../ui/button";
|
|
5
|
+
import {
|
|
6
|
+
DropdownMenu,
|
|
7
|
+
DropdownMenuContent,
|
|
8
|
+
DropdownMenuItem,
|
|
9
|
+
DropdownMenuLabel,
|
|
10
|
+
DropdownMenuSeparator,
|
|
11
|
+
DropdownMenuTrigger,
|
|
12
|
+
} from "../ui/dropdown-menu";
|
|
13
|
+
import type { ArtifactVersionSummary } from "./types";
|
|
14
|
+
|
|
15
|
+
export type ArtifactVersionsMenuProps = {
|
|
16
|
+
versions: readonly ArtifactVersionSummary[];
|
|
17
|
+
currentVersion: number;
|
|
18
|
+
/** The version on screen. Default `currentVersion`. */
|
|
19
|
+
viewingVersion?: number;
|
|
20
|
+
/** Show a version. Without it, picking an older version restores it. */
|
|
21
|
+
onViewVersion?: (version: number) => void;
|
|
22
|
+
/** Make a version current. With `onViewVersion`, offered as "Restore vN" while an older version is on screen. */
|
|
23
|
+
onRestoreVersion?: (version: number) => void | Promise<void>;
|
|
24
|
+
className?: string;
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
/** "vN" menu listing the kept versions, newest first, to view or restore one. */
|
|
28
|
+
export function ArtifactVersionsMenu({
|
|
29
|
+
versions,
|
|
30
|
+
currentVersion,
|
|
31
|
+
viewingVersion = currentVersion,
|
|
32
|
+
onViewVersion,
|
|
33
|
+
onRestoreVersion,
|
|
34
|
+
className,
|
|
35
|
+
}: ArtifactVersionsMenuProps) {
|
|
36
|
+
const sorted = [...versions].sort((a, b) => b.version - a.version);
|
|
37
|
+
|
|
38
|
+
const restore = async (version: number) => {
|
|
39
|
+
try {
|
|
40
|
+
await onRestoreVersion?.(version);
|
|
41
|
+
} catch {
|
|
42
|
+
toast.error("Couldn't restore version");
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
const pick = (version: number) => {
|
|
47
|
+
if (onViewVersion) onViewVersion(version);
|
|
48
|
+
else if (version !== currentVersion) void restore(version);
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
return (
|
|
52
|
+
<DropdownMenu>
|
|
53
|
+
<DropdownMenuTrigger asChild>
|
|
54
|
+
<Button
|
|
55
|
+
variant="ghost"
|
|
56
|
+
size="sm"
|
|
57
|
+
aria-label="Versions"
|
|
58
|
+
className={className}
|
|
59
|
+
startContent={<IconHistory size={16} />}
|
|
60
|
+
endContent={<IconChevronDown size={14} />}
|
|
61
|
+
>
|
|
62
|
+
v{viewingVersion}
|
|
63
|
+
</Button>
|
|
64
|
+
</DropdownMenuTrigger>
|
|
65
|
+
<DropdownMenuContent fitViewport suppressAltKey restoreScrollLockOnClose align="end" className="min-w-52">
|
|
66
|
+
<DropdownMenuLabel>Versions</DropdownMenuLabel>
|
|
67
|
+
{sorted.map((entry) => {
|
|
68
|
+
const current = entry.version === currentVersion;
|
|
69
|
+
const time = formatCompactRelativeTime(entry.createdAt);
|
|
70
|
+
return (
|
|
71
|
+
<DropdownMenuItem
|
|
72
|
+
key={entry.version}
|
|
73
|
+
data-version={entry.version}
|
|
74
|
+
disabled={!onViewVersion && (current || !onRestoreVersion)}
|
|
75
|
+
startContent={
|
|
76
|
+
entry.version === viewingVersion ? <IconCheck size={16} /> : <span aria-hidden className="size-4" />
|
|
77
|
+
}
|
|
78
|
+
description={entry.title ? `${time} · ${entry.title}` : time}
|
|
79
|
+
endContent={
|
|
80
|
+
current ? (
|
|
81
|
+
<span className="text-xs text-muted-foreground">Current</span>
|
|
82
|
+
) : !onViewVersion && onRestoreVersion ? (
|
|
83
|
+
<span className="text-xs text-muted-foreground">Restore</span>
|
|
84
|
+
) : undefined
|
|
85
|
+
}
|
|
86
|
+
onClick={() => pick(entry.version)}
|
|
87
|
+
>
|
|
88
|
+
v{entry.version}
|
|
89
|
+
</DropdownMenuItem>
|
|
90
|
+
);
|
|
91
|
+
})}
|
|
92
|
+
{onViewVersion && onRestoreVersion && viewingVersion !== currentVersion ? (
|
|
93
|
+
<>
|
|
94
|
+
<DropdownMenuSeparator />
|
|
95
|
+
<DropdownMenuItem startContent={<IconRestore size={16} />} onClick={() => void restore(viewingVersion)}>
|
|
96
|
+
Restore v{viewingVersion}
|
|
97
|
+
</DropdownMenuItem>
|
|
98
|
+
</>
|
|
99
|
+
) : null}
|
|
100
|
+
</DropdownMenuContent>
|
|
101
|
+
</DropdownMenu>
|
|
102
|
+
);
|
|
103
|
+
}
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
import type { ReactNode } from "react";
|
|
2
|
+
import { IconCopy, IconDownload, IconExternalLink, IconPencil, IconTrash } from "@tabler/icons-react";
|
|
3
|
+
import { ARTIFACT_FORMAT_FILES } from "@vvedantb/server";
|
|
4
|
+
import { skipConfirmTitle } from "../../app/src/confirm/ConfirmSkipHint";
|
|
5
|
+
import { Artifact, ArtifactAction, ArtifactActions, ArtifactHeader, ArtifactTitle } from "../ai-elements/artifact";
|
|
6
|
+
import { TooltipProvider } from "../ui/tooltip";
|
|
7
|
+
import { cn } from "../utils/cn";
|
|
8
|
+
import { useArtifactEditDialogs, type ArtifactEditCallbacks } from "./artifact-dialogs";
|
|
9
|
+
import { copyArtifactBody, downloadArtifactBody, openArtifactInNewTab } from "./artifact-file";
|
|
10
|
+
import { ArtifactRender, type ArtifactRenderProps } from "./artifact-render";
|
|
11
|
+
import { ArtifactTypeIcon } from "./artifact-type-icon";
|
|
12
|
+
import { ArtifactVersionsMenu, type ArtifactVersionsMenuProps } from "./artifact-versions-menu";
|
|
13
|
+
import type { ArtifactDocument, ArtifactVersionSummary } from "./types";
|
|
14
|
+
|
|
15
|
+
export type ArtifactViewerProps = ArtifactEditCallbacks &
|
|
16
|
+
Pick<ArtifactRenderProps, "store" | "stateGlobalAliases"> &
|
|
17
|
+
Pick<ArtifactVersionsMenuProps, "viewingVersion" | "onViewVersion" | "onRestoreVersion"> & {
|
|
18
|
+
/** The artifact, with the body of the version on screen. */
|
|
19
|
+
artifact: ArtifactDocument;
|
|
20
|
+
/** Kept versions for the versions menu. Omit to hide the menu. */
|
|
21
|
+
versions?: readonly ArtifactVersionSummary[];
|
|
22
|
+
/** The artifact's own page, for "Open in new tab". Omit to hide the button. */
|
|
23
|
+
href?: string;
|
|
24
|
+
/** Before the title, e.g. a back link from the app's router. */
|
|
25
|
+
headerStart?: ReactNode;
|
|
26
|
+
/** Extra header actions, before Delete. */
|
|
27
|
+
actions?: ReactNode;
|
|
28
|
+
className?: string;
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* One artifact: a header with the title and its actions (versions, rename,
|
|
33
|
+
* copy, download as the format's file, open in new tab, delete) above the
|
|
34
|
+
* rendered body. Rename and delete go through confirm dialogs; Alt-click on
|
|
35
|
+
* Delete skips the dialog.
|
|
36
|
+
*/
|
|
37
|
+
export function ArtifactViewer({
|
|
38
|
+
artifact,
|
|
39
|
+
store,
|
|
40
|
+
stateGlobalAliases,
|
|
41
|
+
versions,
|
|
42
|
+
viewingVersion,
|
|
43
|
+
onViewVersion,
|
|
44
|
+
onRestoreVersion,
|
|
45
|
+
href,
|
|
46
|
+
onRename,
|
|
47
|
+
onDelete,
|
|
48
|
+
headerStart,
|
|
49
|
+
actions,
|
|
50
|
+
className,
|
|
51
|
+
}: ArtifactViewerProps) {
|
|
52
|
+
const edit = useArtifactEditDialogs({ title: artifact.title, onRename, onDelete });
|
|
53
|
+
const extension = ARTIFACT_FORMAT_FILES[artifact.format].extension;
|
|
54
|
+
const actionClass = "h-8 min-w-8";
|
|
55
|
+
|
|
56
|
+
return (
|
|
57
|
+
<TooltipProvider>
|
|
58
|
+
<Artifact className={cn("flex min-h-0 flex-1 flex-col overflow-hidden", className)}>
|
|
59
|
+
<ArtifactHeader className="items-center">
|
|
60
|
+
<div className="flex min-w-0 items-center gap-2">
|
|
61
|
+
{headerStart}
|
|
62
|
+
<ArtifactTypeIcon type={artifact.type} />
|
|
63
|
+
<ArtifactTitle className="truncate">{artifact.title}</ArtifactTitle>
|
|
64
|
+
</div>
|
|
65
|
+
<ArtifactActions className="shrink-0">
|
|
66
|
+
{versions ? (
|
|
67
|
+
<ArtifactVersionsMenu
|
|
68
|
+
versions={versions}
|
|
69
|
+
currentVersion={artifact.currentVersion}
|
|
70
|
+
viewingVersion={viewingVersion}
|
|
71
|
+
onViewVersion={onViewVersion}
|
|
72
|
+
onRestoreVersion={onRestoreVersion}
|
|
73
|
+
/>
|
|
74
|
+
) : null}
|
|
75
|
+
{onRename ? (
|
|
76
|
+
<ArtifactAction
|
|
77
|
+
tooltip="Rename"
|
|
78
|
+
size="icon-sm"
|
|
79
|
+
className={actionClass}
|
|
80
|
+
icon={<IconPencil size={16} />}
|
|
81
|
+
onClick={edit.startRename}
|
|
82
|
+
/>
|
|
83
|
+
) : null}
|
|
84
|
+
<ArtifactAction
|
|
85
|
+
tooltip="Copy"
|
|
86
|
+
size="icon-sm"
|
|
87
|
+
className={actionClass}
|
|
88
|
+
icon={<IconCopy size={16} />}
|
|
89
|
+
onClick={() => void copyArtifactBody(artifact.body)}
|
|
90
|
+
/>
|
|
91
|
+
<ArtifactAction
|
|
92
|
+
tooltip={`Download .${extension}`}
|
|
93
|
+
label="Download"
|
|
94
|
+
size="icon-sm"
|
|
95
|
+
className={actionClass}
|
|
96
|
+
icon={<IconDownload size={16} />}
|
|
97
|
+
onClick={() => downloadArtifactBody(artifact.title, artifact.format, artifact.body)}
|
|
98
|
+
/>
|
|
99
|
+
{href !== undefined ? (
|
|
100
|
+
<ArtifactAction
|
|
101
|
+
tooltip="Open in new tab"
|
|
102
|
+
size="icon-sm"
|
|
103
|
+
className={actionClass}
|
|
104
|
+
icon={<IconExternalLink size={16} />}
|
|
105
|
+
onClick={() => openArtifactInNewTab(href)}
|
|
106
|
+
/>
|
|
107
|
+
) : null}
|
|
108
|
+
{actions}
|
|
109
|
+
{onDelete ? (
|
|
110
|
+
<ArtifactAction
|
|
111
|
+
tooltip={skipConfirmTitle("Delete")}
|
|
112
|
+
label="Delete"
|
|
113
|
+
size="icon-sm"
|
|
114
|
+
className={cn(actionClass, "text-danger hover:text-danger")}
|
|
115
|
+
icon={<IconTrash size={16} />}
|
|
116
|
+
onClick={(event) => edit.requestDelete(event)}
|
|
117
|
+
/>
|
|
118
|
+
) : null}
|
|
119
|
+
</ArtifactActions>
|
|
120
|
+
</ArtifactHeader>
|
|
121
|
+
<div className="min-h-0 flex-1 overflow-hidden bg-surface-secondary">
|
|
122
|
+
<ArtifactRender
|
|
123
|
+
artifact={artifact}
|
|
124
|
+
store={store}
|
|
125
|
+
stateGlobalAliases={stateGlobalAliases}
|
|
126
|
+
className="h-full min-h-64"
|
|
127
|
+
/>
|
|
128
|
+
</div>
|
|
129
|
+
</Artifact>
|
|
130
|
+
{edit.dialogs}
|
|
131
|
+
</TooltipProvider>
|
|
132
|
+
);
|
|
133
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export * from "./types";
|
|
2
|
+
export * from "./artifact-type-icon";
|
|
3
|
+
export * from "./artifact-file";
|
|
4
|
+
export * from "./artifact-frame";
|
|
5
|
+
export * from "./artifact-render";
|
|
6
|
+
export * from "./artifact-dialogs";
|
|
7
|
+
export * from "./artifact-card";
|
|
8
|
+
export * from "./artifact-list";
|
|
9
|
+
export * from "./artifact-list-toolbar";
|
|
10
|
+
export * from "./artifact-versions-menu";
|
|
11
|
+
export * from "./artifact-viewer";
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { ArtifactDetailRow, ArtifactListRow } from "@vvedantb/server";
|
|
2
|
+
|
|
3
|
+
/** What a card or list row shows. Any `ArtifactListRow` fits; the body is never needed. */
|
|
4
|
+
export type ArtifactSummary = Pick<ArtifactListRow, "id" | "title" | "description" | "type" | "format" | "updatedAt">;
|
|
5
|
+
|
|
6
|
+
/** What the viewer renders: the summary fields it shows plus the body of the version on screen. */
|
|
7
|
+
export type ArtifactDocument = Pick<
|
|
8
|
+
ArtifactDetailRow,
|
|
9
|
+
"id" | "title" | "type" | "format" | "language" | "stateSpec" | "currentVersion" | "body"
|
|
10
|
+
>;
|
|
11
|
+
|
|
12
|
+
/** One entry in the versions menu. */
|
|
13
|
+
export type ArtifactVersionSummary = {
|
|
14
|
+
version: number;
|
|
15
|
+
createdAt: number;
|
|
16
|
+
/** The title the artifact had at this version, when it differs. */
|
|
17
|
+
title?: string;
|
|
18
|
+
};
|
package/src/index.ts
CHANGED
|
@@ -106,6 +106,10 @@ export * from "./ai-elements/sources";
|
|
|
106
106
|
export * from "./ai-elements/speech-input";
|
|
107
107
|
export * from "./ai-elements/suggestion";
|
|
108
108
|
|
|
109
|
+
// Artifact viewers: frame with the state bridge, card, list, toolbar, viewer.
|
|
110
|
+
// The core (schemas, state ops, document wrapper) comes from `@vvedantb/server`.
|
|
111
|
+
export * from "./artifacts";
|
|
112
|
+
|
|
109
113
|
export * from "./audio";
|
|
110
114
|
|
|
111
115
|
export * from "./composer";
|
package/tokens/README.md
ADDED
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
# `@vvedantb/ui/tokens`
|
|
2
|
+
|
|
3
|
+
Design tokens and shared Tailwind v4 CSS for the vvedantb web apps. The CSS and Tailwind preset are subpaths of `@vvedantb/ui`; the native JS tokens are named exports of the root (`tokens`, `Tokens`). Source-exported: no build step. Paths in the `File` column are relative to `packages/ui/tokens/`.
|
|
4
|
+
|
|
5
|
+
## Exports
|
|
6
|
+
|
|
7
|
+
| Export | File | What it is |
|
|
8
|
+
| --- | --- | --- |
|
|
9
|
+
| `@vvedantb/ui/tokens`, `@vvedantb/ui/tokens/tokens.css` | `src/tokens.css` | Colour, radius, shadow, ease and font tokens (`@theme`), light/dark variables, `dark` variant, the radius utilities `rounded-surface` (`clamp(0.75rem, var(--radius), 1rem)`), `rounded-menu-item` (`min(var(--radius), 0.5rem)`) and `rounded-control` (`min(var(--radius), 0.625rem)`) (0.7.1; `rounded-surface` was in `utilities.css` before), `*` border and `body` defaults. 0.7.2 adds `--sidebar-accent` / `sidebar-accent` (sidebar nav row fill: light `var(--surface-tertiary)`, dark `oklch(22.64% 0 0)`). In 0.2.1 it also defines shadcn-style aliases (`primary`, `muted-foreground`, `secondary`, `destructive`, `card`, `popover`, `input`, `ring`) that point at the same tokens. |
|
|
10
|
+
| `tokens` and `Tokens` from `@vvedantb/ui` | `src/native.ts` | JS colours, radii and spacing for React Native. `@vvedantb/native-ui` keeps its own copy in `src/tokens.ts`; a test keeps the two equal. |
|
|
11
|
+
| `@vvedantb/ui/tokens/css/base.css` | `src/css/base.css` | `html` touch/accent, `::selection`, control transitions, pointer cursor, range accent (`@layer base`). |
|
|
12
|
+
| `@vvedantb/ui/tokens/css/dialog.css` | `src/css/dialog.css` | Unlayered `max-width: none` for `@vvedantb/ui` compact (bottom-sheet) dialogs. |
|
|
13
|
+
| `@vvedantb/ui/tokens/css/modal.css` | `src/css/modal.css` | `.t-modal`, `.is-open`, `.is-closing` and `t-modal-presence-wait` (`@layer components`). |
|
|
14
|
+
| `@vvedantb/ui/tokens/css/tabs.css` | `src/css/tabs.css` | `.t-tab`, active colour, `.t-tabs-pill`, small-screen `.t-tabs` scrolling. |
|
|
15
|
+
| `@vvedantb/ui/tokens/css/tabs-pills.css` | `src/css/tabs-pills.css` | `--tabs-*` colour variables, `.t-tabs--segmented`, `.t-tabs--pills` and pill hover / active fills. |
|
|
16
|
+
| `@vvedantb/ui/tokens/css/utilities.css` | `src/css/utilities.css` | `@utility hit-target` and `@utility reveal-on-hover`. `rounded-surface` moved to `tokens.css` in 0.7.1. |
|
|
17
|
+
| `@vvedantb/ui/tokens/css/scrollbar-thin.css` | `src/css/scrollbar-thin.css` | `.scrollbar-thin` (`@layer utilities`, always emitted). |
|
|
18
|
+
| `@vvedantb/ui/tokens/css/animations.css` | `src/css/animations.css` | `animate-aurora`, `animate-fade-in-up`, `animate-indeterminate` as `@theme` (CSS-first apps). |
|
|
19
|
+
| `@vvedantb/ui/tokens/css/compat-shadcn-rgb.css`, `@vvedantb/ui/tokens/compat/shadcn-rgb.css` | `src/css/compat-shadcn-rgb.css` | Replaces `tokens.css` for apps with shadcn-style `R G B` channel variables. Defines only the UI-only `--color-*` names as `rgb(var(--x) / alpha)` references, `--radius-field`, `--scrollbar`, `--field-radius`, the same three radius utilities as `tokens.css` and a `glass-panel-strong` fallback. Import it **or** `tokens.css`, never both. |
|
|
20
|
+
| `@vvedantb/ui/tokens/css/index.css` | `src/css/index.css` | base + dialog + utilities + scrollbar-thin + animations, for new CSS-first apps. |
|
|
21
|
+
| `@vvedantb/ui/tokens/tailwind-preset` | `src/tailwind-preset.mjs` (+ `.d.mts`) | Tailwind preset for apps that load a JS config with `@config`. |
|
|
22
|
+
|
|
23
|
+
Every file was extracted because the same rule (same at-rule context, selector and body) sits in 3 or more of the five apps. The measured duplication is in `verify/ANALYSIS.md`, and the proof that each app compiles to the same CSS after migrating is in `verify/RESULTS.md`. Blocks that only 2 apps share, or that drift in a way that would change an app's CSS, stay in the apps; `verify/ANALYSIS.md` lists them.
|
|
24
|
+
|
|
25
|
+
## Use
|
|
26
|
+
|
|
27
|
+
CSS-first app (no `tailwind.config`):
|
|
28
|
+
|
|
29
|
+
```css
|
|
30
|
+
@import "tailwindcss";
|
|
31
|
+
@import "@vvedantb/ui/tokens";
|
|
32
|
+
@import "@vvedantb/ui/tokens/css/animations.css";
|
|
33
|
+
@import "@vvedantb/ui/tokens/css/base.css";
|
|
34
|
+
/* ...app @layer base rules... */
|
|
35
|
+
@import "@vvedantb/ui/tokens/css/modal.css";
|
|
36
|
+
@import "@vvedantb/ui/tokens/css/tabs.css";
|
|
37
|
+
/* ...app @layer components rules... */
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
App with a JS config (`@config "../tailwind.config.ts"`):
|
|
41
|
+
|
|
42
|
+
```ts
|
|
43
|
+
import { tokensPreset } from "@vvedantb/ui/tokens/tailwind-preset";
|
|
44
|
+
|
|
45
|
+
export default {
|
|
46
|
+
presets: [tokensPreset()],
|
|
47
|
+
// or tokensPreset({ color: (name) => `color-mix(in oklch, var(--${name}) calc(<alpha-value> * 100%), transparent)` })
|
|
48
|
+
content: ["./src/**/*.{ts,tsx}"],
|
|
49
|
+
theme: { extend: { /* app-only colours, fonts, animations */ } },
|
|
50
|
+
plugins: [tailwindcssAnimate],
|
|
51
|
+
};
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
The preset holds `darkMode: "class"`, the shared colour map (`border`, `surface.*`, `danger.*`, `field.*`, shadcn aliases `primary`/`secondary`/`destructive`/`card`/`popover`/`input` ...), `borderRadius` lg/md/sm/field, `boxShadow` soft/panel/insetSoft, `ease-smooth`, `screens` xs to 2xl in px, and the aurora / fade-in-up / indeterminate / accordion keyframes. It does not hold plugins, `content`, fonts, `accent`/`muted`/`ring`/`sidebar` (they differ per app) or accordion timings.
|
|
55
|
+
|
|
56
|
+
Do not import `css/animations.css` in an app that uses the preset: the preset already defines the same keyframes and animations.
|
|
57
|
+
|
|
58
|
+
### Where to put the imports
|
|
59
|
+
|
|
60
|
+
Tailwind inlines an `@import` where it sits, even in the middle of a file (it must be at top level, not inside an `@layer` block). Put each import where the app's own copy of the rules was. Within one layer, later rules win at equal specificity, so moving shared rules above or below app rules can flip the result for elements matched by both. `examples/migration.md` gives the exact position for each app, and `pnpm --filter @vvedantb/ui verify` checks it.
|
|
61
|
+
|
|
62
|
+
### Variables each file needs
|
|
63
|
+
|
|
64
|
+
| File | Needs | Provided by |
|
|
65
|
+
| --- | --- | --- |
|
|
66
|
+
| `base.css` | `--accent`, `--foreground` | tokens.css or the app theme |
|
|
67
|
+
| `dialog.css` | none | |
|
|
68
|
+
| `modal.css` | `--modal-open-dur`, `--modal-close-dur`, `--modal-scale`, `--modal-scale-close`, `--modal-ease` | app `:root` |
|
|
69
|
+
| `tabs.css` | `--tabs-dur`, `--tabs-ease` (app `:root`); `--tabs-text-muted`, `--tabs-text-active`, `--tabs-pill-bg` | colours: tabs-pills.css or the app theme |
|
|
70
|
+
| `tabs-pills.css` | `--muted`, `--segment`, `--segment-foreground`, `--default` | tokens.css or the app theme |
|
|
71
|
+
| `utilities.css` | `--breakpoint-sm` (Tailwind default or app theme) | Tailwind |
|
|
72
|
+
| `scrollbar-thin.css` | `--scrollbar` | tokens.css or the app theme |
|
|
73
|
+
| `animations.css` | none | |
|
|
74
|
+
| `tailwind-preset` | the CSS variables named in its colour map, `--radius`, `--field-radius` | tokens.css or the app theme |
|
|
75
|
+
|
|
76
|
+
### Using an existing shadcn RGB theme
|
|
77
|
+
|
|
78
|
+
See the package `README.md`. With the compat file, `base.css`, `scrollbar-thin.css`, `utilities.css`, `dialog.css`, `modal.css` and `tabs.css` need no `tokens.css`. `base.css` reads `--accent` and `--foreground` and `tabs-pills.css` reads `--muted`, `--segment` and `--default`. Those are not channel-compatible, so skip `tabs-pills.css` and `index.css` (which includes `base.css`) unless the app defines those variables as full colours.
|
|
79
|
+
|
|
80
|
+
### Parameters
|
|
81
|
+
|
|
82
|
+
Where apps share a rule but drifted in one value, the value is a custom property whose fallback is the most common value. Set it on `:root` to keep a different value.
|
|
83
|
+
|
|
84
|
+
| File | Property | Default | Set by |
|
|
85
|
+
| --- | --- | --- | --- |
|
|
86
|
+
| `base.css` | `--tokens-control-transition-property` | `background-color, border-color, color, box-shadow, transform, opacity` | app-c: `background-color, color, transform, opacity` |
|
|
87
|
+
| `base.css` | `--tokens-control-transition-duration` | `240ms` | app-c: `100ms` |
|
|
88
|
+
|
|
89
|
+
## Develop
|
|
90
|
+
|
|
91
|
+
```sh
|
|
92
|
+
pnpm --filter @vvedantb/ui build # export targets exist + tsc (primitives, shell, app)
|
|
93
|
+
pnpm --filter @vvedantb/ui test # vitest (app helpers) + offline node --test: exports, CSS structure, Tailwind compile, preset
|
|
94
|
+
pnpm --filter @vvedantb/ui analyze # rule-level duplication across the app clones -> verify/ANALYSIS.tables.md
|
|
95
|
+
pnpm --filter @vvedantb/ui verify # before/after compile of every app -> verify/RESULTS.md, examples/migration.md
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
`analyze` and `verify` need the app clones (`APPS_DIR`, default `/workspace/cvx`; name or symlink the clones `app-a` to `app-e` inside it) and network access the first time: they install Tailwind 4.3.3, the plugins, postcss and jiti into a scratch directory (`VERIFY_DIR`, default `/workspace/pk-tokens-verify`, outside the repo). The migration for each app is data in `verify/migrations/<app>.json`. Each removed block must equal the shared file's block with the same context and selector, or the run fails.
|