@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.
Files changed (40) hide show
  1. package/README.md +153 -23
  2. package/dist/components/account-settings.d.ts +24 -0
  3. package/dist/components/account-settings.js +49 -0
  4. package/dist/components/alert-dialog.d.ts +5 -1
  5. package/dist/components/alert-dialog.js +2 -2
  6. package/dist/components/app-shell.d.ts +25 -4
  7. package/dist/components/app-shell.js +89 -47
  8. package/dist/components/avatar.d.ts +7 -2
  9. package/dist/components/avatar.js +28 -6
  10. package/dist/components/container.d.ts +19 -0
  11. package/dist/components/container.js +46 -0
  12. package/dist/components/dialog.d.ts +6 -2
  13. package/dist/components/dialog.js +4 -4
  14. package/dist/components/dropdown-menu.d.ts +5 -1
  15. package/dist/components/dropdown-menu.js +2 -2
  16. package/dist/components/page-header.d.ts +24 -0
  17. package/dist/components/page-header.js +42 -0
  18. package/dist/components/settings-dialog.d.ts +65 -10
  19. package/dist/components/settings-dialog.js +210 -29
  20. package/dist/components/sheet.d.ts +3 -1
  21. package/dist/components/sheet.js +2 -2
  22. package/dist/components/sidebar-core.js +5 -5
  23. package/dist/components/sidebar-peek.d.ts +40 -0
  24. package/dist/components/sidebar-peek.js +204 -0
  25. package/dist/components/table.d.ts +8 -1
  26. package/dist/components/table.js +5 -4
  27. package/dist/components/theme-provider.d.ts +1 -1
  28. package/dist/components/theme-provider.js +4 -1
  29. package/dist/components/theme-setting.d.ts +12 -0
  30. package/dist/components/theme-setting.js +66 -0
  31. package/dist/components/theme-toggle.d.ts +22 -0
  32. package/dist/components/theme-toggle.js +60 -0
  33. package/dist/components/tooltip.js +7 -1
  34. package/dist/components/user-menu.d.ts +17 -0
  35. package/dist/components/user-menu.js +38 -11
  36. package/dist/hooks/use-autosave-form.d.ts +36 -0
  37. package/dist/hooks/use-autosave-form.js +81 -0
  38. package/dist/index.d.ts +10 -3
  39. package/dist/index.js +10 -3
  40. package/package.json +1 -1
@@ -12,7 +12,7 @@ import { PanelLeftIcon } from "lucide-react";
12
12
  // src/components/sidebar-core.tsx
13
13
  const SIDEBAR_COOKIE_NAME = "sidebar_state";
14
14
  const SIDEBAR_COOKIE_MAX_AGE = 604800;
15
- const SIDEBAR_WIDTH = "14rem";
15
+ const SIDEBAR_WIDTH = "20rem";
16
16
  const SIDEBAR_WIDTH_MOBILE = "18rem";
17
17
  const SIDEBAR_WIDTH_ICON = "3rem";
18
18
  const SIDEBAR_KEYBOARD_SHORTCUT = "b";
