@cbrl/design 0.9.0 → 0.10.0
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 +100 -23
- package/dist/components/account-settings.d.ts +24 -0
- package/dist/components/account-settings.js +49 -0
- package/dist/components/alert-dialog.d.ts +5 -1
- package/dist/components/alert-dialog.js +2 -2
- package/dist/components/app-shell.d.ts +25 -4
- package/dist/components/app-shell.js +89 -47
- package/dist/components/avatar.d.ts +7 -2
- package/dist/components/avatar.js +28 -6
- package/dist/components/dropdown-menu.d.ts +5 -1
- package/dist/components/dropdown-menu.js +2 -2
- package/dist/components/settings-dialog.d.ts +65 -10
- package/dist/components/settings-dialog.js +210 -29
- package/dist/components/sidebar-core.js +5 -5
- package/dist/components/sidebar-peek.d.ts +40 -0
- package/dist/components/sidebar-peek.js +204 -0
- package/dist/components/table.d.ts +8 -1
- package/dist/components/table.js +5 -4
- package/dist/components/theme-provider.d.ts +1 -1
- package/dist/components/theme-provider.js +4 -1
- package/dist/components/theme-setting.d.ts +12 -0
- package/dist/components/theme-setting.js +66 -0
- package/dist/components/tooltip.js +7 -1
- package/dist/components/user-menu.d.ts +17 -0
- package/dist/components/user-menu.js +38 -11
- package/dist/hooks/use-autosave-form.d.ts +36 -0
- package/dist/hooks/use-autosave-form.js +81 -0
- package/dist/index.d.ts +7 -3
- package/dist/index.js +7 -3
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -27,13 +27,15 @@ this package.
|
|
|
27
27
|
|
|
28
28
|
Mount `ThemeProvider` (a client wrapper over `next-themes`, same props) and
|
|
29
29
|
`<Toaster />` in the root layout if you use dark mode or toasts. `next-themes`
|
|
30
|
-
is a peer dependency so the app and the toaster share one theme state.
|
|
30
|
+
is a peer dependency so the app and the toaster share one theme state. It
|
|
31
|
+
defaults to `attribute="class"`, `defaultTheme="system"` and `enableSystem`:
|
|
32
|
+
the app follows the system until the user picks a theme (`ThemeSetting`).
|
|
31
33
|
|
|
32
34
|
```tsx
|
|
33
35
|
// src/app/layout.tsx
|
|
34
36
|
import { ThemeProvider, Toaster } from '@cbrl/design'
|
|
35
37
|
|
|
36
|
-
;<ThemeProvider
|
|
38
|
+
;<ThemeProvider disableTransitionOnChange>
|
|
37
39
|
{children}
|
|
38
40
|
<Toaster />
|
|
39
41
|
</ThemeProvider>
|
|
@@ -240,6 +242,20 @@ their built-in close button (default `"Close"`).
|
|
|
240
242
|
grouped navigation and footer, sticky header, content inset). Routing stays in
|
|
241
243
|
the app: you render each nav link, so the package never imports `next`.
|
|
242
244
|
|
|
245
|
+
By default (`collapsible="offcanvas"`) it behaves like the Claude app on `md+`:
|
|
246
|
+
a fixed toolbar on the top left holds the sidebar toggle (`Ctrl/⌘+B`) and the
|
|
247
|
+
history back/forward buttons (disabled, as in the Claude app, when the
|
|
248
|
+
browser's Navigation API says there is nowhere to go); collapsed, the sidebar is fully hidden, and
|
|
249
|
+
hovering the toggle or the window's left edge (the rail) slides it in over the
|
|
250
|
+
content until the pointer leaves; clicking pins it, and clicking the rail of a
|
|
251
|
+
pinned sidebar collapses it. `collapsible="icon"` keeps the rail of icons and
|
|
252
|
+
the toggle in the header. Toolbar texts: `toolbarLabels`. With nothing in
|
|
253
|
+
`headerStart`/`headerEnd`, the top bar shows only on phones (where it holds the
|
|
254
|
+
sidebar trigger and `account`), as in the Claude app: put context switchers in
|
|
255
|
+
the account menu and the primary action in `primaryAction` (a nav item: the
|
|
256
|
+
first, highlighted row of the sidebar list, e.g. "Criar"). `brand` is optional; the Claude-app chrome
|
|
257
|
+
leaves it out.
|
|
258
|
+
|
|
243
259
|
```tsx
|
|
244
260
|
'use client'
|
|
245
261
|
|
|
@@ -273,9 +289,16 @@ export function AppShell({ children }: { children: React.ReactNode }) {
|
|
|
273
289
|
}
|
|
274
290
|
```
|
|
275
291
|
|
|
276
|
-
The
|
|
292
|
+
The content scrolls in one container that keeps a stable scrollbar gutter (no
|
|
293
|
+
shift when a page starts to scroll); a screen that fills the viewport marks an
|
|
294
|
+
element `data-fills-viewport` to drop the gutter. The shell handles the
|
|
295
|
+
`<nav aria-label>` landmark, the active item, closing the
|
|
277
296
|
mobile drawer and tooltips when collapsed. The sidebar primitives (`Sidebar`,
|
|
278
|
-
`SidebarProvider`, `SidebarMenu*`, `useSidebar`, …) are exported for custom shells
|
|
297
|
+
`SidebarProvider`, `SidebarMenu*`, `useSidebar`, …) are exported for custom shells,
|
|
298
|
+
and so is the Claude-app behavior: inside `SidebarProvider`, wrap the shell in
|
|
299
|
+
`SidebarPeekProvider` and use `PeekSidebar` (instead of `Sidebar`) and
|
|
300
|
+
`AppToolbar`; leave `APP_TOOLBAR_HEIGHT` free at the top of the sidebar and of
|
|
301
|
+
the content. `useSidebarPeek()` tells whether the sidebar is peeking.
|
|
279
302
|
|
|
280
303
|
### Tabs and scrolling strips
|
|
281
304
|
|
|
@@ -309,44 +332,97 @@ return <div ref={ref}>{width > 480 ? <Wide /> : <Narrow />}</div>
|
|
|
309
332
|
|
|
310
333
|
### Settings dialog
|
|
311
334
|
|
|
312
|
-
`SettingsDialog` is the settings
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
335
|
+
`SettingsDialog` is the settings modal in the Claude app's layout: a
|
|
336
|
+
"Configurações" title bar, a filled search box (with a clear button) over the
|
|
337
|
+
section nav (a column from `sm`, a sideways-scrolling strip on phones that keeps
|
|
338
|
+
the active section in view), and the active section's content. The search
|
|
339
|
+
matches section labels and `keywords`, ignoring case, accents and plurals;
|
|
340
|
+
Enter opens the first match and Escape clears the search before closing.
|
|
341
|
+
Sections sharing a `group` sit together, with a divider between groups.
|
|
342
|
+
|
|
343
|
+
Build sections from `SettingsGroup` (a titled block, optional `action`) and
|
|
344
|
+
`SettingsItem` (label and description on the left, the control on the right).
|
|
345
|
+
The sections every app has ship ready: `AccountSettings` (profile: photo, name,
|
|
346
|
+
e-mail; signing out stays in the user menu) and `ThemeSetting` (system / light /
|
|
347
|
+
dark, system by default). App-specific sections stay in the app, which decides
|
|
348
|
+
which sections a user sees and loads their data; the dialog renders `children`
|
|
349
|
+
for the active one. `useHashSection(prefix, keys?)` routes it through
|
|
350
|
+
`#<prefix>/<section>` (`hashchange` in, `history.replaceState` on switch and
|
|
351
|
+
close):
|
|
319
352
|
|
|
320
353
|
```tsx
|
|
321
354
|
'use client'
|
|
322
355
|
|
|
323
|
-
import {
|
|
324
|
-
|
|
356
|
+
import {
|
|
357
|
+
AccountSettings,
|
|
358
|
+
SettingsDialog,
|
|
359
|
+
SettingsGroup,
|
|
360
|
+
SettingsItem,
|
|
361
|
+
ThemeSetting,
|
|
362
|
+
useHashSection,
|
|
363
|
+
type SettingsAccount,
|
|
364
|
+
type SettingsDialogSection,
|
|
365
|
+
} from '@cbrl/design'
|
|
366
|
+
import { CircleUser, CreditCard, Palette } from 'lucide-react'
|
|
325
367
|
|
|
326
|
-
type Key = '
|
|
368
|
+
type Key = 'conta' | 'aparencia' | 'cobranca'
|
|
327
369
|
const SECTIONS: readonly SettingsDialogSection<Key>[] = [
|
|
328
|
-
{ key: '
|
|
329
|
-
{ key: '
|
|
370
|
+
{ key: 'conta', label: 'Conta', icon: CircleUser, group: 'conta', keywords: ['perfil'] },
|
|
371
|
+
{ key: 'aparencia', label: 'Aparência', icon: Palette, group: 'app', keywords: ['tema'] },
|
|
372
|
+
{ key: 'cobranca', label: 'Cobrança', icon: CreditCard, group: 'produto' },
|
|
330
373
|
]
|
|
331
374
|
|
|
332
|
-
export function SettingsModal() {
|
|
333
|
-
const { section, open, close } = useHashSection<Key>('
|
|
375
|
+
export function SettingsModal({ account }: { account: SettingsAccount }) {
|
|
376
|
+
const { section, open, close } = useHashSection<Key>('configuracoes', [
|
|
377
|
+
'conta',
|
|
378
|
+
'aparencia',
|
|
379
|
+
'cobranca',
|
|
380
|
+
])
|
|
334
381
|
return (
|
|
335
382
|
<SettingsDialog
|
|
336
383
|
open={section !== null}
|
|
337
384
|
onOpenChange={(next) => !next && close()}
|
|
338
385
|
sections={SECTIONS}
|
|
339
|
-
value={section ?? '
|
|
386
|
+
value={section ?? 'conta'}
|
|
340
387
|
onValueChange={open}
|
|
341
|
-
navLabel="Seções de configuração"
|
|
342
388
|
>
|
|
343
|
-
{section === '
|
|
389
|
+
{section === 'conta' && <AccountSettings account={account} />}
|
|
390
|
+
{section === 'aparencia' && (
|
|
391
|
+
<SettingsGroup title="Geral">
|
|
392
|
+
<SettingsItem label="Tema">
|
|
393
|
+
<ThemeSetting />
|
|
394
|
+
</SettingsItem>
|
|
395
|
+
</SettingsGroup>
|
|
396
|
+
)}
|
|
397
|
+
{section === 'cobranca' && <BillingPanel />}
|
|
344
398
|
</SettingsDialog>
|
|
345
399
|
)
|
|
346
400
|
}
|
|
347
|
-
// Anywhere: <a href="#
|
|
401
|
+
// Anywhere: <a href="#configuracoes/cobranca">Cobrança</a>
|
|
348
402
|
```
|
|
349
403
|
|
|
404
|
+
Rows: `SettingsItem` puts the label (a real `<label>` with `htmlFor`) and an
|
|
405
|
+
optional description on the left and the control on the right, with inputs
|
|
406
|
+
and select triggers at the standard compact width; `layout="stacked"` puts a
|
|
407
|
+
large control (a textarea) under the label. For a variable set of rows (units,
|
|
408
|
+
rules) give the group a `listLabel` and render `SettingsItem as="li"`; an empty
|
|
409
|
+
group shows `SettingsEmpty`. Small actions go in the group's `action`, never as
|
|
410
|
+
big buttons at the end. Fields that save themselves (no "Salvar" button) use `useAutosaveForm({ submit,
|
|
411
|
+
successMessage, onSaved })`: spread `formProps` on the `<form>`; text fields
|
|
412
|
+
(uncontrolled, with `defaultValue`) save on blur or Enter and Escape undoes;
|
|
413
|
+
selects, switches and pickers call `saveSoon()` after changing. A value set
|
|
414
|
+
by a picker goes in a hidden input controlled by state (`value={state}`), then
|
|
415
|
+
`saveSoon()` — an uncontrolled hidden input is reset by React's re-render
|
|
416
|
+
before the save reads it. Pass the router's refresh as `onSaved` when the
|
|
417
|
+
page must reload its data.
|
|
418
|
+
|
|
419
|
+
Account menus composed by apps start with
|
|
420
|
+
`DropdownMenuAccountHeader` (the `UserMenu` header) and use `USER_MENU_WIDTH`.
|
|
421
|
+
|
|
422
|
+
Texts default to pt-BR; override them with `labels` (`title`, `nav`, `search`,
|
|
423
|
+
`searchPlaceholder`, `clearSearch`, `noResults`) on the dialog, and `labels` on
|
|
424
|
+
`AccountSettings` and `ThemeSetting`.
|
|
425
|
+
|
|
350
426
|
Next.js App Router: a fragment-only navigation (plain `<a href="#…">`, a typed
|
|
351
427
|
URL) bypasses the router, whose history sync then rewrites the URL without the
|
|
352
428
|
hash and would close the dialog at once. The hook re-states the URL through
|
|
@@ -354,7 +430,8 @@ hash and would close the dialog at once. The hook re-states the URL through
|
|
|
354
430
|
`open`/`close`) so the router adopts it; outside Next this is a no-op.
|
|
355
431
|
|
|
356
432
|
Uncontrolled use: `defaultOpen`/`defaultValue`. Slots: `settings-dialog`,
|
|
357
|
-
`settings-dialog-nav`, `settings-dialog-content
|
|
433
|
+
`settings-dialog-nav`, `settings-dialog-content`, `settings-group`,
|
|
434
|
+
`settings-item`.
|
|
358
435
|
|
|
359
436
|
### Forms (react-hook-form)
|
|
360
437
|
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
export type SettingsAccount = {
|
|
2
|
+
name: string | null;
|
|
3
|
+
email: string | null;
|
|
4
|
+
avatarUrl: string | null;
|
|
5
|
+
};
|
|
6
|
+
export type AccountSettingsLabels = {
|
|
7
|
+
profile: string;
|
|
8
|
+
photo: string;
|
|
9
|
+
name: string;
|
|
10
|
+
email: string;
|
|
11
|
+
};
|
|
12
|
+
export declare function AccountSettings({ account, labels: labelsProp, profileRows, children }: {
|
|
13
|
+
account: SettingsAccount;
|
|
14
|
+
labels?: Partial<AccountSettingsLabels>;
|
|
15
|
+
/**
|
|
16
|
+
* The app's editable profile rows (`SettingsItem`s: full name, phone…),
|
|
17
|
+
* inside the same Perfil group after the photo — everything about the person
|
|
18
|
+
* in one place, as in the Claude app. With them, the read-only Nome row is
|
|
19
|
+
* left out (the app edits the name).
|
|
20
|
+
*/
|
|
21
|
+
profileRows?: React.ReactNode;
|
|
22
|
+
/** App-specific groups, after the profile. */
|
|
23
|
+
children?: React.ReactNode;
|
|
24
|
+
}): import("react").JSX.Element;
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { initials } from "../lib/initials.js";
|
|
3
|
+
import { Avatar, AvatarFallback, AvatarImage } from "./avatar.js";
|
|
4
|
+
import { SettingsGroup, SettingsItem } from "./settings-dialog.js";
|
|
5
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
6
|
+
// src/components/account-settings.tsx
|
|
7
|
+
const DEFAULT_LABELS = {
|
|
8
|
+
profile: "Perfil",
|
|
9
|
+
photo: "Foto de perfil",
|
|
10
|
+
name: "Nome",
|
|
11
|
+
email: "E-mail"
|
|
12
|
+
};
|
|
13
|
+
function AccountSettings({ account, labels: labelsProp, profileRows, children }) {
|
|
14
|
+
const labels = {
|
|
15
|
+
...DEFAULT_LABELS,
|
|
16
|
+
...labelsProp
|
|
17
|
+
};
|
|
18
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsxs(SettingsGroup, {
|
|
19
|
+
title: labels.profile,
|
|
20
|
+
children: [
|
|
21
|
+
/* @__PURE__ */ jsx(SettingsItem, {
|
|
22
|
+
label: labels.photo,
|
|
23
|
+
children: /* @__PURE__ */ jsxs(Avatar, {
|
|
24
|
+
size: "lg",
|
|
25
|
+
children: [account.avatarUrl ? /* @__PURE__ */ jsx(AvatarImage, {
|
|
26
|
+
src: account.avatarUrl,
|
|
27
|
+
alt: account.name ?? account.email ?? ""
|
|
28
|
+
}) : null, /* @__PURE__ */ jsx(AvatarFallback, { children: initials(account.name, account.email) })]
|
|
29
|
+
})
|
|
30
|
+
}),
|
|
31
|
+
account.name && profileRows === void 0 ? /* @__PURE__ */ jsx(SettingsItem, {
|
|
32
|
+
label: labels.name,
|
|
33
|
+
children: /* @__PURE__ */ jsx("span", {
|
|
34
|
+
className: "text-muted-foreground truncate text-sm",
|
|
35
|
+
children: account.name
|
|
36
|
+
})
|
|
37
|
+
}) : null,
|
|
38
|
+
account.email ? /* @__PURE__ */ jsx(SettingsItem, {
|
|
39
|
+
label: labels.email,
|
|
40
|
+
children: /* @__PURE__ */ jsx("span", {
|
|
41
|
+
className: "text-muted-foreground truncate text-sm",
|
|
42
|
+
children: account.email
|
|
43
|
+
})
|
|
44
|
+
}) : null,
|
|
45
|
+
profileRows
|
|
46
|
+
]
|
|
47
|
+
}), children] });
|
|
48
|
+
}
|
|
49
|
+
export { AccountSettings };
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { buttonVariants } from "./button.js";
|
|
1
2
|
import * as React from "react";
|
|
2
3
|
import { AlertDialog as AlertDialog$1 } from "radix-ui";
|
|
3
4
|
declare function AlertDialog({ ...props }: React.ComponentProps<typeof AlertDialog$1.Root>): React.JSX.Element;
|
|
@@ -9,6 +10,9 @@ declare function AlertDialogHeader({ className, ...props }: React.ComponentProps
|
|
|
9
10
|
declare function AlertDialogFooter({ className, ...props }: React.ComponentProps<'div'>): React.JSX.Element;
|
|
10
11
|
declare function AlertDialogTitle({ className, ...props }: React.ComponentProps<typeof AlertDialog$1.Title>): React.JSX.Element;
|
|
11
12
|
declare function AlertDialogDescription({ className, ...props }: React.ComponentProps<typeof AlertDialog$1.Description>): React.JSX.Element;
|
|
12
|
-
declare function AlertDialogAction({ className, ...props }: React.ComponentProps<typeof AlertDialog$1.Action>
|
|
13
|
+
declare function AlertDialogAction({ className, variant, ...props }: React.ComponentProps<typeof AlertDialog$1.Action> & {
|
|
14
|
+
/** Button look of the confirming action (destructive by default). */
|
|
15
|
+
variant?: NonNullable<Parameters<typeof buttonVariants>[0]>['variant'];
|
|
16
|
+
}): React.JSX.Element;
|
|
13
17
|
declare function AlertDialogCancel({ className, ...props }: React.ComponentProps<typeof AlertDialog$1.Cancel>): React.JSX.Element;
|
|
14
18
|
export { AlertDialog, AlertDialogAction, AlertDialogCancel, AlertDialogContent, AlertDialogDescription, AlertDialogFooter, AlertDialogHeader, AlertDialogOverlay, AlertDialogPortal, AlertDialogTitle, AlertDialogTrigger };
|
|
@@ -65,10 +65,10 @@ function AlertDialogDescription({ className, ...props }) {
|
|
|
65
65
|
...props
|
|
66
66
|
});
|
|
67
67
|
}
|
|
68
|
-
function AlertDialogAction({ className, ...props }) {
|
|
68
|
+
function AlertDialogAction({ className, variant = "destructive", ...props }) {
|
|
69
69
|
return /* @__PURE__ */ jsx(AlertDialog$1.Action, {
|
|
70
70
|
"data-slot": "alert-dialog-action",
|
|
71
|
-
className: cn(buttonVariants({ variant
|
|
71
|
+
className: cn(buttonVariants({ variant }), className),
|
|
72
72
|
...props
|
|
73
73
|
});
|
|
74
74
|
}
|
|
@@ -1,14 +1,19 @@
|
|
|
1
1
|
import { NavItem, NavSection } from "../lib/nav.js";
|
|
2
2
|
import { Sidebar } from "./sidebar-core.js";
|
|
3
3
|
import "./sidebar.js";
|
|
4
|
+
import { AppToolbarLabels } from "./sidebar-peek.js";
|
|
4
5
|
import * as React from "react";
|
|
5
6
|
export type AppShellNavLink = (item: NavItem, props: {
|
|
6
7
|
onNavigate: () => void;
|
|
7
8
|
children: React.ReactNode;
|
|
8
9
|
}) => React.ReactNode;
|
|
9
10
|
export type AppShellProps = {
|
|
10
|
-
/**
|
|
11
|
-
|
|
11
|
+
/**
|
|
12
|
+
* Brand block at the top of the sidebar (product/tenant name, logo).
|
|
13
|
+
* Optional: the Claude-app chrome has none — the toolbar and
|
|
14
|
+
* `sidebarAction` open the sidebar.
|
|
15
|
+
*/
|
|
16
|
+
brand?: React.ReactNode;
|
|
12
17
|
/** Nav sections, already filtered/resolved by the consumer (RBAC, signals…). */
|
|
13
18
|
sections: NavSection[];
|
|
14
19
|
/** Current pathname — drives the active nav highlight. */
|
|
@@ -29,8 +34,24 @@ export type AppShellProps = {
|
|
|
29
34
|
headerStart?: React.ReactNode;
|
|
30
35
|
/** Right of the top header (e.g. notifications). */
|
|
31
36
|
headerEnd?: React.ReactNode;
|
|
32
|
-
/**
|
|
37
|
+
/**
|
|
38
|
+
* Primary action on top of the sidebar (e.g. "Criar", "Publicar imóvel"),
|
|
39
|
+
* drawn like the Claude app's "new chat": the first row of the sidebar list,
|
|
40
|
+
* styled as the primary button, in the same rhythm as the nav items. Rendered through
|
|
41
|
+
* `renderNavLink`, like the nav items.
|
|
42
|
+
*/
|
|
43
|
+
primaryAction?: NavItem;
|
|
44
|
+
/**
|
|
45
|
+
* Sidebar collapse behavior. Defaults to `offcanvas`, the Claude-app chrome:
|
|
46
|
+
* a fixed toolbar (toggle, back, forward), the sidebar fully hidden when
|
|
47
|
+
* collapsed and peeking over the content on hover. With nothing in
|
|
48
|
+
* `headerStart`/`headerEnd` the top header shows only on phones (where it
|
|
49
|
+
* holds the sidebar trigger and `account`). `icon` keeps a rail of icons and
|
|
50
|
+
* the toggle in the header.
|
|
51
|
+
*/
|
|
33
52
|
collapsible?: React.ComponentProps<typeof Sidebar>['collapsible'];
|
|
53
|
+
/** Texts of the toolbar (offcanvas). */
|
|
54
|
+
toolbarLabels?: Partial<AppToolbarLabels>;
|
|
34
55
|
/** Accessible label for the nav landmark. Defaults to `Navegação principal`. */
|
|
35
56
|
navLabel?: string;
|
|
36
57
|
/** Whether the sidebar starts expanded (uncontrolled). Defaults to `true`. */
|
|
@@ -44,4 +65,4 @@ export type AppShellProps = {
|
|
|
44
65
|
onOpenChange?: (open: boolean) => void;
|
|
45
66
|
children: React.ReactNode;
|
|
46
67
|
};
|
|
47
|
-
export declare function AppShell({ brand, sections, pathname, renderNavLink, footer, account, headerStart, headerEnd, collapsible, navLabel, defaultOpen, open, onOpenChange, children }: AppShellProps): React.JSX.Element;
|
|
68
|
+
export declare function AppShell({ brand, sections, pathname, renderNavLink, footer, account, headerStart, headerEnd, primaryAction, collapsible, toolbarLabels, navLabel, defaultOpen, open, onOpenChange, children }: AppShellProps): React.JSX.Element;
|
|
@@ -1,52 +1,76 @@
|
|
|
1
1
|
"use client";
|
|
2
|
+
import { cn } from "../lib/cn.js";
|
|
2
3
|
import { isActive } from "../lib/nav.js";
|
|
3
4
|
import { Sidebar, SidebarContent, SidebarFooter, SidebarHeader, SidebarInset, SidebarProvider, SidebarRail, SidebarTrigger, useSidebar } from "./sidebar-core.js";
|
|
4
5
|
import { SidebarGroup, SidebarGroupContent, SidebarGroupLabel, SidebarMenu, SidebarMenuButton, SidebarMenuItem } from "./sidebar-menu.js";
|
|
6
|
+
import { AppToolbar, PeekSidebar, SidebarPeekProvider } from "./sidebar-peek.js";
|
|
5
7
|
import { TooltipProvider } from "./tooltip.js";
|
|
6
8
|
import "react";
|
|
7
9
|
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
8
10
|
// src/components/app-shell.tsx
|
|
9
|
-
function AppShell({ brand, sections, pathname, renderNavLink, footer, account, headerStart, headerEnd, collapsible = "
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
11
|
+
function AppShell({ brand, sections, pathname, renderNavLink, footer, account, headerStart, headerEnd, primaryAction, collapsible = "offcanvas", toolbarLabels, navLabel = "Navegação principal", defaultOpen = true, open, onOpenChange, children }) {
|
|
12
|
+
const peek = collapsible === "offcanvas";
|
|
13
|
+
const desktopBar = !peek || Boolean(headerStart) || Boolean(headerEnd);
|
|
14
|
+
let toolbarRow;
|
|
15
|
+
if (peek) toolbarRow = desktopBar ? "md:pt-14" : "md:pt-12";
|
|
16
|
+
const sidebar = /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
17
|
+
/* @__PURE__ */ jsx(SidebarHeader, {
|
|
18
|
+
className: cn(toolbarRow, !brand && "p-0"),
|
|
19
|
+
children: brand ? /* @__PURE__ */ jsx("div", {
|
|
20
|
+
className: "flex items-center gap-2 px-2 py-1.5",
|
|
21
|
+
children: brand
|
|
22
|
+
}) : null
|
|
23
|
+
}),
|
|
24
|
+
/* @__PURE__ */ jsx(SidebarContent, { children: /* @__PURE__ */ jsx(ShellNav, {
|
|
25
|
+
sections,
|
|
26
|
+
pathname,
|
|
27
|
+
renderNavLink,
|
|
28
|
+
navLabel,
|
|
29
|
+
primaryAction,
|
|
30
|
+
labelTooltips: collapsible === "icon"
|
|
31
|
+
}) }),
|
|
32
|
+
footer ? /* @__PURE__ */ jsx(SidebarFooter, { children: footer }) : null
|
|
33
|
+
] });
|
|
34
|
+
return /* @__PURE__ */ jsx(TooltipProvider, { children: /* @__PURE__ */ jsx(SidebarProvider, {
|
|
35
|
+
defaultOpen,
|
|
36
|
+
open,
|
|
37
|
+
onOpenChange,
|
|
38
|
+
children: /* @__PURE__ */ jsxs(SidebarPeekProvider, { children: [
|
|
39
|
+
peek ? /* @__PURE__ */ jsx(AppToolbar, {
|
|
40
|
+
labels: toolbarLabels,
|
|
41
|
+
className: desktopBar ? "h-14" : "h-12"
|
|
42
|
+
}) : null,
|
|
43
|
+
peek ? /* @__PURE__ */ jsx(PeekSidebar, { children: sidebar }) : /* @__PURE__ */ jsxs(Sidebar, {
|
|
17
44
|
collapsible,
|
|
18
|
-
children: [
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
})] })]
|
|
41
|
-
})
|
|
42
|
-
});
|
|
45
|
+
children: [sidebar, /* @__PURE__ */ jsx(SidebarRail, {})]
|
|
46
|
+
}),
|
|
47
|
+
/* @__PURE__ */ jsxs(SidebarInset, { children: [
|
|
48
|
+
/* @__PURE__ */ jsx(ShellHeader, {
|
|
49
|
+
account,
|
|
50
|
+
headerStart,
|
|
51
|
+
headerEnd,
|
|
52
|
+
toolbar: peek,
|
|
53
|
+
desktop: desktopBar
|
|
54
|
+
}),
|
|
55
|
+
desktopBar ? null : /* @__PURE__ */ jsx("div", {
|
|
56
|
+
"aria-hidden": true,
|
|
57
|
+
className: "hidden h-12 shrink-0 md:block"
|
|
58
|
+
}),
|
|
59
|
+
/* @__PURE__ */ jsx("div", {
|
|
60
|
+
"data-slot": "app-scroll",
|
|
61
|
+
className: "min-h-0 flex-1 [scrollbar-gutter:stable] overflow-y-auto overscroll-contain has-[[data-fills-viewport]]:[scrollbar-gutter:auto]",
|
|
62
|
+
children
|
|
63
|
+
})
|
|
64
|
+
] })
|
|
65
|
+
] })
|
|
66
|
+
}) });
|
|
43
67
|
}
|
|
44
|
-
function ShellHeader({ account, headerStart, headerEnd }) {
|
|
45
|
-
const { isMobile } = useSidebar();
|
|
68
|
+
function ShellHeader({ account, headerStart, headerEnd, toolbar, desktop }) {
|
|
69
|
+
const { isMobile, open } = useSidebar();
|
|
46
70
|
return /* @__PURE__ */ jsxs("header", {
|
|
47
|
-
className: "border-border bg-card/60 z-30 flex h-14 shrink-0 items-center gap-3 border-b px-4 backdrop-blur md:px-6",
|
|
71
|
+
className: cn("border-border bg-card/60 z-30 flex h-14 shrink-0 items-center gap-3 border-b px-4 backdrop-blur md:px-6", toolbar && !open && "md:pl-28", !desktop && "md:hidden"),
|
|
48
72
|
children: [
|
|
49
|
-
/* @__PURE__ */ jsx(SidebarTrigger, {}),
|
|
73
|
+
/* @__PURE__ */ jsx(SidebarTrigger, { className: toolbar ? "md:hidden" : void 0 }),
|
|
50
74
|
headerStart,
|
|
51
75
|
/* @__PURE__ */ jsxs("div", {
|
|
52
76
|
className: "ml-auto flex items-center gap-2",
|
|
@@ -58,20 +82,38 @@ function ShellHeader({ account, headerStart, headerEnd }) {
|
|
|
58
82
|
]
|
|
59
83
|
});
|
|
60
84
|
}
|
|
61
|
-
function ShellNav({ sections, pathname, renderNavLink, navLabel }) {
|
|
85
|
+
function ShellNav({ sections, pathname, renderNavLink, navLabel, primaryAction, labelTooltips }) {
|
|
62
86
|
const { setOpenMobile } = useSidebar();
|
|
63
87
|
const onNavigate = () => setOpenMobile(false);
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
88
|
+
const content = (item) => /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx(item.icon, {}), /* @__PURE__ */ jsx("span", { children: item.label })] });
|
|
89
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [primaryAction ? /* @__PURE__ */ jsx(SidebarGroup, {
|
|
90
|
+
className: "pb-0.5",
|
|
91
|
+
children: /* @__PURE__ */ jsx(SidebarMenu, { children: /* @__PURE__ */ jsx(SidebarMenuItem, { children: /* @__PURE__ */ jsx(SidebarMenuButton, {
|
|
67
92
|
asChild: true,
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
children: renderNavLink(
|
|
93
|
+
tooltip: labelTooltips ? primaryAction.label : void 0,
|
|
94
|
+
className: "bg-primary text-primary-foreground hover:bg-primary/90 hover:text-primary-foreground active:bg-primary/90 active:text-primary-foreground font-medium shadow-xs",
|
|
95
|
+
children: renderNavLink(primaryAction, {
|
|
71
96
|
onNavigate,
|
|
72
|
-
children:
|
|
97
|
+
children: content(primaryAction)
|
|
73
98
|
})
|
|
74
|
-
}) }
|
|
75
|
-
})
|
|
99
|
+
}) }) })
|
|
100
|
+
}) : null, /* @__PURE__ */ jsx("nav", {
|
|
101
|
+
"aria-label": navLabel,
|
|
102
|
+
children: sections.map((section, index) => /* @__PURE__ */ jsxs(SidebarGroup, {
|
|
103
|
+
className: primaryAction && index === 0 ? "pt-0" : void 0,
|
|
104
|
+
children: [section.label ? /* @__PURE__ */ jsx(SidebarGroupLabel, { children: section.label }) : null, /* @__PURE__ */ jsx(SidebarGroupContent, { children: /* @__PURE__ */ jsx(SidebarMenu, {
|
|
105
|
+
className: "gap-0.5",
|
|
106
|
+
children: section.items.map((item) => /* @__PURE__ */ jsx(SidebarMenuItem, { children: /* @__PURE__ */ jsx(SidebarMenuButton, {
|
|
107
|
+
asChild: true,
|
|
108
|
+
isActive: isActive(item, pathname),
|
|
109
|
+
tooltip: labelTooltips ? item.label : void 0,
|
|
110
|
+
children: renderNavLink(item, {
|
|
111
|
+
onNavigate,
|
|
112
|
+
children: content(item)
|
|
113
|
+
})
|
|
114
|
+
}) }, item.href))
|
|
115
|
+
}) })]
|
|
116
|
+
}, section.label))
|
|
117
|
+
})] });
|
|
76
118
|
}
|
|
77
119
|
export { AppShell };
|
|
@@ -1,10 +1,15 @@
|
|
|
1
1
|
import * as React from "react";
|
|
2
2
|
import { Avatar as Avatar$1 } from "radix-ui";
|
|
3
|
-
declare function Avatar({ className, size, ...props }: React.ComponentProps<typeof Avatar$1.Root> & {
|
|
3
|
+
declare function Avatar({ className, size, shape, ...props }: React.ComponentProps<typeof Avatar$1.Root> & {
|
|
4
4
|
size?: 'default' | 'sm' | 'lg';
|
|
5
|
+
/** `square` (rounded corners) for things that are not people: a business, a space. */
|
|
6
|
+
shape?: 'circle' | 'square';
|
|
5
7
|
}): React.JSX.Element;
|
|
6
8
|
declare function AvatarImage({ className, ...props }: React.ComponentProps<typeof Avatar$1.Image>): React.JSX.Element;
|
|
7
|
-
declare function AvatarFallback({ className, ...props }: React.ComponentProps<typeof Avatar$1.Fallback>
|
|
9
|
+
declare function AvatarFallback({ className, colorSeed, ...props }: React.ComponentProps<typeof Avatar$1.Fallback> & {
|
|
10
|
+
/** A stable id (e.g. a business id): paints the fallback with its own color. */
|
|
11
|
+
colorSeed?: string;
|
|
12
|
+
}): React.JSX.Element;
|
|
8
13
|
declare function AvatarBadge({ className, ...props }: React.ComponentProps<'span'>): React.JSX.Element;
|
|
9
14
|
type AvatarGroupProps = React.ComponentProps<'div'> & {
|
|
10
15
|
/**
|
|
@@ -4,25 +4,47 @@ import * as React from "react";
|
|
|
4
4
|
import { Avatar as Avatar$1 } from "radix-ui";
|
|
5
5
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
6
6
|
// src/components/avatar.tsx
|
|
7
|
-
function Avatar({ className, size = "default", ...props }) {
|
|
7
|
+
function Avatar({ className, size = "default", shape = "circle", ...props }) {
|
|
8
8
|
return /* @__PURE__ */ jsx(Avatar$1.Root, {
|
|
9
9
|
"data-slot": "avatar",
|
|
10
10
|
"data-size": size,
|
|
11
|
-
|
|
11
|
+
"data-shape": shape,
|
|
12
|
+
className: cn("group/avatar after:border-border relative flex size-8 shrink-0 rounded-full select-none after:absolute after:inset-0 after:rounded-full after:border after:mix-blend-darken data-[size=lg]:size-10 data-[size=sm]:size-6 dark:after:mix-blend-lighten", "data-[shape=square]:rounded-md data-[shape=square]:after:rounded-md", className),
|
|
12
13
|
...props
|
|
13
14
|
});
|
|
14
15
|
}
|
|
15
16
|
function AvatarImage({ className, ...props }) {
|
|
16
17
|
return /* @__PURE__ */ jsx(Avatar$1.Image, {
|
|
17
18
|
"data-slot": "avatar-image",
|
|
18
|
-
className: cn("aspect-square size-full rounded-full object-cover", className),
|
|
19
|
+
className: cn("aspect-square size-full rounded-full object-cover group-data-[shape=square]/avatar:rounded-md", className),
|
|
19
20
|
...props
|
|
20
21
|
});
|
|
21
22
|
}
|
|
22
|
-
|
|
23
|
+
/**
|
|
24
|
+
* Fallback colors picked by `colorSeed`: solid enough to tell items apart at a
|
|
25
|
+
* glance (e.g. which business is active), readable with white initials in
|
|
26
|
+
* both themes.
|
|
27
|
+
*/
|
|
28
|
+
const AVATAR_COLORS = [
|
|
29
|
+
"bg-sky-600 text-white",
|
|
30
|
+
"bg-emerald-600 text-white",
|
|
31
|
+
"bg-amber-600 text-white",
|
|
32
|
+
"bg-rose-600 text-white",
|
|
33
|
+
"bg-violet-600 text-white",
|
|
34
|
+
"bg-teal-600 text-white",
|
|
35
|
+
"bg-orange-600 text-white",
|
|
36
|
+
"bg-indigo-600 text-white"
|
|
37
|
+
];
|
|
38
|
+
/** Stable palette index for a seed (same seed, same color, everywhere). */
|
|
39
|
+
function avatarColorIndex(seed) {
|
|
40
|
+
let hash = 0;
|
|
41
|
+
for (const char of seed) hash = hash * 31 + char.charCodeAt(0) >>> 0;
|
|
42
|
+
return hash % AVATAR_COLORS.length;
|
|
43
|
+
}
|
|
44
|
+
function AvatarFallback({ className, colorSeed, ...props }) {
|
|
23
45
|
return /* @__PURE__ */ jsx(Avatar$1.Fallback, {
|
|
24
46
|
"data-slot": "avatar-fallback",
|
|
25
|
-
className: cn("bg-muted text-muted-foreground flex size-full items-center justify-center rounded-full text-sm group-data-[size=sm]/avatar:text-xs", className),
|
|
47
|
+
className: cn("bg-muted text-muted-foreground flex size-full items-center justify-center rounded-full text-sm group-data-[shape=square]/avatar:rounded-md group-data-[size=sm]/avatar:text-xs", colorSeed === void 0 ? void 0 : AVATAR_COLORS[avatarColorIndex(colorSeed)], className),
|
|
26
48
|
...props
|
|
27
49
|
});
|
|
28
50
|
}
|
|
@@ -55,4 +77,4 @@ function AvatarGroupCount({ className, ...props }) {
|
|
|
55
77
|
...props
|
|
56
78
|
});
|
|
57
79
|
}
|
|
58
|
-
export { Avatar, AvatarBadge, AvatarFallback, AvatarGroup, AvatarGroupCount, AvatarImage };
|
|
80
|
+
export { Avatar, AvatarBadge, AvatarFallback, AvatarGroup, AvatarGroupCount, AvatarImage, avatarColorIndex };
|
|
@@ -7,7 +7,11 @@ declare function DropdownMenuContent({ className, align, sideOffset, ...props }:
|
|
|
7
7
|
declare function DropdownMenuGroup({ ...props }: React.ComponentProps<typeof DropdownMenu$1.Group>): React.JSX.Element;
|
|
8
8
|
declare function DropdownMenuItem({ className, inset, variant, ...props }: React.ComponentProps<typeof DropdownMenu$1.Item> & {
|
|
9
9
|
inset?: boolean;
|
|
10
|
-
|
|
10
|
+
/**
|
|
11
|
+
* `highlight`: blue label and icon on the usual background, for the menu's
|
|
12
|
+
* creation action (e.g. "Novo negócio…"), as in Notion.
|
|
13
|
+
*/
|
|
14
|
+
variant?: 'default' | 'destructive' | 'highlight';
|
|
11
15
|
}): React.JSX.Element;
|
|
12
16
|
declare function DropdownMenuCheckboxItem({ className, children, checked, inset, ...props }: React.ComponentProps<typeof DropdownMenu$1.CheckboxItem> & {
|
|
13
17
|
inset?: boolean;
|
|
@@ -43,7 +43,7 @@ function DropdownMenuItem({ className, inset, variant = "default", ...props }) {
|
|
|
43
43
|
"data-slot": "dropdown-menu-item",
|
|
44
44
|
"data-inset": inset,
|
|
45
45
|
"data-variant": variant,
|
|
46
|
-
className: cn("group/dropdown-menu-item focus:bg-accent focus:text-accent-foreground
|
|
46
|
+
className: cn("group/dropdown-menu-item focus:bg-accent data-[variant=default]:focus:text-accent-foreground data-[variant=default]:focus:**:text-accent-foreground data-[variant=highlight]:text-blue-600 dark:data-[variant=highlight]:text-blue-400 data-[variant=highlight]:*:[svg]:text-current data-[variant=destructive]:text-destructive data-[variant=destructive]:focus:bg-destructive/10 data-[variant=destructive]:focus:text-destructive dark:data-[variant=destructive]:focus:bg-destructive/20 data-[variant=destructive]:*:[svg]:text-destructive relative flex cursor-default items-center gap-1.5 rounded-md px-1.5 py-1 text-sm outline-hidden select-none data-disabled:pointer-events-none data-disabled:opacity-50 data-inset:pl-7 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4", className),
|
|
47
47
|
...props
|
|
48
48
|
});
|
|
49
49
|
}
|
|
@@ -112,7 +112,7 @@ function DropdownMenuSubTrigger({ className, inset, children, ...props }) {
|
|
|
112
112
|
return /* @__PURE__ */ jsxs(DropdownMenu$1.SubTrigger, {
|
|
113
113
|
"data-slot": "dropdown-menu-sub-trigger",
|
|
114
114
|
"data-inset": inset,
|
|
115
|
-
className: cn("focus:bg-accent focus:text-accent-foreground
|
|
115
|
+
className: cn("focus:bg-accent data-[variant=default]:focus:text-accent-foreground data-[variant=default]:focus:**:text-accent-foreground data-[variant=highlight]:text-blue-600 dark:data-[variant=highlight]:text-blue-400 data-[variant=highlight]:*:[svg]:text-current data-open:bg-accent data-open:text-accent-foreground flex cursor-default items-center gap-1.5 rounded-md px-1.5 py-1 text-sm outline-hidden select-none data-inset:pl-7 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4", className),
|
|
116
116
|
...props,
|
|
117
117
|
children: [children, /* @__PURE__ */ jsx(ChevronRightIcon, { className: "ml-auto" })]
|
|
118
118
|
});
|