@cbrl/design 0.8.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 +153 -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/container.d.ts +19 -0
- package/dist/components/container.js +46 -0
- package/dist/components/dialog.d.ts +6 -2
- package/dist/components/dialog.js +4 -4
- package/dist/components/dropdown-menu.d.ts +5 -1
- package/dist/components/dropdown-menu.js +2 -2
- package/dist/components/page-header.d.ts +24 -0
- package/dist/components/page-header.js +42 -0
- package/dist/components/settings-dialog.d.ts +65 -10
- package/dist/components/settings-dialog.js +210 -29
- package/dist/components/sheet.d.ts +3 -1
- package/dist/components/sheet.js +2 -2
- 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/theme-toggle.d.ts +22 -0
- package/dist/components/theme-toggle.js +60 -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 +10 -3
- package/dist/index.js +10 -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>
|
|
@@ -181,12 +183,79 @@ import { ChevronDown } from 'lucide-react'
|
|
|
181
183
|
</ButtonGroup>
|
|
182
184
|
```
|
|
183
185
|
|
|
186
|
+
### Page layout
|
|
187
|
+
|
|
188
|
+
`Container` centers content and caps its width; `gutter` adds the horizontal
|
|
189
|
+
padding (vertical spacing stays with the caller). Use `asChild` to render a
|
|
190
|
+
semantic element.
|
|
191
|
+
|
|
192
|
+
| `size` | max width | | `gutter` | padding |
|
|
193
|
+
| ------- | ---------------- | --- | -------- | ------------------------ |
|
|
194
|
+
| `prose` | 840px | | `none` | — (default) |
|
|
195
|
+
| `sm` | 1120px | | `sm` | `px-6` |
|
|
196
|
+
| `md` | 1200px (default) | | `md` | `px-6 sm:px-10 lg:px-14` |
|
|
197
|
+
| `lg` | 1280px | | | |
|
|
198
|
+
| `xl` | 1600px | | | |
|
|
199
|
+
|
|
200
|
+
```tsx
|
|
201
|
+
import { Container, PageHeader, PageHeaderSkeleton, Button } from '@cbrl/design'
|
|
202
|
+
|
|
203
|
+
<Container asChild size="xl" className="px-4 py-5 md:px-6 md:py-8">
|
|
204
|
+
<main>
|
|
205
|
+
<PageHeader
|
|
206
|
+
title="Imóveis"
|
|
207
|
+
description="Gerencie seus imóveis."
|
|
208
|
+
actions={<Button>Novo imóvel</Button>}
|
|
209
|
+
className="mb-6 md:mb-8"
|
|
210
|
+
/>
|
|
211
|
+
</main>
|
|
212
|
+
</Container>
|
|
213
|
+
|
|
214
|
+
// loading.tsx
|
|
215
|
+
<PageHeaderSkeleton titleWidth="w-32" descriptionWidth={null} />
|
|
216
|
+
```
|
|
217
|
+
|
|
218
|
+
### Theme toggle
|
|
219
|
+
|
|
220
|
+
`ThemeToggle` flips light/dark through `next-themes` (mount `ThemeProvider`).
|
|
221
|
+
`variant="icon"` (default) is a ghost sun/moon button; `variant="text"` is a mono
|
|
222
|
+
uppercase label. Labels default to pt-BR and are overridable via `labels`.
|
|
223
|
+
|
|
224
|
+
```tsx
|
|
225
|
+
<ThemeToggle
|
|
226
|
+
variant="text"
|
|
227
|
+
labels={{
|
|
228
|
+
light: 'light',
|
|
229
|
+
dark: 'dark',
|
|
230
|
+
switchToLight: 'Switch to light theme',
|
|
231
|
+
switchToDark: 'Switch to dark theme',
|
|
232
|
+
}}
|
|
233
|
+
/>
|
|
234
|
+
```
|
|
235
|
+
|
|
236
|
+
`SheetContent`, `DialogContent` and `DialogFooter` take `closeLabel` to localize
|
|
237
|
+
their built-in close button (default `"Close"`).
|
|
238
|
+
|
|
184
239
|
### App shell
|
|
185
240
|
|
|
186
241
|
`AppShell` renders the whole authenticated layout (collapsible sidebar with brand,
|
|
187
242
|
grouped navigation and footer, sticky header, content inset). Routing stays in
|
|
188
243
|
the app: you render each nav link, so the package never imports `next`.
|
|
189
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
|
+
|
|
190
259
|
```tsx
|
|
191
260
|
'use client'
|
|
192
261
|
|
|
@@ -220,9 +289,16 @@ export function AppShell({ children }: { children: React.ReactNode }) {
|
|
|
220
289
|
}
|
|
221
290
|
```
|
|
222
291
|
|
|
223
|
-
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
|
|
224
296
|
mobile drawer and tooltips when collapsed. The sidebar primitives (`Sidebar`,
|
|
225
|
-
`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.
|
|
226
302
|
|
|
227
303
|
### Tabs and scrolling strips
|
|
228
304
|
|
|
@@ -256,44 +332,97 @@ return <div ref={ref}>{width > 480 ? <Wide /> : <Narrow />}</div>
|
|
|
256
332
|
|
|
257
333
|
### Settings dialog
|
|
258
334
|
|
|
259
|
-
`SettingsDialog` is the settings
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
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):
|
|
266
352
|
|
|
267
353
|
```tsx
|
|
268
354
|
'use client'
|
|
269
355
|
|
|
270
|
-
import {
|
|
271
|
-
|
|
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'
|
|
272
367
|
|
|
273
|
-
type Key = '
|
|
368
|
+
type Key = 'conta' | 'aparencia' | 'cobranca'
|
|
274
369
|
const SECTIONS: readonly SettingsDialogSection<Key>[] = [
|
|
275
|
-
{ key: '
|
|
276
|
-
{ 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' },
|
|
277
373
|
]
|
|
278
374
|
|
|
279
|
-
export function SettingsModal() {
|
|
280
|
-
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
|
+
])
|
|
281
381
|
return (
|
|
282
382
|
<SettingsDialog
|
|
283
383
|
open={section !== null}
|
|
284
384
|
onOpenChange={(next) => !next && close()}
|
|
285
385
|
sections={SECTIONS}
|
|
286
|
-
value={section ?? '
|
|
386
|
+
value={section ?? 'conta'}
|
|
287
387
|
onValueChange={open}
|
|
288
|
-
navLabel="Seções de configuração"
|
|
289
388
|
>
|
|
290
|
-
{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 />}
|
|
291
398
|
</SettingsDialog>
|
|
292
399
|
)
|
|
293
400
|
}
|
|
294
|
-
// Anywhere: <a href="#
|
|
401
|
+
// Anywhere: <a href="#configuracoes/cobranca">Cobrança</a>
|
|
295
402
|
```
|
|
296
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
|
+
|
|
297
426
|
Next.js App Router: a fragment-only navigation (plain `<a href="#…">`, a typed
|
|
298
427
|
URL) bypasses the router, whose history sync then rewrites the URL without the
|
|
299
428
|
hash and would close the dialog at once. The hook re-states the URL through
|
|
@@ -301,7 +430,8 @@ hash and would close the dialog at once. The hook re-states the URL through
|
|
|
301
430
|
`open`/`close`) so the router adopts it; outside Next this is a no-op.
|
|
302
431
|
|
|
303
432
|
Uncontrolled use: `defaultOpen`/`defaultValue`. Slots: `settings-dialog`,
|
|
304
|
-
`settings-dialog-nav`, `settings-dialog-content
|
|
433
|
+
`settings-dialog-nav`, `settings-dialog-content`, `settings-group`,
|
|
434
|
+
`settings-item`.
|
|
305
435
|
|
|
306
436
|
### Forms (react-hook-form)
|
|
307
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 };
|