-
Notifications
You must be signed in to change notification settings - Fork 314
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Dropdowns complete. Note that dropdowns can easily be removed if they…
… are deemed unecessary for the functionality of this webpage
- Loading branch information
1 parent
1879c54
commit f3c618c
Showing
5 changed files
with
97 additions
and
73 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
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,26 +1,93 @@ | ||
import { useState } from 'react'; | ||
import styles from './SampleCategory.module.css'; | ||
|
||
import { NextRouter } from 'next/router'; | ||
import Link from 'next/link'; | ||
import { PageCategory } from '../pages/samples/[slug]'; | ||
|
||
type PageType = { | ||
[key: string]: React.ComponentType & { render: { preload: () => void } }; | ||
}; | ||
|
||
type PageComponentType = { | ||
[key: string]: React.ComponentType; | ||
}; | ||
|
||
interface SampleCategoryProps { | ||
title: string; | ||
category: PageCategory; | ||
router: NextRouter; | ||
onClickPageLink: () => void; | ||
} | ||
|
||
export const SampleCategory = ({ title }: SampleCategoryProps) => { | ||
export const SampleCategory = ({ | ||
category, | ||
onClickPageLink, | ||
router, | ||
}: SampleCategoryProps) => { | ||
const { title, pages, sampleNames } = category; | ||
const [open, setOpen] = useState<boolean>(true); | ||
return ( | ||
<div style={{ display: 'flex' }} onClick={() => setOpen(!open)}> | ||
<h3 | ||
style={{ | ||
marginTop: '5px', | ||
}} | ||
> | ||
{title} | ||
</h3> | ||
<div className={`${styles.dropdown}`} data-collapsed={open}> | ||
<svg width="15" height="15" viewBox="0 0 20 20"> | ||
<path d="M0 7 L 20 7 L 10 16" fill="black" /> | ||
</svg> | ||
<div> | ||
<div className={styles.sampleCategory} onClick={() => setOpen(!open)}> | ||
<h3 | ||
style={{ | ||
marginTop: '5px', | ||
}} | ||
> | ||
{title} | ||
</h3> | ||
<div className={`${styles.dropdown}`} data-collapsed={open}> | ||
<svg width="15" height="15" viewBox="0 0 20 20"> | ||
<path d="M0 7 L 20 7 L 10 16" fill="black" /> | ||
</svg> | ||
</div> | ||
</div> | ||
{open | ||
? sampleNames.map((slug) => { | ||
return ( | ||
<SampleLink | ||
key={`samples/${slug}`} | ||
slug={slug} | ||
router={router} | ||
pages={pages} | ||
onClick={() => onClickPageLink()} | ||
/> | ||
); | ||
}) | ||
: null} | ||
</div> | ||
); | ||
}; | ||
|
||
interface SampleLinkProps { | ||
router: NextRouter; | ||
slug: string; | ||
pages: PageComponentType; | ||
onClick: () => void; | ||
} | ||
|
||
export const SampleLink = ({ | ||
router, | ||
slug, | ||
pages, | ||
onClick, | ||
}: SampleLinkProps) => { | ||
const className = | ||
router.pathname === `/samples/[slug]` && router.query['slug'] === slug | ||
? styles.selected | ||
: undefined; | ||
|
||
return ( | ||
<li | ||
key={slug} | ||
className={className} | ||
onMouseOver={() => { | ||
(pages as PageType)[slug].render.preload(); | ||
}} | ||
> | ||
<Link href={`/samples/${slug}`} onClick={() => onClick()}> | ||
{slug} | ||
</Link> | ||
</li> | ||
); | ||
}; |
This file was deleted.
Oops, something went wrong.
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