@vvedantb/ui 0.5.0 → 0.5.2

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 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.2)
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,95 @@ 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
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 ghost `Button`; 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
+
330
+ ### Resizable panel (0.5.1)
331
+
332
+ Pass `resizable` to `AppShell`. Widths are panel px, rail excluded. Without it nothing changes.
333
+
334
+ ```tsx
335
+ <AppShell
336
+ resizable={{ storageKey: "sidebar-width", defaultWidth: 256, minWidth: 200, maxWidth: 480 }}
337
+ sidebar={<AppSidebar /* as above */ />}
338
+ >
339
+ {page}
340
+ </AppShell>
341
+ ```
342
+
343
+ - `resizable`: `storageKey`, `defaultWidth`, `minWidth`, `maxWidth`, `label` (default `"Resize sidebar"`). The shell reads the stored width (a JSON number in `localStorage`) on mount, ignores invalid values, clamps it to the bounds and writes each change. Server and hydration renders use `defaultWidth`. `--app-shell-sidebar-width` becomes `calc(<railWidth> + <width>px)` and `sidebarWidth` is ignored. While resizing, the main margin and `<aside>` width transitions are off.
344
+ - `AppSidebar` adds the handle to the `<aside>` right edge on desktop while the panel shows (not `collapsed`, not `panelHidden`). The mobile drawer has none.
345
+ - `SidebarResizeHandle` (`className`): the handle, for custom layouts. Place it in a positioned parent. Dragging past the bounds rubber-bands and springs back on release. ArrowLeft and ArrowRight step 16px. Double-click resets to `defaultWidth`. It renders nothing outside a resizable `AppShell`.
346
+ - `useAppShellResize()`: `{ width, setWidth, isResizing, minWidth, maxWidth, defaultWidth }`, or `null` outside a resizable `AppShell`. `setWidth` takes a number or an updater.
347
+
348
+ ```tsx
349
+ function PanelWidth() {
350
+ const resize = useAppShellResize();
351
+ return resize ? <span>{Math.round(resize.width)}px</span> : null;
352
+ }
353
+ ```
354
+
355
+ ### Rail tabs (0.5.1)
356
+
357
+ `SidebarRail tabs` renders the body as a Radix tabs list (arrow-key roving focus, same classes). Wrap the sidebar in a Tabs root with `orientation="vertical"` (the package `Tabs` works). `RailTile tabValue` renders a tabs trigger: tile classes, the children, the label as sr-only text instead of `aria-label`, then the badge. `active` drives the state classes and other props (for example `aria-expanded`) go to the trigger. `asChild` is ignored with `tabValue`. Without `tabs` and `tabValue` the rail renders as before.
358
+
359
+ ```tsx
360
+ <Tabs value={tab} onValueChange={setTab} orientation="vertical">
361
+ <AppSidebar
362
+ /* … */
363
+ rail={
364
+ <SidebarRail tabs>
365
+ <RailTile tabValue="files" label="Files" active={tab === "files"} aria-expanded={tab === "files" ? !collapsed : undefined}>
366
+ <IconFiles size={22} />
367
+ </RailTile>
368
+ <RailTile tabValue="search" label="Search" active={tab === "search"}>
369
+ <IconSearch size={22} />
370
+ </RailTile>
371
+ </SidebarRail>
372
+ }
373
+ panel={
374
+ <>
375
+ <TabsContent value="files">{files}</TabsContent>
376
+ <TabsContent value="search">{search}</TabsContent>
377
+ </>
378
+ }
379
+ />
380
+ </Tabs>
381
+ ```
382
+
301
383
  ## Toaster
302
384
 
