-
Notifications
You must be signed in to change notification settings - Fork 51
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: arrows for scroll + small fixes
- Loading branch information
Showing
4 changed files
with
60 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,47 +1,32 @@ | ||
import {useEffect, useRef, useState} from 'react'; | ||
import {motion} from 'framer-motion'; | ||
import {type ForwardedRef, forwardRef, type ReactElement} from 'react'; | ||
|
||
import {FeaturedApp} from './FeaturedApp'; | ||
|
||
import type {TApp} from 'pages/home/[category]'; | ||
import type {ReactElement} from 'react'; | ||
|
||
export function AppsCarousel(props: {apps: TApp[]}): ReactElement { | ||
const targetRef = useRef<HTMLDivElement | null>(null); | ||
const [width, set_width] = useState(0); | ||
|
||
useEffect(() => { | ||
set_width(Number(targetRef.current?.scrollWidth) - Number(targetRef.current?.offsetWidth)); | ||
}, []); | ||
|
||
export const AppsCarousel = forwardRef((props: {apps: TApp[]}, ref: ForwardedRef<HTMLDivElement>): ReactElement => { | ||
return ( | ||
<section | ||
ref={targetRef} | ||
className={'relative'}> | ||
<section className={'left-0 -mx-1 w-full md:absolute'}> | ||
<div | ||
className={ | ||
'pointer-events-none absolute -left-36 top-0 z-10 h-full w-1/6 bg-gradient-to-r from-gray-900 to-transparent' | ||
'pointer-events-none absolute left-0 top-0 z-10 h-full w-1/6 bg-gradient-to-r from-gray-900 to-transparent' | ||
} | ||
/> | ||
<div | ||
className={ | ||
'pointer-events-none absolute right-0 top-0 z-10 h-full w-1/5 bg-gradient-to-l from-gray-900 to-transparent' | ||
} | ||
/> | ||
<motion.div | ||
drag={'x'} | ||
dragConstraints={{ | ||
right: 0, | ||
left: -width | ||
}} | ||
className={'flex gap-x-6'}> | ||
<div | ||
ref={ref} | ||
className={'flex gap-x-6 overflow-x-auto pb-1 pr-1 scrollbar-none md:pl-28 lg:pl-36'}> | ||
{props.apps.map((app, i) => ( | ||
<FeaturedApp | ||
key={app.name + i} | ||
app={app} | ||
/> | ||
))} | ||
</motion.div> | ||
</div> | ||
</section> | ||
); | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters