@behavioral-agentic-design-system/core 0.24.0 → 0.27.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 +87 -5
- package/src/app/preview/components/page.tsx +4745 -244
- 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-action-button.tsx +179 -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 +51 -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 +343 -0
- package/src/components/ui/typing-indicator.tsx +96 -0
- package/src/components/ui/visually-hidden.tsx +42 -0
- package/src/components/ui/watermark.tsx +0 -0
- package/src/components/ui/word-rotate.tsx +82 -0
- package/src/data/docs-index.ts +10 -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/FloatingActionButton.stories.tsx +215 -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 +150 -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 +190 -0
- package/src/stories/TypingIndicator.stories.tsx +139 -0
- package/src/stories/VisuallyHidden.stories.tsx +105 -0
- package/src/stories/Watermark.stories.tsx +212 -0
- package/src/stories/WordRotate.stories.tsx +101 -0
- package/src/styles.css +88 -6
- package/src/tokens.json +3 -3
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
"use client"
|
|
2
|
+
|
|
3
|
+
import * as React from "react"
|
|
4
|
+
import { XIcon } from "lucide-react"
|
|
5
|
+
import { cn } from "../../lib/utils"
|
|
6
|
+
|
|
7
|
+
type FloatingPanelPosition =
|
|
8
|
+
| "bottom-right"
|
|
9
|
+
| "bottom-left"
|
|
10
|
+
| "top-right"
|
|
11
|
+
| "top-left"
|
|
12
|
+
|
|
13
|
+
const positionClasses: Record<FloatingPanelPosition, string> = {
|
|
14
|
+
"bottom-right": "bottom-4 right-4",
|
|
15
|
+
"bottom-left": "bottom-4 left-4",
|
|
16
|
+
"top-right": "top-4 right-4",
|
|
17
|
+
"top-left": "top-4 left-4",
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
type FloatingPanelProps = Omit<React.HTMLAttributes<HTMLElement>, "title"> & {
|
|
21
|
+
/** Viewport corner the panel anchors to. Default "bottom-right". */
|
|
22
|
+
defaultPosition?: FloatingPanelPosition
|
|
23
|
+
/**
|
|
24
|
+
* Optional header title. When it is a plain string the landmark's
|
|
25
|
+
* accessible name derives from it via aria-labelledby.
|
|
26
|
+
*/
|
|
27
|
+
title?: React.ReactNode
|
|
28
|
+
/**
|
|
29
|
+
* Visibility. Default true — FloatingPanel is a persistent companion
|
|
30
|
+
* surface, not a popup. When false the panel carries the `hidden`
|
|
31
|
+
* attribute so it leaves the tab order and the accessibility tree.
|
|
32
|
+
*/
|
|
33
|
+
open?: boolean
|
|
34
|
+
/**
|
|
35
|
+
* When provided, a labelled close button renders in the header and
|
|
36
|
+
* fires onOpenChange(false) on click.
|
|
37
|
+
*/
|
|
38
|
+
onOpenChange?: (open: boolean) => void
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Floating, always-rendered, non-modal companion panel anchored to a
|
|
43
|
+
* viewport corner. Floats over content without blocking it — contextual
|
|
44
|
+
* help that stays available while the user works, debug overlays,
|
|
45
|
+
* sticky-note panels.
|
|
46
|
+
*
|
|
47
|
+
* Not a Sheet (edge-anchored slide-in), not a Popover (trigger-anchored,
|
|
48
|
+
* dismissable), not a Dialog (modal, focus-trapped). Focus is deliberately
|
|
49
|
+
* NOT trapped: the panel is a `role="complementary"` landmark the user
|
|
50
|
+
* tabs into and out of like any other page region.
|
|
51
|
+
*
|
|
52
|
+
* Reduced motion: the base layer's `prefers-reduced-motion` rule collapses
|
|
53
|
+
* the open/close transition automatically; no component-level guard needed.
|
|
54
|
+
*/
|
|
55
|
+
function FloatingPanel({
|
|
56
|
+
defaultPosition = "bottom-right",
|
|
57
|
+
title,
|
|
58
|
+
open = true,
|
|
59
|
+
onOpenChange,
|
|
60
|
+
className,
|
|
61
|
+
children,
|
|
62
|
+
...props
|
|
63
|
+
}: FloatingPanelProps) {
|
|
64
|
+
const titleId = React.useId()
|
|
65
|
+
const hasStringTitle = typeof title === "string" && title.length > 0
|
|
66
|
+
const showHeader = title != null || onOpenChange != null
|
|
67
|
+
|
|
68
|
+
return (
|
|
69
|
+
<div
|
|
70
|
+
data-slot="floating-panel"
|
|
71
|
+
data-open={open}
|
|
72
|
+
role="complementary"
|
|
73
|
+
// Consumer aria-label / aria-labelledby in {...props} spreads AFTER
|
|
74
|
+
// these defaults, so an explicit name always wins.
|
|
75
|
+
aria-labelledby={hasStringTitle ? titleId : undefined}
|
|
76
|
+
aria-label={hasStringTitle ? undefined : "Floating panel"}
|
|
77
|
+
hidden={!open || undefined}
|
|
78
|
+
className={cn(
|
|
79
|
+
"fixed z-50 w-72 rounded-lg border border-border bg-background p-4 text-foreground shadow-lg",
|
|
80
|
+
positionClasses[defaultPosition],
|
|
81
|
+
open ? "opacity-100 scale-100" : "opacity-0 scale-95",
|
|
82
|
+
className
|
|
83
|
+
)}
|
|
84
|
+
style={{
|
|
85
|
+
transitionProperty: "opacity, transform",
|
|
86
|
+
transitionDuration: "var(--duration-base)",
|
|
87
|
+
transitionTimingFunction: "var(--ease-out)",
|
|
88
|
+
}}
|
|
89
|
+
{...props}
|
|
90
|
+
>
|
|
91
|
+
{showHeader && (
|
|
92
|
+
<header
|
|
93
|
+
data-slot="floating-panel-header"
|
|
94
|
+
className="mb-2 flex items-start justify-between gap-2"
|
|
95
|
+
>
|
|
96
|
+
{title != null ? (
|
|
97
|
+
<p
|
|
98
|
+
id={hasStringTitle ? titleId : undefined}
|
|
99
|
+
data-slot="floating-panel-title"
|
|
100
|
+
className="min-w-0 truncate text-sm font-medium"
|
|
101
|
+
>
|
|
102
|
+
{title}
|
|
103
|
+
</p>
|
|
104
|
+
) : (
|
|
105
|
+
<span aria-hidden="true" />
|
|
106
|
+
)}
|
|
107
|
+
{onOpenChange != null && (
|
|
108
|
+
<button
|
|
109
|
+
type="button"
|
|
110
|
+
aria-label="Close panel"
|
|
111
|
+
onClick={() => onOpenChange(false)}
|
|
112
|
+
className="-mr-1 -mt-1 flex size-8 shrink-0 items-center justify-center rounded-sm text-muted-foreground hover:bg-accent hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring"
|
|
113
|
+
style={{
|
|
114
|
+
transitionProperty: "background-color, color",
|
|
115
|
+
transitionDuration: "var(--duration-fast)",
|
|
116
|
+
transitionTimingFunction: "var(--ease-out)",
|
|
117
|
+
}}
|
|
118
|
+
>
|
|
119
|
+
<XIcon size={16} strokeWidth={1.5} aria-hidden="true" />
|
|
120
|
+
</button>
|
|
121
|
+
)}
|
|
122
|
+
</header>
|
|
123
|
+
)}
|
|
124
|
+
{children}
|
|
125
|
+
</div>
|
|
126
|
+
)
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
export { FloatingPanel, type FloatingPanelProps, type FloatingPanelPosition }
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import * as React from "react"
|
|
2
|
+
|
|
3
|
+
import { cn } from "../../lib/utils"
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Explicit default locale. FormatNumber never reads the runtime locale
|
|
7
|
+
* (navigator.language): an implicit locale formats differently on the
|
|
8
|
+
* server and the client, which is the classic hydration-mismatch bug.
|
|
9
|
+
* Consumers localizing for real pass `locale` from their own i18n layer.
|
|
10
|
+
*/
|
|
11
|
+
const FORMAT_NUMBER_DEFAULT_LOCALE = "en-US"
|
|
12
|
+
|
|
13
|
+
export interface FormatNumberProps
|
|
14
|
+
extends Omit<React.ComponentProps<"span">, "style" | "children">,
|
|
15
|
+
Intl.NumberFormatOptions {
|
|
16
|
+
/** The number to format. */
|
|
17
|
+
value: number
|
|
18
|
+
/**
|
|
19
|
+
* BCP 47 locale tag. Defaults to "en-US" (explicit, SSR-safe) — pass your
|
|
20
|
+
* i18n layer's locale to localize.
|
|
21
|
+
*/
|
|
22
|
+
locale?: string
|
|
23
|
+
/**
|
|
24
|
+
* `font-variant-numeric: tabular-nums` so digits occupy equal widths.
|
|
25
|
+
*
|
|
26
|
+
* **Defaults to `true`.** Tabular figures are the right baseline for a
|
|
27
|
+
* number-*display* primitive: they align in columns and stat rows, and —
|
|
28
|
+
* load-bearing for BADS' default face — they sidestep a rendering collision
|
|
29
|
+
* in Hyperlegible Sans, whose *proportional* figures carry kern pairs that
|
|
30
|
+
* Chromium over-applies, cramping/overlapping decimals (e.g. `$182,450.00`).
|
|
31
|
+
* Tabular figures use fixed advances with no kerning, so numbers render
|
|
32
|
+
* cleanly in the brand font. Pass `tabular={false}` to opt back into
|
|
33
|
+
* proportional figures (fine for prose on a fork whose font renders them
|
|
34
|
+
* cleanly; may cramp on Hyperlegible).
|
|
35
|
+
*/
|
|
36
|
+
tabular?: boolean
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Locale-aware number display primitive — a thin wrapper around
|
|
41
|
+
* `Intl.NumberFormat`. Handles decimal, currency, percent, unit, and
|
|
42
|
+
* compact notation. Display-only: for editable numbers use NumberInput.
|
|
43
|
+
*
|
|
44
|
+
* Note: `style` here is the Intl style ("decimal" | "currency" | "percent"
|
|
45
|
+
* | "unit"), matching Chakra/Ark — NOT the CSS style prop. Style the span
|
|
46
|
+
* via `className`.
|
|
47
|
+
*/
|
|
48
|
+
function FormatNumber({
|
|
49
|
+
value,
|
|
50
|
+
locale = FORMAT_NUMBER_DEFAULT_LOCALE,
|
|
51
|
+
tabular = true,
|
|
52
|
+
className,
|
|
53
|
+
title,
|
|
54
|
+
// Intl.NumberFormatOptions (ES2020 set) — passed to the formatter, kept
|
|
55
|
+
// out of the DOM spread so no unknown attributes leak onto the <span>.
|
|
56
|
+
localeMatcher,
|
|
57
|
+
numberingSystem,
|
|
58
|
+
style,
|
|
59
|
+
currency,
|
|
60
|
+
currencyDisplay,
|
|
61
|
+
currencySign,
|
|
62
|
+
unit,
|
|
63
|
+
unitDisplay,
|
|
64
|
+
useGrouping,
|
|
65
|
+
minimumIntegerDigits,
|
|
66
|
+
minimumFractionDigits,
|
|
67
|
+
maximumFractionDigits,
|
|
68
|
+
minimumSignificantDigits,
|
|
69
|
+
maximumSignificantDigits,
|
|
70
|
+
notation,
|
|
71
|
+
compactDisplay,
|
|
72
|
+
signDisplay,
|
|
73
|
+
...props
|
|
74
|
+
}: FormatNumberProps) {
|
|
75
|
+
const options: Intl.NumberFormatOptions = {
|
|
76
|
+
localeMatcher,
|
|
77
|
+
numberingSystem,
|
|
78
|
+
style,
|
|
79
|
+
currency,
|
|
80
|
+
currencyDisplay,
|
|
81
|
+
currencySign,
|
|
82
|
+
unit,
|
|
83
|
+
unitDisplay,
|
|
84
|
+
useGrouping,
|
|
85
|
+
minimumIntegerDigits,
|
|
86
|
+
minimumFractionDigits,
|
|
87
|
+
maximumFractionDigits,
|
|
88
|
+
minimumSignificantDigits,
|
|
89
|
+
maximumSignificantDigits,
|
|
90
|
+
notation,
|
|
91
|
+
compactDisplay,
|
|
92
|
+
signDisplay,
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
const formatted = new Intl.NumberFormat(locale, options).format(value)
|
|
96
|
+
|
|
97
|
+
// Compact notation abbreviates ("1.2M"). Screen readers announce the
|
|
98
|
+
// visible text as-is (no aria-label override — SC 2.5.3 hygiene); the
|
|
99
|
+
// full-precision value rides the native title attribute so it stays
|
|
100
|
+
// recoverable on hover / long-press. A consumer-supplied title wins.
|
|
101
|
+
const fullValue =
|
|
102
|
+
notation === "compact" && title === undefined
|
|
103
|
+
? new Intl.NumberFormat(locale, {
|
|
104
|
+
...options,
|
|
105
|
+
notation: "standard",
|
|
106
|
+
compactDisplay: undefined,
|
|
107
|
+
}).format(value)
|
|
108
|
+
: undefined
|
|
109
|
+
|
|
110
|
+
return (
|
|
111
|
+
<span
|
|
112
|
+
data-slot="format-number"
|
|
113
|
+
className={cn(tabular && "tabular-nums", className)}
|
|
114
|
+
title={title ?? fullValue}
|
|
115
|
+
{...props}
|
|
116
|
+
>
|
|
117
|
+
{formatted}
|
|
118
|
+
</span>
|
|
119
|
+
)
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
export { FormatNumber, FORMAT_NUMBER_DEFAULT_LOCALE }
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
"use client"
|
|
2
|
+
|
|
3
|
+
import * as React from "react"
|
|
4
|
+
|
|
5
|
+
import { cn } from "../../lib/utils"
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Escape regex-special characters so raw user input (search queries,
|
|
9
|
+
* filter terms) can never break — or worse, alter — the match pattern.
|
|
10
|
+
* `.` `*` `+` `?` `^` `$` `{` `}` `(` `)` `|` `[` `]` `\` are all literalized.
|
|
11
|
+
*/
|
|
12
|
+
function escapeRegExp(value: string): string {
|
|
13
|
+
return value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export interface HighlightProps
|
|
17
|
+
extends Omit<React.ComponentProps<"span">, "children"> {
|
|
18
|
+
/**
|
|
19
|
+
* Substring(s) to mark inside `children`. Matching is case-insensitive
|
|
20
|
+
* and safe against regex-special characters. Empty / whitespace-only
|
|
21
|
+
* terms are ignored — an empty query renders the text unchanged.
|
|
22
|
+
*/
|
|
23
|
+
highlight: string | string[]
|
|
24
|
+
/**
|
|
25
|
+
* The full text to search. A plain string (not ReactNode) so matching
|
|
26
|
+
* semantics are a compile-time guarantee.
|
|
27
|
+
*/
|
|
28
|
+
children: string
|
|
29
|
+
/** Extra classes merged onto every `<mark>` (e.g. a subtler fork tint). */
|
|
30
|
+
markClassName?: string
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Wraps every case-insensitive occurrence of `highlight` inside `children`
|
|
35
|
+
* in a semantic `<mark>` styled with the audited `primary` /
|
|
36
|
+
* `primary-foreground` token pair (15.79:1, AAA in both modes).
|
|
37
|
+
*
|
|
38
|
+
* Display-only: `<mark>` carries no focus, keyboard, or target-size
|
|
39
|
+
* contract, and most screen readers do not announce it — never make the
|
|
40
|
+
* highlight the sole carrier of "this matched"; pair it with a result
|
|
41
|
+
* count or a filtered list.
|
|
42
|
+
*/
|
|
43
|
+
function Highlight({
|
|
44
|
+
highlight,
|
|
45
|
+
children,
|
|
46
|
+
markClassName,
|
|
47
|
+
className,
|
|
48
|
+
...props
|
|
49
|
+
}: HighlightProps) {
|
|
50
|
+
const terms = (Array.isArray(highlight) ? highlight : [highlight]).filter(
|
|
51
|
+
(term) => term.trim().length > 0
|
|
52
|
+
)
|
|
53
|
+
|
|
54
|
+
let content: React.ReactNode = children
|
|
55
|
+
if (terms.length > 0) {
|
|
56
|
+
// One capture group around the whole alternation: String.split keeps
|
|
57
|
+
// the captured matches in the result at odd indices — no RegExp
|
|
58
|
+
// lastIndex statefulness, no re-testing of chunks.
|
|
59
|
+
const pattern = new RegExp(`(${terms.map(escapeRegExp).join("|")})`, "gi")
|
|
60
|
+
content = children.split(pattern).map((chunk, index) =>
|
|
61
|
+
index % 2 === 1 ? (
|
|
62
|
+
<mark
|
|
63
|
+
key={index}
|
|
64
|
+
data-slot="highlight-mark"
|
|
65
|
+
className={cn(
|
|
66
|
+
"rounded-sm bg-primary px-0.5 text-primary-foreground",
|
|
67
|
+
markClassName
|
|
68
|
+
)}
|
|
69
|
+
>
|
|
70
|
+
{chunk}
|
|
71
|
+
</mark>
|
|
72
|
+
) : (
|
|
73
|
+
chunk
|
|
74
|
+
)
|
|
75
|
+
)
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
return (
|
|
79
|
+
<span data-slot="highlight" className={className} {...props}>
|
|
80
|
+
{content}
|
|
81
|
+
</span>
|
|
82
|
+
)
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
export { Highlight }
|
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
"use client"
|
|
2
|
+
|
|
3
|
+
import * as React from "react"
|
|
4
|
+
import { ImageOff } from "lucide-react"
|
|
5
|
+
|
|
6
|
+
import { cn } from "../../lib/utils"
|
|
7
|
+
import { Skeleton } from "./skeleton"
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Image — image display primitive with fallback, aspect ratio, and lazy
|
|
11
|
+
* loading.
|
|
12
|
+
*
|
|
13
|
+
* Wraps a native img element with the three behaviors every product surface
|
|
14
|
+
* re-rolls by hand: a Skeleton while the image loads, a token-styled fallback
|
|
15
|
+
* when the src is broken (the accessible name survives via `role="img"` +
|
|
16
|
+
* `aria-label`), and an optional CSS `aspect-ratio` frame so layouts don't
|
|
17
|
+
* shift when the image arrives. Loads lazily by default.
|
|
18
|
+
*
|
|
19
|
+
* Display-only: no focus, keyboard, or target-size contract (like Text). The
|
|
20
|
+
* only motion is a token-driven opacity fade-in on load (pattern c), which
|
|
21
|
+
* the base layer collapses under prefers-reduced-motion.
|
|
22
|
+
*
|
|
23
|
+
* NOT a lightbox (zoom/preview is a separate concern) and NOT a `next/image`
|
|
24
|
+
* substitute — there's no optimization pipeline here; pass an already-sized
|
|
25
|
+
* URL as `src`.
|
|
26
|
+
*/
|
|
27
|
+
|
|
28
|
+
type ImageProps = Omit<React.ComponentProps<"img">, "alt"> & {
|
|
29
|
+
/**
|
|
30
|
+
* Alternative text. Required at the type level — pass `""` explicitly for
|
|
31
|
+
* a purely decorative image.
|
|
32
|
+
*/
|
|
33
|
+
alt: string
|
|
34
|
+
/** Fixed aspect ratio for the frame, e.g. `"16/9"`, `"4/3"`, `"1/1"` or a number. */
|
|
35
|
+
ratio?: number | `${number}/${number}`
|
|
36
|
+
/** How the image fills the frame. Default `"cover"`. */
|
|
37
|
+
fit?: "cover" | "contain" | "fill"
|
|
38
|
+
/** Token radius on the frame. Default `"md"`. */
|
|
39
|
+
radius?: "none" | "sm" | "md" | "lg" | "full"
|
|
40
|
+
/**
|
|
41
|
+
* Rendered when the image fails to load. A string renders as styled text;
|
|
42
|
+
* a node renders as-is (own its semantics). Default: a muted ImageOff
|
|
43
|
+
* glyph, with the accessible name kept via `role="img"` + `aria-label`.
|
|
44
|
+
*/
|
|
45
|
+
fallback?: React.ReactNode
|
|
46
|
+
/** Native lazy loading. Default `true`. */
|
|
47
|
+
lazy?: boolean
|
|
48
|
+
/** Caption below the image. Promotes the root to a semantic `<figure>`. */
|
|
49
|
+
caption?: React.ReactNode
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
const fitClasses = {
|
|
53
|
+
cover: "object-cover",
|
|
54
|
+
contain: "object-contain",
|
|
55
|
+
fill: "object-fill",
|
|
56
|
+
} as const
|
|
57
|
+
|
|
58
|
+
const radiusClasses = {
|
|
59
|
+
none: "rounded-none",
|
|
60
|
+
sm: "rounded-sm",
|
|
61
|
+
md: "rounded-md",
|
|
62
|
+
lg: "rounded-lg",
|
|
63
|
+
full: "rounded-full",
|
|
64
|
+
} as const
|
|
65
|
+
|
|
66
|
+
type LoadStatus = "loading" | "loaded" | "error"
|
|
67
|
+
|
|
68
|
+
function Image({
|
|
69
|
+
className,
|
|
70
|
+
alt,
|
|
71
|
+
ratio,
|
|
72
|
+
fit = "cover",
|
|
73
|
+
radius = "md",
|
|
74
|
+
fallback,
|
|
75
|
+
lazy = true,
|
|
76
|
+
caption,
|
|
77
|
+
src,
|
|
78
|
+
onLoad,
|
|
79
|
+
onError,
|
|
80
|
+
...props
|
|
81
|
+
}: ImageProps) {
|
|
82
|
+
const [status, setStatus] = React.useState<LoadStatus>(src ? "loading" : "error")
|
|
83
|
+
const imgRef = React.useRef<HTMLImageElement | null>(null)
|
|
84
|
+
|
|
85
|
+
// Reset the state machine when the src changes.
|
|
86
|
+
React.useEffect(() => {
|
|
87
|
+
setStatus(src ? "loading" : "error")
|
|
88
|
+
}, [src])
|
|
89
|
+
|
|
90
|
+
// Cached images can complete before hydration, so the load event never
|
|
91
|
+
// reaches React — check completeness on mount or the skeleton sticks.
|
|
92
|
+
React.useEffect(() => {
|
|
93
|
+
const el = imgRef.current
|
|
94
|
+
if (el && el.complete) {
|
|
95
|
+
setStatus(el.naturalWidth > 0 ? "loaded" : "error")
|
|
96
|
+
}
|
|
97
|
+
}, [src])
|
|
98
|
+
|
|
99
|
+
const aspectRatio =
|
|
100
|
+
typeof ratio === "number" ? String(ratio) : ratio ? ratio.replace("/", " / ") : undefined
|
|
101
|
+
|
|
102
|
+
const showFallback = status === "error"
|
|
103
|
+
const fallbackIsNode = fallback != null && typeof fallback !== "string"
|
|
104
|
+
|
|
105
|
+
const frame = (
|
|
106
|
+
<div
|
|
107
|
+
data-slot="image-frame"
|
|
108
|
+
className={cn(
|
|
109
|
+
"relative w-full overflow-hidden bg-muted",
|
|
110
|
+
radiusClasses[radius],
|
|
111
|
+
// No ratio + still loading/error: give the frame a body so the
|
|
112
|
+
// skeleton/fallback isn't a zero-height sliver.
|
|
113
|
+
!aspectRatio && status !== "loaded" && "min-h-24"
|
|
114
|
+
)}
|
|
115
|
+
style={aspectRatio ? { aspectRatio } : undefined}
|
|
116
|
+
>
|
|
117
|
+
{status === "loading" && (
|
|
118
|
+
<Skeleton
|
|
119
|
+
data-slot="image-skeleton"
|
|
120
|
+
className="absolute inset-0 h-full w-full rounded-none"
|
|
121
|
+
/>
|
|
122
|
+
)}
|
|
123
|
+
{!showFallback && (
|
|
124
|
+
<img
|
|
125
|
+
ref={imgRef}
|
|
126
|
+
data-slot="image"
|
|
127
|
+
data-state={status}
|
|
128
|
+
alt={alt}
|
|
129
|
+
src={src}
|
|
130
|
+
loading={lazy ? "lazy" : undefined}
|
|
131
|
+
onLoad={(event) => {
|
|
132
|
+
setStatus("loaded")
|
|
133
|
+
onLoad?.(event)
|
|
134
|
+
}}
|
|
135
|
+
onError={(event) => {
|
|
136
|
+
setStatus("error")
|
|
137
|
+
onError?.(event)
|
|
138
|
+
}}
|
|
139
|
+
className={cn(
|
|
140
|
+
"w-full transition-opacity",
|
|
141
|
+
aspectRatio ? "h-full" : "h-auto",
|
|
142
|
+
fitClasses[fit],
|
|
143
|
+
status === "loaded" ? "opacity-100" : "opacity-0"
|
|
144
|
+
)}
|
|
145
|
+
style={{
|
|
146
|
+
transitionDuration: "var(--duration-base)",
|
|
147
|
+
transitionTimingFunction: "var(--ease-out)",
|
|
148
|
+
}}
|
|
149
|
+
{...props}
|
|
150
|
+
/>
|
|
151
|
+
)}
|
|
152
|
+
{showFallback &&
|
|
153
|
+
(fallbackIsNode ? (
|
|
154
|
+
<div data-slot="image-fallback" className={cn(aspectRatio && "absolute inset-0")}>
|
|
155
|
+
{fallback}
|
|
156
|
+
</div>
|
|
157
|
+
) : (
|
|
158
|
+
<div
|
|
159
|
+
data-slot="image-fallback"
|
|
160
|
+
role="img"
|
|
161
|
+
aria-label={alt || undefined}
|
|
162
|
+
className={cn(
|
|
163
|
+
"flex flex-col items-center justify-center gap-2 p-4 text-muted-foreground",
|
|
164
|
+
aspectRatio ? "absolute inset-0" : "min-h-24"
|
|
165
|
+
)}
|
|
166
|
+
>
|
|
167
|
+
<ImageOff strokeWidth={1.5} className="size-5 shrink-0" aria-hidden="true" />
|
|
168
|
+
{typeof fallback === "string" && (
|
|
169
|
+
<span className="max-w-full truncate text-xs">{fallback}</span>
|
|
170
|
+
)}
|
|
171
|
+
</div>
|
|
172
|
+
))}
|
|
173
|
+
</div>
|
|
174
|
+
)
|
|
175
|
+
|
|
176
|
+
if (caption != null) {
|
|
177
|
+
return (
|
|
178
|
+
<figure data-slot="image-root" className={cn("m-0 flex w-full flex-col gap-2", className)}>
|
|
179
|
+
{frame}
|
|
180
|
+
<figcaption data-slot="image-caption" className="text-xs text-muted-foreground">
|
|
181
|
+
{caption}
|
|
182
|
+
</figcaption>
|
|
183
|
+
</figure>
|
|
184
|
+
)
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
return (
|
|
188
|
+
<div data-slot="image-root" className={cn("w-full", className)}>
|
|
189
|
+
{frame}
|
|
190
|
+
</div>
|
|
191
|
+
)
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
export { Image }
|
|
195
|
+
export type { ImageProps }
|
|
@@ -3,11 +3,14 @@
|
|
|
3
3
|
// import paths so optional peer deps stay optional.
|
|
4
4
|
export * from "./accordion";
|
|
5
5
|
export * from "./alert";
|
|
6
|
+
export * from "./angle-slider";
|
|
6
7
|
export * from "./aspect-ratio";
|
|
7
8
|
export * from "./carousel";
|
|
8
9
|
export * from "./alert-dialog";
|
|
9
10
|
export * from "./avatar";
|
|
10
11
|
export * from "./badge";
|
|
12
|
+
export * from "./blockquote";
|
|
13
|
+
export * from "./bottom-navigation";
|
|
11
14
|
export * from "./breadcrumb";
|
|
12
15
|
export * from "./button";
|
|
13
16
|
export * from "./calendar";
|
|
@@ -17,6 +20,7 @@ export * from "./chart";
|
|
|
17
20
|
export * from "./checkbox";
|
|
18
21
|
export * from "./collapsible";
|
|
19
22
|
export * from "./color-picker";
|
|
23
|
+
export * from "./color-swatch";
|
|
20
24
|
export * from "./command";
|
|
21
25
|
export * from "./context-menu";
|
|
22
26
|
export * from "./data-list";
|
|
@@ -29,8 +33,11 @@ export * from "./input";
|
|
|
29
33
|
export * from "./input-group";
|
|
30
34
|
export * from "./kbd";
|
|
31
35
|
export * from "./label";
|
|
36
|
+
export * from "./link";
|
|
32
37
|
export * from "./menubar";
|
|
38
|
+
export * from "./motion-toggle";
|
|
33
39
|
export * from "./navigation-menu";
|
|
40
|
+
export * from "./notification";
|
|
34
41
|
export * from "./number-input";
|
|
35
42
|
export * from "./pagination";
|
|
36
43
|
export * from "./password-input";
|
|
@@ -48,11 +55,13 @@ export * from "./skeleton";
|
|
|
48
55
|
export * from "./slider";
|
|
49
56
|
export * from "./sonner";
|
|
50
57
|
export * from "./spinner";
|
|
58
|
+
export * from "./spoiler";
|
|
51
59
|
export * from "./stepper";
|
|
52
60
|
export * from "./switch";
|
|
53
61
|
export * from "./table";
|
|
54
62
|
export * from "./tabs";
|
|
55
63
|
export * from "./tag";
|
|
64
|
+
export * from "./text";
|
|
56
65
|
export * from "./segmented-control";
|
|
57
66
|
export * from "./tags-input";
|
|
58
67
|
export * from "./timeline";
|
|
@@ -64,3 +73,45 @@ export * from "./tooltip";
|
|
|
64
73
|
export * from "./tree-view";
|
|
65
74
|
export * from "./editable";
|
|
66
75
|
export * from "./qr-code";
|
|
76
|
+
export * from "./highlight";
|
|
77
|
+
export * from "./format-number";
|
|
78
|
+
export * from "./autocomplete";
|
|
79
|
+
export * from "./button-group";
|
|
80
|
+
export * from "./checkbox-group";
|
|
81
|
+
export * from "./circular-progress";
|
|
82
|
+
export * from "./code";
|
|
83
|
+
export * from "./combobox";
|
|
84
|
+
export * from "./copy-button";
|
|
85
|
+
export * from "./date-range-picker";
|
|
86
|
+
export * from "./empty-state";
|
|
87
|
+
export * from "./field";
|
|
88
|
+
export * from "./indicator";
|
|
89
|
+
export * from "./list";
|
|
90
|
+
export * from "./marquee";
|
|
91
|
+
export * from "./multi-select";
|
|
92
|
+
export * from "./native-select";
|
|
93
|
+
export * from "./pin-input";
|
|
94
|
+
export * from "./time-picker";
|
|
95
|
+
export * from "./visually-hidden";
|
|
96
|
+
export * from "./meter";
|
|
97
|
+
export * from "./chip";
|
|
98
|
+
export * from "./transfer-list";
|
|
99
|
+
export * from "./burger";
|
|
100
|
+
export * from "./action-bar";
|
|
101
|
+
export * from "./checkbox-card";
|
|
102
|
+
export * from "./watermark";
|
|
103
|
+
export * from "./loading-overlay";
|
|
104
|
+
export * from "./float-label";
|
|
105
|
+
export * from "./tour";
|
|
106
|
+
export * from "./image";
|
|
107
|
+
export * from "./masonry";
|
|
108
|
+
export * from "./listbox";
|
|
109
|
+
export * from "./floating-panel";
|
|
110
|
+
export * from "./anchor";
|
|
111
|
+
export * from "./overlay";
|
|
112
|
+
export * from "./cascader";
|
|
113
|
+
export * from "./affix";
|
|
114
|
+
export * from "./skip-link";
|
|
115
|
+
export * from "./timer";
|
|
116
|
+
export * from "./signature-pad";
|
|
117
|
+
export * from "./floating-action-button";
|
|
@@ -21,8 +21,8 @@ const indicatorDotVariants = cva(
|
|
|
21
21
|
default: "bg-primary text-primary-foreground",
|
|
22
22
|
secondary: "bg-secondary text-secondary-foreground",
|
|
23
23
|
destructive: "bg-destructive text-white",
|
|
24
|
-
success: "bg-[
|
|
25
|
-
warning: "bg-[
|
|
24
|
+
success: "bg-[var(--success)] text-white",
|
|
25
|
+
warning: "bg-[var(--warning)] text-white",
|
|
26
26
|
},
|
|
27
27
|
size: {
|
|
28
28
|
// Dot-only base dimensions; labeled mode overrides height + min-width below
|