-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patheditorial.tsx
69 lines (61 loc) · 2.44 KB
/
editorial.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
import { useState } from 'react'
import Image from 'next/image'
import Link from 'next/link'
import Lightbox from 'yet-another-react-lightbox'
import Zoom from 'yet-another-react-lightbox/plugins/zoom'
import 'yet-another-react-lightbox/styles.css'
import PageTransition from '@/components/pageTransition'
import { Suggest } from '@/components/suggest'
import { photos } from '@/lib/editorial'
import ScrollToTop from 'react-scroll-to-top'
import { UpArrow } from '@/components/upArrow'
type Props = {}
type EditorialPageRef = React.ForwardedRef<HTMLDivElement>
type Photo = {
src: string
width: number
height: number
alt: string
href: string
btnTxt: string
}
const LinkButton = ({ href, btnTxt }: { href: string; btnTxt: string }) => {
return (
<div className='w-max mx-auto border text-xs flex flex-shrink py-2 text-[var(--fg)] font-extrabold border-[var(--fg)] rounded-xl mt-6 mb-16 hover:bg-red-500 hover:text-[var(--fg)] transition-colors sm:text-2xl md:text-3xl md:px-2'>
<Link className='py-1 px-2 md:px-6' href={href}>
{btnTxt}
</Link>
</div>
)
}
const PageImage = (photo: Photo) => {
const { src, alt, width, height } = photo
return <Image className='mx-auto' src={src} width={width} height={height} alt={alt} />
}
const Editorial = (props: Props, ref: EditorialPageRef) => {
const [index, setIndex] = useState(-1)
return (
<PageTransition ref={ref}>
<div className='w-full px-16'>
<h1 className='text-center py-6 text-4xl font-extrabold'>Editorial</h1>
{photos.map((photo, i) => (
<div key={i}>
<div onClick={() => setIndex(i)}>
<PageImage {...photo} />
</div>
<LinkButton href={photo.href} btnTxt={photo.btnTxt} />
</div>
))}
<div className='w-max mx-auto border text-sm flex flex-shrink py-2 text-red-500 font-extrabold border-[var(--fg)] rounded-xl mt-6 mb-16 hover:bg-[#1B1B1B] hover:text-[var(--fg)] transition-colors md:text-3xl md:px-2'>
<Link className='py-1 px-2 md:px-6' href='https://www.motortrend.com/staff/john-roberts/'>
More Editorial Here
</Link>
</div>
</div>
<Suggest />
<Lightbox slides={photos} open={index >= 0} close={() => setIndex(-1)} index={index} plugins={[Zoom]} />
{index <= 0 && <ScrollToTop className='scroll' smooth component={<UpArrow size={40} color={'black'} />} />}
</PageTransition>
)
}
export default Editorial