303
385
  ```tsx
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vvedantb/ui",
3
- "version": "0.5.0",
3
+ "version": "0.5.2",
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",
@@ -1,5 +1,10 @@
1
1
  import type { CSSProperties, ReactNode } from "react";
2
2
  import { cn } from "../../src/utils/cn";
3
+ import {
4
+ SidebarResizeProvider,
5
+ useSidebarResizeState,
6
+ type SidebarResizeOptions,
7
+ } from "./SidebarResize";
3
8
 
4
9
  export type AppShellProps = {
5
10
  /** Rendered between the skip link and `<main>`, usually an `AppSidebar`. */
@@ -13,8 +18,14 @@ export type AppShellProps = {
13
18
  panelHidden?: boolean;
14
19
  /** Sets `--app-shell-rail-width`. Default `"4rem"`. */
15
20
  railWidth?: string;
16
- /** Sets `--app-shell-sidebar-width` (rail plus panel). Default `"20rem"`. */
21
+ /** Sets `--app-shell-sidebar-width` (rail plus panel). Default `"20rem"`. Ignored with `resizable`. */
17
22
  sidebarWidth?: string;
23
+ /**
24
+ * Opt-in resizable panel. The shell owns the persisted panel width, sets
25
+ * `--app-shell-sidebar-width` to `calc(<railWidth> + <width>px)` and shares
26
+ * the state with `AppSidebar`, `SidebarResizeHandle` and `useAppShellResize`.
27
+ */
28
+ resizable?: SidebarResizeOptions;
18
29
  /** Sets `--app-shell-mobile-header-height`. Default `"calc(3.5rem + env(safe-area-inset-top, 0px))"`. */
19
30
  mobileHeaderHeight?: string;
20
31
  /** Default `"Skip to main content"`. */
@@ -36,6 +47,7 @@ export function AppShell({
36
47
  panelHidden = false,
37
48
  railWidth = "4rem",
38
49
  sidebarWidth = "20rem",
50
+ resizable,
39
51
  mobileHeaderHeight = "calc(3.5rem + env(safe-area-inset-top, 0px))",
40
52
  skipLinkLabel = "Skip to main content",
41
53
  mainId = "main-content",
@@ -43,41 +55,45 @@ export function AppShell({
43
55
  mainClassName,
44
56
  contentClassName,
45
57
  }: AppShellProps) {
58
+ const resize = useSidebarResizeState(resizable);
46
59
  const style: ShellVars = {
47
60
  "--app-shell-rail-width": railWidth,
48
- "--app-shell-sidebar-width": sidebarWidth,
61
+ "--app-shell-sidebar-width": resize ? `calc(${railWidth} + ${resize.width}px)` : sidebarWidth,
49
62
  "--app-shell-mobile-header-height": mobileHeaderHeight,
50
63
  };
51
64
  return (
52
- <div className={cn("relative h-dvh overflow-hidden bg-background", className)} style={style}>
53
- <a
54
- href={`#${mainId}`}
55
- className="sr-only focus:absolute focus:left-3 focus:top-[max(0.75rem,env(safe-area-inset-top))] focus:z-[100] focus:block focus:rounded-lg focus:bg-surface-secondary focus:px-3 focus:py-2 focus:text-sm focus:font-medium focus:text-foreground focus:outline-none focus-visible:ring-2 focus-visible:ring-focus-ring"
56
- >
57
- {skipLinkLabel}
58
- </a>
59
- {sidebar}
60
- <main
61
- id={mainId}
62
- tabIndex={-1}
63
- className={cn(
64
- "relative z-10 flex h-full min-h-0 outline-none md:p-2",
65
- panelHidden
66
- ? "md:ml-[var(--app-shell-rail-width)]"
67
- : "md:ml-[var(--app-shell-sidebar-width)]",
68
- "md:transition-[margin-left] md:[transition-duration:280ms] md:[transition-timing-function:cubic-bezier(0.22,1,0.36,1)]",
69
- mainClassName,
70
- )}
71
- >
72
- <div
65
+ <SidebarResizeProvider value={resize}>
66
+ <div className={cn("relative h-dvh overflow-hidden bg-background", className)} style={style}>
67
+ <a
68
+ href={`#${mainId}`}
69
+ className="sr-only focus:absolute focus:left-3 focus:top-[max(0.75rem,env(safe-area-inset-top))] focus:z-[100] focus:block focus:rounded-lg focus:bg-surface-secondary focus:px-3 focus:py-2 focus:text-sm focus:font-medium focus:text-foreground focus:outline-none focus-visible:ring-2 focus-visible:ring-focus-ring"
70
+ >
71
+ {skipLinkLabel}
72
+ </a>
73
+ {sidebar}
74
+ <main
75
+ id={mainId}
76
+ tabIndex={-1}
73
77
  className={cn(
74
- "flex min-h-0 flex-1 flex-col overflow-hidden bg-surface pt-[var(--app-shell-mobile-header-height)] md:rounded-lg md:pt-0",
75
- contentClassName,
78
+ "relative z-10 flex h-full min-h-0 outline-none md:p-2",
79
+ panelHidden
80
+ ? "md:ml-[var(--app-shell-rail-width)]"
81
+ : "md:ml-[var(--app-shell-sidebar-width)]",
82
+ !resize?.isResizing &&
83
+ "md:transition-[margin-left] md:[transition-duration:280ms] md:[transition-timing-function:cubic-bezier(0.22,1,0.36,1)]",
84
+ mainClassName,
76
85
  )}
