ContributeLayout.tsx 3.54 KB
Newer Older
Stefan Probst's avatar
Stefan Probst committed
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
import cx from 'clsx'
import Link from 'next/link'
import type { PropsWithChildren } from 'react'
import { Fragment } from 'react'

import GridLayout from '@/modules/layout/GridLayout'
import Mdx from '@/modules/markdown/Mdx'
import Metadata from '@/modules/metadata/Metadata'
import Breadcrumbs from '@/modules/ui/Breadcrumbs'
import Header from '@/modules/ui/Header'
import LastUpdatedAt from '@/modules/ui/LastUpdatedAt'
import Triangle from '@/modules/ui/Triangle'
import { Title } from '@/modules/ui/typography/Title'
import styles from '@/screens/contribute/ContributeLayout.module.css'
import type { UrlObject } from '@/utils/useActiveLink'
import { useActiveLink } from '@/utils/useActiveLink'

/**
 * Shared contribute screen layout.
 */
export default function ContributeLayout({
  breadcrumb,
  title,
  lastUpdatedAt,
  children,
  links,
}: PropsWithChildren<{
  title: string
  breadcrumb: { pathname: string; label: string }
  lastUpdatedAt: string
  links: Array<{ label: string; pathname: string }>
}>): JSX.Element {
  return (
    <Fragment>
      <Metadata title={title} />
      <GridLayout className={styles.grid}>
37
        <Header image={'/assets/images/about/clouds@2x.png'}>
Stefan Probst's avatar
Stefan Probst committed
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
          <Breadcrumbs links={[{ pathname: '/', label: 'Home' }, breadcrumb]} />
        </Header>
        <b
          className={cx(
            'border-b bg-gray-50 border-gray-200',
            styles.leftBleed,
          )}
        />
        <div
          className={cx(
            'border-b bg-gray-50 border-gray-200',
            styles.sideColumn,
          )}
        >
          <p className="p-6 text-lg font-bold">Find out more</p>
        </div>
        <SideColumn>
          <nav aria-label="Page navigation">
            <ul className="pl-6">
              {links.map(({ label, pathname }) => {
                return (
                  <li key={pathname}>
                    <NavLink href={{ pathname }}>{label}</NavLink>
                  </li>
                )
              })}
            </ul>
          </nav>
        </SideColumn>
        <MainColumn>
          <div className="mx-auto space-y-6 max-w-80ch">
            <Title>{title}</Title>
            <Mdx>{children}</Mdx>
            <LastUpdatedAt date={lastUpdatedAt} />
          </div>
        </MainColumn>
      </GridLayout>
    </Fragment>
  )
}

/**
 * Main column layout.
 */
function MainColumn({ children }: PropsWithChildren<unknown>) {
  const classNames = {
    section: cx('px-6 pb-12', styles.mainColumn),
    bleed: cx(styles.rightBleed),
  }

  return (
    <Fragment>
      <section className={classNames.section}>{children}</section>
      <b className={classNames.bleed} />
    </Fragment>
  )
}

/**
 * Side column layout.
 */
function SideColumn({ children }: PropsWithChildren<unknown>) {
  const classNames = {
    section: cx('bg-gray-50 pb-12', styles.sideColumn),
    bleed: cx('bg-gray-50', styles.leftBleed),
  }

  return (
    <Fragment>
      <b className={classNames.bleed} />
      <section className={classNames.section}>{children}</section>
    </Fragment>
  )
}

function NavLink({ href, children }: PropsWithChildren<{ href: UrlObject }>) {
  const isActive = useActiveLink(href)
  const classNames = cx(
    'px-8 py-10 inline-flex border-l-4 w-full justify-between',
    isActive
      ? 'border-gray-800 bg-gray-200'
      : 'text-primary-800 border-gray-200 hover:bg-gray-100',
  )
  return (
    <Link href={href}>
      <a className={classNames}>
        <span>{children}</span>
        <span className="transform -rotate-90">
          <Triangle />
        </span>
      </a>
    </Link>
  )
}