aboutsummaryrefslogtreecommitdiffstats
path: root/src/components/organisms/widgets/table-of-contents.tsx
diff options
context:
space:
mode:
authorArmand Philippot <git@armandphilippot.com>2023-11-14 15:11:22 +0100
committerArmand Philippot <git@armandphilippot.com>2023-11-14 19:06:42 +0100
commita3a4c50f26b8750ae1c87f1f1103b84b7d2e6315 (patch)
treeae286c7c6b3ab4f556f20adf5e42b24641351296 /src/components/organisms/widgets/table-of-contents.tsx
parent50f1c501a87ef5f5650750dbeca797e833ec7c3a (diff)
refactor(components): replace LinksListWidget with LinksWidget
* avoid List component repeat * rewrite tests and CSS * add an id to LinksWidgetItemData (previously LinksListItems) type because the label could be duplicated
Diffstat (limited to 'src/components/organisms/widgets/table-of-contents.tsx')
-rw-r--r--src/components/organisms/widgets/table-of-contents.tsx11
1 files changed, 6 insertions, 5 deletions
diff --git a/src/components/organisms/widgets/table-of-contents.tsx b/src/components/organisms/widgets/table-of-contents.tsx
index 8892485..5f14415 100644
--- a/src/components/organisms/widgets/table-of-contents.tsx
+++ b/src/components/organisms/widgets/table-of-contents.tsx
@@ -1,9 +1,9 @@
import type { FC } from 'react';
import { useIntl } from 'react-intl';
import { useHeadingsTree, type Heading } from '../../../utils/hooks';
-import { type LinksListItems, LinksListWidget } from './links-list-widget';
+import { Heading as HeadingComponent } from '../../atoms';
+import { LinksWidget, type LinksWidgetItemData } from './links-widget';
import styles from './table-of-contents.module.scss';
-import { Heading as HeadingComponent } from 'src/components/atoms';
type TableOfContentsProps = {
/**
@@ -32,17 +32,18 @@ export const TableOfContents: FC<TableOfContentsProps> = ({ wrapper }) => {
* @param {Heading[]} tree - The headings tree.
* @returns {LinksListItems[]} The list items.
*/
- const getItems = (tree: Heading[]): LinksListItems[] =>
+ const getItems = (tree: Heading[]): LinksWidgetItemData[] =>
tree.map((heading) => {
return {
- name: heading.title,
+ id: heading.id,
+ label: heading.title,
url: `#${heading.id}`,
child: getItems(heading.children),
};
});
return (
- <LinksListWidget
+ <LinksWidget
className={styles.list}
heading={
<HeadingComponent isFake level={3}>