@dinachi/cli 0.8.2 → 0.10.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.
Files changed (52) hide show
  1. package/CHANGELOG.md +144 -0
  2. package/README.md +36 -5
  3. package/dist/index.js +336 -62
  4. package/package.json +17 -14
  5. package/templates/animated-icon/animated-icon.tsx +145 -0
  6. package/templates/animated-icon/index.ts +1 -0
  7. package/templates/animated-list/animated-list.tsx +161 -0
  8. package/templates/animated-list/index.ts +2 -0
  9. package/templates/animated-tabs/animated-tabs.tsx +244 -0
  10. package/templates/animated-tabs/index.ts +13 -0
  11. package/templates/badge/badge.tsx +4 -4
  12. package/templates/carousel/carousel.tsx +492 -0
  13. package/templates/carousel/index.ts +1 -0
  14. package/templates/compare-slider/compare-slider.tsx +383 -0
  15. package/templates/compare-slider/index.ts +2 -0
  16. package/templates/expandable-card/expandable-card.tsx +509 -0
  17. package/templates/expandable-card/index.ts +1 -0
  18. package/templates/hold-to-confirm/hold-to-confirm.tsx +573 -0
  19. package/templates/hold-to-confirm/index.ts +2 -0
  20. package/templates/load-transition/index.ts +1 -0
  21. package/templates/load-transition/load-transition.tsx +163 -0
  22. package/templates/marquee/index.ts +2 -0
  23. package/templates/marquee/marquee.tsx +256 -0
  24. package/templates/number-ticker/index.ts +2 -0
  25. package/templates/number-ticker/number-ticker.tsx +470 -0
  26. package/templates/otp-field/index.ts +1 -0
  27. package/templates/otp-field/otp-field.tsx +72 -0
  28. package/templates/progress-ring/index.ts +1 -0
  29. package/templates/progress-ring/progress-ring.tsx +268 -0
  30. package/templates/scroll-progress/index.ts +2 -0
  31. package/templates/scroll-progress/scroll-progress.tsx +147 -0
  32. package/templates/scroll-reveal/index.ts +2 -0
  33. package/templates/scroll-reveal/scroll-reveal.tsx +198 -0
  34. package/templates/select/select.tsx +4 -2
  35. package/templates/slider/slider.tsx +1 -1
  36. package/templates/sortable/index.ts +1 -0
  37. package/templates/sortable/sortable.tsx +349 -0
  38. package/templates/stagger-list/index.ts +2 -0
  39. package/templates/stagger-list/stagger-list.tsx +204 -0
  40. package/templates/streaming-text/index.ts +2 -0
  41. package/templates/streaming-text/streaming-text.tsx +220 -0
  42. package/templates/swipeable-row/index.ts +2 -0
  43. package/templates/swipeable-row/swipeable-row.tsx +368 -0
  44. package/templates/text-morph/index.ts +2 -0
  45. package/templates/text-morph/text-morph.tsx +265 -0
  46. package/templates/text-shimmer/index.ts +2 -0
  47. package/templates/text-shimmer/text-shimmer.tsx +151 -0
  48. package/templates/textarea/textarea.tsx +1 -2
  49. package/templates/toast/toast.tsx +24 -19
  50. package/templates/tsconfig.json +1 -0
  51. package/LICENSE +0 -21
  52. package/templates/utils/variants.ts +0 -6
