@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,381 @@
|
|
|
1
|
+
"use client"
|
|
2
|
+
|
|
3
|
+
import * as React from "react"
|
|
4
|
+
import { Eraser, Undo2 } from "lucide-react"
|
|
5
|
+
|
|
6
|
+
import { cn } from "../../lib/utils"
|
|
7
|
+
import { Button } from "./button"
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* SignaturePad — canvas-based freehand drawing input for capturing
|
|
11
|
+
* handwritten signatures (legal onboarding, consent forms, medical intake,
|
|
12
|
+
* e-signing). Ground-up React canvas primitive (Radix has no equivalent;
|
|
13
|
+
* cross-referenced against Ark UI / Chakra v3 SignaturePad).
|
|
14
|
+
*
|
|
15
|
+
* Token discipline: the default ink is the computed `--foreground`, resolved
|
|
16
|
+
* from the canvas element via `getComputedStyle` at draw time (canvas 2D
|
|
17
|
+
* `strokeStyle` cannot consume `var()` expressions, and BADS tokens are raw
|
|
18
|
+
* `oklch(...)` values — an unresolved var would silently paint black). Same
|
|
19
|
+
* computed-style pattern as Watermark's ink. A MutationObserver on `<html>`'s
|
|
20
|
+
* class redraws existing strokes on light/dark flip so the signature stays
|
|
21
|
+
* theme-correct. Exports are made opaque by filling the computed
|
|
22
|
+
* `--background` (or the `backgroundColor` prop) before serializing, so
|
|
23
|
+
* PNG/JPEG data URLs don't come out transparent or black.
|
|
24
|
+
*
|
|
25
|
+
* Ethics note: a handwritten signature is a biometric-analog. The component
|
|
26
|
+
* holds strokes in memory only — persistence, transmission, and retention are
|
|
27
|
+
* entirely the caller's responsibility (see the registry ethicsContract).
|
|
28
|
+
*/
|
|
29
|
+
|
|
30
|
+
type Point = { x: number; y: number }
|
|
31
|
+
|
|
32
|
+
export type SignaturePadHandle = {
|
|
33
|
+
/** Remove every stroke and announce "Signature cleared". */
|
|
34
|
+
clear: () => void
|
|
35
|
+
/** Remove the most recent stroke. */
|
|
36
|
+
undo: () => void
|
|
37
|
+
/** True when no strokes have been drawn. */
|
|
38
|
+
isEmpty: () => boolean
|
|
39
|
+
/**
|
|
40
|
+
* Export the signature as a data URL (default `image/png`). The background
|
|
41
|
+
* is filled opaque (computed `--background`, or the `backgroundColor` prop
|
|
42
|
+
* when set) before serializing.
|
|
43
|
+
*/
|
|
44
|
+
toDataURL: (type?: string) => string
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export type SignaturePadProps = Omit<
|
|
48
|
+
React.ComponentPropsWithoutRef<"div">,
|
|
49
|
+
"onPointerDown" | "onPointerMove" | "onPointerUp" | "onPointerCancel"
|
|
50
|
+
> & {
|
|
51
|
+
/**
|
|
52
|
+
* Stroke ink. Default `"var(--foreground)"` — a `var(--x)` expression is
|
|
53
|
+
* resolved against the canvas's computed style at draw time, so forks'
|
|
54
|
+
* re-theming and light/dark both apply. Any concrete CSS color string
|
|
55
|
+
* passes through untouched.
|
|
56
|
+
*/
|
|
57
|
+
penColor?: string
|
|
58
|
+
/** Stroke width in CSS px (device-pixel-ratio scaling is internal). Default 2. */
|
|
59
|
+
penWidth?: number
|
|
60
|
+
/**
|
|
61
|
+
* On-screen canvas fill. Default `"transparent"` (the wrapper's
|
|
62
|
+
* `bg-background` shows through). Exports always get an opaque fill.
|
|
63
|
+
*/
|
|
64
|
+
backgroundColor?: string
|
|
65
|
+
/** Fires when a stroke completes, with the current opaque data URL. */
|
|
66
|
+
onEnd?: (dataUrl: string) => void
|
|
67
|
+
/** Disables drawing and the Clear/Undo controls. */
|
|
68
|
+
disabled?: boolean
|
|
69
|
+
/** Accessible name for the drawing surface. */
|
|
70
|
+
"aria-label"?: string
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
const SignaturePad = React.forwardRef<SignaturePadHandle, SignaturePadProps>(
|
|
74
|
+
function SignaturePad(
|
|
75
|
+
{
|
|
76
|
+
penColor = "var(--foreground)",
|
|
77
|
+
penWidth = 2,
|
|
78
|
+
backgroundColor = "transparent",
|
|
79
|
+
onEnd,
|
|
80
|
+
disabled = false,
|
|
81
|
+
className,
|
|
82
|
+
"aria-label": ariaLabel = "Signature pad — draw your signature",
|
|
83
|
+
...props
|
|
84
|
+
},
|
|
85
|
+
ref
|
|
86
|
+
) {
|
|
87
|
+
const canvasRef = React.useRef<HTMLCanvasElement>(null)
|
|
88
|
+
// Stroke history lives in refs — pointermove must never re-render.
|
|
89
|
+
const strokesRef = React.useRef<Point[][]>([])
|
|
90
|
+
const isDrawingRef = React.useRef(false)
|
|
91
|
+
// State only changes once per completed action (stroke end / undo /
|
|
92
|
+
// clear), driving the hint fade, control disabled states, and the
|
|
93
|
+
// aria-live announcement.
|
|
94
|
+
const [strokeCount, setStrokeCount] = React.useState(0)
|
|
95
|
+
const [announcement, setAnnouncement] = React.useState("")
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* Resolve the ink to a concrete color the canvas API accepts. The canvas
|
|
99
|
+
* carries `text-foreground`, so `computed.color` is the token fallback.
|
|
100
|
+
*/
|
|
101
|
+
const resolveInk = React.useCallback(() => {
|
|
102
|
+
const canvas = canvasRef.current
|
|
103
|
+
if (!canvas) return ""
|
|
104
|
+
const computed = getComputedStyle(canvas)
|
|
105
|
+
const varMatch = /^var\((--[\w-]+)\)$/.exec(penColor.trim())
|
|
106
|
+
if (varMatch) {
|
|
107
|
+
return computed.getPropertyValue(varMatch[1]).trim() || computed.color
|
|
108
|
+
}
|
|
109
|
+
return penColor
|
|
110
|
+
}, [penColor])
|
|
111
|
+
|
|
112
|
+
/** Prepare a 2D context in CSS-pixel coordinates with the pen applied. */
|
|
113
|
+
const getContext = React.useCallback(() => {
|
|
114
|
+
const canvas = canvasRef.current
|
|
115
|
+
if (!canvas) return null
|
|
116
|
+
const ctx = canvas.getContext("2d")
|
|
117
|
+
if (!ctx) return null
|
|
118
|
+
const dpr = window.devicePixelRatio || 1
|
|
119
|
+
ctx.setTransform(dpr, 0, 0, dpr, 0, 0)
|
|
120
|
+
ctx.lineJoin = "round"
|
|
121
|
+
ctx.lineCap = "round"
|
|
122
|
+
ctx.lineWidth = penWidth
|
|
123
|
+
ctx.strokeStyle = resolveInk()
|
|
124
|
+
return ctx
|
|
125
|
+
}, [penWidth, resolveInk])
|
|
126
|
+
|
|
127
|
+
/** Full replay of the stroke history (resize, undo, theme flip). */
|
|
128
|
+
const redraw = React.useCallback(() => {
|
|
129
|
+
const canvas = canvasRef.current
|
|
130
|
+
const ctx = getContext()
|
|
131
|
+
if (!canvas || !ctx) return
|
|
132
|
+
const rect = canvas.getBoundingClientRect()
|
|
133
|
+
ctx.clearRect(0, 0, rect.width, rect.height)
|
|
134
|
+
if (backgroundColor !== "transparent") {
|
|
135
|
+
ctx.fillStyle = backgroundColor
|
|
136
|
+
ctx.fillRect(0, 0, rect.width, rect.height)
|
|
137
|
+
}
|
|
138
|
+
for (const stroke of strokesRef.current) {
|
|
139
|
+
if (stroke.length === 0) continue
|
|
140
|
+
ctx.beginPath()
|
|
141
|
+
ctx.moveTo(stroke[0].x, stroke[0].y)
|
|
142
|
+
for (let i = 1; i < stroke.length; i++) {
|
|
143
|
+
ctx.lineTo(stroke[i].x, stroke[i].y)
|
|
144
|
+
}
|
|
145
|
+
if (stroke.length === 1) {
|
|
146
|
+
// A tap leaves a dot — round caps need a zero-length segment.
|
|
147
|
+
ctx.lineTo(stroke[0].x, stroke[0].y)
|
|
148
|
+
}
|
|
149
|
+
ctx.stroke()
|
|
150
|
+
}
|
|
151
|
+
}, [backgroundColor, getContext])
|
|
152
|
+
|
|
153
|
+
// Size the backing store at devicePixelRatio so strokes stay crisp, and
|
|
154
|
+
// replay history whenever the element resizes.
|
|
155
|
+
React.useEffect(() => {
|
|
156
|
+
const canvas = canvasRef.current
|
|
157
|
+
if (!canvas) return
|
|
158
|
+
const resize = () => {
|
|
159
|
+
const dpr = window.devicePixelRatio || 1
|
|
160
|
+
const rect = canvas.getBoundingClientRect()
|
|
161
|
+
const width = Math.max(1, Math.round(rect.width * dpr))
|
|
162
|
+
const height = Math.max(1, Math.round(rect.height * dpr))
|
|
163
|
+
if (canvas.width !== width || canvas.height !== height) {
|
|
164
|
+
canvas.width = width
|
|
165
|
+
canvas.height = height
|
|
166
|
+
}
|
|
167
|
+
redraw()
|
|
168
|
+
}
|
|
169
|
+
resize()
|
|
170
|
+
const observer = new ResizeObserver(resize)
|
|
171
|
+
observer.observe(canvas)
|
|
172
|
+
return () => observer.disconnect()
|
|
173
|
+
}, [redraw])
|
|
174
|
+
|
|
175
|
+
// Theme flip: the computed --foreground ink changes with <html>'s class,
|
|
176
|
+
// so replay existing strokes in the new theme's ink.
|
|
177
|
+
React.useEffect(() => {
|
|
178
|
+
const observer = new MutationObserver(redraw)
|
|
179
|
+
observer.observe(document.documentElement, {
|
|
180
|
+
attributes: true,
|
|
181
|
+
attributeFilter: ["class"],
|
|
182
|
+
})
|
|
183
|
+
return () => observer.disconnect()
|
|
184
|
+
}, [redraw])
|
|
185
|
+
|
|
186
|
+
/** Opaque export — transparent canvases serialize black in JPEG. */
|
|
187
|
+
const exportDataURL = React.useCallback(
|
|
188
|
+
(type?: string) => {
|
|
189
|
+
const canvas = canvasRef.current
|
|
190
|
+
if (!canvas) return ""
|
|
191
|
+
const out = document.createElement("canvas")
|
|
192
|
+
out.width = canvas.width
|
|
193
|
+
out.height = canvas.height
|
|
194
|
+
const ctx = out.getContext("2d")
|
|
195
|
+
if (!ctx) return ""
|
|
196
|
+
const computed = getComputedStyle(canvas)
|
|
197
|
+
const fill =
|
|
198
|
+
backgroundColor !== "transparent"
|
|
199
|
+
? backgroundColor
|
|
200
|
+
: computed.getPropertyValue("--background").trim() ||
|
|
201
|
+
computed.backgroundColor
|
|
202
|
+
ctx.fillStyle = fill
|
|
203
|
+
ctx.fillRect(0, 0, out.width, out.height)
|
|
204
|
+
ctx.drawImage(canvas, 0, 0)
|
|
205
|
+
return out.toDataURL(type)
|
|
206
|
+
},
|
|
207
|
+
[backgroundColor]
|
|
208
|
+
)
|
|
209
|
+
|
|
210
|
+
const clear = React.useCallback(() => {
|
|
211
|
+
strokesRef.current = []
|
|
212
|
+
redraw()
|
|
213
|
+
setStrokeCount(0)
|
|
214
|
+
setAnnouncement("Signature cleared")
|
|
215
|
+
}, [redraw])
|
|
216
|
+
|
|
217
|
+
const undo = React.useCallback(() => {
|
|
218
|
+
if (strokesRef.current.length === 0) return
|
|
219
|
+
strokesRef.current = strokesRef.current.slice(0, -1)
|
|
220
|
+
redraw()
|
|
221
|
+
const remaining = strokesRef.current.length
|
|
222
|
+
setStrokeCount(remaining)
|
|
223
|
+
setAnnouncement(remaining === 0 ? "Signature cleared" : "Last stroke removed")
|
|
224
|
+
}, [redraw])
|
|
225
|
+
|
|
226
|
+
React.useImperativeHandle(
|
|
227
|
+
ref,
|
|
228
|
+
() => ({
|
|
229
|
+
clear,
|
|
230
|
+
undo,
|
|
231
|
+
isEmpty: () => strokesRef.current.length === 0,
|
|
232
|
+
toDataURL: (type?: string) => exportDataURL(type),
|
|
233
|
+
}),
|
|
234
|
+
[clear, undo, exportDataURL]
|
|
235
|
+
)
|
|
236
|
+
|
|
237
|
+
const pointFromEvent = (event: React.PointerEvent<HTMLCanvasElement>): Point => {
|
|
238
|
+
const rect = event.currentTarget.getBoundingClientRect()
|
|
239
|
+
return { x: event.clientX - rect.left, y: event.clientY - rect.top }
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
const handlePointerDown = (event: React.PointerEvent<HTMLCanvasElement>) => {
|
|
243
|
+
if (disabled) return
|
|
244
|
+
if (event.pointerType === "mouse" && event.button !== 0) return
|
|
245
|
+
// Capture routes every subsequent pointer event here, even off-element —
|
|
246
|
+
// covers mouse, touch, and pen with one code path.
|
|
247
|
+
event.currentTarget.setPointerCapture(event.pointerId)
|
|
248
|
+
isDrawingRef.current = true
|
|
249
|
+
const point = pointFromEvent(event)
|
|
250
|
+
strokesRef.current = [...strokesRef.current, [point]]
|
|
251
|
+
const ctx = getContext()
|
|
252
|
+
if (ctx) {
|
|
253
|
+
ctx.beginPath()
|
|
254
|
+
ctx.moveTo(point.x, point.y)
|
|
255
|
+
ctx.lineTo(point.x, point.y)
|
|
256
|
+
ctx.stroke()
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
const handlePointerMove = (event: React.PointerEvent<HTMLCanvasElement>) => {
|
|
261
|
+
if (!isDrawingRef.current) return
|
|
262
|
+
const strokes = strokesRef.current
|
|
263
|
+
const stroke = strokes[strokes.length - 1]
|
|
264
|
+
const previous = stroke[stroke.length - 1]
|
|
265
|
+
const point = pointFromEvent(event)
|
|
266
|
+
stroke.push(point)
|
|
267
|
+
// Incremental segment — no full replay per move.
|
|
268
|
+
const ctx = getContext()
|
|
269
|
+
if (ctx) {
|
|
270
|
+
ctx.beginPath()
|
|
271
|
+
ctx.moveTo(previous.x, previous.y)
|
|
272
|
+
ctx.lineTo(point.x, point.y)
|
|
273
|
+
ctx.stroke()
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
const endStroke = (event: React.PointerEvent<HTMLCanvasElement>) => {
|
|
278
|
+
if (!isDrawingRef.current) return
|
|
279
|
+
isDrawingRef.current = false
|
|
280
|
+
if (event.currentTarget.hasPointerCapture(event.pointerId)) {
|
|
281
|
+
event.currentTarget.releasePointerCapture(event.pointerId)
|
|
282
|
+
}
|
|
283
|
+
setStrokeCount(strokesRef.current.length)
|
|
284
|
+
setAnnouncement("Signature captured")
|
|
285
|
+
onEnd?.(exportDataURL())
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
return (
|
|
289
|
+
<div
|
|
290
|
+
data-slot="signature-pad"
|
|
291
|
+
className={cn(
|
|
292
|
+
"flex w-full flex-col gap-3 rounded-lg border bg-background p-3",
|
|
293
|
+
className
|
|
294
|
+
)}
|
|
295
|
+
{...props}
|
|
296
|
+
>
|
|
297
|
+
<div className="relative">
|
|
298
|
+
<canvas
|
|
299
|
+
ref={canvasRef}
|
|
300
|
+
data-slot="signature-canvas"
|
|
301
|
+
role="img"
|
|
302
|
+
aria-label={ariaLabel}
|
|
303
|
+
tabIndex={disabled ? -1 : 0}
|
|
304
|
+
aria-disabled={disabled || undefined}
|
|
305
|
+
className={cn(
|
|
306
|
+
// touch-none: drawing must not scroll the page on touch devices.
|
|
307
|
+
// text-foreground feeds resolveInk's computed-color fallback.
|
|
308
|
+
"block h-40 w-full cursor-crosshair touch-none rounded-md border border-input bg-transparent text-foreground outline-none",
|
|
309
|
+
"focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/50",
|
|
310
|
+
disabled && "pointer-events-none cursor-default opacity-50"
|
|
311
|
+
)}
|
|
312
|
+
onPointerDown={handlePointerDown}
|
|
313
|
+
onPointerMove={handlePointerMove}
|
|
314
|
+
onPointerUp={endStroke}
|
|
315
|
+
onPointerCancel={endStroke}
|
|
316
|
+
/>
|
|
317
|
+
{/* Empty-state hint. Decorative (aria-hidden) — the canvas's
|
|
318
|
+
aria-label carries the instruction for AT. Fades out on the
|
|
319
|
+
first stroke via token-driven motion (pattern c). */}
|
|
320
|
+
<div
|
|
321
|
+
aria-hidden="true"
|
|
322
|
+
className={cn(
|
|
323
|
+
"pointer-events-none absolute inset-x-8 bottom-8 select-none border-b border-dashed border-muted-foreground/40 pb-1 text-center text-sm text-muted-foreground transition-opacity",
|
|
324
|
+
strokeCount > 0 ? "opacity-0" : "opacity-100"
|
|
325
|
+
)}
|
|
326
|
+
style={{
|
|
327
|
+
transitionDuration: "var(--duration-fast)",
|
|
328
|
+
transitionTimingFunction: "var(--ease-out)",
|
|
329
|
+
}}
|
|
330
|
+
>
|
|
331
|
+
Sign here
|
|
332
|
+
</div>
|
|
333
|
+
</div>
|
|
334
|
+
<div
|
|
335
|
+
data-slot="signature-controls"
|
|
336
|
+
className="flex items-center justify-end gap-2 text-muted-foreground"
|
|
337
|
+
>
|
|
338
|
+
{/* Keyboard-operable bypass for the pointer-only surface: every
|
|
339
|
+
corrective action is reachable by Tab + Enter/Space. icon-xl =
|
|
340
|
+
44×44px (SC 2.5.5 Enhanced). */}
|
|
341
|
+
<Button
|
|
342
|
+
type="button"
|
|
343
|
+
variant="outline"
|
|
344
|
+
size="icon-xl"
|
|
345
|
+
aria-label="Undo last stroke"
|
|
346
|
+
disabled={disabled || strokeCount === 0}
|
|
347
|
+
onClick={undo}
|
|
348
|
+
className="transition-colors"
|
|
349
|
+
style={{
|
|
350
|
+
transitionDuration: "var(--duration-fast)",
|
|
351
|
+
transitionTimingFunction: "var(--ease-out)",
|
|
352
|
+
}}
|
|
353
|
+
>
|
|
354
|
+
<Undo2 strokeWidth={1.5} aria-hidden="true" />
|
|
355
|
+
</Button>
|
|
356
|
+
<Button
|
|
357
|
+
type="button"
|
|
358
|
+
variant="outline"
|
|
359
|
+
size="icon-xl"
|
|
360
|
+
aria-label="Clear signature"
|
|
361
|
+
disabled={disabled || strokeCount === 0}
|
|
362
|
+
onClick={clear}
|
|
363
|
+
className="transition-colors"
|
|
364
|
+
style={{
|
|
365
|
+
transitionDuration: "var(--duration-fast)",
|
|
366
|
+
transitionTimingFunction: "var(--ease-out)",
|
|
367
|
+
}}
|
|
368
|
+
>
|
|
369
|
+
<Eraser strokeWidth={1.5} aria-hidden="true" />
|
|
370
|
+
</Button>
|
|
371
|
+
</div>
|
|
372
|
+
{/* State changes announce without moving focus. */}
|
|
373
|
+
<span className="sr-only" aria-live="polite" aria-atomic="true">
|
|
374
|
+
{announcement}
|
|
375
|
+
</span>
|
|
376
|
+
</div>
|
|
377
|
+
)
|
|
378
|
+
}
|
|
379
|
+
)
|
|
380
|
+
|
|
381
|
+
export { SignaturePad }
|
|
@@ -1,10 +1,67 @@
|
|
|
1
1
|
import { cn } from "../../lib/utils"
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
type SkeletonProps = React.ComponentProps<"div"> & {
|
|
4
|
+
/**
|
|
5
|
+
* Placeholder silhouette. `default` is the classic rounded block,
|
|
6
|
+
* `circle` matches an avatar (default `size-10`, override via className),
|
|
7
|
+
* `text` is a single text line (default `h-4 w-full`).
|
|
8
|
+
* Mirrors Avatar's `shape` prop vocabulary.
|
|
9
|
+
*/
|
|
10
|
+
shape?: "default" | "circle" | "text"
|
|
11
|
+
/**
|
|
12
|
+
* Text shape only. `lines >= 2` renders a stacked column of text lines
|
|
13
|
+
* with the last line at 60% width (the "paragraph loading" pattern).
|
|
14
|
+
* Ignored for other shapes; `<= 1` renders a single text line.
|
|
15
|
+
*/
|
|
16
|
+
lines?: number
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
const shapeClasses = {
|
|
20
|
+
// The default class string MUST stay byte-identical to the pre-variant
|
|
21
|
+
// primitive so a bare <Skeleton /> renders exactly as before (Tier-4
|
|
22
|
+
// additive contract) — don't reorder or split it.
|
|
23
|
+
default: "animate-pulse rounded-md bg-accent",
|
|
24
|
+
circle: "animate-pulse rounded-full bg-accent size-10",
|
|
25
|
+
text: "animate-pulse rounded-md bg-accent h-4 w-full",
|
|
26
|
+
} as const
|
|
27
|
+
|
|
28
|
+
function Skeleton({
|
|
29
|
+
className,
|
|
30
|
+
shape = "default",
|
|
31
|
+
lines,
|
|
32
|
+
...props
|
|
33
|
+
}: SkeletonProps) {
|
|
34
|
+
const lineCount =
|
|
35
|
+
shape === "text" && typeof lines === "number" && lines >= 2
|
|
36
|
+
? Math.floor(lines)
|
|
37
|
+
: 0
|
|
38
|
+
|
|
39
|
+
if (lineCount) {
|
|
40
|
+
return (
|
|
41
|
+
<div
|
|
42
|
+
data-slot="skeleton"
|
|
43
|
+
data-shape="text"
|
|
44
|
+
className={cn("flex w-full flex-col gap-2", className)}
|
|
45
|
+
{...props}
|
|
46
|
+
>
|
|
47
|
+
{Array.from({ length: lineCount }, (_, i) => (
|
|
48
|
+
<div
|
|
49
|
+
key={i}
|
|
50
|
+
data-slot="skeleton-line"
|
|
51
|
+
className={cn(shapeClasses.text, i === lineCount - 1 && "w-3/5")}
|
|
52
|
+
/>
|
|
53
|
+
))}
|
|
54
|
+
</div>
|
|
55
|
+
)
|
|
56
|
+
}
|
|
57
|
+
|
|
4
58
|
return (
|
|
5
59
|
<div
|
|
6
60
|
data-slot="skeleton"
|
|
7
|
-
|
|
61
|
+
// data-shape is omitted for the default shape so a bare <Skeleton />
|
|
62
|
+
// stays byte-identical to the pre-variant render.
|
|
63
|
+
data-shape={shape === "default" ? undefined : shape}
|
|
64
|
+
className={cn(shapeClasses[shape], className)}
|
|
8
65
|
{...props}
|
|
9
66
|
/>
|
|
10
67
|
)
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
"use client"
|
|
2
|
+
|
|
3
|
+
import * as React from "react"
|
|
4
|
+
|
|
5
|
+
import { cn } from "../../lib/utils"
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* SkipLink + SkipTarget — WCAG 2.4.1 (Bypass Blocks). A visually hidden
|
|
9
|
+
* link rendered as the FIRST focusable element on the page; the first Tab
|
|
10
|
+
* press reveals it, and activating it jumps keyboard and screen-reader
|
|
11
|
+
* focus past the repeated chrome (header, sidebar, nav) straight to the
|
|
12
|
+
* main content. Modeled on Chakra's skip-nav pair.
|
|
13
|
+
*
|
|
14
|
+
* <body>
|
|
15
|
+
* <SkipLink href="#main-content" />
|
|
16
|
+
* <SiteHeader /> <Sidebar />
|
|
17
|
+
* <SkipTarget id="main-content" />
|
|
18
|
+
* <main>…</main>
|
|
19
|
+
* </body>
|
|
20
|
+
*
|
|
21
|
+
* Visibility contract: `sr-only` at rest — clipped to 1px, still in the tab
|
|
22
|
+
* order and the accessibility tree. On `:focus` it un-clips to a fixed
|
|
23
|
+
* top-left pill styled like the BADS Button primary (bg-primary,
|
|
24
|
+
* text-primary-foreground, `min-h-11` 44px target, focus ring). `:focus`
|
|
25
|
+
* (not `:focus-visible`) is deliberate: an sr-only element can only be
|
|
26
|
+
* reached by keyboard or AT, so there is no mouse-focus case to suppress —
|
|
27
|
+
* and screen-reader focus does not always set `:focus-visible`.
|
|
28
|
+
*
|
|
29
|
+
* Focus handoff: the href jump is native (`<a href="#id">`), so it works
|
|
30
|
+
* without JavaScript. On click the link ALSO calls `.focus()` on the target
|
|
31
|
+
* — some browsers historically moved only the scroll position, not
|
|
32
|
+
* sequential focus, which silently defeats the skip. `SkipTarget` carries
|
|
33
|
+
* `tabIndex={-1}` so it can receive that programmatic focus without ever
|
|
34
|
+
* being a Tab stop of its own (an invisible Tab stop would strand keyboard
|
|
35
|
+
* users — see VisuallyHidden's warning).
|
|
36
|
+
*
|
|
37
|
+
* Motion note: the reveal is intentionally NOT animated — a focus indicator
|
|
38
|
+
* must appear instantly (SC 2.4.7; same reason `transition-all` is banned
|
|
39
|
+
* for fading focus rings in). The only transition is hover bg on the
|
|
40
|
+
* revealed pill, on the motion tokens.
|
|
41
|
+
*/
|
|
42
|
+
|
|
43
|
+
export interface SkipLinkProps extends Omit<React.ComponentProps<"a">, "href"> {
|
|
44
|
+
/** Fragment href of the SkipTarget to jump to, e.g. `"#main-content"`. */
|
|
45
|
+
href: string
|
|
46
|
+
/** Link text. Default "Skip to content". */
|
|
47
|
+
children?: React.ReactNode
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
function SkipLink({
|
|
51
|
+
href,
|
|
52
|
+
children = "Skip to content",
|
|
53
|
+
className,
|
|
54
|
+
onClick,
|
|
55
|
+
...props
|
|
56
|
+
}: SkipLinkProps) {
|
|
57
|
+
return (
|
|
58
|
+
<a
|
|
59
|
+
data-slot="skip-link"
|
|
60
|
+
href={href}
|
|
61
|
+
className={cn(
|
|
62
|
+
// Rest state: clipped but focusable — first thing Tab reaches.
|
|
63
|
+
"sr-only",
|
|
64
|
+
// Focused: un-clip to a fixed top-left pill above all app chrome.
|
|
65
|
+
"focus:not-sr-only focus:fixed focus:top-4 focus:left-4 focus:z-50",
|
|
66
|
+
// BADS Button-primary appearance + the 44px CTA floor.
|
|
67
|
+
"focus:inline-flex focus:min-h-11 focus:items-center focus:justify-center focus:rounded-md focus:bg-primary focus:px-5 focus:text-sm focus:font-medium focus:text-primary-foreground focus:shadow-md",
|
|
68
|
+
// Ring instead of default outline; hover shade for mouse users who
|
|
69
|
+
// click the revealed pill while it holds focus.
|
|
70
|
+
"outline-none transition-colors focus:ring-[3px] focus:ring-ring/50 hover:focus:bg-primary/90",
|
|
71
|
+
className
|
|
72
|
+
)}
|
|
73
|
+
style={{
|
|
74
|
+
transitionDuration: "var(--duration-fast)",
|
|
75
|
+
transitionTimingFunction: "var(--ease-out)",
|
|
76
|
+
}}
|
|
77
|
+
onClick={(event) => {
|
|
78
|
+
onClick?.(event)
|
|
79
|
+
if (event.defaultPrevented) return
|
|
80
|
+
const id = href.startsWith("#") ? href.slice(1) : null
|
|
81
|
+
if (!id) return
|
|
82
|
+
// Belt-and-suspenders: guarantee sequential focus moves too, not
|
|
83
|
+
// just the scroll position (see component doc).
|
|
84
|
+
document.getElementById(id)?.focus()
|
|
85
|
+
}}
|
|
86
|
+
{...props}
|
|
87
|
+
>
|
|
88
|
+
{children}
|
|
89
|
+
</a>
|
|
90
|
+
)
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
export interface SkipTargetProps extends React.ComponentProps<"div"> {
|
|
94
|
+
/** The id the paired SkipLink's href points at. */
|
|
95
|
+
id: string
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* The landing point for a SkipLink. Renders visually hidden (`sr-only`) and
|
|
100
|
+
* out of the Tab order (`tabIndex={-1}`), existing only to receive the
|
|
101
|
+
* programmatic focus jump. Place it immediately before the main content.
|
|
102
|
+
*/
|
|
103
|
+
function SkipTarget({ id, className, ...props }: SkipTargetProps) {
|
|
104
|
+
return (
|
|
105
|
+
<div
|
|
106
|
+
data-slot="skip-target"
|
|
107
|
+
id={id}
|
|
108
|
+
tabIndex={-1}
|
|
109
|
+
// Programmatic-focus anchor only — never a visible focus indicator,
|
|
110
|
+
// never a Tab stop, so no ring is required or wanted here.
|
|
111
|
+
className={cn("sr-only outline-none", className)}
|
|
112
|
+
{...props}
|
|
113
|
+
/>
|
|
114
|
+
)
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
export { SkipLink, SkipTarget }
|
|
@@ -5,16 +5,31 @@ import * as SliderPrimitive from "@radix-ui/react-slider"
|
|
|
5
5
|
|
|
6
6
|
import { cn } from "../../lib/utils"
|
|
7
7
|
|
|
8
|
+
/**
|
|
9
|
+
* A single tick along the track. A bare `number` renders a dot only; the
|
|
10
|
+
* object form adds a label below (horizontal) or beside (vertical) the track.
|
|
11
|
+
*/
|
|
12
|
+
type SliderMark = number | { value: number; label?: React.ReactNode }
|
|
13
|
+
|
|
8
14
|
function Slider({
|
|
9
15
|
className,
|
|
10
16
|
defaultValue,
|
|
11
17
|
value,
|
|
12
18
|
min = 0,
|
|
13
19
|
max = 100,
|
|
20
|
+
orientation = "horizontal",
|
|
21
|
+
marks,
|
|
14
22
|
"aria-label": ariaLabel,
|
|
15
23
|
"aria-labelledby": ariaLabelledby,
|
|
16
24
|
...props
|
|
17
|
-
}: React.ComponentProps<typeof SliderPrimitive.Root>
|
|
25
|
+
}: React.ComponentProps<typeof SliderPrimitive.Root> & {
|
|
26
|
+
/**
|
|
27
|
+
* Tick marks rendered along the track. Additive and decorative — marks are
|
|
28
|
+
* `aria-hidden` (each thumb already announces the value) and never change
|
|
29
|
+
* the slider's default rendering when omitted.
|
|
30
|
+
*/
|
|
31
|
+
marks?: SliderMark[]
|
|
32
|
+
}) {
|
|
18
33
|
const _values = React.useMemo(
|
|
19
34
|
() =>
|
|
20
35
|
Array.isArray(value)
|
|
@@ -25,6 +40,19 @@ function Slider({
|
|
|
25
40
|
[value, defaultValue, min, max]
|
|
26
41
|
)
|
|
27
42
|
|
|
43
|
+
const _marks = React.useMemo(
|
|
44
|
+
() =>
|
|
45
|
+
(marks ?? []).map((m) =>
|
|
46
|
+
typeof m === "number" ? { value: m, label: undefined } : m
|
|
47
|
+
),
|
|
48
|
+
[marks]
|
|
49
|
+
)
|
|
50
|
+
const isVertical = orientation === "vertical"
|
|
51
|
+
const hasLabels = _marks.some((m) => m.label != null)
|
|
52
|
+
// Clamp so an out-of-range mark can't push a dot off the track.
|
|
53
|
+
const pctOf = (v: number) =>
|
|
54
|
+
Math.min(100, Math.max(0, ((v - min) / (max - min)) * 100))
|
|
55
|
+
|
|
28
56
|
return (
|
|
29
57
|
<SliderPrimitive.Root
|
|
30
58
|
data-slot="slider"
|
|
@@ -32,8 +60,11 @@ function Slider({
|
|
|
32
60
|
value={value}
|
|
33
61
|
min={min}
|
|
34
62
|
max={max}
|
|
63
|
+
orientation={orientation}
|
|
35
64
|
className={cn(
|
|
36
65
|
"relative flex w-full touch-none items-center select-none data-[disabled]:opacity-50 data-[orientation=vertical]:h-full data-[orientation=vertical]:min-h-44 data-[orientation=vertical]:w-auto data-[orientation=vertical]:flex-col",
|
|
66
|
+
// Reserve room for mark labels so they never overlap following content.
|
|
67
|
+
hasLabels && (isVertical ? "mr-12" : "mb-7"),
|
|
37
68
|
className
|
|
38
69
|
)}
|
|
39
70
|
{...props}
|
|
@@ -56,6 +87,59 @@ function Slider({
|
|
|
56
87
|
)}
|
|
57
88
|
/>
|
|
58
89
|
</SliderPrimitive.Track>
|
|
90
|
+
{_marks.length > 0 && (
|
|
91
|
+
// Dots overlay the track. Decorative only — the scale they visualize
|
|
92
|
+
// is already announced through each thumb's value.
|
|
93
|
+
<span
|
|
94
|
+
data-slot="slider-marks"
|
|
95
|
+
aria-hidden
|
|
96
|
+
className="pointer-events-none absolute inset-0"
|
|
97
|
+
>
|
|
98
|
+
{_marks.map((m, index) => {
|
|
99
|
+
const pct = pctOf(m.value)
|
|
100
|
+
return (
|
|
101
|
+
<span
|
|
102
|
+
key={index}
|
|
103
|
+
className="absolute size-1.5 -translate-x-1/2 -translate-y-1/2 rounded-full bg-background ring-1 ring-primary/40"
|
|
104
|
+
style={
|
|
105
|
+
isVertical
|
|
106
|
+
? { bottom: `${pct}%`, left: "50%" }
|
|
107
|
+
: { left: `${pct}%`, top: "50%" }
|
|
108
|
+
}
|
|
109
|
+
/>
|
|
110
|
+
)
|
|
111
|
+
})}
|
|
112
|
+
</span>
|
|
113
|
+
)}
|
|
114
|
+
{hasLabels && (
|
|
115
|
+
<span
|
|
116
|
+
data-slot="slider-mark-labels"
|
|
117
|
+
aria-hidden
|
|
118
|
+
className={cn(
|
|
119
|
+
"pointer-events-none absolute text-xs text-muted-foreground",
|
|
120
|
+
isVertical ? "top-0 left-full ml-3 h-full" : "top-full mt-2 w-full"
|
|
121
|
+
)}
|
|
122
|
+
>
|
|
123
|
+
{_marks.map((m, index) =>
|
|
124
|
+
m.label == null ? null : (
|
|
125
|
+
<span
|
|
126
|
+
key={index}
|
|
127
|
+
className={cn(
|
|
128
|
+
"absolute tabular-nums whitespace-nowrap",
|
|
129
|
+
isVertical ? "-translate-y-1/2" : "-translate-x-1/2"
|
|
130
|
+
)}
|
|
131
|
+
style={
|
|
132
|
+
isVertical
|
|
133
|
+
? { bottom: `${pctOf(m.value)}%` }
|
|
134
|
+
: { left: `${pctOf(m.value)}%` }
|
|
135
|
+
}
|
|
136
|
+
>
|
|
137
|
+
{m.label}
|
|
138
|
+
</span>
|
|
139
|
+
)
|
|
140
|
+
)}
|
|
141
|
+
</span>
|
|
142
|
+
)}
|
|
59
143
|
{Array.from({ length: _values.length }, (_, index) => {
|
|
60
144
|
// Radix puts role="slider" on the thumb, not the Root, so the
|
|
61
145
|
// accessible name has to live here — a label on Root alone fails
|
|
@@ -81,3 +165,4 @@ function Slider({
|
|
|
81
165
|
}
|
|
82
166
|
|
|
83
167
|
export { Slider }
|
|
168
|
+
export type { SliderMark }
|