@behavioral-agentic-design-system/core 0.5.0 → 0.7.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 (61) hide show
  1. package/LICENSE +21 -0
  2. package/package.json +39 -7
  3. package/scripts/bads-sync.mjs +1 -1
  4. package/scripts/build-fonts.cjs +97 -0
  5. package/scripts/build-tokens.cjs +202 -10
  6. package/src/api/brand-fonts.ts +301 -0
  7. package/src/api/brand-mark.ts +146 -0
  8. package/src/api/layers/file.ts +8 -5
  9. package/src/api/layers.ts +27 -4
  10. package/src/api/site-auth.ts +50 -0
  11. package/src/app/preview/cards/page.tsx +1 -1
  12. package/src/app/preview/components/page.tsx +78 -1
  13. package/src/app/preview/icons/page.tsx +5 -0
  14. package/src/app/shell.tsx +105 -39
  15. package/src/app/site-login/page.tsx +82 -0
  16. package/src/brand-fonts.css +5 -0
  17. package/src/components/Foundations/Motion.stories.tsx +66 -0
  18. package/src/components/brand-mark.tsx +64 -0
  19. package/src/components/customize/brand-mark-section.tsx +265 -0
  20. package/src/components/customize/font-pickers.tsx +293 -0
  21. package/src/components/customize/letter-spacing.tsx +3 -2
  22. package/src/components/customize/save-bar.tsx +11 -5
  23. package/src/components/customize/type-scale.tsx +3 -2
  24. package/src/components/customize-tab.tsx +330 -24
  25. package/src/components/dev-identity-badge.tsx +92 -0
  26. package/src/components/home-tab.tsx +1291 -380
  27. package/src/components/layers-tab.tsx +179 -12
  28. package/src/components/ui/alert.tsx +10 -2
  29. package/src/components/ui/bottom-sheet.tsx +124 -0
  30. package/src/components/ui/button.tsx +2 -2
  31. package/src/components/ui/calendar.tsx +1 -1
  32. package/src/components/ui/chart.tsx +118 -7
  33. package/src/components/ui/checkbox.tsx +3 -2
  34. package/src/components/ui/dialog.tsx +3 -3
  35. package/src/components/ui/index.ts +1 -0
  36. package/src/components/ui/radio-group.tsx +4 -3
  37. package/src/components/ui/sheet.tsx +1 -1
  38. package/src/components/ui/sidebar.tsx +6 -1
  39. package/src/components/ui/sonner.tsx +18 -0
  40. package/src/components/ui/switch.tsx +9 -3
  41. package/src/components/ui/tabs.tsx +7 -1
  42. package/src/fonts/HyperlegibleSans-Bold.woff2 +0 -0
  43. package/src/fonts/HyperlegibleSans-BoldItalic.woff2 +0 -0
  44. package/src/fonts/HyperlegibleSans-Italic.woff2 +0 -0
  45. package/src/fonts/HyperlegibleSans-Medium.woff2 +0 -0
  46. package/src/fonts/HyperlegibleSans-MediumItalic.woff2 +0 -0
  47. package/src/fonts/HyperlegibleSans-Regular.woff2 +0 -0
  48. package/src/fonts/InterVariable-Italic.woff2 +0 -0
  49. package/src/fonts/InterVariable.woff2 +0 -0
  50. package/src/fonts.css +99 -0
  51. package/src/hooks/use-global-brand-mark.ts +64 -0
  52. package/src/hooks/use-global-mono-font.ts +13 -3
  53. package/src/hooks/use-global-primary-color.ts +192 -9
  54. package/src/hooks/use-global-sans-font.ts +5 -3
  55. package/src/hooks/use-global-serif-font.ts +13 -3
  56. package/src/lib/storage.ts +29 -0
  57. package/src/lib/svg-sanitize.ts +272 -0
  58. package/src/styles.css +126 -6
  59. package/src/tokens.json +100 -9
  60. package/src/app/preview/mail/page.tsx +0 -4
  61. package/src/app/preview/pricing/page.tsx +0 -4
@@ -2,6 +2,8 @@
2
2
 
3
3
  import { useEffect, useState } from "react";
4
4
  import { Loader2, FileText, GitCommit, ChevronRight, Check, AlertCircle } from "lucide-react";
5
+ import ReactMarkdown, { type Components } from "react-markdown";
6
+ import remarkGfm from "remark-gfm";
5
7
  import { Button } from "@behavioral-agentic-design-system/core/components/ui/button";
6
8
  import { Input } from "@behavioral-agentic-design-system/core/components/ui/input";
7
9
  import { Textarea } from "@behavioral-agentic-design-system/core/components/ui/textarea";
@@ -9,16 +11,132 @@ import { ScrollArea } from "@behavioral-agentic-design-system/core/components/ui
9
11
 
10
12
  type LayerEntry = { slug: string; label: string; files: string[] };
11
13
  type SaveStatus = "idle" | "saving" | "success" | "error";
