Skip to content

Commit 7ba579d

Browse files
committed
Figure out drag constraints for Marquees
1 parent 6f52538 commit 7ba579d

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

src/app/conf/_design-system/marquee.tsx

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import { clsx } from "clsx"
44
import { useMotionValue, animate, motion } from "motion/react"
5-
import { useState, useEffect, Fragment } from "react"
5+
import { useState, useEffect, Fragment, useRef } from "react"
66
import useMeasure from "react-use-measure"
77

88
export interface MarqueeProps {
@@ -102,19 +102,27 @@ export function Marquee({
102102
}
103103
: {}
104104

105-
const multiples = drag ? 12 : 2
106105
const dragProps = drag
107106
? {
108-
drag: "x" as const,
107+
drag: direction === "horizontal" ? ("x" as const) : ("y" as const),
109108
onDragStart: () => {
110109
document.documentElement.style.cursor = "grabbing"
111110
},
112111
onDragEnd: () => {
113112
document.documentElement.style.cursor = "initial"
114113
},
114+
dragConstraints:
115+
direction === "horizontal"
116+
? {
117+
right: 0,
118+
// window.innerWidth won't be stale because resizing the window triggers useMeasure
119+
left: window.innerWidth - width,
120+
}
121+
: {},
115122
}
116123
: {}
117124

125+
const multiples = 2
118126
return (
119127
<div className={clsx("overflow-hidden", className)}>
120128
<motion.div
@@ -131,10 +139,10 @@ export function Marquee({
131139
{...dragProps}
132140
{...hoverProps}
133141
>
134-
{Array.from({ length: multiples }).map((_, i) => (
142+
{Array.from({ length: 2 }).map((_, i) => (
135143
<Fragment key={i}>
136144
{children}
137-
{separator}
145+
{i < multiples - 1 && separator}
138146
</Fragment>
139147
))}
140148
</motion.div>

0 commit comments

Comments
 (0)