@istmx/ui 0.1.12 → 0.1.13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (55) hide show
  1. package/LICENSE +21 -21
  2. package/README.md +533 -469
  3. package/bin/istmx.mjs +481 -318
  4. package/package.json +27 -27
  5. package/registry/accordion.tsx +186 -0
  6. package/registry/ai-chat-block/ai-chat-block.tsx +456 -460
  7. package/registry/ai-chat-block/ai-chat-input.tsx +694 -694
  8. package/registry/ai-chat-block/attachment.tsx +466 -466
  9. package/registry/ai-chat-block/chat-code-block.tsx +50 -50
  10. package/registry/ai-chat-block/chat-composer.tsx +51 -51
  11. package/registry/ai-chat-block/chat-logo.tsx +18 -18
  12. package/registry/ai-chat-block/chat-message.tsx +161 -161
  13. package/registry/ai-chat-block/chat-sidebar.tsx +273 -273
  14. package/registry/ai-chat-block/chat-user-avatar.tsx +9 -9
  15. package/registry/ai-chat-block/code-highlighter.tsx +342 -357
  16. package/registry/ai-chat-block/default-attachments.tsx +42 -42
  17. package/registry/ai-chat-block/index.ts +30 -30
  18. package/registry/ai-chat-block/message-content.tsx +287 -287
  19. package/registry/ai-chat-block/message-list.tsx +93 -93
  20. package/registry/ai-chat-block/send-button.tsx +102 -102
  21. package/registry/ai-chat-block/types.ts +70 -71
  22. package/registry/ai-chat-block/utils.ts +6 -6
  23. package/registry/ai-chat-block/voice-button.tsx +66 -66
  24. package/registry/alert-dialog.tsx +229 -0
  25. package/registry/alert.tsx +188 -0
  26. package/registry/animated-text.tsx +228 -225
  27. package/registry/aspect-ratio.tsx +32 -0
  28. package/registry/avatar-group.tsx +66 -0
  29. package/registry/avatar.tsx +121 -0
  30. package/registry/badge.tsx +52 -0
  31. package/registry/bento-grid.tsx +438 -433
  32. package/registry/button.tsx +156 -237
  33. package/registry/carousel.tsx +184 -0
  34. package/registry/dock-navigation.tsx +200 -198
  35. package/registry/drift-canvas.tsx +383 -0
  36. package/registry/drift-wall.tsx +361 -0
  37. package/registry/flex-carousel.tsx +1430 -0
  38. package/registry/guided-gallery.tsx +1506 -0
  39. package/registry/image-accordion.tsx +306 -302
  40. package/registry/image-trail.tsx +126 -121
  41. package/registry/infinite-image-canvas.tsx +268 -263
  42. package/registry/input-otp.tsx +332 -0
  43. package/registry/list-card.tsx +130 -0
  44. package/registry/mobile-menu-dock.tsx +216 -211
  45. package/registry/morph-slider.tsx +756 -0
  46. package/registry/pixel-cat.tsx +972 -1020
  47. package/registry/scroll-canvas-cards.tsx +643 -640
  48. package/registry/scroll-parallax-hero.tsx +566 -565
  49. package/registry/scroll-story-cards.tsx +443 -438
  50. package/registry/slider.tsx +163 -0
  51. package/registry/spotlight-grid.tsx +226 -0
  52. package/registry/streaming-text.tsx +269 -278
  53. package/registry/text-reveal.tsx +311 -307
  54. package/registry/user-avatar.tsx +99 -0
  55. package/registry/utils.ts +6 -6