14
+ type FileType = "editable" | "read-only";
15
+ type ViewMode = "preview" | "code";
16
+
17
+ function getFileType(path: string): FileType {
18
+ if (path.endsWith("tokens.json")) return "read-only";
19
+ return "editable";
20
+ }
21
+
22
+ function isMarkdown(path: string | null): boolean {
23
+ return !!path && path.toLowerCase().endsWith(".md");
24
+ }
25
+
26
+ // BADS-styled wrapper around react-markdown so the rendered preview reads
27
+ // like the rest of the system (token-aligned colors, AAA text contrast,
28
+ // 14px floor on body type via the global type scale).
29
+ const MARKDOWN_COMPONENTS: Components = {
30
+ h1: ({ children, ...props }: any) => (
31
+ <h1 className="mt-6 mb-3 text-2xl font-semibold tracking-tight first:mt-0" {...props}>{children}</h1>
32
+ ),
33
+ h2: ({ children, ...props }: any) => (
34
+ <h2 className="mt-6 mb-3 text-xl font-semibold tracking-tight first:mt-0" {...props}>{children}</h2>
35
+ ),
36
+ h3: ({ children, ...props }: any) => (
37
+ <h3 className="mt-5 mb-2 text-lg font-semibold tracking-tight" {...props}>{children}</h3>
38
+ ),
39
+ h4: ({ children, ...props }: any) => (
40
+ <h4 className="mt-4 mb-2 text-base font-semibold" {...props}>{children}</h4>
41
+ ),
42
+ h5: ({ children, ...props }: any) => (
43
+ <h5 className="mt-3 mb-1 text-sm font-semibold uppercase tracking-wide text-muted-foreground" {...props}>{children}</h5>
44
+ ),
45
+ h6: ({ children, ...props }: any) => (
46
+ <h6 className="mt-3 mb-1 text-sm font-semibold uppercase tracking-wide text-muted-foreground" {...props}>{children}</h6>
47
+ ),
48
+ p: ({ children, ...props }: any) => (
49
+ <p className="mb-3 leading-relaxed" {...props}>{children}</p>
50
+ ),
51
+ a: ({ children, href, ...props }: any) => (
52
+ <a href={href} target="_blank" rel="noreferrer" className="text-primary underline underline-offset-2 hover:text-primary/80" {...props}>{children}</a>
53
+ ),
54
+ ul: ({ children, ...props }: any) => (
55
+ <ul className="mb-3 list-disc space-y-1 pl-6" {...props}>{children}</ul>
56
+ ),
57
+ ol: ({ children, ...props }: any) => (
58
+ <ol className="mb-3 list-decimal space-y-1 pl-6" {...props}>{children}</ol>
59
+ ),
60
+ li: ({ children, ...props }: any) => (
61
+ <li className="leading-relaxed" {...props}>{children}</li>
62
+ ),
63
+ code: ({ children, className, ...props }: any) => {
64
+ const inline = !/language-/.test(className ?? "");
65
+ if (inline) {
66
+ return (
67
+ <code className="rounded bg-muted px-1.5 py-0.5 font-mono text-xs text-foreground" {...props}>{children}</code>
68
+ );
69
+ }
70
+ return (
71
+ <code className={`font-mono text-xs ${className ?? ""}`} {...props}>{children}</code>
72
+ );
73
+ },
74
+ pre: ({ children, ...props }: any) => (
75
+ <pre className="mb-3 overflow-x-auto rounded-md border bg-muted/50 p-4 text-xs leading-relaxed" {...props}>{children}</pre>
76
+ ),
77
+ blockquote: ({ children, ...props }: any) => (
78
+ <blockquote className="mb-3 border-l-4 border-border pl-4 italic text-muted-foreground" {...props}>{children}</blockquote>
79
+ ),
80
+ hr: () => <hr className="my-6 border-border" />,
81
+ table: ({ children, ...props }: any) => (
82
+ <div className="mb-3 overflow-x-auto">
83
+ <table className="w-full border-collapse text-xs" {...props}>{children}</table>
84
+ </div>
85
+ ),
86
+ thead: ({ children, ...props }: any) => (
87
+ <thead className="border-b bg-muted/40 text-left" {...props}>{children}</thead>
88
+ ),
89
+ th: ({ children, ...props }: any) => (
90
+ <th className="border border-border px-3 py-2 font-medium" {...props}>{children}</th>
91
+ ),
92
+ td: ({ children, ...props }: any) => (
93
+ <td className="border border-border px-3 py-2 align-top" {...props}>{children}</td>
94
+ ),
95
+ img: ({ src, alt, ...props }: any) => (
96
+ <img src={typeof src === "string" ? src : undefined} alt={alt ?? ""} className="my-3 max-w-full rounded-md border" {...props} />
97
+ ),
98
+ strong: ({ children, ...props }: any) => (
99
+ <strong className="font-semibold text-foreground" {...props}>{children}</strong>
100
+ ),
101
+ em: ({ children, ...props }: any) => (
102
+ <em className="italic" {...props}>{children}</em>
103
+ ),
104
+ };
105
+
106
+ function MarkdownPreview({ source }: { source: string }) {
107
+ return (
108
+ <div className="max-w-3xl text-sm text-foreground/90">
109
+ <ReactMarkdown remarkPlugins={[remarkGfm]} components={MARKDOWN_COMPONENTS}>
110
+ {source}
111
+ </ReactMarkdown>
112
+ </div>
113
+ );
114
+ }
115
+
116
+ // fileType is set synchronously when activePath changes, but `content` only
117
+ // updates after the fetch resolves. That tick of stale content briefly
118
+ // renders inside the read-only branch, crashing JSON.parse if the previous
119
+ // file was markdown. Fall back to raw text on any parse error.
120
+ function prettyJsonOrRaw(content: string): string {
121
+ if (!content) return "";
122
+ try {
123
+ return JSON.stringify(JSON.parse(content), null, 2);
124
+ } catch {
125
+ return content;
126
+ }
127
+ }
12
128
 
