@vvedantb/ui 0.5.1 → 0.5.3
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 +34 -5
- package/package.json +1 -1
- package/shell/src/AppSidebar.tsx +11 -2
- package/shell/src/SidebarAccountMenu.tsx +40 -2
- package/shell/src/SidebarRail.tsx +4 -6
- package/src/ui/confirm-dialog.tsx +41 -2
package/README.md
CHANGED
|
@@ -208,11 +208,13 @@ import { ConfirmDialog, SlideOverPanel, ToolbarSearchInput } from "@vvedantb/ui"
|
|
|
208
208
|
<ToolbarSearchInput value={query} onChange={setQuery} />
|
|
209
209
|
|
|
210
210
|
<ConfirmDialog size="sm" open={open} onOpenChange={setOpen} title="Delete item?" variant="destructive" onConfirm={remove} />
|
|
211
|
+
|
|
212
|
+
<ConfirmDialog size="md" open={open} onOpenChange={setOpen} title="Delete item?" description="This cannot be undone." confirmLabel="Delete" variant="destructive" onConfirm={remove} />
|
|
211
213
|
```
|
|
212
214
|
|
|
213
215
|
- `SlideOverPanel`: a right-side panel, absolutely positioned inside its nearest positioned parent. It is not a portal or dialog. It slides in with a spring and is hidden below `md`. Only the close button closes it (no Escape, no outside click). `width` is `"w-96"` (default) or `"w-80"`. `closeLabel` defaults to `"Close panel"`. `className` merges last.
|
|
214
216
|
- `ToolbarSearchInput`: a compact `h-8` search field for toolbars, with a search icon and a clear button. The clear button stays mounted and is hidden while the value is blank. Clearing calls `onChange("")` and does not move focus. Defaults: `placeholder="Search..."`, `label="Search"` (the `aria-label`), `clearLabel="Clear search"`. The ref goes to the `<input>`.
|
|
215
|
-
- `ConfirmDialog` `size`: `"default"` keeps the alert dialog. `"sm"` renders a compact, dismissible dialog (outside click, Escape and the close button close it) with small Cancel and confirm buttons. Cancel calls `onCancel` and then `onOpenChange(false)`. Confirm calls `onConfirm` only, so the caller closes it.
|
|
217
|
+
- `ConfirmDialog` `size`: `"default"` keeps the alert dialog. `"sm"` renders a compact, dismissible dialog (outside click, Escape and the close button close it) with small Cancel and confirm buttons. Cancel calls `onCancel` and then `onOpenChange(false)`. Confirm calls `onConfirm` only, so the caller closes it. `"md"` (0.5.2) is dismissible like `"sm"`, with the title in a header (`pb-4`), the description in its own section (`py-6`) and a footer (`pt-4`) with default-size buttons. It has the same Cancel and confirm behaviour as `"sm"`.
|
|
216
218
|
|
|
217
219
|
## Buttons, menus and fields (0.4.4)
|
|
218
220
|
|
|
@@ -248,7 +250,7 @@ import {
|
|
|
248
250
|
- `SelectField`: a labelled single select built from `Select`. Children are `SelectItem`s. An empty `value` shows the placeholder. `id` goes to the trigger and the label points at it. `className` merges onto the trigger.
|
|
249
251
|
- Motion: `springTransition`, `springFastTransition` and `fadeUpSpring` presets. `FadePresence` takes optional `variants` (`hidden`, `show`, `exit`); omitted, it keeps its opacity fade. `PanelTransition` wraps children in React `ViewTransition` with `default="none"` and `enter`/`exit` classes (`vt-panel-in`, `vt-panel-out` by default). It needs a React build that exports `ViewTransition`, and the app supplies the `::view-transition-*` CSS.
|
|
250
252
|
|
|
251
|
-
## App shell (0.5.0
|
|
253
|
+
## App shell (0.5.0 to 0.5.3)
|
|
252
254
|
|
|
253
255
|
A sidebar and main page layout, extracted from existing app markup. It is router-free: pass your own links (with `asChild`), state and media query result. Tooltips need a `TooltipProvider` above the shell.
|
|
254
256
|
|
|
@@ -289,15 +291,42 @@ import {
|
|
|
289
291
|
|
|
290
292
|
- Widths: `AppShell` sets `--app-shell-rail-width` (default `4rem`), `--app-shell-sidebar-width` (rail plus panel, default `20rem`) and `--app-shell-mobile-header-height` (default `calc(3.5rem + env(safe-area-inset-top, 0px))`) as inline style. Change them with `railWidth`, `sidebarWidth` and `mobileHeaderHeight`. The other pieces read these variables. Outside `AppShell`, set the variables yourself or pass a width class with `className`.
|
|
291
293
|
- `AppShell`: `sidebar`, `children`, `panelHidden` (main offsets by the rail width instead of the sidebar width), `skipLinkLabel` (`"Skip to main content"`), `mainId` (`"main-content"`), `className`, `mainClassName`, `contentClassName`.
|
|
292
|
-
- `AppSidebar`: `rail`, `panel` (not rendered while `panelHidden`), `collapsed`, `panelHidden`, `isDesktop`, `mobileOpen`, `onMobileOpenChange`, `id` (default from `useId`), `asideProps` (`data-*` attributes for the `<aside>`), `className`, `mobileTitle`, `mobileMenuIcon` (`(open) => node`, default a menu icon), `mobileMenuLabel` (`"Open navigation menu"`), `closeLabel` (`"Close navigation"`). Swipe left or Escape closes the drawer. The drawer is `inert` while closed on mobile, and closes when `isDesktop` becomes `true`. Close it on route change in the app.
|
|
294
|
+
- `AppSidebar`: `rail`, `panel` (not rendered while `panelHidden`), `collapsed`, `panelHidden`, `isDesktop`, `mobileOpen`, `onMobileOpenChange`, `id` (default from `useId`), `asideProps` (`data-*` attributes for the `<aside>`), `className`, `mobileTitle`, `mobileHeaderActions` (0.5.2; trailing actions such as icon buttons, in place of the end spacer), `mobileMenuIcon` (`(open) => node`, default a menu icon), `mobileMenuLabel` (`"Open navigation menu"`), `closeLabel` (`"Close navigation"`). Swipe left or Escape closes the drawer. The drawer is `inert` while closed on mobile, and closes when `isDesktop` becomes `true`. Close it on route change in the app.
|
|
293
295
|
- `SidebarRail`: `top`, `children` (scroll body), `footer`, `showDivider`, `bodyAsChild` (the single child, for example a tabs list, becomes the body), `className`, `topClassName`, `bodyClassName`, `footerClassName`. Other HTML attributes (`id`, `data-*`, `aria-*`) go to the root `<div>`. The top and footer wrappers render only when their slot is set.
|
|
294
|
-
- `RailTile`: `label` (`aria-label` and tooltip), `active`, `tooltip`, `showTooltip` (default `true`), `badge` (inside the tile, after the children; style it with `railBadgeClass`), `asChild`, `className`. Without `asChild` it is a
|
|
296
|
+
- `RailTile`: `label` (`aria-label` and tooltip), `active`, `tooltip`, `showTooltip` (default `true`), `badge` (inside the tile, after the children; style it with `railBadgeClass`), `asChild`, `className`. Without `asChild` it is a native `<button type="button">` (0.5.3), so icons keep their authored size; other props go to it. With `asChild` the child (for example a router link) gets the tile classes and `aria-current="page"` when active.
|
|
295
297
|
- `RailDivider`, `SidebarIconTooltip` (`label`, `enabled`, `side` `"right"`, `sideOffset` 8).
|
|
296
298
|
- `SidebarPanel`: `title`, `headerTrailing`, `onClose` (adds the close button; pass it on the mobile drawer only), `closeLabel`, `closeButtonClassName`, `collapsed` (`md:hidden`), `className`, `children`.
|
|
297
|
-
- `SidebarAccountMenu`: `name`, `email` (two-line label when set), `stackedLabel` (two-line layout even without `email`, default `false`), `imageUrl` (initials without it), `align` (`"center"`), `side` (`"right"`), `sideOffset` (8), `collisionPadding`, `contentClassName`, `children` (menu items). `SidebarAccountMenuPlaceholder` is the tile-sized loading box.
|
|
299
|
+
- `SidebarAccountMenu`: `name`, `email` (two-line label when set), `stackedLabel` (two-line layout even without `email`, default `false`), `imageUrl` (initials without it), `align` (`"center"`), `side` (`"right"`), `sideOffset` (8), `collisionPadding`, `contentClassName`, `children` (menu items). 0.5.2 adds `badge` (unread dot beside the trigger, in a `relative` wrapper around the menu, so the trigger's dimming and press scale skip it: `true` shows it, `false` fades it out, omitted renders no wrapper and no dot), `triggerProps` (spread onto the trigger `Button` after the defaults; `className` merges last) and `contentProps` (spread onto `DropdownMenuContent`, for example `fitViewport` or `aria-label`; no `className`, use `contentClassName`). `SidebarAccountMenuPlaceholder` is the tile-sized loading box.
|
|
298
300
|
- `SignOutDialog`: `open`, `onOpenChange` (not called with `false` while `pending`), `pending`, `onConfirm`, `description`, `contentClassName`, `title` (`"Sign out"`), `question` (`"Sign out of your account?"`).
|
|
299
301
|
- Class helpers: `railTileClass`, `railTileStateClass(active)`, `railBadgeClass`, `sidebarNavRowClass(isIconOnly)`, `sidebarNavLinkTextClass(isActive)`, `sidebarSectionLabelClass`.
|
|
300
302
|
|
|
303
|
+
### Header actions and account badge (0.5.2)
|
|
304
|
+
|
|
305
|
+
All opt-in. Without these props the header keeps its end spacer and the account trigger has no dot.
|
|
306
|
+
|
|
307
|
+
```tsx
|
|
308
|
+
<AppSidebar
|
|
309
|
+
/* … */
|
|
310
|
+
mobileHeaderActions={
|
|
311
|
+
<>
|
|
312
|
+
<Button size="icon" variant="ghost" aria-label="Search"><IconSearch size={20} /></Button>
|
|
313
|
+
<Button size="icon" variant="ghost" aria-label="New item"><IconPlus size={20} /></Button>
|
|
314
|
+
</>
|
|
315
|
+
}
|
|
316
|
+
/>
|
|
317
|
+
|
|
318
|
+
<SidebarAccountMenu
|
|
319
|
+
name={name}
|
|
320
|
+
badge={hasUnread}
|
|
321
|
+
triggerProps={{ "aria-label": hasUnread ? `Account menu for ${name}, unread updates` : `Account menu for ${name}` }}
|
|
322
|
+
contentProps={{ fitViewport: true, "aria-label": "Account" }}
|
|
323
|
+
>
|
|
324
|
+
<DropdownMenuItem>Settings</DropdownMenuItem>
|
|
325
|
+
</SidebarAccountMenu>
|
|
326
|
+
```
|
|
327
|
+
|
|
328
|
+
The dot is `aria-hidden`, so say it in the trigger label when it matters, as above.
|
|
329
|
+
|
|
301
330
|
### Resizable panel (0.5.1)
|
|
302
331
|
|
|
303
332
|
Pass `resizable` to `AppShell`. Widths are panel px, rail excluded. Without it nothing changes.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vvedantb/ui",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.3",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"description": "Shared React 19 UI for web apps: one JavaScript entry (primitives, shell pieces, app helpers, native tokens), design-token CSS, shared Tailwind v4 CSS and a Tailwind preset.",
|
|
6
6
|
"type": "module",
|
package/shell/src/AppSidebar.tsx
CHANGED
|
@@ -29,6 +29,8 @@ export type AppSidebarProps = {
|
|
|
29
29
|
className?: string;
|
|
30
30
|
/** Centred in the mobile header when truthy. */
|
|
31
31
|
mobileTitle?: ReactNode;
|
|
32
|
+
/** Trailing actions in the mobile header, for example icon buttons. Replaces the end spacer. */
|
|
33
|
+
mobileHeaderActions?: ReactNode;
|
|
32
34
|
/** Menu button icon. Default a 20px menu icon. */
|
|
33
35
|
mobileMenuIcon?: (open: boolean) => ReactNode;
|
|
34
36
|
/** Default `"Open navigation menu"`. */
|
|
@@ -57,6 +59,7 @@ export function AppSidebar({
|
|
|
57
59
|
asideProps,
|
|
58
60
|
className,
|
|
59
61
|
mobileTitle,
|
|
62
|
+
mobileHeaderActions,
|
|
60
63
|
mobileMenuIcon = defaultMobileMenuIcon,
|
|
61
64
|
mobileMenuLabel = "Open navigation menu",
|
|
62
65
|
closeLabel = "Close navigation",
|
|
@@ -95,7 +98,7 @@ export function AppSidebar({
|
|
|
95
98
|
<>
|
|
96
99
|
<header
|
|
97
100
|
onKeyDown={closeOnEscape}
|
|
98
|
-
className="fixed inset-x-0 top-0 z-30 flex h-[var(--app-shell-mobile-header-height)] items-center gap-2 bg-
|
|
101
|
+
className="fixed inset-x-0 top-0 z-30 flex h-[var(--app-shell-mobile-header-height)] items-center gap-2 bg-surface px-3 pt-[env(safe-area-inset-top,0px)] pl-[max(0.75rem,env(safe-area-inset-left))] pr-[max(0.75rem,env(safe-area-inset-right))] md:hidden"
|
|
99
102
|
>
|
|
100
103
|
<Button
|
|
101
104
|
type="button"
|
|
@@ -114,7 +117,13 @@ export function AppSidebar({
|
|
|
114
117
|
{mobileTitle}
|
|
115
118
|
</h1>
|
|
116
119
|
) : null}
|
|
117
|
-
|
|
120
|
+
{mobileHeaderActions ? (
|
|
121
|
+
<div data-app-sidebar-mobile-actions="" className="ml-auto flex shrink-0 items-center gap-2">
|
|
122
|
+
{mobileHeaderActions}
|
|
123
|
+
</div>
|
|
124
|
+
) : (
|
|
125
|
+
<div className="ml-auto h-11 w-11 shrink-0" aria-hidden="true" />
|
|
126
|
+
)}
|
|
118
127
|
</header>
|
|
119
128
|
|
|
120
129
|
<AnimatePresence initial={false}>
|
|
@@ -30,6 +30,19 @@ export type SidebarAccountMenuProps = {
|
|
|
30
30
|
collisionPadding?: ContentProps["collisionPadding"];
|
|
31
31
|
/** Merged onto the menu content after `w-56`. */
|
|
32
32
|
contentClassName?: string;
|
|
33
|
+
/**
|
|
34
|
+
* Unread dot over the trigger's top-right corner, a sibling of the trigger in
|
|
35
|
+
* a `relative` wrapper. `true` shows it, `false` keeps it mounted at zero
|
|
36
|
+
* opacity so it fades out. Omitted: no wrapper and no dot.
|
|
37
|
+
*/
|
|
38
|
+
badge?: boolean;
|
|
39
|
+
/** Spread onto the trigger `Button` after the defaults (overrides `title`, `aria-label`, …). `className` merges last. */
|
|
40
|
+
triggerProps?: Omit<ComponentPropsWithoutRef<typeof Button>, "children" | "asChild">;
|
|
41
|
+
/** Spread onto `DropdownMenuContent`, for example `fitViewport` or `aria-label`. Use `contentClassName` for classes. */
|
|
42
|
+
contentProps?: Omit<
|
|
43
|
+
ContentProps,
|
|
44
|
+
"children" | "className" | "align" | "side" | "sideOffset" | "collisionPadding"
|
|
45
|
+
>;
|
|
33
46
|
/** Menu items after the label and separator. */
|
|
34
47
|
children?: ReactNode;
|
|
35
48
|
};
|
|
@@ -73,9 +86,12 @@ export function SidebarAccountMenu({
|
|
|
73
86
|
sideOffset = 8,
|
|
74
87
|
collisionPadding,
|
|
75
88
|
contentClassName,
|
|
89
|
+
badge,
|
|
90
|
+
triggerProps,
|
|
91
|
+
contentProps,
|
|
76
92
|
children,
|
|
77
93
|
}: SidebarAccountMenuProps) {
|
|
78
|
-
|
|
94
|
+
const menu = (
|
|
79
95
|
<DropdownMenu>
|
|
80
96
|
<DropdownMenuTrigger asChild>
|
|
81
97
|
<Button
|
|
@@ -83,12 +99,19 @@ export function SidebarAccountMenu({
|
|
|
83
99
|
variant="ghost"
|
|
84
100
|
title={name}
|
|
85
101
|
aria-label={`Account menu for ${name}`}
|
|
86
|
-
|
|
102
|
+
{...triggerProps}
|
|
103
|
+
className={cn(
|
|
104
|
+
railTileClass,
|
|
105
|
+
"h-11 w-11 p-0",
|
|
106
|
+
railTileStateClass(false),
|
|
107
|
+
triggerProps?.className,
|
|
108
|
+
)}
|
|
87
109
|
>
|
|
88
110
|
<AccountAvatar src={imageUrl} name={name} className="h-7 w-7" />
|
|
89
111
|
</Button>
|
|
90
112
|
</DropdownMenuTrigger>
|
|
91
113
|
<DropdownMenuContent
|
|
114
|
+
{...contentProps}
|
|
92
115
|
align={align}
|
|
93
116
|
side={side}
|
|
94
117
|
sideOffset={sideOffset}
|
|
@@ -111,6 +134,21 @@ export function SidebarAccountMenu({
|
|
|
111
134
|
</DropdownMenuContent>
|
|
112
135
|
</DropdownMenu>
|
|
113
136
|
);
|
|
137
|
+
if (badge === undefined) return menu;
|
|
138
|
+
// Sibling of the trigger, so its opacity and press scale do not reach the dot.
|
|
139
|
+
return (
|
|
140
|
+
<div className="relative">
|
|
141
|
+
{menu}
|
|
142
|
+
<span
|
|
143
|
+
aria-hidden="true"
|
|
144
|
+
data-account-badge=""
|
|
145
|
+
className={cn(
|
|
146
|
+
"pointer-events-none absolute right-0 top-0 h-2.5 w-2.5 rounded-full border-2 border-background bg-danger transition-opacity duration-150 ease-out",
|
|
147
|
+
badge ? "opacity-100" : "opacity-0",
|
|
148
|
+
)}
|
|
149
|
+
/>
|
|
150
|
+
</div>
|
|
151
|
+
);
|
|
114
152
|
}
|
|
115
153
|
|
|
116
154
|
export type SidebarAccountMenuPlaceholderProps = { className?: string };
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import type { ComponentPropsWithoutRef, ReactNode } from "react";
|
|
2
2
|
import { Slot, Slottable } from "@radix-ui/react-slot";
|
|
3
3
|
import * as TabsPrimitive from "@radix-ui/react-tabs";
|
|
4
|
-
import { Button } from "../../src/ui/button";
|
|
5
4
|
import { cn } from "../../src/utils/cn";
|
|
6
5
|
import { railTileClass, railTileStateClass } from "./app-shell-classes";
|
|
7
6
|
import { SidebarIconTooltip } from "./SidebarIconTooltip";
|
|
@@ -99,7 +98,7 @@ export type RailTileProps = Omit<ComponentPropsWithoutRef<"button">, "children">
|
|
|
99
98
|
children: ReactNode;
|
|
100
99
|
};
|
|
101
100
|
|
|
102
|
-
/** Rail tile with a right-side tooltip. Renders a
|
|
101
|
+
/** Rail tile with a right-side tooltip. Renders a native `<button>`, its child with `asChild`, or a tabs trigger with `tabValue`. */
|
|
103
102
|
export function RailTile({
|
|
104
103
|
label,
|
|
105
104
|
active = false,
|
|
@@ -135,16 +134,15 @@ export function RailTile({
|
|
|
135
134
|
{badge}
|
|
136
135
|
</Slot>
|
|
137
136
|
) : (
|
|
138
|
-
<
|
|
137
|
+
<button
|
|
139
138
|
type="button"
|
|
140
|
-
variant="ghost"
|
|
141
139
|
{...props}
|
|
142
140
|
aria-label={label}
|
|
143
|
-
className={cn(railTileClass, "group
|
|
141
|
+
className={cn(railTileClass, "group", railTileStateClass(active), className)}
|
|
144
142
|
>
|
|
145
143
|
{children}
|
|
146
144
|
{badge}
|
|
147
|
-
</
|
|
145
|
+
</button>
|
|
148
146
|
)}
|
|
149
147
|
</SidebarIconTooltip>
|
|
150
148
|
);
|
|
@@ -10,7 +10,14 @@ import {
|
|
|
10
10
|
AlertDialogTitle,
|
|
11
11
|
} from "./alert-dialog";
|
|
12
12
|
import { Button } from "./button";
|
|
13
|
-
import {
|
|
13
|
+
import {
|
|
14
|
+
Dialog,
|
|
15
|
+
DialogContent,
|
|
16
|
+
DialogDescription,
|
|
17
|
+
DialogFooter,
|
|
18
|
+
DialogHeader,
|
|
19
|
+
DialogTitle,
|
|
20
|
+
} from "./dialog";
|
|
14
21
|
|
|
15
22
|
export type ConfirmDialogProps = React.ComponentProps<typeof AlertDialog> & {
|
|
16
23
|
title: React.ReactNode;
|
|
@@ -25,8 +32,10 @@ export type ConfirmDialogProps = React.ComponentProps<typeof AlertDialog> & {
|
|
|
25
32
|
* `"default"`: blocking alert dialog that closes on either button.
|
|
26
33
|
* `"sm"`: compact dismissible dialog (outside click, Escape and the close
|
|
27
34
|
* button close it). Confirm does not close it; the caller controls `open`.
|
|
35
|
+
* `"md"`: dismissible dialog like `"sm"`, with a header, description and
|
|
36
|
+
* footer in separate sections and default-size buttons.
|
|
28
37
|
*/
|
|
29
|
-
size?: "default" | "sm";
|
|
38
|
+
size?: "default" | "sm" | "md";
|
|
30
39
|
};
|
|
31
40
|
|
|
32
41
|
function ConfirmDialog({
|
|
@@ -78,6 +87,36 @@ function ConfirmDialog({
|
|
|
78
87
|
);
|
|
79
88
|
}
|
|
80
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
|
+
|
|
81
120
|
return (
|
|
82
121
|
<AlertDialog {...props}>
|
|
83
122
|
{children}
|