@cbrl/design 0.9.0 → 0.11.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 (56) hide show
  1. package/README.md +173 -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 +66 -10
  7. package/dist/components/app-shell.js +284 -53
  8. package/dist/components/avatar.d.ts +7 -2
  9. package/dist/components/avatar.js +28 -6
  10. package/dist/components/badge.js +1 -1
  11. package/dist/components/button-group.d.ts +1 -1
  12. package/dist/components/button-group.js +1 -1
  13. package/dist/components/button.js +1 -1
  14. package/dist/components/container.d.ts +1 -1
  15. package/dist/components/container.js +1 -1
  16. package/dist/components/dropdown-menu.d.ts +5 -1
  17. package/dist/components/dropdown-menu.js +3 -3
  18. package/dist/components/field.d.ts +1 -1
  19. package/dist/components/field.js +1 -1
  20. package/dist/components/list.js +1 -1
  21. package/dist/components/main.js +1 -1
  22. package/dist/components/page-header.js +3 -3
  23. package/dist/components/settings-dialog-mobile.d.ts +23 -0
  24. package/dist/components/settings-dialog-mobile.js +198 -0
  25. package/dist/components/settings-dialog.d.ts +96 -10
  26. package/dist/components/settings-dialog.js +264 -29
  27. package/dist/components/settings-mobile-blocks.d.ts +25 -0
  28. package/dist/components/settings-mobile-blocks.js +126 -0
  29. package/dist/components/sidebar-core.js +7 -7
  30. package/dist/components/sidebar-menu.js +1 -1
  31. package/dist/components/sidebar-peek.d.ts +40 -0
  32. package/dist/components/sidebar-peek.js +204 -0
  33. package/dist/components/status-dot.js +1 -1
  34. package/dist/components/table.d.ts +8 -1
  35. package/dist/components/table.js +5 -4
  36. package/dist/components/tabs.d.ts +1 -1
  37. package/dist/components/tabs.js +1 -1
  38. package/dist/components/theme-provider.d.ts +1 -1
  39. package/dist/components/theme-provider.js +4 -1
  40. package/dist/components/theme-setting.d.ts +12 -0
  41. package/dist/components/theme-setting.js +66 -0
  42. package/dist/components/tooltip.js +7 -1
  43. package/dist/components/typography.js +1 -1
  44. package/dist/components/user-menu.d.ts +17 -0
  45. package/dist/components/user-menu.js +40 -12
  46. package/dist/components/workspace-picker.d.ts +21 -0
  47. package/dist/components/workspace-picker.js +51 -0
  48. package/dist/globals.css +33 -0
  49. package/dist/hooks/use-autosave-form.d.ts +36 -0
  50. package/dist/hooks/use-autosave-form.js +81 -0
  51. package/dist/hooks/use-mobile.d.ts +1 -0
  52. package/dist/hooks/use-mobile.js +14 -7
  53. package/dist/index.d.ts +13 -6
  54. package/dist/index.js +8 -3
  55. package/dist/lib/mobile-chrome.js +12 -0
  56. package/package.json +1 -1
