@behavioral-agentic-design-system/core 0.24.0 → 0.26.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +5 -2
- package/scripts/build-tokens.cjs +79 -5
- package/src/app/preview/components/page.tsx +4474 -208
- package/src/app/shell.tsx +18 -6
- package/src/components/customize/brand-mark-section.tsx +1 -1
- package/src/components/customize-tab.tsx +2 -2
- package/src/components/home-tab.tsx +2 -2
- package/src/components/ui/action-bar.tsx +142 -0
- package/src/components/ui/affix.tsx +109 -0
- package/src/components/ui/alert.tsx +37 -3
- package/src/components/ui/anchor.tsx +136 -0
- package/src/components/ui/angle-slider.tsx +265 -0
- package/src/components/ui/autocomplete.tsx +223 -0
- package/src/components/ui/avatar.tsx +8 -2
- package/src/components/ui/blockquote.tsx +112 -0
- package/src/components/ui/bottom-navigation.tsx +144 -0
- package/src/components/ui/burger.tsx +117 -0
- package/src/components/ui/button.tsx +101 -3
- package/src/components/ui/calendar.tsx +1 -1
- package/src/components/ui/card.tsx +43 -5
- package/src/components/ui/carousel.tsx +10 -5
- package/src/components/ui/cascader.tsx +253 -0
- package/src/components/ui/checkbox-card.tsx +176 -0
- package/src/components/ui/checkbox-group.tsx +231 -0
- package/src/components/ui/checkbox.tsx +14 -3
- package/src/components/ui/chip.tsx +143 -0
- package/src/components/ui/circular-progress.tsx +2 -2
- package/src/components/ui/color-swatch.tsx +73 -0
- package/src/components/ui/copy-button.tsx +21 -4
- package/src/components/ui/date-picker.tsx +6 -3
- package/src/components/ui/date-range-picker.tsx +6 -3
- package/src/components/ui/float-label.tsx +114 -0
- package/src/components/ui/floating-panel.tsx +129 -0
- package/src/components/ui/format-number.tsx +122 -0
- package/src/components/ui/highlight.tsx +85 -0
- package/src/components/ui/image.tsx +195 -0
- package/src/components/ui/index.ts +50 -0
- package/src/components/ui/indicator.tsx +2 -2
- package/src/components/ui/input.tsx +48 -4
- package/src/components/ui/kbd.tsx +1 -1
- package/src/components/ui/link.tsx +158 -0
- package/src/components/ui/listbox.tsx +426 -0
- package/src/components/ui/loading-overlay.tsx +80 -0
- package/src/components/ui/marquee.tsx +193 -0
- package/src/components/ui/masonry.tsx +164 -0
- package/src/components/ui/meter.tsx +186 -0
- package/src/components/ui/motion-toggle.tsx +170 -0
- package/src/components/ui/notification.tsx +175 -0
- package/src/components/ui/overlay.tsx +63 -0
- package/src/components/ui/progress.tsx +95 -4
- package/src/components/ui/rating-group.tsx +1 -0
- package/src/components/ui/separator.tsx +57 -1
- package/src/components/ui/sidebar.tsx +1 -1
- package/src/components/ui/signature-pad.tsx +381 -0
- package/src/components/ui/skeleton.tsx +59 -2
- package/src/components/ui/skip-link.tsx +117 -0
- package/src/components/ui/slider.tsx +86 -1
- package/src/components/ui/spoiler.tsx +131 -0
- package/src/components/ui/tabs.tsx +1 -1
- package/src/components/ui/text.tsx +135 -0
- package/src/components/ui/textarea.tsx +66 -2
- package/src/components/ui/timeline.tsx +71 -14
- package/src/components/ui/timer.tsx +183 -0
- package/src/components/ui/tour.tsx +332 -0
- package/src/components/ui/transfer-list.tsx +308 -0
- package/src/components/ui/visually-hidden.tsx +42 -0
- package/src/components/ui/watermark.tsx +0 -0
- package/src/data/docs-index.ts +9 -2
- package/src/stories/ActionBar.stories.tsx +201 -0
- package/src/stories/Affix.stories.tsx +165 -0
- package/src/stories/Alert.stories.tsx +58 -0
- package/src/stories/Anchor.stories.tsx +236 -0
- package/src/stories/AngleSlider.stories.tsx +128 -0
- package/src/stories/Autocomplete.stories.tsx +216 -0
- package/src/stories/Avatar.stories.tsx +73 -1
- package/src/stories/Blockquote.stories.tsx +148 -0
- package/src/stories/BottomNavigation.stories.tsx +195 -0
- package/src/stories/Burger.stories.tsx +79 -0
- package/src/stories/Button.stories.tsx +103 -2
- package/src/stories/Calendar.stories.tsx +4 -0
- package/src/stories/Card.stories.tsx +30 -0
- package/src/stories/Carousel.stories.tsx +2 -1
- package/src/stories/Cascader.stories.tsx +285 -0
- package/src/stories/Checkbox.stories.tsx +13 -0
- package/src/stories/CheckboxCard.stories.tsx +210 -0
- package/src/stories/CheckboxGroup.stories.tsx +186 -0
- package/src/stories/Chip.stories.tsx +173 -0
- package/src/stories/CircularProgress.stories.tsx +3 -0
- package/src/stories/ColorSwatch.stories.tsx +81 -0
- package/src/stories/CopyButton.stories.tsx +3 -3
- package/src/stories/DatePicker.stories.tsx +3 -0
- package/src/stories/DateRangePicker.stories.tsx +3 -0
- package/src/stories/Editable.stories.tsx +14 -0
- package/src/stories/FloatLabel.stories.tsx +148 -0
- package/src/stories/FloatingPanel.stories.tsx +176 -0
- package/src/stories/FormatNumber.stories.tsx +308 -0
- package/src/stories/Highlight.stories.tsx +140 -0
- package/src/stories/Image.stories.tsx +141 -0
- package/src/stories/Indicator.stories.tsx +3 -0
- package/src/stories/Input.stories.tsx +33 -0
- package/src/stories/Kbd.stories.tsx +3 -0
- package/src/stories/Link.stories.tsx +198 -0
- package/src/stories/Listbox.stories.tsx +240 -0
- package/src/stories/LoadingOverlay.stories.tsx +148 -0
- package/src/stories/Marquee.stories.tsx +170 -0
- package/src/stories/Masonry.stories.tsx +227 -0
- package/src/stories/Meter.stories.tsx +143 -0
- package/src/stories/MotionToggle.stories.tsx +85 -0
- package/src/stories/Notification.stories.tsx +264 -0
- package/src/stories/Overlay.stories.tsx +169 -0
- package/src/stories/PasswordInput.stories.tsx +4 -0
- package/src/stories/Progress.stories.tsx +70 -27
- package/src/stories/RatingGroup.stories.tsx +5 -0
- package/src/stories/Separator.stories.tsx +41 -5
- package/src/stories/Sidebar.stories.tsx +2 -1
- package/src/stories/SignaturePad.stories.tsx +112 -0
- package/src/stories/Skeleton.stories.tsx +23 -4
- package/src/stories/SkipLink.stories.tsx +137 -0
- package/src/stories/Slider.stories.tsx +28 -0
- package/src/stories/Spoiler.stories.tsx +122 -0
- package/src/stories/Tabs.stories.tsx +2 -1
- package/src/stories/Text.stories.tsx +191 -0
- package/src/stories/Textarea.stories.tsx +58 -6
- package/src/stories/Timeline.stories.tsx +82 -0
- package/src/stories/Timer.stories.tsx +160 -0
- package/src/stories/Tour.stories.tsx +191 -0
- package/src/stories/TransferList.stories.tsx +169 -0
- package/src/stories/VisuallyHidden.stories.tsx +105 -0
- package/src/stories/Watermark.stories.tsx +212 -0
- package/src/styles.css +80 -6
- package/src/tokens.json +2 -2
package/src/app/shell.tsx
CHANGED
|
@@ -411,7 +411,19 @@ export function Shell({ tabs, defaultTab }: ShellProps) {
|
|
|
411
411
|
|
|
412
412
|
return (
|
|
413
413
|
<ShellNavContext.Provider value={navValue}>
|
|
414
|
-
|
|
414
|
+
{/* h-dvh (dynamic viewport height), NOT min-h-screen (100vh): the shell is a
|
|
415
|
+
fixed app frame whose tabs scroll internally (native tabs own an
|
|
416
|
+
overflow-y-auto container; iframe tabs scroll their own document). With
|
|
417
|
+
min-h-screen the layout is sized to the *large* (address-bar-hidden)
|
|
418
|
+
viewport, so on mobile the <body> overflows by ~one address-bar height.
|
|
419
|
+
The first touch scrolls THAT (collapsing the address bar), then the body
|
|
420
|
+
hits its limit and iOS doesn't hand the gesture to the inner scroller —
|
|
421
|
+
"scrolls for a second, then freezes." h-dvh tracks the *visible* height,
|
|
422
|
+
so the body never overflows and every gesture goes straight to the inner
|
|
423
|
+
scroll container. overflow-hidden guarantees the body itself never
|
|
424
|
+
scrolls. Do NOT move this to globals.css — the iframe'd /preview/* routes
|
|
425
|
+
share this layout and must keep their own document scroll. */}
|
|
426
|
+
<div className="h-dvh overflow-hidden bg-background flex flex-col">
|
|
415
427
|
{/* Skip-to-content: visually hidden until focused so keyboard users can
|
|
416
428
|
bypass the header and tab strip and jump straight to the panel area. */}
|
|
417
429
|
<a
|
|
@@ -467,7 +479,7 @@ export function Shell({ tabs, defaultTab }: ShellProps) {
|
|
|
467
479
|
title={`Open ${link.label}`}
|
|
468
480
|
>
|
|
469
481
|
<a href={link.href} target="_blank" rel="noreferrer" aria-label={`Open ${link.label} in a new tab`}>
|
|
470
|
-
<ExternalLink className="h-4 w-4
|
|
482
|
+
<ExternalLink className="h-4 w-4" strokeWidth={1.5} />
|
|
471
483
|
<span className="text-xs font-medium hidden sm:inline">{link.label}</span>
|
|
472
484
|
</a>
|
|
473
485
|
</Button>
|
|
@@ -481,7 +493,7 @@ export function Shell({ tabs, defaultTab }: ShellProps) {
|
|
|
481
493
|
title="Open Storybook"
|
|
482
494
|
>
|
|
483
495
|
<a href={storybookUrl} target="_blank" rel="noreferrer" aria-label="Open Storybook in a new tab">
|
|
484
|
-
<BookOpen className="h-4 w-4
|
|
496
|
+
<BookOpen className="h-4 w-4" strokeWidth={1.5} />
|
|
485
497
|
<span className="text-xs font-medium hidden sm:inline">Storybook</span>
|
|
486
498
|
</a>
|
|
487
499
|
</Button>
|
|
@@ -495,7 +507,7 @@ export function Shell({ tabs, defaultTab }: ShellProps) {
|
|
|
495
507
|
title={`Open ${brand.repo.replace(/^https?:\/\//, "")} on GitHub`}
|
|
496
508
|
>
|
|
497
509
|
<a href={brand.repo} target="_blank" rel="noreferrer" aria-label="Open GitHub repo in a new tab">
|
|
498
|
-
<GithubMark className="h-4 w-4
|
|
510
|
+
<GithubMark className="h-4 w-4" />
|
|
499
511
|
<span className="text-xs font-medium hidden sm:inline">GitHub</span>
|
|
500
512
|
</a>
|
|
501
513
|
</Button>
|
|
@@ -508,9 +520,9 @@ export function Shell({ tabs, defaultTab }: ShellProps) {
|
|
|
508
520
|
aria-label={dark ? "Switch to light mode" : "Switch to dark mode"}
|
|
509
521
|
>
|
|
510
522
|
{dark ? (
|
|
511
|
-
<Sun className="h-4 w-4
|
|
523
|
+
<Sun className="h-4 w-4" />
|
|
512
524
|
) : (
|
|
513
|
-
<Moon className="h-4 w-4
|
|
525
|
+
<Moon className="h-4 w-4" />
|
|
514
526
|
)}
|
|
515
527
|
</Button>
|
|
516
528
|
</div>
|
|
@@ -241,7 +241,7 @@ function PreviewTile({ mode, svg }: { mode: "light" | "dark"; svg: string | null
|
|
|
241
241
|
{/* 96px size — login/branded surfaces */}
|
|
242
242
|
<Mark size={96} svg={svg} mode={mode} />
|
|
243
243
|
</div>
|
|
244
|
-
<span className="text-xs
|
|
244
|
+
<span className="text-xs opacity-60">{isLight ? "Light" : "Dark"}</span>
|
|
245
245
|
</div>
|
|
246
246
|
);
|
|
247
247
|
}
|
|
@@ -151,9 +151,9 @@ function ColorSwatch({
|
|
|
151
151
|
<button
|
|
152
152
|
type="button"
|
|
153
153
|
onClick={handleReset}
|
|
154
|
-
className="inline-flex items-center gap-1 text-
|
|
154
|
+
className="inline-flex items-center gap-1 text-sm text-muted-foreground hover:text-foreground transition-colors"
|
|
155
155
|
>
|
|
156
|
-
<RotateCcw className="h-
|
|
156
|
+
<RotateCcw className="h-4 w-4" strokeWidth={1.5} />
|
|
157
157
|
Reset
|
|
158
158
|
</button>
|
|
159
159
|
)}
|
|
@@ -32,7 +32,7 @@ import { Separator } from "@behavioral-agentic-design-system/core/components/ui/
|
|
|
32
32
|
import { BadsUpdateBanner } from "@behavioral-agentic-design-system/core/components/bads-update-banner";
|
|
33
33
|
import registry from "@/layer-5-component-registry/component-registry.json";
|
|
34
34
|
import tokens from "@/packages/core/src/tokens.json";
|
|
35
|
-
import { DOCS_INDEX, DOCS_TOTAL } from "@behavioral-agentic-design-system/core/data/docs-index";
|
|
35
|
+
import { AUTOMATION_COUNT, DOCS_INDEX, DOCS_TOTAL } from "@behavioral-agentic-design-system/core/data/docs-index";
|
|
36
36
|
|
|
37
37
|
type HomeTabProps = {
|
|
38
38
|
onBrowseDocs?: () => void;
|
|
@@ -322,7 +322,7 @@ export function HomeTab({ onBrowseDocs, onBrowseComponents }: HomeTabProps) {
|
|
|
322
322
|
<MetricPill label="Layers" value={LAYER_COUNT} />
|
|
323
323
|
<MetricPill label="Components" value={componentCount} />
|
|
324
324
|
<MetricPill label="Tokens" value={primitiveTokenCount + semanticTokenCount} />
|
|
325
|
-
<MetricPill label="
|
|
325
|
+
<MetricPill label="Automations" value={AUTOMATION_COUNT} />
|
|
326
326
|
</div>
|
|
327
327
|
</section>
|
|
328
328
|
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
"use client"
|
|
2
|
+
|
|
3
|
+
import * as React from "react"
|
|
4
|
+
import { XIcon } from "lucide-react"
|
|
5
|
+
|
|
6
|
+
import { cn } from "../../lib/utils"
|
|
7
|
+
|
|
8
|
+
// ─── ActionBar ───────────────────────────────────────────────────────────────
|
|
9
|
+
// Floating bulk-selection toolbar. Fixed near the bottom of the viewport,
|
|
10
|
+
// centered horizontally; appears when selectedCount > 0 and dismisses (but
|
|
11
|
+
// stays in the DOM, inert) when selection is cleared, so the exit transition
|
|
12
|
+
// can play and the count live-region survives across renders.
|
|
13
|
+
|
|
14
|
+
interface ActionBarProps extends React.ComponentProps<"div"> {
|
|
15
|
+
selectedCount: number
|
|
16
|
+
onClearSelection?: () => void
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
const ActionBar = React.forwardRef<HTMLDivElement, ActionBarProps>(
|
|
20
|
+
(
|
|
21
|
+
{
|
|
22
|
+
selectedCount,
|
|
23
|
+
onClearSelection,
|
|
24
|
+
children,
|
|
25
|
+
className,
|
|
26
|
+
onKeyDown,
|
|
27
|
+
...props
|
|
28
|
+
},
|
|
29
|
+
ref
|
|
30
|
+
) => {
|
|
31
|
+
const rootRef = React.useRef<HTMLDivElement>(null)
|
|
32
|
+
React.useImperativeHandle(ref, () => rootRef.current as HTMLDivElement)
|
|
33
|
+
|
|
34
|
+
const open = selectedCount > 0
|
|
35
|
+
|
|
36
|
+
function handleKeyDown(e: React.KeyboardEvent<HTMLDivElement>) {
|
|
37
|
+
const container = rootRef.current
|
|
38
|
+
if (container) {
|
|
39
|
+
const items = Array.from(
|
|
40
|
+
container.querySelectorAll<HTMLElement>("button")
|
|
41
|
+
).filter((el) => !el.hasAttribute("disabled"))
|
|
42
|
+
|
|
43
|
+
const idx = items.indexOf(document.activeElement as HTMLElement)
|
|
44
|
+
if (idx !== -1) {
|
|
45
|
+
let target: HTMLElement | undefined
|
|
46
|
+
if (e.key === "ArrowLeft") {
|
|
47
|
+
target = items[(idx - 1 + items.length) % items.length]
|
|
48
|
+
} else if (e.key === "ArrowRight") {
|
|
49
|
+
target = items[(idx + 1) % items.length]
|
|
50
|
+
} else if (e.key === "Home") {
|
|
51
|
+
target = items[0]
|
|
52
|
+
} else if (e.key === "End") {
|
|
53
|
+
target = items[items.length - 1]
|
|
54
|
+
}
|
|
55
|
+
if (target) {
|
|
56
|
+
e.preventDefault()
|
|
57
|
+
target.focus()
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
onKeyDown?.(e)
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
return (
|
|
65
|
+
<div
|
|
66
|
+
ref={rootRef}
|
|
67
|
+
data-slot="action-bar"
|
|
68
|
+
data-state={open ? "open" : "closed"}
|
|
69
|
+
role="toolbar"
|
|
70
|
+
aria-label="Bulk actions"
|
|
71
|
+
aria-orientation="horizontal"
|
|
72
|
+
aria-hidden={open ? undefined : true}
|
|
73
|
+
inert={open ? undefined : true}
|
|
74
|
+
onKeyDown={handleKeyDown}
|
|
75
|
+
className={cn(
|
|
76
|
+
"pointer-events-none fixed inset-x-0 bottom-6 z-50 flex justify-center px-4",
|
|
77
|
+
className
|
|
78
|
+
)}
|
|
79
|
+
{...props}
|
|
80
|
+
>
|
|
81
|
+
<div
|
|
82
|
+
data-slot="action-bar-panel"
|
|
83
|
+
className={cn(
|
|
84
|
+
"flex items-center gap-1 rounded-lg border bg-popover p-1.5 text-popover-foreground shadow-lg",
|
|
85
|
+
"transition-[opacity,transform]",
|
|
86
|
+
open
|
|
87
|
+
? "pointer-events-auto translate-y-0 opacity-100"
|
|
88
|
+
: "pointer-events-none translate-y-2 opacity-0"
|
|
89
|
+
)}
|
|
90
|
+
style={{
|
|
91
|
+
transitionDuration: "var(--duration-base)",
|
|
92
|
+
transitionTimingFunction: "var(--ease-out)",
|
|
93
|
+
}}
|
|
94
|
+
>
|
|
95
|
+
<span
|
|
96
|
+
data-slot="action-bar-count"
|
|
97
|
+
aria-live="polite"
|
|
98
|
+
aria-atomic="true"
|
|
99
|
+
className="inline-flex min-h-11 items-center whitespace-nowrap px-3 text-sm font-medium tabular-nums"
|
|
100
|
+
>
|
|
101
|
+
{selectedCount} selected
|
|
102
|
+
</span>
|
|
103
|
+
{onClearSelection ? (
|
|
104
|
+
<button
|
|
105
|
+
type="button"
|
|
106
|
+
data-slot="action-bar-clear"
|
|
107
|
+
aria-label="Clear selection"
|
|
108
|
+
onClick={onClearSelection}
|
|
109
|
+
className={cn(
|
|
110
|
+
"inline-flex min-h-11 min-w-11 shrink-0 items-center justify-center rounded-md text-muted-foreground",
|
|
111
|
+
"hover:bg-accent hover:text-accent-foreground",
|
|
112
|
+
"focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-1",
|
|
113
|
+
"transition-colors"
|
|
114
|
+
)}
|
|
115
|
+
style={{
|
|
116
|
+
transitionDuration: "var(--duration-fast)",
|
|
117
|
+
transitionTimingFunction: "var(--ease-out)",
|
|
118
|
+
}}
|
|
119
|
+
>
|
|
120
|
+
<XIcon strokeWidth={1.5} className="size-4" aria-hidden="true" />
|
|
121
|
+
</button>
|
|
122
|
+
) : null}
|
|
123
|
+
<div
|
|
124
|
+
role="separator"
|
|
125
|
+
aria-orientation="vertical"
|
|
126
|
+
className="mx-1 h-6 w-px shrink-0 bg-border"
|
|
127
|
+
/>
|
|
128
|
+
<div
|
|
129
|
+
data-slot="action-bar-actions"
|
|
130
|
+
className="flex items-center gap-1"
|
|
131
|
+
>
|
|
132
|
+
{children}
|
|
133
|
+
</div>
|
|
134
|
+
</div>
|
|
135
|
+
</div>
|
|
136
|
+
)
|
|
137
|
+
}
|
|
138
|
+
)
|
|
139
|
+
ActionBar.displayName = "ActionBar"
|
|
140
|
+
|
|
141
|
+
export { ActionBar }
|
|
142
|
+
export type { ActionBarProps }
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
"use client"
|
|
2
|
+
|
|
3
|
+
import * as React from "react"
|
|
4
|
+
import { createPortal } from "react-dom"
|
|
5
|
+
|
|
6
|
+
import { cn } from "../../lib/utils"
|
|
7
|
+
import { usePortalThemeClass } from "../../hooks/use-portal-theme-class"
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Affix — pins arbitrary content to a fixed viewport position (the
|
|
11
|
+
* Mantine/Ant Design Affix shape). The canonical uses are a scroll-to-top
|
|
12
|
+
* button or a chat-open FAB that stays anchored to a viewport corner
|
|
13
|
+
* regardless of scroll position.
|
|
14
|
+
*
|
|
15
|
+
* By default the content renders through a `document.body` portal
|
|
16
|
+
* (`withinPortal`), so no ancestor `overflow: hidden` / `transform` /
|
|
17
|
+
* `filter` can clip it or hijack its containing block. Because the portal
|
|
18
|
+
* escapes any theme class a consumer applies to a page wrapper, the content
|
|
19
|
+
* merges `usePortalThemeClass()` — mount `<PortalThemeProvider>` near the
|
|
20
|
+
* app root and theme-scoped CSS variables reach the pinned content too.
|
|
21
|
+
*
|
|
22
|
+
* With `withinPortal={false}` the fixed element renders in place. Note the
|
|
23
|
+
* CSS trap that makes this mode useful for demos and dangerous in apps: any
|
|
24
|
+
* transformed/filtered ancestor becomes the containing block for
|
|
25
|
+
* `position: fixed`, so the content pins to that ancestor instead of the
|
|
26
|
+
* viewport. The showcase and stories exploit this deliberately with a
|
|
27
|
+
* `transform: translateZ(0)` frame; real apps should keep the portal.
|
|
28
|
+
*
|
|
29
|
+
* Accessibility: the wrapper is purely presentational — no role, no
|
|
30
|
+
* landmark, never a focus target itself. The accessible name, target size
|
|
31
|
+
* (44×44 floor), and interactive states all belong to the children (use the
|
|
32
|
+
* BADS Button `icon-xl` size for FABs). Zero-motion exception (documented,
|
|
33
|
+
* not omitted): the wrapper has no interactive states of its own — it is
|
|
34
|
+
* always visible and never focusable — so the system-wide microanimation
|
|
35
|
+
* rule applies to its children, not to it.
|
|
36
|
+
*
|
|
37
|
+
* SSR: in portal mode the component renders `null` on the server and mounts
|
|
38
|
+
* client-side (a fixed FAB is not meaningful pre-hydration content).
|
|
39
|
+
* Inline mode renders identically server- and client-side.
|
|
40
|
+
*/
|
|
41
|
+
|
|
42
|
+
export interface AffixPosition {
|
|
43
|
+
top?: number | string
|
|
44
|
+
right?: number | string
|
|
45
|
+
bottom?: number | string
|
|
46
|
+
left?: number | string
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export interface AffixProps extends React.ComponentProps<"div"> {
|
|
50
|
+
/**
|
|
51
|
+
* Viewport offsets. Numbers become px; strings pass through (so consumers
|
|
52
|
+
* can use `"var(--spacing-4)"`, `rem`, or `env(safe-area-inset-bottom)`).
|
|
53
|
+
* Default `{ bottom: 20, right: 20 }` — the Mantine convention.
|
|
54
|
+
*/
|
|
55
|
+
position?: AffixPosition
|
|
56
|
+
/** Stacking order for the fixed element. Default 50 (BADS overlay tier). */
|
|
57
|
+
zIndex?: number
|
|
58
|
+
/**
|
|
59
|
+
* Render through a `document.body` portal (default true). Set false to
|
|
60
|
+
* render in place — see the containing-block trap in the component doc.
|
|
61
|
+
*/
|
|
62
|
+
withinPortal?: boolean
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
function toCssLength(value: number | string | undefined): string | undefined {
|
|
66
|
+
if (value === undefined) return undefined
|
|
67
|
+
return typeof value === "number" ? `${value}px` : value
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
function Affix({
|
|
71
|
+
position = { bottom: 20, right: 20 },
|
|
72
|
+
zIndex = 50,
|
|
73
|
+
withinPortal = true,
|
|
74
|
+
className,
|
|
75
|
+
style,
|
|
76
|
+
children,
|
|
77
|
+
...props
|
|
78
|
+
}: AffixProps) {
|
|
79
|
+
const portalThemeClass = usePortalThemeClass()
|
|
80
|
+
const [mounted, setMounted] = React.useState(false)
|
|
81
|
+
|
|
82
|
+
React.useEffect(() => {
|
|
83
|
+
setMounted(true)
|
|
84
|
+
}, [])
|
|
85
|
+
|
|
86
|
+
const node = (
|
|
87
|
+
<div
|
|
88
|
+
data-slot="affix"
|
|
89
|
+
className={cn("fixed", withinPortal ? portalThemeClass : null, className)}
|
|
90
|
+
style={{
|
|
91
|
+
top: toCssLength(position.top),
|
|
92
|
+
right: toCssLength(position.right),
|
|
93
|
+
bottom: toCssLength(position.bottom),
|
|
94
|
+
left: toCssLength(position.left),
|
|
95
|
+
zIndex,
|
|
96
|
+
...style,
|
|
97
|
+
}}
|
|
98
|
+
{...props}
|
|
99
|
+
>
|
|
100
|
+
{children}
|
|
101
|
+
</div>
|
|
102
|
+
)
|
|
103
|
+
|
|
104
|
+
if (!withinPortal) return node
|
|
105
|
+
if (!mounted) return null
|
|
106
|
+
return createPortal(node, document.body)
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
export { Affix }
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import * as React from "react"
|
|
2
|
+
import { X } from "lucide-react"
|
|
2
3
|
import { cva, type VariantProps } from "class-variance-authority"
|
|
3
4
|
|
|
4
5
|
import { cn } from "../../lib/utils"
|
|
@@ -46,15 +47,48 @@ const alertVariants = cva(
|
|
|
46
47
|
function Alert({
|
|
47
48
|
className,
|
|
48
49
|
variant,
|
|
50
|
+
onDismiss,
|
|
51
|
+
action,
|
|
52
|
+
children,
|
|
49
53
|
...props
|
|
50
|
-
}: React.ComponentProps<"div"> &
|
|
54
|
+
}: React.ComponentProps<"div"> &
|
|
55
|
+
VariantProps<typeof alertVariants> & {
|
|
56
|
+
/** Called when the dismiss button is clicked. Renders an × button at top-right. */
|
|
57
|
+
onDismiss?: () => void
|
|
58
|
+
/** Action row rendered below AlertDescription (e.g. a Button or Link). */
|
|
59
|
+
action?: React.ReactNode
|
|
60
|
+
}) {
|
|
51
61
|
return (
|
|
52
62
|
<div
|
|
53
63
|
data-slot="alert"
|
|
54
64
|
role="alert"
|
|
55
|
-
className={cn(alertVariants({ variant }), className)}
|
|
65
|
+
className={cn(alertVariants({ variant }), onDismiss && "pr-10", className)}
|
|
56
66
|
{...props}
|
|
57
|
-
|
|
67
|
+
>
|
|
68
|
+
{children}
|
|
69
|
+
{action && (
|
|
70
|
+
<div
|
|
71
|
+
data-slot="alert-action"
|
|
72
|
+
className="col-start-2 flex flex-wrap gap-2 pt-2"
|
|
73
|
+
>
|
|
74
|
+
{action}
|
|
75
|
+
</div>
|
|
76
|
+
)}
|
|
77
|
+
{onDismiss && (
|
|
78
|
+
<button
|
|
79
|
+
type="button"
|
|
80
|
+
onClick={onDismiss}
|
|
81
|
+
aria-label="Dismiss"
|
|
82
|
+
className="absolute right-3 top-3 rounded-sm p-0.5 opacity-60 transition-opacity hover:opacity-100 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-1"
|
|
83
|
+
style={{
|
|
84
|
+
transitionDuration: "var(--duration-fast)",
|
|
85
|
+
transitionTimingFunction: "var(--ease-out)",
|
|
86
|
+
}}
|
|
87
|
+
>
|
|
88
|
+
<X className="size-4" strokeWidth={1.5} aria-hidden />
|
|
89
|
+
</button>
|
|
90
|
+
)}
|
|
91
|
+
</div>
|
|
58
92
|
)
|
|
59
93
|
}
|
|
60
94
|
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
"use client"
|
|
2
|
+
|
|
3
|
+
import * as React from "react"
|
|
4
|
+
|
|
5
|
+
import { cn } from "../../lib/utils"
|
|
6
|
+
|
|
7
|
+
interface AnchorItem {
|
|
8
|
+
/** Target element's ID (without #). Must resolve to a real element on the page. */
|
|
9
|
+
id: string
|
|
10
|
+
/** Display text for the link. */
|
|
11
|
+
label: string
|
|
12
|
+
/** Nesting depth: 0 = top, 1 = sub, 2 = sub-sub. Default 0. */
|
|
13
|
+
depth?: number
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
interface AnchorProps extends React.ComponentProps<"nav"> {
|
|
17
|
+
items: AnchorItem[]
|
|
18
|
+
/** aria-label for the nav. Default "On this page" */
|
|
19
|
+
label?: string
|
|
20
|
+
/** Offset in px from the top of the viewport for IntersectionObserver rootMargin. Default 0. */
|
|
21
|
+
offset?: number
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
// Each depth level adds pl-3 of indentation. Clamped at depth 2.
|
|
25
|
+
const DEPTH_PADDING = ["pl-3", "pl-6", "pl-9"] as const
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Scroll-linked in-page navigation (scroll-spy). Renders a vertical list of
|
|
29
|
+
* anchor links and highlights the one whose target section is currently
|
|
30
|
+
* visible in the viewport, via IntersectionObserver.
|
|
31
|
+
*
|
|
32
|
+
* Distinct from NavigationMenu (multi-page) and Breadcrumb (path hierarchy).
|
|
33
|
+
* Cross-system references: Mantine TableOfContents, Ant Design Anchor.
|
|
34
|
+
*/
|
|
35
|
+
function Anchor({
|
|
36
|
+
items,
|
|
37
|
+
label = "On this page",
|
|
38
|
+
offset = 0,
|
|
39
|
+
className,
|
|
40
|
+
...props
|
|
41
|
+
}: AnchorProps) {
|
|
42
|
+
const [activeId, setActiveId] = React.useState<string | null>(null)
|
|
43
|
+
|
|
44
|
+
// Key the effect off the id list (not array identity) so consumers can
|
|
45
|
+
// inline `items` without tearing the observer down on every render.
|
|
46
|
+
const idKey = items.map((item) => item.id).join("\n")
|
|
47
|
+
|
|
48
|
+
React.useEffect(() => {
|
|
49
|
+
// SSR / very old browsers: no observer, links still work as plain anchors.
|
|
50
|
+
if (typeof IntersectionObserver === "undefined") return
|
|
51
|
+
|
|
52
|
+
const ids = idKey.split("\n").filter(Boolean)
|
|
53
|
+
const visible = new Set<string>()
|
|
54
|
+
|
|
55
|
+
const observer = new IntersectionObserver(
|
|
56
|
+
(entries) => {
|
|
57
|
+
for (const entry of entries) {
|
|
58
|
+
if (entry.isIntersecting) visible.add(entry.target.id)
|
|
59
|
+
else visible.delete(entry.target.id)
|
|
60
|
+
}
|
|
61
|
+
// Deterministic resolution: first item (in items order) whose target
|
|
62
|
+
// is visible wins. Keep the previous active id while nothing is
|
|
63
|
+
// visible (e.g. mid-jump between long sections).
|
|
64
|
+
const first = ids.find((id) => visible.has(id))
|
|
65
|
+
if (first) setActiveId(first)
|
|
66
|
+
},
|
|
67
|
+
{ rootMargin: `${-offset}px 0px 0px 0px`, threshold: 0 }
|
|
68
|
+
)
|
|
69
|
+
|
|
70
|
+
for (const id of ids) {
|
|
71
|
+
const el = document.getElementById(id)
|
|
72
|
+
if (el) observer.observe(el)
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
return () => observer.disconnect()
|
|
76
|
+
}, [idKey, offset])
|
|
77
|
+
|
|
78
|
+
return (
|
|
79
|
+
<nav
|
|
80
|
+
data-slot="anchor"
|
|
81
|
+
aria-label={label}
|
|
82
|
+
className={cn("text-sm", className)}
|
|
83
|
+
{...props}
|
|
84
|
+
>
|
|
85
|
+
<ul className="flex flex-col border-l border-border">
|
|
86
|
+
{items.map((item) => {
|
|
87
|
+
const isActive = activeId === item.id
|
|
88
|
+
const depth = Math.min(Math.max(item.depth ?? 0, 0), 2)
|
|
89
|
+
return (
|
|
90
|
+
<li key={item.id} className="relative">
|
|
91
|
+
<a
|
|
92
|
+
data-slot="anchor-item"
|
|
93
|
+
data-active={isActive ? "" : undefined}
|
|
94
|
+
href={`#${item.id}`}
|
|
95
|
+
aria-current={isActive ? "location" : undefined}
|
|
96
|
+
className={cn(
|
|
97
|
+
"flex min-h-8 items-center rounded-sm py-1 pr-3 transition-colors outline-none",
|
|
98
|
+
"focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2",
|
|
99
|
+
DEPTH_PADDING[depth],
|
|
100
|
+
isActive
|
|
101
|
+
? "font-medium text-primary"
|
|
102
|
+
: "text-muted-foreground hover:text-foreground"
|
|
103
|
+
)}
|
|
104
|
+
style={{
|
|
105
|
+
transitionDuration: "var(--duration-fast)",
|
|
106
|
+
transitionTimingFunction: "var(--ease-out)",
|
|
107
|
+
}}
|
|
108
|
+
>
|
|
109
|
+
{/* Active indicator line, riding the rail. Decorative — the
|
|
110
|
+
accessible state signal is aria-current="location". */}
|
|
111
|
+
<span
|
|
112
|
+
aria-hidden="true"
|
|
113
|
+
data-slot="anchor-indicator"
|
|
114
|
+
className={cn(
|
|
115
|
+
"absolute inset-y-1 -left-px w-0.5 rounded-full bg-primary transition-opacity",
|
|
116
|
+
isActive ? "opacity-100" : "opacity-0"
|
|
117
|
+
)}
|
|
118
|
+
style={{
|
|
119
|
+
transitionDuration: "var(--duration-fast)",
|
|
120
|
+
transitionTimingFunction: "var(--ease-out)",
|
|
121
|
+
}}
|
|
122
|
+
/>
|
|
123
|
+
<span className="min-w-0 truncate" title={item.label}>
|
|
124
|
+
{item.label}
|
|
125
|
+
</span>
|
|
126
|
+
</a>
|
|
127
|
+
</li>
|
|
128
|
+
)
|
|
129
|
+
})}
|
|
130
|
+
</ul>
|
|
131
|
+
</nav>
|
|
132
|
+
)
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
export { Anchor }
|
|
136
|
+
export type { AnchorProps, AnchorItem }
|