@@ -1,66 +1,66 @@
1
- 'use client'
2
-
3
- import { AnimatePresence, motion, useReducedMotion } from 'motion/react'
4
- import { IconMicrophone, IconPlayerStop } from '@tabler/icons-react'
5
-
6
- export type VoiceButtonProps = {
7
- listening: boolean
8
- disabled?: boolean
9
- onClick: () => void
10
- startLabel?: string
11
- stopLabel?: string
12
- }
13
-
14
- export default function VoiceButton({
15
- listening,
16
- disabled = false,
17
- onClick,
18
- startLabel = 'Start voice input',
19
- stopLabel = 'Stop voice input',
20
- }: VoiceButtonProps) {
21
- const reduceMotion = useReducedMotion()
22
-
23
- return (
24
- <motion.button
25
- type="button"
26
- onClick={onClick}
27
- aria-pressed={listening}
28
- aria-label={listening ? stopLabel : startLabel}
29
- title={listening ? stopLabel : startLabel}
30
- disabled={disabled}
31
- whileTap={reduceMotion ? undefined : { scale: 0.9 }}
32
- whileHover={reduceMotion ? undefined : { y: -1 }}
33
- className={`focus-visible:outline-foreground relative flex size-8 shrink-0 cursor-pointer items-center justify-center overflow-visible rounded-xl border transition-colors duration-200 focus-visible:outline-2 focus-visible:outline-offset-2 disabled:cursor-not-allowed disabled:opacity-50 sm:size-9 ${
34
- listening
35
- ? 'border-[var(--chat-accent,var(--foreground))] bg-[var(--chat-accent,var(--foreground))] text-white'
36
- : 'border-border/70 bg-surface/40 text-muted hover:border-foreground/40 hover:text-foreground'
37
- }`}
38
- >
39
- {listening && !reduceMotion ? (
40
- <motion.span
41
- aria-hidden="true"
42
- className="border-[var(--chat-accent,var(--foreground))] pointer-events-none absolute inset-0 rounded-[inherit] border"
43
- initial={{ opacity: 0.5, scale: 1 }}
44
- animate={{ opacity: 0, scale: 1.55 }}
45
- transition={{ repeat: Infinity, duration: 1.5, ease: 'easeOut' }}
46
- />
47
- ) : null}
48
- <AnimatePresence mode="wait" initial={false}>
49
- <motion.span
50
- key={listening ? 'on' : 'off'}
51
- initial={reduceMotion ? { opacity: 0 } : { opacity: 0, scale: 0.6, rotate: -35 }}
52
- animate={{ opacity: 1, scale: 1, rotate: 0 }}
53
- exit={reduceMotion ? { opacity: 0 } : { opacity: 0, scale: 0.6, rotate: 35 }}
54
- transition={{ duration: reduceMotion ? 0 : 0.16 }}
55
- className="relative flex items-center justify-center"
56
- >
57
- {listening ? (
58
- <IconPlayerStop size={13} stroke={1.6} aria-hidden="true" />
59
- ) : (
60
- <IconMicrophone size={17} stroke={1.7} aria-hidden="true" />
61
- )}
62
- </motion.span>
63
- </AnimatePresence>
64
- </motion.button>
65
- )
66
- }
1
+ 'use client'
2
+
3
+ import { AnimatePresence, motion, useReducedMotion } from 'motion/react'
4
+ import { IconMicrophone, IconPlayerStop } from '@tabler/icons-react'
5
+
6
+ export type VoiceButtonProps = {
7
+ listening: boolean
8
+ disabled?: boolean
9
+ onClick: () => void
10
+ startLabel?: string
11
+ stopLabel?: string
12
+ }
13
+
14
+ export default function VoiceButton({
15
+ listening,
16
+ disabled = false,
17
+ onClick,
18
+ startLabel = 'Start voice input',
19
+ stopLabel = 'Stop voice input',
20
+ }: VoiceButtonProps) {
21
+ const reduceMotion = useReducedMotion()
22
+
23
+ return (
24
+ <motion.button
25
+ type="button"
26
+ onClick={onClick}
27
+ aria-pressed={listening}
28
+ aria-label={listening ? stopLabel : startLabel}
29
+ title={listening ? stopLabel : startLabel}
30
+ disabled={disabled}
31
+ whileTap={reduceMotion ? undefined : { scale: 0.9 }}
32
+ whileHover={reduceMotion ? undefined : { y: -1 }}
33
+ className={`focus-visible:outline-foreground relative flex size-8 shrink-0 cursor-pointer items-center justify-center overflow-visible rounded-xl border transition-colors duration-200 focus-visible:outline-2 focus-visible:outline-offset-2 disabled:cursor-not-allowed disabled:opacity-50 sm:size-9 ${
34
+ listening
35
+ ? 'border-[var(--chat-accent,var(--foreground))] bg-[var(--chat-accent,var(--foreground))] text-white'
36
+ : 'border-border/70 bg-surface/40 text-muted hover:border-foreground/40 hover:text-foreground'
37
+ }`}
38
+ >
39
+ {listening && !reduceMotion ? (
40
+ <motion.span
41
+ aria-hidden="true"
42
+ className="border-[var(--chat-accent,var(--foreground))] pointer-events-none absolute inset-0 rounded-[inherit] border"
43
+ initial={{ opacity: 0.5, scale: 1 }}
44
+ animate={{ opacity: 0, scale: 1.55 }}
45
+ transition={{ repeat: Infinity, duration: 1.5, ease: 'easeOut' }}
46
+ />
47
+ ) : null}
48
+ <AnimatePresence mode="wait" initial={false}>
49
+ <motion.span
50
+ key={listening ? 'on' : 'off'}
51
+ initial={reduceMotion ? { opacity: 0 } : { opacity: 0, scale: 0.6, rotate: -35 }}
52
+ animate={{ opacity: 1, scale: 1, rotate: 0 }}
53
+ exit={reduceMotion ? { opacity: 0 } : { opacity: 0, scale: 0.6, rotate: 35 }}
54
+ transition={{ duration: reduceMotion ? 0 : 0.16 }}
55
+ className="relative flex items-center justify-center"
56
+ >
57
+ {listening ? (
58
+ <IconPlayerStop size={13} stroke={1.6} aria-hidden="true" />
59
+ ) : (
60
+ <IconMicrophone size={17} stroke={1.7} aria-hidden="true" />
61
+ )}
62
+ </motion.span>
63
+ </AnimatePresence>
64
+ </motion.button>
65
+ )
66
+ }
@@ -0,0 +1,229 @@
1
+ 'use client'
2
+
3
+ import * as React from 'react'
4
+ import { motion, useReducedMotion, type HTMLMotionProps } from 'motion/react'
5
+ import { cn } from '@/lib/utils'
6
+
7
+ interface AlertDialogContextValue {
8
+ open: boolean
9
+ setOpen: (open: boolean) => void
10
+ titleId: string
11
+ descriptionId: string
12
+ onConfirm?: () => void
13
+ }
14
+
15
+ const AlertDialogContext = React.createContext<AlertDialogContextValue | null>(null)
16
+
17
+ function useAlertDialogContext() {
18
+ const context = React.useContext(AlertDialogContext)
19
+ if (!context) throw new Error('AlertDialog components must be used inside AlertDialog.')
20
+ return context
21
+ }
22
+
23
+ export interface AlertDialogProps extends React.HTMLAttributes<HTMLDivElement> {
24
+ open?: boolean
25
+ defaultOpen?: boolean
26
+ onOpenChange?: (open: boolean) => void
27
+ onConfirm?: () => void
28
+ }
29
+
30
+ const AlertDialog = React.forwardRef<HTMLDivElement, AlertDialogProps>(
31
+ ({ className, open, defaultOpen = false, onOpenChange, onConfirm, children, ...props }, ref) => {
32
+ const [uncontrolledOpen, setUncontrolledOpen] = React.useState(defaultOpen)
33
+ const isOpen = open ?? uncontrolledOpen
34
+ const ids = React.useId()
35
+ const setOpen = React.useCallback((nextOpen: boolean) => {
36
+ if (open === undefined) setUncontrolledOpen(nextOpen)
37
+ onOpenChange?.(nextOpen)
38
+ }, [onOpenChange, open])
39
+
40
+ return (
41
+ <AlertDialogContext.Provider value={{ open: isOpen, setOpen, titleId: `${ids}-title`, descriptionId: `${ids}-description`, onConfirm }}>
42
+ <div {...props} ref={ref} data-slot="alert-dialog" className={cn('inline-flex', className)}>
43
+ {children}
44
+ </div>
45
+ </AlertDialogContext.Provider>
46
+ )
47
+ },
48
+ )
49
+
50
+ AlertDialog.displayName = 'AlertDialog'
51
+
52
+ export type AlertDialogTriggerProps = Omit<HTMLMotionProps<'button'>, 'ref'>
53
+
54
+ const AlertDialogTrigger = React.forwardRef<HTMLButtonElement, AlertDialogTriggerProps>(({ className, onClick, children, ...props }, ref) => {
55
+ const context = useAlertDialogContext()
56
+ const reduceMotion = useReducedMotion()
57
+
58
+ return (
59
+ <motion.button
60
+ {...props}
61
+ ref={ref}
62
+ type="button"
63
+ aria-haspopup="dialog"
64
+ aria-expanded={context.open}
65
+ data-slot="alert-dialog-trigger"
66
+ onClick={(event) => {
67
+ onClick?.(event)
68
+ if (!event.defaultPrevented) context.setOpen(true)
69
+ }}
70
+ whileTap={reduceMotion ? undefined : { scale: 0.98 }}
71
+ className={cn('inline-flex min-h-10 cursor-pointer items-center justify-center rounded-2xl border border-[var(--button-border)] bg-[linear-gradient(to_bottom,var(--button-surface-top),var(--button-surface-bottom))] px-4 text-sm font-medium text-foreground shadow-[inset_0_0_0_1px_var(--effect-white-full)] transition-colors hover:border-[var(--button-border-hover)] focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-foreground/70', className)}
72
+ >
73
+ {children}
74
+ </motion.button>
75
+ )
76
+ })
77
+
78
+ AlertDialogTrigger.displayName = 'AlertDialogTrigger'
79
+
80
+ export interface AlertDialogContentProps extends Omit<React.DialogHTMLAttributes<HTMLDialogElement>, 'open'> {
81
+ overlayClassName?: string
82
+ modal?: boolean
83
+ }
84
+
85
+ const AlertDialogContent = React.forwardRef<HTMLDialogElement, AlertDialogContentProps>(({ className, overlayClassName, modal = true, children, onCancel, onClose, ...props }, forwardedRef) => {
86
+ const context = useAlertDialogContext()
87
+ const reduceMotion = useReducedMotion()
88
+ const dialogRef = React.useRef<HTMLDialogElement>(null)
89
+ const closeTimer = React.useRef<ReturnType<typeof setTimeout> | null>(null)
90
+ React.useImperativeHandle(forwardedRef, () => dialogRef.current as HTMLDialogElement)
91
+
92
+ React.useEffect(() => {
93
+ const dialog = dialogRef.current
94
+ if (!dialog) return
95
+ if (closeTimer.current) clearTimeout(closeTimer.current)
96
+ if (context.open && !dialog.open) {
97
+ if (modal) dialog.showModal()
98
+ else dialog.show()
99
+ } else if (!context.open && dialog.open) {
100
+ closeTimer.current = setTimeout(() => {
101
+ if (dialog.open) dialog.close()
102
+ }, reduceMotion ? 0 : 180)
103
+ }
104
+ return () => {
105
+ if (closeTimer.current) clearTimeout(closeTimer.current)
106
+ }
107
+ }, [context.open, modal, reduceMotion])
108
+
109
+ return (
110
+ <dialog
111
+ {...props}
112
+ ref={dialogRef}
113
+ role="alertdialog"
114
+ aria-labelledby={context.titleId}
115
+ aria-describedby={context.descriptionId}
116
+ data-slot="alert-dialog-content"
117
+ onCancel={(event) => {
118
+ onCancel?.(event)
119
+ if (!event.defaultPrevented) {
120
+ event.preventDefault()
121
+ context.setOpen(false)
122
+ }
123
+ }}
124
+ onClose={(event) => {
125
+ onClose?.(event)
126
+ if (context.open) context.setOpen(false)
127
+ }}
128
+ style={modal ? undefined : { position: 'absolute', inset: '50% auto auto 50%', transform: 'translate(-50%, -50%)', width: 'min(28rem, calc(100vw - 2rem))', maxWidth: 'calc(100vw - 2rem)', margin: 0, zIndex: 30 }}
129
+ className={cn('m-auto max-h-[calc(100dvh-2rem)] w-[calc(100%-2rem)] max-w-md overflow-visible border-0 bg-transparent p-0 text-foreground outline-none', modal && 'backdrop:bg-foreground/30 backdrop:backdrop-blur-sm', overlayClassName)}
130
+ >
131
+ <motion.div
132
+ initial={false}
133
+ animate={context.open ? { opacity: 1, y: 0, scale: 1 } : { opacity: 0, y: 8, scale: 0.98 }}
134
+ transition={{ duration: reduceMotion ? 0 : 0.18, ease: [0.22, 1, 0.36, 1] }}
135
+ className={cn('max-h-[calc(100dvh-2rem)] overflow-y-auto rounded-3xl border border-[var(--button-border)] bg-[linear-gradient(to_bottom,var(--button-surface-top),var(--button-surface-bottom))] p-4 shadow-2xl sm:p-5', className)}
136
+ >
137
+ {children}
138
+ </motion.div>
139
+ </dialog>
140
+ )
141
+ })
142
+
143
+ AlertDialogContent.displayName = 'AlertDialogContent'
144
+
145
+ export type AlertDialogHeaderProps = React.HTMLAttributes<HTMLDivElement>
146
+
147
+ const AlertDialogHeader = React.forwardRef<HTMLDivElement, AlertDialogHeaderProps>(({ className, ...props }, ref) => (
148
+ <div {...props} ref={ref} data-slot="alert-dialog-header" className={cn('space-y-2 text-left', className)} />
149
+ ))
150
+
151
+ AlertDialogHeader.displayName = 'AlertDialogHeader'
152
+
153
+ export type AlertDialogTitleProps = React.HTMLAttributes<HTMLHeadingElement>
154
+
155
+ const AlertDialogTitle = React.forwardRef<HTMLHeadingElement, AlertDialogTitleProps>(({ className, id, ...props }, ref) => {
156
+ const context = useAlertDialogContext()
157
+ return <h2 {...props} ref={ref} id={id ?? context.titleId} data-slot="alert-dialog-title" className={cn('font-grotesk text-lg font-semibold tracking-tight', className)} />
158
+ })
159
+
160
+ AlertDialogTitle.displayName = 'AlertDialogTitle'
161
+
162
+ export type AlertDialogDescriptionProps = React.HTMLAttributes<HTMLParagraphElement>
163
+
164
+ const AlertDialogDescription = React.forwardRef<HTMLParagraphElement, AlertDialogDescriptionProps>(({ className, id, ...props }, ref) => {
165
+ const context = useAlertDialogContext()
166
+ return <p {...props} ref={ref} id={id ?? context.descriptionId} data-slot="alert-dialog-description" className={cn('text-sm leading-6 text-muted-foreground', className)} />
167
+ })
168
+
169
+ AlertDialogDescription.displayName = 'AlertDialogDescription'
170
+
171
+ export type AlertDialogFooterProps = React.HTMLAttributes<HTMLDivElement>
172
+
173
+ const AlertDialogFooter = React.forwardRef<HTMLDivElement, AlertDialogFooterProps>(({ className, ...props }, ref) => (
174
+ <div {...props} ref={ref} data-slot="alert-dialog-footer" className={cn('mt-5 flex flex-col-reverse gap-2 sm:flex-row sm:justify-end', className)} />
175
+ ))
176
+
177
+ AlertDialogFooter.displayName = 'AlertDialogFooter'
178
+
179
+ export type AlertDialogCancelProps = React.ButtonHTMLAttributes<HTMLButtonElement>
180
+
181
+ const AlertDialogCancel = React.forwardRef<HTMLButtonElement, AlertDialogCancelProps>(({ className, onClick, ...props }, ref) => {
182
+ const context = useAlertDialogContext()
183
+ return (
184
+ <button
185
+ {...props}
186
+ ref={ref}
187
+ type="button"
188
+ data-slot="alert-dialog-cancel"
189
+ onClick={(event) => {
190
+ onClick?.(event)
191
+ if (!event.defaultPrevented) context.setOpen(false)
192
+ }}
193
+ className={cn('inline-flex min-h-10 cursor-pointer items-center justify-center rounded-2xl border border-[var(--button-border)] bg-background px-4 text-sm font-medium text-foreground transition-colors hover:bg-muted focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-foreground/70', className)}
194
+ />
195
+ )
196
+ })
197
+
198
+ AlertDialogCancel.displayName = 'AlertDialogCancel'
199
+
200
+ export interface AlertDialogActionProps extends Omit<HTMLMotionProps<'button'>, 'ref'> {
201
+ variant?: 'default' | 'destructive'
202
+ }
203
+
204
+ const AlertDialogAction = React.forwardRef<HTMLButtonElement, AlertDialogActionProps>(({ className, onClick, variant = 'default', ...props }, ref) => {
205
+ const context = useAlertDialogContext()
206
+ const reduceMotion = useReducedMotion()
207
+ return (
208
+ <motion.button
209
+ {...props}
210
+ ref={ref}
211
+ type="button"
212
+ data-slot="alert-dialog-action"
213
+ data-variant={variant}
214
+ onClick={(event) => {
215
+ onClick?.(event)
216
+ if (!event.defaultPrevented) {
217
+ context.onConfirm?.()
218
+ context.setOpen(false)
219
+ }
220
+ }}
221
+ whileTap={reduceMotion ? undefined : { scale: 0.98 }}
222
+ className={cn('inline-flex min-h-10 cursor-pointer items-center justify-center rounded-2xl px-4 text-sm font-medium shadow-[inset_0_1px_0_var(--effect-white-24)] transition-opacity hover:opacity-90 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-foreground/70', variant === 'destructive' ? 'border border-[var(--status-error)] bg-[var(--status-error)] text-white' : 'border border-foreground bg-foreground text-background', className)}
223
+ />
224
+ )
225
+ })
226
+
227
+ AlertDialogAction.displayName = 'AlertDialogAction'
228
+
229
+ export { AlertDialog, AlertDialogTrigger, AlertDialogContent, AlertDialogHeader, AlertDialogTitle, AlertDialogDescription, AlertDialogFooter, AlertDialogCancel, AlertDialogAction }
@@ -0,0 +1,188 @@
1
+ 'use client'
2
+
3
+ import * as React from 'react'
4
+ import { AnimatePresence, motion, useReducedMotion, type HTMLMotionProps, type PanInfo } from 'motion/react'
5
+ import { cn } from '@/lib/utils'
6
+
7
+ const alertVariants = {
8
+ default: 'border-border bg-surface text-foreground',
9
+ destructive: 'border-[color-mix(in_oklab,var(--status-error)_36%,var(--border))] bg-[color-mix(in_oklab,var(--status-error-soft)_72%,var(--background))] text-foreground',
10
+ success: 'border-[color-mix(in_oklab,var(--status-success)_36%,var(--border))] bg-[color-mix(in_oklab,var(--status-success-soft)_72%,var(--background))] text-foreground',
11
+ warning: 'border-[color-mix(in_oklab,var(--status-warning)_36%,var(--border))] bg-[color-mix(in_oklab,var(--status-warning-soft)_72%,var(--background))] text-foreground',
12
+ info: 'border-border bg-muted text-foreground',
13
+ } as const
14
+
15
+ const alertIconColors = {
16
+ default: 'text-muted-foreground',
17
+ destructive: 'text-[var(--status-error-strong)]',
18
+ success: 'text-[var(--status-success-strong)]',
19
+ warning: 'text-[var(--status-warning-strong)]',
20
+ info: 'text-foreground',
21
+ } as const
22
+
23
+ export type AlertVariant = keyof typeof alertVariants
24
+
25
+ export interface AlertStackItem {
26
+ id: string
27
+ title: React.ReactNode
28
+ description: React.ReactNode
29
+ variant?: AlertVariant
30
+ }
31
+
32
+ export interface AlertStackProps extends React.HTMLAttributes<HTMLDivElement> {
33
+ items?: AlertStackItem[]
34
+ defaultItems?: AlertStackItem[]
35
+ onDismiss?: (item: AlertStackItem) => void
36
+ maxVisible?: number
37
+ swipeThreshold?: number
38
+ }
39
+
40
+ const AlertStack = React.forwardRef<HTMLDivElement, AlertStackProps>(
41
+ ({ className, items, defaultItems = [], onDismiss, maxVisible = 3, swipeThreshold = 72, ...props }, ref) => {
42
+ const [uncontrolledItems, setUncontrolledItems] = React.useState(defaultItems)
43
+ const [exitDirection, setExitDirection] = React.useState(1)
44
+ const reduceMotion = useReducedMotion()
45
+ const currentItems = items ?? uncontrolledItems
46
+
47
+ const dismiss = React.useCallback((item: AlertStackItem) => {
48
+ if (items === undefined) setUncontrolledItems((previous) => previous.filter((current) => current.id !== item.id))
49
+ onDismiss?.(item)
50
+ }, [items, onDismiss])
51
+
52
+ const handleDragEnd = React.useCallback((item: AlertStackItem, info: PanInfo) => {
53
+ if (Math.abs(info.offset.x) < swipeThreshold && Math.abs(info.velocity.x) < 650) return
54
+ setExitDirection(info.offset.x + info.velocity.x * 0.14 >= 0 ? 1 : -1)
55
+ dismiss(item)
56
+ }, [dismiss, swipeThreshold])
57
+
58
+ return (
59
+ <div {...props} ref={ref} role="region" data-slot="alert-stack" aria-label={props['aria-label'] ?? 'Dismissible alerts'} className={cn('relative min-h-32 w-full', className)}>
60
+ <AnimatePresence initial={false} custom={exitDirection}>
61
+ {currentItems.slice(0, maxVisible).map((item, index) => (
62
+ <motion.div
63
+ key={item.id}
64
+ custom={exitDirection}
65
+ drag={index === 0 ? 'x' : false}
66
+ dragConstraints={{ left: -520, right: 520 }}
67
+ dragElastic={1}
68
+ dragMomentum={false}
69
+ onDragEnd={(_, info) => index === 0 && handleDragEnd(item, info)}
70
+ layout={!reduceMotion}
71
+ initial={reduceMotion ? false : { opacity: 0, x: 0, y: index * 10 + 8, scale: 1 - index * 0.035 }}
72
+ animate={{ opacity: index < maxVisible ? 1 : 0, x: 0, y: index * 10, scale: 1 - index * 0.035 }}
73
+ variants={{
74
+ swish: (direction: number) => ({
75
+ x: reduceMotion ? 0 : direction * 520,
76
+ opacity: 0,
77
+ rotate: reduceMotion ? 0 : direction * 7,
78
+ transition: reduceMotion ? { duration: 0 } : { type: 'spring', stiffness: 380, damping: 30, mass: 0.55 },
79
+ }),
80
+ }}
81
+ exit="swish"
82
+ transition={reduceMotion ? { duration: 0 } : { type: 'spring', stiffness: 360, damping: 30, mass: 0.7 }}
83
+ style={{ zIndex: currentItems.length - index, transformOrigin: '50% 15%' }}
84
+ aria-hidden={index > 0}
85
+ inert={index > 0}
86
+ role="group"
87
+ aria-label={index === 0 ? 'Swipe left or right to dismiss this alert' : undefined}
88
+ className={cn('absolute inset-x-0 top-0 touch-pan-y', index === 0 ? 'cursor-grab active:cursor-grabbing' : 'pointer-events-none')}
89
+ >
90
+ <Alert
91
+ variant={item.variant}
92
+ title={item.title}
93
+ dismissible={index === 0}
94
+ onOpenChange={(open) => {
95
+ if (!open && index === 0) dismiss(item)
96
+ }}
97
+ className="shadow-lg"
98
+ >
99
+ {item.description}
100
+ </Alert>
101
+ </motion.div>
102
+ ))}
103
+ </AnimatePresence>
104
+ </div>
105
+ )
106
+ },
107
+ )
108
+
109
+ AlertStack.displayName = 'AlertStack'
110
+
111
+ export interface AlertProps extends Omit<HTMLMotionProps<'div'>, 'title' | 'children'> {
112
+ variant?: AlertVariant
113
+ title?: React.ReactNode
114
+ role?: 'alert' | 'status' | 'region'
115
+ children?: React.ReactNode
116
+ dismissible?: boolean
117
+ open?: boolean
118
+ defaultOpen?: boolean
119
+ onOpenChange?: (open: boolean) => void
120
+ }
121
+
122
+ const Alert = React.forwardRef<HTMLDivElement, AlertProps>(
123
+ ({ className, variant = 'default', title, role, children, dismissible = false, open, defaultOpen = true, onOpenChange, ...props }, ref) => {
124
+ const reduceMotion = useReducedMotion()
125
+ const [uncontrolledOpen, setUncontrolledOpen] = React.useState(defaultOpen)
126
+ const isOpen = open ?? uncontrolledOpen
127
+ const dismiss = () => {
128
+ if (open === undefined) setUncontrolledOpen(false)
129
+ onOpenChange?.(false)
130
+ }
131
+
132
+ return (
133
+ <AnimatePresence>
134
+ {isOpen && (
135
+ <motion.div
136
+ {...props}
137
+ ref={ref}
138
+ layout={reduceMotion ? false : 'position'}
139
+ initial={reduceMotion ? false : { opacity: 0, y: 5 }}
140
+ animate={{ opacity: 1, y: 0 }}
141
+ exit={reduceMotion ? { opacity: 0 } : { opacity: 0, y: -4 }}
142
+ transition={reduceMotion ? { duration: 0 } : { type: 'spring', stiffness: 420, damping: 32 }}
143
+ role={role ?? (variant === 'destructive' ? 'alert' : 'status')}
144
+ aria-live={variant === 'destructive' ? 'assertive' : 'polite'}
145
+ data-slot="alert"
146
+ data-variant={variant}
147
+ className={cn('relative w-full rounded-2xl border px-4 py-3.5 pr-12 text-sm shadow-[inset_0_1px_0_var(--effect-white-10)]', alertVariants[variant], className)}
148
+ >
149
+ <div className="flex items-start gap-3">
150
+ <AnimatePresence propagate>
151
+ <motion.svg
152
+ key={variant}
153
+ aria-hidden="true"
154
+ viewBox="0 0 24 24"
155
+ fill="none"
156
+ initial={reduceMotion ? false : { opacity: 0, scale: 0.65, rotate: -18 }}
157
+ animate={{ opacity: 1, scale: 1, rotate: 0 }}
158
+ exit={reduceMotion ? { opacity: 0 } : { opacity: 0, scale: 0.7, rotate: 18 }}
159
+ transition={reduceMotion ? { duration: 0 } : { type: 'spring', stiffness: 420, damping: 24 }}
160
+ className={cn('mt-0.5 size-5 shrink-0', alertIconColors[variant])}
161
+ >
162
+ {variant === 'success' ? (
163
+ <path d="m5 12.5 4.2 4.2L19 7" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round" />
164
+ ) : variant === 'warning' ? (
165
+ <><path d="M10.3 4.7 2.9 17.5A1.7 1.7 0 0 0 4.4 20h15.2a1.7 1.7 0 0 0 1.5-2.5L13.7 4.7a2 2 0 0 0-3.4 0Z" stroke="currentColor" strokeWidth="1.7" strokeLinejoin="round" /><path d="M12 9v4m0 3h.01" stroke="currentColor" strokeWidth="1.8" strokeLinecap="round" /></>
166
+ ) : variant === 'destructive' ? (
167
+ <><circle cx="12" cy="12" r="9" stroke="currentColor" strokeWidth="1.7" /><path d="M12 8v5m0 3h.01" stroke="currentColor" strokeWidth="1.8" strokeLinecap="round" /></>
168
+ ) : (
169
+ <><circle cx="12" cy="12" r="9" stroke="currentColor" strokeWidth="1.7" /><path d="M12 11v5m0-8h.01" stroke="currentColor" strokeWidth="1.8" strokeLinecap="round" /></>
170
+ )}
171
+ </motion.svg>
172
+ </AnimatePresence>
173
+ <div className="min-w-0">
174
+ {title && <h5 className="mb-1 font-grotesk text-sm font-semibold leading-none tracking-tight">{title}</h5>}
175
+ {children && <div className="text-sm leading-6 text-muted-foreground [&_a]:font-medium [&_a]:text-foreground [&_a]:underline [&_a]:underline-offset-4">{children}</div>}
176
+ </div>
177
+ </div>
178
+ {dismissible && <button type="button" aria-label="Dismiss alert" onClick={dismiss} className="absolute right-2.5 top-2.5 grid size-8 cursor-pointer place-items-center rounded-lg text-muted-foreground transition-colors hover:bg-foreground/5 hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-foreground/70"><svg aria-hidden="true" viewBox="0 0 20 20" fill="none" className="size-4"><path d="m5 5 10 10M15 5 5 15" stroke="currentColor" strokeWidth="1.6" strokeLinecap="round" /></svg></button>}
179
+ </motion.div>
180
+ )}
181
+ </AnimatePresence>
182
+ )
183
+ },
184
+ )
185
+
186
+ Alert.displayName = 'Alert'
187
+
188
+ export { Alert, AlertStack, alertVariants }