2
2
3
3
import { clsx } from "clsx"
4
4
import { useMotionValue , animate , motion } from "motion/react"
5
- import { useState , useEffect , Fragment } from "react"
5
+ import { useState , useEffect , Fragment , useRef } from "react"
6
6
import useMeasure from "react-use-measure"
7
7
8
8
export interface MarqueeProps {
@@ -102,19 +102,27 @@ export function Marquee({
102
102
}
103
103
: { }
104
104
105
- const multiples = drag ? 12 : 2
106
105
const dragProps = drag
107
106
? {
108
- drag : " x" as const ,
107
+ drag : direction === "horizontal" ? ( " x" as const ) : ( "y" as const ) ,
109
108
onDragStart : ( ) => {
110
109
document . documentElement . style . cursor = "grabbing"
111
110
} ,
112
111
onDragEnd : ( ) => {
113
112
document . documentElement . style . cursor = "initial"
114
113
} ,
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
+ : { } ,
115
122
}
116
123
: { }
117
124
125
+ const multiples = 2
118
126
return (
119
127
< div className = { clsx ( "overflow-hidden" , className ) } >
120
128
< motion . div
@@ -131,10 +139,10 @@ export function Marquee({
131
139
{ ...dragProps }
132
140
{ ...hoverProps }
133
141
>
134
- { Array . from ( { length : multiples } ) . map ( ( _ , i ) => (
142
+ { Array . from ( { length : 2 } ) . map ( ( _ , i ) => (
135
143
< Fragment key = { i } >
136
144
{ children }
137
- { separator }
145
+ { i < multiples - 1 && separator }
138
146
</ Fragment >
139
147
) ) }
140
148
</ motion . div >
0 commit comments