Skip to content

Commit ab45404

Browse files
committed
review(ui-components): some nits
1 parent 17c7036 commit ab45404

File tree

1 file changed

+11
-10
lines changed
  • packages/ui-components/src/Common/TableOfContents

1 file changed

+11
-10
lines changed

packages/ui-components/src/Common/TableOfContents/index.tsx

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,17 @@ import classNames from 'classnames';
33
import { LinkLike } from '#ui/types';
44

55
import type { Heading } from '@vcarl/remark-headings';
6-
import type { FC } from 'react';
6+
import type { ComponentProps, FC } from 'react';
77

88
import styles from './index.module.css';
99

10-
type TableOfContentsProps = {
10+
const depthClasses: Record<number, string> = {
11+
3: styles.depthThree,
12+
4: styles.depthFour,
13+
};
14+
15+
type TableOfContentsProps = ComponentProps<'details'> & {
1116
headings: Array<Heading>;
12-
ariaLabel: string;
1317
summaryTitle: string;
1418
minDepth?: number;
1519
maxDepth?: number;
@@ -18,29 +22,26 @@ type TableOfContentsProps = {
1822

1923
const TableOfContents: FC<TableOfContentsProps> = ({
2024
headings,
21-
ariaLabel,
2225
summaryTitle,
2326
minDepth = 2,
27+
className,
2428
maxDepth = 4,
2529
as: Component = 'a',
30+
...props
2631
}) => {
2732
const filteredHeadings = headings.filter(
2833
({ depth }) => depth >= minDepth && depth <= maxDepth
2934
);
3035

3136
return (
32-
<details className={styles.details} aria-label={ariaLabel}>
37+
<details className={classNames(styles.details, className)} {...props}>
3338
<summary className={styles.summary}>{summaryTitle}</summary>
3439
<ul className={styles.list}>
3540
{filteredHeadings.map((head, index) => (
3641
<li key={head.data?.id ?? index}>
3742
<Component
3843
href={head.data?.id && `#${head.data.id}`}
39-
className={classNames(
40-
styles.link,
41-
head.depth === 3 && styles.depthThree,
42-
head.depth === 4 && styles.depthFour
43-
)}
44+
className={classNames(styles.link, depthClasses[head.depth])}
4445
>
4546
{head.value}
4647
</Component>

0 commit comments

Comments
 (0)