Skip to content

Commit

Permalink
Dropdowns complete. Note that dropdowns can easily be removed if they…
Browse files Browse the repository at this point in the history
… are deemed unecessary for the functionality of this webpage
  • Loading branch information
cmhhelgeson committed Feb 28, 2024
1 parent 1879c54 commit f3c618c
Show file tree
Hide file tree
Showing 5 changed files with 97 additions and 73 deletions.
12 changes: 10 additions & 2 deletions src/components/SampleCategory.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,25 @@
to { transform: rotate(0deg); }
}

.sampleCategory {
display: flex;
cursor: pointer;
}

.dropdown {
margin-left: 8px;
margin-top: 7px;
margin-bottom: 5px;
}

li.selected a {
color: #ff0000;
}

.dropdown[data-collapsed=false] {
animation: openTriangle 0.3s forwards ease-in-out;
animation: closeTriangle 0.3s forwards ease-in-out;
}

.dropdown[data-collapsed=true] {
animation: closeTriangle 0.3s forwards ease-in-out;
animation: openTriangle 0.3s forwards ease-in-out;
}
95 changes: 81 additions & 14 deletions src/components/SampleCategory.tsx
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>
);
};
44 changes: 0 additions & 44 deletions src/components/SampleLink.tsx

This file was deleted.

17 changes: 5 additions & 12 deletions src/pages/_app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -69,18 +69,11 @@ const MainLayout: React.FunctionComponent<AppProps> = ({
className={styles.exampleList}
key={`/categories/${category.title}`}
>
<SampleCategory title={category.title} />
{category.sampleNames.map((slug) => {
return (
<SampleLink
key={`samples/${slug}`}
slug={slug}
router={router}
pages={category.pages}
onClick={() => setListExpanded(false)}
/>
);
})}
<SampleCategory
category={category}
router={router}
onClickPageLink={() => setListExpanded(false)}
/>
</ul>
);
})}
Expand Down
2 changes: 1 addition & 1 deletion src/pages/samples/[slug].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ const pages: PageComponentType = {
...benchmarkPages,
};

interface PageCategory {
export interface PageCategory {
title: string;
pages: PageComponentType;
sampleNames: string[];
Expand Down

0 comments on commit f3c618c

Please sign in to comment.