Skip to content

Commit 73f0665

Browse files
authored
Docs - Category introductory page (#3715)
* Added introductory page for sidebar categories * removed title from sidebar configuration * Removed console and description * Added DocCard implementation and removed DocCardList
1 parent 5f54bbb commit 73f0665

File tree

3 files changed

+85
-0
lines changed

3 files changed

+85
-0
lines changed

docuilib/sidebars.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,10 @@ module.exports = {
6464
type: 'category',
6565
label: componentsCategories[category],
6666
collapsed: true,
67+
link: {
68+
type: 'generated-index',
69+
keywords: [category]
70+
},
6771
items: [
6872
{
6973
type: 'autogenerated',

docuilib/src/theme/DocCard/index.tsx

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
import React, {type ReactNode} from 'react';
2+
import clsx from 'clsx';
3+
import Link from '@docusaurus/Link';
4+
import {findFirstSidebarItemLink} from '@docusaurus/plugin-content-docs/client';
5+
6+
import type {Props} from '@theme/DocCard';
7+
import Heading from '@theme/Heading';
8+
import type {PropSidebarItemCategory, PropSidebarItemLink} from '@docusaurus/plugin-content-docs';
9+
10+
import styles from './styles.module.css';
11+
12+
function CardContainer({href, children}: {href: string; children: ReactNode}): JSX.Element {
13+
return (
14+
<Link href={href} className={clsx('card padding--lg', styles.cardContainer)}>
15+
{children}
16+
</Link>
17+
);
18+
}
19+
20+
function CardLayout({href, title}: {href: string; title: string}): JSX.Element {
21+
return (
22+
<CardContainer href={href}>
23+
<Heading as="h2" className={clsx('text--truncate', styles.cardTitle)} title={title}>
24+
{title}
25+
</Heading>
26+
</CardContainer>
27+
);
28+
}
29+
30+
function CardCategory({item}: {item: PropSidebarItemCategory}): JSX.Element | null {
31+
const href = findFirstSidebarItemLink(item);
32+
33+
// Unexpected: categories that don't have a link have been filtered upfront
34+
if (!href) {
35+
return null;
36+
}
37+
38+
return <CardLayout href={href} title={item.label}/>;
39+
}
40+
41+
function CardLink({item}: {item: PropSidebarItemLink}): JSX.Element {
42+
return <CardLayout href={item.href} title={item.label}/>;
43+
}
44+
45+
export default function DocCard({item}: Props): JSX.Element {
46+
switch (item.type) {
47+
case 'link':
48+
return <CardLink item={item}/>;
49+
case 'category':
50+
return <CardCategory item={item}/>;
51+
default:
52+
throw new Error(`unknown item type ${JSON.stringify(item)}`);
53+
}
54+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
.cardContainer {
2+
--ifm-link-color: var(--ifm-color-emphasis-800);
3+
--ifm-link-hover-color: var(--ifm-color-emphasis-700);
4+
--ifm-link-hover-decoration: none;
5+
6+
box-shadow: 0 1.5px 3px 0 rgb(0 0 0 / 15%);
7+
border: 1px solid var(--ifm-color-emphasis-200);
8+
transition: all var(--ifm-transition-fast) ease;
9+
transition-property: border, box-shadow;
10+
}
11+
12+
.cardContainer:hover {
13+
border-color: var(--ifm-color-primary);
14+
box-shadow: 0 3px 6px 0 rgb(0 0 0 / 20%);
15+
}
16+
17+
.cardContainer *:last-child {
18+
margin-bottom: 0;
19+
}
20+
21+
.cardTitle {
22+
font-size: 1.2rem;
23+
}
24+
25+
.cardDescription {
26+
font-size: 0.8rem;
27+
}

0 commit comments

Comments
 (0)