-
Notifications
You must be signed in to change notification settings - Fork 8
/
CategoryPage.tsx
48 lines (47 loc) · 1.4 KB
/
CategoryPage.tsx
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
37
38
39
40
41
42
43
44
45
46
47
48
/** @jsx jsx */
import { FC } from 'react';
import { jsx, Box, Themed } from 'theme-ui';
import { DocType, getCategoryPath } from '@component-controls/core';
import { Link } from '@component-controls/components';
import {
useDocument,
useDocsByCategory,
useStore,
} from '@component-controls/store';
import { PageContainer } from '../PageContainer';
import { DocumentsList } from '../DocumentsList';
export interface CategoryPageProps {
type: DocType;
category: any;
}
export const CategoryPage: FC<CategoryPageProps> = ({ type, category }) => {
const store = useStore();
const { config } = store;
const pageConfig = config.pages?.[type] || {};
const pages = useDocsByCategory(type, category);
const customPage = useDocument(category);
const Page =
customPage && customPage.type === type ? customPage.MDXPage : undefined;
return (
<PageContainer
type={type}
variant="categorypage.pagecontainer"
id="content"
>
<Box variant="categorypage.titlecontainer">
<Themed.h1>{category}</Themed.h1>
<Link
href={`${getCategoryPath(store, type)}`}
>{`All ${pageConfig.label}`}</Link>
</Box>
{Page && (
<Box variant="categorypage.mdxcontainer">
<Page />
</Box>
)}
<Box variant="categorypage.listcontainer">
<DocumentsList pages={pages} type={type} />
</Box>
</PageContainer>
);
};