@@ -0,0 +1,268 @@
1
+ "use client"
2
+
3
+ import * as React from "react"
4
+ import {
5
+ motion,
6
+ MotionConfigContext,
7
+ useMotionValue,
8
+ useReducedMotion,
9
+ useSpring,
10
+ useTransform,
11
+ } from "motion/react"
12
+ import { cn } from "@/lib/utils"
13
+
14
+ /** `useReducedMotion` reads the OS setting only, and only at mount. Also honour an
15
+ * app-level `<MotionConfig reducedMotion>`, so a user preference in the host app
16
+ * reaches this component. */
17
+ function useReducedMotionConfig() {
18
+ const config = React.useContext(MotionConfigContext)
19
+ const prefersReduced = useReducedMotion()
20
+ if (config.reducedMotion === "always") return true
21
+ if (config.reducedMotion === "never") return false
22
+ return prefersReduced ?? false
23
+ }
24
+
25
+ /** Apple's move-and-reposition spring, the same one the number ticker uses, so a ring and
26
+ * a count beside it travel on one clock. */
27
+ const SETTLE = { duration: 400, bounce: 0 } as const
28
+
29
+ const DEFAULT_SIZE = 96
30
+
31
+ export interface ProgressRingProps
32
+ extends Omit<React.ComponentProps<"div">, "children"> {
33
+ /** 0–100. Omit it for the indeterminate arc. */
34
+ value?: number
35
+ /** Accessible name. Defaults to "Progress", or "Loading" when indeterminate. */
36
+ label?: string
37
+ /** Outer diameter in px. */
38
+ size?: number
39
+ /** Stroke width in px. Scales with `size` unless given. */
40
+ thickness?: number
41
+ /** Show the percentage in the middle. Ignored when indeterminate — there is no number
42
+ * to show. */
43
+ showValue?: boolean
44
+ }
45
+
46
+ /**
47
+ * A radial progress arc.
48
+ *
49
+ * The value is driven through a spring rather than a tween, which matters more here than it
50
+ * looks: progress arrives in jumps, and a tween restarted on every jump either stutters or
51
+ * has to be cancelled and rebuilt. A spring re-targets from wherever the arc currently is
52
+ * and carries its velocity across, so a fast run of updates reads as one accelerating sweep
53
+ * instead of a series of separate moves.
54
+ *
55
+ * One honest caveat: the arc is `stroke-dashoffset`, which is not a compositor property. At
56
+ * this size that is fine — one small element repainting a stroke. Forty of them on a page
57
+ * would be a different conversation, and the alternative is a rotated half-disc mask that
58
+ * animates on `transform` but cannot do a rounded cap cleanly.
59
+ */
60
+ const ProgressRing = React.forwardRef<HTMLDivElement, ProgressRingProps>(
61
+ // Two independent contracts, determinate-or-not and reduced-motion-or-not, and every
62
+ // branch is one of the four combinations. Splitting the render in two would duplicate
63
+ // the ring to separate the arc.
64
+ // fallow-ignore-next-line complexity
65
+ (
66
+ {
67
+ value,
68
+ label,
69
+ size = DEFAULT_SIZE,
70
+ thickness,
71
+ showValue = true,
72
+ className,
73
+ ...props
74
+ },
75
+ ref
76
+ ) => {
77
+ const reducedMotion = useReducedMotionConfig()
78
+ const indeterminate = value === undefined
79
+
80
+ // A ring twice the size with the same 8px stroke reads as a thinner ring, not a bigger
81
+ // one. Proportional is the default; an explicit `thickness` wins.
82
+ const stroke = thickness ?? Math.max(3, Math.round(size * 0.085))
83
+ const radius = (size - stroke) / 2
84
+ const circumference = 2 * Math.PI * radius
85
+
86
+ const offsetFor = (v: number) =>
87
+ circumference - (Math.min(Math.max(v, 0), 100) / 100) * circumference
88
+
89
+ const target = useMotionValue(value ?? 0)
90
+ React.useEffect(() => {
91
+ if (value !== undefined) target.set(value)
92
+ }, [value, target])
93
+
94
+ const eased = useSpring(target, SETTLE)
95
+ const offset = useTransform(eased, offsetFor)
96
+ const readout = useTransform(eased, (v) => `${Math.round(v)}%`)
97
+
98
+ // The arc starts at twelve o'clock either way. Rotating the whole SVG is a transform,
99
+ // so the sweep costs nothing, unlike re-deriving the path.
100
+ const spin =
101
+ indeterminate && !reducedMotion
102
+ ? {
103
+ animate: { rotate: [-90, 270] },
104
+ transition: {
105
+ duration: 1.4,
106
+ repeat: Infinity,
107
+ ease: "linear" as const,
108
+ },
109
+ }
110
+ : { animate: { rotate: -90 }, transition: { duration: 0 } }
111
+
112
+ // An indeterminate ring has no value to report, so it is a live region rather than a
113
+ // progressbar. A `progressbar` with no `aria-valuenow` is announced as 0%, which is a
114
+ // worse answer than "loading".
115
+ const rounded = Math.round(value ?? 0)
116
+ const reported = indeterminate
117
+ ? { role: "status" as const }
118
+ : {
119
+ role: "progressbar" as const,
120
+ "aria-valuenow": rounded,
121
+ "aria-valuemin": 0,
122
+ "aria-valuemax": 100,
123
+ "aria-valuetext": `${rounded} percent`,
124
+ }
125
+
126
+ return (
127
+ <div
128
+ ref={ref}
129
+ className={cn("relative", className)}
130
+ style={{ width: size, height: size }}
131
+ {...props}
132
+ >
133
+ <motion.svg
134
+ width={size}
135
+ height={size}
136
+ {...spin}
137
+ {...reported}
138
+ aria-label={label ?? (indeterminate ? "Loading" : "Progress")}
139
+ >
140
+ <circle
141
+ cx={size / 2}
142
+ cy={size / 2}
143
+ r={radius}
144
+ fill="none"
145
+ strokeWidth={stroke}
146
+ className="stroke-muted"
147
+ />
148
+
149
+ {indeterminate ? (
150
+ <IndeterminateArc
151
+ cx={size / 2}
152
+ cy={size / 2}
153
+ r={radius}
154
+ stroke={stroke}
155
+ circumference={circumference}
156
+ reducedMotion={reducedMotion}
157
+ />
158
+ ) : (
159
+ <motion.circle
160
+ cx={size / 2}
161
+ cy={size / 2}
162
+ r={radius}
163
+ fill="none"
164
+ strokeWidth={stroke}
165
+ strokeLinecap="round"
166
+ strokeDasharray={circumference}
167
+ // Reduced motion means the arc reports the value rather than travelling to
168
+ // it. The spring is still constructed — it is a hook — but nothing reads it,
169
+ // so the arc and the number land together in one frame.
170
+ strokeDashoffset={reducedMotion ? offsetFor(value ?? 0) : offset}
171
+ className="stroke-primary"
172
+ />
173
+ )}
174
+ </motion.svg>
175
+
176
+ {!indeterminate && showValue ? (
177
+ <div className="absolute inset-0 flex items-center justify-center">
178
+ {/* The number reads the same spring as the arc, so the two can never
179
+ disagree. */}
180
+ <motion.span
181
+ aria-hidden
182
+ className="font-semibold tabular-nums text-foreground"
183
+ style={{ fontSize: Math.round(size * 0.19) }}
184
+ >
185
+ {reducedMotion ? `${rounded}%` : readout}
186
+ </motion.span>
187
+ </div>
188
+ ) : null}
189
+ </div>
190
+ )
191
+ }
192
+ )
193
+ ProgressRing.displayName = "ProgressRing"
194
+
195
+ /**
196
+ * The indeterminate arc grows and shrinks as it sweeps.
197
+ *
198
+ * A fixed arc spinning at a constant rate is a loading spinner, and it says only "still
199
+ * running". Letting the arc lengthen and shorten under the rotation is what makes it read
200
+ * as *work happening* rather than as a wheel turning: the sweep and the rotation are
201
+ * deliberately different lengths, so the pattern never lands in the same place twice in a
202
+ * row.
203
+ */
204
+ function IndeterminateArc({
205
+ cx,
206
+ cy,
207
+ r,
208
+ stroke,
209
+ circumference,
210
+ reducedMotion,
211
+ }: {
212
+ cx: number
213
+ cy: number
214
+ r: number
215
+ stroke: number
216
+ circumference: number
217
+ reducedMotion: boolean
218
+ }) {
219
+ if (reducedMotion) {
220
+ // No rotation, no sweep. A static gap still reads as "in progress" without anything
221
+ // moving — and an endlessly repeating animation is the one thing the preference most
222
+ // clearly means to stop.
223
+ return (
224
+ <circle
225
+ cx={cx}
226
+ cy={cy}
227
+ r={r}
228
+ fill="none"
229
+ strokeWidth={stroke}
230
+ strokeLinecap="round"
231
+ strokeDasharray={`${circumference * 0.25} ${circumference}`}
232
+ className="stroke-primary"
233
+ />
234
+ )
235
+ }
236
+
237
+ return (
238
+ <motion.circle
239
+ cx={cx}
240
+ cy={cy}
241
+ r={r}
242
+ fill="none"
243
+ strokeWidth={stroke}
244
+ strokeLinecap="round"
245
+ className="stroke-primary"
246
+ initial={{
247
+ strokeDasharray: `${circumference * 0.06} ${circumference}`,
248
+ strokeDashoffset: 0,
249
+ }}
250
+ animate={{
251
+ strokeDasharray: [
252
+ `${circumference * 0.06} ${circumference}`,
253
+ `${circumference * 0.65} ${circumference}`,
254
+ `${circumference * 0.06} ${circumference}`,
255
+ ],
256
+ strokeDashoffset: [0, -circumference * 0.2, -circumference * 0.95],
257
+ }}
258
+ transition={{
259
+ duration: 1.6,
260
+ repeat: Infinity,
261
+ ease: "easeInOut",
262
+ times: [0, 0.5, 1],
263
+ }}
264
+ />
265
+ )
266
+ }
267
+
268
+ export { ProgressRing }
@@ -0,0 +1,2 @@
1
+ export { ScrollProgress } from './scroll-progress'
2
+ export type { ScrollProgressProps, ScrollProgressContainer } from './scroll-progress'
@@ -0,0 +1,147 @@
1
+ "use client"
2
+
3
+ import * as React from "react"
4
+ import { motion, MotionConfigContext, useReducedMotion, useScroll, useSpring } 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
+ const useIsomorphicLayoutEffect =
19
+ typeof window !== "undefined" ? React.useLayoutEffect : React.useEffect
20
+
21
+ /** The critically damped UI spring — damping ratio 1.0, response 0.3s. The snappy end of
22
+ * the range, because a bar that trails the scroll thumb reads as broken rather than as
23
+ * smooth, and nothing here may bounce: overshoot on a progress bar claims progress the
24
+ * reader has not made.
25
+ *
26
+ * Written as physics rather than Motion's `duration`/`bounce` shorthand deliberately. A
27
+ * duration-defined spring zeroes the value's inherited velocity every time it re-targets,
28
+ * and this one re-targets on every scroll frame — the shorthand restarts the bar from
29
+ * rest continuously, so it can only ever lag. The physics form carries velocity across
30
+ * re-targets, which is what lets the bar run at the speed the reader is scrolling.
31
+ *
32
+ * Kept as the derivation (Motion's own response → stiffness conversion) so the damping
33
+ * ratio stays exactly 1 rather than drifting with a rounded literal. */
34
+ const RESPONSE_SECONDS = 0.3
35
+ const STIFFNESS = ((2 * Math.PI) / (RESPONSE_SECONDS * 1.2)) ** 2
36
+ const SPRING = {
37
+ stiffness: STIFFNESS,
38
+ damping: 2 * Math.sqrt(STIFFNESS),
39
+ mass: 1,
40
+ } as const
41
+
42
+ /** A ref to the scrollport, or a CSS selector for one. */
43
+ export type ScrollProgressContainer =
44
+ | React.RefObject<HTMLElement | null>
45
+ | string
46
+
47
+ /** A selector is accepted because an app whose scrollport lives in a server-rendered
48
+ * layout has nowhere to hang a ref. It resolves in a layout effect declared *before*
49
+ * `useScroll`, so the scroll listener attaches to the right element on the first commit;
50
+ * the node is in the DOM by then even when its own ref is not yet set. A selector that
51
+ * matches nothing falls back to the page rather than throwing.
52
+ *
53
+ * A ref is handed to `useScroll` untouched — an ancestor's ref is still empty while this
54
+ * component's layout effects run, and Motion already defers its listener by a phase to
55
+ * cover exactly that. */
56
+ function useScrollContainer(container?: ScrollProgressContainer) {
57
+ const [ref, setRef] = React.useState<React.RefObject<HTMLElement | null>>(
58
+ () => ({ current: null })
59
+ )
60
+
61
+ useIsomorphicLayoutEffect(() => {
62
+ if (typeof container !== "string") return
63
+
64
+ const resolved =
65
+ document.querySelector<HTMLElement>(container) ??
66
+ // `scrollingElement` is null in quirks mode, and the element it names is the
67
+ // documentElement everywhere else, so that is the fallback's fallback. Handing
68
+ // Motion an empty ref instead would throw.
69
+ (document.scrollingElement as HTMLElement | null) ??
70
+ document.documentElement
71
+
72
+ if (ref.current === resolved) return
73
+
74
+ // Filling the object in place is enough on mount. After that `useScroll` only moves
75
+ // its listener when the ref identity changes, so a later swap needs a new object.
76
+ if (ref.current === null) ref.current = resolved
77
+ else setRef({ current: resolved })
78
+ }, [container, ref])
79
+
80
+ return typeof container === "string" ? ref : container
81
+ }
82
+
83
+ export interface ScrollProgressProps
84
+ extends React.ComponentProps<typeof motion.div> {
85
+ /** Scroll container to track — a ref, or a CSS selector for a scrollport you cannot hang
86
+ * a ref on. Omit to track the page, but note that an app which scrolls an inner element
87
+ * rather than the document leaves the bar at zero until it is pointed at that element. */
88
+ containerRef?: ScrollProgressContainer
89
+ /** Smooth the bar with a spring. Set `false` for a 1:1 bar. */
90
+ smooth?: boolean
91
+ /** Position the bar itself. Set `false` to place it yourself. */
92
+ fixed?: boolean
93
+ }
94
+
95
+ /**
96
+ * A bar tracking how far a scroll container has been read.
97
+ *
98
+ * Uses `scaleX` rather than `width` — width forces layout on every scroll frame, scaleX
99
+ * runs on the compositor.
100
+ *
101
+ * The spring is not decoration: a mouse wheel arrives in discrete notches, and smoothing
102
+ * turns that staircase into continuous motion. It is short enough that the bar never
103
+ * visibly disagrees with the text on screen. A reduced-motion preference drops it and
104
+ * tracks scroll 1:1 — the bar still moves, because that movement is the reader's own
105
+ * gesture rather than motion the interface added.
106
+ */
107
+ const ScrollProgress = React.forwardRef<HTMLDivElement, ScrollProgressProps>(
108
+ (
109
+ {
110
+ containerRef,
111
+ smooth = true,
112
+ fixed = true,
113
+ className,
114
+ style,
115
+ ...props
116
+ },
117
+ ref
118
+ ) => {
119
+ const container = useScrollContainer(containerRef)
120
+ const { scrollYProgress } = useScroll({ container })
121
+ const springProgress = useSpring(scrollYProgress, SPRING)
122
+ const reducedMotion = useReducedMotionConfig()
123
+
124
+ const scaleX = smooth && !reducedMotion ? springProgress : scrollYProgress
125
+
126
+ return (
127
+ <motion.div
128
+ ref={ref}
129
+ aria-hidden
130
+ style={{ scaleX, ...style }}
131
+ // `will-change-transform` stays on permanently, against the usual advice to hint
132
+ // only imminent motion: this element is transformed on essentially every scroll
133
+ // frame, so the layer it promotes is never idle. `pointer-events-none` keeps a
134
+ // fixed bar from swallowing clicks along the top edge of the viewport.
135
+ className={cn(
136
+ "pointer-events-none h-0.5 w-full origin-left bg-primary will-change-transform",
137
+ fixed && "fixed inset-x-0 top-0 z-50",
138
+ className
139
+ )}
140
+ {...props}
141
+ />
142
+ )
143
+ }
144
+ )
145
+ ScrollProgress.displayName = "ScrollProgress"
146
+
147
+ export { ScrollProgress }
@@ -0,0 +1,2 @@
1
+ export { ScrollReveal } from './scroll-reveal'
2
+ export type { ScrollRevealProps } from './scroll-reveal'
@@ -0,0 +1,198 @@
1
+ "use client"
2
+
3
+ import * as React from "react"
4
+ import { motion, MotionConfigContext, useInView, useReducedMotion } from "motion/react"
5
+ import { cn } from "@/lib/utils"
6
+
7
+ /** Motion does not export it, so it is read back off `useInView`. */
8
+ type InViewMargin = NonNullable<Parameters<typeof useInView>[1]>["margin"]
9
+
10
+ /** `useReducedMotion` reads the OS setting only, and only at mount. Also honour an
11
+ * app-level `<MotionConfig reducedMotion>`, so a user preference in the host app
12
+ * reaches this component. */
13
+ function useReducedMotionConfig() {
14
+ const config = React.useContext(MotionConfigContext)
15
+ const prefersReduced = useReducedMotion()
16
+ if (config.reducedMotion === "always") return true
17
+ if (config.reducedMotion === "never") return false
18
+ return prefersReduced
19
+ }
20
+
21
+ const EASE_OUT: [number, number, number, number] = [0.23, 1, 0.32, 1]
22
+
23
+ /** A reveal is an entrance, and UI motion stays under 300ms. The block also has to
24
+ * finish arriving before the reader scrolls past it — at half a second a fast scroll
25
+ * leaves it still wiping as it crosses the middle of the screen. */
26
+ const DEFAULT_DURATION = 0.3
27
+
28
+ /** Seconds. Shared with the rest of the motion tier so a page that reduces one
29
+ * component reduces all of them at the same rate. */
30
+ const REDUCED_DURATION = 0.2
31
+
32
+ type Direction = "up" | "down" | "left" | "right"
33
+
34
+ // All values are percentages so motion can interpolate the clip-path cleanly —
35
+ // mixing px and % in one inset() breaks interpolation.
36
+ const HIDDEN_CLIP: Record<Direction, string> = {
37
+ up: "inset(0% 0% 100% 0%)",
38
+ down: "inset(100% 0% 0% 0%)",
39
+ left: "inset(0% 0% 0% 100%)",
40
+ right: "inset(0% 100% 0% 0%)",
41
+ }
42
+
43
+ const SHOWN_CLIP = "inset(0% 0% 0% 0%)"
44
+
45
+ const OFFSET: Record<Direction, { x: number; y: number }> = {
46
+ up: { x: 0, y: 1 },
47
+ down: { x: 0, y: -1 },
48
+ left: { x: 1, y: 0 },
49
+ right: { x: -1, y: 0 },
50
+ }
51
+
52
+ const SHOWN_TRANSFORM = "translate(0px, 0px)"
53
+
54
+ export interface ScrollRevealProps
55
+ extends React.ComponentProps<typeof motion.div> {
56
+ /** Direction the content travels as it reveals. The aperture opens against the
57
+ * travel, so the block appears to slide up through a shutter opening downwards. */
58
+ direction?: Direction
59
+ /** Travel distance in px. Matches StaggerList's item travel; the wipe is the
60
+ * gesture here, and the nudge only gives it a direction. */
61
+ distance?: number
62
+ /** Seconds. The wipe traverses the whole block rather than nudging it, which puts
63
+ * it in the same class of slower gesture as StaggerList's `blur` — and on the same
64
+ * budget. Front-loaded by `EASE_OUT`, so most of the travel lands in the first
65
+ * third and the rest is settle. */
66
+ duration?: number
67
+ /** Seconds to wait after entering view. Only useful for cascading sibling reveals,
68
+ * and only in the 0.03–0.08 range per step — past that the last block is late
69
+ * enough to read as a wait. For an actual list, reach for StaggerList instead,
70
+ * which sequences from one trigger rather than one observer per item. */
71
+ delay?: number
72
+ /** Re-run every time it re-enters view. Off by default and best left off: replaying
73
+ * an entrance on content the reader has already read is decoration, not
74
+ * information, and it makes the page feel like it is fighting the scroll. */
75
+ repeat?: boolean
76
+ /** Root margin for the viewport trigger. The default holds the reveal back until
77
+ * the block is clear of the fold, so the wipe is not already over by the time it
78
+ * is worth looking at. The cost is that a block shorter than that inset which sits
79
+ * at the very bottom of the scroll range can never clear the line — pass `"0px"`
80
+ * for trailing content with nothing below it. */
81
+ margin?: string
82
+ /** Fraction of the element that must be visible, 0–1. Defaults to `"some"` — any
83
+ * intersection at all — because a numeric amount is unreachable for a block taller
84
+ * than the root, and content that never reveals is worse than content that reveals
85
+ * early. `margin` is the threshold that does the work. */
86
+ amount?: number | "some" | "all"
87
+ /** Observe against a scrollable ancestor instead of the viewport. Needed whenever
88
+ * the content lives in its own scroll container — a dialog body, a sidebar, a chat
89
+ * log — since otherwise the trigger is measured against the window and fires at
90
+ * effectively arbitrary times. Must be an ancestor of the revealed content:
91
+ * IntersectionObserver reports no intersection at all against an unrelated root,
92
+ * and the block would stay hidden forever. */
93
+ root?: React.RefObject<Element | null>
94
+ }
95
+
96
+ /**
97
+ * A block that wipes into view the first time it is scrolled to.
98
+ *
99
+ * The reveal is a `clip-path` inset paired with a short travel, so the content is
100
+ * uncovered edge-first rather than fading in as a whole — a fade alone reads as a
101
+ * loading state rather than as arrival.
102
+ *
103
+ * Use it sparingly, and only on content the reader has not seen yet: one hero block,
104
+ * one feature grid. A page where everything reveals is a page that is slow to read,
105
+ * because every block withholds itself until the scroll catches up. Anything the
106
+ * reader returns to, or arrives at from a deep link, is better off just being there.
107
+ *
108
+ * The hidden state is a real style on the element, so the content depends on JS
109
+ * running to become visible. That is the trade for the effect; don't wrap anything
110
+ * whose absence would be a bug rather than a missing flourish.
111
+ */
112
+ const ScrollReveal = React.forwardRef<HTMLDivElement, ScrollRevealProps>(
113
+ (
114
+ {
115
+ direction = "up",
116
+ distance = 8,
117
+ duration = DEFAULT_DURATION,
118
+ delay = 0,
119
+ repeat = false,
120
+ margin = "0px 0px -100px 0px",
121
+ amount = "some",
122
+ root,
123
+ className,
124
+ children,
125
+ ...props
126
+ },
127
+ ref
128
+ ) => {
129
+ const wrapperRef = React.useRef<HTMLDivElement>(null)
130
+
131
+ const inView = useInView(wrapperRef, {
132
+ once: !repeat,
133
+ // Motion types this as a template literal, which a plain `string` prop cannot
134
+ // satisfy. Kept as `string` so callers are not made to fight the type.
135
+ margin: margin as InViewMargin,
136
+ amount,
137
+ root,
138
+ })
139
+ const reducedMotion = useReducedMotionConfig()
140
+
141
+ const offset = OFFSET[direction]
142
+
143
+ // Reduced motion keeps the fade — it still signals "new content arrived" —
144
+ // but drops the wipe and the travel.
145
+ const hidden = reducedMotion
146
+ ? { opacity: 0 }
147
+ : {
148
+ opacity: 0,
149
+ clipPath: HIDDEN_CLIP[direction],
150
+ // A `transform` string rather than motion's `x`/`y`: only `opacity`,
151
+ // `clipPath`, `filter` and `transform` are handed off to WAAPI. `x` and `y`
152
+ // stay on the main thread, which is the worst place to be for something
153
+ // that by definition runs while the user is scrolling — and it would leave
154
+ // the clip and the travel on two different clocks, drifting apart.
155
+ transform: `translate(${offset.x * distance}px, ${offset.y * distance}px)`,
156
+ }
157
+
158
+ const shown = reducedMotion
159
+ ? { opacity: 1 }
160
+ : { opacity: 1, clipPath: SHOWN_CLIP, transform: SHOWN_TRANSFORM }
161
+
162
+ return (
163
+ // The observed node and the animated node have to be different elements.
164
+ // `clip-path` shrinks an element's intersection rect in Chromium, and the hidden
165
+ // state clips to zero area — so observing the node we wipe would pin `inView` to
166
+ // false and the content could never reveal itself. This wrapper is never clipped,
167
+ // and stays an implementation detail: the ref goes to the same node as `className`
168
+ // and the rest of the props, which is the one a caller wrote.
169
+ <div ref={wrapperRef}>
170
+ <motion.div
171
+ ref={ref}
172
+ className={cn(className)}
173
+ initial={hidden}
174
+ animate={inView ? shown : hidden}
175
+ transition={
176
+ inView
177
+ ? {
178
+ duration: reducedMotion ? REDUCED_DURATION : duration,
179
+ delay,
180
+ ease: EASE_OUT,
181
+ }
182
+ : // Re-arming is not a performance anyone should have to sit through.
183
+ // Under `repeat`, animating back out would fade the block away at the
184
+ // edge of the viewport while it is still being read, and `delay` would
185
+ // hold it there first. Leaving view resets instead.
186
+ { duration: 0 }
187
+ }
188
+ {...props}
189
+ >
190
+ {children}
191
+ </motion.div>
192
+ </div>
193
+ )
194
+ }
195
+ )
196
+ ScrollReveal.displayName = "ScrollReveal"
197
+
198
+ export { ScrollReveal }
@@ -39,16 +39,18 @@ const SelectContent = React.forwardRef<
39
39
  readonly sideOffset?: number
