@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
@@ -0,0 +1,19 @@
1
+ import * as React from "react";
2
+ import { VariantProps } from "class-variance-authority";
3
+ /**
4
+ * Horizontal page container: centers content, caps its width and (optionally)
5
+ * applies the horizontal gutter. Vertical spacing is the caller's job.
6
+ *
7
+ * Widths: `prose` 840px · `sm` 1120px · `md` 1200px · `lg` 1280px · `xl` 1600px.
8
+ * Gutters: `none` · `sm` (px-6) · `md` (px-6 → sm:px-10 → lg:px-14).
9
+ */
10
+ declare const containerVariants: (props?: ({
11
+ size?: "sm" | "lg" | "prose" | "md" | "xl" | null | undefined;
12
+ gutter?: "sm" | "md" | "none" | null | undefined;
13
+ } & import("class-variance-authority/types").ClassProp) | undefined) => string;
14
+ type ContainerProps = React.ComponentProps<'div'> & VariantProps<typeof containerVariants> & {
15
+ /** Render the single child (e.g. `<main>`, `<section>`) with the container classes. */
16
+ asChild?: boolean;
17
+ };
18
+ declare function Container({ className, size, gutter, asChild, ...props }: ContainerProps): React.JSX.Element;
19
+ export { Container, type ContainerProps, containerVariants };
@@ -0,0 +1,46 @@
1
+ import { cn } from "../lib/cn.js";
2
+ import "react";
3
+ import { cva } from "class-variance-authority";
4
+ import { Slot } from "radix-ui";
5
+ import { jsx } from "react/jsx-runtime";
6
+ // src/components/container.tsx
7
+ /**
8
+ * Horizontal page container: centers content, caps its width and (optionally)
9
+ * applies the horizontal gutter. Vertical spacing is the caller's job.
10
+ *
11
+ * Widths: `prose` 840px · `sm` 1120px · `md` 1200px · `lg` 1280px · `xl` 1600px.
12
+ * Gutters: `none` · `sm` (px-6) · `md` (px-6 → sm:px-10 → lg:px-14).
13
+ */
14
+ const containerVariants = cva("mx-auto w-full", {
15
+ variants: {
16
+ size: {
17
+ prose: "max-w-[840px]",
18
+ sm: "max-w-[1120px]",
19
+ md: "max-w-[1200px]",
20
+ lg: "max-w-[1280px]",
21
+ xl: "max-w-[1600px]"
22
+ },
23
+ gutter: {
24
+ none: "",
25
+ sm: "px-6",
26
+ md: "px-6 sm:px-10 lg:px-14"
27
+ }
28
+ },
29
+ defaultVariants: {
30
+ size: "md",
31
+ gutter: "none"
32
+ }
33
+ });
34
+ function Container({ className, size, gutter, asChild = false, ...props }) {
35
+ const Comp = asChild ? Slot.Root : "div";
36
+ return /* @__PURE__ */ jsx(Comp, {
37
+ "data-slot": "container",
38
+ "data-size": size ?? "md",
39
+ className: cn(containerVariants({
40
+ size,
41
+ gutter
42
+ }), className),
43
+ ...props
44
+ });
45
+ }
46
+ export { Container, containerVariants };
@@ -5,11 +5,15 @@ declare function DialogTrigger({ ...props }: React.ComponentProps<typeof Dialog$
5
5
  declare function DialogPortal({ ...props }: React.ComponentProps<typeof Dialog$1.Portal>): React.JSX.Element;
6
6
  declare function DialogClose({ ...props }: React.ComponentProps<typeof Dialog$1.Close>): React.JSX.Element;
7
7
  declare function DialogOverlay({ className, ...props }: React.ComponentProps<typeof Dialog$1.Overlay>): React.JSX.Element;
8
- declare function DialogContent({ className, children, showCloseButton, ...props }: React.ComponentProps<typeof Dialog$1.Content> & {
8
+ declare function DialogContent({ className, children, showCloseButton, closeLabel, ...props }: React.ComponentProps<typeof Dialog$1.Content> & {
9
+ /** Accessible label of the built-in close button. */
10
+ closeLabel?: string;
9
11
  showCloseButton?: boolean;
10
12
  }): React.JSX.Element;
11
13
  declare function DialogHeader({ className, ...props }: React.ComponentProps<'div'>): React.JSX.Element;
12
- declare function DialogFooter({ className, showCloseButton, children, ...props }: React.ComponentProps<'div'> & {
14
+ declare function DialogFooter({ className, showCloseButton, closeLabel, children, ...props }: React.ComponentProps<'div'> & {
15
+ /** Text of the footer close button. */
16
+ closeLabel?: string;
13
17
  showCloseButton?: boolean;
14
18
  }): React.JSX.Element;
15
19
  declare function DialogTitle({ className, ...props }: React.ComponentProps<typeof Dialog$1.Title>): React.JSX.Element;
@@ -37,7 +37,7 @@ function DialogOverlay({ className, ...props }) {
37
37
  ...props
38
38
  });
39
39
  }
40
- function DialogContent({ className, children, showCloseButton = true, ...props }) {
40
+ function DialogContent({ className, children, showCloseButton = true, closeLabel = "Close", ...props }) {
41
41
  return /* @__PURE__ */ jsxs(DialogPortal, { children: [/* @__PURE__ */ jsx(DialogOverlay, {}), /* @__PURE__ */ jsxs(Dialog$1.Content, {
42
42
  "data-slot": "dialog-content",
43
43
  className: cn("bg-popover text-popover-foreground ring-foreground/10 data-open:animate-in data-open:fade-in-0 data-open:zoom-in-95 data-closed:animate-out data-closed:fade-out-0 data-closed:zoom-out-95 fixed top-1/2 left-1/2 z-50 grid w-full max-w-[calc(100%-2rem)] -translate-x-1/2 -translate-y-1/2 gap-4 rounded-xl p-4 text-sm ring-1 duration-100 outline-none sm:max-w-sm", className),
@@ -51,7 +51,7 @@ function DialogContent({ className, children, showCloseButton = true, ...props }
51
51
  size: "icon-sm",
52
52
  children: [/* @__PURE__ */ jsx(XIcon, {}), /* @__PURE__ */ jsx("span", {
53
53
  className: "sr-only",
54
- children: "Close"
54
+ children: closeLabel
55
55
  })]
56
56
  })
57
57
  })]
@@ -64,7 +64,7 @@ function DialogHeader({ className, ...props }) {
64
64
  ...props
65
65
  });
66
66
  }
67
- function DialogFooter({ className, showCloseButton = false, children, ...props }) {
67
+ function DialogFooter({ className, showCloseButton = false, closeLabel = "Close", children, ...props }) {
68
68
  return /* @__PURE__ */ jsxs("div", {
69
69
  "data-slot": "dialog-footer",
70
70
  className: cn("bg-muted/50 -mx-4 -mb-4 flex flex-col-reverse gap-2 rounded-b-xl border-t p-4 sm:flex-row sm:justify-end", className),
@@ -73,7 +73,7 @@ function DialogFooter({ className, showCloseButton = false, children, ...props }
73
73
  asChild: true,
74
74
  children: /* @__PURE__ */ jsx(Button, {
75
75
  variant: "outline",
76
- children: "Close"
76
+ children: closeLabel
77
77
  })
78
78
  })]
79
79
  });
@@ -7,7 +7,11 @@ declare function DropdownMenuContent({ className, align, sideOffset, ...props }:
7
7
  declare function DropdownMenuGroup({ ...props }: React.ComponentProps<typeof DropdownMenu$1.Group>): React.JSX.Element;
8
8
  declare function DropdownMenuItem({ className, inset, variant, ...props }: React.ComponentProps<typeof DropdownMenu$1.Item> & {
9
9
  inset?: boolean;
10
- variant?: 'default' | 'destructive';
10
+ /**
11
+ * `highlight`: blue label and icon on the usual background, for the menu's
12
+ * creation action (e.g. "Novo negócio…"), as in Notion.
13
+ */
14
+ variant?: 'default' | 'destructive' | 'highlight';
11
15
  }): React.JSX.Element;
12
16
  declare function DropdownMenuCheckboxItem({ className, children, checked, inset, ...props }: React.ComponentProps<typeof DropdownMenu$1.CheckboxItem> & {
13
17
  inset?: boolean;
@@ -43,7 +43,7 @@ function DropdownMenuItem({ className, inset, variant = "default", ...props }) {
43
43
  "data-slot": "dropdown-menu-item",
44
44
  "data-inset": inset,
45
45
  "data-variant": variant,
46
- className: cn("group/dropdown-menu-item focus:bg-accent focus:text-accent-foreground not-data-[variant=destructive]:focus:**:text-accent-foreground data-[variant=destructive]:text-destructive data-[variant=destructive]:focus:bg-destructive/10 data-[variant=destructive]:focus:text-destructive dark:data-[variant=destructive]:focus:bg-destructive/20 data-[variant=destructive]:*:[svg]:text-destructive relative flex cursor-default items-center gap-1.5 rounded-md px-1.5 py-1 text-sm outline-hidden select-none data-disabled:pointer-events-none data-disabled:opacity-50 data-inset:pl-7 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4", className),
46
+ className: cn("group/dropdown-menu-item focus:bg-accent data-[variant=default]:focus:text-accent-foreground data-[variant=default]:focus:**:text-accent-foreground data-[variant=highlight]:text-blue-600 dark:data-[variant=highlight]:text-blue-400 data-[variant=highlight]:*:[svg]:text-current data-[variant=destructive]:text-destructive data-[variant=destructive]:focus:bg-destructive/10 data-[variant=destructive]:focus:text-destructive dark:data-[variant=destructive]:focus:bg-destructive/20 data-[variant=destructive]:*:[svg]:text-destructive relative flex cursor-default items-center gap-1.5 rounded-md px-1.5 py-1 text-sm outline-hidden select-none data-disabled:pointer-events-none data-disabled:opacity-50 data-inset:pl-7 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4", className),
47
47
  ...props
48
48
  });
49
49
  }
@@ -112,7 +112,7 @@ function DropdownMenuSubTrigger({ className, inset, children, ...props }) {
112
112
  return /* @__PURE__ */ jsxs(DropdownMenu$1.SubTrigger, {
113
113
  "data-slot": "dropdown-menu-sub-trigger",
114
114
  "data-inset": inset,
115
- className: cn("focus:bg-accent focus:text-accent-foreground not-data-[variant=destructive]:focus:**:text-accent-foreground data-open:bg-accent data-open:text-accent-foreground flex cursor-default items-center gap-1.5 rounded-md px-1.5 py-1 text-sm outline-hidden select-none data-inset:pl-7 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4", className),
115
+ className: cn("focus:bg-accent data-[variant=default]:focus:text-accent-foreground data-[variant=default]:focus:**:text-accent-foreground data-[variant=highlight]:text-blue-600 dark:data-[variant=highlight]:text-blue-400 data-[variant=highlight]:*:[svg]:text-current data-open:bg-accent data-open:text-accent-foreground flex cursor-default items-center gap-1.5 rounded-md px-1.5 py-1 text-sm outline-hidden select-none data-inset:pl-7 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4", className),
116
116
  ...props,
117
117
  children: [children, /* @__PURE__ */ jsx(ChevronRightIcon, { className: "ml-auto" })]
118
118
  });
@@ -0,0 +1,24 @@
1
+ import * as React from "react";
2
+ type PageHeaderProps = Omit<React.ComponentProps<'div'>, 'title'> & {
3
+ /** Page title, rendered as the page's `<h1>`. */
4
+ title: React.ReactNode;
5
+ /** Optional supporting copy under the title. */
6
+ description?: React.ReactNode;
7
+ /** Optional trailing actions (buttons, menus), aligned to the end of the row. */
8
+ actions?: React.ReactNode;
9
+ };
10
+ /**
11
+ * Title row of an app page: `<h1>` + optional description on the start side,
12
+ * optional actions on the end side (wrapping below on narrow screens).
13
+ * Outer spacing is the caller's job — pass it via `className`.
14
+ */
15
+ declare function PageHeader({ title, description, actions, className, ...props }: PageHeaderProps): React.JSX.Element;
16
+ type PageHeaderSkeletonProps = React.ComponentProps<'div'> & {
17
+ /** Width class of the title bar. */
18
+ titleWidth?: string;
19
+ /** Width class of the description bar; `null` hides it. */
20
+ descriptionWidth?: string | null;
21
+ };
22
+ /** Loading placeholder whose dimensions mirror `PageHeader` (title + description). */
23
+ declare function PageHeaderSkeleton({ titleWidth, descriptionWidth, className, ...props }: PageHeaderSkeletonProps): React.JSX.Element;
24
+ export { PageHeader, type PageHeaderProps, PageHeaderSkeleton, type PageHeaderSkeletonProps };
@@ -0,0 +1,42 @@
1
+ import { cn } from "../lib/cn.js";
2
+ import { Skeleton } from "./skeleton.js";
3
+ import "react";
4
+ import { jsx, jsxs } from "react/jsx-runtime";
5
+ // src/components/page-header.tsx
6
+ /**
7
+ * Title row of an app page: `<h1>` + optional description on the start side,
8
+ * optional actions on the end side (wrapping below on narrow screens).
9
+ * Outer spacing is the caller's job — pass it via `className`.
10
+ */
11
+ function PageHeader({ title, description, actions, className, ...props }) {
12
+ return /* @__PURE__ */ jsxs("div", {
13
+ "data-slot": "page-header",
14
+ className: cn("flex flex-wrap items-center justify-between gap-2", className),
15
+ ...props,
16
+ children: [/* @__PURE__ */ jsxs("div", {
17
+ className: "min-w-0 flex-1",
18
+ children: [/* @__PURE__ */ jsx("h1", {
19
+ className: "text-xl font-semibold tracking-tight md:text-2xl",
20
+ children: title
21
+ }), description ? /* @__PURE__ */ jsx("p", {
22
+ "data-slot": "page-header-description",
23
+ className: "text-muted-foreground mt-1 text-sm md:text-base",
24
+ children: description
25
+ }) : null]
26
+ }), actions ? /* @__PURE__ */ jsx("div", {
27
+ "data-slot": "page-header-actions",
28
+ className: "flex flex-wrap items-center gap-2",
29
+ children: actions
30
+ }) : null]
31
+ });
32
+ }
33
+ /** Loading placeholder whose dimensions mirror `PageHeader` (title + description). */
34
+ function PageHeaderSkeleton({ titleWidth = "w-40", descriptionWidth = "w-64", className, ...props }) {
35
+ return /* @__PURE__ */ jsxs("div", {
36
+ "data-slot": "page-header-skeleton",
37
+ className,
38
+ ...props,
39
+ children: [/* @__PURE__ */ jsx(Skeleton, { className: cn("h-6 md:h-7", titleWidth) }), descriptionWidth ? /* @__PURE__ */ jsx(Skeleton, { className: cn("mt-1 h-4 md:h-5", descriptionWidth) }) : null]
40
+ });
41
+ }
42
+ export { PageHeader, PageHeaderSkeleton };
@@ -6,8 +6,26 @@ export type SettingsDialogSection<K extends string = string> = {
6
6
  icon?: React.ComponentType<{
7
7
  className?: string;
8
8
  }>;
9
- /** Shown under the title in the header while this section is active. */
9
+ /** Shown on top of the content while this section is active. */
10
10
  description?: React.ReactNode;
11
+ /** Extra terms the search matches (what the section holds, synonyms). */
12
+ keywords?: readonly string[];
13
+ /** Sections sharing a group sit together; a divider separates groups. */
14
+ group?: string;
15
+ };
16
+ export type SettingsDialogLabels = {
17
+ /** Title of the modal. */
18
+ title: string;
19
+ /** Accessible name of the section nav. */
20
+ nav: string;
21
+ /** Accessible name of the search box. */
22
+ search: string;
23
+ /** Short placeholder of the search box (the nav column is narrow). */
24
+ searchPlaceholder: string;
25
+ /** Accessible name of the search's clear button. */
26
+ clearSearch: string;
27
+ /** Shown in the nav when no section matches. */
28
+ noResults: string;
11
29
  };
12
30
  export type SettingsDialogProps<K extends string = string> = {
13
31
  open?: boolean;
@@ -19,18 +37,55 @@ export type SettingsDialogProps<K extends string = string> = {
19
37
  /** Initial section when uncontrolled. Defaults to the first section. */
20
38
  defaultValue?: K;
21
39
  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;
40
+ labels?: Partial<SettingsDialogLabels>;
26
41
  /** Content of the active section; apps switch on the value. */
27
42
  children?: React.ReactNode;
28
43
  className?: string;
29
44
  };
30
45
  /**
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.
46
+ * Sections where every word of the query starts some word of the label or
47
+ * keywords (accents and plurals ignored).
48
+ */
49
+ export declare function matchSections<K extends string>(sections: readonly SettingsDialogSection<K>[], query: string): readonly SettingsDialogSection<K>[];
50
+ /**
51
+ * Settings modal: a title bar, then the section nav (a column from `sm`, a
52
+ * row on phones) under a search box, beside the active section's content.
53
+ * Typing filters the nav by label and keywords; Enter opens the first match;
54
+ * Escape (or the clear button) empties the search before closing.
55
+ */
56
+ export declare function SettingsDialog<K extends string>({ open, defaultOpen, onOpenChange, sections, value, defaultValue, onValueChange, labels: labelsProp, children, className }: SettingsDialogProps<K>): React.JSX.Element;
57
+ /** A titled block of settings rows ("Perfil", "Geral"…). */
58
+ export declare function SettingsGroup({ title, action, listLabel, children, className }: {
59
+ title?: React.ReactNode;
60
+ /** Right of the title (e.g. a small button acting on the whole group). */
61
+ action?: React.ReactNode;
62
+ /**
63
+ * Makes the rows a list (`ul`, named by this label) — for a variable set of
64
+ * items (accounts, units, rules). Render each row as `SettingsItem as="li"`.
65
+ */
66
+ listLabel?: string;
67
+ children?: React.ReactNode;
68
+ className?: string;
69
+ }): React.JSX.Element;
70
+ /** Muted text standing for a group with nothing to list ("Nenhuma regra ainda."). */
71
+ export declare function SettingsEmpty({ children }: {
72
+ children: React.ReactNode;
73
+ }): React.JSX.Element;
74
+ /**
75
+ * One setting: label (and description) on the left, its control on the right
76
+ * — or, with `layout="stacked"`, a large control (a textarea) under them.
77
+ * Inputs and select triggers in the control get the standard compact width.
35
78
  */
36
- export declare function SettingsDialog<K extends string>({ open, defaultOpen, onOpenChange, sections, value, defaultValue, onValueChange, navLabel, title, children, className }: SettingsDialogProps<K>): React.JSX.Element;
79
+ export declare function SettingsItem({ label, description, leading, htmlFor, layout, as: Row, children, className }: {
80
+ label: React.ReactNode;
81
+ description?: React.ReactNode;
82
+ /** Before the label: an icon or avatar identifying the row (e.g. a business). */
83
+ leading?: React.ReactNode;
84
+ /** Id of the control: the label becomes its `<label>`. */
85
+ htmlFor?: string;
86
+ layout?: 'inline' | 'stacked';
87
+ /** `li` inside a `SettingsGroup listLabel`. */
88
+ as?: 'div' | 'li';
89
+ children?: React.ReactNode;
90
+ className?: string;
91
+ }): React.JSX.Element;
@@ -1,22 +1,66 @@
1
1
  "use client";
2
+ import { isDirtyField } from "../hooks/use-autosave-form.js";
2
3
  import { useScrollStrip } from "../hooks/use-scroll-strip.js";
3
4
  import { cn } from "../lib/cn.js";
4
- import { fadeMask } from "../lib/scroll-target.js";
5
5
  import { Dialog, DialogContent, DialogDescription, DialogHeader, DialogTitle } from "./dialog.js";
6
+ import { InputGroup, InputGroupAddon, InputGroupInput } from "./input-group.js";
6
7
  import { ScrollArea } from "./scroll-area.js";
7
8
  import * as React from "react";
8
9
  import { jsx, jsxs } from "react/jsx-runtime";
10
+ import { Search, X } from "lucide-react";
9
11
  // src/components/settings-dialog.tsx
12
+ const DEFAULT_LABELS = {
13
+ title: "Configurações",
14
+ nav: "Seções de configuração",
15
+ search: "Buscar configurações",
16
+ searchPlaceholder: "Procurar",
17
+ clearSearch: "Limpar busca",
18
+ noResults: "Nada encontrado"
19
+ };
20
+ /** Fades only the edges of the phone strip that hide sections (as in the DS). */
21
+ function fadeMask({ start, end }) {
22
+ if (!start && !end) return void 0;
23
+ return `linear-gradient(to right, ${start ? "transparent 0, black 1.5rem" : "black 0"}, ${end ? "black calc(100% - 1.5rem), transparent 100%" : "black 100%"})`;
24
+ }
25
+ /** Lowercase without diacritics, so "aparencia" finds "Aparência". */
26
+ function normalizeSearch(text) {
27
+ return text.normalize("NFD").replace(/\p{Diacritic}/gu, "").toLowerCase().trim();
28
+ }
29
+ /** Light plural folding, so "conexão" finds "Conexões" and "regra" "Regras". */
30
+ function stem(word) {
31
+ return word.replace(/(oes|aes)$/, "ao").replace(/(?<=.{3})s$/, "");
32
+ }
33
+ /** Each word normalized, plus its plural-folded form. */
34
+ const words = (text) => normalizeSearch(text).split(/[\s\-/]+/).filter(Boolean).flatMap((word) => [word, stem(word)]);
35
+ /**
36
+ * Sections where every word of the query starts some word of the label or
37
+ * keywords (accents and plurals ignored).
38
+ */
39
+ function matchSections(sections, query) {
40
+ const terms = normalizeSearch(query).split(/\s+/).filter(Boolean);
41
+ if (terms.length === 0) return sections;
42
+ return sections.filter((section) => {
43
+ const haystack = words([section.label, ...section.keywords ?? []].join(" "));
44
+ return terms.every((term) => [term, stem(term)].some((form) => haystack.some((word) => word.startsWith(form))));
45
+ });
46
+ }
10
47
  /**
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.
48
+ * Settings modal: a title bar, then the section nav (a column from `sm`, a
49
+ * row on phones) under a search box, beside the active section's content.
50
+ * Typing filters the nav by label and keywords; Enter opens the first match;
51
+ * Escape (or the clear button) empties the search before closing.
15
52
  */
16
- function SettingsDialog({ open, defaultOpen, onOpenChange, sections, value, defaultValue, onValueChange, navLabel = "Settings sections", title, children, className }) {
53
+ function SettingsDialog({ open, defaultOpen, onOpenChange, sections, value, defaultValue, onValueChange, labels: labelsProp, children, className }) {
54
+ const labels = {
55
+ ...DEFAULT_LABELS,
56
+ ...labelsProp
57
+ };
17
58
  const [inner, setInner] = React.useState(defaultValue);
59
+ const [query, setQuery] = React.useState("");
60
+ const searchRef = React.useRef(null);
18
61
  const current = value ?? inner ?? sections[0]?.key;
19
62
  const active = sections.find((s) => s.key === current);
63
+ const visible = matchSections(sections, query);
20
64
  const select = (key) => {
21
65
  if (value === void 0) setInner(key);
22
66
  onValueChange?.(key);
@@ -27,55 +71,192 @@ function SettingsDialog({ open, defaultOpen, onOpenChange, sections, value, defa
27
71
  onOpenChange,
28
72
  children: /* @__PURE__ */ jsxs(DialogContent, {
29
73
  "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),
74
+ className: cn("flex h-[min(85vh,44rem)] max-w-4xl flex-col gap-0 overflow-hidden p-0 sm:max-w-4xl", className),
31
75
  onOpenAutoFocus: (event) => event.preventDefault(),
32
- children: [/* @__PURE__ */ jsx(SettingsDialogNav, {
33
- label: navLabel,
34
- sections,
35
- current,
36
- onSelect: select
76
+ onEscapeKeyDown: (event) => {
77
+ if (isDirtyField(document.activeElement)) {
78
+ event.preventDefault();
79
+ return;
80
+ }
81
+ if (query === "") return;
82
+ event.preventDefault();
83
+ setQuery("");
84
+ },
85
+ children: [/* @__PURE__ */ jsxs(DialogHeader, {
86
+ className: "border-b px-4 py-3 pr-12 text-left",
87
+ children: [/* @__PURE__ */ jsx(DialogTitle, {
88
+ className: "text-base",
89
+ children: labels.title
90
+ }), /* @__PURE__ */ jsx(DialogDescription, {
91
+ className: "sr-only",
92
+ children: active?.label
93
+ })]
37
94
  }), /* @__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
95
+ className: "grid min-h-0 flex-1 grid-rows-[auto_1fr] sm:grid-cols-[14rem_minmax(0,1fr)] sm:grid-rows-1",
96
+ children: [/* @__PURE__ */ jsxs("div", {
97
+ className: "flex min-w-0 flex-col gap-2 border-b p-3 sm:border-r sm:border-b-0",
98
+ children: [/* @__PURE__ */ jsxs(InputGroup, {
99
+ className: "bg-muted/70 dark:bg-muted/50 h-8 border-transparent shadow-none",
100
+ children: [
101
+ /* @__PURE__ */ jsx(InputGroupAddon, {
102
+ align: "inline-start",
103
+ children: /* @__PURE__ */ jsx(Search, { "aria-hidden": true })
104
+ }),
105
+ /* @__PURE__ */ jsx(InputGroupInput, {
106
+ ref: searchRef,
107
+ type: "search",
108
+ value: query,
109
+ placeholder: labels.searchPlaceholder,
110
+ "aria-label": labels.search,
111
+ className: "[&::-webkit-search-cancel-button]:appearance-none",
112
+ onChange: (event) => setQuery(event.target.value),
113
+ onKeyDown: (event) => {
114
+ const first = visible[0];
115
+ if (event.key === "Enter" && first !== void 0) {
116
+ event.preventDefault();
117
+ select(first.key);
118
+ }
119
+ }
120
+ }),
121
+ query === "" ? null : /* @__PURE__ */ jsx(InputGroupAddon, {
122
+ align: "inline-end",
123
+ children: /* @__PURE__ */ jsx("button", {
124
+ type: "button",
125
+ "aria-label": labels.clearSearch,
126
+ onClick: () => {
127
+ setQuery("");
128
+ searchRef.current?.focus();
129
+ },
130
+ 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",
131
+ children: /* @__PURE__ */ jsx(X, {
132
+ "aria-hidden": true,
133
+ className: "size-3.5"
134
+ })
135
+ })
136
+ })
137
+ ]
138
+ }), /* @__PURE__ */ jsx(SettingsNav, {
139
+ label: labels.nav,
140
+ noResults: labels.noResults,
141
+ sections: visible,
142
+ current,
143
+ onSelect: select
44
144
  })]
45
145
  }), /* @__PURE__ */ jsx(ScrollArea, {
46
- className: "min-h-0 flex-1 [&_[data-slot=scroll-area-viewport]>div]:!block",
47
- children: /* @__PURE__ */ jsx("div", {
146
+ className: "min-h-0 [&_[data-slot=scroll-area-viewport]>div]:!block",
147
+ children: /* @__PURE__ */ jsxs("div", {
148
+ role: "region",
149
+ "aria-label": active?.label,
48
150
  "data-slot": "settings-dialog-content",
49
- className: "p-6",
50
- children
151
+ className: "grid gap-8 px-6 py-5",
152
+ children: [active?.description ? /* @__PURE__ */ jsx("p", {
153
+ className: "text-muted-foreground -mb-4 text-sm",
154
+ children: active.description
155
+ }) : null, children]
51
156
  })
52
157
  })]
53
158
  })]
54
159
  })
55
160
  });
56
161
  }
57
- function SettingsDialogNav({ label, sections, current, onSelect }) {
162
+ function SettingsNav({ label, noResults, sections, current, onSelect }) {
58
163
  const ref = React.useRef(null);
59
164
  const edges = useScrollStrip(ref, "[aria-current=\"page\"]");
60
- return /* @__PURE__ */ jsx("nav", {
165
+ return /* @__PURE__ */ jsxs("nav", {
61
166
  ref,
62
167
  "aria-label": label,
63
168
  "data-slot": "settings-dialog-nav",
64
169
  "data-fade-start": edges.start || void 0,
65
170
  "data-fade-end": edges.end || void 0,
66
171
  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", {
172
+ className: "flex [scrollbar-width:none] gap-0.5 overflow-x-auto sm:flex-col sm:overflow-x-visible [&::-webkit-scrollbar]:hidden",
173
+ 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", {
174
+ role: "separator",
175
+ className: "bg-border mx-2.5 my-2 hidden h-px sm:block"
176
+ }) : null, /* @__PURE__ */ jsxs("button", {
69
177
  type: "button",
70
178
  onClick: () => onSelect(key),
71
179
  "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",
180
+ 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
181
  children: [Icon ? /* @__PURE__ */ jsx("span", {
74
182
  "aria-hidden": true,
75
183
  className: "flex shrink-0",
76
184
  children: /* @__PURE__ */ jsx(Icon, { className: "size-4" })
77
185
  }) : null, itemLabel]
78
- }, key))
186
+ })] }, key)), sections.length === 0 ? /* @__PURE__ */ jsx("p", {
187
+ role: "status",
188
+ className: "text-muted-foreground px-2.5 py-1.5 text-sm",
189
+ children: noResults
190
+ }) : null]
191
+ });
192
+ }
193
+ /** A titled block of settings rows ("Perfil", "Geral"…). */
194
+ function SettingsGroup({ title, action, listLabel, children, className }) {
195
+ return /* @__PURE__ */ jsxs("section", {
196
+ "data-slot": "settings-group",
197
+ className: cn("grid gap-1", className),
198
+ children: [title || action ? /* @__PURE__ */ jsxs("div", {
199
+ className: "flex min-h-8 items-center justify-between gap-4",
200
+ children: [title ? /* @__PURE__ */ jsx("h3", {
201
+ className: "text-sm font-medium",
202
+ children: title
203
+ }) : /* @__PURE__ */ jsx("span", {}), action ? /* @__PURE__ */ jsx("div", {
204
+ className: "flex items-center gap-2",
205
+ children: action
206
+ }) : null]
207
+ }) : null, listLabel === void 0 ? /* @__PURE__ */ jsx("div", {
208
+ className: "grid",
209
+ children
210
+ }) : /* @__PURE__ */ jsx("ul", {
211
+ "aria-label": listLabel,
212
+ className: "grid",
213
+ children
214
+ })]
215
+ });
216
+ }
217
+ /** Muted text standing for a group with nothing to list ("Nenhuma regra ainda."). */
218
+ function SettingsEmpty({ children }) {
219
+ return /* @__PURE__ */ jsx("p", {
220
+ "data-slot": "settings-empty",
221
+ className: "text-muted-foreground py-2.5 text-sm",
222
+ children
223
+ });
224
+ }
225
+ /**
226
+ * One setting: label (and description) on the left, its control on the right
227
+ * — or, with `layout="stacked"`, a large control (a textarea) under them.
228
+ * Inputs and select triggers in the control get the standard compact width.
229
+ */
230
+ function SettingsItem({ label, description, leading, htmlFor, layout = "inline", as: Row = "div", children, className }) {
231
+ const stacked = layout === "stacked";
232
+ return /* @__PURE__ */ jsxs(Row, {
233
+ "data-slot": "settings-item",
234
+ "data-layout": layout,
235
+ className: cn("flex min-h-12 gap-6 border-b py-2.5 last:border-b-0", stacked ? "flex-col gap-2" : "items-center justify-between", className),
236
+ children: [/* @__PURE__ */ jsxs("div", {
237
+ className: "flex min-w-0 items-center gap-3",
238
+ children: [leading ? /* @__PURE__ */ jsx("span", {
239
+ className: "flex shrink-0",
240
+ children: leading
241
+ }) : null, /* @__PURE__ */ jsxs("div", {
242
+ className: "grid min-w-0 gap-0.5",
243
+ children: [htmlFor ? /* @__PURE__ */ jsx("label", {
244
+ htmlFor,
245
+ className: "text-sm",
246
+ children: label
247
+ }) : /* @__PURE__ */ jsx("div", {
248
+ className: "text-sm",
249
+ children: label
250
+ }), description ? /* @__PURE__ */ jsx("p", {
251
+ className: "text-muted-foreground text-sm leading-snug",
252
+ children: description
253
+ }) : null]
254
+ })]
255
+ }), children === void 0 ? null : /* @__PURE__ */ jsx("div", {
256
+ "data-slot": "settings-item-control",
257
+ className: cn(stacked ? "grid" : "flex shrink-0 items-center gap-2 [&_[data-slot=input]]:w-56 [&_[data-slot=select-trigger]]:w-56"),
258
+ children
259
+ })]
79
260
  });
80
261
  }
81
- export { SettingsDialog };
262
+ export { SettingsDialog, SettingsEmpty, SettingsGroup, SettingsItem, matchSections, normalizeSearch };
@@ -3,7 +3,9 @@ import { Dialog } from "radix-ui";
3
3
  declare function Sheet({ ...props }: React.ComponentProps<typeof Dialog.Root>): React.JSX.Element;
4
4
  declare function SheetTrigger({ ...props }: React.ComponentProps<typeof Dialog.Trigger>): React.JSX.Element;
5
5
  declare function SheetClose({ ...props }: React.ComponentProps<typeof Dialog.Close>): React.JSX.Element;
6
- declare function SheetContent({ className, children, side, showCloseButton, ...props }: React.ComponentProps<typeof Dialog.Content> & {
6
+ declare function SheetContent({ className, children, side, showCloseButton, closeLabel, ...props }: React.ComponentProps<typeof Dialog.Content> & {
7
+ /** Accessible label of the built-in close button. */
8
+ closeLabel?: string;
7
9
  side?: 'top' | 'right' | 'bottom' | 'left';
8
10
  showCloseButton?: boolean;
9
11
  }): React.JSX.Element;
@@ -37,7 +37,7 @@ function SheetOverlay({ className, ...props }) {
37
37
  ...props
38
38
  });
39
39
  }
40
- function SheetContent({ className, children, side = "right", showCloseButton = true, ...props }) {
40
+ function SheetContent({ className, children, side = "right", showCloseButton = true, closeLabel = "Close", ...props }) {
41
41
  return /* @__PURE__ */ jsxs(SheetPortal, { children: [/* @__PURE__ */ jsx(SheetOverlay, {}), /* @__PURE__ */ jsxs(Dialog.Content, {
42
42
  "data-slot": "sheet-content",
43
43
  "data-side": side,
@@ -52,7 +52,7 @@ function SheetContent({ className, children, side = "right", showCloseButton = t
52
52
  size: "icon-sm",
53
53
  children: [/* @__PURE__ */ jsx(XIcon, {}), /* @__PURE__ */ jsx("span", {
54
54
  className: "sr-only",
55
- children: "Close"
55
+ children: closeLabel
56
56
  })]
57
57
  })
58
58
  })]