From d2bfd4b0704c1487769f39ab95d37a8d45f909a2 Mon Sep 17 00:00:00 2001 From: Sofiya Pavlenko Date: Tue, 14 Jan 2025 14:29:47 +0300 Subject: [PATCH] feat(Toc): render 6 levels of nested items --- src/components/Toc/Toc.scss | 23 ------- src/components/Toc/Toc.tsx | 65 ++++--------------- src/components/Toc/TocItem/TocItem.scss | 10 ++- src/components/Toc/TocItem/TocItem.tsx | 28 +++----- src/components/Toc/TocItem/index.ts | 1 + .../Toc/TocSections/TocSections.scss | 13 ++++ .../Toc/TocSections/TocSections.tsx | 62 ++++++++++++++++++ src/components/Toc/TocSections/index.ts | 1 + .../Toc/__stories__/Toc.stories.tsx | 17 +++++ src/components/Toc/__tests__/Toc.test.tsx | 49 +++++++++++++- 10 files changed, 167 insertions(+), 102 deletions(-) delete mode 100644 src/components/Toc/Toc.scss create mode 100644 src/components/Toc/TocItem/index.ts create mode 100644 src/components/Toc/TocSections/TocSections.scss create mode 100644 src/components/Toc/TocSections/TocSections.tsx create mode 100644 src/components/Toc/TocSections/index.ts diff --git a/src/components/Toc/Toc.scss b/src/components/Toc/Toc.scss deleted file mode 100644 index 14b59f6d35..0000000000 --- a/src/components/Toc/Toc.scss +++ /dev/null @@ -1,23 +0,0 @@ -@use '../variables'; -@use '../../../styles/mixins.scss'; - -$block: '.#{variables.$ns}toc'; - -#{$block} { - &__title { - @include mixins.text-body-2(); - - color: var(--g-color-text-primary); - margin-block-end: 12px; - } - - &__sections, - &__subsections { - padding: 0; - margin: 0; - - overflow: hidden auto; - - list-style: none; - } -} diff --git a/src/components/Toc/Toc.tsx b/src/components/Toc/Toc.tsx index 50aba8a882..c47f6f0684 100644 --- a/src/components/Toc/Toc.tsx +++ b/src/components/Toc/Toc.tsx @@ -1,17 +1,14 @@ import * as React from 'react'; -import type {AriaLabelingProps, QAProps} from '../types'; +import type {QAProps} from '../types'; import {block} from '../utils/cn'; -import {filterDOMProps} from '../utils/filterDOMProps'; -import {TocItem} from './TocItem/TocItem'; +import {TocSections} from './TocSections'; import type {TocItem as TocItemType} from './types'; -import './Toc.scss'; - const b = block('toc'); -export interface TocProps extends AriaLabelingProps, QAProps { +export interface TocProps extends QAProps { className?: string; items: TocItemType[]; value?: string; @@ -20,55 +17,17 @@ export interface TocProps extends AriaLabelingProps, QAProps { } export const Toc = React.forwardRef(function Toc(props, ref) { - const {value: activeValue, items, className, onUpdate, onItemClick, qa, ...restProps} = props; + const {value: activeValue, items, className, onUpdate, qa, onItemClick} = props; return ( -