File size: 3,406 Bytes
1e92f2d |
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 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 |
import { IconProps } from 'phosphor-react'
import { assignInlineVars } from '@vanilla-extract/dynamic'
import { ForwardRefExoticComponent, RefAttributes } from 'react'
import { Link } from '@remix-run/react'
import { isStringGuard } from '~/helpers/guards'
import { useIsDarkTheme } from '~/hooks/useIsDarkTheme'
import { Button } from '../Buttons/Button'
import { Copy } from '../Text/Copy'
import { GradientHeader } from '../Text/GradientHeader'
import { Heading } from '../Text/Heading'
import clsx from 'clsx'
import {
backgroundTile,
colsVar,
grid,
iconWrapper,
navSection,
tile,
tileButton,
tileCanHover,
tileCopy,
} from './NavigationGrid.css'
export interface Tile {
href: string
label: string
description: string
comingSoon?: boolean
isExternal?: boolean
Icon?:
| ForwardRefExoticComponent<IconProps & RefAttributes<SVGSVGElement>>
| string
}
interface NavigationGridProps {
tiles: Tile[]
cols?: number
subheading?: string
heading?: string
smallTiles?: boolean
className?: string
}
export const NavigationGrid = ({
tiles,
cols = 2,
subheading,
heading,
smallTiles = false,
className,
}: NavigationGridProps) => {
return (
<section className={clsx(navSection, className)}>
{subheading ? (
<GradientHeader fontStyle="XXS" tag="h2" weight="semiblack">
{subheading}
</GradientHeader>
) : null}
{heading ? (
<Heading fontStyle="M" tag="h3">
{heading}
</Heading>
) : null}
<div
className={grid({
smallTiles: Boolean(smallTiles),
})}
style={{
...assignInlineVars({
[colsVar]: `${cols}`,
}),
}}
>
{tiles.map(tile => (
<NavigationItem
key={tile.label}
variant={smallTiles ? 'small' : 'large'}
{...tile}
/>
))}
</div>
</section>
)
}
interface NavigationItemProps extends Tile {
variant: 'small' | 'large'
}
const NavigationItem = ({
label,
href,
description,
comingSoon = false,
isExternal = false,
variant = 'large',
Icon,
}: NavigationItemProps) => {
const canHover = Boolean(!comingSoon)
const isDarkMode = useIsDarkTheme()
const renderTile = () => (
<span
className={clsx(
tile({
small: variant === 'small',
}),
canHover && tileCanHover
)}
>
<span className={backgroundTile} />
{Icon && isStringGuard(Icon) ? (
<span className={iconWrapper({ isString: true })}>{Icon}</span>
) : Icon && !isStringGuard(Icon) ? (
<span className={iconWrapper({ isString: false })}>
<Icon size={32} weight={isDarkMode ? 'light' : 'regular'} />
</span>
) : null}
<Heading tag="h2" fontStyle="S" weight="semiblack">
{label}
</Heading>
<Copy className={tileCopy}>{description}</Copy>
{variant === 'large' ? (
<Button className={tileButton} disabled={comingSoon}>
{comingSoon ? <span>Coming soon!</span> : <span>Read more</span>}
</Button>
) : null}
</span>
)
if (comingSoon) {
return renderTile()
}
if (isExternal) {
return (
<a href={href} rel="noopener noreferrer" target="_blank">
{renderTile()}
</a>
)
}
return <Link to={href}>{renderTile()}</Link>
}
|