@vvedantb/ui 0.7.1 → 0.7.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 +97 -4
- package/package.json +1 -1
- package/shell/src/Sidebar.tsx +17 -1
- package/shell/src/SidebarPanel.tsx +65 -4
- package/shell/src/app-shell-classes.ts +68 -7
- package/shell/src/index.ts +6 -0
- package/src/index.ts +6 -0
- package/tokens/README.md +1 -1
- package/tokens/src/css/compat-shadcn-rgb.css +4 -0
- package/tokens/src/tokens.css +5 -0
package/README.md
CHANGED
|
@@ -299,7 +299,7 @@ import {
|
|
|
299
299
|
- `SidebarPanel`: legacy (still supported) `headerTrailing`, `onClose`, `closeLabel` and `closeButtonClassName`; compose `Sidebar.Panel` parts instead. `title`, `headerTrailing`, `onClose` (adds the close button; pass it on the mobile drawer only), `closeLabel`, `closeButtonClassName`, `collapsed` (`md:hidden`), `className`, `children`.
|
|
300
300
|
- `SidebarAccountMenu`: legacy (still supported) `badge`, `triggerProps`, `contentProps` and `stackedLabel`; compose `Sidebar.Account*` parts instead. `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.
|
|
301
301
|
- `SignOutDialog`: legacy (still supported) `question` and `title`; compose `ConfirmDialog` parts with `alert={false}` for other copy. `open`, `onOpenChange` (not called with `false` while `pending`), `pending`, `onConfirm`, `description`, `contentClassName`, `title` (`"Sign out"`), `question` (`"Sign out of your account?"`).
|
|
302
|
-
- Class helpers: `railTileClass`, `railTileStateClass(active)`, `railBadgeClass`, `sidebarNavRowClass(isIconOnly)`, `sidebarNavLinkTextClass(isActive)`, `sidebarNavItemClass({ active, iconOnly })`, `sidebarNavIconClass(active)`, `sidebarSectionLabelClass`. See [Menu item corners and sidebar nav rows (0.7.1)](#menu-item-corners-and-sidebar-nav-rows-071).
|
|
302
|
+
- Class helpers: `railTileClass`, `railTileStateClass(active)`, `railBadgeClass`, `sidebarNavRowClass(isIconOnly)`, `sidebarNavLinkTextClass(isActive)`, `sidebarNavItemClass({ active, iconOnly, selected, dragging, dropTarget })`, `sidebarNavIconClass(active)`, `sidebarSectionLabelClass`, and the row parts `sidebarNavItemLeadingClass`, `sidebarNavItemLabelClass`, `sidebarNavItemSubtitleClass`, `sidebarNavItemTrailingClass`, `sidebarNavItemActionsClass` and `sidebarNavItemIndentStyle(indent)`. See [Menu item corners and sidebar nav rows (0.7.1)](#menu-item-corners-and-sidebar-nav-rows-071) and [Sidebar nav row parts (0.7.2)](#sidebar-nav-row-parts-072).
|
|
303
303
|
|
|
304
304
|
### Header actions and account badge (0.5.2)
|
|
305
305
|
|
|
@@ -434,7 +434,8 @@ Convention: compound parts are static members of a namespace object, `<Namespace
|
|
|
434
434
|
| `PanelHeader` | Padded header row for `PanelTitle` and `PanelActions`. |
|
|
435
435
|
| `PanelTitle` / `PanelActions` | The `<h2>` and the trailing actions. |
|
|
436
436
|
| `PanelClose` | Ghost close button. `label` (`"Close navigation"`). Without `onClick` it closes the drawer. |
|
|
437
|
-
| `NavItem` | Panel nav row (`sidebarNavItemClass`). `active` (fill, `font-medium`, `aria-current="page"`), `iconOnly`, `icon` (element; gets `sidebarNavIconClass`), `asChild` for a router link. A `<button type="button">` without `asChild`. |
|
|
437
|
+
| `NavItem` | Panel nav row (`sidebarNavItemClass`). `active` (fill, `font-medium`, `aria-current="page"`), `iconOnly`, `icon` (element; gets `sidebarNavIconClass`), `asChild` for a router link. A `<button type="button">` without `asChild`. 0.7.2: `selected`, `indent`, `dragging`, `dropTarget`; see [Sidebar nav row parts (0.7.2)](#sidebar-nav-row-parts-072). |
|
|
438
|
+
| `NavItemLeading` / `NavItemLabel` / `NavItemTrailing` / `NavItemActions` | Row parts (0.7.2): leading slot, truncated label, always-visible trailing content and hover-revealed actions. `<span>`, or the child with `asChild`. |
|
|
438
439
|
| `AccountMenu` | Dropdown root. `badge` adds the unread dot (`AccountBadge`) in a `relative` wrapper. |
|
|
439
440
|
| `AccountTrigger` | Rail-tile-sized avatar button. `userName` (default `title` and `aria-label`, and the initials), `imageUrl`, plus `Button` props; native `name` goes to the button. |
|
|
440
441
|
| `AccountAvatar` | Avatar image or initials. `userName`, `imageUrl`. |
|
|
@@ -693,12 +694,104 @@ Colour mapping. The package has no sidebar colour tokens, so the rows use the ne
|
|
|
693
694
|
|
|
694
695
|
| Role | Reference look (light / dark, sRGB) | Package token (light / dark, sRGB) |
|
|
695
696
|
| --- | --- | --- |
|
|
696
|
-
| Hover and active fill | 233 234 236 / 28 28 28 | `surface-tertiary`: 234 234 234 / about 39 39 39. Light matches; dark is a step lighter. It is the rail tile's active fill too, so a rail tile and a nav row stay the same. |
|
|
697
|
+
| Hover and active fill | 233 234 236 / 28 28 28 | `surface-tertiary`: 234 234 234 / about 39 39 39. Light matches; dark is a step lighter. It is the rail tile's active fill too, so a rail tile and a nav row stay the same. From 0.7.2 the rows use `sidebar-accent` (234 234 234 / 28 28 28); see below. |
|
|
697
698
|
| Active text and icon | 9 9 11 / 250 250 250 | `foreground`: 24 24 24 / 252 252 252 |
|
|
698
699
|
| Idle text (80%) | 24 24 25 / 251 252 253 | `foreground` at 80% |
|
|
699
700
|
| Idle icon | 100 101 103 / 159 160 162 | `muted-foreground` (`--muted`): 114 114 114 / 160 160 160 |
|
|
700
701
|
| Focus ring (35%) | 9 9 11 / 250 250 250 | `foreground` at 35% |
|
|
701
702
|
|
|
703
|
+
## Sidebar nav row parts (0.7.2)
|
|
704
|
+
|
|
705
|
+
One row style for every sidebar list: plain nav links and rich rows (checkbox, avatar, two-line label, nested folders, `...` menus, drag and drop, rename inputs). `Sidebar.NavItem` is the row; the parts go inside it.
|
|
706
|
+
|
|
707
|
+
Rich row (the link is the row; the parts are its children):
|
|
708
|
+
|
|
709
|
+
```tsx
|
|
710
|
+
<Sidebar.NavItem asChild active={isActive} selected={selected} indent={1} dragging={isDragged} dropTarget={isOver}>
|
|
711
|
+
<Link to="/chat/$id" params={{ id }} draggable onDragStart={onDragStart}>
|
|
712
|
+
<Sidebar.NavItemLeading>
|
|
713
|
+
<Checkbox checked={selected} onClick={(event) => event.stopPropagation()} aria-label={`Select ${title}`} />
|
|
714
|
+
</Sidebar.NavItemLeading>
|
|
715
|
+
<Sidebar.NavItemLabel>{title}</Sidebar.NavItemLabel>
|
|
716
|
+
<Sidebar.NavItemTrailing>{generating ? <Spinner size={14} decorative /> : count}</Sidebar.NavItemTrailing>
|
|
717
|
+
<Sidebar.NavItemActions>
|
|
718
|
+
<DropdownMenu>
|
|
719
|
+
<DropdownMenuTrigger asChild>
|
|
720
|
+
<Button
|
|
721
|
+
variant="ghost"
|
|
722
|
+
size="icon-xs"
|
|
723
|
+
aria-label="Row actions"
|
|
724
|
+
onClick={(event) => {
|
|
725
|
+
event.stopPropagation();
|
|
726
|
+
event.preventDefault();
|
|
727
|
+
}}
|
|
728
|
+
>
|
|
729
|
+
<IconDots size={16} />
|
|
730
|
+
</Button>
|
|
731
|
+
</DropdownMenuTrigger>
|
|
732
|
+
<DropdownMenuContent>...</DropdownMenuContent>
|
|
733
|
+
</DropdownMenu>
|
|
734
|
+
</Sidebar.NavItemActions>
|
|
735
|
+
</Link>
|
|
736
|
+
</Sidebar.NavItem>
|
|
737
|
+
```
|
|
738
|
+
|
|
739
|
+
Simple row (unchanged from 0.7.1):
|
|
740
|
+
|
|
741
|
+
```tsx
|
|
742
|
+
<Sidebar.NavItem asChild active={active} icon={<IconHome />}>
|
|
743
|
+
<Link to="/home"><span className="truncate">Home</span></Link>
|
|
744
|
+
</Sidebar.NavItem>
|
|
745
|
+
```
|
|
746
|
+
|
|
747
|
+
`Sidebar.NavItem` props added in 0.7.2:
|
|
748
|
+
|
|
749
|
+
| Prop | Effect |
|
|
750
|
+
| --- | --- |
|
|
751
|
+
| `selected` | The active fill (`bg-sidebar-accent text-foreground`) without `font-medium` or `aria-current`. `data-selected="true"`. |
|
|
752
|
+
| `indent` | Nesting level from 0. Left padding is `calc(1rem + indent * 12px)`: 16px, 28px, 40px, ... Set as inline `paddingLeft`, so any depth works and a `style.paddingLeft` you pass wins. Ignored with `iconOnly`. |
|
|
753
|
+
| `dragging` | `opacity-40 cursor-grabbing`. `data-dragging="true"`. |
|
|
754
|
+
| `dropTarget` | Fill plus `ring-2 ring-inset ring-focus`. `data-drop-target="true"`. |
|
|
755
|
+
|
|
756
|
+
`active` also sets `data-active="true"`. Each attribute is left off when its prop is false. The styles key off the attributes (`data-[selected=true]:`, `data-[dragging=true]:`, `data-[drop-target=true]:`), so a row that sets them itself (for example from a tree library's drag state) gets the same look. `sidebarNavItemClass` takes the same `selected`, `dragging` and `dropTarget` options for rows that use the class only.
|
|
757
|
+
|
|
758
|
+
Parts. Each renders a `<span>` with its class (`className` merges last), or merges onto its single child with `asChild`:
|
|
759
|
+
|
|
760
|
+
| Part | Class | Use |
|
|
761
|
+
| --- | --- | --- |
|
|
762
|
+
| `NavItemLeading` | `sidebarNavItemLeadingClass`: `flex shrink-0 items-center` | Checkbox, icon, avatar, status dot, folder chevron. Put `sidebarNavIconClass(active)` on an icon. A 40px avatar makes the row taller; add `py-2` to the row if you want more room. |
|
|
763
|
+
| `NavItemLabel` | `sidebarNavItemLabelClass`: `min-w-0 flex-1 truncate` | The title. For two lines, put `<span className="block truncate">` and `<span className={sidebarNavItemSubtitleClass}>` (`block truncate text-xs text-muted-foreground`) inside. For rename, `asChild` on the input. |
|
|
764
|
+
| `NavItemTrailing` | `sidebarNavItemTrailingClass`: `ml-auto flex shrink-0 items-center gap-1.5 text-xs text-muted-foreground` | Always visible: counts, unread dots, spinners, badges. |
|
|
765
|
+
| `NavItemActions` | `sidebarNavItemActionsClass` (below) | Hover-revealed `...` button. |
|
|
766
|
+
|
|
767
|
+
Actions sit in the row flow at the end (`ml-auto`), so an `asChild` link row needs no `relative`. The part is `h-6` with `-my-1`, so a 24px or 28px icon button does not change the 30px row height. It reserves its width while hidden, so the label truncates a little earlier. For the older overlay look, pass `className="absolute right-3"` to the part and `relative` to the row. Visibility:
|
|
768
|
+
|
|
769
|
+
- `opacity-0` by default, `transition-opacity duration-75`.
|
|
770
|
+
- `group-hover:opacity-100` and `group-focus-within:opacity-100`: the row is a `group`.
|
|
771
|
+
- `has-[[data-state=open]]:opacity-100`: a Radix menu trigger inside it is open.
|
|
772
|
+
- `data-[state=open]:opacity-100`: the part itself is the trigger (`asChild`).
|
|
773
|
+
|
|
774
|
+
The part adds no handlers. Call `stopPropagation()` (and `preventDefault()` inside a link) on the button so it does not run the row click.
|
|
775
|
+
|
|
776
|
+
Other rich-row needs:
|
|
777
|
+
|
|
778
|
+
- Folder rows and drop zones: render the row as a `<div>` or `<button>` (`asChild` on a `<div>` when the row holds its own buttons) and wrap it in your drop zone. Set `dropTarget` while a drag is over it.
|
|
779
|
+
- Indent guide lines: absolutely positioned spans in the row; add `relative` to the row.
|
|
780
|
+
- Context menus and hover cards: wrap `Sidebar.NavItem` as before; `ContextMenuTrigger asChild` can wrap it directly.
|
|
781
|
+
|
|
782
|
+
Classes a rich row no longer needs beside the parts: `rounded-lg`, `rounded-md`, `text-sm` (and `text-sm` on the title span), `px-3 py-1.5`, `gap-3`, `py-2`/`gap-3` for padding alone, `pl-7`/`pl-8` (use `indent`), `bg-surface-tertiary` for active, hover or selected, `ring-2 ring-inset ring-focus` and `opacity-40 cursor-grabbing` for drag states, `opacity-0 group-hover:opacity-100 group-focus-within:opacity-100 transition-opacity` on the menu button, `mr-2` on a checkbox (the row `gap-2` spaces it), `truncate flex-1 min-w-0` on the title, `text-xs text-muted` on counts, and app row helpers that set any of these (a local list-item class, an outer `group py-px` wrapper, a `ui-sidebar-row` class).
|
|
783
|
+
|
|
784
|
+
### Fill colour: `sidebar-accent`
|
|
785
|
+
|
|
786
|
+
Rows (hover, active, selected, drop target) use `bg-sidebar-accent` instead of `bg-surface-tertiary`.
|
|
787
|
+
|
|
788
|
+
| | Light | Dark |
|
|
789
|
+
| --- | --- | --- |
|
|
790
|
+
| `tokens.css` `--sidebar-accent` | `var(--surface-tertiary)` (about 234 234 234; unchanged) | `oklch(22.64% 0 0)` (28 28 28; was about 39 39 39) |
|
|
791
|
+
| `compat-shadcn-rgb.css` `--color-sidebar-accent` | `rgb(var(--sidebar-accent, var(--secondary)))`: the app's `--sidebar-accent` channels if defined, else `--secondary` as before | same |
|
|
792
|
+
|
|
793
|
+
Rail tiles keep `surface-tertiary`, so in dark mode the active rail tile is a step lighter than the active row. An app that imports `tokens.css` and defines its own `--sidebar-accent` overrides the fill; it must be a full colour value there (use `compat-shadcn-rgb.css` for `R G B` channels).
|
|
794
|
+
|
|
702
795
|
## Toaster
|
|
703
796
|
|
|
704
797
|
```tsx
|
|
@@ -747,7 +840,7 @@ Components use `text-muted-foreground`, `primary` and `--color-*` theme variable
|
|
|
747
840
|
Use this when the app defines shadcn-style variables as space-separated channels (`--background: 244 245 246`) and reads them as `rgb(var(--background) / 0.5)`.
|
|
748
841
|
|
|
749
842
|
1. Import `compat-shadcn-rgb.css` **instead of** `tokens.css`. Never import both.
|
|
750
|
-
2. The app keeps `--background`, `--foreground`, `--card`, `--popover`, `--primary`, `--secondary`, `--muted`, `--accent`, `--destructive`, `--border`, `--input`, `--ring` (each with its `-foreground` where shadcn has one) and `--radius`. The compat file does not define them. It only references them, so the app can change `--primary`, `--ring`, `--radius` or `--font-sans` at runtime.
|
|
843
|
+
2. The app keeps `--background`, `--foreground`, `--card`, `--popover`, `--primary`, `--secondary`, `--muted`, `--accent`, `--destructive`, `--border`, `--input`, `--ring` (each with its `-foreground` where shadcn has one) and `--radius`. The compat file does not define them. It only references them, so the app can change `--primary`, `--ring`, `--radius` or `--font-sans` at runtime. `--sidebar-accent` is optional: sidebar nav rows use it when set, else `--secondary` (0.7.2).
|
|
751
844
|
3. Add the `@source` line for the package sources.
|
|
752
845
|
|
|
753
846
|
```css
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vvedantb/ui",
|
|
3
|
-
"version": "0.7.
|
|
3
|
+
"version": "0.7.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",
|
package/shell/src/Sidebar.tsx
CHANGED
|
@@ -9,7 +9,18 @@ import {
|
|
|
9
9
|
AccountSeparator,
|
|
10
10
|
AccountTrigger,
|
|
11
11
|
} from "./SidebarAccountMenu";
|
|
12
|
-
import {
|
|
12
|
+
import {
|
|
13
|
+
NavItem,
|
|
14
|
+
NavItemActions,
|
|
15
|
+
NavItemLabel,
|
|
16
|
+
NavItemLeading,
|
|
17
|
+
NavItemTrailing,
|
|
18
|
+
Panel,
|
|
19
|
+
PanelActions,
|
|
20
|
+
PanelClose,
|
|
21
|
+
PanelHeader,
|
|
22
|
+
PanelTitle,
|
|
23
|
+
} from "./SidebarPanel";
|
|
13
24
|
import { Rail, RailBody, RailFooter, RailHeader, RailItem, RailSeparator } from "./SidebarRail";
|
|
14
25
|
|
|
15
26
|
export type {
|
|
@@ -36,6 +47,7 @@ export type {
|
|
|
36
47
|
SidebarPanelHeaderProps,
|
|
37
48
|
SidebarPanelRootProps,
|
|
38
49
|
SidebarPanelTitleProps,
|
|
50
|
+
SidebarNavItemPartProps,
|
|
39
51
|
SidebarNavItemProps,
|
|
40
52
|
} from "./SidebarPanel";
|
|
41
53
|
export type {
|
|
@@ -70,6 +82,10 @@ export const Sidebar = {
|
|
|
70
82
|
PanelActions,
|
|
71
83
|
PanelClose,
|
|
72
84
|
NavItem,
|
|
85
|
+
NavItemLeading,
|
|
86
|
+
NavItemLabel,
|
|
87
|
+
NavItemTrailing,
|
|
88
|
+
NavItemActions,
|
|
73
89
|
AccountMenu,
|
|
74
90
|
AccountTrigger,
|
|
75
91
|
AccountAvatar,
|
|
@@ -3,7 +3,17 @@ import { Slot, Slottable } from "@radix-ui/react-slot";
|
|
|
3
3
|
import { IconX } from "@tabler/icons-react";
|
|
4
4
|
import { Button, type ButtonProps } from "../../src/ui/button";
|
|
5
5
|
import { cn } from "../../src/utils/cn";
|
|
6
|
-
import {
|
|
6
|
+
import {
|
|
7
|
+
panelCloseButtonClass,
|
|
8
|
+
sidebarHeaderRowClass,
|
|
9
|
+
sidebarNavIconClass,
|
|
10
|
+
sidebarNavItemActionsClass,
|
|
11
|
+
sidebarNavItemClass,
|
|
12
|
+
sidebarNavItemIndentStyle,
|
|
13
|
+
sidebarNavItemLabelClass,
|
|
14
|
+
sidebarNavItemLeadingClass,
|
|
15
|
+
sidebarNavItemTrailingClass,
|
|
16
|
+
} from "./app-shell-classes";
|
|
7
17
|
import { useOptionalSidebar } from "./SidebarChrome";
|
|
8
18
|
|
|
9
19
|
export type SidebarPanelProps = {
|
|
@@ -134,23 +144,36 @@ export function PanelClose({ label = "Close navigation", onClick, className, chi
|
|
|
134
144
|
}
|
|
135
145
|
|
|
136
146
|
export type SidebarNavItemProps = ComponentPropsWithoutRef<"button"> & {
|
|
137
|
-
/** Current route: static fill, `font-medium`, `aria-current="page"`. */
|
|
147
|
+
/** Current route: static fill, `font-medium`, `aria-current="page"`, `data-active="true"`. */
|
|
138
148
|
active?: boolean;
|
|
139
149
|
/** Collapsed panel: centred icon, no horizontal padding. */
|
|
140
150
|
iconOnly?: boolean;
|
|
141
|
-
/** Leading icon element; gets `sidebarNavIconClass(active)` merged onto it. */
|
|
151
|
+
/** Leading icon element; gets `sidebarNavIconClass(active)` merged onto it. For other leading content use `Sidebar.NavItemLeading`. */
|
|
142
152
|
icon?: ReactElement;
|
|
143
153
|
/** Render the single child element (for example a router link) as the row. */
|
|
144
154
|
asChild?: boolean;
|
|
155
|
+
/** Picked (for example in a multi-select list): the active fill without `font-medium`. Sets `data-selected="true"`. */
|
|
156
|
+
selected?: boolean;
|
|
157
|
+
/** Nesting level from 0. Each level adds 12px to the 16px left padding. Ignored with `iconOnly`. */
|
|
158
|
+
indent?: number;
|
|
159
|
+
/** Row being dragged. Sets `data-dragging="true"`. */
|
|
160
|
+
dragging?: boolean;
|
|
161
|
+
/** Row under a drag. Sets `data-drop-target="true"`. */
|
|
162
|
+
dropTarget?: boolean;
|
|
145
163
|
};
|
|
146
164
|
|
|
147
|
-
/** Panel nav row (`sidebarNavItemClass`). Renders a native `<button>`, or its child with `asChild`. */
|
|
165
|
+
/** Panel nav row (`sidebarNavItemClass`). Renders a native `<button>`, or its child with `asChild`. Compose `NavItemLeading`, `NavItemLabel`, `NavItemTrailing` and `NavItemActions` inside. */
|
|
148
166
|
export function NavItem({
|
|
149
167
|
active = false,
|
|
150
168
|
iconOnly = false,
|
|
151
169
|
icon,
|
|
152
170
|
asChild = false,
|
|
171
|
+
selected = false,
|
|
172
|
+
indent = 0,
|
|
173
|
+
dragging = false,
|
|
174
|
+
dropTarget = false,
|
|
153
175
|
className,
|
|
176
|
+
style,
|
|
154
177
|
children,
|
|
155
178
|
...props
|
|
156
179
|
}: SidebarNavItemProps) {
|
|
@@ -160,6 +183,11 @@ export function NavItem({
|
|
|
160
183
|
type={asChild ? undefined : "button"}
|
|
161
184
|
{...props}
|
|
162
185
|
aria-current={active ? "page" : undefined}
|
|
186
|
+
data-active={active || undefined}
|
|
187
|
+
data-selected={selected || undefined}
|
|
188
|
+
data-dragging={dragging || undefined}
|
|
189
|
+
data-drop-target={dropTarget || undefined}
|
|
190
|
+
style={indent > 0 && !iconOnly ? { ...sidebarNavItemIndentStyle(indent), ...style } : style}
|
|
163
191
|
className={cn(sidebarNavItemClass({ active, iconOnly }), className)}
|
|
164
192
|
>
|
|
165
193
|
{icon ? <Slot className={sidebarNavIconClass(active)}>{icon}</Slot> : null}
|
|
@@ -167,3 +195,36 @@ export function NavItem({
|
|
|
167
195
|
</Row>
|
|
168
196
|
);
|
|
169
197
|
}
|
|
198
|
+
|
|
199
|
+
export type SidebarNavItemPartProps = ComponentPropsWithoutRef<"span"> & {
|
|
200
|
+
/** Merge the part classes onto the single child element instead of a `<span>`. */
|
|
201
|
+
asChild?: boolean;
|
|
202
|
+
};
|
|
203
|
+
|
|
204
|
+
function NavItemPart({ partClass, asChild = false, className, ...props }: SidebarNavItemPartProps & { partClass: string }) {
|
|
205
|
+
const Part = asChild ? Slot : "span";
|
|
206
|
+
return <Part {...props} className={cn(partClass, className)} />;
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
/** Leading slot of a nav row: checkbox, icon, avatar or status dot (`sidebarNavItemLeadingClass`). */
|
|
210
|
+
export function NavItemLeading(props: SidebarNavItemPartProps) {
|
|
211
|
+
return <NavItemPart {...props} partClass={sidebarNavItemLeadingClass} />;
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
/** Truncated label of a nav row (`sidebarNavItemLabelClass`). `asChild` on a rename input keeps the layout. */
|
|
215
|
+
export function NavItemLabel(props: SidebarNavItemPartProps) {
|
|
216
|
+
return <NavItemPart {...props} partClass={sidebarNavItemLabelClass} />;
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
/** Always-visible trailing content of a nav row: counts, badges, spinners (`sidebarNavItemTrailingClass`). */
|
|
220
|
+
export function NavItemTrailing(props: SidebarNavItemPartProps) {
|
|
221
|
+
return <NavItemPart {...props} partClass={sidebarNavItemTrailingClass} />;
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
/**
|
|
225
|
+
* Hover-revealed actions of a nav row, such as a `...` menu (`sidebarNavItemActionsClass`).
|
|
226
|
+
* Adds no handlers: stop propagation (and prevent default inside a link) on the button.
|
|
227
|
+
*/
|
|
228
|
+
export function NavItemActions(props: SidebarNavItemPartProps) {
|
|
229
|
+
return <NavItemPart {...props} partClass={sidebarNavItemActionsClass} />;
|
|
230
|
+
}
|
|
@@ -28,13 +28,14 @@ export const sidebarSectionLabelClass =
|
|
|
28
28
|
"sidebar-section-label px-4 py-1 text-[11px] leading-4 font-medium tracking-[-0.01em]";
|
|
29
29
|
|
|
30
30
|
/**
|
|
31
|
-
* Nav row state: idle rows are `foreground/80` and get the
|
|
32
|
-
* the active row is `font-medium text-foreground` on a static
|
|
31
|
+
* Nav row state: idle rows are `foreground/80` and get the `sidebar-accent`
|
|
32
|
+
* fill on hover; the active row is `font-medium text-foreground` on a static
|
|
33
|
+
* fill.
|
|
33
34
|
*/
|
|
34
35
|
export function sidebarNavLinkTextClass(isActive: boolean): string {
|
|
35
36
|
return isActive
|
|
36
|
-
? "bg-
|
|
37
|
-
: "font-normal text-foreground/80 hover:bg-
|
|
37
|
+
? "bg-sidebar-accent font-medium text-foreground"
|
|
38
|
+
: "font-normal text-foreground/80 hover:bg-sidebar-accent hover:text-foreground";
|
|
38
39
|
}
|
|
39
40
|
|
|
40
41
|
/**
|
|
@@ -53,13 +54,73 @@ export type SidebarNavItemClassOptions = {
|
|
|
53
54
|
active?: boolean;
|
|
54
55
|
/** Collapsed panel: centred icon, no horizontal padding. */
|
|
55
56
|
iconOnly?: boolean;
|
|
57
|
+
/** Picked (for example in a multi-select list): the active fill, without `font-medium`. Same as `data-selected="true"`. */
|
|
58
|
+
selected?: boolean;
|
|
59
|
+
/** Row being dragged: `opacity-40 cursor-grabbing`. Same as `data-dragging="true"`. */
|
|
60
|
+
dragging?: boolean;
|
|
61
|
+
/** Row under a drag: fill plus an inset `ring-focus` ring. Same as `data-drop-target="true"`. */
|
|
62
|
+
dropTarget?: boolean;
|
|
56
63
|
};
|
|
57
64
|
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
65
|
+
// Row states an app can also set as data attributes on the row itself.
|
|
66
|
+
const sidebarNavItemDataStateClass =
|
|
67
|
+
"data-[selected=true]:bg-sidebar-accent data-[selected=true]:text-foreground data-[dragging=true]:cursor-grabbing data-[dragging=true]:opacity-40 data-[drop-target=true]:bg-sidebar-accent data-[drop-target=true]:text-foreground data-[drop-target=true]:ring-2 data-[drop-target=true]:ring-inset data-[drop-target=true]:ring-focus";
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Whole panel nav row: `sidebarNavRowClass` plus `sidebarNavLinkTextClass`,
|
|
71
|
+
* plus `data-selected`, `data-dragging` and `data-drop-target` (`="true"`)
|
|
72
|
+
* styles. The `selected`, `dragging` and `dropTarget` options apply the same
|
|
73
|
+
* styles without the attributes.
|
|
74
|
+
*/
|
|
75
|
+
export function sidebarNavItemClass({
|
|
76
|
+
active = false,
|
|
77
|
+
iconOnly = false,
|
|
78
|
+
selected = false,
|
|
79
|
+
dragging = false,
|
|
80
|
+
dropTarget = false,
|
|
81
|
+
}: SidebarNavItemClassOptions = {}): string {
|
|
82
|
+
return cn(
|
|
83
|
+
sidebarNavRowClass(iconOnly),
|
|
84
|
+
sidebarNavLinkTextClass(active),
|
|
85
|
+
sidebarNavItemDataStateClass,
|
|
86
|
+
selected && "bg-sidebar-accent text-foreground",
|
|
87
|
+
dragging && "cursor-grabbing opacity-40",
|
|
88
|
+
dropTarget && "bg-sidebar-accent text-foreground ring-2 ring-inset ring-focus",
|
|
89
|
+
);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* Nested row padding: each `indent` level adds 12px to the row's 16px
|
|
94
|
+
* (`px-4`) left padding. Put it on the row's `style`.
|
|
95
|
+
*/
|
|
96
|
+
export function sidebarNavItemIndentStyle(indent: number): { paddingLeft: string } {
|
|
97
|
+
return { paddingLeft: `calc(1rem + ${indent * 12}px)` };
|
|
61
98
|
}
|
|
62
99
|
|
|
100
|
+
/** Row part: leading checkbox, icon, avatar or status dot. */
|
|
101
|
+
export const sidebarNavItemLeadingClass = "flex shrink-0 items-center";
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* Row part: the label, which takes the free width and truncates. For two
|
|
105
|
+
* lines, put `block truncate` spans inside (subtitle: `sidebarNavItemSubtitleClass`).
|
|
106
|
+
*/
|
|
107
|
+
export const sidebarNavItemLabelClass = "min-w-0 flex-1 truncate";
|
|
108
|
+
|
|
109
|
+
/** Second, muted line inside the label. */
|
|
110
|
+
export const sidebarNavItemSubtitleClass = "block truncate text-xs text-muted-foreground";
|
|
111
|
+
|
|
112
|
+
/** Row part: always-visible trailing content (counts, badges, spinners). */
|
|
113
|
+
export const sidebarNavItemTrailingClass = "ml-auto flex shrink-0 items-center gap-1.5 text-xs text-muted-foreground";
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* Row part: actions such as a `...` menu button. In the row flow at the end,
|
|
117
|
+
* 24px tall without growing the row. Hidden until the row is hovered or has
|
|
118
|
+
* focus, or a menu trigger inside it (or the part itself) is
|
|
119
|
+
* `data-state="open"`.
|
|
120
|
+
*/
|
|
121
|
+
export const sidebarNavItemActionsClass =
|
|
122
|
+
"-my-1 ml-auto flex h-6 shrink-0 items-center opacity-0 transition-opacity duration-75 group-hover:opacity-100 group-focus-within:opacity-100 has-[[data-state=open]]:opacity-100 data-[state=open]:opacity-100";
|
|
123
|
+
|
|
63
124
|
/** Nav row icon (put it on the `<svg>`): 19px, muted until active. */
|
|
64
125
|
export function sidebarNavIconClass(active: boolean): string {
|
|
65
126
|
return cn("size-[19px] shrink-0", active ? "text-foreground" : "text-muted-foreground");
|
package/shell/src/index.ts
CHANGED
|
@@ -46,7 +46,13 @@ export {
|
|
|
46
46
|
railTileClass,
|
|
47
47
|
railTileStateClass,
|
|
48
48
|
sidebarNavIconClass,
|
|
49
|
+
sidebarNavItemActionsClass,
|
|
49
50
|
sidebarNavItemClass,
|
|
51
|
+
sidebarNavItemIndentStyle,
|
|
52
|
+
sidebarNavItemLabelClass,
|
|
53
|
+
sidebarNavItemLeadingClass,
|
|
54
|
+
sidebarNavItemSubtitleClass,
|
|
55
|
+
sidebarNavItemTrailingClass,
|
|
50
56
|
sidebarNavLinkTextClass,
|
|
51
57
|
sidebarNavRowClass,
|
|
52
58
|
sidebarSectionLabelClass,
|
package/src/index.ts
CHANGED
|
@@ -159,7 +159,13 @@ export {
|
|
|
159
159
|
railTileClass,
|
|
160
160
|
railTileStateClass,
|
|
161
161
|
sidebarNavIconClass,
|
|
162
|
+
sidebarNavItemActionsClass,
|
|
162
163
|
sidebarNavItemClass,
|
|
164
|
+
sidebarNavItemIndentStyle,
|
|
165
|
+
sidebarNavItemLabelClass,
|
|
166
|
+
sidebarNavItemLeadingClass,
|
|
167
|
+
sidebarNavItemSubtitleClass,
|
|
168
|
+
sidebarNavItemTrailingClass,
|
|
163
169
|
sidebarNavLinkTextClass,
|
|
164
170
|
sidebarNavRowClass,
|
|
165
171
|
sidebarSectionLabelClass,
|
package/tokens/README.md
CHANGED
|
@@ -6,7 +6,7 @@ Design tokens and shared Tailwind v4 CSS for the vvedantb web apps. The CSS and
|
|
|
6
6
|
|
|
7
7
|
| Export | File | What it is |
|
|
8
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. 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. |
|
|
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
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
11
|
| `@vvedantb/ui/tokens/css/base.css` | `src/css/base.css` | `html` touch/accent, `::selection`, control transitions, pointer cursor, range accent (`@layer base`). |
|
|
12
12
|
| `@vvedantb/ui/tokens/css/dialog.css` | `src/css/dialog.css` | Unlayered `max-width: none` for `@vvedantb/ui` compact (bottom-sheet) dialogs. |
|
|
@@ -23,6 +23,9 @@
|
|
|
23
23
|
* --accent, --accent-foreground, --destructive, --destructive-foreground,
|
|
24
24
|
* --border, --input, --ring and --radius (all colours as "R G B").
|
|
25
25
|
*
|
|
26
|
+
* `--color-sidebar-accent` (sidebar nav row fill) reads the app's
|
|
27
|
+
* `--sidebar-accent` when it is defined, else `--secondary`.
|
|
28
|
+
*
|
|
26
29
|
* `--color-card` and `--color-muted` are references to `--card` and `--muted`.
|
|
27
30
|
* `SonnerToaster sonnerVars` reads them, along with `--color-border` and
|
|
28
31
|
* `--color-foreground`. An app that already maps those names keeps its own
|
|
@@ -44,6 +47,7 @@
|
|
|
44
47
|
--color-surface-secondary-foreground: rgb(var(--foreground));
|
|
45
48
|
--color-surface-tertiary: rgb(var(--secondary));
|
|
46
49
|
--color-surface-tertiary-foreground: rgb(var(--secondary-foreground));
|
|
50
|
+
--color-sidebar-accent: rgb(var(--sidebar-accent, var(--secondary)));
|
|
47
51
|
--color-overlay: rgb(var(--popover));
|
|
48
52
|
--color-overlay-foreground: rgb(var(--popover-foreground));
|
|
49
53
|
--color-field-background: rgb(var(--card));
|
package/tokens/src/tokens.css
CHANGED
|
@@ -56,6 +56,7 @@
|
|
|
56
56
|
--color-surface-tertiary: var(--surface-tertiary);
|
|
57
57
|
--color-surface-tertiary-foreground: var(--surface-tertiary-foreground);
|
|
58
58
|
--color-surface-card: var(--surface-card);
|
|
59
|
+
--color-sidebar-accent: var(--sidebar-accent);
|
|
59
60
|
--color-warning: var(--warning);
|
|
60
61
|
--color-warning-foreground: var(--warning-foreground);
|
|
61
62
|
|
|
@@ -155,6 +156,8 @@
|
|
|
155
156
|
--surface-tertiary: oklch(93.73% 0 0);
|
|
156
157
|
--surface-tertiary-foreground: oklch(21.03% 0 0);
|
|
157
158
|
--surface-card: oklch(98% 0 0);
|
|
159
|
+
/* Sidebar nav row hover, active and selected fill. */
|
|
160
|
+
--sidebar-accent: var(--surface-tertiary);
|
|
158
161
|
--warning: oklch(78.19% 0.159 72.33);
|
|
159
162
|
--warning-foreground: oklch(21.03% 0.0059 72.33);
|
|
160
163
|
--radius: 1rem;
|
|
@@ -202,6 +205,8 @@
|
|
|
202
205
|
--surface-tertiary: oklch(27.21% 0.0023 0);
|
|
203
206
|
--surface-tertiary-foreground: oklch(99.11% 0 0);
|
|
204
207
|
--surface-card: oklch(25.7% 0.0023 0);
|
|
208
|
+
/* sRGB 28 28 28: a step darker than --surface-tertiary. */
|
|
209
|
+
--sidebar-accent: oklch(22.64% 0 0);
|
|
205
210
|
--warning: oklch(82.03% 0.1392 76.34);
|
|
206
211
|
--warning-foreground: oklch(21.03% 0.0059 76.34);
|
|
207
212
|
--radius: 1rem;
|