77
86
  >
78
- {children}
79
- </div>
80
- </main>
81
- </div>
87
+ <div
88
+ className={cn(
89
+ "flex min-h-0 flex-1 flex-col overflow-hidden bg-surface pt-[var(--app-shell-mobile-header-height)] md:rounded-lg md:pt-0",
90
+ contentClassName,
91
+ )}
92
+ >
93
+ {children}
94
+ </div>
95
+ </main>
96
+ </div>
97
+ </SidebarResizeProvider>
82
98
  );
83
99
  }
@@ -5,6 +5,7 @@ import { Button } from "../../src/ui/button";
5
5
  import { motionEase, motionTiming } from "../../src/motion/presets";
6
6
  import { cn } from "../../src/utils/cn";
7
7
  import { mobileMenuButtonClass } from "./app-shell-classes";
8
+ import { SidebarResizeHandle, useSidebarResizeContext } from "./SidebarResize";
8
9
 
9
10
  export type AppSidebarProps = {
10
11
  /** Icon rail, usually a `SidebarRail`. */
@@ -28,6 +29,8 @@ export type AppSidebarProps = {
28
29
  className?: string;
29
30
  /** Centred in the mobile header when truthy. */
30
31
  mobileTitle?: ReactNode;
32
+ /** Trailing actions in the mobile header, for example icon buttons. Replaces the end spacer. */
33
+ mobileHeaderActions?: ReactNode;
31
34
  /** Menu button icon. Default a 20px menu icon. */
32
35
  mobileMenuIcon?: (open: boolean) => ReactNode;
33
36
  /** Default `"Open navigation menu"`. */
@@ -41,7 +44,8 @@ const defaultMobileMenuIcon = () => <IconMenu2 size={20} />;
41
44
  /**
42
45
  * Sidebar chrome: the mobile header, the drawer backdrop and the `<aside>`
43
46
  * (fixed on desktop, a swipe-to-close drawer below it). Reads the
44
- * `--app-shell-*` width variables set by `AppShell`.
47
+ * `--app-shell-*` width variables set by `AppShell`. Inside a resizable
48
+ * `AppShell` it adds the resize handle while the panel shows on desktop.
45
49
  */
46
50
  export function AppSidebar({
47
51
  rail,
@@ -55,6 +59,7 @@ export function AppSidebar({
55
59
  asideProps,
56
60
  className,
57
61
  mobileTitle,
62
+ mobileHeaderActions,
58
63
  mobileMenuIcon = defaultMobileMenuIcon,
59
64
  mobileMenuLabel = "Open navigation menu",
60
65
  closeLabel = "Close navigation",
@@ -62,6 +67,8 @@ export function AppSidebar({
62
67
  const autoId = useId();
63
68
  const drawerId = id ?? autoId;
64
69
  const layout = isDesktop ? "desktop" : "drawer";
70
+ const resize = useSidebarResizeContext();
71
+ const showResizeHandle = resize !== null && isDesktop && !collapsed && !panelHidden;
65
72
 
66
73
  // Reaching the desktop breakpoint closes the drawer, so it does not reopen
67
74
  // on the way back down. Runs on breakpoint change only.
@@ -110,7 +117,13 @@ export function AppSidebar({
110
117
  {mobileTitle}
111
118
  </h1>
112
119
  ) : null}
113
- <div className="ml-auto h-11 w-11 shrink-0" aria-hidden="true" />
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
+ )}
114
127
  </header>
115
128
 
116
129
  <AnimatePresence initial={false}>
@@ -142,7 +155,8 @@ export function AppSidebar({
142
155
  collapsed || panelHidden
143
156
  ? "md:w-[var(--app-shell-rail-width)]"
144
157
  : "md:w-[var(--app-shell-sidebar-width)]",
145
- "md:transition-[width] md:[transition-duration:280ms] md:[transition-timing-function:cubic-bezier(0.22,1,0.36,1)]",
158
+ !resize?.isResizing &&
159
+ "md:transition-[width] md:[transition-duration:280ms] md:[transition-timing-function:cubic-bezier(0.22,1,0.36,1)]",
146
160
  className,
147
161
  )}
148
162
  initial={false}
@@ -156,6 +170,7 @@ export function AppSidebar({
156
170
  >
157
171
  {rail}
158
172
  {panelHidden ? null : panel}
173
+ {showResizeHandle ? <SidebarResizeHandle /> : null}
159
174
  </motion.aside>
160
175
  </>
161
176
  );
@@ -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
- return (
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
- className={cn(railTileClass, "h-11 w-11 p-0", railTileStateClass(false))}
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,5 +1,6 @@
1
1
  import type { ComponentPropsWithoutRef, ReactNode } from "react";
2
2
  import { Slot, Slottable } from "@radix-ui/react-slot";
3
+ import * as TabsPrimitive from "@radix-ui/react-tabs";
3
4
  import { Button } from "../../src/ui/button";
4
5
  import { cn } from "../../src/utils/cn";
5
6
  import { railTileClass, railTileStateClass } from "./app-shell-classes";
@@ -16,6 +17,12 @@ export type SidebarRailProps = Omit<ComponentPropsWithoutRef<"div">, "children"
16
17
  showDivider?: boolean;
17
18
  /** Render the body as its single child element (for example a tabs list), with the body classes merged. */
18
19
  bodyAsChild?: boolean;
20
+ /**
21
+ * Render the body as a Radix tabs list (arrow-key roving focus). Use it
22
+ * inside a Tabs root with `orientation="vertical"` and give each `RailTile`
23
+ * a `tabValue`. Default `false`.
24
+ */
25
+ tabs?: boolean;
19
26
  className?: string;
20
27
  topClassName?: string;
21
28
  bodyClassName?: string;
@@ -29,6 +36,7 @@ export function SidebarRail({
29
36
  footer,
30
37
  showDivider = false,
31
38
  bodyAsChild = false,
39
+ tabs = false,
32
40
  className,
33
41
  topClassName,
34
42
  bodyClassName,
@@ -36,6 +44,10 @@ export function SidebarRail({
36
44
  ...props
37
45
  }: SidebarRailProps) {
38
46
  const Body = bodyAsChild ? Slot : "div";
47
+ const bodyClass = cn(
48
+ "flex w-full flex-1 flex-col items-center gap-1.5 overflow-y-auto py-2",
49
+ bodyClassName,
50
+ );
39
51
  return (
40
52
  <div
41
53
  {...props}
@@ -50,14 +62,13 @@ export function SidebarRail({
50
62
  {top}
51
63
  </div>
52
64
  )}
53
- <Body
54
- className={cn(
55
- "flex w-full flex-1 flex-col items-center gap-1.5 overflow-y-auto py-2",
56
- bodyClassName,
57
- )}
58
- >
59
- {children}
60
- </Body>
65
+ {tabs ? (
66
+ <TabsPrimitive.List asChild={bodyAsChild} className={bodyClass}>
67
+ {children}
68
+ </TabsPrimitive.List>
69
+ ) : (
70
+ <Body className={bodyClass}>{children}</Body>
71
+ )}
61
72
  {footer == null ? null : (
62
73
  <div className={cn("flex w-full flex-col items-center gap-1.5 py-3", footerClassName)}>
63
74
  {footer}
@@ -80,10 +91,15 @@ export type RailTileProps = Omit<ComponentPropsWithoutRef<"button">, "children">
80
91
  badge?: ReactNode;
81
92
  /** Render the single child element (for example a router link) as the tile. */
82
93
  asChild?: boolean;
94
+ /**
95
+ * Render a Radix tabs trigger for this value (inside a `SidebarRail tabs`).
96
+ * The label is sr-only text instead of `aria-label`; `asChild` is ignored.
97
+ */
98
+ tabValue?: string;
83
99
  children: ReactNode;
84
100
  };
85
101
 
86
- /** Rail tile with a right-side tooltip. Renders a ghost `Button`, or its child with `asChild`. */
102
+ /** Rail tile with a right-side tooltip. Renders a ghost `Button`, its child with `asChild`, or a tabs trigger with `tabValue`. */
87
103
  export function RailTile({
88
104
  label,
89
105
  active = false,
@@ -91,13 +107,24 @@ export function RailTile({
91
107
  showTooltip = true,
92
108
  badge,
93
109
  asChild = false,
110
+ tabValue,
94
111
  className,
95
112
  children,
96
113
  ...props
97
114
  }: RailTileProps) {
98
115
  return (
99
116
  <SidebarIconTooltip label={tooltip ?? label} enabled={showTooltip}>
100
- {asChild ? (
117
+ {tabValue !== undefined ? (
118
+ <TabsPrimitive.Trigger
119
+ {...props}
120
+ value={tabValue}
121
+ className={cn(railTileClass, "group relative", railTileStateClass(active), className)}
122
+ >
123
+ {children}
124
+ <span className="sr-only">{label}</span>
125
+ {badge}
126
+ </TabsPrimitive.Trigger>
127
+ ) : asChild ? (
101
128
  <Slot
102
129
  {...props}
103
130
  aria-label={label}
@@ -0,0 +1,257 @@
1
+ import {
2
+ createContext,
3
+ useContext,
4
+ useEffect,
5
+ useRef,
6
+ useState,
7
+ useSyncExternalStore,
8
+ type KeyboardEvent,
9
+ type PointerEvent,
10
+ } from "react";
11
+ import { animate } from "motion";
12
+ import { cn } from "../../src/utils/cn";
13
+
14
+ /** Opt-in resizable sidebar panel. Widths are panel px, rail excluded. */
15
+ export type SidebarResizeOptions = {
16
+ /** `localStorage` key for the panel width (a JSON number). */
17
+ storageKey: string;
18
+ defaultWidth: number;
19
+ minWidth: number;
20
+ maxWidth: number;
21
+ /** Handle `aria-label`. Default `"Resize sidebar"`. */
22
+ label?: string;
23
+ };
24
+
25
+ type WidthUpdate = number | ((width: number) => number);
26
+ type Animation = ReturnType<typeof animate>;
27
+
28
+ type SidebarResizeState = {
29
+ width: number;
30
+ setWidth: (update: WidthUpdate) => void;
31
+ isResizing: boolean;
32
+ minWidth: number;
33
+ maxWidth: number;
34
+ defaultWidth: number;
35
+ label: string;
36
+ /** Latest width, readable between renders (pointer moves can outpace them). */
37
+ currentWidth: () => number;
38
+ stopAnimation: () => void;
39
+ startResizing: () => void;
40
+ settleToClamp: (velocity: number) => void;
41
+ };
42
+
43
+ const SidebarResizeContext = createContext<SidebarResizeState | null>(null);
44
+ export const SidebarResizeProvider = SidebarResizeContext.Provider;
45
+
46
+ const KEYBOARD_STEP = 16;
47
+
48
+ function rubberband(overshoot: number, dimension: number, constant = 0.55): number {
49
+ return (overshoot * dimension * constant) / (dimension + constant * Math.abs(overshoot));
50
+ }
51
+
52
+ type Sample = { x: number; t: number };
53
+
54
+ function releaseVelocity(samples: Sample[]): number {
55
+ if (samples.length < 2) return 0;
56
+ const newest = samples[samples.length - 1];
57
+ const oldest = samples[0];
58
+ if (!newest || !oldest) return 0;
59
+ const dt = newest.t - oldest.t;
60
+ if (dt <= 0) return 0;
61
+ return ((newest.x - oldest.x) / dt) * 1000;
62
+ }
63
+
64
+ function readStoredWidth(storageKey: string | undefined): number | null {
65
+ if (storageKey === undefined || typeof window === "undefined") return null;
66
+ try {
67
+ const raw = window.localStorage.getItem(storageKey);
68
+ if (raw === null || raw.trim() === "") return null;
69
+ // A JSON number parses the same with Number(); anything else is NaN.
70
+ const value = Number(raw);
71
+ return Number.isFinite(value) ? value : null;
72
+ } catch {
73
+ return null;
74
+ }
75
+ }
76
+
77
+ function writeStoredWidth(storageKey: string, width: number) {
78
+ try {
79
+ window.localStorage.setItem(storageKey, JSON.stringify(width));
80
+ } catch {
81
+ // Storage full or blocked: keep the in-memory width.
82
+ }
83
+ }
84
+
85
+ const subscribeNever = () => () => {};
86
+ const serverSnapshot = () => null;
87
+
88
+ /**
89
+ * Width and resize state for `AppShell`. Returns `null` without options. The
90
+ * stored width is read through `useSyncExternalStore` (the server snapshot is
91
+ * `null`, so SSR and hydration render `defaultWidth`); later writes go to
92
+ * local state and storage.
93
+ */
94
+ export function useSidebarResizeState(
95
+ options: SidebarResizeOptions | undefined,
96
+ ): SidebarResizeState | null {
97
+ const storageKey = options?.storageKey;
98
+ const stored = useSyncExternalStore(subscribeNever, () => readStoredWidth(storageKey), serverSnapshot);
99
+ const [override, setOverride] = useState<number | null>(null);
100
+ const [isResizing, setIsResizing] = useState(false);
101
+ const widthRef = useRef<number | null>(null);
102
+ const animRef = useRef<Animation | null>(null);
103
+
104
+ useEffect(() => () => animRef.current?.stop(), []);
105
+
106
+ if (!options) return null;
107
+ const { defaultWidth, minWidth, maxWidth } = options;
108
+ const clampWidth = (width: number) => Math.min(maxWidth, Math.max(minWidth, width));
109
+ const width = override ?? (stored === null ? defaultWidth : clampWidth(stored));
110
+ const currentWidth = () => widthRef.current ?? width;
111
+
112
+ const setWidth = (update: WidthUpdate) => {
113
+ const next = typeof update === "function" ? update(currentWidth()) : update;
114
+ widthRef.current = next;
115
+ setOverride(next);
116
+ writeStoredWidth(options.storageKey, next);
117
+ };
118
+
119
+ const stopAnimation = () => animRef.current?.stop();
120
+
121
+ const settleToClamp = (velocity: number) => {
122
+ const from = currentWidth();
123
+ const to = clampWidth(from);
124
+ setIsResizing(false);
125
+ if (from === to) return;
126
+ animRef.current?.stop();
127
+ animRef.current = animate(from, to, {
128
+ type: "spring",
129
+ bounce: 0.2,
130
+ duration: 0.35,
131
+ velocity,
132
+ onUpdate: (value) => setWidth(value),
133
+ });
134
+ };
135
+
136
+ return {
137
+ width,
138
+ setWidth,
139
+ isResizing,
140
+ minWidth,
141
+ maxWidth,
142
+ defaultWidth,
143
+ label: options.label ?? "Resize sidebar",
144
+ currentWidth,
145
+ stopAnimation,
146
+ startResizing: () => setIsResizing(true),
147
+ settleToClamp,
148
+ };
149
+ }
150
+
151
+ export function useSidebarResizeContext(): SidebarResizeState | null {
152
+ return useContext(SidebarResizeContext);
153
+ }
154
+
155
+ export type AppShellResize = {
156
+ /** Panel width in px (rail excluded). Can sit past the bounds mid-drag. */
157
+ width: number;
158
+ setWidth: (update: WidthUpdate) => void;
159
+ isResizing: boolean;
160
+ minWidth: number;
161
+ maxWidth: number;
162
+ defaultWidth: number;
163
+ };
164
+
165
+ /** Panel width and resize state of the nearest resizable `AppShell`, or `null`. */
166
+ export function useAppShellResize(): AppShellResize | null {
167
+ const resize = useContext(SidebarResizeContext);
168
+ if (!resize) return null;
169
+ const { width, setWidth, isResizing, minWidth, maxWidth, defaultWidth } = resize;
170
+ return { width, setWidth, isResizing, minWidth, maxWidth, defaultWidth };
171
+ }
172
+
173
+ export type SidebarResizeHandleProps = { className?: string };
174
+
175
+ /**
176
+ * Vertical separator on the right edge of its positioned parent. Drag past the
177
+ * bounds rubber-bands and springs back on release; arrow keys step 16px;
178
+ * double-click resets. Renders nothing outside a resizable `AppShell`.
179
+ */
180
+ export function SidebarResizeHandle({ className }: SidebarResizeHandleProps) {
181
+ const resize = useContext(SidebarResizeContext);
182
+ const samplesRef = useRef<Sample[]>([]);
183
+ if (!resize) return null;
184
+ const { width, setWidth, isResizing, minWidth, maxWidth, defaultWidth } = resize;
185
+ const clampWidth = (value: number) => Math.min(maxWidth, Math.max(minWidth, value));
186
+ const softWidth = (value: number) => {
187
+ if (value < minWidth) return minWidth - rubberband(minWidth - value, minWidth);
188
+ if (value > maxWidth) return maxWidth + rubberband(value - maxWidth, maxWidth);
189
+ return value;
190
+ };
191
+
192
+ const handlePointerDown = (event: PointerEvent<HTMLDivElement>) => {
193
+ event.preventDefault();
194
+ resize.stopAnimation();
195
+ event.currentTarget.setPointerCapture(event.pointerId);
196
+ samplesRef.current = [{ x: resize.currentWidth(), t: performance.now() }];
197
+ resize.startResizing();
198
+ };
199
+
200
+ const handlePointerMove = (event: PointerEvent<HTMLDivElement>) => {
201
+ if (!isResizing) return;
202
+ const next = softWidth(resize.currentWidth() + event.movementX);
203
+ const now = performance.now();
204
+ const samples = samplesRef.current;
205
+ samples.push({ x: next, t: now });
206
+ while (samples.length > 5 || now - (samples[0]?.t ?? now) > 80) samples.shift();
207
+ setWidth(next);
208
+ };
209
+
210
+ const handlePointerUp = (event: PointerEvent<HTMLDivElement>) => {
211
+ event.currentTarget.releasePointerCapture(event.pointerId);
212
+ resize.settleToClamp(releaseVelocity(samplesRef.current));
213
+ samplesRef.current = [];
214
+ };
215
+
216
+ const handlePointerCancel = (event: PointerEvent<HTMLDivElement>) => {
217
+ event.currentTarget.releasePointerCapture(event.pointerId);
218
+ resize.settleToClamp(0);
219
+ samplesRef.current = [];
220
+ };
221
+
222
+ const handleDoubleClick = () => {
223
+ resize.stopAnimation();
224
+ setWidth(defaultWidth);
225
+ };
226
+
227
+ const handleKeyDown = (event: KeyboardEvent<HTMLDivElement>) => {
228
+ if (event.key !== "ArrowLeft" && event.key !== "ArrowRight") return;
229
+ event.preventDefault();
230
+ resize.stopAnimation();
231
+ const step = event.key === "ArrowLeft" ? -KEYBOARD_STEP : KEYBOARD_STEP;
232
+ setWidth((current) => clampWidth(current + step));
233
+ };
234
+
235
+ return (
236
+ <div
237
+ role="separator"
238
+ aria-orientation="vertical"
239
+ aria-label={resize.label}
240
+ aria-valuenow={clampWidth(width)}
241
+ aria-valuemin={minWidth}
242
+ aria-valuemax={maxWidth}
243
+ tabIndex={0}
244
+ className={cn(
245
+ "absolute inset-y-0 right-0 z-50 h-full w-1.5 cursor-col-resize outline-hidden transition-[background-color] hover:bg-default focus-visible:bg-default",
246
+ isResizing && "bg-default",
247
+ className,
248
+ )}
249
+ onPointerDown={handlePointerDown}
250
+ onPointerMove={handlePointerMove}
251
+ onPointerUp={handlePointerUp}
252
+ onPointerCancel={handlePointerCancel}
253
+ onDoubleClick={handleDoubleClick}
254
+ onKeyDown={handleKeyDown}
255
+ />
256
+ );
257
+ }
@@ -16,6 +16,12 @@ export { AppSidebar } from "./AppSidebar.js";
16
16
  export type { AppSidebarProps } from "./AppSidebar.js";
17
17
  export { SidebarRail, RailTile, RailDivider } from "./SidebarRail.js";
18
18
  export type { SidebarRailProps, RailTileProps, RailDividerProps } from "./SidebarRail.js";
19
+ export { SidebarResizeHandle, useAppShellResize } from "./SidebarResize.js";
20
+ export type {
21
+ AppShellResize,
22
+ SidebarResizeHandleProps,
23
+ SidebarResizeOptions,
24
+ } from "./SidebarResize.js";
19
25
  export { SidebarIconTooltip } from "./SidebarIconTooltip.js";
20
26
  export type { SidebarIconTooltipProps } from "./SidebarIconTooltip.js";
21
27
  export { SidebarPanel } from "./SidebarPanel.js";
package/src/index.ts CHANGED
@@ -128,6 +128,12 @@ export { AppSidebar } from "../shell/src/AppSidebar";
128
128
  export type { AppSidebarProps } from "../shell/src/AppSidebar";
129
129
  export { SidebarRail, RailTile, RailDivider } from "../shell/src/SidebarRail";
130
130
  export type { SidebarRailProps, RailTileProps, RailDividerProps } from "../shell/src/SidebarRail";
131
+ export { SidebarResizeHandle, useAppShellResize } from "../shell/src/SidebarResize";
132
+ export type {
133
+ AppShellResize,
134
+ SidebarResizeHandleProps,
135
+ SidebarResizeOptions,
136
+ } from "../shell/src/SidebarResize";
131
137
  export { SidebarIconTooltip } from "../shell/src/SidebarIconTooltip";
132
138
  export type { SidebarIconTooltipProps } from "../shell/src/SidebarIconTooltip";
133
139
  export { SidebarPanel } from "../shell/src/SidebarPanel";
@@ -10,7 +10,14 @@ import {
10
10
  AlertDialogTitle,
11
11
  } from "./alert-dialog";
12
12
  import { Button } from "./button";
13
- import { Dialog, DialogContent, DialogDescription, DialogTitle } from "./dialog";
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}