ef00732685
- Made the use of `const` and `let` consistent - import required functions and types from 'react' instead of using the `React.` namespace. - Added `Expand` type, which can expand complex types to their "final" result. - Ensured that we use `as const` for DEFAULT_XXX_TAG where we used a string. So that we have the type of `div` instead of `string` for example. - Used `interface` over `type` where possible. I'm personally more of a `type` fan. But the TypeScript recommends `interfaces` where possible because they are faster, yield better error messages and so on.
65 lines
1.5 KiB
TypeScript
65 lines
1.5 KiB
TypeScript
import React from 'react'
|
|
import ErrorPage from 'next/error'
|
|
import Head from 'next/head'
|
|
import Link from 'next/link'
|
|
|
|
import { ExamplesType, resolveAllExamples } from '../playground-utils/resolve-all-examples'
|
|
import { PropsOf } from '../src/types'
|
|
|
|
function NextLink(props: PropsOf<'a'>) {
|
|
let { href, children, ...rest } = props
|
|
return (
|
|
<Link href={href}>
|
|
<a {...rest}>{children}</a>
|
|
</Link>
|
|
)
|
|
}
|
|
|
|
export async function getStaticProps() {
|
|
return {
|
|
props: {
|
|
examples: await resolveAllExamples('pages'),
|
|
},
|
|
}
|
|
}
|
|
|
|
export default function Page(props: { examples: false | ExamplesType[] }) {
|
|
if (props.examples === false) {
|
|
return <ErrorPage statusCode={404} />
|
|
}
|
|
|
|
return (
|
|
<>
|
|
<Head>
|
|
<title>Examples</title>
|
|
</Head>
|
|
|
|
<div className="container my-24">
|
|
<div className="prose">
|
|
<h2>Examples</h2>
|
|
<Examples examples={props.examples} />
|
|
</div>
|
|
</div>
|
|
</>
|
|
)
|
|
}
|
|
|
|
export function Examples(props: { examples: ExamplesType[] }) {
|
|
return (
|
|
<ul>
|
|
{props.examples.map(example => (
|
|
<li key={example.path}>
|
|
{example.children ? (
|
|
<h3 className="text-xl capitalize">{example.name}</h3>
|
|
) : (
|
|
<NextLink href={example.path} className="capitalize">
|
|
{example.name}
|
|
</NextLink>
|
|
)}
|
|
{example.children && <Examples examples={example.children} />}
|
|
</li>
|
|
))}
|
|
</ul>
|
|
)
|
|
}
|