@dinachi/cli 0.9.0 → 0.11.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/CHANGELOG.md +101 -0
- package/README.md +34 -5
- package/dist/index.js +294 -63
- package/package.json +8 -6
- package/templates/accordion/accordion.tsx +4 -5
- package/templates/alert-dialog/alert-dialog.tsx +9 -2
- package/templates/animated-icon/animated-icon.tsx +145 -0
- package/templates/animated-icon/index.ts +1 -0
- package/templates/animated-list/animated-list.tsx +161 -0
- package/templates/animated-list/index.ts +2 -0
- package/templates/animated-tabs/animated-tabs.tsx +244 -0
- package/templates/animated-tabs/index.ts +13 -0
- package/templates/autocomplete/autocomplete.tsx +6 -4
- package/templates/button/button.tsx +19 -2
- package/templates/carousel/carousel.tsx +492 -0
- package/templates/carousel/index.ts +1 -0
- package/templates/collapsible/collapsible.tsx +3 -7
- package/templates/combobox/combobox.tsx +6 -4
- package/templates/compare-slider/compare-slider.tsx +383 -0
- package/templates/compare-slider/index.ts +2 -0
- package/templates/context-menu/context-menu.tsx +10 -6
- package/templates/dialog/dialog.tsx +9 -2
- package/templates/drawer/drawer.tsx +24 -2
- package/templates/expandable-card/expandable-card.tsx +509 -0
- package/templates/expandable-card/index.ts +1 -0
- package/templates/hold-to-confirm/hold-to-confirm.tsx +580 -0
- package/templates/hold-to-confirm/index.ts +2 -0
- package/templates/load-transition/index.ts +1 -0
- package/templates/load-transition/load-transition.tsx +163 -0
- package/templates/marquee/index.ts +2 -0
- package/templates/marquee/marquee.tsx +256 -0
- package/templates/menu/menu.tsx +10 -6
- package/templates/menubar/menubar.tsx +10 -6
- package/templates/meter/meter.tsx +1 -1
- package/templates/navigation-menu/navigation-menu.tsx +9 -6
- package/templates/number-ticker/index.ts +2 -0
- package/templates/number-ticker/number-ticker.tsx +470 -0
- package/templates/otp-field/otp-field.tsx +3 -2
- package/templates/popover/popover.tsx +7 -6
- package/templates/preview-card/preview-card.tsx +2 -1
- package/templates/progress/progress.tsx +1 -1
- package/templates/progress-ring/index.ts +1 -0
- package/templates/progress-ring/progress-ring.tsx +268 -0
- package/templates/scroll-progress/index.ts +2 -0
- package/templates/scroll-progress/scroll-progress.tsx +147 -0
- package/templates/scroll-reveal/index.ts +2 -0
- package/templates/scroll-reveal/scroll-reveal.tsx +198 -0
- package/templates/select/select.tsx +18 -4
- package/templates/slider/slider.tsx +3 -2
- package/templates/sortable/index.ts +1 -0
- package/templates/sortable/sortable.tsx +349 -0
- package/templates/stagger-list/index.ts +2 -0
- package/templates/stagger-list/stagger-list.tsx +204 -0
- package/templates/streaming-text/index.ts +2 -0
- package/templates/streaming-text/streaming-text.tsx +220 -0
- package/templates/swipeable-row/index.ts +2 -0
- package/templates/swipeable-row/swipeable-row.tsx +368 -0
- package/templates/switch/switch.tsx +4 -2
- package/templates/tabs/tabs.tsx +10 -2
- package/templates/text-morph/index.ts +2 -0
- package/templates/text-morph/text-morph.tsx +265 -0
- package/templates/text-shimmer/index.ts +2 -0
- package/templates/text-shimmer/text-shimmer.tsx +151 -0
- package/templates/textarea/textarea.tsx +1 -2
- package/templates/toast/toast.tsx +24 -19
- package/templates/toggle/toggle.tsx +1 -1
- package/templates/tooltip/tooltip.tsx +10 -4
- package/templates/tsconfig.json +1 -0
- package/templates/utils/variants.ts +0 -6
|
@@ -0,0 +1,265 @@
|
|
|
1
|
+
"use client"
|
|
2
|
+
|
|
3
|
+
import * as React from "react"
|
|
4
|
+
import {
|
|
5
|
+
AnimatePresence,
|
|
6
|
+
motion,
|
|
7
|
+
MotionConfigContext,
|
|
8
|
+
useReducedMotion,
|
|
9
|
+
type Transition,
|
|
10
|
+
} from "motion/react"
|
|
11
|
+
import { cn } from "@/lib/utils"
|
|
12
|
+
|
|
13
|
+
/** `useReducedMotion` reads the OS setting only, and only at mount. Also honour an
|
|
14
|
+
* app-level `<MotionConfig reducedMotion>`, so a user preference in the host app
|
|
15
|
+
* reaches this component. */
|
|
16
|
+
function useReducedMotionConfig() {
|
|
17
|
+
const config = React.useContext(MotionConfigContext)
|
|
18
|
+
const prefersReduced = useReducedMotion()
|
|
19
|
+
if (config.reducedMotion === "always") return true
|
|
20
|
+
if (config.reducedMotion === "never") return false
|
|
21
|
+
return prefersReduced
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const EASE_OUT: [number, number, number, number] = [0.23, 1, 0.32, 1]
|
|
25
|
+
|
|
26
|
+
/** Characters that survive the morph are neither arriving nor leaving — they are
|
|
27
|
+
* travelling across the word — and on-screen movement wants a curve that eases both
|
|
28
|
+
* ends rather than one tuned to feel responsive at the start. */
|
|
29
|
+
const EASE_IN_OUT: [number, number, number, number] = [0.77, 0, 0.175, 1]
|
|
30
|
+
|
|
31
|
+
/** Clearing the old characters is the system responding; reading the new ones is what
|
|
32
|
+
* the user is here for. The exit runs short of the entrance so the gap has closed by
|
|
33
|
+
* the time the eye arrives. */
|
|
34
|
+
const EXIT_RATIO = 0.6
|
|
35
|
+
|
|
36
|
+
/** Seconds. Under a reduced-motion preference the change still needs a bridge, but a
|
|
37
|
+
* short crossfade is the whole of it. Shared with the rest of the motion tier so a
|
|
38
|
+
* page that reduces one component reduces all of them at the same rate. */
|
|
39
|
+
const REDUCED_DURATION = 0.2
|
|
40
|
+
|
|
41
|
+
/** The morph is driven from a layout effect so the setup commit never paints. On the
|
|
42
|
+
* server there is nothing to lay out, and `useLayoutEffect` warns there. */
|
|
43
|
+
const useIsomorphicLayoutEffect =
|
|
44
|
+
typeof window !== "undefined" ? React.useLayoutEffect : React.useEffect
|
|
45
|
+
|
|
46
|
+
interface GraphemeSegmenter {
|
|
47
|
+
segment(input: string): Iterable<{ segment: string }>
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
let segmenter: GraphemeSegmenter | null | undefined
|
|
51
|
+
|
|
52
|
+
/** Splitting on code points detaches a combining accent from its letter and shatters
|
|
53
|
+
* multi-codepoint emoji, so segment by grapheme wherever the runtime offers it. */
|
|
54
|
+
function toGraphemes(text: string): string[] {
|
|
55
|
+
if (segmenter === undefined) {
|
|
56
|
+
const Segmenter = (
|
|
57
|
+
Intl as unknown as {
|
|
58
|
+
Segmenter?: new (
|
|
59
|
+
locales: undefined,
|
|
60
|
+
options: { granularity: "grapheme" }
|
|
61
|
+
) => GraphemeSegmenter
|
|
62
|
+
}
|
|
63
|
+
).Segmenter
|
|
64
|
+
segmenter = Segmenter
|
|
65
|
+
? new Segmenter(undefined, { granularity: "grapheme" })
|
|
66
|
+
: null
|
|
67
|
+
}
|
|
68
|
+
return segmenter
|
|
69
|
+
? Array.from(segmenter.segment(text), (entry) => entry.segment)
|
|
70
|
+
: Array.from(text)
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Keys are grapheme + occurrence index, so the second "s" in "accessible" is a distinct,
|
|
75
|
+
* stable identity from the first. Without the occurrence counter, React reuses the
|
|
76
|
+
* wrong node and characters teleport instead of sliding.
|
|
77
|
+
*/
|
|
78
|
+
function toCharacters(text: string) {
|
|
79
|
+
const seen: Record<string, number> = {}
|
|
80
|
+
return toGraphemes(text).map((char) => {
|
|
81
|
+
seen[char] = (seen[char] ?? 0) + 1
|
|
82
|
+
return { key: `${char}-${seen[char]}`, char }
|
|
83
|
+
})
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
interface MorphPhase {
|
|
87
|
+
/** The string the character layer is rendering. */
|
|
88
|
+
text: string
|
|
89
|
+
/** Whether the character layer is mounted at all. */
|
|
90
|
+
split: boolean
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* Text is content, not decoration. Held permanently in one element per character it
|
|
95
|
+
* stops being selectable, findable with the browser's find-in-page, wrappable at word
|
|
96
|
+
* boundaries, and pronounceable — a screen reader spells it out. So the split exists
|
|
97
|
+
* only for the length of the morph and the resting DOM is a single text node.
|
|
98
|
+
*
|
|
99
|
+
* Getting there costs two commits. `AnimatePresence` can only animate an exit for a
|
|
100
|
+
* child it rendered on the previous pass, so the first commit mounts the *outgoing*
|
|
101
|
+
* string as characters and a layout effect swaps in the incoming one. Layout effects
|
|
102
|
+
* flush before paint, so the intermediate frame is never shown.
|
|
103
|
+
*/
|
|
104
|
+
function useMorphPhase(
|
|
105
|
+
text: string,
|
|
106
|
+
enabled: boolean,
|
|
107
|
+
settleMs: number
|
|
108
|
+
): MorphPhase {
|
|
109
|
+
const [phase, setPhase] = React.useState<MorphPhase>({ text, split: false })
|
|
110
|
+
|
|
111
|
+
if (enabled && !phase.split && phase.text !== text) {
|
|
112
|
+
setPhase({ text: phase.text, split: true })
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
useIsomorphicLayoutEffect(() => {
|
|
116
|
+
if (!enabled) {
|
|
117
|
+
if (phase.split || phase.text !== text) setPhase({ text, split: false })
|
|
118
|
+
return
|
|
119
|
+
}
|
|
120
|
+
if (phase.split && phase.text !== text) setPhase({ text, split: true })
|
|
121
|
+
}, [enabled, phase, text])
|
|
122
|
+
|
|
123
|
+
React.useEffect(() => {
|
|
124
|
+
if (!enabled || !phase.split || phase.text !== text) return
|
|
125
|
+
const id = window.setTimeout(() => setPhase({ text, split: false }), settleMs)
|
|
126
|
+
// Cleared whenever the target changes again, so a morph interrupted mid-flight
|
|
127
|
+
// restarts the settle instead of collapsing to a text node under its own feet.
|
|
128
|
+
return () => window.clearTimeout(id)
|
|
129
|
+
}, [enabled, phase, text, settleMs])
|
|
130
|
+
|
|
131
|
+
return phase
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
export interface TextMorphProps
|
|
135
|
+
extends Omit<React.ComponentProps<typeof motion.span>, "children"> {
|
|
136
|
+
/** The text to display. Changing it triggers the morph. */
|
|
137
|
+
children: string
|
|
138
|
+
/** Blur radius in px on entering and exiting characters. */
|
|
139
|
+
blur?: number
|
|
140
|
+
/** Vertical travel in px for entering and exiting characters. */
|
|
141
|
+
distance?: number
|
|
142
|
+
/** Seconds. Keep it under 0.3 — this is a content change, not a transition the
|
|
143
|
+
* reader should have to sit through. */
|
|
144
|
+
duration?: number
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
/**
|
|
148
|
+
* Text that morphs character by character.
|
|
149
|
+
*
|
|
150
|
+
* Characters present in both strings keep their identity and slide to their new
|
|
151
|
+
* positions; only the genuine additions and removals fade. `mode="popLayout"` pulls
|
|
152
|
+
* exiting characters out of flow immediately, so the survivors start closing the gap
|
|
153
|
+
* on the same frame rather than waiting for the exit to finish.
|
|
154
|
+
*
|
|
155
|
+
* There is no per-character stagger. At the 30–80ms that reads as a cascade, a ten
|
|
156
|
+
* character word spends 270–720ms on the stagger alone before its last character has
|
|
157
|
+
* even begun — several times the budget for a UI transition. Anything short enough to
|
|
158
|
+
* stay inside the budget lands below a frame of separation, which is no stagger at all.
|
|
159
|
+
*/
|
|
160
|
+
const TextMorph = React.forwardRef<HTMLSpanElement, TextMorphProps>(
|
|
161
|
+
(
|
|
162
|
+
{ children, blur = 2, distance = 8, duration = 0.25, className, ...props },
|
|
163
|
+
ref
|
|
164
|
+
) => {
|
|
165
|
+
const reducedMotion = useReducedMotionConfig()
|
|
166
|
+
// A little past the animation, so the characters are never stitched back into a
|
|
167
|
+
// text node while one of them is still moving.
|
|
168
|
+
const settleMs = Math.round(duration * 1000) + 60
|
|
169
|
+
const phase = useMorphPhase(children, !reducedMotion, settleMs)
|
|
170
|
+
|
|
171
|
+
const { enter, exit, move } = React.useMemo(
|
|
172
|
+
() => ({
|
|
173
|
+
enter: { duration, ease: EASE_OUT } as Transition,
|
|
174
|
+
exit: { duration: duration * EXIT_RATIO, ease: EASE_OUT } as Transition,
|
|
175
|
+
move: { duration, ease: EASE_IN_OUT } as Transition,
|
|
176
|
+
}),
|
|
177
|
+
[duration]
|
|
178
|
+
)
|
|
179
|
+
|
|
180
|
+
const characters = React.useMemo(
|
|
181
|
+
() => (phase.split ? toCharacters(phase.text) : []),
|
|
182
|
+
[phase.split, phase.text]
|
|
183
|
+
)
|
|
184
|
+
|
|
185
|
+
if (reducedMotion) {
|
|
186
|
+
return (
|
|
187
|
+
<motion.span
|
|
188
|
+
ref={ref}
|
|
189
|
+
className={cn("relative inline-block", className)}
|
|
190
|
+
{...props}
|
|
191
|
+
>
|
|
192
|
+
{/* Travel and blur are what the preference asks us to drop. The crossfade
|
|
193
|
+
stays, so the change still reads as one word becoming another rather
|
|
194
|
+
than as a blink. */}
|
|
195
|
+
<AnimatePresence mode="popLayout" initial={false}>
|
|
196
|
+
<motion.span
|
|
197
|
+
key={children}
|
|
198
|
+
initial={{ opacity: 0 }}
|
|
199
|
+
animate={{ opacity: 1 }}
|
|
200
|
+
exit={{ opacity: 0 }}
|
|
201
|
+
transition={{ duration: REDUCED_DURATION, ease: EASE_OUT }}
|
|
202
|
+
>
|
|
203
|
+
{children}
|
|
204
|
+
</motion.span>
|
|
205
|
+
</AnimatePresence>
|
|
206
|
+
</motion.span>
|
|
207
|
+
)
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
return (
|
|
211
|
+
<motion.span
|
|
212
|
+
ref={ref}
|
|
213
|
+
layout
|
|
214
|
+
transition={move}
|
|
215
|
+
className={cn(
|
|
216
|
+
// `relative` because `popLayout` positions exiting characters absolutely
|
|
217
|
+
// against the nearest positioned ancestor — without it they anchor outside
|
|
218
|
+
// the word and jump the moment the layout animation transforms the wrapper.
|
|
219
|
+
// `inline-block` rather than `inline-flex`: a flex container never wraps, so
|
|
220
|
+
// a long string would run out of its column. Kerning and ligatures are off in
|
|
221
|
+
// both states because a run of one-character boxes cannot kern; matching the
|
|
222
|
+
// resting text node to that is what stops the word twitching width each time
|
|
223
|
+
// the characters are stitched back together.
|
|
224
|
+
"relative inline-block [font-kerning:none] [font-variant-ligatures:none]",
|
|
225
|
+
className
|
|
226
|
+
)}
|
|
227
|
+
{...props}
|
|
228
|
+
>
|
|
229
|
+
{phase.split ? (
|
|
230
|
+
<>
|
|
231
|
+
<AnimatePresence mode="popLayout" initial={false}>
|
|
232
|
+
{characters.map(({ key, char }) => (
|
|
233
|
+
<motion.span
|
|
234
|
+
key={key}
|
|
235
|
+
layout
|
|
236
|
+
aria-hidden
|
|
237
|
+
className="inline-block whitespace-pre"
|
|
238
|
+
initial={{ opacity: 0, filter: `blur(${blur}px)`, y: distance }}
|
|
239
|
+
animate={{ opacity: 1, filter: "blur(0px)", y: 0 }}
|
|
240
|
+
exit={{
|
|
241
|
+
opacity: 0,
|
|
242
|
+
filter: `blur(${blur}px)`,
|
|
243
|
+
y: -distance,
|
|
244
|
+
transition: exit,
|
|
245
|
+
}}
|
|
246
|
+
transition={{ default: enter, layout: move }}
|
|
247
|
+
>
|
|
248
|
+
{char}
|
|
249
|
+
</motion.span>
|
|
250
|
+
))}
|
|
251
|
+
</AnimatePresence>
|
|
252
|
+
{/* The characters are decorative for as long as they are moving; this is
|
|
253
|
+
what a screen reader announces during the morph. */}
|
|
254
|
+
<span className="sr-only">{children}</span>
|
|
255
|
+
</>
|
|
256
|
+
) : (
|
|
257
|
+
children
|
|
258
|
+
)}
|
|
259
|
+
</motion.span>
|
|
260
|
+
)
|
|
261
|
+
}
|
|
262
|
+
)
|
|
263
|
+
TextMorph.displayName = "TextMorph"
|
|
264
|
+
|
|
265
|
+
export { TextMorph }
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
"use client"
|
|
2
|
+
|
|
3
|
+
import * as React from "react"
|
|
4
|
+
import { MotionConfigContext, useReducedMotion } from "motion/react"
|
|
5
|
+
import { cn } from "@/lib/utils"
|
|
6
|
+
|
|
7
|
+
/** `useReducedMotion` reads the OS setting only, and only at mount. Also honour an
|
|
8
|
+
* app-level `<MotionConfig reducedMotion>`, so a user preference in the host app
|
|
9
|
+
* reaches this component. */
|
|
10
|
+
function useReducedMotionConfig() {
|
|
11
|
+
const config = React.useContext(MotionConfigContext)
|
|
12
|
+
const prefersReduced = useReducedMotion()
|
|
13
|
+
if (config.reducedMotion === "always") return true
|
|
14
|
+
if (config.reducedMotion === "never") return false
|
|
15
|
+
return prefersReduced
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export type TextShimmerVariant = "sweep" | "pulse"
|
|
19
|
+
|
|
20
|
+
/** Seconds for one loop. These are cycle lengths for ambient motion, not durations
|
|
21
|
+
* for a transition answering an input, so the sub-300ms UI budget does not apply —
|
|
22
|
+
* at that length either variant would strobe. `pulse` runs the slower of the two
|
|
23
|
+
* because a whole label changing brightness is more noticeable than a band crossing
|
|
24
|
+
* it, and the quieter effect is the one that can afford to be seen less often. */
|
|
25
|
+
const DEFAULT_DURATION: Record<TextShimmerVariant, number> = {
|
|
26
|
+
sweep: 1.6,
|
|
27
|
+
pulse: 1.8,
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export interface TextShimmerProps extends React.ComponentPropsWithoutRef<"span"> {
|
|
31
|
+
/** Which effect to run. See each variant's note on the component. */
|
|
32
|
+
variant?: TextShimmerVariant
|
|
33
|
+
/** Seconds for one cycle. Defaults per variant. */
|
|
34
|
+
duration?: number
|
|
35
|
+
/** How dim the un-lit text is, 0–1. This is a label the user is waiting on, not a
|
|
36
|
+
* placeholder, so it has to stay readable at this value. */
|
|
37
|
+
dim?: number
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* A shimmer for pending states where a spinner would be too loud — "Thinking…",
|
|
42
|
+
* "Generating…". Signalling that something is in flight is the whole of what it is
|
|
43
|
+
* for. It loops for as long as it is mounted, in the corner of the user's eye, so
|
|
44
|
+
* mount it when the work starts and unmount it when the work lands; a loop running
|
|
45
|
+
* over settled text is noise, and no amount of tuning makes decoration justify a
|
|
46
|
+
* permanent animation.
|
|
47
|
+
*
|
|
48
|
+
* - `sweep` — a soft highlight band travelling across the text. The default.
|
|
49
|
+
* - `pulse` — the whole label breathes between dim and lit. Quieter, and free: it
|
|
50
|
+
* animates opacity and nothing else. Prefer it in dense or small text, where a
|
|
51
|
+
* band is too subtle to read anyway.
|
|
52
|
+
*
|
|
53
|
+
* Both are built from `currentColor`, so they inherit the surrounding text colour and
|
|
54
|
+
* theme themselves. `sweep` paints the highlight through `background-clip: text`, and
|
|
55
|
+
* clears the fill with `-webkit-text-fill-color` rather than `color: transparent` —
|
|
56
|
+
* the gradient is made of `currentColor`, so zeroing `color` would erase it.
|
|
57
|
+
*
|
|
58
|
+
* `sweep` moves that gradient with `background-position`, which the compositor cannot
|
|
59
|
+
* accelerate. There is no transform-only equivalent: a gradient is fixed to the box
|
|
60
|
+
* painting it, so translating the box carries the highlight and the glyphs together,
|
|
61
|
+
* and masking a duplicate of the text does not help because a mask travels with its
|
|
62
|
+
* element too. What is avoidable is the per-frame JavaScript, so the loop is driven
|
|
63
|
+
* through the Web Animations API instead of a rAF loop — the browser owns the
|
|
64
|
+
* timeline, and a busy main thread no longer costs frames during exactly the pending
|
|
65
|
+
* work this is reporting on. The repaint that remains is bounded by the element's
|
|
66
|
+
* box: keep this on label-sized text, never a paragraph.
|
|
67
|
+
*
|
|
68
|
+
* Under reduced motion the loop does not run at all. A continuous ambient animation
|
|
69
|
+
* has no gentler version worth keeping — but the dim colour stays, so the label still
|
|
70
|
+
* reads as unsettled rather than as ordinary prose.
|
|
71
|
+
*/
|
|
72
|
+
const TextShimmer = React.forwardRef<HTMLSpanElement, TextShimmerProps>(
|
|
73
|
+
(
|
|
74
|
+
{
|
|
75
|
+
variant = "sweep",
|
|
76
|
+
duration,
|
|
77
|
+
dim = 0.7,
|
|
78
|
+
className,
|
|
79
|
+
style,
|
|
80
|
+
children,
|
|
81
|
+
...props
|
|
82
|
+
},
|
|
83
|
+
ref
|
|
84
|
+
) => {
|
|
85
|
+
const reducedMotion = useReducedMotionConfig()
|
|
86
|
+
const nodeRef = React.useRef<HTMLSpanElement>(null)
|
|
87
|
+
React.useImperativeHandle(ref, () => nodeRef.current as HTMLSpanElement, [])
|
|
88
|
+
|
|
89
|
+
const seconds = duration ?? DEFAULT_DURATION[variant]
|
|
90
|
+
|
|
91
|
+
React.useEffect(() => {
|
|
92
|
+
const node = nodeRef.current
|
|
93
|
+
if (!node || reducedMotion) return
|
|
94
|
+
|
|
95
|
+
const animation = node.animate(
|
|
96
|
+
variant === "pulse"
|
|
97
|
+
? [{ opacity: 1 }, { opacity: dim }, { opacity: 1 }]
|
|
98
|
+
: // The gradient is `base` at both 0% and 100%, so it tiles without a seam,
|
|
99
|
+
// and percentage positions resolve against (element − image) width — which
|
|
100
|
+
// is -W here, since the image is 2W wide. So a 200% change moves the image
|
|
101
|
+
// by exactly one tile and lands on an identical frame: the loop closes on
|
|
102
|
+
// itself, with no jump to hide and no dead time to pad.
|
|
103
|
+
[
|
|
104
|
+
{ backgroundPosition: "0% center" },
|
|
105
|
+
{ backgroundPosition: "-200% center" },
|
|
106
|
+
],
|
|
107
|
+
{
|
|
108
|
+
duration: seconds * 1000,
|
|
109
|
+
iterations: Infinity,
|
|
110
|
+
// Constant motion takes a linear curve. On `sweep` it is also structural:
|
|
111
|
+
// an eased curve would visibly hitch every time the tile seam came round.
|
|
112
|
+
easing: "linear",
|
|
113
|
+
}
|
|
114
|
+
)
|
|
115
|
+
return () => animation.cancel()
|
|
116
|
+
}, [variant, dim, seconds, reducedMotion])
|
|
117
|
+
|
|
118
|
+
const base = `color-mix(in oklab, currentColor ${Math.round(dim * 100)}%, transparent)`
|
|
119
|
+
|
|
120
|
+
const shimmerStyle: React.CSSProperties = reducedMotion
|
|
121
|
+
? { opacity: dim }
|
|
122
|
+
: variant === "pulse"
|
|
123
|
+
? {}
|
|
124
|
+
: {
|
|
125
|
+
backgroundImage: `linear-gradient(90deg, ${base} 35%, currentColor 50%, ${base} 65%)`,
|
|
126
|
+
backgroundSize: "200% 100%",
|
|
127
|
+
backgroundRepeat: "repeat",
|
|
128
|
+
backgroundClip: "text",
|
|
129
|
+
WebkitBackgroundClip: "text",
|
|
130
|
+
WebkitTextFillColor: "transparent",
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
return (
|
|
134
|
+
<span
|
|
135
|
+
ref={nodeRef}
|
|
136
|
+
// The element is reporting a pending state, so assistive tech should read it
|
|
137
|
+
// as one. It also makes the decorative use of a shimmer feel as wrong in the
|
|
138
|
+
// markup as it is on screen.
|
|
139
|
+
role="status"
|
|
140
|
+
className={cn("inline-block", className)}
|
|
141
|
+
style={{ ...shimmerStyle, ...style }}
|
|
142
|
+
{...props}
|
|
143
|
+
>
|
|
144
|
+
{children}
|
|
145
|
+
</span>
|
|
146
|
+
)
|
|
147
|
+
}
|
|
148
|
+
)
|
|
149
|
+
TextShimmer.displayName = "TextShimmer"
|
|
150
|
+
|
|
151
|
+
export { TextShimmer }
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import * as React from "react"
|
|
2
2
|
import { cn } from "@/lib/utils"
|
|
3
3
|
|
|
4
|
-
export
|
|
5
|
-
extends React.TextareaHTMLAttributes<HTMLTextAreaElement> {}
|
|
4
|
+
export type TextareaProps = React.TextareaHTMLAttributes<HTMLTextAreaElement>
|
|
6
5
|
|
|
7
6
|
const Textarea = React.forwardRef<HTMLTextAreaElement, TextareaProps>(
|
|
8
7
|
({ className, ...props }, ref) => {
|
|
@@ -9,20 +9,23 @@ import { XIcon } from "lucide-react";
|
|
|
9
9
|
// Toast Provider
|
|
10
10
|
const ToastProvider = BaseToast.Provider;
|
|
11
11
|
|
|
12
|
+
export type ToastViewportProps = React.ComponentProps<
|
|
13
|
+
typeof BaseToast.Viewport
|
|
14
|
+
>;
|
|
15
|
+
|
|
12
16
|
// Toast Viewport
|
|
13
|
-
const ToastViewport = React.forwardRef<
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
));
|
|
17
|
+
const ToastViewport = React.forwardRef<HTMLDivElement, ToastViewportProps>(
|
|
18
|
+
({ className, ...props }, ref) => (
|
|
19
|
+
<BaseToast.Viewport
|
|
20
|
+
ref={ref}
|
|
21
|
+
className={cn(
|
|
22
|
+
"fixed z-10 top-auto right-4 bottom-4 mx-auto flex w-[250px] sm:right-8 sm:bottom-8 sm:w-[300px]",
|
|
23
|
+
className
|
|
24
|
+
)}
|
|
25
|
+
{...props}
|
|
26
|
+
/>
|
|
27
|
+
)
|
|
28
|
+
);
|
|
26
29
|
ToastViewport.displayName = "ToastViewport";
|
|
27
30
|
|
|
28
31
|
// Toast Portal
|
|
@@ -43,8 +46,9 @@ const toastVariants = cva(
|
|
|
43
46
|
"[transform:translateX(var(--toast-swipe-movement-x))_translateY(calc(var(--toast-swipe-movement-y)-(var(--toast-index)*var(--peek))-(var(--shrink)*var(--height))))_scale(var(--scale))]",
|
|
44
47
|
// Height management (collapse to frontmost height)
|
|
45
48
|
"h-[var(--height)]",
|
|
46
|
-
// Appearance
|
|
47
|
-
|
|
49
|
+
// Appearance. No `overflow-hidden` here: the gap pseudo-element below sits past the
|
|
50
|
+
// card's bottom edge, and clipping it breaks the reach between stacked toasts.
|
|
51
|
+
"origin-bottom cursor-default rounded-xl border bg-clip-padding bg-background p-4 shadow-lg select-none",
|
|
48
52
|
// Transition (includes height for expand/collapse animation)
|
|
49
53
|
"[transition:transform_0.5s_cubic-bezier(0.22,1,0.36,1),opacity_0.5s,height_0.15s]",
|
|
50
54
|
// Gap pseudo-element for hover detection between stacked toasts
|
|
@@ -130,7 +134,9 @@ const ToastDescription = React.forwardRef<
|
|
|
130
134
|
));
|
|
131
135
|
ToastDescription.displayName = "ToastDescription";
|
|
132
136
|
|
|
133
|
-
// Toast Content
|
|
137
|
+
// Toast Content — the row inside the card, and what fades while the toast is behind another.
|
|
138
|
+
// `pr-6` keeps the row clear of the close button, which is positioned against the card
|
|
139
|
+
// rather than laid out in the row, so nothing here would otherwise leave it room.
|
|
134
140
|
const ToastContent = React.forwardRef<
|
|
135
141
|
HTMLDivElement,
|
|
136
142
|
React.ComponentProps<typeof BaseToast.Content>
|
|
@@ -138,7 +144,7 @@ const ToastContent = React.forwardRef<
|
|
|
138
144
|
<BaseToast.Content
|
|
139
145
|
ref={ref}
|
|
140
146
|
className={cn(
|
|
141
|
-
"overflow-hidden transition-opacity [transition-duration:250ms]",
|
|
147
|
+
"flex items-start gap-3 overflow-hidden pr-6 transition-opacity [transition-duration:250ms]",
|
|
142
148
|
"data-[behind]:pointer-events-none data-[behind]:opacity-0",
|
|
143
149
|
"data-[expanded]:pointer-events-auto data-[expanded]:opacity-100",
|
|
144
150
|
className
|
|
@@ -159,7 +165,6 @@ const ToastAction = React.forwardRef<
|
|
|
159
165
|
"inline-flex h-8 shrink-0 items-center justify-center rounded-md border bg-transparent px-3 text-sm font-medium transition-colors",
|
|
160
166
|
"hover:bg-secondary focus:outline-none focus:ring-1 focus:ring-ring",
|
|
161
167
|
"disabled:pointer-events-none disabled:opacity-50",
|
|
162
|
-
"group-[.destructive]:border-muted/40 group-[.destructive]:hover:border-destructive/30 group-[.destructive]:hover:bg-destructive group-[.destructive]:hover:text-destructive-foreground group-[.destructive]:focus:ring-destructive",
|
|
163
168
|
className
|
|
164
169
|
)}
|
|
165
170
|
{...props}
|
|
@@ -268,7 +273,7 @@ function ToastList({ renderToast }: { renderToast?: RenderToastFn }) {
|
|
|
268
273
|
renderToast(toast)
|
|
269
274
|
) : (
|
|
270
275
|
<ToastContent>
|
|
271
|
-
<div className="grid gap-1">
|
|
276
|
+
<div className="grid flex-1 gap-1">
|
|
272
277
|
{toast.title && <ToastTitle>{toast.title}</ToastTitle>}
|
|
273
278
|
{toast.description && (
|
|
274
279
|
<ToastDescription>{toast.description}</ToastDescription>
|
|
@@ -8,7 +8,7 @@ import { cn } from "@/lib/utils"
|
|
|
8
8
|
const toggleVariants = cva(
|
|
9
9
|
[
|
|
10
10
|
"inline-flex items-center justify-center rounded-md text-sm font-medium",
|
|
11
|
-
"ring-offset-background transition-
|
|
11
|
+
"ring-offset-background transition-colors duration-[var(--motion-duration-fast,150ms)]",
|
|
12
12
|
"focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2",
|
|
13
13
|
"disabled:pointer-events-none disabled:opacity-50",
|
|
14
14
|
"data-[disabled]:pointer-events-none data-[disabled]:opacity-50",
|
|
@@ -60,10 +60,16 @@ const TooltipPopup: React.ForwardRefExoticComponent<
|
|
|
60
60
|
<BaseTooltip.Popup
|
|
61
61
|
ref={ref}
|
|
62
62
|
className={cn(
|
|
63
|
-
"origin-(--transform-origin) rounded-md px-3 py-1.5 text-sm shadow-md",
|
|
64
|
-
"transition-[transform,scale,opacity] duration-
|
|
65
|
-
"data-ending-style:scale-95 data-ending-style:opacity-0",
|
|
66
|
-
"data-starting-style:scale-95 data-starting-style:opacity-0",
|
|
63
|
+
"origin-[var(--transform-origin)] rounded-md px-3 py-1.5 text-sm shadow-md",
|
|
64
|
+
"transition-[transform,scale,opacity] duration-[var(--motion-duration-fast,150ms)] ease-[var(--motion-ease-out,cubic-bezier(0.23,1,0.32,1))]",
|
|
65
|
+
"data-[ending-style]:scale-95 data-[ending-style]:opacity-0",
|
|
66
|
+
"data-[starting-style]:scale-95 data-[starting-style]:opacity-0",
|
|
67
|
+
"motion-reduce:data-[starting-style]:scale-100 motion-reduce:data-[ending-style]:scale-100",
|
|
68
|
+
// Base UI sets data-instant when the open came from an adjacent trigger while a
|
|
69
|
+
// tooltip was already up, from keyboard focus, or from Escape. All three are
|
|
70
|
+
// cases where the animation is the only thing standing between the user and the
|
|
71
|
+
// content they asked for.
|
|
72
|
+
"data-[instant]:duration-0",
|
|
67
73
|
variantStyles[variant],
|
|
68
74
|
className
|
|
69
75
|
)}
|
package/templates/tsconfig.json
CHANGED
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
// This file can contain shared utilities that are NOT component-specific
|
|
2
|
-
// Following shadcn pattern, component variants are embedded in each component
|
|
3
|
-
|
|
4
|
-
// Re-export common types that components might need
|
|
5
|
-
export type { VariantProps } from 'class-variance-authority'
|
|
6
|
-
export { cva } from 'class-variance-authority'
|