40
40
  readonly portal?: boolean
41
41
  }
42
- >(({ className, children, alignItemWithTrigger = false, sideOffset = 4, portal = true, ...props }, ref) => {
42
+ >(({ className, children, alignItemWithTrigger = false, sideOffset = 4, portal = false, ...props }, ref) => {
43
43
  const content = (
44
44
  <SelectPrimitive.Positioner
45
45
  sideOffset={sideOffset}
46
46
  alignItemWithTrigger={alignItemWithTrigger}
47
+ positionMethod="fixed"
48
+ className="z-50"
47
49
  >
48
50
  <SelectPrimitive.Popup
49
51
  ref={ref}
50
52
  className={cn(
51
- "relative z-50 max-h-96 min-w-[var(--anchor-width)] overflow-hidden rounded-md border bg-popover text-popover-foreground shadow-md",
53
+ "relative max-h-96 min-w-[var(--anchor-width)] overflow-hidden rounded-md border bg-popover text-popover-foreground shadow-md",
52
54
  "data-[open]:animate-in data-[closed]:animate-out data-[closed]:fade-out-0 data-[open]:fade-in-0 data-[closed]:zoom-out-95 data-[open]:zoom-in-95",
53
55
  "data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2",
54
56
  !alignItemWithTrigger &&
@@ -73,7 +73,7 @@ const SliderThumb = React.forwardRef<
73
73
  <BaseSlider.Thumb
74
74
  ref={ref}
75
75
  className={cn(
76
- "block h-5 w-5 z-10 rounded-full border-2 border-primary bg-background ring-offset-background transition-colors",
76
+ "block h-5 w-5 rounded-full border-2 border-primary bg-background ring-offset-background transition-colors",
77
77
  "focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2",
78
78
  "data-[disabled]:pointer-events-none data-[disabled]:opacity-50",
79
79
  "data-[dragging]:scale-110",
@@ -0,0 +1 @@
1
+ export * from './sortable'