13
129
  export function LayersTab() {
14
130
  const [layers, setLayers] = useState<LayerEntry[]>([]);
15
131
  const [openLayers, setOpenLayers] = useState<Set<string>>(new Set());
16
132
  const [activePath, setActivePath] = useState<string | null>(null);
133
+ const [fileType, setFileType] = useState<FileType>("editable");
17
134
  const [content, setContent] = useState<string>("");
18
135
  const [originalContent, setOriginalContent] = useState<string>("");
19
136
  const [commitMessage, setCommitMessage] = useState<string>("");
20
137
  const [status, setStatus] = useState<SaveStatus>("idle");
21
138
  const [statusMessage, setStatusMessage] = useState<string>("");
139
+ const [viewMode, setViewMode] = useState<ViewMode>("preview");
22
140
 
23
141
  // Load tree
24
142
  useEffect(() => {
@@ -38,6 +156,7 @@ export function LayersTab() {
38
156
  if (!activePath) return;
39
157
  setStatus("idle");
40
158
  setStatusMessage("");
159
+ setFileType(getFileType(activePath));
41
160
  fetch(`/api/layers/file?path=${encodeURIComponent(activePath)}`)
42
161
  .then((r) => r.json())
43
162
  .then((data) => {
@@ -163,21 +282,69 @@ export function LayersTab() {
163
282
  {activePath.split("/").pop()}
164
283
  </h2>
165
284
  </div>
166
- {dirty && (
167
- <span className="text-xs text-muted-foreground shrink-0">Unsaved</span>
168
- )}
285
+ <div className="flex items-center gap-3 shrink-0">
286
+ {isMarkdown(activePath) && (
287
+ <div
288
+ role="tablist"
289
+ aria-label="View mode"
290
+ className="inline-flex items-center gap-1 rounded-md border bg-muted/40 p-1"
291
+ >
292
+ <button
293
+ role="tab"
294
+ type="button"
295
+ aria-selected={viewMode === "preview"}
296
+ onClick={() => setViewMode("preview")}
297
+ className={`rounded px-3 py-1 text-xs font-medium transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring ${
298
+ viewMode === "preview"
299
+ ? "bg-background text-foreground shadow-xs"
300
+ : "text-muted-foreground hover:text-foreground"
301
+ }`}
302
+ >
303
+ Preview
304
+ </button>
305
+ <button
306
+ role="tab"
307
+ type="button"
308
+ aria-selected={viewMode === "code"}
309
+ onClick={() => setViewMode("code")}
310
+ className={`rounded px-3 py-1 text-xs font-medium transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring ${
311
+ viewMode === "code"
312
+ ? "bg-background text-foreground shadow-xs"
313
+ : "text-muted-foreground hover:text-foreground"
314
+ }`}
315
+ >
316
+ Code
317
+ </button>
318
+ </div>
319
+ )}
320
+ {dirty && (
321
+ <span className="text-xs text-muted-foreground">Unsaved</span>
322
+ )}
323
+ </div>
169
324
  </header>
170
325
 
171
- <Textarea
172
- value={content}
173
- onChange={(e) => setContent(e.target.value)}
174
- className={`flex-1 rounded-none border-0 font-mono text-sm leading-relaxed resize-none focus-visible:ring-0 ${
175
- dirty || status !== "idle" ? "pb-32" : ""
176
- }`}
177
- spellCheck={false}
178
- />
326
+ {fileType === "read-only" ? (
327
+ <div className="flex-1 rounded-none border-0 font-mono text-sm leading-relaxed overflow-auto bg-muted/30 p-6">
328
+ <pre className="whitespace-pre-wrap break-words text-foreground/80">
329
+ {prettyJsonOrRaw(content)}
330
+ </pre>
331
+ </div>
332
+ ) : isMarkdown(activePath) && viewMode === "preview" ? (
333
+ <div className="flex-1 overflow-auto px-6 py-8">
334
+ <MarkdownPreview source={content} />
335
+ </div>
336
+ ) : (
337
+ <Textarea
338
+ value={content}
339
+ onChange={(e) => setContent(e.target.value)}
340
+ className={`flex-1 rounded-none border-0 font-mono text-sm leading-relaxed resize-none focus-visible:ring-0 ${
341
+ dirty || status !== "idle" ? "pb-32" : ""
342
+ }`}
343
+ spellCheck={false}
344
+ />
345
+ )}
179
346
 
180
- {(dirty || status !== "idle") && (
347
+ {fileType === "editable" && (dirty || status !== "idle") && (
181
348
  <div className="fixed bottom-0 left-0 right-0 z-50 border-t bg-card/95 backdrop-blur supports-[backdrop-filter]:bg-card/80 shadow-lg">
182
349
  <div className="max-w-7xl mx-auto px-8 py-8 flex items-center gap-4">
183
350
  <GitCommit className="h-4 w-4 text-muted-foreground shrink-0" />
@@ -12,9 +12,17 @@ const alertVariants = cva(
12
12
  {
13
13
  variants: {
14
14
  variant: {
15
- default: "bg-card text-card-foreground",
15
+ // bg-muted gives default alerts a subtle surface bump so they read as
16
+ // a callout even when nested inside a Card (which is also bg-card).
17
+ // Without this, default alert + card = identical surfaces, no hierarchy.
18
+ default: "border-l-4 border-l-primary bg-primary/5 text-foreground [&>svg]:text-primary dark:bg-primary/10",
19
+ // bg-destructive/10 gives destructive alerts a soft red tint without
20
+ // overwhelming the surface. Composite contrast (destructive on
21
+ // destructive/10 over card) stays above AA 4.5:1 across the default
22
+ // BADS palette; forks with very saturated destructive tokens should
23
+ // re-check with `pnpm wcag:audit` after token edits.
16
24
  destructive:
17
- "bg-card text-destructive *:data-[slot=alert-description]:text-destructive/90 [&>svg]:text-current",
25
+ "border-l-4 border-l-destructive bg-destructive/5 text-destructive *:data-[slot=alert-description]:text-destructive/90 [&>svg]:text-current dark:bg-destructive/10",
18
26
  },
19
27
  },
20
28
  defaultVariants: {
@@ -0,0 +1,124 @@
1
+ "use client"
2
+
3
+ import * as React from "react"
4
+
5
+ import { cn } from "../../lib/utils"
6
+ import {
7
+ Sheet,
8
+ SheetClose,
9
+ SheetContent,
10
+ SheetDescription,
11
+ SheetFooter,
12
+ SheetHeader,
13
+ SheetTitle,
14
+ SheetTrigger,
15
+ } from "./sheet"
16
+
17
+ /**
18
+ * BottomSheet — a bottom-anchored disclosure surface, the dominant
19
+ * secondary-content container in current production apps (Raycast, Linear
20
+ * mobile, Arc). Built on the Radix Dialog–backed Sheet primitive with
21
+ * `side="bottom"`, so it inherits Sheet's focus trap, ESC/overlay dismissal,
22
+ * scroll lock, and AAA-tuned focus ring for free.
23
+ *
24
+ * What this adds over `<SheetContent side="bottom">`:
25
+ * - Rounded top corners + a centered grab-handle affordance (the visual
26
+ * signal users now read as "this panel came from the bottom").
27
+ * - Mobile-first sizing: caps at 85svh and scrolls internally so a tall
28
+ * sheet never pushes its footer off-screen.
29
+ * - A coherent BottomSheet* API surface so callers don't mix Sheet and
30
+ * BottomSheet names.
31
+ *
32
+ * Not draggable. This wrapper is intentionally built on Radix, not vaul, so
33
+ * there are no drag-to-dismiss physics or snap points — dismissal is via the
34
+ * grab handle (decorative), overlay click, ESC, or an explicit close button.
35
+ * If a fork needs true drag/snap behavior, that's a separate vaul-backed
36
+ * primitive and a deliberate dependency decision (see CHANGELOG 2026-05-31).
37
+ */
38
+
39
+ function BottomSheet({ ...props }: React.ComponentProps<typeof Sheet>) {
40
+ return <Sheet data-slot="bottom-sheet" {...props} />
41
+ }
42
+
43
+ function BottomSheetTrigger({
44
+ ...props
45
+ }: React.ComponentProps<typeof SheetTrigger>) {
46
+ return <SheetTrigger data-slot="bottom-sheet-trigger" {...props} />
47
+ }
48
+
49
+ function BottomSheetClose({
50
+ ...props
51
+ }: React.ComponentProps<typeof SheetClose>) {
52
+ return <SheetClose data-slot="bottom-sheet-close" {...props} />
53
+ }
54
+
55
+ function BottomSheetContent({
56
+ className,
57
+ children,
58
+ showHandle = true,
59
+ showCloseButton = true,
60
+ ...props
61
+ }: React.ComponentProps<typeof SheetContent> & {
62
+ /** Show the decorative grab-handle affordance at the top. Default true. */
63
+ showHandle?: boolean
64
+ }) {
65
+ return (
66
+ <SheetContent
67
+ side="bottom"
68
+ showCloseButton={showCloseButton}
69
+ data-slot="bottom-sheet-content"
70
+ className={cn(
71
+ // Rounded top + capped height + internal scroll so a tall sheet keeps
72
+ // its footer reachable. svh tracks the mobile dynamic viewport.
73
+ "max-h-[85svh] gap-0 overflow-y-auto rounded-t-xl pb-[max(1rem,env(safe-area-inset-bottom))]",
74
+ className
75
+ )}
76
+ {...props}
77
+ >
78
+ {showHandle && (
79
+ <div
80
+ aria-hidden="true"
81
+ className="mx-auto mt-3 mb-1 h-1.5 w-12 shrink-0 rounded-full bg-muted-foreground/30"
82
+ />
83
+ )}
84
+ {children}
85
+ </SheetContent>
86
+ )
87
+ }
88
+
89
+ // Header/Footer/Title/Description are 1:1 with Sheet's — re-exported under the
90
+ // BottomSheet name so callers get a single coherent API.
91
+ function BottomSheetHeader({
92
+ ...props
93
+ }: React.ComponentProps<typeof SheetHeader>) {
94
+ return <SheetHeader data-slot="bottom-sheet-header" {...props} />
95
+ }
96
+
97
+ function BottomSheetFooter({
98
+ ...props
99
+ }: React.ComponentProps<typeof SheetFooter>) {
100
+ return <SheetFooter data-slot="bottom-sheet-footer" {...props} />
101
+ }
102
+
103
+ function BottomSheetTitle({
104
+ ...props
105
+ }: React.ComponentProps<typeof SheetTitle>) {
106
+ return <SheetTitle data-slot="bottom-sheet-title" {...props} />
107
+ }
108
+
109
+ function BottomSheetDescription({
110
+ ...props
111
+ }: React.ComponentProps<typeof SheetDescription>) {
112
+ return <SheetDescription data-slot="bottom-sheet-description" {...props} />
113
+ }
114
+
115
+ export {
116
+ BottomSheet,
117
+ BottomSheetTrigger,
118
+ BottomSheetClose,
119
+ BottomSheetContent,
120
+ BottomSheetHeader,
121
+ BottomSheetFooter,
122
+ BottomSheetTitle,
123
+ BottomSheetDescription,
124
+ }
@@ -5,7 +5,7 @@ import { Slot } from "@radix-ui/react-slot"
5
5
  import { cn } from "../../lib/utils"
6
6
 
7
7
  const buttonVariants = cva(
8
- "inline-flex shrink-0 items-center justify-center gap-2 rounded-md text-sm font-medium whitespace-nowrap transition-all outline-none focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/50 disabled:pointer-events-none disabled:opacity-50 aria-invalid:border-destructive aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",
8
+ "inline-flex shrink-0 items-center justify-center gap-2 rounded-full text-sm font-medium whitespace-nowrap transition-all outline-none focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/50 disabled:pointer-events-none disabled:opacity-50 aria-invalid:border-destructive aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",
9
9
  {
10
10
  variants: {
11
11
  variant: {
@@ -18,7 +18,7 @@ const buttonVariants = cva(
18
18
  "bg-secondary text-secondary-foreground hover:bg-secondary/80",
19
19
  ghost:
20
20
  "hover:bg-accent hover:text-accent-foreground dark:hover:bg-accent/50",
21
- link: "text-primary underline-offset-4 hover:underline",
21
+ link: "text-link underline-offset-4 hover:underline",
22
22
  accent: "bg-accent text-accent-foreground shadow-sm hover:bg-accent/80",
23
23
  },
24
24
  size: {
@@ -205,7 +205,7 @@ function CalendarDayButton({
205
205
  data-range-end={modifiers.range_end}
206
206
  data-range-middle={modifiers.range_middle}
207
207
  className={cn(
208
- "flex aspect-square size-auto w-full min-w-(--cell-size) flex-col gap-1 leading-none font-normal group-data-[focused=true]/day:relative group-data-[focused=true]/day:z-10 group-data-[focused=true]/day:border-ring group-data-[focused=true]/day:ring-[3px] group-data-[focused=true]/day:ring-ring/50 data-[range-end=true]:rounded-md data-[range-end=true]:rounded-r-md data-[range-end=true]:bg-primary data-[range-end=true]:text-primary-foreground data-[range-middle=true]:rounded-none data-[range-middle=true]:bg-accent data-[range-middle=true]:text-accent-foreground data-[range-start=true]:rounded-md data-[range-start=true]:rounded-l-md data-[range-start=true]:bg-primary data-[range-start=true]:text-primary-foreground data-[selected-single=true]:bg-primary data-[selected-single=true]:text-primary-foreground dark:hover:text-accent-foreground [&>span]:text-xs [&>span]:opacity-70",
208
+ "flex aspect-square size-auto w-full min-w-(--cell-size) flex-col gap-1 leading-none font-normal group-data-[focused=true]/day:relative group-data-[focused=true]/day:z-10 group-data-[focused=true]/day:border-ring group-data-[focused=true]/day:ring-[3px] group-data-[focused=true]/day:ring-ring/50 data-[range-end=true]:rounded-md data-[range-end=true]:rounded-r-md data-[range-end=true]:bg-primary data-[range-end=true]:text-primary-foreground data-[range-middle=true]:rounded-none data-[range-middle=true]:bg-accent data-[range-middle=true]:text-foreground data-[range-start=true]:rounded-md data-[range-start=true]:rounded-l-md data-[range-start=true]:bg-primary data-[range-start=true]:text-primary-foreground data-[selected-single=true]:bg-primary data-[selected-single=true]:text-primary-foreground dark:hover:text-accent-foreground [&>span]:text-xs [&>span]:opacity-70",
209
209
  defaultClassNames.day,
210
210
  className
211
211
  )}
@@ -34,41 +34,152 @@ function useChart() {
34
34
  return context
35
35
  }
36
36
 
37
+ // Recharts v3 components that ship a stroke-dasharray entrance animation.
38
+ // Animation is ON by default — the ResizeObserver gate below ensures the
39
+ // chart never mounts during SSR or before its container has measurable
40
+ // dimensions, which is what causes the "invisible chart" bug in plain
41
+ // Recharts v3. Pass `animate={false}` on the container if you need to
42
+ // freeze the chart at its final state (e.g. for screenshots or print).
43
+ const ANIMATED_RECHARTS_COMPONENTS = new Set<React.ElementType>([
44
+ RechartsPrimitive.Line,
45
+ RechartsPrimitive.Area,
46
+ RechartsPrimitive.Bar,
47
+ RechartsPrimitive.Pie,
48
+ RechartsPrimitive.Radar,
49
+ RechartsPrimitive.RadialBar,
50
+ RechartsPrimitive.Scatter,
51
+ ])
52
+
53
+ function injectAnimationDefault(
54
+ node: React.ReactNode,
55
+ animate: boolean
56
+ ): React.ReactNode {
57
+ // When animate is true we leave Recharts' defaults alone (entrance
58
+ // animation on). When animate is false we walk the tree and force
59
+ // isAnimationActive={false} on every animated primitive.
60
+ if (animate) return node
61
+ if (Array.isArray(node)) {
62
+ return node.map((child, i) => (
63
+ <React.Fragment key={i}>{injectAnimationDefault(child, animate)}</React.Fragment>
64
+ ))
65
+ }
66
+ if (!React.isValidElement(node)) return node
67
+ const element = node as React.ReactElement<any>
68
+ const props = element.props || {}
69
+ const isAnimated = ANIMATED_RECHARTS_COMPONENTS.has(
70
+ element.type as React.ElementType
71
+ )
72
+ const needsDefault =
73
+ isAnimated && props.isAnimationActive === undefined
74
+ const hasChildren = props.children !== undefined
75
+ if (!needsDefault && !hasChildren) return element
76
+ const nextProps: Record<string, unknown> = {}
77
+ if (needsDefault) nextProps.isAnimationActive = false
78
+ if (hasChildren) {
79
+ nextProps.children = injectAnimationDefault(props.children, animate)
80
+ }
81
+ return React.cloneElement(element, nextProps)
82
+ }
83
+
84
+ function usePrefersReducedMotion() {
85
+ const [reduced, setReduced] = React.useState(false)
86
+ React.useEffect(() => {
87
+ if (typeof window === "undefined" || !window.matchMedia) return
88
+ const mql = window.matchMedia("(prefers-reduced-motion: reduce)")
89
+ setReduced(mql.matches)
90
+ const onChange = (e: MediaQueryListEvent) => setReduced(e.matches)
91
+ mql.addEventListener("change", onChange)
92
+ return () => mql.removeEventListener("change", onChange)
93
+ }, [])
94
+ return reduced
95
+ }
96
+
37
97
  function ChartContainer({
38
98
  id,
39
99
  className,
40
100
  children,
41
101
  config,
42
102
  style,
103
+ animate = true,
43
104
  ...props
44
105
  }: React.ComponentProps<"div"> & {
45
106
  config: ChartConfig
107
+ /**
108
+ * Whether the chart plays Recharts' default entrance animation. On by
109
+ * default — the ResizeObserver gate ensures the chart only mounts once
110
+ * the container is measurable, which prevents the SSR-then-hydrate
111
+ * invisible-chart bug. Pass `animate={false}` to freeze the chart at
112
+ * its final state (e.g. for screenshots, print). Users with
113
+ * `prefers-reduced-motion: reduce` get `animate={false}` automatically
114
+ * regardless of this prop (SC 2.3.3).
115
+ */
116
+ animate?: boolean
46
117
  children: React.ComponentProps<
47
118
  typeof RechartsPrimitive.ResponsiveContainer
48
119
  >["children"]
49
120
  }) {
50
121
  const uniqueId = React.useId()
51
122
  const chartId = `chart-${id || uniqueId.replace(/:/g, "")}`
123
+ const prefersReducedMotion = usePrefersReducedMotion()
124
+ const effectiveAnimate = animate && !prefersReducedMotion
125
+
126
+ // ResponsiveContainer logs "width(-1) and height(-1)" whenever it renders
127
+ // before the wrapping div has a measurable size — SSR, first paint, or
128
+ // any container-query-gated height that hasn't kicked in yet. Gate on a
129
+ // ResizeObserver so the chart only mounts once we've observed non-zero
130
+ // width AND height. The wrapping div still SSRs so layout is reserved.
131
+ const containerRef = React.useRef<HTMLDivElement | null>(null)
132
+ const [hasSize, setHasSize] = React.useState(false)
133
+
134
+ React.useEffect(() => {
135
+ const el = containerRef.current
136
+ if (!el) return
137
+ const observer = new ResizeObserver((entries) => {
138
+ for (const entry of entries) {
139
+ const { width, height } = entry.contentRect
140
+ if (width > 0 && height > 0) {
141
+ setHasSize(true)
142
+ return
143
+ }
144
+ }
145
+ setHasSize(false)
146
+ })
147
+ observer.observe(el)
148
+ return () => observer.disconnect()
149
+ }, [])
150
+
151
+ // Recursively default isAnimationActive={false} on every animated Recharts
152
+ // child. Consumers can override per-element by passing the prop explicitly,
153
+ // or opt the whole tree back in via the `animate` prop on the container.
154
+ const safeChildren = React.useMemo(
155
+ () => injectAnimationDefault(children, effectiveAnimate) as typeof children,
156
+ [children, effectiveAnimate]
157
+ )
52
158
 
53
159
  return (
54
160
  <ChartContext.Provider value={{ config }}>
55
161
  <div
162
+ ref={containerRef}
56
163
  data-slot="chart"
57
164
  data-chart={chartId}
58
165
  className={cn(
166
+ // Default to block. The prior default `display: grid` (a leftover
167
+ // from older shadcn chart code) confused Recharts v3's
168
+ // ResizeObserver and caused it to measure -1x-1 through the
169
+ // implicit auto rows. Consumers pass w-full + an explicit height
170
+ // class; block lets those determine the box.
59
171
  "relative w-full text-xs [&_.recharts-cartesian-axis-tick_text]:fill-muted-foreground [&_.recharts-cartesian-grid_line[stroke='#ccc']]:stroke-border/50 [&_.recharts-curve.recharts-tooltip-cursor]:stroke-border [&_.recharts-dot[stroke='#fff']]:stroke-transparent [&_.recharts-layer]:outline-hidden [&_.recharts-polar-grid_[stroke='#ccc']]:stroke-border [&_.recharts-radial-bar-background-sector]:fill-muted [&_.recharts-rectangle.recharts-tooltip-cursor]:fill-muted [&_.recharts-reference-line_[stroke='#ccc']]:stroke-border [&_.recharts-sector]:outline-hidden [&_.recharts-sector[stroke='#fff']]:stroke-transparent [&_.recharts-surface]:outline-hidden",
60
172
  className
61
173
  )}
62
- style={{
63
- display: "grid",
64
- ...style,
65
- }}
174
+ style={style}
66
175
  {...props}
67
176
  >
68
177
  <ChartStyle id={chartId} config={config} />
69
- <RechartsPrimitive.ResponsiveContainer width="100%" height="100%">
70
- {children}
71
- </RechartsPrimitive.ResponsiveContainer>
178
+ {hasSize ? (
179
+ <RechartsPrimitive.ResponsiveContainer width="100%" height="100%">
180
+ {safeChildren}
181
+ </RechartsPrimitive.ResponsiveContainer>
182
+ ) : null}
72
183
  </div>
73
184
  </ChartContext.Provider>
74
185
  )
@@ -14,14 +14,15 @@ function Checkbox({
14
14
  <CheckboxPrimitive.Root
15
15
  data-slot="checkbox"
16
16
  className={cn(
17
- "peer size-8 shrink-0 rounded-[4px] border-2 border-muted-foreground/60 bg-white shadow-xs transition-shadow outline-none focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/50 disabled:cursor-not-allowed disabled:opacity-50 aria-invalid:border-destructive aria-invalid:ring-destructive/20 data-[state=checked]:border-primary data-[state=checked]:bg-primary data-[state=checked]:text-primary-foreground dark:aria-invalid:ring-destructive/40",
17
+ "peer inline-flex size-8 shrink-0 items-center justify-center rounded-[4px] border-2 border-muted-foreground/60 bg-white leading-none shadow-xs transition-[background-color,border-color,color] duration-[210ms] ease-in-out outline-none focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/50 disabled:cursor-not-allowed disabled:opacity-50 aria-invalid:border-destructive aria-invalid:ring-destructive/20 data-[state=checked]:border-primary data-[state=checked]:bg-primary data-[state=checked]:text-primary-foreground data-[state=indeterminate]:border-primary data-[state=indeterminate]:bg-primary data-[state=indeterminate]:text-primary-foreground dark:aria-invalid:ring-destructive/40",
18
18
  className
19
19
  )}
20
20
  {...props}
21
21
  >
22
22
  <CheckboxPrimitive.Indicator
23
+ forceMount
23
24
  data-slot="checkbox-indicator"
24
- className="grid place-content-center text-current transition-none"
25
+ className="grid place-content-center text-current opacity-0 scale-75 transition-[opacity,transform] duration-[120ms] ease-out data-[state=checked]:opacity-100 data-[state=checked]:scale-100 data-[state=indeterminate]:opacity-100 data-[state=indeterminate]:scale-100"
25
26
  >
26
27
  <CheckIcon className="size-6" strokeWidth={3} />
27
28
  </CheckboxPrimitive.Indicator>
@@ -9,7 +9,7 @@ import { cn } from "../../lib/utils"
9
9
  import { Button } from "./button"
10
10
 
11
11
  const dialogContentVariants = cva(
12
- "fixed left-[50%] top-[50%] z-50 grid w-full translate-x-[-50%] translate-y-[-50%] gap-4 border bg-background p-6 shadow-lg duration-200 outline-none data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 sm:rounded-lg",
12
+ "fixed left-[50%] top-[50%] z-50 grid w-full translate-x-[-50%] translate-y-[-50%] gap-4 border bg-background p-6 shadow-2xl ring-1 ring-white/10 duration-200 outline-none data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 sm:rounded-lg",
13
13
  {
14
14
  variants: {
15
15
  size: {
@@ -59,7 +59,7 @@ function DialogOverlay({
59
59
  <DialogPrimitive.Overlay
60
60
  data-slot="dialog-overlay"
61
61
  className={cn(
62
- "fixed inset-0 z-50 bg-black/50 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:animate-in data-[state=open]:fade-in-0",
62
+ "fixed inset-0 z-50 bg-black/40 backdrop-blur-sm data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:animate-in data-[state=open]:fade-in-0",
63
63
  className
64
64
  )}
65
65
  {...props}
@@ -90,7 +90,7 @@ function DialogContent({
90
90
  {showCloseButton && (
91
91
  <DialogPrimitive.Close
92
92
  data-slot="dialog-close"
93
- className="absolute top-4 right-4 rounded-xs opacity-70 ring-offset-background transition-opacity hover:opacity-100 focus:ring-2 focus:ring-ring focus:ring-offset-2 focus:outline-hidden disabled:pointer-events-none data-[state=open]:bg-accent data-[state=open]:text-muted-foreground [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4"
93
+ className="absolute top-4 right-4 rounded-xs opacity-70 ring-offset-background transition-opacity hover:opacity-100 focus:ring-2 focus:ring-ring focus:ring-offset-2 focus:outline-hidden disabled:pointer-events-none data-[state=open]:bg-accent data-[state=open]:text-muted-foreground [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-8"
94
94
  >
95
95
  <XIcon />
96
96
  <span className="sr-only">Close</span>
@@ -24,6 +24,7 @@ export * from "./scroll-area";
24
24
  export * from "./select";
25
25
  export * from "./separator";
26
26
  export * from "./sheet";
27
+ export * from "./bottom-sheet";
27
28
  export * from "./sidebar";
28
29
  export * from "./skeleton";
29
30
  export * from "./slider";
@@ -27,16 +27,17 @@ function RadioGroupItem({
27
27
  <RadioGroupPrimitive.Item
28
28
  data-slot="radio-group-item"
29
29
  className={cn(
30
- "aspect-square size-9 shrink-0 rounded-full border-2 border-muted-foreground/60 bg-white text-primary shadow-xs transition-[color,box-shadow] outline-none focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/50 disabled:cursor-not-allowed disabled:opacity-50 aria-invalid:border-destructive aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 data-[state=checked]:bg-primary data-[state=checked]:border-primary",
30
+ "aspect-square size-9 shrink-0 rounded-full border-2 border-muted-foreground/60 bg-white text-primary shadow-xs transition-[background-color,border-color,color] duration-[210ms] ease-in-out outline-none focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/50 disabled:cursor-not-allowed disabled:opacity-50 aria-invalid:border-destructive aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 data-[state=checked]:bg-primary data-[state=checked]:border-primary",
31
31
  className
32
32
  )}
33
33
  {...props}
34
34
  >
35
35
  <RadioGroupPrimitive.Indicator
36
+ forceMount
36
37
  data-slot="radio-group-indicator"
37
- className="relative flex items-center justify-center"
38
+ className="flex h-full w-full items-center justify-center opacity-0 scale-75 transition-[opacity,transform] duration-[120ms] ease-out data-[state=checked]:opacity-100 data-[state=checked]:scale-100"
38
39
  >
39
- <CircleIcon className="absolute top-1/2 left-1/2 size-3 -translate-x-1/2 -translate-y-1/2 fill-primary-foreground" />
40
+ <CircleIcon className="size-4 fill-primary-foreground stroke-primary-foreground" />
40
41
  </RadioGroupPrimitive.Indicator>
41
42
  </RadioGroupPrimitive.Item>
42
43
  )
@@ -36,7 +36,7 @@ function SheetOverlay({
36
36
  <SheetPrimitive.Overlay
37
37
  data-slot="sheet-overlay"
38
38
  className={cn(
39
- "fixed inset-0 z-50 bg-black/50 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:animate-in data-[state=open]:fade-in-0",
39
+ "fixed inset-0 z-50 bg-black/40 backdrop-blur-sm data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:animate-in data-[state=open]:fade-in-0",
40
40
  className
41
41
  )}
42
42
  {...props}