@behavioral-agentic-design-system/core 0.40.0 → 0.42.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/README.md +2 -0
- package/package.json +19 -3
- package/scripts/a11y-lint.cjs +41 -2
- package/scripts/health-report.mjs +16 -2
- package/scripts/lint-slop.mjs +25 -1
- package/scripts/wcag-audit.cjs +72 -5
- package/src/app/opengraph-image.tsx +5 -0
- package/src/app/preview/components/page.tsx +1269 -2
- package/src/app/shell.tsx +8 -5
- package/src/components/Foundations/Motion.stories.tsx +1 -0
- package/src/components/customize/design-controls.tsx +16 -1
- package/src/components/studio/studio.tsx +153 -0
- package/src/components/ui/anchor.tsx +37 -3
- package/src/components/ui/attachment.tsx +211 -0
- package/src/components/ui/chart.tsx +3 -0
- package/src/components/ui/code.tsx +1 -1
- package/src/components/ui/color-picker.tsx +1 -1
- package/src/components/ui/gauge-chart.tsx +238 -0
- package/src/components/ui/heatmap.tsx +256 -0
- package/src/components/ui/index.ts +9 -0
- package/src/components/ui/infinite-scroll.tsx +103 -0
- package/src/components/ui/json-input.tsx +351 -0
- package/src/components/ui/navigation-progress.tsx +281 -0
- package/src/components/ui/number-input.tsx +1 -4
- package/src/components/ui/password-input.tsx +2 -1
- package/src/components/ui/password-strength-input.tsx +288 -0
- package/src/components/ui/pill.tsx +140 -0
- package/src/components/ui/popover.tsx +27 -4
- package/src/components/ui/scroll-progress.tsx +100 -0
- package/src/components/ui/snackbar.tsx +393 -0
- package/src/components/ui/sortable-list.tsx +342 -0
- package/src/components/ui/squircle.tsx +1 -1
- package/src/components/ui/table.tsx +1 -1
- package/src/components/ui/tour.tsx +1 -3
- package/src/data/docs-index.ts +24 -0
- package/src/lib/clamp.ts +2 -0
- package/src/stories/Anchor.stories.tsx +54 -0
- package/src/stories/Attachment.stories.tsx +189 -0
- package/src/stories/Chart.stories.tsx +4 -0
- package/src/stories/Code.stories.tsx +1 -0
- package/src/stories/ColorPicker.stories.tsx +1 -0
- package/src/stories/GaugeChart.stories.tsx +163 -0
- package/src/stories/Heatmap.stories.tsx +172 -0
- package/src/stories/InfiniteScroll.stories.tsx +225 -0
- package/src/stories/JsonInput.stories.tsx +212 -0
- package/src/stories/NavigationProgress.stories.tsx +159 -0
- package/src/stories/NumberInput.stories.tsx +1 -0
- package/src/stories/PasswordInput.stories.tsx +4 -0
- package/src/stories/PasswordStrengthInput.stories.tsx +211 -0
- package/src/stories/Pill.stories.tsx +201 -0
- package/src/stories/Popover.stories.tsx +29 -1
- package/src/stories/Portal.stories.tsx +3 -1
- package/src/stories/ScrollProgress.stories.tsx +117 -0
- package/src/stories/Snackbar.stories.tsx +315 -0
- package/src/stories/SortableList.stories.tsx +263 -0
- package/src/stories/Squircle.stories.tsx +1 -0
- package/src/stories/Table.stories.tsx +1 -0
- package/src/stories/Tour.stories.tsx +1 -0
- package/src/stories/story-groups.json +17 -6
- package/LICENSE +0 -21
|
@@ -0,0 +1,288 @@
|
|
|
1
|
+
"use client"
|
|
2
|
+
|
|
3
|
+
import * as React from "react"
|
|
4
|
+
|
|
5
|
+
import { cn } from "../../lib/utils"
|
|
6
|
+
import { PasswordInput, type PasswordInputProps } from "./password-input"
|
|
7
|
+
|
|
8
|
+
// ─── Types ────────────────────────────────────────────────────────────────────
|
|
9
|
+
|
|
10
|
+
/** 0 = no input · 1 = weak · 2 = fair · 3 = good · 4 = strong */
|
|
11
|
+
export type PasswordStrength = 0 | 1 | 2 | 3 | 4
|
|
12
|
+
|
|
13
|
+
export interface PasswordStrengthInputProps
|
|
14
|
+
extends Omit<PasswordInputProps, "onChange" | "className"> {
|
|
15
|
+
/** Standard onChange forwarded to the underlying <input>. */
|
|
16
|
+
onChange?: (e: React.ChangeEvent<HTMLInputElement>) => void
|
|
17
|
+
/**
|
|
18
|
+
* Custom strength calculator. Receives the raw value string and must return
|
|
19
|
+
* 0 (no input) | 1 (weak) | 2 (fair) | 3 (good) | 4 (strong).
|
|
20
|
+
*
|
|
21
|
+
* Default: built-in heuristic keyed off length + character variety.
|
|
22
|
+
* Replace via prop to wire zxcvbn, a backend scorer, or a rules list.
|
|
23
|
+
*/
|
|
24
|
+
strengthFn?: (value: string) => PasswordStrength
|
|
25
|
+
/**
|
|
26
|
+
* Number of visual segments in the strength bar.
|
|
27
|
+
* @default 4
|
|
28
|
+
*/
|
|
29
|
+
segments?: 3 | 4 | 5
|
|
30
|
+
/**
|
|
31
|
+
* Whether to render the strength label ("Weak", "Fair", "Good", "Strong").
|
|
32
|
+
* Label also carries the aria-live region so screen readers hear strength
|
|
33
|
+
* changes regardless of this prop.
|
|
34
|
+
* @default true
|
|
35
|
+
*/
|
|
36
|
+
showLabel?: boolean
|
|
37
|
+
/**
|
|
38
|
+
* Whether to render the requirements hint list below the strength bar.
|
|
39
|
+
* @default false
|
|
40
|
+
*/
|
|
41
|
+
showHints?: boolean
|
|
42
|
+
/** className on the outer wrapper div. */
|
|
43
|
+
className?: string
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
// ─── Default strength heuristic ───────────────────────────────────────────────
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Returns 0–4 based on length + character-variety heuristics:
|
|
50
|
+
*
|
|
51
|
+
* | Score | Label | Criteria |
|
|
52
|
+
* |-------|--------|------------------------------------------------------|
|
|
53
|
+
* | 0 | — | Empty string |
|
|
54
|
+
* | 1 | Weak | Non-empty, none of the bonuses below |
|
|
55
|
+
* | 2 | Fair | ≥8 chars |
|
|
56
|
+
* | 3 | Good | ≥8 chars + uppercase/lowercase + digit |
|
|
57
|
+
* | 4 | Strong | ≥12 chars + uppercase/lowercase + digit + special |
|
|
58
|
+
*
|
|
59
|
+
* Pass your own `strengthFn` prop to use zxcvbn or a rules-based scorer.
|
|
60
|
+
*/
|
|
61
|
+
export function defaultStrengthFn(value: string): PasswordStrength {
|
|
62
|
+
if (!value.length) return 0
|
|
63
|
+
let score = 0
|
|
64
|
+
if (value.length >= 8) score++
|
|
65
|
+
if (value.length >= 12) score++
|
|
66
|
+
if (/[A-Z]/.test(value) && /[a-z]/.test(value)) score++
|
|
67
|
+
if (/[0-9]/.test(value)) score++
|
|
68
|
+
if (/[^A-Za-z0-9]/.test(value)) score++
|
|
69
|
+
// Floor at 1 (weak) for any non-empty input; cap at 4 (strong).
|
|
70
|
+
return Math.min(4, Math.max(1, score)) as PasswordStrength
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
// ─── Static config ────────────────────────────────────────────────────────────
|
|
74
|
+
|
|
75
|
+
const STRENGTH_LABEL: Record<1 | 2 | 3 | 4, string> = {
|
|
76
|
+
1: "Weak",
|
|
77
|
+
2: "Fair",
|
|
78
|
+
3: "Good",
|
|
79
|
+
4: "Strong",
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* Segment and label colors, keyed by strength level.
|
|
84
|
+
*
|
|
85
|
+
* Uses `bg-[var(--token)]` for --success and --warning because those tokens
|
|
86
|
+
* are declared as oklch values; wrapping them in hsl() would silently fail.
|
|
87
|
+
* (Same pattern as Meter and Sonner.)
|
|
88
|
+
*/
|
|
89
|
+
const STRENGTH_SEGMENT_BG: Record<1 | 2 | 3 | 4, string> = {
|
|
90
|
+
1: "bg-destructive",
|
|
91
|
+
2: "bg-[var(--warning)]",
|
|
92
|
+
3: "bg-primary",
|
|
93
|
+
4: "bg-[var(--success)]",
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
const STRENGTH_LABEL_COLOR: Record<1 | 2 | 3 | 4, string> = {
|
|
97
|
+
1: "text-destructive",
|
|
98
|
+
2: "text-[var(--warning)]",
|
|
99
|
+
3: "text-primary",
|
|
100
|
+
4: "text-[var(--success)]",
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
export const PASSWORD_HINTS = [
|
|
104
|
+
"At least 8 characters",
|
|
105
|
+
"Uppercase and lowercase letters",
|
|
106
|
+
"At least one number",
|
|
107
|
+
"At least one special character (!@#$…)",
|
|
108
|
+
"12 or more characters for maximum strength",
|
|
109
|
+
] as const
|
|
110
|
+
|
|
111
|
+
// Segment transition — explicit properties, never transition-all.
|
|
112
|
+
const segmentMotion: React.CSSProperties = {
|
|
113
|
+
transitionProperty: "background-color",
|
|
114
|
+
transitionDuration: "var(--duration-base)",
|
|
115
|
+
transitionTimingFunction: "var(--ease-out)",
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
// ─── PasswordStrengthInput ────────────────────────────────────────────────────
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* PasswordInput with an inline segmented strength meter below the field.
|
|
122
|
+
*
|
|
123
|
+
* Composes BADS `PasswordInput` + a row of animated segment bars + a strength
|
|
124
|
+
* label. Strength is calculated from the live value via `strengthFn`; the
|
|
125
|
+
* built-in heuristic covers most signup/change-password surfaces. Override to
|
|
126
|
+
* wire zxcvbn or a backend scorer.
|
|
127
|
+
*
|
|
128
|
+
* ### Accessibility
|
|
129
|
+
* - Strength is conveyed by color **and** text (SC 1.4.1 — use of color).
|
|
130
|
+
* - The label carries `aria-live="polite"` + `aria-atomic="true"` so
|
|
131
|
+
* screen readers announce changes without the user having to query.
|
|
132
|
+
* - The input's `aria-describedby` is extended with the live-region id when
|
|
133
|
+
* there is text to describe.
|
|
134
|
+
*
|
|
135
|
+
* ### Peer parity
|
|
136
|
+
* Mantine `PasswordInput` (strength meter prop), shadcn/ui Auth block
|
|
137
|
+
* (password-strength composition), MUI docs (PasswordStrength example),
|
|
138
|
+
* Ark UI (PasswordInput + Meter composition).
|
|
139
|
+
*
|
|
140
|
+
* @example
|
|
141
|
+
* ```tsx
|
|
142
|
+
* // Uncontrolled — simplest usage on a signup form
|
|
143
|
+
* <PasswordStrengthInput
|
|
144
|
+
* placeholder="New password"
|
|
145
|
+
* autoComplete="new-password"
|
|
146
|
+
* showHints
|
|
147
|
+
* />
|
|
148
|
+
*
|
|
149
|
+
* // Controlled
|
|
150
|
+
* const [pw, setPw] = React.useState("")
|
|
151
|
+
* <PasswordStrengthInput
|
|
152
|
+
* value={pw}
|
|
153
|
+
* onChange={(e) => setPw(e.target.value)}
|
|
154
|
+
* autoComplete="new-password"
|
|
155
|
+
* />
|
|
156
|
+
* ```
|
|
157
|
+
*/
|
|
158
|
+
export function PasswordStrengthInput({
|
|
159
|
+
value,
|
|
160
|
+
defaultValue = "",
|
|
161
|
+
onChange,
|
|
162
|
+
strengthFn = defaultStrengthFn,
|
|
163
|
+
segments = 4,
|
|
164
|
+
showLabel = true,
|
|
165
|
+
showHints = false,
|
|
166
|
+
id,
|
|
167
|
+
className,
|
|
168
|
+
"aria-describedby": consumerDescribedBy,
|
|
169
|
+
...props
|
|
170
|
+
}: PasswordStrengthInputProps) {
|
|
171
|
+
const generatedId = React.useId()
|
|
172
|
+
const inputId = id ?? generatedId
|
|
173
|
+
const strengthRegionId = `${inputId}-strength`
|
|
174
|
+
|
|
175
|
+
// Uncontrolled path: track the raw value in local state so strength updates
|
|
176
|
+
// on every keystroke. Controlled path: strength is derived from `value` prop.
|
|
177
|
+
const [internalValue, setInternalValue] = React.useState(
|
|
178
|
+
typeof defaultValue === "string" ? defaultValue : ""
|
|
179
|
+
)
|
|
180
|
+
const isControlled = value !== undefined
|
|
181
|
+
const currentValue = isControlled ? String(value ?? "") : internalValue
|
|
182
|
+
const strength = strengthFn(currentValue)
|
|
183
|
+
const hasInput = currentValue.length > 0
|
|
184
|
+
|
|
185
|
+
function handleChange(e: React.ChangeEvent<HTMLInputElement>) {
|
|
186
|
+
if (!isControlled) setInternalValue(e.target.value)
|
|
187
|
+
onChange?.(e)
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
// Merge caller's aria-describedby with the strength region id.
|
|
191
|
+
const mergedDescribedBy = [
|
|
192
|
+
consumerDescribedBy,
|
|
193
|
+
hasInput ? strengthRegionId : undefined,
|
|
194
|
+
]
|
|
195
|
+
.filter(Boolean)
|
|
196
|
+
.join(" ") || undefined
|
|
197
|
+
|
|
198
|
+
// How many segments should appear filled at this strength level?
|
|
199
|
+
// round((strength / 4) * N) maps 0–4 evenly onto 0–N for any segment count.
|
|
200
|
+
const filledCount = hasInput ? Math.round((strength / 4) * segments) : 0
|
|
201
|
+
|
|
202
|
+
const strengthKey = strength as 1 | 2 | 3 | 4
|
|
203
|
+
const segmentColor =
|
|
204
|
+
hasInput && strength > 0 ? STRENGTH_SEGMENT_BG[strengthKey] : null
|
|
205
|
+
|
|
206
|
+
return (
|
|
207
|
+
<div
|
|
208
|
+
className={cn("flex flex-col gap-1.5", className)}
|
|
209
|
+
data-slot="password-strength-input"
|
|
210
|
+
>
|
|
211
|
+
<PasswordInput
|
|
212
|
+
id={inputId}
|
|
213
|
+
value={isControlled ? value : undefined}
|
|
214
|
+
defaultValue={isControlled ? undefined : (defaultValue as string)}
|
|
215
|
+
onChange={handleChange}
|
|
216
|
+
aria-describedby={mergedDescribedBy}
|
|
217
|
+
{...props}
|
|
218
|
+
/>
|
|
219
|
+
|
|
220
|
+
{/* Segment bar — aria-hidden; the live region below carries the a11y signal */}
|
|
221
|
+
<div
|
|
222
|
+
role="presentation"
|
|
223
|
+
aria-hidden="true"
|
|
224
|
+
className="flex gap-1"
|
|
225
|
+
data-slot="strength-segments"
|
|
226
|
+
>
|
|
227
|
+
{Array.from({ length: segments }, (_, i) => {
|
|
228
|
+
const filled = i < filledCount
|
|
229
|
+
return (
|
|
230
|
+
<div
|
|
231
|
+
key={i}
|
|
232
|
+
data-slot="strength-segment"
|
|
233
|
+
data-filled={filled || undefined}
|
|
234
|
+
className={cn(
|
|
235
|
+
"h-1.5 flex-1 rounded-full",
|
|
236
|
+
filled && segmentColor ? segmentColor : "bg-border"
|
|
237
|
+
)}
|
|
238
|
+
style={segmentMotion}
|
|
239
|
+
/>
|
|
240
|
+
)
|
|
241
|
+
})}
|
|
242
|
+
</div>
|
|
243
|
+
|
|
244
|
+
{/* Strength label + aria-live region */}
|
|
245
|
+
{showLabel && (
|
|
246
|
+
<p
|
|
247
|
+
id={strengthRegionId}
|
|
248
|
+
role="status"
|
|
249
|
+
aria-live="polite"
|
|
250
|
+
aria-atomic="true"
|
|
251
|
+
data-slot="strength-label"
|
|
252
|
+
className={cn(
|
|
253
|
+
"h-[1.25rem] text-sm font-medium leading-none",
|
|
254
|
+
!hasInput || strength === 0
|
|
255
|
+
? "text-transparent select-none"
|
|
256
|
+
: STRENGTH_LABEL_COLOR[strengthKey]
|
|
257
|
+
)}
|
|
258
|
+
>
|
|
259
|
+
{hasInput && strength > 0 ? STRENGTH_LABEL[strengthKey] : " "}
|
|
260
|
+
</p>
|
|
261
|
+
)}
|
|
262
|
+
|
|
263
|
+
{/* Optional requirements hints */}
|
|
264
|
+
{showHints && (
|
|
265
|
+
<ul
|
|
266
|
+
data-slot="strength-hints"
|
|
267
|
+
className="mt-0.5 space-y-1"
|
|
268
|
+
aria-label="Password requirements"
|
|
269
|
+
>
|
|
270
|
+
{PASSWORD_HINTS.map((hint) => (
|
|
271
|
+
<li
|
|
272
|
+
key={hint}
|
|
273
|
+
className="flex items-center gap-2 text-sm text-muted-foreground"
|
|
274
|
+
>
|
|
275
|
+
<span
|
|
276
|
+
className="size-1.5 shrink-0 rounded-full bg-current opacity-30"
|
|
277
|
+
aria-hidden="true"
|
|
278
|
+
/>
|
|
279
|
+
{hint}
|
|
280
|
+
</li>
|
|
281
|
+
))}
|
|
282
|
+
</ul>
|
|
283
|
+
)}
|
|
284
|
+
</div>
|
|
285
|
+
)
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
PasswordStrengthInput.displayName = "PasswordStrengthInput"
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
import * as React from "react"
|
|
2
|
+
import { cva, type VariantProps } from "class-variance-authority"
|
|
3
|
+
|
|
4
|
+
import { cn } from "../../lib/utils"
|
|
5
|
+
|
|
6
|
+
// Pill — compact, non-removable, read-only label.
|
|
7
|
+
//
|
|
8
|
+
// The fourth member of the label family, and the only one with no behavior
|
|
9
|
+
// baked into its API:
|
|
10
|
+
// - Tag → passive label WITH dismiss DNA (onClose) + semantic status
|
|
11
|
+
// variants; takes its text via `label`.
|
|
12
|
+
// - Badge → status/count semantics (primary fill by default,
|
|
13
|
+
// success/warning/info/destructive) and a focus ring for the
|
|
14
|
+
// `asChild` anchor case.
|
|
15
|
+
// - Chip → interactive filter toggle (native button, role=checkbox).
|
|
16
|
+
// - Pill → this. A neutral label for metadata that is neither a status
|
|
17
|
+
// nor an action and can never be removed in place: taxonomy
|
|
18
|
+
// terms, owner names, environment names, counts in a header.
|
|
19
|
+
//
|
|
20
|
+
// Peer parity: Mantine `Pill` (plain span, no role, `disabled` dims only) and
|
|
21
|
+
// Chakra `Tag` without its close trigger. Like both, Pill renders a plain
|
|
22
|
+
// <span> with no ARIA role: a label with no interaction needs none, and a
|
|
23
|
+
// screen reader reads it as inline text in sequence with its neighbours.
|
|
24
|
+
//
|
|
25
|
+
// Motion is pattern (c): `transition-colors` for the property list + inline
|
|
26
|
+
// var(--duration-fast) / var(--ease-out). Pill has no hover state of its own
|
|
27
|
+
// (it is not interactive), so the transition only fires when a consumer
|
|
28
|
+
// re-themes it (variant swap, theme toggle) — but the token-driven duration
|
|
29
|
+
// is still what keeps that repaint consistent with Tag and Badge.
|
|
30
|
+
|
|
31
|
+
const pillVariants = cva(
|
|
32
|
+
[
|
|
33
|
+
// Long-label overflow contract (CLAUDE.md → "Long-label overflow"): the
|
|
34
|
+
// span is the flex parent (max-w-full min-w-0 overflow-hidden); the inner
|
|
35
|
+
// label span truncates. Pills routinely hold runtime strings — user names,
|
|
36
|
+
// slugs, taxonomy terms — that have no word boundaries to wrap at.
|
|
37
|
+
"inline-flex max-w-full min-w-0 shrink-0 items-center overflow-hidden rounded-full border font-medium whitespace-nowrap select-none",
|
|
38
|
+
"transition-colors",
|
|
39
|
+
"data-[disabled]:opacity-50",
|
|
40
|
+
"[&_svg]:pointer-events-none [&_svg]:shrink-0",
|
|
41
|
+
],
|
|
42
|
+
{
|
|
43
|
+
variants: {
|
|
44
|
+
variant: {
|
|
45
|
+
default: "border-transparent bg-secondary text-secondary-foreground",
|
|
46
|
+
outline: "border-border bg-transparent text-foreground",
|
|
47
|
+
muted: "border-transparent bg-muted text-muted-foreground",
|
|
48
|
+
},
|
|
49
|
+
/**
|
|
50
|
+
* Height ladder. sm is the default (Mantine's default register —
|
|
51
|
+
* dense metadata rows, card footers); md matches Tag md / Badge lg for
|
|
52
|
+
* body-copy rows; lg is for header and hero metadata.
|
|
53
|
+
* BADS text-xs = 14px and text-sm = 16px — never below 14px (AAA floor).
|
|
54
|
+
*/
|
|
55
|
+
size: {
|
|
56
|
+
sm: "gap-1 px-2 py-0.5 text-xs [&_svg]:size-3",
|
|
57
|
+
md: "gap-1 px-2.5 py-0.5 text-sm [&_svg]:size-3.5",
|
|
58
|
+
lg: "gap-1.5 px-3 py-1 text-sm [&_svg]:size-4",
|
|
59
|
+
},
|
|
60
|
+
},
|
|
61
|
+
defaultVariants: {
|
|
62
|
+
variant: "default",
|
|
63
|
+
size: "sm",
|
|
64
|
+
},
|
|
65
|
+
}
|
|
66
|
+
)
|
|
67
|
+
|
|
68
|
+
type PillProps = Omit<React.ComponentProps<"span">, "children"> &
|
|
69
|
+
VariantProps<typeof pillVariants> & {
|
|
70
|
+
/**
|
|
71
|
+
* Optional leading element — a Lucide icon (strokeWidth 1.5), a custom
|
|
72
|
+
* SVG, or a small Avatar (`size="xs"`). SVGs are sized per `size`;
|
|
73
|
+
* anything else keeps its own dimensions.
|
|
74
|
+
*/
|
|
75
|
+
icon?: React.ReactNode
|
|
76
|
+
/**
|
|
77
|
+
* Presentational dimming. Pill has no interactive state to disable —
|
|
78
|
+
* this mirrors Mantine's `disabled` and exists so a pill inside a
|
|
79
|
+
* disabled control (a disabled fieldset's selected values, an archived
|
|
80
|
+
* row) dims with it. Sets `data-disabled` only: the owning control is
|
|
81
|
+
* responsible for conveying the disabled state to assistive tech.
|
|
82
|
+
*/
|
|
83
|
+
disabled?: boolean
|
|
84
|
+
/** Visible label text. Keep it to a few words — Pill truncates, it never wraps. */
|
|
85
|
+
children: React.ReactNode
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
function Pill({
|
|
89
|
+
className,
|
|
90
|
+
variant,
|
|
91
|
+
size,
|
|
92
|
+
icon,
|
|
93
|
+
disabled,
|
|
94
|
+
style,
|
|
95
|
+
children,
|
|
96
|
+
...props
|
|
97
|
+
}: PillProps) {
|
|
98
|
+
return (
|
|
99
|
+
<span
|
|
100
|
+
data-slot="pill"
|
|
101
|
+
data-variant={variant ?? "default"}
|
|
102
|
+
data-size={size ?? "sm"}
|
|
103
|
+
data-disabled={disabled ? "" : undefined}
|
|
104
|
+
className={cn(pillVariants({ variant, size }), className)}
|
|
105
|
+
style={{
|
|
106
|
+
transitionDuration: "var(--duration-fast)",
|
|
107
|
+
transitionTimingFunction: "var(--ease-out)",
|
|
108
|
+
...style,
|
|
109
|
+
}}
|
|
110
|
+
{...props}
|
|
111
|
+
>
|
|
112
|
+
{icon != null && (
|
|
113
|
+
<span aria-hidden="true" className="flex shrink-0 items-center [&>svg]:stroke-[1.5]">
|
|
114
|
+
{icon}
|
|
115
|
+
</span>
|
|
116
|
+
)}
|
|
117
|
+
<span className="min-w-0 truncate">{children}</span>
|
|
118
|
+
</span>
|
|
119
|
+
)
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
type PillGroupProps = React.ComponentProps<"div">
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* Wrapping flex row for a set of Pills. Plain <div> — a row of labels is
|
|
126
|
+
* inline text, not a list widget. Pass `aria-label` or `role="list"` only
|
|
127
|
+
* when the group itself is a navigable landmark in the consuming surface.
|
|
128
|
+
*/
|
|
129
|
+
function PillGroup({ className, ...props }: PillGroupProps) {
|
|
130
|
+
return (
|
|
131
|
+
<div
|
|
132
|
+
data-slot="pill-group"
|
|
133
|
+
className={cn("flex flex-wrap items-center gap-1.5", className)}
|
|
134
|
+
{...props}
|
|
135
|
+
/>
|
|
136
|
+
)
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
export { Pill, PillGroup, pillVariants }
|
|
140
|
+
export type { PillProps, PillGroupProps }
|
|
@@ -21,9 +21,23 @@ function PopoverTrigger({
|
|
|
21
21
|
function PopoverContent({
|
|
22
22
|
className,
|
|
23
23
|
align = "center",
|
|
24
|
-
sideOffset
|
|
24
|
+
sideOffset,
|
|
25
|
+
showArrow = false,
|
|
26
|
+
children,
|
|
25
27
|
...props
|
|
26
|
-
}: React.ComponentProps<typeof PopoverPrimitive.Content>
|
|
28
|
+
}: React.ComponentProps<typeof PopoverPrimitive.Content> & {
|
|
29
|
+
/**
|
|
30
|
+
* Renders a directional arrow caret pointing at the trigger. Matches the
|
|
31
|
+
* popover border + background so it reads as an extension of the panel.
|
|
32
|
+
* Peer parity: Mantine Popover arrow, Ant Design Popover arrow, MUI Popper
|
|
33
|
+
* arrow, Chakra UI Popover arrow. Defaults to false (existing behaviour
|
|
34
|
+
* unchanged — byte-identical for consumers that don't set this prop).
|
|
35
|
+
*/
|
|
36
|
+
showArrow?: boolean
|
|
37
|
+
}) {
|
|
38
|
+
// When showArrow is true, add extra sideOffset to accommodate the arrow height
|
|
39
|
+
// so the panel doesn't overlap the trigger element.
|
|
40
|
+
const resolvedSideOffset = sideOffset ?? (showArrow ? 8 : 4)
|
|
27
41
|
// See use-portal-theme-class.ts: lets a PortalThemeProvider scope class
|
|
28
42
|
// (e.g. "atrium-theme") apply to portal content so theme-scoped CSS
|
|
29
43
|
// variables resolve inside the portal.
|
|
@@ -33,14 +47,23 @@ function PopoverContent({
|
|
|
33
47
|
<PopoverPrimitive.Content
|
|
34
48
|
data-slot="popover-content"
|
|
35
49
|
align={align}
|
|
36
|
-
sideOffset={
|
|
50
|
+
sideOffset={resolvedSideOffset}
|
|
37
51
|
className={cn(
|
|
38
52
|
"z-50 w-72 origin-(--radix-popover-content-transform-origin) rounded-md border bg-popover p-4 text-popover-foreground shadow-md outline-hidden data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95 data-[state=open]:animate-in data-[state=open]:fade-in-0 data-[state=open]:zoom-in-95",
|
|
39
53
|
portalThemeClass,
|
|
40
54
|
className
|
|
41
55
|
)}
|
|
42
56
|
{...props}
|
|
43
|
-
|
|
57
|
+
>
|
|
58
|
+
{children}
|
|
59
|
+
{showArrow && (
|
|
60
|
+
<PopoverPrimitive.Arrow
|
|
61
|
+
width={11}
|
|
62
|
+
height={5.5}
|
|
63
|
+
className="fill-popover [filter:drop-shadow(0_1.5px_0_var(--border))]"
|
|
64
|
+
/>
|
|
65
|
+
)}
|
|
66
|
+
</PopoverPrimitive.Content>
|
|
44
67
|
</PopoverPrimitive.Portal>
|
|
45
68
|
)
|
|
46
69
|
}
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
"use client"
|
|
2
|
+
|
|
3
|
+
import * as React from "react"
|
|
4
|
+
import { cn } from "../../lib/utils"
|
|
5
|
+
|
|
6
|
+
export interface ScrollProgressProps {
|
|
7
|
+
/**
|
|
8
|
+
* Element to track scroll progress for.
|
|
9
|
+
* When omitted, tracks the window (document scroll).
|
|
10
|
+
*/
|
|
11
|
+
containerRef?: React.RefObject<HTMLElement | null>
|
|
12
|
+
/**
|
|
13
|
+
* Where to render the bar. "page" = fixed at top of viewport (default for
|
|
14
|
+
* window tracking). "sticky" = sticky inside a scrolling container.
|
|
15
|
+
* "inline" = renders in flow — position it yourself.
|
|
16
|
+
*/
|
|
17
|
+
position?: "fixed" | "sticky" | "inline"
|
|
18
|
+
/** Override the bar height. Default "2px". */
|
|
19
|
+
height?: string
|
|
20
|
+
/** Override the filled color. Default `var(--primary)`. */
|
|
21
|
+
color?: string
|
|
22
|
+
/** Override the track (background) color. Default `var(--border)`. */
|
|
23
|
+
trackColor?: string
|
|
24
|
+
className?: string
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Scroll-position progress indicator. Shows how far the user has scrolled
|
|
29
|
+
* through the tracked element or the whole page as a thin colored bar.
|
|
30
|
+
*
|
|
31
|
+
* Sources: GitHub PR scroll indicator, Mantine ScrollProgress RFC, shadcn
|
|
32
|
+
* community recipe (2026-Q3), Next.js nprogress-style indicators.
|
|
33
|
+
*
|
|
34
|
+
* Reduced-motion: the bar updates immediately without any `transition`
|
|
35
|
+
* (the base layer's 0.01ms override would silently fire here anyway).
|
|
36
|
+
*/
|
|
37
|
+
function ScrollProgress({
|
|
38
|
+
containerRef,
|
|
39
|
+
position = "fixed",
|
|
40
|
+
height = "2px",
|
|
41
|
+
color,
|
|
42
|
+
trackColor,
|
|
43
|
+
className,
|
|
44
|
+
}: ScrollProgressProps) {
|
|
45
|
+
const [progress, setProgress] = React.useState(0)
|
|
46
|
+
|
|
47
|
+
React.useEffect(() => {
|
|
48
|
+
function calculate() {
|
|
49
|
+
if (containerRef?.current) {
|
|
50
|
+
const el = containerRef.current
|
|
51
|
+
const scrollTop = el.scrollTop
|
|
52
|
+
const scrollHeight = el.scrollHeight - el.clientHeight
|
|
53
|
+
setProgress(scrollHeight > 0 ? (scrollTop / scrollHeight) * 100 : 0)
|
|
54
|
+
} else {
|
|
55
|
+
const scrollTop = window.scrollY || document.documentElement.scrollTop
|
|
56
|
+
const docHeight =
|
|
57
|
+
document.documentElement.scrollHeight -
|
|
58
|
+
document.documentElement.clientHeight
|
|
59
|
+
setProgress(docHeight > 0 ? (scrollTop / docHeight) * 100 : 0)
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
const target = containerRef?.current ?? window
|
|
64
|
+
target.addEventListener("scroll", calculate, { passive: true })
|
|
65
|
+
calculate()
|
|
66
|
+
return () => target.removeEventListener("scroll", calculate)
|
|
67
|
+
}, [containerRef])
|
|
68
|
+
|
|
69
|
+
return (
|
|
70
|
+
<div
|
|
71
|
+
data-slot="scroll-progress"
|
|
72
|
+
role="progressbar"
|
|
73
|
+
aria-label="Page scroll progress"
|
|
74
|
+
aria-valuenow={Math.round(progress)}
|
|
75
|
+
aria-valuemin={0}
|
|
76
|
+
aria-valuemax={100}
|
|
77
|
+
className={cn(
|
|
78
|
+
"left-0 top-0 w-full overflow-hidden",
|
|
79
|
+
position === "fixed" && "fixed z-50",
|
|
80
|
+
position === "sticky" && "sticky z-10",
|
|
81
|
+
position === "inline" && "relative",
|
|
82
|
+
className
|
|
83
|
+
)}
|
|
84
|
+
style={{
|
|
85
|
+
height,
|
|
86
|
+
backgroundColor: trackColor ?? "var(--border)",
|
|
87
|
+
}}
|
|
88
|
+
>
|
|
89
|
+
<div
|
|
90
|
+
className="h-full"
|
|
91
|
+
style={{
|
|
92
|
+
width: `${progress}%`,
|
|
93
|
+
backgroundColor: color ?? "var(--primary)",
|
|
94
|
+
}}
|
|
95
|
+
/>
|
|
96
|
+
</div>
|
|
97
|
+
)
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
export { ScrollProgress }
|