@vvedantb/ui 0.5.4 → 0.6.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +184 -5
- package/app/README.md +100 -0
- package/package.json +11 -10
- package/shell/src/AppShell.tsx +130 -43
- package/shell/src/AppSidebar.tsx +27 -125
- package/shell/src/Sidebar.tsx +78 -0
- package/shell/src/SidebarAccountMenu.tsx +169 -77
- package/shell/src/SidebarChrome.tsx +295 -0
- package/shell/src/SidebarHeader.tsx +6 -7
- package/shell/src/SidebarPanel.tsx +95 -33
- package/shell/src/SidebarRail.tsx +74 -28
- package/shell/src/SignOutDialog.tsx +24 -51
- package/shell/src/app-shell-classes.ts +6 -0
- package/shell/src/index.ts +9 -1
- package/src/index.ts +9 -1
- package/src/ui/confirm-dialog-parts.tsx +355 -0
- package/src/ui/confirm-dialog.tsx +65 -106
- package/src/ui/overlay-a11y.ts +5 -3
- package/tokens/README.md +98 -0
|
@@ -1,34 +1,39 @@
|
|
|
1
1
|
import * as React from "react";
|
|
2
|
-
import {
|
|
3
|
-
AlertDialog,
|
|
4
|
-
AlertDialogAction,
|
|
5
|
-
AlertDialogCancel,
|
|
6
|
-
AlertDialogContent,
|
|
7
|
-
AlertDialogDescription,
|
|
8
|
-
AlertDialogFooter,
|
|
9
|
-
AlertDialogHeader,
|
|
10
|
-
AlertDialogTitle,
|
|
11
|
-
} from "./alert-dialog";
|
|
12
|
-
import { Button } from "./button";
|
|
13
|
-
import {
|
|
14
|
-
Dialog,
|
|
15
|
-
DialogContent,
|
|
16
|
-
DialogDescription,
|
|
17
|
-
DialogFooter,
|
|
18
|
-
DialogHeader,
|
|
19
|
-
DialogTitle,
|
|
20
|
-
} from "./dialog";
|
|
2
|
+
import { ConfirmDialogParts as Parts, type ConfirmDialogRootProps } from "./confirm-dialog-parts";
|
|
21
3
|
|
|
22
|
-
export
|
|
4
|
+
export { useConfirmDialog } from "./confirm-dialog-parts";
|
|
5
|
+
export type {
|
|
6
|
+
ConfirmDialogActionProps,
|
|
7
|
+
ConfirmDialogBodyProps,
|
|
8
|
+
ConfirmDialogCancelProps,
|
|
9
|
+
ConfirmDialogContentProps,
|
|
10
|
+
ConfirmDialogDescriptionProps,
|
|
11
|
+
ConfirmDialogFieldProps,
|
|
12
|
+
ConfirmDialogFooterProps,
|
|
13
|
+
ConfirmDialogHeaderProps,
|
|
14
|
+
ConfirmDialogRootProps,
|
|
15
|
+
ConfirmDialogSize,
|
|
16
|
+
ConfirmDialogTitleProps,
|
|
17
|
+
} from "./confirm-dialog-parts";
|
|
18
|
+
|
|
19
|
+
export type ConfirmDialogProps = Omit<
|
|
20
|
+
ConfirmDialogRootProps,
|
|
21
|
+
"size" | "alert" | "pending" | "confirmPhrase"
|
|
22
|
+
> & {
|
|
23
23
|
title: React.ReactNode;
|
|
24
24
|
description?: React.ReactNode;
|
|
25
|
+
/** Legacy (still supported): compose `ConfirmDialog.Cancel` instead. */
|
|
25
26
|
cancelLabel?: React.ReactNode;
|
|
27
|
+
/** Legacy (still supported): compose `ConfirmDialog.Action` instead. */
|
|
26
28
|
confirmLabel?: React.ReactNode;
|
|
27
29
|
onCancel?: () => void;
|
|
28
30
|
onConfirm?: () => void;
|
|
31
|
+
/** Legacy (still supported): pass `variant` to `ConfirmDialog.Action` instead. */
|
|
29
32
|
variant?: "default" | "destructive";
|
|
30
33
|
confirmDisabled?: boolean;
|
|
31
34
|
/**
|
|
35
|
+
* Legacy (still supported): use `ConfirmDialog.Root size` with the parts.
|
|
36
|
+
*
|
|
32
37
|
* `"default"`: blocking alert dialog that closes on either button.
|
|
33
38
|
* `"sm"`: compact dismissible dialog (outside click, Escape and the close
|
|
34
39
|
* button close it). Confirm does not close it; the caller controls `open`.
|
|
@@ -38,7 +43,7 @@ export type ConfirmDialogProps = React.ComponentProps<typeof AlertDialog> & {
|
|
|
38
43
|
size?: "default" | "sm" | "md";
|
|
39
44
|
};
|
|
40
45
|
|
|
41
|
-
function
|
|
46
|
+
function LegacyConfirmDialog({
|
|
42
47
|
title,
|
|
43
48
|
description,
|
|
44
49
|
cancelLabel = "Cancel",
|
|
@@ -51,95 +56,49 @@ function ConfirmDialog({
|
|
|
51
56
|
children,
|
|
52
57
|
...props
|
|
53
58
|
}: ConfirmDialogProps) {
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
{children}
|
|
58
|
-
<DialogContent className="sm:max-w-96">
|
|
59
|
-
<DialogTitle className="mb-2 text-sm font-medium">{title}</DialogTitle>
|
|
60
|
-
{description != null ? (
|
|
61
|
-
<DialogDescription className="mb-4 text-sm text-muted-foreground">
|
|
62
|
-
{description}
|
|
63
|
-
</DialogDescription>
|
|
64
|
-
) : null}
|
|
65
|
-
<div className="flex justify-end gap-2">
|
|
66
|
-
<Button
|
|
67
|
-
variant="ghost"
|
|
68
|
-
size="sm"
|
|
69
|
-
onClick={() => {
|
|
70
|
-
onCancel?.();
|
|
71
|
-
props.onOpenChange?.(false);
|
|
72
|
-
}}
|
|
73
|
-
>
|
|
74
|
-
{cancelLabel}
|
|
75
|
-
</Button>
|
|
76
|
-
<Button
|
|
77
|
-
variant={variant}
|
|
78
|
-
size="sm"
|
|
79
|
-
disabled={confirmDisabled}
|
|
80
|
-
onClick={onConfirm}
|
|
81
|
-
>
|
|
82
|
-
{confirmLabel}
|
|
83
|
-
</Button>
|
|
84
|
-
</div>
|
|
85
|
-
</DialogContent>
|
|
86
|
-
</Dialog>
|
|
87
|
-
);
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
if (size === "md") {
|
|
91
|
-
return (
|
|
92
|
-
<Dialog {...props}>
|
|
93
|
-
{children}
|
|
94
|
-
<DialogContent className="sm:max-w-96">
|
|
95
|
-
<DialogHeader className="pb-4">
|
|
96
|
-
<DialogTitle>{title}</DialogTitle>
|
|
97
|
-
</DialogHeader>
|
|
98
|
-
{description != null ? (
|
|
99
|
-
<DialogDescription className="py-6 text-muted-foreground">{description}</DialogDescription>
|
|
100
|
-
) : null}
|
|
101
|
-
<DialogFooter className="pt-4">
|
|
102
|
-
<Button
|
|
103
|
-
variant="ghost"
|
|
104
|
-
onClick={() => {
|
|
105
|
-
onCancel?.();
|
|
106
|
-
props.onOpenChange?.(false);
|
|
107
|
-
}}
|
|
108
|
-
>
|
|
109
|
-
{cancelLabel}
|
|
110
|
-
</Button>
|
|
111
|
-
<Button variant={variant} disabled={confirmDisabled} onClick={onConfirm}>
|
|
112
|
-
{confirmLabel}
|
|
113
|
-
</Button>
|
|
114
|
-
</DialogFooter>
|
|
115
|
-
</DialogContent>
|
|
116
|
-
</Dialog>
|
|
117
|
-
);
|
|
118
|
-
}
|
|
119
|
-
|
|
59
|
+
const titleNode = <Parts.Title>{title}</Parts.Title>;
|
|
60
|
+
const descriptionNode =
|
|
61
|
+
description != null ? <Parts.Description>{description}</Parts.Description> : null;
|
|
120
62
|
return (
|
|
121
|
-
<
|
|
63
|
+
<Parts.Root {...props} size={size}>
|
|
122
64
|
{children}
|
|
123
|
-
<
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
65
|
+
<Parts.Content>
|
|
66
|
+
{size === "sm" ? (
|
|
67
|
+
<>
|
|
68
|
+
{titleNode}
|
|
69
|
+
{descriptionNode}
|
|
70
|
+
</>
|
|
71
|
+
) : size === "md" ? (
|
|
72
|
+
<>
|
|
73
|
+
<Parts.Header>{titleNode}</Parts.Header>
|
|
74
|
+
{descriptionNode}
|
|
75
|
+
</>
|
|
76
|
+
) : (
|
|
77
|
+
<Parts.Header>
|
|
78
|
+
{titleNode}
|
|
79
|
+
{descriptionNode}
|
|
80
|
+
</Parts.Header>
|
|
81
|
+
)}
|
|
82
|
+
<Parts.Footer>
|
|
83
|
+
{/* The alert cancel passes the click event on; sm and md call onCancel bare. */}
|
|
84
|
+
<Parts.Cancel onClick={size === "default" ? onCancel : () => onCancel?.()}>
|
|
85
|
+
{cancelLabel}
|
|
86
|
+
</Parts.Cancel>
|
|
87
|
+
<Parts.Action variant={variant} disabled={confirmDisabled} onClick={onConfirm}>
|
|
137
88
|
{confirmLabel}
|
|
138
|
-
</
|
|
139
|
-
</
|
|
140
|
-
</
|
|
141
|
-
</
|
|
89
|
+
</Parts.Action>
|
|
90
|
+
</Parts.Footer>
|
|
91
|
+
</Parts.Content>
|
|
92
|
+
</Parts.Root>
|
|
142
93
|
);
|
|
143
94
|
}
|
|
95
|
+
LegacyConfirmDialog.displayName = "ConfirmDialog";
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* Confirm dialog. Call it with props (the legacy prop-driven API), or compose
|
|
99
|
+
* the parts: `ConfirmDialog.Root`, `.Content`, `.Header`, `.Title`,
|
|
100
|
+
* `.Description`, `.Body`, `.Footer`, `.Cancel`, `.Action` and `.Field`.
|
|
101
|
+
*/
|
|
102
|
+
const ConfirmDialog = Object.assign(LegacyConfirmDialog, Parts);
|
|
144
103
|
|
|
145
104
|
export { ConfirmDialog };
|
package/src/ui/overlay-a11y.ts
CHANGED
|
@@ -143,11 +143,13 @@ export function treeHasDialogDescription(
|
|
|
143
143
|
if (!React.isValidElement(child)) return false;
|
|
144
144
|
const type = child.type;
|
|
145
145
|
if (type === descriptionType) return true;
|
|
146
|
+
// Wrappers named like `ConfirmDialog.Description` count too.
|
|
146
147
|
const displayName =
|
|
147
|
-
typeof type === "object" && type !== null
|
|
148
|
-
|
|
148
|
+
(typeof type === "function" || (typeof type === "object" && type !== null)) &&
|
|
149
|
+
"displayName" in type
|
|
150
|
+
? type.displayName
|
|
149
151
|
: undefined;
|
|
150
|
-
if (displayName === "
|
|
152
|
+
if (typeof displayName === "string" && /Dialog\.?Description$/.test(displayName)) return true;
|
|
151
153
|
const props = child.props as { children?: React.ReactNode };
|
|
152
154
|
return treeHasDialogDescription(props.children, descriptionType);
|
|
153
155
|
});
|
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, `*` border and `body` defaults. 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`, `@utility reveal-on-hover` and `@utility rounded-surface` (`clamp(0.75rem, var(--radius), 1rem)`). |
|
|
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` 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.
|