diff --git a/src/components/SampleCategory.module.css b/src/components/SampleCategory.module.css new file mode 100644 index 00000000..abc8e616 --- /dev/null +++ b/src/components/SampleCategory.module.css @@ -0,0 +1,8 @@ +.sampleCategory { + display: flex; +} + + +li.selected a { + color: #ff0000; +} \ No newline at end of file diff --git a/src/components/SampleCategory.tsx b/src/components/SampleCategory.tsx new file mode 100644 index 00000000..428b8006 --- /dev/null +++ b/src/components/SampleCategory.tsx @@ -0,0 +1,84 @@ +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 { + category: PageCategory; + router: NextRouter; + onClickPageLink: () => void; +} + +export const SampleCategory = ({ + category, + onClickPageLink, + router, +}: SampleCategoryProps) => { + const { title, pages, sampleNames } = category; + return ( +
+
+

+ {title} +

+
+ {sampleNames.map((slug) => { + return ( + onClickPageLink()} + /> + ); + })} +
+ ); +}; + +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 ( +
  • { + (pages as PageType)[slug].render.preload(); + }} + > + onClick()}> + {slug} + +
  • + ); +}; diff --git a/src/pages/MainLayout.module.css b/src/pages/MainLayout.module.css index c60673fb..f91ac2a9 100644 --- a/src/pages/MainLayout.module.css +++ b/src/pages/MainLayout.module.css @@ -23,15 +23,15 @@ margin-block-end: 16px; } +.exampleList h3 { + color: rgb(43, 126, 171); +} + .exampleList li { list-style: none; padding: 0.3em 0; } -.exampleList li.selected a { - color: #ff0000; -} - .expand { display: none; float: right; @@ -45,7 +45,6 @@ .panel .panelContents { display: block; transition: max-height 0s; - overflow: none; max-height: 100vh; } @@ -67,12 +66,12 @@ .panel .panelContents { display: block; transition: max-height 0.3s ease-out; - overflow: hidden; max-height: 0px; } .panel[data-expanded='false'] .panelContents { max-height: 0vh; + overflow: hidden; } .panel[data-expanded='true'] .panelContents { diff --git a/src/pages/_app.tsx b/src/pages/_app.tsx index d01f075c..a44ec918 100644 --- a/src/pages/_app.tsx +++ b/src/pages/_app.tsx @@ -7,20 +7,16 @@ import { useMemo, memo, useState } from 'react'; import './styles.css'; import styles from './MainLayout.module.css'; -import { pages } from './samples/[slug]'; +import { pageCategories } from './samples/[slug]'; +import { SampleCategory } from '../components/SampleCategory'; const title = 'WebGPU Samples'; -type PageType = { - [key: string]: React.ComponentType & { render: { preload: () => void } }; -}; - const MainLayout: React.FunctionComponent = ({ Component, pageProps, }) => { const router = useRouter(); - const samplesNames = Object.keys(pages); const [listExpanded, setListExpanded] = useState(false); const ComponentMemo = useMemo(() => { @@ -66,36 +62,26 @@ const MainLayout: React.FunctionComponent = ({ Github
    -
      - {samplesNames.map((slug) => { - const className = - router.pathname === `/samples/[slug]` && - router.query['slug'] === slug - ? styles.selected - : undefined; - return ( -
    • { - (pages as PageType)[slug].render.preload(); - }} - > - { - setListExpanded(false); - }} - > - {slug} - -
    • - ); - })} -
    + {pageCategories.map((category) => { + return ( +
      + setListExpanded(false)} + /> +
    + ); + })}
    -

    Other Pages

    -