@@ -107,7 +107,7 @@ function Sidebar({ side = "left", variant = "sidebar", collapsible = "offcanvas"
107
107
  side,
108
108
  children: [/* @__PURE__ */ jsxs(SheetHeader, {
109
109
  className: "sr-only",
110
- children: [/* @__PURE__ */ jsx(SheetTitle, { children: "Sidebar" }), /* @__PURE__ */ jsx(SheetDescription, { children: "Displays the mobile sidebar." })]
110
+ children: [/* @__PURE__ */ jsx(SheetTitle, { children: "Barra lateral" }), /* @__PURE__ */ jsx(SheetDescription, { children: "Navegação do aplicativo." })]
111
111
  }), /* @__PURE__ */ jsx("div", {
112
112
  className: "flex h-full w-full flex-col",
113
113
  children
@@ -153,7 +153,7 @@ function SidebarTrigger({ className, onClick, ...props }) {
153
153
  ...props,
154
154
  children: [/* @__PURE__ */ jsx(PanelLeftIcon, {}), /* @__PURE__ */ jsx("span", {
155
155
  className: "sr-only",
156
- children: "Toggle Sidebar"
156
+ children: "Alternar barra lateral"
157
157
  })]
158
158
  });
159
159
  }
@@ -162,10 +162,10 @@ function SidebarRail({ className, ...props }) {
162
162
  return /* @__PURE__ */ jsx("button", {
163
163
  "data-sidebar": "rail",
164
164
  "data-slot": "sidebar-rail",
165
- "aria-label": "Toggle Sidebar",
165
+ "aria-label": "Alternar barra lateral",
166
166
  tabIndex: -1,
167
167
  onClick: toggleSidebar,
168
- title: "Toggle Sidebar",
168
+ title: "Alternar barra lateral",
169
169
  className: cn("hover:after:bg-sidebar-border absolute inset-y-0 z-20 hidden w-4 transition-all ease-linear group-data-[side=left]:-right-4 group-data-[side=right]:left-0 after:absolute after:inset-y-0 after:start-1/2 after:w-[2px] sm:flex ltr:-translate-x-1/2 rtl:-translate-x-1/2", "in-data-[side=left]:cursor-w-resize in-data-[side=right]:cursor-e-resize", "[[data-side=left][data-state=collapsed]_&]:cursor-e-resize [[data-side=right][data-state=collapsed]_&]:cursor-w-resize", "hover:group-data-[collapsible=offcanvas]:bg-sidebar group-data-[collapsible=offcanvas]:translate-x-0 group-data-[collapsible=offcanvas]:after:left-full", "[[data-side=left][data-collapsible=offcanvas]_&]:-right-2", "[[data-side=right][data-collapsible=offcanvas]_&]:-left-2", className),
170
170
  ...props
171
171
  });
@@ -0,0 +1,40 @@
1
+ import { Sidebar } from "./sidebar-core.js";
2
+ import "./sidebar.js";
3
+ import * as React from "react";
4
+ /** Whether the collapsed sidebar is peeking over the content right now. */
5
+ export declare function useSidebarPeek(): {
6
+ peeking: boolean;
7
+ };
8
+ /** Goes inside `SidebarProvider`, around `PeekSidebar` and `AppToolbar`. */
9
+ export declare function SidebarPeekProvider({ children }: {
10
+ children: React.ReactNode;
11
+ }): React.JSX.Element;
12
+ /**
13
+ * The DS `Sidebar`, off-canvas when collapsed, that slides in over the
14
+ * content while peeking. Its rail starts a peek from the window's left edge.
15
+ */
16
+ export declare function PeekSidebar({ className, children, ...props }: React.ComponentProps<typeof Sidebar>): React.JSX.Element;
17
+ export type AppToolbarLabels = {
18
+ show: string;
19
+ hide: string;
20
+ back: string;
21
+ forward: string;
22
+ /** Shortcut hint in the toggle's tooltip. */
23
+ shortcut: string;
24
+ };
25
+ /** Space the fixed toolbar takes on top of the sidebar and the content (md+). */
26
+ export declare const APP_TOOLBAR_HEIGHT = "h-12";
27
+ /**
28
+ * Fixed on the top left (md+): the sidebar toggle (hover peeks, click pins)
29
+ * and the history back/forward buttons. Leave `APP_TOOLBAR_HEIGHT` free at the
30
+ * top of the sidebar and of the content.
31
+ */
32
+ export declare function AppToolbar({ labels: labelsProp, onBack, onForward, className }: {
33
+ labels?: Partial<AppToolbarLabels>;
34
+ /** Replaces the browser's history back (the button then stays enabled). */
35
+ onBack?: () => void;
36
+ /** Replaces the browser's history forward (the button then stays enabled). */
37
+ onForward?: () => void;
38
+ /** E.g. `h-14` to line up with a 56px header (default `h-12`). */
39
+ className?: string;
40
+ }): React.JSX.Element;
@@ -0,0 +1,204 @@
1
+ "use client";
2
+ import { cn } from "../lib/cn.js";
3
+ import { Button } from "./button.js";
4
+ import { Sidebar, SidebarRail, useSidebar } from "./sidebar-core.js";
5
+ import { Tooltip, TooltipContent, TooltipTrigger } from "./tooltip.js";
6
+ import * as React from "react";
7
+ import { jsx, jsxs } from "react/jsx-runtime";
8
+ import { ChevronLeft, ChevronRight, PanelLeft } from "lucide-react";
9
+ // src/components/sidebar-peek.tsx
10
+ /** Pointer grace before a peek closes (crossing gaps, small overshoots). */
11
+ const PEEK_CLOSE_DELAY = 250;
12
+ /** A menu (or popover) opened from the sidebar is on screen: its trigger is open. */
13
+ function hasOpenPopup(container) {
14
+ return container?.querySelector("[data-state=\"open\"]") != null;
15
+ }
16
+ /** A click inside the sidebar or inside a popup it opened (portaled content). */
17
+ function isInsidePeek(target, container) {
18
+ if (!(target instanceof Element)) return false;
19
+ return (container?.contains(target) ?? false) || target.closest("[data-radix-popper-content-wrapper]") !== null;
20
+ }
21
+ const PeekContext = React.createContext(null);
22
+ function usePeek() {
23
+ const peek = React.useContext(PeekContext);
24
+ if (peek === null) throw new Error("usePeek must be used within <SidebarPeekProvider>");
25
+ return peek;
26
+ }
27
+ /** Whether the collapsed sidebar is peeking over the content right now. */
28
+ function useSidebarPeek() {
29
+ return { peeking: usePeek().peeking };
30
+ }
31
+ /** Goes inside `SidebarProvider`, around `PeekSidebar` and `AppToolbar`. */
32
+ function SidebarPeekProvider({ children }) {
33
+ const { open, isMobile } = useSidebar();
34
+ const [peeking, setPeeking] = React.useState(false);
35
+ const timer = React.useRef(null);
36
+ const containerRef = React.useRef(null);
37
+ const outsideClick = React.useRef(null);
38
+ const stopHolding = () => {
39
+ if (outsideClick.current !== null) document.removeEventListener("pointerdown", outsideClick.current, true);
40
+ outsideClick.current = null;
41
+ };
42
+ const clear = () => {
43
+ if (timer.current !== null) clearTimeout(timer.current);
44
+ timer.current = null;
45
+ stopHolding();
46
+ };
47
+ const holdUntilOutsideClick = () => {
48
+ stopHolding();
49
+ const listener = (event) => {
50
+ if (isInsidePeek(event.target, containerRef.current)) return;
51
+ stopHolding();
52
+ setPeeking(false);
53
+ };
54
+ outsideClick.current = listener;
55
+ document.addEventListener("pointerdown", listener, true);
56
+ };
57
+ const value = React.useMemo(() => ({
58
+ peeking: peeking && !open && !isMobile,
59
+ show: () => {
60
+ clear();
61
+ setPeeking(true);
62
+ },
63
+ hideSoon: () => {
64
+ clear();
65
+ timer.current = setTimeout(() => {
66
+ timer.current = null;
67
+ if (hasOpenPopup(containerRef.current)) holdUntilOutsideClick();
68
+ else setPeeking(false);
69
+ }, PEEK_CLOSE_DELAY);
70
+ },
71
+ hideNow: () => {
72
+ clear();
73
+ setPeeking(false);
74
+ },
75
+ containerRef
76
+ }), [
77
+ peeking,
78
+ open,
79
+ isMobile
80
+ ]);
81
+ React.useEffect(() => clear, []);
82
+ return /* @__PURE__ */ jsx(PeekContext.Provider, {
83
+ value,
84
+ children
85
+ });
86
+ }
87
+ /**
88
+ * The DS `Sidebar`, off-canvas when collapsed, that slides in over the
89
+ * content while peeking. Its rail starts a peek from the window's left edge.
90
+ */
91
+ function PeekSidebar({ className, children, ...props }) {
92
+ const { open } = useSidebar();
93
+ const { peeking, show, hideSoon, containerRef } = usePeek();
94
+ return /* @__PURE__ */ jsxs(Sidebar, {
95
+ ref: containerRef,
96
+ collapsible: "offcanvas",
97
+ "data-peeking": peeking || void 0,
98
+ onMouseEnter: peeking ? show : void 0,
99
+ onMouseLeave: peeking ? hideSoon : void 0,
100
+ className: cn(peeking && "!left-0 z-40 shadow-xl", className),
101
+ ...props,
102
+ children: [children, /* @__PURE__ */ jsx(SidebarRail, { onMouseEnter: open ? void 0 : show })]
103
+ });
104
+ }
105
+ const DEFAULT_TOOLBAR_LABELS = {
106
+ show: "Mostrar barra lateral",
107
+ hide: "Ocultar barra lateral",
108
+ back: "Voltar",
109
+ forward: "Avançar",
110
+ shortcut: "Ctrl+B"
111
+ };
112
+ const browserNavigation = () => window.navigation;
113
+ const subscribeHistory = (onChange) => {
114
+ const navigation = browserNavigation();
115
+ navigation?.addEventListener("currententrychange", onChange);
116
+ return () => navigation?.removeEventListener("currententrychange", onChange);
117
+ };
118
+ const historySnapshot = () => {
119
+ const navigation = browserNavigation();
120
+ if (navigation === void 0) return "?";
121
+ return `${navigation.canGoBack ? 1 : 0}|${navigation.canGoForward ? 1 : 0}`;
122
+ };
123
+ /**
124
+ * Whether the browser history can go back / forward, from the Navigation API
125
+ * (`navigation.canGoBack` / `canGoForward`, updated on every entry change —
126
+ * router pushes included). Router-agnostic: it reads the browser, not the app.
127
+ */
128
+ function useHistoryMoves() {
129
+ const snapshot = React.useSyncExternalStore(subscribeHistory, historySnapshot, () => "?");
130
+ if (snapshot === "?") return {
131
+ back: true,
132
+ forward: true
133
+ };
134
+ return {
135
+ back: snapshot.startsWith("1"),
136
+ forward: snapshot.endsWith("1")
137
+ };
138
+ }
139
+ /** Space the fixed toolbar takes on top of the sidebar and the content (md+). */
140
+ const APP_TOOLBAR_HEIGHT = "h-12";
141
+ /**
142
+ * Fixed on the top left (md+): the sidebar toggle (hover peeks, click pins)
143
+ * and the history back/forward buttons. Leave `APP_TOOLBAR_HEIGHT` free at the
144
+ * top of the sidebar and of the content.
145
+ */
146
+ function AppToolbar({ labels: labelsProp, onBack, onForward, className }) {
147
+ const labels = {
148
+ ...DEFAULT_TOOLBAR_LABELS,
149
+ ...labelsProp
150
+ };
151
+ const { open, toggleSidebar } = useSidebar();
152
+ const { show, hideSoon, hideNow } = usePeek();
153
+ const toggleLabel = open ? labels.hide : labels.show;
154
+ const moves = useHistoryMoves();
155
+ return /* @__PURE__ */ jsxs("div", {
156
+ "data-slot": "app-toolbar",
157
+ className: cn("fixed top-0 left-0 z-50 hidden items-center gap-0.5 px-2 md:flex", APP_TOOLBAR_HEIGHT, className),
158
+ children: [
159
+ /* @__PURE__ */ jsxs(Tooltip, { children: [/* @__PURE__ */ jsx(TooltipTrigger, {
160
+ asChild: true,
161
+ children: /* @__PURE__ */ jsx(Button, {
162
+ variant: "ghost",
163
+ size: "icon-sm",
164
+ "aria-label": toggleLabel,
165
+ "aria-expanded": open,
166
+ onMouseEnter: open ? void 0 : show,
167
+ onMouseLeave: open ? void 0 : hideSoon,
168
+ onClick: () => {
169
+ hideNow();
170
+ toggleSidebar();
171
+ },
172
+ children: /* @__PURE__ */ jsx(PanelLeft, { "aria-hidden": true })
173
+ })
174
+ }), /* @__PURE__ */ jsxs(TooltipContent, {
175
+ side: "right",
176
+ children: [
177
+ toggleLabel,
178
+ " ",
179
+ /* @__PURE__ */ jsx("kbd", {
180
+ className: "ml-1 opacity-70",
181
+ children: labels.shortcut
182
+ })
183
+ ]
184
+ })] }),
185
+ /* @__PURE__ */ jsx(Button, {
186
+ variant: "ghost",
187
+ size: "icon-sm",
188
+ "aria-label": labels.back,
189
+ disabled: onBack === void 0 && !moves.back,
190
+ onClick: onBack ?? (() => window.history.back()),
191
+ children: /* @__PURE__ */ jsx(ChevronLeft, { "aria-hidden": true })
192
+ }),
193
+ /* @__PURE__ */ jsx(Button, {
194
+ variant: "ghost",
195
+ size: "icon-sm",
196
+ "aria-label": labels.forward,
197
+ disabled: onForward === void 0 && !moves.forward,
198
+ onClick: onForward ?? (() => window.history.forward()),
199
+ children: /* @__PURE__ */ jsx(ChevronRight, { "aria-hidden": true })
200
+ })
201
+ ]
202
+ });
203
+ }
204
+ export { APP_TOOLBAR_HEIGHT, AppToolbar, PeekSidebar, SidebarPeekProvider, hasOpenPopup, isInsidePeek, useSidebarPeek };
@@ -1,5 +1,12 @@
1
1
  import * as React from "react";
2
- declare function Table({ className, ...props }: React.ComponentProps<'table'>): React.JSX.Element;
2
+ declare function Table({ className, variant, ...props }: React.ComponentProps<'table'> & {
3
+ /**
4
+ * `settings`: a table inside a settings group, as in the Claude app's
5
+ * "where you signed in" list — small muted header, 44px rows, edges aligned
6
+ * with the group (no side padding on the first/last column), no hover fill.
7
+ */
8
+ variant?: 'default' | 'settings';
9
+ }): React.JSX.Element;
3
10
  declare function TableHeader({ className, ...props }: React.ComponentProps<'thead'>): React.JSX.Element;
4
11
  declare function TableBody({ className, ...props }: React.ComponentProps<'tbody'>): React.JSX.Element;
5
12
  declare function TableFooter({ className, ...props }: React.ComponentProps<'tfoot'>): React.JSX.Element;
@@ -2,12 +2,13 @@ import { cn } from "../lib/cn.js";
2
2
  import "react";
3
3
  import { jsx } from "react/jsx-runtime";
4
4
  // src/components/table.tsx
5
- function Table({ className, ...props }) {
5
+ function Table({ className, variant = "default", ...props }) {
6
6
  return /* @__PURE__ */ jsx("div", {
7
7
  "data-slot": "table-container",
8
8
  className: "relative w-full overflow-x-auto",
9
9
  children: /* @__PURE__ */ jsx("table", {
10
10
  "data-slot": "table",
11
+ "data-variant": variant,
11
12
  className: cn("w-full caption-bottom text-sm", className),
12
13
  ...props
13
14
  })
@@ -37,21 +38,21 @@ function TableFooter({ className, ...props }) {
37
38
  function TableRow({ className, ...props }) {
38
39
  return /* @__PURE__ */ jsx("tr", {
39
40
  "data-slot": "table-row",
40
- className: cn("hover:bg-muted/50 data-[state=selected]:bg-muted border-b transition-colors", className),
41
+ className: cn("hover:bg-muted/50 data-[state=selected]:bg-muted border-b transition-colors in-data-[variant=settings]:hover:bg-transparent", className),
41
42
  ...props
42
43
  });
43
44
  }
44
45
  function TableHead({ className, ...props }) {
45
46
  return /* @__PURE__ */ jsx("th", {
46
47
  "data-slot": "table-head",
47
- className: cn("text-muted-foreground h-10 px-2 text-left align-middle font-medium whitespace-nowrap [&:has([role=checkbox])]:pr-0 [&>[role=checkbox]]:translate-y-[2px]", className),
48
+ className: cn("text-muted-foreground h-10 px-2 text-left align-middle font-medium whitespace-nowrap [&:has([role=checkbox])]:pr-0 [&>[role=checkbox]]:translate-y-[2px]", "in-data-[variant=settings]:h-8 in-data-[variant=settings]:px-3 in-data-[variant=settings]:text-xs in-data-[variant=settings]:font-normal in-data-[variant=settings]:first:pl-0 in-data-[variant=settings]:last:pr-0", className),
48
49
  ...props
49
50
  });
50
51
  }
51
52
  function TableCell({ className, ...props }) {
52
53
  return /* @__PURE__ */ jsx("td", {
53
54
  "data-slot": "table-cell",
54
- className: cn("p-2 align-middle whitespace-nowrap [&:has([role=checkbox])]:pr-0 [&>[role=checkbox]]:translate-y-[2px]", className),
55
+ className: cn("p-2 align-middle whitespace-nowrap [&:has([role=checkbox])]:pr-0 [&>[role=checkbox]]:translate-y-[2px]", "in-data-[variant=settings]:h-11 in-data-[variant=settings]:px-3 in-data-[variant=settings]:py-0 in-data-[variant=settings]:[&>*+*]:ml-1.5 in-data-[variant=settings]:first:pl-0 in-data-[variant=settings]:last:pr-0", className),
55
56
  ...props
56
57
  });
57
58
  }
@@ -11,5 +11,5 @@ import { ThemeProvider as ThemeProvider$1 } from "next-themes";
11
11
  * </ThemeProvider>
12
12
  * ```
13
13
  */
14
- declare function ThemeProvider({ children, ...props }: React.ComponentProps<typeof ThemeProvider$1>): React.JSX.Element;
14
+ declare function ThemeProvider({ children, attribute, defaultTheme, enableSystem, ...props }: React.ComponentProps<typeof ThemeProvider$1>): React.JSX.Element;
15
15
  export { ThemeProvider };
@@ -13,8 +13,11 @@ import { ThemeProvider as ThemeProvider$1 } from "next-themes";
13
13
  * </ThemeProvider>
14
14
  * ```
15
15
  */
16
- function ThemeProvider({ children, ...props }) {
16
+ function ThemeProvider({ children, attribute = "class", defaultTheme = "system", enableSystem = true, ...props }) {
17
17
  return /* @__PURE__ */ jsx(ThemeProvider$1, {
18
+ attribute,
19
+ defaultTheme,
20
+ enableSystem,
18
21
  ...props,
19
22
  children
20
23
  });
@@ -0,0 +1,12 @@
1
+ export type ThemeChoice = 'system' | 'light' | 'dark';
2
+ export type ThemeSettingLabels = {
3
+ group: string;
4
+ system: string;
5
+ light: string;
6
+ dark: string;
7
+ };
8
+ /** System, light or dark as three icon segments; next-themes stores the choice. */
9
+ export declare function ThemeSetting({ labels: labelsProp, className }: {
10
+ labels?: Partial<ThemeSettingLabels>;
11
+ className?: string;
12
+ }): import("react").JSX.Element;
@@ -0,0 +1,66 @@
1
+ "use client";
2
+ import { cn } from "../lib/cn.js";
3
+ import { Tooltip as Tooltip$1, TooltipContent, TooltipProvider, TooltipTrigger } from "./tooltip.js";
4
+ import { useSyncExternalStore } from "react";
5
+ import { RadioGroup } from "radix-ui";
6
+ import { jsx, jsxs } from "react/jsx-runtime";
7
+ import { Monitor, Moon, Sun } from "lucide-react";
8
+ import { useTheme } from "next-themes";
9
+ // src/components/theme-setting.tsx
10
+ const DEFAULT_LABELS = {
11
+ group: "Tema",
12
+ system: "Sistema",
13
+ light: "Claro",
14
+ dark: "Escuro"
15
+ };
16
+ const CHOICES = [
17
+ {
18
+ value: "system",
19
+ icon: Monitor
20
+ },
21
+ {
22
+ value: "light",
23
+ icon: Sun
24
+ },
25
+ {
26
+ value: "dark",
27
+ icon: Moon
28
+ }
29
+ ];
30
+ const subscribeNothing = () => () => {};
31
+ /** True once hydrated: next-themes only knows the stored theme in the browser. */
32
+ function useHydrated() {
33
+ return useSyncExternalStore(subscribeNothing, () => true, () => false);
34
+ }
35
+ /** System, light or dark as three icon segments; next-themes stores the choice. */
36
+ function ThemeSetting({ labels: labelsProp, className }) {
37
+ const labels = {
38
+ ...DEFAULT_LABELS,
39
+ ...labelsProp
40
+ };
41
+ const { theme, setTheme } = useTheme();
42
+ const value = useHydrated() ? theme ?? "system" : void 0;
43
+ return /* @__PURE__ */ jsx(TooltipProvider, { children: /* @__PURE__ */ jsx(RadioGroup.Root, {
44
+ "aria-label": labels.group,
45
+ value,
46
+ onValueChange: setTheme,
47
+ orientation: "horizontal",
48
+ className: cn("inline-flex gap-0.5", className),
49
+ children: CHOICES.map(({ value: choice, icon: Icon }) => /* @__PURE__ */ jsxs(Tooltip$1, { children: [/* @__PURE__ */ jsx(TooltipTrigger, {
50
+ asChild: true,
51
+ children: /* @__PURE__ */ jsx(RadioGroup.Item, {
52
+ value: choice,
53
+ "aria-label": labels[choice],
54
+ className: "text-muted-foreground hover:text-foreground data-[state=checked]:bg-foreground/10 data-[state=checked]:text-foreground focus-visible:ring-ring/50 flex size-7 cursor-pointer items-center justify-center rounded-sm transition-colors outline-none focus-visible:ring-2",
55
+ children: /* @__PURE__ */ jsx(Icon, {
56
+ "aria-hidden": true,
57
+ className: "size-4"
58
+ })
59
+ })
60
+ }), /* @__PURE__ */ jsx(TooltipContent, {
61
+ side: "bottom",
62
+ children: labels[choice]
63
+ })] }, choice))
64
+ }) });
65
+ }
66
+ export { ThemeSetting };
@@ -0,0 +1,22 @@
1
+ import * as React from "react";
2
+ type ThemeToggleLabels = {
3
+ /** Visible name of the light theme (`text` variant). */
4
+ light?: string;
5
+ /** Visible name of the dark theme (`text` variant). */
6
+ dark?: string;
7
+ /** Accessible label of the button when it switches to light. */
8
+ switchToLight?: string;
9
+ /** Accessible label of the button when it switches to dark. */
10
+ switchToDark?: string;
11
+ };
12
+ type ThemeToggleProps = Omit<React.ComponentProps<'button'>, 'children' | 'onClick'> & {
13
+ /** `icon`: ghost icon button (sun/moon). `text`: mono uppercase label + glyph. */
14
+ variant?: 'icon' | 'text';
15
+ labels?: ThemeToggleLabels;
16
+ };
17
+ /**
18
+ * Light/dark toggle wired to `next-themes` (mount the DS `ThemeProvider`).
19
+ * Renders a neutral placeholder until hydrated so SSR markup never mismatches.
20
+ */
21
+ declare function ThemeToggle({ variant, labels, className, ...props }: ThemeToggleProps): React.JSX.Element;
22
+ export { ThemeToggle, type ThemeToggleLabels, type ThemeToggleProps };
@@ -0,0 +1,60 @@
1
+ "use client";
2
+ import { cn } from "../lib/cn.js";
3
+ import { Button } from "./button.js";
4
+ import * as React from "react";
5
+ import { jsx } from "react/jsx-runtime";
6
+ import { MoonIcon, SunIcon } from "lucide-react";
7
+ import { useTheme } from "next-themes";
8
+ // src/components/theme-toggle.tsx
9
+ const defaultLabels = {
10
+ light: "claro",
11
+ dark: "escuro",
12
+ switchToLight: "Mudar para o tema claro",
13
+ switchToDark: "Mudar para o tema escuro"
14
+ };
15
+ function useMounted() {
16
+ return React.useSyncExternalStore(() => () => {}, () => true, () => false);
17
+ }
18
+ /**
19
+ * Light/dark toggle wired to `next-themes` (mount the DS `ThemeProvider`).
20
+ * Renders a neutral placeholder until hydrated so SSR markup never mismatches.
21
+ */
22
+ function ThemeToggle({ variant = "icon", labels, className, ...props }) {
23
+ const { resolvedTheme, setTheme } = useTheme();
24
+ const mounted = useMounted();
25
+ const l = {
26
+ ...defaultLabels,
27
+ ...labels
28
+ };
29
+ const isDark = mounted && resolvedTheme === "dark";
30
+ const next = isDark ? "light" : "dark";
31
+ const label = isDark ? l.switchToLight : l.switchToDark;
32
+ if (variant === "text") {
33
+ let text = "— — —";
34
+ if (mounted) text = isDark ? `${l.light} ☀` : `${l.dark} ☾`;
35
+ return /* @__PURE__ */ jsx("button", {
36
+ type: "button",
37
+ "data-slot": "theme-toggle",
38
+ "aria-label": label,
39
+ onClick: () => setTheme(next),
40
+ className: cn("text-muted-foreground hover:text-foreground focus-visible:text-foreground font-mono text-[0.7rem] tracking-[0.12em] uppercase transition-colors focus-visible:outline-none", className),
41
+ ...props,
42
+ children: /* @__PURE__ */ jsx("span", {
43
+ className: "inline-block min-w-[3.5rem] text-right tabular-nums",
44
+ children: text
45
+ })
46
+ });
47
+ }
48
+ return /* @__PURE__ */ jsx(Button, {
49
+ type: "button",
50
+ variant: "ghost",
51
+ size: "icon",
52
+ "data-slot": "theme-toggle",
53
+ "aria-label": label,
54
+ onClick: () => setTheme(next),
55
+ className,
56
+ ...props,
57
+ children: isDark ? /* @__PURE__ */ jsx(SunIcon, {}) : /* @__PURE__ */ jsx(MoonIcon, {})
58
+ });
59
+ }
60
+ export { ThemeToggle };
@@ -4,7 +4,13 @@ import "react";
4
4
  import { Tooltip as Tooltip$1 } from "radix-ui";
5
5
  import { jsx, jsxs } from "react/jsx-runtime";
6
6
  // src/components/tooltip.tsx
7
- function TooltipProvider({ delayDuration = 0, ...props }) {
7
+ /**
8
+ * Hover delay before a tooltip opens: long enough that clicking a button does
9
+ * not flash its tooltip, short enough to still help. Moving between nearby
10
+ * tooltips skips the delay (Radix `skipDelayDuration`).
11
+ */
12
+ const TOOLTIP_DELAY = 500;
13
+ function TooltipProvider({ delayDuration = TOOLTIP_DELAY, ...props }) {
8
14
  return /* @__PURE__ */ jsx(Tooltip$1.Provider, {
9
15
  "data-slot": "tooltip-provider",
10
16
  delayDuration,
@@ -24,4 +24,21 @@ export type UserMenuProps = {
24
24
  * and any links are wired by the consumer — this component is presentation. */
25
25
  children: React.ReactNode;
26
26
  };
27
+ /**
28
+ * Width of the account menu's popup (17rem, 272px — the Claude app's). Apps
29
+ * composing their own account menu (e.g. with a context switcher) use it on
30
+ * their `DropdownMenuContent` so every app's menu has the same size.
31
+ */
32
+ export declare const USER_MENU_WIDTH = "w-68";
33
+ /**
34
+ * Who is signed in, on top of an account menu (name over e-mail, optionally
35
+ * with the avatar). `UserMenu` draws it; apps composing their own account
36
+ * menu put it first in their `DropdownMenuContent`.
37
+ */
38
+ export declare function DropdownMenuAccountHeader({ name, secondary, avatarUrl }: {
39
+ name: string | null;
40
+ secondary?: string | null;
41
+ /** Pass it (even `null`) to show the avatar beside the identity. */
42
+ avatarUrl?: string | null;
43
+ }): React.JSX.Element;
27
44
  export declare function UserMenu({ name, secondary, avatarUrl, triggerLabel, trigger, align, children }: UserMenuProps): React.JSX.Element;
@@ -12,6 +12,39 @@ import { Fragment, jsx, jsxs } from "react/jsx-runtime";
12
12
  function userMenuInitials(name, secondary) {
13
13
  return initials(name, secondary);
14
14
  }
15
+ /**
16
+ * Width of the account menu's popup (17rem, 272px — the Claude app's). Apps
17
+ * composing their own account menu (e.g. with a context switcher) use it on
18
+ * their `DropdownMenuContent` so every app's menu has the same size.
19
+ */
20
+ const USER_MENU_WIDTH = "w-68";
21
+ /**
22
+ * Who is signed in, on top of an account menu (name over e-mail, optionally
23
+ * with the avatar). `UserMenu` draws it; apps composing their own account
24
+ * menu put it first in their `DropdownMenuContent`.
25
+ */
26
+ function DropdownMenuAccountHeader({ name, secondary = null, avatarUrl }) {
27
+ return /* @__PURE__ */ jsxs(DropdownMenuLabel, {
28
+ "data-slot": "dropdown-menu-account-header",
29
+ className: "flex items-center gap-2 font-normal",
30
+ children: [avatarUrl === void 0 ? null : /* @__PURE__ */ jsxs(Avatar, {
31
+ size: "default",
32
+ children: [avatarUrl ? /* @__PURE__ */ jsx(AvatarImage, {
33
+ src: avatarUrl,
34
+ alt: name ?? secondary ?? ""
35
+ }) : null, /* @__PURE__ */ jsx(AvatarFallback, { children: initials(name, secondary) })]
36
+ }), /* @__PURE__ */ jsxs("span", {
37
+ className: "flex min-w-0 flex-col gap-1",
38
+ children: [name ? /* @__PURE__ */ jsx("span", {
39
+ className: "text-foreground truncate text-sm font-medium",
40
+ children: name
41
+ }) : null, secondary ? /* @__PURE__ */ jsx("span", {
42
+ className: "truncate text-xs",
43
+ children: secondary
44
+ }) : null]
45
+ })]
46
+ });
47
+ }
15
48
  function UserMenu({ name, secondary = null, avatarUrl = null, triggerLabel = "Account", trigger, align = "end", children }) {
16
49
  return /* @__PURE__ */ jsxs(DropdownMenu, {
17
50
  modal: false,
@@ -32,18 +65,12 @@ function UserMenu({ name, secondary = null, avatarUrl = null, triggerLabel = "Ac
32
65
  })
33
66
  }), /* @__PURE__ */ jsxs(DropdownMenuContent, {
34
67
  align,
35
- className: "w-56",
36
- children: [name || secondary ? /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsxs(DropdownMenuLabel, {
37
- className: "flex flex-col gap-1 font-normal",
38
- children: [name ? /* @__PURE__ */ jsx("span", {
39
- className: "text-sm font-medium",
40
- children: name
41
- }) : null, secondary ? /* @__PURE__ */ jsx("span", {
42
- className: "text-muted-foreground truncate text-xs",
43
- children: secondary
44
- }) : null]
68
+ className: USER_MENU_WIDTH,
69
+ children: [name || secondary ? /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx(DropdownMenuAccountHeader, {
70
+ name,
71
+ secondary
45
72
  }), /* @__PURE__ */ jsx(DropdownMenuSeparator, {})] }) : null, children]
46
73
  })]
47
74
  });
48
75
  }
49
- export { UserMenu, userMenuInitials };
76
+ export { DropdownMenuAccountHeader, USER_MENU_WIDTH, UserMenu, userMenuInitials };
@@ -0,0 +1,36 @@
1
+ import * as React from "react";
2
+ export type AutosaveResult = {
3
+ ok: true;
4
+ } | {
5
+ ok: false;
6
+ error: string;
7
+ };
8
+ export type AutosaveFormOptions = {
9
+ /** Persists the form (e.g. a server action); `ok: false` keeps the field dirty and shows `error`. */
10
+ submit: (formData: FormData) => Promise<AutosaveResult>;
11
+ /** Short confirmation toast after a save ("Negócio atualizado."). */
12
+ successMessage: string;
13
+ /** After a successful save (e.g. the router's refresh). */
14
+ onSaved?: () => void;
15
+ };
16
+ /**
17
+ * Settings fields that save themselves, as in the Claude app — no "Salvar"
18
+ * button: a text field saves when it loses focus or on Enter, Escape undoes
19
+ * the edit, a select/switch saves on change (call `saveSoon`). Nothing is
20
+ * sent when nothing changed; an invalid form (a required field left empty)
21
+ * goes back to the saved values. Spread `formProps` on the `<form>` and give
22
+ * its fields `defaultValue`s.
23
+ */
24
+ export declare function useAutosaveForm({ submit, successMessage, onSaved }: AutosaveFormOptions): {
25
+ /** The last save's error, for the row's description. */
26
+ error: string | null;
27
+ pending: boolean;
28
+ /** Saves after the current event (for selects, switches, pickers). */
29
+ saveSoon: () => void;
30
+ formProps: {
31
+ ref: React.RefObject<HTMLFormElement | null>;
32
+ onBlur: () => void;
33
+ onKeyDown: (event: React.KeyboardEvent<HTMLFormElement>) => void;
34
+ onSubmit: (event: React.FormEvent<HTMLFormElement>) => void;
35
+ };
36
+ };