@@ -0,0 +1,198 @@
1
+ "use client";
2
+ import { cn } from "../lib/cn.js";
3
+ import { initials } from "../lib/initials.js";
4
+ import { MOBILE_BAR, MOBILE_BAR_ROW, MOBILE_ROUND_BUTTON } from "../lib/mobile-chrome.js";
5
+ import { Avatar as Avatar$1, AvatarFallback, AvatarImage } from "./avatar.js";
6
+ import { DialogDescription, DialogTitle } from "./dialog.js";
7
+ import { DropdownMenu as DropdownMenu$1, DropdownMenuContent, DropdownMenuItem, DropdownMenuLabel, DropdownMenuSeparator, DropdownMenuTrigger } from "./dropdown-menu.js";
8
+ import { AppearanceCard, SignOutRow, WorkspacesCard } from "./settings-mobile-blocks.js";
9
+ import "react";
10
+ import { Dialog } from "radix-ui";
11
+ import { Fragment, jsx, jsxs } from "react/jsx-runtime";
12
+ import { ChevronLeft, ChevronRight, ExternalLink, FileText, Info, X } from "lucide-react";
13
+ // src/components/settings-dialog-mobile.tsx
14
+ function groupSections(sections) {
15
+ const groups = [];
16
+ for (const section of sections) {
17
+ const last = groups.at(-1);
18
+ if (last && last.label === section.group) last.items.push(section);
19
+ else groups.push({
20
+ label: section.group,
21
+ items: [section]
22
+ });
23
+ }
24
+ return groups;
25
+ }
26
+ function AboutLink({ link }) {
27
+ const Icon = link.kind === "document" ? FileText : ExternalLink;
28
+ const external = link.kind !== "document";
29
+ return /* @__PURE__ */ jsx(DropdownMenuItem, {
30
+ asChild: true,
31
+ className: "gap-3 py-2.5 text-base [&_svg]:size-5",
32
+ children: /* @__PURE__ */ jsxs("a", {
33
+ href: link.href,
34
+ target: external ? "_blank" : void 0,
35
+ rel: external ? "noreferrer" : void 0,
36
+ children: [/* @__PURE__ */ jsx(Icon, { "aria-hidden": true }), link.label]
37
+ })
38
+ });
39
+ }
40
+ function AboutMenu({ about, label }) {
41
+ return /* @__PURE__ */ jsxs(DropdownMenu$1, {
42
+ modal: false,
43
+ children: [/* @__PURE__ */ jsx(DropdownMenuTrigger, {
44
+ "aria-label": label,
45
+ className: MOBILE_ROUND_BUTTON,
46
+ children: /* @__PURE__ */ jsx(Info, { "aria-hidden": true })
47
+ }), /* @__PURE__ */ jsxs(DropdownMenuContent, {
48
+ align: "end",
49
+ className: "w-72 rounded-2xl p-2",
50
+ children: [
51
+ about.version ? /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx(DropdownMenuLabel, {
52
+ className: "text-foreground px-3 py-2 text-base font-normal",
53
+ children: about.version
54
+ }), /* @__PURE__ */ jsx(DropdownMenuSeparator, {})] }) : null,
55
+ about.links?.map((link) => /* @__PURE__ */ jsx(AboutLink, { link }, link.href)),
56
+ about.links?.length && about.support?.length ? /* @__PURE__ */ jsx(DropdownMenuSeparator, {}) : null,
57
+ about.support?.map((link) => /* @__PURE__ */ jsx(AboutLink, { link }, link.href))
58
+ ]
59
+ })]
60
+ });
61
+ }
62
+ function MobileSettings({ sections, current, view, onOpen, onBack, account, about, extras = {}, labels, children }) {
63
+ const active = sections.find((s) => s.key === current);
64
+ const inSection = view === "section" && active !== void 0;
65
+ return /* @__PURE__ */ jsxs("div", {
66
+ "data-slot": "settings-mobile",
67
+ className: "relative flex min-h-0 flex-1 flex-col",
68
+ children: [/* @__PURE__ */ jsxs("div", {
69
+ "data-slot": "settings-mobile-bar",
70
+ className: cn(MOBILE_BAR, "absolute inset-x-0 top-0 flex items-center px-4", MOBILE_BAR_ROW),
71
+ children: [
72
+ inSection ? /* @__PURE__ */ jsx("button", {
73
+ type: "button",
74
+ "aria-label": labels.back,
75
+ className: MOBILE_ROUND_BUTTON,
76
+ onClick: onBack,
77
+ children: /* @__PURE__ */ jsx(ChevronLeft, { "aria-hidden": true })
78
+ }) : /* @__PURE__ */ jsx(Dialog.Close, {
79
+ "aria-label": labels.close,
80
+ className: MOBILE_ROUND_BUTTON,
81
+ children: /* @__PURE__ */ jsx(X, { "aria-hidden": true })
82
+ }),
83
+ /* @__PURE__ */ jsx(DialogTitle, {
84
+ className: "pointer-events-none absolute inset-x-20 truncate text-center text-base font-semibold",
85
+ children: inSection ? active.label : labels.title
86
+ }),
87
+ /* @__PURE__ */ jsx(DialogDescription, {
88
+ className: "sr-only",
89
+ children: inSection ? active.label : labels.title
90
+ }),
91
+ !inSection && about ? /* @__PURE__ */ jsx("div", {
92
+ className: "ml-auto",
93
+ children: /* @__PURE__ */ jsx(AboutMenu, {
94
+ about,
95
+ label: labels.about
96
+ })
97
+ }) : null
98
+ ]
99
+ }), /* @__PURE__ */ jsx("div", {
100
+ className: "pb-safe min-h-0 flex-1 overflow-y-auto overscroll-contain pt-16 [scroll-padding-top:4rem]",
101
+ children: inSection ? /* @__PURE__ */ jsxs("div", {
102
+ role: "region",
103
+ "aria-label": active.label,
104
+ "data-slot": "settings-dialog-content",
105
+ className: "grid gap-6 px-4 pt-2 pb-8",
106
+ children: [active.description ? /* @__PURE__ */ jsx("p", {
107
+ className: "text-muted-foreground px-1 text-sm",
108
+ children: active.description
109
+ }) : null, children]
110
+ }) : /* @__PURE__ */ jsx(SettingsHome, {
111
+ label: labels.title,
112
+ sections,
113
+ account,
114
+ extras,
115
+ onOpen
116
+ })
117
+ })]
118
+ });
119
+ }
120
+ function AccountCard({ account, onOpen }) {
121
+ const content = /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsxs(Avatar$1, {
122
+ className: "size-12",
123
+ children: [account.avatarUrl ? /* @__PURE__ */ jsx(AvatarImage, {
124
+ src: account.avatarUrl,
125
+ alt: ""
126
+ }) : null, /* @__PURE__ */ jsx(AvatarFallback, { children: initials(account.name, account.secondary ?? null) })]
127
+ }), /* @__PURE__ */ jsxs("span", {
128
+ className: "grid min-w-0 flex-1 text-left",
129
+ children: [/* @__PURE__ */ jsx("span", {
130
+ className: "truncate text-base",
131
+ children: account.name
132
+ }), account.secondary ? /* @__PURE__ */ jsx("span", {
133
+ className: "text-muted-foreground truncate text-sm",
134
+ children: account.secondary
135
+ }) : null]
136
+ })] });
137
+ const section = account.section;
138
+ if (section === void 0) return /* @__PURE__ */ jsx("div", {
139
+ className: "bg-card flex items-center gap-3 rounded-2xl p-4",
140
+ children: content
141
+ });
142
+ return /* @__PURE__ */ jsx("button", {
143
+ type: "button",
144
+ onClick: () => onOpen(section),
145
+ className: "bg-card active:bg-muted flex cursor-pointer items-center gap-3 rounded-2xl p-4",
146
+ children: content
147
+ });
148
+ }
149
+ /** The home of the phone settings: account card, then a card per group. */
150
+ function SettingsHome({ label, sections, account, extras, onOpen }) {
151
+ let top = null;
152
+ if (extras.workspaces) top = /* @__PURE__ */ jsx(WorkspacesCard, { workspaces: extras.workspaces });
153
+ else if (account) top = /* @__PURE__ */ jsx(AccountCard, {
154
+ account,
155
+ onOpen
156
+ });
157
+ return /* @__PURE__ */ jsxs("nav", {
158
+ "aria-label": label,
159
+ className: "grid gap-6 px-4 pt-2 pb-8",
160
+ children: [
161
+ top,
162
+ groupSections(sections).map((group, index) => /* @__PURE__ */ jsxs("section", {
163
+ className: "grid gap-2",
164
+ children: [group.label ? /* @__PURE__ */ jsx("h3", {
165
+ className: "text-muted-foreground px-4 text-sm first-letter:uppercase",
166
+ children: (group.label && extras.groupLabels?.[group.label]) ?? group.label
167
+ }) : null, /* @__PURE__ */ jsx("ul", {
168
+ className: "bg-card overflow-hidden rounded-2xl",
169
+ children: group.items.map(({ key, label: itemLabel, icon: Icon }) => /* @__PURE__ */ jsx("li", {
170
+ className: "group/row",
171
+ children: /* @__PURE__ */ jsxs("button", {
172
+ type: "button",
173
+ onClick: () => onOpen(key),
174
+ className: "active:bg-muted flex min-h-14 w-full cursor-pointer items-center gap-4 pl-4 text-left",
175
+ children: [Icon ? /* @__PURE__ */ jsx("span", {
176
+ "aria-hidden": true,
177
+ className: "text-foreground/80 flex shrink-0",
178
+ children: /* @__PURE__ */ jsx(Icon, { className: "size-6" })
179
+ }) : null, /* @__PURE__ */ jsxs("span", {
180
+ className: "border-border flex min-h-14 flex-1 items-center gap-2 border-b pr-4 group-last/row:border-b-0",
181
+ children: [/* @__PURE__ */ jsx("span", {
182
+ className: "flex-1 text-base",
183
+ children: itemLabel
184
+ }), /* @__PURE__ */ jsx(ChevronRight, {
185
+ "aria-hidden": true,
186
+ className: "text-muted-foreground size-5"
187
+ })]
188
+ })]
189
+ })
190
+ }, key))
191
+ })]
192
+ }, group.label ?? index)),
193
+ extras.appearance ? /* @__PURE__ */ jsx(AppearanceCard, { labels: extras.appearance }) : null,
194
+ extras.signOut ? /* @__PURE__ */ jsx(SignOutRow, { signOut: extras.signOut }) : null
195
+ ]
196
+ });
197
+ }
198
+ export { MobileSettings };
@@ -1,3 +1,5 @@
1
+ import { SettingsAbout, SettingsDialogAccount } from "./settings-dialog-mobile.js";
2
+ import { SettingsSignOut, SettingsWorkspaces } from "./settings-mobile-blocks.js";
1
3
  import * as React from "react";
