Skip to content

Commit 7e52a62

Browse files
authored
Merge pull request #14020 from ethereum/home-values-rtl-fix
fix: RTL styling for ValuesMarquee
2 parents af2195f + 6acf719 commit 7e52a62

File tree

1 file changed

+23
-4
lines changed

1 file changed

+23
-4
lines changed

src/components/Homepage/ValuesMarquee.tsx

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,15 @@ import {
1919
} from "../ui/section"
2020

2121
import { usePrefersReducedMotion } from "@/hooks/usePrefersReducedMotion"
22+
import { useRtlFlip } from "@/hooks/useRtlFlip"
2223

2324
type ItemProps = React.HTMLAttributes<HTMLButtonElement> & {
2425
pairing: Pairing
2526
separatorClass: string
2627
container?: HTMLElement | null
2728
label: string
2829
eventCategory: string
30+
direction: HTMLDivElement["dir"]
2931
}
3032

3133
const Item = ({
@@ -36,6 +38,7 @@ const Item = ({
3638
container,
3739
label,
3840
eventCategory,
41+
direction,
3942
}: ItemProps) => (
4043
<>
4144
<Tooltip
@@ -86,6 +89,7 @@ const Item = ({
8689
"flex flex-nowrap items-center text-nowrap rounded-full px-4 py-1 font-bold uppercase",
8790
className
8891
)}
92+
dir={direction}
8993
>
9094
{children}
9195
</div>
@@ -98,6 +102,7 @@ const Item = ({
98102
/>
99103
</>
100104
)
105+
Item.displayName = "MarqueeItem"
101106

102107
type RowProps = React.HTMLAttributes<HTMLDivElement> & {
103108
toRight?: boolean
@@ -106,12 +111,15 @@ type RowProps = React.HTMLAttributes<HTMLDivElement> & {
106111
const Row = forwardRef<HTMLDivElement, RowProps>(
107112
({ className, children, toRight }, ref) => {
108113
const { prefersReducedMotion } = usePrefersReducedMotion()
114+
109115
const fadeEdges = {
110116
mask: `linear-gradient(to right, transparent 1rem, white 15%, white 85%, transparent calc(100% - 1rem))`,
111117
}
112118

113119
return (
114-
<div ref={ref} className={cn("group", className)}>
120+
// Note: dir="ltr" forced on parent to prevent "translateX" animation bugs
121+
// Locale "direction" passed to marquee Item for correction
122+
<div ref={ref} className={cn("group", className)} dir="ltr">
115123
<div
116124
className="flex max-w-full overflow-hidden motion-reduce:overflow-auto"
117125
style={prefersReducedMotion ? {} : fadeEdges}
@@ -137,7 +145,7 @@ const Row = forwardRef<HTMLDivElement, RowProps>(
137145
)
138146
}
139147
)
140-
Row.displayName = "Row"
148+
Row.displayName = "MarqueeRow"
141149

142150
const ValuesMarquee = () => {
143151
const { t, pairings, eventCategory } = useValuesMarquee()
@@ -160,6 +168,8 @@ const ValuesMarquee = () => {
160168
}
161169
}, [])
162170

171+
const { direction, isRtl, twFlipForRtl } = useRtlFlip()
172+
163173
return (
164174
<Section id="values" className="!sm:my-64 !my-48 scroll-m-48">
165175
<SectionContent className="flex flex-col items-center text-center">
@@ -185,6 +195,7 @@ const ValuesMarquee = () => {
185195
separatorClass="bg-accent-a"
186196
className="group/item bg-blue-100 text-blue-600 hover:bg-blue-600 hover:text-white dark:hover:bg-blue-700"
187197
eventCategory={eventCategory}
198+
direction={direction}
188199
>
189200
<FaCheck className="me-1 text-success group-hover/item:text-white" />
190201
{pairing.ethereum.label}
@@ -206,13 +217,19 @@ const ValuesMarquee = () => {
206217
className="bg-gray-200/20 text-body-medium hover:bg-gray-600 hover:text-white dark:bg-gray-950 dark:text-body"
207218
separatorClass="bg-gray-200 dark:bg-gray-950"
208219
eventCategory={eventCategory}
220+
direction={direction}
209221
>
210222
{pairing.legacy.label}
211223
</Item>
212224
))}
213225
</Row>
214226

215-
<div className="absolute start-[50%] top-[50%] flex -translate-x-[50%] -translate-y-[50%] items-center overflow-hidden rounded-lg text-sm font-bold">
227+
<div
228+
className={cn(
229+
"absolute start-[50%] top-[50%] flex -translate-y-[50%] items-center overflow-hidden rounded-lg text-sm font-bold",
230+
isRtl ? "translate-x-[50%]" : "-translate-x-[50%]"
231+
)}
232+
>
216233
<p className="bg-gray-50 px-4 py-1 text-body-medium dark:bg-gray-800 dark:text-gray-200">
217234
{t("page-index-values-legacy")}
218235
</p>
@@ -222,7 +239,8 @@ const ValuesMarquee = () => {
222239
"border-t-[15px] border-t-blue-50 dark:border-t-blue-600",
223240
"border-r-8 border-r-blue-50 dark:border-r-blue-600",
224241
"border-b-[15px] border-b-gray-50 dark:border-b-gray-800",
225-
"border-l-8 border-l-gray-50 dark:border-l-gray-800"
242+
"border-l-8 border-l-gray-50 dark:border-l-gray-800",
243+
twFlipForRtl
226244
)}
227245
/>
228246

@@ -234,5 +252,6 @@ const ValuesMarquee = () => {
234252
</Section>
235253
)
236254
}
255+
ValuesMarquee.displayName = "ValuesMarquee"
237256

238257
export default ValuesMarquee

0 commit comments

Comments
 (0)