-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
Feat(toc): Introduce #5399
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feat(toc): Introduce #5399
Changes from all commits
3ad4e7f
fa60fb5
702c6f6
4192059
6e9f8a9
78243d9
256353a
0730e23
139e586
53c261c
476014a
941ce12
a171828
8592879
7355240
da67367
8d5b109
7e2fd2d
fb56c1c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| const toc1 = [ | ||
| { depth: 1, value: 'Heading 1', data: { id: 'custom-id' } }, | ||
| { depth: 2, value: 'Heading 2' }, | ||
| { depth: 3, value: 'Heading 3' }, | ||
| ]; | ||
|
|
||
| const toc2 = [ | ||
| { depth: 1, value: 'Heading 1' }, | ||
| { depth: 3, value: 'Heading 3' }, | ||
| { depth: 3, value: 'Heading 3' }, | ||
| { depth: 2, value: 'Heading 2' }, | ||
| { depth: 4, value: 'Heading 4' }, | ||
| { depth: 6, value: 'Heading 6' }, | ||
| { depth: 5, value: 'Heading 5' }, | ||
| { depth: 1, value: 'Heading 1' }, | ||
| ]; | ||
|
|
||
| export { toc1, toc2 }; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,92 @@ | ||
| // Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
|
||
| exports[`Article/TableOfContents Blank smoke-test 1`] = ` | ||
| <details class="TableOfContents_tableOfContents__mQhnM"> | ||
| <summary> | ||
| <strong> | ||
| Table of Contents | ||
| </strong> | ||
| </summary> | ||
| <ul> | ||
| </ul> | ||
| </details> | ||
| `; | ||
|
|
||
| exports[`Article/TableOfContents Default smoke-test 1`] = ` | ||
| <details class="TableOfContents_tableOfContents__mQhnM"> | ||
| <summary> | ||
| <strong> | ||
| Table of Contents | ||
| </strong> | ||
| </summary> | ||
| <ul> | ||
| <li> | ||
| <a href="/#custom-id"> | ||
| Heading 1 | ||
| </a> | ||
| </li> | ||
| <li class="TableOfContents_depth2__G_V8e"> | ||
| <a href="/#undefined"> | ||
| Heading 2 | ||
| </a> | ||
| </li> | ||
| <li class="TableOfContents_depth3__0IhVA"> | ||
| <a href="/#undefined"> | ||
| Heading 3 | ||
| </a> | ||
| </li> | ||
| </ul> | ||
| </details> | ||
| `; | ||
|
|
||
| exports[`Article/TableOfContents Second smoke-test 1`] = ` | ||
| <details class="TableOfContents_tableOfContents__mQhnM"> | ||
| <summary> | ||
| <strong> | ||
| Table of Contents | ||
| </strong> | ||
| </summary> | ||
| <ul> | ||
| <li> | ||
| <a href="/#undefined"> | ||
| Heading 1 | ||
| </a> | ||
| </li> | ||
| <li class="TableOfContents_depth3__0IhVA"> | ||
| <a href="/#undefined"> | ||
| Heading 3 | ||
| </a> | ||
| </li> | ||
| <li class="TableOfContents_depth3__0IhVA"> | ||
| <a href="/#undefined"> | ||
| Heading 3 | ||
| </a> | ||
| </li> | ||
| <li class="TableOfContents_depth2__G_V8e"> | ||
| <a href="/#undefined"> | ||
| Heading 2 | ||
| </a> | ||
| </li> | ||
| <li class="TableOfContents_depth4__ZUaHh"> | ||
| <a href="/#undefined"> | ||
| Heading 4 | ||
| </a> | ||
| </li> | ||
| <li class="TableOfContents_depth6__jf0Ig"> | ||
| <a href="/#undefined"> | ||
| Heading 6 | ||
| </a> | ||
| </li> | ||
| <li class="TableOfContents_depth5__szqVc"> | ||
| <a href="/#undefined"> | ||
| Heading 5 | ||
| </a> | ||
| </li> | ||
| <li> | ||
| <a href="/#undefined"> | ||
| Heading 1 | ||
| </a> | ||
| </li> | ||
| </ul> | ||
| </details> | ||
| `; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,63 @@ | ||
| .tableOfContents { | ||
| background-color: var(--color-fill-banner); | ||
| border-radius: 5px; | ||
| cursor: pointer; | ||
| padding: var(--space-12); | ||
|
|
||
| strong { | ||
| color: var(--color-text-secondary); | ||
| display: inline-block; | ||
| font-size: var(--font-size-body2); | ||
| margin: 0; | ||
| text-transform: uppercase; | ||
| } | ||
|
|
||
|
|
||
| ul { | ||
| margin: var(--space-04) 0 0 var(--space-08); | ||
| padding: var(--space-08) 0 0 var(--space-24); | ||
|
|
||
| li { | ||
|
|
||
| // not use for now | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please remove this commented code 😅 |
||
| //&.depth1 { | ||
| // | ||
| //} | ||
| &.depth2 { | ||
| list-style-type: square; | ||
| margin-left: var(--space-08); | ||
| } | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Empty line between each other statement... 👀 |
||
| &.depth3 { | ||
| margin-left: var(--space-16); | ||
| } | ||
| &.depth4 { | ||
| list-style-type: square; | ||
| margin-left: var(--space-24); | ||
| } | ||
| &.depth5 { | ||
| margin-left: var(--space-32); | ||
| } | ||
| &.depth6 { | ||
| list-style-type: square; | ||
| margin-left: var(--space-40); | ||
| } | ||
|
|
||
| p { | ||
| margin: 0; | ||
| } | ||
|
|
||
| a { | ||
| font-family: var(--sans-serif); | ||
| text-decoration: underline; | ||
| text-decoration: none; | ||
| text-decoration-color: var(--black4); | ||
| transition: all ease-out 0.2s; | ||
|
|
||
| &:hover { | ||
| color: var(--brand-light); | ||
| text-decoration: none; | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| import { toc1, toc2 } from '../../../__fixtures__/page'; | ||
| import TableOfContents from './'; | ||
| import type { Meta as MetaObj, StoryObj } from '@storybook/react'; | ||
|
|
||
| type Story = StoryObj<typeof TableOfContents>; | ||
| type Meta = MetaObj<typeof TableOfContents>; | ||
|
|
||
| export const Default: Story = { | ||
| args: { | ||
| tableOfContents: toc1, | ||
| }, | ||
| }; | ||
|
|
||
| export const Second: Story = { | ||
| args: { | ||
| tableOfContents: toc2, | ||
| }, | ||
| }; | ||
|
|
||
| export const Blank: Story = { | ||
| args: { | ||
| tableOfContents: [], | ||
| }, | ||
| }; | ||
|
|
||
| export default { component: TableOfContents } as Meta; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| import { FormattedMessage } from 'react-intl'; | ||
| import Link from 'next/link'; | ||
| import styles from './index.module.scss'; | ||
| import type { FC } from 'react'; | ||
|
|
||
| type TableOfContentsProps = { | ||
| tableOfContents: { | ||
| depth: number; | ||
| value: string; | ||
| data?: { | ||
| id: string; | ||
| }; | ||
| }[]; | ||
| }; | ||
|
|
||
| const TableOfContents: FC<TableOfContentsProps> = ({ tableOfContents }) => { | ||
| return ( | ||
| <details className={styles.tableOfContents}> | ||
| <summary> | ||
| <strong> | ||
| <FormattedMessage id="components.article.tableOfContents" /> | ||
| </strong> | ||
| </summary> | ||
| <ul> | ||
| {tableOfContents.map(({ depth, value, data }) => ( | ||
| <li key={value} className={styles[`depth${depth}`]}> | ||
| <Link href={`#${data?.id}`}> | ||
| {value} | ||
| </Link> | ||
| </li> | ||
| ))} | ||
| </ul> | ||
| </details> | ||
| ); | ||
| }; | ||
|
|
||
| export default TableOfContents; |
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1 @@ | ||
| [] | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please do not commit these files.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Run |
||
| [{"major":20,"version":"20.3.1","codename":"","currentStart":"2023-04-18","ltsStart":"2023-10-24","maintenanceStart":"2024-10-22","endOfLife":"2026-04-30","npm":"9.6.7","v8":"11.3.244.8","releaseDate":"2023-06-20","modules":"115"},{"major":19,"version":"19.9.0","currentStart":"2022-10-18","maintenanceStart":"2023-04-01","endOfLife":"2023-06-01","npm":"9.6.3","v8":"10.8.168.25","releaseDate":"2023-04-10","modules":"111"},{"major":18,"version":"18.16.1","codename":"Hydrogen","currentStart":"2022-04-19","ltsStart":"2022-10-25","maintenanceStart":"2023-10-18","endOfLife":"2025-04-30","npm":"9.5.1","v8":"10.2.154.26","releaseDate":"2023-06-20","modules":"108"},{"major":17,"version":"17.9.1","currentStart":"2021-10-19","maintenanceStart":"2022-04-01","endOfLife":"2022-06-01","npm":"8.11.0","v8":"9.6.180.15","releaseDate":"2022-06-01","modules":"102"},{"major":16,"version":"16.20.1","codename":"Gallium","currentStart":"2021-04-20","ltsStart":"2021-10-26","maintenanceStart":"2022-10-18","endOfLife":"2023-09-11","npm":"8.19.4","v8":"9.4.146.26","releaseDate":"2023-06-20","modules":"93"},{"major":15,"version":"15.14.0","currentStart":"2020-10-20","maintenanceStart":"2021-04-01","endOfLife":"2021-06-01","npm":"7.7.6","v8":"8.6.395.17","releaseDate":"2021-04-06","modules":"88"},{"major":14,"version":"14.21.3","codename":"Fermium","currentStart":"2020-04-21","ltsStart":"2020-10-27","maintenanceStart":"2021-10-19","endOfLife":"2023-04-30","npm":"6.14.18","v8":"8.4.371.23","releaseDate":"2023-02-16","modules":"83"},{"major":13,"version":"13.14.0","currentStart":"2019-10-22","maintenanceStart":"2020-04-01","endOfLife":"2020-06-01","npm":"6.14.4","v8":"7.9.317.25","releaseDate":"2020-04-29","modules":"79"},{"major":12,"version":"12.22.12","codename":"Erbium","currentStart":"2019-04-23","ltsStart":"2019-10-21","maintenanceStart":"2020-11-30","endOfLife":"2022-04-30","npm":"6.14.16","v8":"7.8.279.23","releaseDate":"2022-04-05","modules":"72"},{"major":11,"version":"11.15.0","currentStart":"2018-10-23","maintenanceStart":"2019-04-22","endOfLife":"2019-06-01","npm":"6.7.0","v8":"7.0.276.38","releaseDate":"2019-04-30","modules":"67"},{"major":10,"version":"10.24.1","codename":"Dubnium","currentStart":"2018-04-24","ltsStart":"2018-10-30","maintenanceStart":"2020-05-19","endOfLife":"2021-04-30","npm":"6.14.12","v8":"6.8.275.32","releaseDate":"2021-04-06","modules":"64"},{"major":9,"version":"9.11.2","currentStart":"2017-10-01","maintenanceStart":"2018-04-01","endOfLife":"2018-06-30","npm":"5.6.0","v8":"6.2.414.46","releaseDate":"2018-06-12","modules":"59"},{"major":8,"version":"8.17.0","codename":"Carbon","currentStart":"2017-05-30","ltsStart":"2017-10-31","maintenanceStart":"2019-01-01","endOfLife":"2019-12-31","npm":"6.13.4","v8":"6.2.414.78","releaseDate":"2019-12-17","modules":"57"},{"major":7,"version":"7.10.1","currentStart":"2016-10-25","maintenanceStart":"2017-04-30","endOfLife":"2017-06-30","npm":"4.2.0","v8":"5.5.372.43","releaseDate":"2017-07-11","modules":"51"},{"major":6,"version":"6.17.1","codename":"Boron","currentStart":"2016-04-26","ltsStart":"2016-10-18","maintenanceStart":"2018-04-30","endOfLife":"2019-04-30","npm":"3.10.10","v8":"5.1.281.111","releaseDate":"2019-04-03","modules":"48"},{"major":5,"version":"5.12.0","currentStart":"2015-10-29","maintenanceStart":"2016-04-30","endOfLife":"2016-06-30","npm":"3.8.6","v8":"4.6.85.32","releaseDate":"2016-06-23","modules":"47"},{"major":4,"version":"4.9.1","codename":"Argon","currentStart":"2015-09-08","ltsStart":"2015-10-12","maintenanceStart":"2017-04-01","endOfLife":"2018-04-30","npm":"2.15.11","v8":"4.5.103.53","releaseDate":"2018-03-29","modules":"46"},{"major":0,"version":"0.12.18","currentStart":"2015-02-06","endOfLife":"2016-12-31","npm":"2.15.11","v8":"3.28.71.20","releaseDate":"2017-02-22","modules":"14"}] | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is the name of this fixture
page?