2
4
  export type SettingsDialogSection<K extends string = string> = {
3
5
  key: K;
@@ -6,8 +8,37 @@ export type SettingsDialogSection<K extends string = string> = {
6
8
  icon?: React.ComponentType<{
7
9
  className?: string;
8
10
  }>;
9
- /** Shown under the title in the header while this section is active. */
11
+ /** Shown on top of the content while this section is active. */
10
12
  description?: React.ReactNode;
13
+ /** Extra terms the search matches (what the section holds, synonyms). */
14
+ keywords?: readonly string[];
15
+ /** Sections sharing a group sit together; a divider separates groups. */
16
+ group?: string;
17
+ };
18
+ export type SettingsDialogLabels = {
19
+ /** Title of the modal. */
20
+ title: string;
21
+ /** Accessible name of the section nav. */
22
+ nav: string;
23
+ /** Accessible name of the search box. */
24
+ search: string;
25
+ /** Short placeholder of the search box (the nav column is narrow). */
26
+ searchPlaceholder: string;
27
+ /** Accessible name of the search's clear button. */
28
+ clearSearch: string;
29
+ /** Shown in the nav when no section matches. */
30
+ noResults: string;
31
+ /** Phones: the back button of a section. */
32
+ back: string;
33
+ /** Phones: the close button. */
34
+ close: string;
35
+ /** Phones: the (i) button with version and links. */
36
+ about: string;
37
+ /** Phones: the theme tiles' heading and names. */
38
+ appearance: string;
39
+ light: string;
40
+ dark: string;
41
+ system: string;
11
42
  };
12
43
  export type SettingsDialogProps<K extends string = string> = {
13
44
  open?: boolean;
@@ -19,18 +50,73 @@ export type SettingsDialogProps<K extends string = string> = {
19
50
  /** Initial section when uncontrolled. Defaults to the first section. */
20
51
  defaultValue?: K;
21
52
  onValueChange?: (key: K) => void;
22
- /** Accessible name of the section nav. */
23
- navLabel?: string;
24
- /** Overrides the header title (defaults to the active section's label). */
25
- title?: React.ReactNode;
53
+ labels?: Partial<SettingsDialogLabels>;
54
+ /**
55
+ * Phones: the identity card on top of the list (Claude-app style); with
56
+ * `section`, tapping it opens that section (e.g. the profile).
57
+ */
58
+ account?: SettingsDialogAccount<K>;
59
+ /** Phones: the (i) menu in the header — app version, policies, support. */
60
+ about?: SettingsAbout;
61
+ /** Phones: the workspace switcher on top (replaces the `account` card). */
62
+ workspaces?: SettingsWorkspaces;
63
+ /**
64
+ * Phones: the theme tiles (Claro / Escuro / Sistema) right in the home, at
65
+ * the end. Pass the key of the app's appearance section to drop it there.
66
+ */
67
+ appearance?: boolean | K;
68
+ /** Phones: "Sair" as the last row of the home. */
69
+ signOut?: SettingsSignOut;
70
+ /** Phones: headings of the section groups, by `group` (else the group itself). */
71
+ groupLabels?: Readonly<Record<string, string>>;
26
72
  /** Content of the active section; apps switch on the value. */
27
73
  children?: React.ReactNode;
28
74
  className?: string;
29
75
  };
30
76
  /**
31
- * Settings modal shell: section nav (a column from `sm`, a sideways-scrolling
32
- * strip on phones that keeps the active section in view), a header with the
33
- * active section's label/description, and a scrolling content area. Which
34
- * sections a user may see and how each loads its data stay in the app.
77
+ * Sections where every word of the query starts some word of the label or
78
+ * keywords (accents and plurals ignored).
79
+ */
80
+ export declare function matchSections<K extends string>(sections: readonly SettingsDialogSection<K>[], query: string): readonly SettingsDialogSection<K>[];
81
+ /**
82
+ * Settings modal: a title bar, then the section nav (a column from `sm`, a
83
+ * row on phones) under a search box, beside the active section's content.
84
+ * Typing filters the nav by label and keywords; Enter opens the first match;
85
+ * Escape (or the clear button) empties the search before closing.
86
+ */
87
+ export declare function SettingsDialog<K extends string>({ open, defaultOpen, onOpenChange, sections, value, defaultValue, onValueChange, labels: labelsProp, account, about, workspaces, appearance, signOut, groupLabels, children, className }: SettingsDialogProps<K>): React.JSX.Element;
88
+ /** A titled block of settings rows ("Perfil", "Geral"…). */
89
+ export declare function SettingsGroup({ title, action, listLabel, children, className }: {
90
+ title?: React.ReactNode;
91
+ /** Right of the title (e.g. a small button acting on the whole group). */
92
+ action?: React.ReactNode;
93
+ /**
94
+ * Makes the rows a list (`ul`, named by this label) — for a variable set of
95
+ * items (accounts, units, rules). Render each row as `SettingsItem as="li"`.
96
+ */
97
+ listLabel?: string;
98
+ children?: React.ReactNode;
99
+ className?: string;
100
+ }): React.JSX.Element;
101
+ /** Muted text standing for a group with nothing to list ("Nenhuma regra ainda."). */
102
+ export declare function SettingsEmpty({ children }: {
103
+ children: React.ReactNode;
104
+ }): React.JSX.Element;
105
+ /**
106
+ * One setting: label (and description) on the left, its control on the right
107
+ * — or, with `layout="stacked"`, a large control (a textarea) under them.
108
+ * Inputs and select triggers in the control get the standard compact width.
35
109
  */
36
- export declare function SettingsDialog<K extends string>({ open, defaultOpen, onOpenChange, sections, value, defaultValue, onValueChange, navLabel, title, children, className }: SettingsDialogProps<K>): React.JSX.Element;
110
+ export declare function SettingsItem({ label, description, leading, htmlFor, layout, as: Row, children, className }: {
111
+ label: React.ReactNode;
112
+ description?: React.ReactNode;
113
+ /** Before the label: an icon or avatar identifying the row (e.g. a business). */
114
+ leading?: React.ReactNode;
115
+ /** Id of the control: the label becomes its `<label>`. */
116
+ htmlFor?: string;
117
+ layout?: 'inline' | 'stacked';
118
+ /** `li` inside a `SettingsGroup listLabel`. */
119
+ as?: 'div' | 'li';
120
+ children?: React.ReactNode;
121
+ className?: string;
122
+ }): React.JSX.Element;
@@ -1,81 +1,316 @@
1
1
  "use client";
2
+ import { isDirtyField } from "../hooks/use-autosave-form.js";
3
+ import { useIsMobile } from "../hooks/use-mobile.js";
2
4
  import { useScrollStrip } from "../hooks/use-scroll-strip.js";
3
5
  import { cn } from "../lib/cn.js";
4
- import { fadeMask } from "../lib/scroll-target.js";
5
6
  import { Dialog, DialogContent, DialogDescription, DialogHeader, DialogTitle } from "./dialog.js";
7
+ import { InputGroup, InputGroupAddon, InputGroupInput } from "./input-group.js";
6
8
  import { ScrollArea } from "./scroll-area.js";
9
+ import { MobileSettings } from "./settings-dialog-mobile.js";
7
10
  import * as React from "react";
8
11
  import { jsx, jsxs } from "react/jsx-runtime";
12
+ import { Search, X } from "lucide-react";
9
13
  // src/components/settings-dialog.tsx
14
+ const DEFAULT_LABELS = {
15
+ title: "Configurações",
16
+ nav: "Seções de configuração",
17
+ search: "Buscar configurações",
18
+ searchPlaceholder: "Procurar",
19
+ clearSearch: "Limpar busca",
20
+ noResults: "Nada encontrado",
21
+ back: "Voltar",
22
+ close: "Fechar",
23
+ about: "Sobre",
24
+ appearance: "Aparência",
25
+ light: "Claro",
26
+ dark: "Escuro",
27
+ system: "Sistema"
28
+ };
29
+ /** Fades only the edges of the phone strip that hide sections (as in the DS). */
30
+ function fadeMask({ start, end }) {
31
+ if (!start && !end) return void 0;
32
+ return `linear-gradient(to right, ${start ? "transparent 0, black 1.5rem" : "black 0"}, ${end ? "black calc(100% - 1.5rem), transparent 100%" : "black 100%"})`;
33
+ }
34
+ /** Lowercase without diacritics, so "aparencia" finds "Aparência". */
35
+ function normalizeSearch(text) {
36
+ return text.normalize("NFD").replace(/\p{Diacritic}/gu, "").toLowerCase().trim();
37
+ }
38
+ /** Light plural folding, so "conexão" finds "Conexões" and "regra" "Regras". */
39
+ function stem(word) {
40
+ return word.replace(/(oes|aes)$/, "ao").replace(/(?<=.{3})s$/, "");
41
+ }
42
+ /** Each word normalized, plus its plural-folded form. */
43
+ const words = (text) => normalizeSearch(text).split(/[\s\-/]+/).filter(Boolean).flatMap((word) => [word, stem(word)]);
44
+ /**
45
+ * Sections where every word of the query starts some word of the label or
46
+ * keywords (accents and plurals ignored).
47
+ */
48
+ function matchSections(sections, query) {
49
+ const terms = normalizeSearch(query).split(/\s+/).filter(Boolean);
50
+ if (terms.length === 0) return sections;
51
+ return sections.filter((section) => {
52
+ const haystack = words([section.label, ...section.keywords ?? []].join(" "));
53
+ return terms.every((term) => [term, stem(term)].some((form) => haystack.some((word) => word.startsWith(form))));
54
+ });
55
+ }
10
56
  /**
11
- * Settings modal shell: section nav (a column from `sm`, a sideways-scrolling
12
- * strip on phones that keeps the active section in view), a header with the
13
- * active section's label/description, and a scrolling content area. Which
14
- * sections a user may see and how each loads its data stay in the app.
57
+ * Settings modal: a title bar, then the section nav (a column from `sm`, a
58
+ * row on phones) under a search box, beside the active section's content.
59
+ * Typing filters the nav by label and keywords; Enter opens the first match;
60
+ * Escape (or the clear button) empties the search before closing.
15
61
  */
16
- function SettingsDialog({ open, defaultOpen, onOpenChange, sections, value, defaultValue, onValueChange, navLabel = "Settings sections", title, children, className }) {
62
+ function SettingsDialog({ open, defaultOpen, onOpenChange, sections, value, defaultValue, onValueChange, labels: labelsProp, account, about, workspaces, appearance, signOut, groupLabels, children, className }) {
63
+ const isMobile = useIsMobile();
64
+ const [mobileView, setMobileView] = React.useState("list");
65
+ const labels = {
66
+ ...DEFAULT_LABELS,
67
+ ...labelsProp
68
+ };
17
69
  const [inner, setInner] = React.useState(defaultValue);
70
+ const [query, setQuery] = React.useState("");
71
+ const searchRef = React.useRef(null);
18
72
  const current = value ?? inner ?? sections[0]?.key;
19
73
  const active = sections.find((s) => s.key === current);
74
+ const visible = matchSections(sections, query);
20
75
  const select = (key) => {
21
76
  if (value === void 0) setInner(key);
22
77
  onValueChange?.(key);
23
78
  };
79
+ if (isMobile) return /* @__PURE__ */ jsx(Dialog, {
80
+ open,
81
+ defaultOpen,
82
+ onOpenChange: (next) => {
83
+ setMobileView("list");
84
+ onOpenChange?.(next);
85
+ },
86
+ children: /* @__PURE__ */ jsx(DialogContent, {
87
+ "data-slot": "settings-dialog",
88
+ showCloseButton: false,
89
+ className: cn("bg-background data-open:slide-in-from-bottom-10 data-closed:slide-out-to-bottom-10 top-[calc(env(safe-area-inset-top,0px)+0.5rem)] bottom-0 left-0 flex h-auto w-full max-w-none translate-x-0 translate-y-0 flex-col gap-0 overflow-hidden rounded-t-3xl rounded-b-none p-0 data-open:zoom-in-100 data-closed:zoom-out-100 sm:max-w-none", className),
90
+ onOpenAutoFocus: (event) => event.preventDefault(),
91
+ onEscapeKeyDown: (event) => {
92
+ if (isDirtyField(document.activeElement)) event.preventDefault();
93
+ },
94
+ children: /* @__PURE__ */ jsx(MobileSettings, {
95
+ sections: typeof appearance === "string" ? sections.filter((s) => s.key !== appearance) : sections,
96
+ extras: {
97
+ workspaces,
98
+ signOut,
99
+ groupLabels,
100
+ appearance: appearance ? {
101
+ title: labels.appearance,
102
+ light: labels.light,
103
+ dark: labels.dark,
104
+ system: labels.system
105
+ } : void 0
106
+ },
107
+ current,
108
+ view: mobileView,
109
+ onOpen: (key) => {
110
+ select(key);
111
+ setMobileView("section");
112
+ },
113
+ onBack: () => setMobileView("list"),
114
+ account,
115
+ about,
116
+ labels,
117
+ children
118
+ })
119
+ })
120
+ });
24
121
  return /* @__PURE__ */ jsx(Dialog, {
25
122
  open,
26
123
  defaultOpen,
27
124
  onOpenChange,
28
125
  children: /* @__PURE__ */ jsxs(DialogContent, {
29
126
  "data-slot": "settings-dialog",
30
- className: cn("grid h-[min(85vh,40rem)] max-w-3xl grid-rows-[auto_1fr] gap-0 overflow-hidden p-0 sm:max-w-3xl sm:grid-cols-[12rem_minmax(0,1fr)] sm:grid-rows-1", className),
127
+ className: cn("flex h-[min(85vh,44rem)] max-w-4xl flex-col gap-0 overflow-hidden p-0 sm:max-w-4xl", className),
31
128
  onOpenAutoFocus: (event) => event.preventDefault(),
32
- children: [/* @__PURE__ */ jsx(SettingsDialogNav, {
33
- label: navLabel,
34
- sections,
35
- current,
36
- onSelect: select
129
+ onEscapeKeyDown: (event) => {
130
+ if (isDirtyField(document.activeElement)) {
131
+ event.preventDefault();
132
+ return;
133
+ }
134
+ if (query === "") return;
135
+ event.preventDefault();
136
+ setQuery("");
137
+ },
138
+ children: [/* @__PURE__ */ jsxs(DialogHeader, {
139
+ className: "border-b px-4 py-3 pr-12 text-left",
140
+ children: [/* @__PURE__ */ jsx(DialogTitle, {
141
+ className: "text-base",
142
+ children: labels.title
143
+ }), /* @__PURE__ */ jsx(DialogDescription, {
144
+ className: "sr-only",
145
+ children: active?.label
146
+ })]
37
147
  }), /* @__PURE__ */ jsxs("div", {
38
- className: "flex min-h-0 min-w-0 flex-col",
39
- children: [/* @__PURE__ */ jsxs(DialogHeader, {
40
- className: "gap-1 border-b p-6 pr-14",
41
- children: [/* @__PURE__ */ jsx(DialogTitle, { children: title ?? active?.label }), active?.description ? /* @__PURE__ */ jsx(DialogDescription, { children: active.description }) : /* @__PURE__ */ jsx(DialogDescription, {
42
- className: "sr-only",
43
- children: active?.label
148
+ className: "grid min-h-0 flex-1 grid-rows-[auto_1fr] sm:grid-cols-[14rem_minmax(0,1fr)] sm:grid-rows-1",
149
+ children: [/* @__PURE__ */ jsxs("div", {
150
+ className: "flex min-w-0 flex-col gap-2 border-b p-3 sm:border-r sm:border-b-0",
151
+ children: [/* @__PURE__ */ jsxs(InputGroup, {
152
+ className: "bg-muted/70 dark:bg-muted/50 h-8 border-transparent shadow-none",
153
+ children: [
154
+ /* @__PURE__ */ jsx(InputGroupAddon, {
155
+ align: "inline-start",
156
+ children: /* @__PURE__ */ jsx(Search, { "aria-hidden": true })
157
+ }),
158
+ /* @__PURE__ */ jsx(InputGroupInput, {
159
+ ref: searchRef,
160
+ type: "search",
161
+ value: query,
162
+ placeholder: labels.searchPlaceholder,
163
+ "aria-label": labels.search,
164
+ className: "[&::-webkit-search-cancel-button]:appearance-none",
165
+ onChange: (event) => setQuery(event.target.value),
166
+ onKeyDown: (event) => {
167
+ const first = visible[0];
168
+ if (event.key === "Enter" && first !== void 0) {
169
+ event.preventDefault();
170
+ select(first.key);
171
+ }
172
+ }
173
+ }),
174
+ query === "" ? null : /* @__PURE__ */ jsx(InputGroupAddon, {
175
+ align: "inline-end",
176
+ children: /* @__PURE__ */ jsx("button", {
177
+ type: "button",
178
+ "aria-label": labels.clearSearch,
179
+ onClick: () => {
180
+ setQuery("");
181
+ searchRef.current?.focus();
182
+ },
183
+ className: "text-muted-foreground hover:text-foreground focus-visible:ring-ring/50 flex size-5 cursor-pointer items-center justify-center rounded-sm outline-none focus-visible:ring-2",
184
+ children: /* @__PURE__ */ jsx(X, {
185
+ "aria-hidden": true,
186
+ className: "size-3.5"
187
+ })
188
+ })
189
+ })
190
+ ]
191
+ }), /* @__PURE__ */ jsx(SettingsNav, {
192
+ label: labels.nav,
193
+ noResults: labels.noResults,
194
+ sections: visible,
195
+ current,
196
+ onSelect: select
44
197
  })]
45
198
  }), /* @__PURE__ */ jsx(ScrollArea, {
46
- className: "min-h-0 flex-1 [&_[data-slot=scroll-area-viewport]>div]:!block",
47
- children: /* @__PURE__ */ jsx("div", {
199
+ className: "min-h-0 [&_[data-slot=scroll-area-viewport]>div]:!block",
200
+ children: /* @__PURE__ */ jsxs("div", {
201
+ role: "region",
202
+ "aria-label": active?.label,
48
203
  "data-slot": "settings-dialog-content",
49
- className: "p-6",
50
- children
204
+ className: "grid gap-8 px-6 py-5",
205
+ children: [active?.description ? /* @__PURE__ */ jsx("p", {
206
+ className: "text-muted-foreground -mb-4 text-sm",
207
+ children: active.description
208
+ }) : null, children]
51
209
  })
52
210
  })]
53
211
  })]
54
212
  })
55
213
  });
56
214
  }
57
- function SettingsDialogNav({ label, sections, current, onSelect }) {
215
+ function SettingsNav({ label, noResults, sections, current, onSelect }) {
58
216
  const ref = React.useRef(null);
59
217
  const edges = useScrollStrip(ref, "[aria-current=\"page\"]");
60
- return /* @__PURE__ */ jsx("nav", {
218
+ return /* @__PURE__ */ jsxs("nav", {
61
219
  ref,
62
220
  "aria-label": label,
63
221
  "data-slot": "settings-dialog-nav",
64
222
  "data-fade-start": edges.start || void 0,
65
223
  "data-fade-end": edges.end || void 0,
66
224
  style: { maskImage: fadeMask(edges) },
67
- className: "bg-muted/40 flex [scrollbar-width:none] gap-0.5 overflow-x-auto border-b p-2 sm:flex-col sm:overflow-x-visible sm:border-r sm:border-b-0 [&::-webkit-scrollbar]:hidden",
68
- children: sections.map(({ key, label: itemLabel, icon: Icon }) => /* @__PURE__ */ jsxs("button", {
225
+ className: "flex [scrollbar-width:none] gap-0.5 overflow-x-auto sm:flex-col sm:overflow-x-visible [&::-webkit-scrollbar]:hidden",
226
+ children: [sections.map(({ key, label: itemLabel, icon: Icon, group }, index) => /* @__PURE__ */ jsxs(React.Fragment, { children: [index > 0 && group !== sections[index - 1]?.group ? /* @__PURE__ */ jsx("span", {
227
+ role: "separator",
228
+ className: "bg-border mx-2.5 my-2 hidden h-px sm:block"
229
+ }) : null, /* @__PURE__ */ jsxs("button", {
69
230
  type: "button",
70
231
  onClick: () => onSelect(key),
71
232
  "aria-current": key === current ? "page" : void 0,
72
- className: "text-muted-foreground hover:bg-background/60 aria-[current=page]:bg-background aria-[current=page]:text-foreground focus-visible:ring-ring/50 flex shrink-0 cursor-pointer items-center gap-2 rounded-md px-3 py-2 text-left text-sm font-normal whitespace-nowrap transition-colors outline-none focus-visible:ring-3 aria-[current=page]:font-medium",
233
+ className: "text-foreground/80 hover:bg-muted aria-[current=page]:bg-muted aria-[current=page]:text-foreground focus-visible:ring-ring/50 flex shrink-0 cursor-pointer items-center gap-2.5 rounded-md px-2.5 py-1.5 text-left text-sm whitespace-nowrap transition-colors outline-none focus-visible:ring-3",
73
234
  children: [Icon ? /* @__PURE__ */ jsx("span", {
74
235
  "aria-hidden": true,
75
236
  className: "flex shrink-0",
76
237
  children: /* @__PURE__ */ jsx(Icon, { className: "size-4" })
77
238
  }) : null, itemLabel]
78
- }, key))
239
+ })] }, key)), sections.length === 0 ? /* @__PURE__ */ jsx("p", {
240
+ role: "status",
241
+ className: "text-muted-foreground px-2.5 py-1.5 text-sm",
242
+ children: noResults
243
+ }) : null]
244
+ });
245
+ }
246
+ const GROUP_BODY = "grid max-md:bg-card max-md:rounded-2xl max-md:px-4";
247
+ /** A titled block of settings rows ("Perfil", "Geral"…). */
248
+ function SettingsGroup({ title, action, listLabel, children, className }) {
249
+ return /* @__PURE__ */ jsxs("section", {
250
+ "data-slot": "settings-group",
251
+ className: cn("grid gap-1", className),
252
+ children: [title || action ? /* @__PURE__ */ jsxs("div", {
253
+ className: "flex min-h-8 items-center justify-between gap-4",
254
+ children: [title ? /* @__PURE__ */ jsx("h3", {
255
+ className: "text-sm font-medium max-md:text-muted-foreground max-md:px-4 max-md:font-normal",
256
+ children: title
257
+ }) : /* @__PURE__ */ jsx("span", {}), action ? /* @__PURE__ */ jsx("div", {
258
+ className: "flex items-center gap-2",
259
+ children: action
260
+ }) : null]
261
+ }) : null, listLabel === void 0 ? /* @__PURE__ */ jsx("div", {
262
+ className: GROUP_BODY,
263
+ children
264
+ }) : /* @__PURE__ */ jsx("ul", {
265
+ "aria-label": listLabel,
266
+ className: GROUP_BODY,
267
+ children
268
+ })]
269
+ });
270
+ }
271
+ /** Muted text standing for a group with nothing to list ("Nenhuma regra ainda."). */
272
+ function SettingsEmpty({ children }) {
273
+ return /* @__PURE__ */ jsx("p", {
274
+ "data-slot": "settings-empty",
275
+ className: "text-muted-foreground py-2.5 text-sm",
276
+ children
277
+ });
278
+ }
279
+ /**
280
+ * One setting: label (and description) on the left, its control on the right
281
+ * — or, with `layout="stacked"`, a large control (a textarea) under them.
282
+ * Inputs and select triggers in the control get the standard compact width.
283
+ */
284
+ function SettingsItem({ label, description, leading, htmlFor, layout = "inline", as: Row = "div", children, className }) {
285
+ const stacked = layout === "stacked";
286
+ return /* @__PURE__ */ jsxs(Row, {
287
+ "data-slot": "settings-item",
288
+ "data-layout": layout,
289
+ className: cn("flex min-h-12 gap-6 border-b py-2.5 last:border-b-0 max-md:min-h-14 max-md:gap-4", stacked ? "flex-col gap-2" : "items-center justify-between", className),
290
+ children: [/* @__PURE__ */ jsxs("div", {
291
+ className: "flex min-w-0 items-center gap-3",
292
+ children: [leading ? /* @__PURE__ */ jsx("span", {
293
+ className: "flex shrink-0",
294
+ children: leading
295
+ }) : null, /* @__PURE__ */ jsxs("div", {
296
+ className: "grid min-w-0 gap-0.5",
297
+ children: [htmlFor ? /* @__PURE__ */ jsx("label", {
298
+ htmlFor,
299
+ className: "text-sm max-md:text-base",
300
+ children: label
301
+ }) : /* @__PURE__ */ jsx("div", {
302
+ className: "text-sm max-md:text-base",
303
+ children: label
304
+ }), description ? /* @__PURE__ */ jsx("p", {
305
+ className: "text-muted-foreground text-sm leading-snug",
306
+ children: description
307
+ }) : null]
308
+ })]
309
+ }), children === void 0 ? null : /* @__PURE__ */ jsx("div", {
310
+ "data-slot": "settings-item-control",
311
+ className: cn(stacked ? "grid" : "flex shrink-0 items-center gap-2 [&_[data-slot=input]]:w-56 [&_[data-slot=select-trigger]]:w-56 max-md:[&_[data-slot=input]]:w-40 max-md:[&_[data-slot=select-trigger]]:w-40"),
312
+ children
313
+ })]
79
314
  });
80
315
  }
81
- export { SettingsDialog };
316
+ export { SettingsDialog, SettingsEmpty, SettingsGroup, SettingsItem, matchSections, normalizeSearch };