@cbrl/design 0.5.0 → 0.6.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +165 -0
- package/dist/components/avatar.d.ts +10 -1
- package/dist/components/avatar.js +13 -5
- package/dist/components/badge.d.ts +1 -1
- package/dist/components/badge.js +3 -0
- package/dist/components/button-group.d.ts +12 -0
- package/dist/components/button-group.js +40 -0
- package/dist/components/field.d.ts +1 -1
- package/dist/components/settings-dialog.d.ts +36 -0
- package/dist/components/settings-dialog.js +81 -0
- package/dist/components/status-dot.d.ts +17 -0
- package/dist/components/status-dot.js +46 -0
- package/dist/components/tabs.d.ts +11 -1
- package/dist/components/tabs.js +31 -5
- package/dist/components/typography.d.ts +1 -1
- package/dist/hooks/use-element-size.d.ts +13 -0
- package/dist/hooks/use-element-size.js +30 -0
- package/dist/hooks/use-hash-section.d.ts +17 -0
- package/dist/hooks/use-hash-section.js +34 -0
- package/dist/hooks/use-scroll-strip.d.ts +17 -0
- package/dist/hooks/use-scroll-strip.js +68 -0
- package/dist/index.d.ts +7 -1
- package/dist/index.js +7 -1
- package/dist/lib/scroll-target.js +26 -0
- package/dist/tokens.css +20 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -39,6 +39,24 @@ import { ThemeProvider, Toaster } from '@cbrl/design'
|
|
|
39
39
|
</ThemeProvider>
|
|
40
40
|
```
|
|
41
41
|
|
|
42
|
+
### Surfaces and elevation
|
|
43
|
+
|
|
44
|
+
Light mode paints the page (`--background`) and the sidebar a soft gray
|
|
45
|
+
(`oklch(0.985 0 0)`, a step lighter than the `0.97` hover fills `--accent` and
|
|
46
|
+
`--sidebar-accent`, so hover stays visible), and cards and popovers white, so
|
|
47
|
+
content surfaces stand out. In dark mode the
|
|
48
|
+
popover is a step lighter than the card (shadows barely show on dark). Use
|
|
49
|
+
`shadow-popup` for floating surfaces that sit over content (event popups,
|
|
50
|
+
detail cards):
|
|
51
|
+
|
|
52
|
+
```tsx
|
|
53
|
+
<div className="bg-popover text-popover-foreground shadow-popup rounded-xl">…</div>
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
Prefer `bg-card` (not `bg-background`) for anything that must match the card it
|
|
57
|
+
sits on. To keep an all-white page, redefine `--background` and `--sidebar` in
|
|
58
|
+
your `:root`.
|
|
59
|
+
|
|
42
60
|
## Usage
|
|
43
61
|
|
|
44
62
|
```tsx
|
|
@@ -62,6 +80,80 @@ or `'?'`.
|
|
|
62
80
|
<AvatarFallback>{initials(user.name, user.email)}</AvatarFallback>
|
|
63
81
|
```
|
|
64
82
|
|
|
83
|
+
### Avatar group
|
|
84
|
+
|
|
85
|
+
`AvatarGroup` overlaps its avatars. Pass `max` to show the first N and collapse
|
|
86
|
+
the rest into a "+K" `AvatarGroupCount` (accessible name `"K more"`, override
|
|
87
|
+
with `overflowLabel`). Without `max` it renders every child, as before.
|
|
88
|
+
|
|
89
|
+
```tsx
|
|
90
|
+
<AvatarGroup max={3} overflowLabel={(n) => `mais ${n} pessoas`}>
|
|
91
|
+
{members.map((m) => (
|
|
92
|
+
<Avatar key={m.id}>
|
|
93
|
+
<AvatarImage src={m.avatarUrl} alt={m.name} />
|
|
94
|
+
<AvatarFallback>{initials(m.name)}</AvatarFallback>
|
|
95
|
+
</Avatar>
|
|
96
|
+
))}
|
|
97
|
+
</AvatarGroup>
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
### Status
|
|
101
|
+
|
|
102
|
+
`StatusDot` is a small status indicator: `tone` (`success`, `warning`,
|
|
103
|
+
`destructive`, `info`, `muted`), `size` (`sm`, `default`, `lg`) and an optional
|
|
104
|
+
`pulse` ring (off under reduced motion). Give it a `label` when nothing next to
|
|
105
|
+
it says the status; without one it is decorative (`aria-hidden`).
|
|
106
|
+
|
|
107
|
+
```tsx
|
|
108
|
+
<span className="flex items-center gap-2">
|
|
109
|
+
<StatusDot tone="success" pulse /> Sincronizado
|
|
110
|
+
</span>
|
|
111
|
+
<StatusDot tone="destructive" label="Falha na sincronização" />
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
`Badge` has the same tones as tinted variants for status text:
|
|
115
|
+
`<Badge variant="success">Ativo</Badge>` (`warning`, `info`, and the existing
|
|
116
|
+
`destructive`, `secondary` for neutral).
|
|
117
|
+
|
|
118
|
+
### Button group
|
|
119
|
+
|
|
120
|
+
`ButtonGroup` joins related buttons into one control (shadcn's button-group):
|
|
121
|
+
inner borders and radii collapse, the focused button rises above its
|
|
122
|
+
neighbors, and `orientation="vertical"` stacks them. `ButtonGroupSeparator`
|
|
123
|
+
draws a divider (useful between same-variant buttons) and `ButtonGroupText`
|
|
124
|
+
holds a label or addon. Nest groups to space them (`gap-2`).
|
|
125
|
+
|
|
126
|
+
Split button (main action + menu of related actions):
|
|
127
|
+
|
|
128
|
+
```tsx
|
|
129
|
+
import {
|
|
130
|
+
Button,
|
|
131
|
+
ButtonGroup,
|
|
132
|
+
ButtonGroupSeparator,
|
|
133
|
+
DropdownMenu,
|
|
134
|
+
DropdownMenuContent,
|
|
135
|
+
DropdownMenuItem,
|
|
136
|
+
DropdownMenuTrigger,
|
|
137
|
+
} from '@cbrl/design'
|
|
138
|
+
import { ChevronDown } from 'lucide-react'
|
|
139
|
+
|
|
140
|
+
;<ButtonGroup aria-label="Salvar">
|
|
141
|
+
<Button onClick={save}>Salvar</Button>
|
|
142
|
+
<ButtonGroupSeparator />
|
|
143
|
+
<DropdownMenu>
|
|
144
|
+
<DropdownMenuTrigger asChild>
|
|
145
|
+
<Button size="icon" aria-label="Mais opções de salvar">
|
|
146
|
+
<ChevronDown />
|
|
147
|
+
</Button>
|
|
148
|
+
</DropdownMenuTrigger>
|
|
149
|
+
<DropdownMenuContent align="end">
|
|
150
|
+
<DropdownMenuItem onSelect={saveAsDraft}>Salvar como rascunho</DropdownMenuItem>
|
|
151
|
+
<DropdownMenuItem onSelect={saveAndNew}>Salvar e criar outro</DropdownMenuItem>
|
|
152
|
+
</DropdownMenuContent>
|
|
153
|
+
</DropdownMenu>
|
|
154
|
+
</ButtonGroup>
|
|
155
|
+
```
|
|
156
|
+
|
|
65
157
|
### App shell
|
|
66
158
|
|
|
67
159
|
`AppShell` renders the whole authenticated layout (collapsible sidebar with brand,
|
|
@@ -105,6 +197,79 @@ The shell handles the `<nav aria-label>` landmark, the active item, closing the
|
|
|
105
197
|
mobile drawer and tooltips when collapsed. The sidebar primitives (`Sidebar`,
|
|
106
198
|
`SidebarProvider`, `SidebarMenu*`, `useSidebar`, …) are exported for custom shells.
|
|
107
199
|
|
|
200
|
+
### Tabs and scrolling strips
|
|
201
|
+
|
|
202
|
+
`TabsList` (both variants) never hides the active tab: when the tabs don't
|
|
203
|
+
fit it scrolls sideways without a scrollbar, fades only the edges that hide
|
|
204
|
+
tabs (`data-fade-start` / `data-fade-end`) and brings the active tab into view
|
|
205
|
+
on mount, resize and change (first tab to the start, last to the end, others
|
|
206
|
+
centered; instant under `prefers-reduced-motion`). Opt out with
|
|
207
|
+
`scrollable={false}`.
|
|
208
|
+
|
|
209
|
+
```tsx
|
|
210
|
+
<Tabs defaultValue="all">
|
|
211
|
+
<TabsList variant="line">
|
|
212
|
+
<TabsTrigger value="all">All</TabsTrigger>
|
|
213
|
+
<TabsTrigger value="overdue">
|
|
214
|
+
Overdue <TabsCount tone="destructive">2</TabsCount>
|
|
215
|
+
</TabsTrigger>
|
|
216
|
+
</TabsList>
|
|
217
|
+
</Tabs>
|
|
218
|
+
```
|
|
219
|
+
|
|
220
|
+
The same behavior for any horizontal strip (a nav row with `aria-current`):
|
|
221
|
+
`useScrollStrip(ref, '[aria-current="page"]')` returns `{ start, end }` (which
|
|
222
|
+
edges hide content). `useElementSize()` returns a React 19 cleanup ref and the
|
|
223
|
+
element's `{ width, height }`, following resizes:
|
|
224
|
+
|
|
225
|
+
```tsx
|
|
226
|
+
const [ref, { width }] = useElementSize()
|
|
227
|
+
return <div ref={ref}>{width > 480 ? <Wide /> : <Narrow />}</div>
|
|
228
|
+
```
|
|
229
|
+
|
|
230
|
+
### Settings dialog
|
|
231
|
+
|
|
232
|
+
`SettingsDialog` is the settings-modal shell: a section nav (a column from
|
|
233
|
+
`sm`, a sideways-scrolling strip on phones that keeps the active section in
|
|
234
|
+
view), a header with the active section's label and description, and a
|
|
235
|
+
scrolling content area. The app decides which sections a user sees and loads
|
|
236
|
+
each section's data; the dialog only renders `children` for the active one.
|
|
237
|
+
`useHashSection(prefix, keys?)` routes it through `#<prefix>/<section>`
|
|
238
|
+
(`hashchange` in, `history.replaceState` on switch and close):
|
|
239
|
+
|
|
240
|
+
```tsx
|
|
241
|
+
'use client'
|
|
242
|
+
|
|
243
|
+
import { SettingsDialog, useHashSection, type SettingsDialogSection } from '@cbrl/design'
|
|
244
|
+
import { CreditCard, User } from 'lucide-react'
|
|
245
|
+
|
|
246
|
+
type Key = 'profile' | 'billing'
|
|
247
|
+
const SECTIONS: readonly SettingsDialogSection<Key>[] = [
|
|
248
|
+
{ key: 'profile', label: 'Perfil', icon: User, description: 'Seu nome e foto.' },
|
|
249
|
+
{ key: 'billing', label: 'Cobrança', icon: CreditCard },
|
|
250
|
+
]
|
|
251
|
+
|
|
252
|
+
export function SettingsModal() {
|
|
253
|
+
const { section, open, close } = useHashSection<Key>('settings', ['profile', 'billing'])
|
|
254
|
+
return (
|
|
255
|
+
<SettingsDialog
|
|
256
|
+
open={section !== null}
|
|
257
|
+
onOpenChange={(next) => !next && close()}
|
|
258
|
+
sections={SECTIONS}
|
|
259
|
+
value={section ?? 'profile'}
|
|
260
|
+
onValueChange={open}
|
|
261
|
+
navLabel="Seções de configuração"
|
|
262
|
+
>
|
|
263
|
+
{section === 'billing' ? <BillingPanel /> : <ProfilePanel />}
|
|
264
|
+
</SettingsDialog>
|
|
265
|
+
)
|
|
266
|
+
}
|
|
267
|
+
// Anywhere: <a href="#settings/billing">Cobrança</a>
|
|
268
|
+
```
|
|
269
|
+
|
|
270
|
+
Uncontrolled use: `defaultOpen`/`defaultValue`. Slots: `settings-dialog`,
|
|
271
|
+
`settings-dialog-nav`, `settings-dialog-content`.
|
|
272
|
+
|
|
108
273
|
## Compatibility contract
|
|
109
274
|
|
|
110
275
|
Breaking changes ship only as major versions (minor while `0.x`). The public
|
|
@@ -6,6 +6,15 @@ declare function Avatar({ className, size, ...props }: React.ComponentProps<type
|
|
|
6
6
|
declare function AvatarImage({ className, ...props }: React.ComponentProps<typeof Avatar$1.Image>): React.JSX.Element;
|
|
7
7
|
declare function AvatarFallback({ className, ...props }: React.ComponentProps<typeof Avatar$1.Fallback>): React.JSX.Element;
|
|
8
8
|
declare function AvatarBadge({ className, ...props }: React.ComponentProps<'span'>): React.JSX.Element;
|
|
9
|
-
|
|
9
|
+
type AvatarGroupProps = React.ComponentProps<'div'> & {
|
|
10
|
+
/**
|
|
11
|
+
* Show at most this many children; the rest collapse into an
|
|
12
|
+
* `AvatarGroupCount` reading "+K". Omit to render every child.
|
|
13
|
+
*/
|
|
14
|
+
max?: number;
|
|
15
|
+
/** Accessible name of the "+K" count. Defaults to `"K more"`. */
|
|
16
|
+
overflowLabel?: (hidden: number) => string;
|
|
17
|
+
};
|
|
18
|
+
declare function AvatarGroup({ className, max, overflowLabel, children, ...props }: AvatarGroupProps): React.JSX.Element;
|
|
10
19
|
declare function AvatarGroupCount({ className, ...props }: React.ComponentProps<'div'>): React.JSX.Element;
|
|
11
20
|
export { Avatar, AvatarBadge, AvatarFallback, AvatarGroup, AvatarGroupCount, AvatarImage };
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { cn } from "../lib/cn.js";
|
|
3
|
-
import "react";
|
|
3
|
+
import * as React from "react";
|
|
4
4
|
import { Avatar as Avatar$1 } from "radix-ui";
|
|
5
|
-
import { jsx } from "react/jsx-runtime";
|
|
5
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
6
6
|
// src/components/avatar.tsx
|
|
7
7
|
function Avatar({ className, size = "default", ...props }) {
|
|
8
8
|
return /* @__PURE__ */ jsx(Avatar$1.Root, {
|
|
@@ -33,11 +33,19 @@ function AvatarBadge({ className, ...props }) {
|
|
|
33
33
|
...props
|
|
34
34
|
});
|
|
35
35
|
}
|
|
36
|
-
function AvatarGroup({ className, ...props }) {
|
|
37
|
-
|
|
36
|
+
function AvatarGroup({ className, max, overflowLabel, children, ...props }) {
|
|
37
|
+
const items = React.Children.toArray(children);
|
|
38
|
+
const limit = max === void 0 ? items.length : Math.max(0, Math.floor(max));
|
|
39
|
+
const hidden = items.length - limit;
|
|
40
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
38
41
|
"data-slot": "avatar-group",
|
|
39
42
|
className: cn("group/avatar-group *:data-[slot=avatar]:ring-background flex -space-x-2 *:data-[slot=avatar]:ring-2", className),
|
|
40
|
-
...props
|
|
43
|
+
...props,
|
|
44
|
+
children: [hidden > 0 ? items.slice(0, limit) : children, hidden > 0 ? /* @__PURE__ */ jsxs(AvatarGroupCount, {
|
|
45
|
+
role: "img",
|
|
46
|
+
"aria-label": overflowLabel?.(hidden) ?? `${hidden} more`,
|
|
47
|
+
children: ["+", hidden]
|
|
48
|
+
}) : null]
|
|
41
49
|
});
|
|
42
50
|
}
|
|
43
51
|
function AvatarGroupCount({ className, ...props }) {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import * as React from "react";
|
|
2
2
|
import { VariantProps } from "class-variance-authority";
|
|
3
3
|
declare const badgeVariants: (props?: ({
|
|
4
|
-
variant?: "default" | "secondary" | "destructive" | "outline" | "ghost" | "link" | null | undefined;
|
|
4
|
+
variant?: "default" | "secondary" | "destructive" | "success" | "warning" | "info" | "outline" | "ghost" | "link" | null | undefined;
|
|
5
5
|
} & import("class-variance-authority/types").ClassProp) | undefined) => string;
|
|
6
6
|
declare function Badge({ className, variant, asChild, ...props }: React.ComponentProps<'span'> & VariantProps<typeof badgeVariants> & {
|
|
7
7
|
asChild?: boolean;
|
package/dist/components/badge.js
CHANGED
|
@@ -9,6 +9,9 @@ const badgeVariants = cva("group/badge focus-visible:border-ring focus-visible:r
|
|
|
9
9
|
default: "bg-primary text-primary-foreground [a]:hover:bg-primary/80",
|
|
10
10
|
secondary: "bg-secondary text-secondary-foreground [a]:hover:bg-secondary/80",
|
|
11
11
|
destructive: "bg-destructive/10 text-destructive focus-visible:ring-destructive/20 dark:bg-destructive/20 dark:focus-visible:ring-destructive/40 [a]:hover:bg-destructive/20",
|
|
12
|
+
success: "bg-emerald-500/15 text-emerald-700 focus-visible:ring-emerald-500/20 dark:text-emerald-300 [a]:hover:bg-emerald-500/25",
|
|
13
|
+
warning: "bg-amber-500/15 text-amber-700 focus-visible:ring-amber-500/20 dark:text-amber-300 [a]:hover:bg-amber-500/25",
|
|
14
|
+
info: "bg-sky-500/15 text-sky-700 focus-visible:ring-sky-500/20 dark:text-sky-300 [a]:hover:bg-sky-500/25",
|
|
12
15
|
outline: "border-border text-foreground [a]:hover:bg-muted [a]:hover:text-muted-foreground",
|
|
13
16
|
ghost: "hover:bg-muted hover:text-muted-foreground dark:hover:bg-muted/50",
|
|
14
17
|
link: "text-primary underline-offset-4 hover:underline"
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { Separator } from "./separator.js";
|
|
2
|
+
import * as React from "react";
|
|
3
|
+
import { VariantProps } from "class-variance-authority";
|
|
4
|
+
declare const buttonGroupVariants: (props?: ({
|
|
5
|
+
orientation?: "horizontal" | "vertical" | null | undefined;
|
|
6
|
+
} & import("class-variance-authority/types").ClassProp) | undefined) => string;
|
|
7
|
+
declare function ButtonGroup({ className, orientation, ...props }: React.ComponentProps<'div'> & VariantProps<typeof buttonGroupVariants>): React.JSX.Element;
|
|
8
|
+
declare function ButtonGroupText({ className, asChild, ...props }: React.ComponentProps<'div'> & {
|
|
9
|
+
asChild?: boolean;
|
|
10
|
+
}): React.JSX.Element;
|
|
11
|
+
declare function ButtonGroupSeparator({ className, orientation, ...props }: React.ComponentProps<typeof Separator>): React.JSX.Element;
|
|
12
|
+
export { ButtonGroup, ButtonGroupSeparator, ButtonGroupText, buttonGroupVariants };
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { cn } from "../lib/cn.js";
|
|
2
|
+
import { Separator as Separator$1 } from "./separator.js";
|
|
3
|
+
import "react";
|
|
4
|
+
import { cva } from "class-variance-authority";
|
|
5
|
+
import { Slot } from "radix-ui";
|
|
6
|
+
import { jsx } from "react/jsx-runtime";
|
|
7
|
+
// src/components/button-group.tsx
|
|
8
|
+
const buttonGroupVariants = cva("group/button-group flex w-fit items-stretch *:focus-visible:relative *:focus-visible:z-10 has-[>[data-slot=button-group]]:gap-2 has-[select[aria-hidden=true]:last-child]:[&>[data-slot=select-trigger]:last-of-type]:rounded-r-lg [&>[data-slot=select-trigger]:not([class*='w-'])]:w-fit [&>input]:flex-1", {
|
|
9
|
+
variants: { orientation: {
|
|
10
|
+
horizontal: "[&>*:not(:first-child)]:rounded-l-none [&>*:not(:first-child)]:border-l-0 [&>*:not(:last-child)]:rounded-r-none [&>[data-slot]:not(:has(~[data-slot]))]:rounded-r-lg!",
|
|
11
|
+
vertical: "flex-col [&>*:not(:first-child)]:rounded-t-none [&>*:not(:first-child)]:border-t-0 [&>*:not(:last-child)]:rounded-b-none [&>[data-slot]:not(:has(~[data-slot]))]:rounded-b-lg!"
|
|
12
|
+
} },
|
|
13
|
+
defaultVariants: { orientation: "horizontal" }
|
|
14
|
+
});
|
|
15
|
+
function ButtonGroup({ className, orientation = "horizontal", ...props }) {
|
|
16
|
+
return /* @__PURE__ */ jsx("div", {
|
|
17
|
+
role: "group",
|
|
18
|
+
"data-slot": "button-group",
|
|
19
|
+
"data-orientation": orientation,
|
|
20
|
+
className: cn(buttonGroupVariants({ orientation }), className),
|
|
21
|
+
...props
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
function ButtonGroupText({ className, asChild = false, ...props }) {
|
|
25
|
+
const Comp = asChild ? Slot.Root : "div";
|
|
26
|
+
return /* @__PURE__ */ jsx(Comp, {
|
|
27
|
+
"data-slot": "button-group-text",
|
|
28
|
+
className: cn("flex items-center gap-2 rounded-lg border bg-muted px-2.5 text-sm font-medium [&_svg]:pointer-events-none [&_svg:not([class*='size-'])]:size-4", className),
|
|
29
|
+
...props
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
function ButtonGroupSeparator({ className, orientation = "vertical", ...props }) {
|
|
33
|
+
return /* @__PURE__ */ jsx(Separator$1, {
|
|
34
|
+
"data-slot": "button-group-separator",
|
|
35
|
+
orientation,
|
|
36
|
+
className: cn("relative self-stretch bg-input data-horizontal:mx-px data-horizontal:w-auto data-vertical:my-px data-vertical:h-auto", className),
|
|
37
|
+
...props
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
export { ButtonGroup, ButtonGroupSeparator, ButtonGroupText, buttonGroupVariants };
|
|
@@ -7,7 +7,7 @@ declare function FieldLegend({ className, variant, ...props }: React.ComponentPr
|
|
|
7
7
|
}): React.JSX.Element;
|
|
8
8
|
declare function FieldGroup({ className, ...props }: React.ComponentProps<'div'>): React.JSX.Element;
|
|
9
9
|
declare const fieldVariants: (props?: ({
|
|
10
|
-
orientation?: "
|
|
10
|
+
orientation?: "horizontal" | "vertical" | "responsive" | null | undefined;
|
|
11
11
|
} & import("class-variance-authority/types").ClassProp) | undefined) => string;
|
|
12
12
|
declare function Field({ className, orientation, ...props }: React.ComponentProps<'div'> & VariantProps<typeof fieldVariants>): React.JSX.Element;
|
|
13
13
|
declare function FieldContent({ className, ...props }: React.ComponentProps<'div'>): React.JSX.Element;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
export type SettingsDialogSection<K extends string = string> = {
|
|
3
|
+
key: K;
|
|
4
|
+
label: string;
|
|
5
|
+
/** Decorative icon shown before the label (e.g. a lucide icon). */
|
|
6
|
+
icon?: React.ComponentType<{
|
|
7
|
+
className?: string;
|
|
8
|
+
}>;
|
|
9
|
+
/** Shown under the title in the header while this section is active. */
|
|
10
|
+
description?: React.ReactNode;
|
|
11
|
+
};
|
|
12
|
+
export type SettingsDialogProps<K extends string = string> = {
|
|
13
|
+
open?: boolean;
|
|
14
|
+
defaultOpen?: boolean;
|
|
15
|
+
onOpenChange?: (open: boolean) => void;
|
|
16
|
+
sections: readonly SettingsDialogSection<K>[];
|
|
17
|
+
/** Active section (controlled). Pair with `onValueChange`. */
|
|
18
|
+
value?: K;
|
|
19
|
+
/** Initial section when uncontrolled. Defaults to the first section. */
|
|
20
|
+
defaultValue?: K;
|
|
21
|
+
onValueChange?: (key: K) => void;
|
|
22
|
+
/** Accessible name of the section nav. */
|
|
23
|
+
navLabel?: string;
|
|
24
|
+
/** Overrides the header title (defaults to the active section's label). */
|
|
25
|
+
title?: React.ReactNode;
|
|
26
|
+
/** Content of the active section; apps switch on the value. */
|
|
27
|
+
children?: React.ReactNode;
|
|
28
|
+
className?: string;
|
|
29
|
+
};
|
|
30
|
+
/**
|
|
31
|
+
* Settings modal shell: section nav (a column from `sm`, a sideways-scrolling
|
|
32
|
+
* strip on phones that keeps the active section in view), a header with the
|
|
33
|
+
* active section's label/description, and a scrolling content area. Which
|
|
34
|
+
* sections a user may see and how each loads its data stay in the app.
|
|
35
|
+
*/
|
|
36
|
+
export declare function SettingsDialog<K extends string>({ open, defaultOpen, onOpenChange, sections, value, defaultValue, onValueChange, navLabel, title, children, className }: SettingsDialogProps<K>): React.JSX.Element;
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { useScrollStrip } from "../hooks/use-scroll-strip.js";
|
|
3
|
+
import { cn } from "../lib/cn.js";
|
|
4
|
+
import { fadeMask } from "../lib/scroll-target.js";
|
|
5
|
+
import { Dialog, DialogContent, DialogDescription, DialogHeader, DialogTitle } from "./dialog.js";
|
|
6
|
+
import { ScrollArea } from "./scroll-area.js";
|
|
7
|
+
import * as React from "react";
|
|
8
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
9
|
+
// src/components/settings-dialog.tsx
|
|
10
|
+
/**
|
|
11
|
+
* Settings modal shell: section nav (a column from `sm`, a sideways-scrolling
|
|
12
|
+
* strip on phones that keeps the active section in view), a header with the
|
|
13
|
+
* active section's label/description, and a scrolling content area. Which
|
|
14
|
+
* sections a user may see and how each loads its data stay in the app.
|
|
15
|
+
*/
|
|
16
|
+
function SettingsDialog({ open, defaultOpen, onOpenChange, sections, value, defaultValue, onValueChange, navLabel = "Settings sections", title, children, className }) {
|
|
17
|
+
const [inner, setInner] = React.useState(defaultValue);
|
|
18
|
+
const current = value ?? inner ?? sections[0]?.key;
|
|
19
|
+
const active = sections.find((s) => s.key === current);
|
|
20
|
+
const select = (key) => {
|
|
21
|
+
if (value === void 0) setInner(key);
|
|
22
|
+
onValueChange?.(key);
|
|
23
|
+
};
|
|
24
|
+
return /* @__PURE__ */ jsx(Dialog, {
|
|
25
|
+
open,
|
|
26
|
+
defaultOpen,
|
|
27
|
+
onOpenChange,
|
|
28
|
+
children: /* @__PURE__ */ jsxs(DialogContent, {
|
|
29
|
+
"data-slot": "settings-dialog",
|
|
30
|
+
className: cn("grid h-[min(85vh,40rem)] max-w-3xl grid-rows-[auto_1fr] gap-0 overflow-hidden p-0 sm:max-w-3xl sm:grid-cols-[12rem_minmax(0,1fr)] sm:grid-rows-1", className),
|
|
31
|
+
onOpenAutoFocus: (event) => event.preventDefault(),
|
|
32
|
+
children: [/* @__PURE__ */ jsx(SettingsDialogNav, {
|
|
33
|
+
label: navLabel,
|
|
34
|
+
sections,
|
|
35
|
+
current,
|
|
36
|
+
onSelect: select
|
|
37
|
+
}), /* @__PURE__ */ jsxs("div", {
|
|
38
|
+
className: "flex min-h-0 min-w-0 flex-col",
|
|
39
|
+
children: [/* @__PURE__ */ jsxs(DialogHeader, {
|
|
40
|
+
className: "gap-1 border-b p-6 pr-14",
|
|
41
|
+
children: [/* @__PURE__ */ jsx(DialogTitle, { children: title ?? active?.label }), active?.description ? /* @__PURE__ */ jsx(DialogDescription, { children: active.description }) : /* @__PURE__ */ jsx(DialogDescription, {
|
|
42
|
+
className: "sr-only",
|
|
43
|
+
children: active?.label
|
|
44
|
+
})]
|
|
45
|
+
}), /* @__PURE__ */ jsx(ScrollArea, {
|
|
46
|
+
className: "min-h-0 flex-1 [&_[data-slot=scroll-area-viewport]>div]:!block",
|
|
47
|
+
children: /* @__PURE__ */ jsx("div", {
|
|
48
|
+
"data-slot": "settings-dialog-content",
|
|
49
|
+
className: "p-6",
|
|
50
|
+
children
|
|
51
|
+
})
|
|
52
|
+
})]
|
|
53
|
+
})]
|
|
54
|
+
})
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
function SettingsDialogNav({ label, sections, current, onSelect }) {
|
|
58
|
+
const ref = React.useRef(null);
|
|
59
|
+
const edges = useScrollStrip(ref, "[aria-current=\"page\"]");
|
|
60
|
+
return /* @__PURE__ */ jsx("nav", {
|
|
61
|
+
ref,
|
|
62
|
+
"aria-label": label,
|
|
63
|
+
"data-slot": "settings-dialog-nav",
|
|
64
|
+
"data-fade-start": edges.start || void 0,
|
|
65
|
+
"data-fade-end": edges.end || void 0,
|
|
66
|
+
style: { maskImage: fadeMask(edges) },
|
|
67
|
+
className: "bg-muted/40 flex [scrollbar-width:none] gap-0.5 overflow-x-auto border-b p-2 sm:flex-col sm:overflow-x-visible sm:border-r sm:border-b-0 [&::-webkit-scrollbar]:hidden",
|
|
68
|
+
children: sections.map(({ key, label: itemLabel, icon: Icon }) => /* @__PURE__ */ jsxs("button", {
|
|
69
|
+
type: "button",
|
|
70
|
+
onClick: () => onSelect(key),
|
|
71
|
+
"aria-current": key === current ? "page" : void 0,
|
|
72
|
+
className: "text-muted-foreground hover:bg-background/60 aria-[current=page]:bg-background aria-[current=page]:text-foreground focus-visible:ring-ring/50 flex shrink-0 cursor-pointer items-center gap-2 rounded-md px-3 py-2 text-left text-sm font-normal whitespace-nowrap transition-colors outline-none focus-visible:ring-3 aria-[current=page]:font-medium",
|
|
73
|
+
children: [Icon ? /* @__PURE__ */ jsx("span", {
|
|
74
|
+
"aria-hidden": true,
|
|
75
|
+
className: "flex shrink-0",
|
|
76
|
+
children: /* @__PURE__ */ jsx(Icon, { className: "size-4" })
|
|
77
|
+
}) : null, itemLabel]
|
|
78
|
+
}, key))
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
export { SettingsDialog };
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import { VariantProps } from "class-variance-authority";
|
|
3
|
+
declare const statusDotVariants: (props?: ({
|
|
4
|
+
tone?: "destructive" | "success" | "warning" | "info" | "muted" | null | undefined;
|
|
5
|
+
size?: "default" | "sm" | "lg" | null | undefined;
|
|
6
|
+
} & import("class-variance-authority/types").ClassProp) | undefined) => string;
|
|
7
|
+
type StatusDotProps = Omit<React.ComponentProps<'span'>, 'children'> & VariantProps<typeof statusDotVariants> & {
|
|
8
|
+
/**
|
|
9
|
+
* Accessible name ("Online", "Sync failed"). Without it the dot is
|
|
10
|
+
* decorative (`aria-hidden`): pair it with visible text that says the same.
|
|
11
|
+
*/
|
|
12
|
+
label?: string;
|
|
13
|
+
/** Draws attention with a ping ring; skipped under reduced motion. */
|
|
14
|
+
pulse?: boolean;
|
|
15
|
+
};
|
|
16
|
+
declare function StatusDot({ className, tone, size, label, pulse, ...props }: StatusDotProps): React.JSX.Element;
|
|
17
|
+
export { StatusDot, type StatusDotProps, statusDotVariants };
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { cn } from "../lib/cn.js";
|
|
2
|
+
import "react";
|
|
3
|
+
import { cva } from "class-variance-authority";
|
|
4
|
+
import { jsx } from "react/jsx-runtime";
|
|
5
|
+
// src/components/status-dot.tsx
|
|
6
|
+
const statusDotVariants = cva("relative inline-flex shrink-0 rounded-full", {
|
|
7
|
+
variants: {
|
|
8
|
+
tone: {
|
|
9
|
+
success: "bg-emerald-500",
|
|
10
|
+
warning: "bg-amber-500",
|
|
11
|
+
destructive: "bg-destructive",
|
|
12
|
+
info: "bg-sky-500",
|
|
13
|
+
muted: "bg-muted-foreground/50"
|
|
14
|
+
},
|
|
15
|
+
size: {
|
|
16
|
+
sm: "size-1.5",
|
|
17
|
+
default: "size-2",
|
|
18
|
+
lg: "size-2.5"
|
|
19
|
+
}
|
|
20
|
+
},
|
|
21
|
+
defaultVariants: {
|
|
22
|
+
tone: "muted",
|
|
23
|
+
size: "default"
|
|
24
|
+
}
|
|
25
|
+
});
|
|
26
|
+
function StatusDot({ className, tone = "muted", size = "default", label, pulse = false, ...props }) {
|
|
27
|
+
const a11y = label ? {
|
|
28
|
+
role: "img",
|
|
29
|
+
"aria-label": label
|
|
30
|
+
} : { "aria-hidden": true };
|
|
31
|
+
return /* @__PURE__ */ jsx("span", {
|
|
32
|
+
"data-slot": "status-dot",
|
|
33
|
+
"data-tone": tone,
|
|
34
|
+
className: cn(statusDotVariants({
|
|
35
|
+
tone,
|
|
36
|
+
size
|
|
37
|
+
}), className),
|
|
38
|
+
...a11y,
|
|
39
|
+
...props,
|
|
40
|
+
children: pulse ? /* @__PURE__ */ jsx("span", {
|
|
41
|
+
"data-slot": "status-dot-pulse",
|
|
42
|
+
className: "absolute inset-0 animate-ping rounded-full bg-inherit opacity-75 motion-reduce:hidden"
|
|
43
|
+
}) : null
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
export { StatusDot, statusDotVariants };
|
|
@@ -11,7 +11,17 @@ declare function Tabs({ className, ...props }: React.ComponentProps<typeof Tabs$
|
|
|
11
11
|
declare const tabsListVariants: (props?: ({
|
|
12
12
|
variant?: "default" | "line" | null | undefined;
|
|
13
13
|
} & import("class-variance-authority/types").ClassProp) | undefined) => string;
|
|
14
|
-
|
|
14
|
+
/**
|
|
15
|
+
* `scrollable` (default `true`): the list never hides the active tab. It
|
|
16
|
+
* scrolls sideways without a scrollbar, fades only the edges that hide tabs
|
|
17
|
+
* (`data-fade-start` / `data-fade-end`), and brings the active tab into view
|
|
18
|
+
* on mount, resize and change (first to the start, last to the end, others
|
|
19
|
+
* centered; instant under reduced motion). `scrollable={false}` restores a
|
|
20
|
+
* plain, non-scrolling list.
|
|
21
|
+
*/
|
|
22
|
+
declare function TabsList({ className, variant, scrollable, ref, style, ...props }: React.ComponentProps<typeof Tabs$1.List> & VariantProps<typeof tabsListVariants> & {
|
|
23
|
+
scrollable?: boolean;
|
|
24
|
+
}): React.JSX.Element;
|
|
15
25
|
declare function TabsTrigger({ className, ...props }: React.ComponentProps<typeof Tabs$1.Trigger>): React.JSX.Element;
|
|
16
26
|
/**
|
|
17
27
|
* Count beside a tab label (items in that tab). `tone="destructive"` flags
|
package/dist/components/tabs.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
"use client";
|
|
2
|
+
import { useScrollStrip } from "../hooks/use-scroll-strip.js";
|
|
2
3
|
import { cn } from "../lib/cn.js";
|
|
3
|
-
import "
|
|
4
|
+
import { fadeMask } from "../lib/scroll-target.js";
|
|
5
|
+
import * as React from "react";
|
|
4
6
|
import { cva } from "class-variance-authority";
|
|
5
7
|
import { Tabs as Tabs$1 } from "radix-ui";
|
|
6
8
|
import { jsx } from "react/jsx-runtime";
|
|
@@ -20,16 +22,40 @@ function Tabs({ className, ...props }) {
|
|
|
20
22
|
*/
|
|
21
23
|
const tabsListVariants = cva("group/tabs-list text-muted-foreground inline-flex items-center", {
|
|
22
24
|
variants: { variant: {
|
|
23
|
-
default: "bg-muted h-9 w-fit justify-center rounded-lg p-1",
|
|
24
|
-
line: "border-border h-9 w-full justify-start gap-4
|
|
25
|
+
default: "bg-muted h-9 w-fit max-w-full justify-center-safe rounded-lg p-1",
|
|
26
|
+
line: "border-border h-9 w-full justify-start gap-4 border-b"
|
|
25
27
|
} },
|
|
26
28
|
defaultVariants: { variant: "default" }
|
|
27
29
|
});
|
|
28
|
-
|
|
30
|
+
const ACTIVE_TAB = "[role=\"tab\"][data-state=\"active\"]";
|
|
31
|
+
/**
|
|
32
|
+
* `scrollable` (default `true`): the list never hides the active tab. It
|
|
33
|
+
* scrolls sideways without a scrollbar, fades only the edges that hide tabs
|
|
34
|
+
* (`data-fade-start` / `data-fade-end`), and brings the active tab into view
|
|
35
|
+
* on mount, resize and change (first to the start, last to the end, others
|
|
36
|
+
* centered; instant under reduced motion). `scrollable={false}` restores a
|
|
37
|
+
* plain, non-scrolling list.
|
|
38
|
+
*/
|
|
39
|
+
function TabsList({ className, variant = "default", scrollable = true, ref, style, ...props }) {
|
|
40
|
+
const stripRef = React.useRef(null);
|
|
41
|
+
const edges = useScrollStrip(stripRef, ACTIVE_TAB, scrollable);
|
|
42
|
+
const setRef = React.useCallback((node) => {
|
|
43
|
+
stripRef.current = node;
|
|
44
|
+
if (typeof ref === "function") ref(node);
|
|
45
|
+
else if (ref) ref.current = node;
|
|
46
|
+
}, [ref]);
|
|
29
47
|
return /* @__PURE__ */ jsx(Tabs$1.List, {
|
|
48
|
+
ref: setRef,
|
|
30
49
|
"data-slot": "tabs-list",
|
|
31
50
|
"data-variant": variant,
|
|
32
|
-
|
|
51
|
+
"data-scrollable": scrollable || void 0,
|
|
52
|
+
"data-fade-start": edges.start || void 0,
|
|
53
|
+
"data-fade-end": edges.end || void 0,
|
|
54
|
+
className: cn(tabsListVariants({ variant }), scrollable && "overflow-x-auto overflow-y-hidden [scrollbar-width:none] [&::-webkit-scrollbar]:hidden", className),
|
|
55
|
+
style: scrollable ? {
|
|
56
|
+
maskImage: fadeMask(edges),
|
|
57
|
+
...style
|
|
58
|
+
} : style,
|
|
33
59
|
...props
|
|
34
60
|
});
|
|
35
61
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import * as React from "react";
|
|
2
2
|
import { VariantProps } from "class-variance-authority";
|
|
3
3
|
declare const typographyVariants: (props?: ({
|
|
4
|
-
variant?: "blockquote" | "code" | "h1" | "h2" | "h3" | "h4" | "p" | "small" | "
|
|
4
|
+
variant?: "blockquote" | "code" | "h1" | "h2" | "h3" | "h4" | "p" | "small" | "muted" | "pageTitle" | "lead" | "large" | null | undefined;
|
|
5
5
|
} & import("class-variance-authority/types").ClassProp) | undefined) => string;
|
|
6
6
|
declare function Typography({ variant, as, className, ...props }: VariantProps<typeof typographyVariants> & {
|
|
7
7
|
as?: React.ElementType;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export interface ElementSize {
|
|
2
|
+
width: number;
|
|
3
|
+
height: number;
|
|
4
|
+
}
|
|
5
|
+
/**
|
|
6
|
+
* Measures an element's content box and follows it on resize (`{0, 0}` until
|
|
7
|
+
* measured). Returns a React 19 cleanup ref: attach it to the element; the
|
|
8
|
+
* observer is disconnected when the element unmounts.
|
|
9
|
+
*
|
|
10
|
+
* const [ref, { width }] = useElementSize<HTMLDivElement>()
|
|
11
|
+
* return <div ref={ref}>{width > 480 ? <Wide /> : <Narrow />}</div>
|
|
12
|
+
*/
|
|
13
|
+
export declare function useElementSize<T extends Element = HTMLDivElement>(): [(element: T) => () => void, ElementSize];
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import * as React from "react";
|
|
3
|
+
// src/hooks/use-element-size.ts
|
|
4
|
+
/**
|
|
5
|
+
* Measures an element's content box and follows it on resize (`{0, 0}` until
|
|
6
|
+
* measured). Returns a React 19 cleanup ref: attach it to the element; the
|
|
7
|
+
* observer is disconnected when the element unmounts.
|
|
8
|
+
*
|
|
9
|
+
* const [ref, { width }] = useElementSize<HTMLDivElement>()
|
|
10
|
+
* return <div ref={ref}>{width > 480 ? <Wide /> : <Narrow />}</div>
|
|
11
|
+
*/
|
|
12
|
+
function useElementSize() {
|
|
13
|
+
const [size, setSize] = React.useState({
|
|
14
|
+
width: 0,
|
|
15
|
+
height: 0
|
|
16
|
+
});
|
|
17
|
+
return [React.useCallback((element) => {
|
|
18
|
+
const observer = new ResizeObserver(([entry]) => {
|
|
19
|
+
const width = entry?.contentRect.width ?? 0;
|
|
20
|
+
const height = entry?.contentRect.height ?? 0;
|
|
21
|
+
setSize((prev) => prev.width === width && prev.height === height ? prev : {
|
|
22
|
+
width,
|
|
23
|
+
height
|
|
24
|
+
});
|
|
25
|
+
});
|
|
26
|
+
observer.observe(element);
|
|
27
|
+
return () => observer.disconnect();
|
|
28
|
+
}, []), size];
|
|
29
|
+
}
|
|
30
|
+
export { useElementSize };
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export type HashSection<K extends string> = {
|
|
2
|
+
/** Section in `#<prefix>/<section>`, or null when the hash doesn't address one. */
|
|
3
|
+
section: K | null;
|
|
4
|
+
/** Points the hash at a section (replaceState: no history entry). */
|
|
5
|
+
open: (section: K) => void;
|
|
6
|
+
/** Clears the hash, keeping path and query (replaceState). */
|
|
7
|
+
close: () => void;
|
|
8
|
+
};
|
|
9
|
+
/**
|
|
10
|
+
* Routes a modal (e.g. `SettingsDialog`) through the URL fragment
|
|
11
|
+
* `#<prefix>/<section>`: links and menus set the hash, the modal opens on the
|
|
12
|
+
* section, switching sections and closing rewrite the hash in place. Pass
|
|
13
|
+
* `keys` to ignore unknown (or not allowed) sections. The fragment never
|
|
14
|
+
* reaches the server.
|
|
15
|
+
*/
|
|
16
|
+
export declare function useHashSection(prefix: string): HashSection<string>;
|
|
17
|
+
export declare function useHashSection<K extends string>(prefix: string, keys: readonly K[]): HashSection<K>;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import * as React from "react";
|
|
3
|
+
// src/hooks/use-hash-section.ts
|
|
4
|
+
function parse(hash, prefix, keys) {
|
|
5
|
+
const head = `#${prefix}/`;
|
|
6
|
+
if (!hash.startsWith(head)) return null;
|
|
7
|
+
const key = decodeURIComponent(hash.slice(head.length));
|
|
8
|
+
if (!key) return null;
|
|
9
|
+
if (keys && !keys.includes(key)) return null;
|
|
10
|
+
return key;
|
|
11
|
+
}
|
|
12
|
+
function useHashSection(prefix, keys) {
|
|
13
|
+
const [section, setSection] = React.useState(null);
|
|
14
|
+
const keysId = keys?.join("\0");
|
|
15
|
+
React.useEffect(() => {
|
|
16
|
+
const allowed = keysId === void 0 ? void 0 : keysId.split("\0");
|
|
17
|
+
const sync = () => setSection(parse(window.location.hash, prefix, allowed));
|
|
18
|
+
sync();
|
|
19
|
+
window.addEventListener("hashchange", sync);
|
|
20
|
+
return () => window.removeEventListener("hashchange", sync);
|
|
21
|
+
}, [prefix, keysId]);
|
|
22
|
+
return {
|
|
23
|
+
section,
|
|
24
|
+
open: React.useCallback((next) => {
|
|
25
|
+
window.history.replaceState(null, "", `#${prefix}/${encodeURIComponent(next)}`);
|
|
26
|
+
setSection(next);
|
|
27
|
+
}, [prefix]),
|
|
28
|
+
close: React.useCallback(() => {
|
|
29
|
+
window.history.replaceState(null, "", window.location.pathname + window.location.search);
|
|
30
|
+
setSection(null);
|
|
31
|
+
}, [])
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
export { useHashSection };
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
export interface ScrollStripEdges {
|
|
3
|
+
/** Content is hidden past the start (left) edge. */
|
|
4
|
+
start: boolean;
|
|
5
|
+
/** Content is hidden past the end (right) edge. */
|
|
6
|
+
end: boolean;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Keeps the active item of a horizontal strip (tabs, a nav row) in view (on
|
|
10
|
+
* mount, on resize and whenever the active item changes, by click or
|
|
11
|
+
* keyboard: watches `data-state` and `aria-current`) and reports which edges
|
|
12
|
+
* hide content, for fade masks. `activeSelector` matches the active item among
|
|
13
|
+
* the strip's children. The first item aligns to the start, the last to the
|
|
14
|
+
* end, the others are centered; smooth unless the user prefers reduced motion.
|
|
15
|
+
* `enabled = false` turns it off (edges stay `false`).
|
|
16
|
+
*/
|
|
17
|
+
export declare function useScrollStrip(ref: React.RefObject<HTMLElement | null>, activeSelector: string, enabled?: boolean): ScrollStripEdges;
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { hiddenEdges, scrollTargetFor } from "../lib/scroll-target.js";
|
|
3
|
+
import * as React from "react";
|
|
4
|
+
// src/hooks/use-scroll-strip.ts
|
|
5
|
+
const reducedMotion = () => window.matchMedia("(prefers-reduced-motion: reduce)").matches;
|
|
6
|
+
/**
|
|
7
|
+
* Keeps the active item of a horizontal strip (tabs, a nav row) in view (on
|
|
8
|
+
* mount, on resize and whenever the active item changes, by click or
|
|
9
|
+
* keyboard: watches `data-state` and `aria-current`) and reports which edges
|
|
10
|
+
* hide content, for fade masks. `activeSelector` matches the active item among
|
|
11
|
+
* the strip's children. The first item aligns to the start, the last to the
|
|
12
|
+
* end, the others are centered; smooth unless the user prefers reduced motion.
|
|
13
|
+
* `enabled = false` turns it off (edges stay `false`).
|
|
14
|
+
*/
|
|
15
|
+
function useScrollStrip(ref, activeSelector, enabled = true) {
|
|
16
|
+
const [edges, setEdges] = React.useState({
|
|
17
|
+
start: false,
|
|
18
|
+
end: false
|
|
19
|
+
});
|
|
20
|
+
React.useEffect(() => {
|
|
21
|
+
const strip = ref.current;
|
|
22
|
+
if (!enabled || strip === null) return;
|
|
23
|
+
const updateEdges = () => {
|
|
24
|
+
const next = hiddenEdges(strip.scrollLeft, strip.clientWidth, strip.scrollWidth);
|
|
25
|
+
setEdges((prev) => prev.start === next.start && prev.end === next.end ? prev : next);
|
|
26
|
+
};
|
|
27
|
+
const reveal = (smooth) => {
|
|
28
|
+
const active = strip.querySelector(activeSelector);
|
|
29
|
+
if (active !== null && strip.scrollWidth > strip.clientWidth) {
|
|
30
|
+
const items = Array.from(strip.children);
|
|
31
|
+
const left = scrollTargetFor({
|
|
32
|
+
viewport: strip.clientWidth,
|
|
33
|
+
content: strip.scrollWidth,
|
|
34
|
+
itemStart: active.getBoundingClientRect().left - strip.getBoundingClientRect().left + strip.scrollLeft,
|
|
35
|
+
itemWidth: active.getBoundingClientRect().width,
|
|
36
|
+
index: items.indexOf(active),
|
|
37
|
+
count: items.length
|
|
38
|
+
});
|
|
39
|
+
if (Math.abs(left - strip.scrollLeft) > 1) strip.scrollTo({
|
|
40
|
+
left,
|
|
41
|
+
behavior: smooth && !reducedMotion() ? "smooth" : "auto"
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
updateEdges();
|
|
45
|
+
};
|
|
46
|
+
reveal(false);
|
|
47
|
+
strip.addEventListener("scroll", updateEdges, { passive: true });
|
|
48
|
+
const resize = new ResizeObserver(() => reveal(false));
|
|
49
|
+
resize.observe(strip);
|
|
50
|
+
const mutations = new MutationObserver(() => reveal(true));
|
|
51
|
+
mutations.observe(strip, {
|
|
52
|
+
subtree: true,
|
|
53
|
+
attributes: true,
|
|
54
|
+
attributeFilter: ["data-state", "aria-current"]
|
|
55
|
+
});
|
|
56
|
+
return () => {
|
|
57
|
+
strip.removeEventListener("scroll", updateEdges);
|
|
58
|
+
resize.disconnect();
|
|
59
|
+
mutations.disconnect();
|
|
60
|
+
};
|
|
61
|
+
}, [
|
|
62
|
+
ref,
|
|
63
|
+
activeSelector,
|
|
64
|
+
enabled
|
|
65
|
+
]);
|
|
66
|
+
return edges;
|
|
67
|
+
}
|
|
68
|
+
export { useScrollStrip };
|
package/dist/index.d.ts
CHANGED
|
@@ -13,6 +13,7 @@ import { Avatar, AvatarBadge, AvatarFallback, AvatarGroup, AvatarGroupCount, Ava
|
|
|
13
13
|
import { Badge, badgeVariants } from "./components/badge.js";
|
|
14
14
|
import { Breadcrumb, BreadcrumbEllipsis, BreadcrumbItem, BreadcrumbLink, BreadcrumbList, BreadcrumbPage, BreadcrumbSeparator } from "./components/breadcrumb.js";
|
|
15
15
|
import { Button, buttonVariants } from "./components/button.js";
|
|
16
|
+
import { ButtonGroup, ButtonGroupSeparator, ButtonGroupText, buttonGroupVariants } from "./components/button-group.js";
|
|
16
17
|
import { Card, CardAction, CardContent, CardDescription, CardFooter, CardHeader, CardTitle } from "./components/card.js";
|
|
17
18
|
import { Checkbox } from "./components/checkbox.js";
|
|
18
19
|
import { Dialog, DialogClose, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogOverlay, DialogPortal, DialogTitle, DialogTrigger } from "./components/dialog.js";
|
|
@@ -33,6 +34,7 @@ import { RadioGroup, RadioGroupItem } from "./components/radio-group.js";
|
|
|
33
34
|
import { Select, SelectContent, SelectGroup, SelectItem, SelectLabel, SelectScrollDownButton, SelectScrollUpButton, SelectSeparator, SelectTrigger, SelectValue } from "./components/select.js";
|
|
34
35
|
import { Skeleton } from "./components/skeleton.js";
|
|
35
36
|
import { Toaster } from "./components/sonner.js";
|
|
37
|
+
import { StatusDot, StatusDotProps, statusDotVariants } from "./components/status-dot.js";
|
|
36
38
|
import { Stepper } from "./components/stepper.js";
|
|
37
39
|
import { Switch } from "./components/switch.js";
|
|
38
40
|
import { Table, TableBody, TableCaption, TableCell, TableFooter, TableHead, TableHeader, TableRow } from "./components/table.js";
|
|
@@ -45,9 +47,13 @@ import { Popover, PopoverContent, PopoverTrigger } from "./components/popover.js
|
|
|
45
47
|
import { ScrollArea, ScrollBar } from "./components/scroll-area.js";
|
|
46
48
|
import { Separator } from "./components/separator.js";
|
|
47
49
|
import { SettingRow, SettingRowGroup } from "./components/setting-row.js";
|
|
50
|
+
import { SettingsDialog, SettingsDialogProps, SettingsDialogSection } from "./components/settings-dialog.js";
|
|
48
51
|
import { SettingsSection } from "./components/settings-section.js";
|
|
49
52
|
import { Sheet, SheetClose, SheetContent, SheetDescription, SheetFooter, SheetHeader, SheetTitle, SheetTrigger } from "./components/sheet.js";
|
|
50
53
|
import "./components/sidebar.js";
|
|
51
54
|
import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from "./components/tooltip.js";
|
|
55
|
+
import { ElementSize, useElementSize } from "./hooks/use-element-size.js";
|
|
56
|
+
import { HashSection, useHashSection } from "./hooks/use-hash-section.js";
|
|
52
57
|
import { useIsMobile } from "./hooks/use-mobile.js";
|
|
53
|
-
|
|
58
|
+
import { ScrollStripEdges, useScrollStrip } from "./hooks/use-scroll-strip.js";
|
|
59
|
+
export { AlertDialog, AlertDialogAction, AlertDialogCancel, AlertDialogContent, AlertDialogDescription, AlertDialogFooter, AlertDialogHeader, AlertDialogOverlay, AlertDialogPortal, AlertDialogTitle, AlertDialogTrigger, AppShell, type AppShellNavLink, type AppShellProps, AuthSplitScreen, type AuthSplitScreenProps, Avatar, AvatarBadge, AvatarFallback, AvatarGroup, AvatarGroupCount, AvatarImage, Badge, type BrandIconProps, Breadcrumb, BreadcrumbEllipsis, BreadcrumbItem, BreadcrumbLink, BreadcrumbList, BreadcrumbPage, BreadcrumbSeparator, Button, ButtonGroup, ButtonGroupSeparator, ButtonGroupText, Calendar, Card, CardAction, CardContent, CardDescription, CardFooter, CardHeader, CardTitle, Checkbox, Collapsible, CollapsibleContent, CollapsibleTrigger, DateField, type DateFieldProps, Dialog, DialogClose, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogOverlay, DialogPortal, DialogTitle, DialogTrigger, DropdownMenu, DropdownMenuCheckboxItem, DropdownMenuContent, DropdownMenuGroup, DropdownMenuItem, DropdownMenuLabel, DropdownMenuPortal, DropdownMenuRadioGroup, DropdownMenuRadioItem, DropdownMenuSeparator, DropdownMenuShortcut, DropdownMenuSub, DropdownMenuSubContent, DropdownMenuSubTrigger, DropdownMenuTrigger, type ElementSize, EmptyState, type EmptyStateProps, Field, FieldContent, FieldDescription, FieldError, FieldGroup, FieldLabel, FieldLegend, FieldSeparator, FieldSet, FieldTitle, GoogleIcon, type HashSection, HighlightedTextarea, Input, InputGroup, InputGroupAddon, InputGroupInput, Label, List, type ListEmptyContent, type ListFilterConfig, ListItem, ListItemActions, ListItemContent, ListItemDescription, type ListItemDescriptor, ListItemLeading, ListItemMedia, ListItemMeta, ListItemTitle, ListItemTrailing, type ListPaginationConfig, type ListProps, type ListSearchConfig, Main, type NavItem, type NavMatch, type NavSection, Pagination, type PaginationProps, Popover, PopoverContent, PopoverTrigger, RadioGroup, RadioGroupItem, ScrollArea, ScrollBar, type ScrollStripEdges, Select, SelectContent, SelectGroup, SelectItem, SelectLabel, SelectScrollDownButton, SelectScrollUpButton, SelectSeparator, SelectTrigger, SelectValue, Separator, SettingRow, SettingRowGroup, SettingsDialog, type SettingsDialogProps, type SettingsDialogSection, SettingsSection, Sheet, SheetClose, SheetContent, SheetDescription, SheetFooter, SheetHeader, SheetTitle, SheetTrigger, Sidebar, SidebarContent, SidebarFooter, SidebarGroup, SidebarGroupAction, SidebarGroupContent, SidebarGroupLabel, SidebarHeader, SidebarInput, SidebarInset, SidebarMenu, SidebarMenuAction, SidebarMenuBadge, SidebarMenuButton, SidebarMenuItem, SidebarMenuSkeleton, SidebarMenuSub, SidebarMenuSubButton, SidebarMenuSubItem, SidebarProvider, SidebarRail, SidebarSeparator, SidebarTrigger, Skeleton, StatusDot, type StatusDotProps, Stepper, Switch, Table, TableBody, TableCaption, TableCell, TableFooter, TableHead, TableHeader, TableRow, Tabs, TabsContent, TabsCount, TabsList, TabsTrigger, Textarea, ThemeProvider, Toaster, Tooltip, TooltipContent, TooltipProvider, TooltipTrigger, Typography, UserMenu, type UserMenuProps, WhatsappIcon, badgeVariants, buttonGroupVariants, buttonVariants, cn, hasActiveChild as hasActiveNavChild, initials, isActive as isNavItemActive, listItemVariants, listVariants, mainVariants, statusDotVariants, tabsListVariants, typographyVariants, useElementSize, useHashSection, useIsMobile, useScrollStrip, useSidebar, userMenuInitials };
|
package/dist/index.js
CHANGED
|
@@ -11,6 +11,7 @@ import { Avatar, AvatarBadge, AvatarFallback, AvatarGroup, AvatarGroupCount, Ava
|
|
|
11
11
|
import { Badge, badgeVariants } from "./components/badge.js";
|
|
12
12
|
import { Breadcrumb, BreadcrumbEllipsis, BreadcrumbItem, BreadcrumbLink, BreadcrumbList, BreadcrumbPage, BreadcrumbSeparator } from "./components/breadcrumb.js";
|
|
13
13
|
import { Button, buttonVariants } from "./components/button.js";
|
|
14
|
+
import { ButtonGroup, ButtonGroupSeparator, ButtonGroupText, buttonGroupVariants } from "./components/button-group.js";
|
|
14
15
|
import { Card, CardAction, CardContent, CardDescription, CardFooter, CardHeader, CardTitle } from "./components/card.js";
|
|
15
16
|
import { Checkbox } from "./components/checkbox.js";
|
|
16
17
|
import { Dialog, DialogClose, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogOverlay, DialogPortal, DialogTitle, DialogTrigger } from "./components/dialog.js";
|
|
@@ -30,6 +31,7 @@ import { RadioGroup, RadioGroupItem } from "./components/radio-group.js";
|
|
|
30
31
|
import { Select, SelectContent, SelectGroup, SelectItem, SelectLabel, SelectScrollDownButton, SelectScrollUpButton, SelectSeparator, SelectTrigger, SelectValue } from "./components/select.js";
|
|
31
32
|
import { Skeleton } from "./components/skeleton.js";
|
|
32
33
|
import { Toaster } from "./components/sonner.js";
|
|
34
|
+
import { StatusDot, statusDotVariants } from "./components/status-dot.js";
|
|
33
35
|
import { Stepper } from "./components/stepper.js";
|
|
34
36
|
import { Switch } from "./components/switch.js";
|
|
35
37
|
import { Table, TableBody, TableCaption, TableCell, TableFooter, TableHead, TableHeader, TableRow } from "./components/table.js";
|
|
@@ -42,10 +44,14 @@ import { Popover, PopoverContent, PopoverTrigger } from "./components/popover.js
|
|
|
42
44
|
import { ScrollArea, ScrollBar } from "./components/scroll-area.js";
|
|
43
45
|
import { Separator } from "./components/separator.js";
|
|
44
46
|
import { SettingRow, SettingRowGroup } from "./components/setting-row.js";
|
|
47
|
+
import { SettingsDialog } from "./components/settings-dialog.js";
|
|
45
48
|
import { SettingsSection } from "./components/settings-section.js";
|
|
46
49
|
import { Sheet, SheetClose, SheetContent, SheetDescription, SheetFooter, SheetHeader, SheetTitle, SheetTrigger } from "./components/sheet.js";
|
|
47
50
|
import { Sidebar, SidebarContent, SidebarFooter, SidebarHeader, SidebarInput, SidebarInset, SidebarProvider, SidebarRail, SidebarSeparator, SidebarTrigger, useSidebar } from "./components/sidebar-core.js";
|
|
48
51
|
import { SidebarGroup, SidebarGroupAction, SidebarGroupContent, SidebarGroupLabel, SidebarMenu, SidebarMenuAction, SidebarMenuBadge, SidebarMenuButton, SidebarMenuItem, SidebarMenuSkeleton, SidebarMenuSub, SidebarMenuSubButton, SidebarMenuSubItem } from "./components/sidebar-menu.js";
|
|
49
52
|
import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from "./components/tooltip.js";
|
|
53
|
+
import { useElementSize } from "./hooks/use-element-size.js";
|
|
54
|
+
import { useHashSection } from "./hooks/use-hash-section.js";
|
|
50
55
|
import { useIsMobile } from "./hooks/use-mobile.js";
|
|
51
|
-
|
|
56
|
+
import { useScrollStrip } from "./hooks/use-scroll-strip.js";
|
|
57
|
+
export { AlertDialog, AlertDialogAction, AlertDialogCancel, AlertDialogContent, AlertDialogDescription, AlertDialogFooter, AlertDialogHeader, AlertDialogOverlay, AlertDialogPortal, AlertDialogTitle, AlertDialogTrigger, AppShell, AuthSplitScreen, Avatar, AvatarBadge, AvatarFallback, AvatarGroup, AvatarGroupCount, AvatarImage, Badge, Breadcrumb, BreadcrumbEllipsis, BreadcrumbItem, BreadcrumbLink, BreadcrumbList, BreadcrumbPage, BreadcrumbSeparator, Button, ButtonGroup, ButtonGroupSeparator, ButtonGroupText, Calendar, Card, CardAction, CardContent, CardDescription, CardFooter, CardHeader, CardTitle, Checkbox, Collapsible, CollapsibleContent, CollapsibleTrigger, DateField, Dialog, DialogClose, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogOverlay, DialogPortal, DialogTitle, DialogTrigger, DropdownMenu, DropdownMenuCheckboxItem, DropdownMenuContent, DropdownMenuGroup, DropdownMenuItem, DropdownMenuLabel, DropdownMenuPortal, DropdownMenuRadioGroup, DropdownMenuRadioItem, DropdownMenuSeparator, DropdownMenuShortcut, DropdownMenuSub, DropdownMenuSubContent, DropdownMenuSubTrigger, DropdownMenuTrigger, EmptyState, Field, FieldContent, FieldDescription, FieldError, FieldGroup, FieldLabel, FieldLegend, FieldSeparator, FieldSet, FieldTitle, GoogleIcon, HighlightedTextarea, Input, InputGroup, InputGroupAddon, InputGroupInput, Label, List, ListItem, ListItemActions, ListItemContent, ListItemDescription, ListItemLeading, ListItemMedia, ListItemMeta, ListItemTitle, ListItemTrailing, Main, Pagination, Popover, PopoverContent, PopoverTrigger, RadioGroup, RadioGroupItem, ScrollArea, ScrollBar, Select, SelectContent, SelectGroup, SelectItem, SelectLabel, SelectScrollDownButton, SelectScrollUpButton, SelectSeparator, SelectTrigger, SelectValue, Separator, SettingRow, SettingRowGroup, SettingsDialog, SettingsSection, Sheet, SheetClose, SheetContent, SheetDescription, SheetFooter, SheetHeader, SheetTitle, SheetTrigger, Sidebar, SidebarContent, SidebarFooter, SidebarGroup, SidebarGroupAction, SidebarGroupContent, SidebarGroupLabel, SidebarHeader, SidebarInput, SidebarInset, SidebarMenu, SidebarMenuAction, SidebarMenuBadge, SidebarMenuButton, SidebarMenuItem, SidebarMenuSkeleton, SidebarMenuSub, SidebarMenuSubButton, SidebarMenuSubItem, SidebarProvider, SidebarRail, SidebarSeparator, SidebarTrigger, Skeleton, StatusDot, Stepper, Switch, Table, TableBody, TableCaption, TableCell, TableFooter, TableHead, TableHeader, TableRow, Tabs, TabsContent, TabsCount, TabsList, TabsTrigger, Textarea, ThemeProvider, Toaster, Tooltip, TooltipContent, TooltipProvider, TooltipTrigger, Typography, UserMenu, WhatsappIcon, badgeVariants, buttonGroupVariants, buttonVariants, cn, hasActiveChild as hasActiveNavChild, initials, isActive as isNavItemActive, listItemVariants, listVariants, mainVariants, statusDotVariants, tabsListVariants, typographyVariants, useElementSize, useHashSection, useIsMobile, useScrollStrip, useSidebar, userMenuInitials };
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
// src/lib/scroll-target.ts
|
|
2
|
+
/**
|
|
3
|
+
* Where to scroll a strip so the item is fully visible: the first item aligns
|
|
4
|
+
* the strip to its start, the last to its end, and the ones in between are
|
|
5
|
+
* centered (so both neighbors peek in), clamped to the scrollable range.
|
|
6
|
+
*/
|
|
7
|
+
function scrollTargetFor(g) {
|
|
8
|
+
const max = Math.max(0, g.content - g.viewport);
|
|
9
|
+
if (g.index <= 0) return 0;
|
|
10
|
+
if (g.index >= g.count - 1) return max;
|
|
11
|
+
const centered = g.itemStart + g.itemWidth / 2 - g.viewport / 2;
|
|
12
|
+
return Math.min(max, Math.max(0, Math.round(centered)));
|
|
13
|
+
}
|
|
14
|
+
/** Which sides of a strip hide content (1px slack for subpixel layouts). */
|
|
15
|
+
function hiddenEdges(scrollLeft, viewport, content) {
|
|
16
|
+
return {
|
|
17
|
+
start: scrollLeft > 1,
|
|
18
|
+
end: scrollLeft + viewport < content - 1
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
/** CSS mask fading only the sides that hide content; `undefined` when none does. */
|
|
22
|
+
function fadeMask({ start, end }) {
|
|
23
|
+
if (!start && !end) return void 0;
|
|
24
|
+
return `linear-gradient(to right, ${start ? "transparent 0, black 1.5rem" : "black 0"}, ${end ? "black calc(100% - 1.5rem), transparent 100%" : "black 100%"})`;
|
|
25
|
+
}
|
|
26
|
+
export { fadeMask, hiddenEdges, scrollTargetFor };
|
package/dist/tokens.css
CHANGED
|
@@ -16,7 +16,13 @@
|
|
|
16
16
|
*/
|
|
17
17
|
|
|
18
18
|
:root {
|
|
19
|
-
|
|
19
|
+
/*
|
|
20
|
+
* Surfaces (light): the page and the sidebar around it are a soft gray so
|
|
21
|
+
* white cards and popups stand out from it (like shadcn's own site). Card
|
|
22
|
+
* and popover stay white. Kept a step lighter than `--accent` /
|
|
23
|
+
* `--sidebar-accent` (0.97) so hover and active fills stay visible.
|
|
24
|
+
*/
|
|
25
|
+
--background: oklch(0.985 0 0);
|
|
20
26
|
--foreground: oklch(0.145 0 0);
|
|
21
27
|
--card: oklch(1 0 0);
|
|
22
28
|
--card-foreground: oklch(0.145 0 0);
|
|
@@ -59,7 +65,8 @@
|
|
|
59
65
|
--foreground: oklch(0.985 0 0);
|
|
60
66
|
--card: oklch(0.205 0 0);
|
|
61
67
|
--card-foreground: oklch(0.985 0 0);
|
|
62
|
-
|
|
68
|
+
/* Floating surfaces read lighter than the cards they float over. */
|
|
69
|
+
--popover: oklch(0.24 0 0);
|
|
63
70
|
--popover-foreground: oklch(0.985 0 0);
|
|
64
71
|
--primary: oklch(0.922 0 0);
|
|
65
72
|
--primary-foreground: oklch(0.205 0 0);
|
|
@@ -91,6 +98,17 @@
|
|
|
91
98
|
--wa-foreground: oklch(0.99 0 0);
|
|
92
99
|
}
|
|
93
100
|
|
|
101
|
+
/*
|
|
102
|
+
* Elevation for floating surfaces (popups over content, Google Calendar
|
|
103
|
+
* style): `shadow-popup`. Mode-independent; dark mode relies on the lighter
|
|
104
|
+
* `--popover` for separation since shadows barely show there.
|
|
105
|
+
*/
|
|
106
|
+
@theme {
|
|
107
|
+
--shadow-popup:
|
|
108
|
+
0 24px 38px 3px rgb(0 0 0 / 0.14), 0 9px 46px 8px rgb(0 0 0 / 0.12),
|
|
109
|
+
0 11px 15px -7px rgb(0 0 0 / 0.2);
|
|
110
|
+
}
|
|
111
|
+
|
|
94
112
|
@theme inline {
|
|
95
113
|
/*
|
|
96
114
|
* Token contract: adopters provide `--font-sans` via `next/font` (typically
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cbrl/design",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.1",
|
|
4
4
|
"description": "Design system on Radix + Tailwind v4: shadcn-style components, layout shells and design tokens with an overridable brand accent.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Kayron Cabral",
|