Skip to content

Commit 8c4d770

Browse files
committed
initial toc for desktop migration
1 parent 211417a commit 8c4d770

File tree

5 files changed

+114
-40
lines changed

5 files changed

+114
-40
lines changed

src/components/TableOfContents/ItemsList.tsx

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,14 @@ const ItemsList = ({
1515
items,
1616
depth,
1717
maxDepth,
18-
activeHash,
18+
// activeHash,
1919
...rest
2020
}: ItemsListProps) => {
2121
if (depth > maxDepth) return null
2222

23+
// FIXME: TEST
24+
const activeHash = "#web3"
25+
2326
return (
2427
<>
2528
{items.map((item, index) => {
@@ -28,15 +31,7 @@ const ItemsList = ({
2831
<ListItem key={index} m={0} {...rest}>
2932
<ToCLink depth={depth} item={item} activeHash={activeHash} />
3033
{items && (
31-
<List
32-
key={title}
33-
fontSize="sm"
34-
lineHeight={1.6}
35-
fontWeight={400}
36-
ps={4}
37-
pe={1}
38-
m={0}
39-
>
34+
<List key={title} fontSize="sm" ps={2} m={0} mt="2" spacing="2">
4035
<ItemsList
4136
items={items}
4237
depth={depth + 1}
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
import * as React from "react"
2+
import { Stack } from "@chakra-ui/react"
3+
import { Meta, StoryObj } from "@storybook/react"
4+
5+
import { ToCItem, TocNodeType } from "@/lib/types"
6+
7+
import TableOfContents from "./"
8+
9+
const tocItems: ToCItem[] = [
10+
{
11+
title: "The early Web",
12+
url: "#early-internet",
13+
items: [
14+
{ title: "Web 1.0: Read-Only (1990-2004)", url: "#web1" },
15+
{ title: "Web 2.0: Read-Write (2004-now)", url: "#web2" },
16+
],
17+
},
18+
{
19+
title: "Web 3.0: Read-Write-Own",
20+
url: "#web3",
21+
items: [
22+
{
23+
title: "What is Web3?",
24+
url: "#what-is-web3",
25+
items: [{ title: "Core ideas of Web3", url: "#core-ideas" }],
26+
},
27+
{
28+
title: "Why is Web3 important?",
29+
url: "#why-is-web3-important",
30+
items: [
31+
{ title: "Ownership", url: "#ownership" },
32+
{
33+
title: "Censorship resistance",
34+
url: "#censorship-resistance",
35+
},
36+
{
37+
title: "Decentralized autonomous organizations (DAOs)",
38+
url: "#daos",
39+
},
40+
],
41+
},
42+
{ title: "Identity", url: "#identity" },
43+
{
44+
title: "Native payments",
45+
url: "#native-payments",
46+
items: [
47+
{ title: "Cryptocurrency", url: "#cryptocurrency" },
48+
{ title: "Micropayments", url: "#micropayments" },
49+
{ title: "Tokenization", url: "#tokenization" },
50+
],
51+
},
52+
],
53+
},
54+
{
55+
title: "Web3 limitations",
56+
url: "#web3-limitations",
57+
items: [
58+
{ title: "Accessibility", url: "#accessibility" },
59+
{ title: "User experience", url: "#user-experience" },
60+
{ title: "Education", url: "#education" },
61+
{
62+
title: "Centralized infrastructure",
63+
url: "#centralized-infrastructure",
64+
},
65+
],
66+
},
67+
{
68+
title: "A decentralized future",
69+
url: "#decentralized-future",
70+
},
71+
{ title: "How can I get involved", url: "#get-involved" },
72+
{ title: "Further reading", url: "#further-reading" },
73+
]
74+
75+
const meta = {
76+
title: "Molecules / Navigation / TableOfContents",
77+
parameters: {
78+
layout: "fullscreen",
79+
},
80+
decorators: [
81+
(Story) => (
82+
<Stack minH="100vh" position="relative">
83+
<Story />
84+
</Stack>
85+
),
86+
],
87+
} satisfies Meta<typeof TableOfContents>
88+
89+
export default meta
90+
91+
type Story = StoryObj<typeof meta>
92+
93+
export const Default: Story = {
94+
render: () => <TableOfContents slug="#web3" items={tocItems} maxDepth={2} />,
95+
}

src/components/TableOfContents/TableOfContentsLink.tsx

Lines changed: 11 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -29,16 +29,20 @@ const Link = ({
2929
const $dotBg = cssVar("dot-bg")
3030

3131
const hoverOrActiveStyle: SystemStyleObject = {
32-
color: "primary.base",
32+
color: $dotBg.reference,
3333
_after: {
3434
content: `""`,
35-
background: $dotBg.reference,
35+
backgroundColor: "background.base",
3636
border: "1px",
37-
borderColor: "primary.base",
37+
borderColor: $dotBg.reference,
3838
borderRadius: "50%",
3939
boxSize: 2,
4040
position: "absolute",
41-
insetInlineStart: "-1.29rem",
41+
// 16px is the initial list padding
42+
// 8px is the padding for each nested list
43+
// 4px is half of the width of the dot
44+
// 1px for the border
45+
insetInlineStart: `calc(-16px - 8px * ${depth} - 4px - 1px)`,
4246
top: "50%",
4347
mt: -1,
4448
},
@@ -51,35 +55,17 @@ const Link = ({
5155
textDecoration="none"
5256
display="inline-block"
5357
position="relative"
54-
color="textTableOfContents"
55-
fontWeight="normal"
56-
mb="0.5rem !important"
58+
color="body.medium"
5759
width={{ base: "100%", lg: "auto" }}
5860
_hover={{
5961
...hoverOrActiveStyle,
6062
}}
6163
sx={{
62-
[$dotBg.variable]: "colors.background",
64+
[$dotBg.variable]: "var(--eth-colors-primary-hover)",
6365
"&.active": {
64-
[$dotBg.variable]: "colors.primary",
66+
[$dotBg.variable]: "var(--eth-colors-primary-visited)",
6567
...hoverOrActiveStyle,
6668
},
67-
"&.nested": {
68-
_before: {
69-
content: `"⌞"`,
70-
opacity: 0.5,
71-
display: "inline-flex",
72-
position: "absolute",
73-
insetInlineStart: -3.5,
74-
top: -1,
75-
transform: flipForRtl,
76-
},
77-
"&.active, &:hover": {
78-
_after: {
79-
insetInlineStart: "-2.29rem",
80-
},
81-
},
82-
},
8369
}}
8470
>
8571
{title}

src/components/TableOfContents/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ const TableOfContents = ({
9696
<Box mb={2} textTransform="uppercase">
9797
{t("on-this-page")}
9898
</Box>
99-
<List m={0}>
99+
<List m={0} spacing="2">
100100
<ItemsList
101101
items={items}
102102
depth={0}

src/lib/utils/toc.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,16 +31,14 @@ export const parseHeadingId = (heading: string): string => {
3131
*/
3232
export const outerListProps: ListProps = {
3333
borderStart: "1px solid",
34-
borderStartColor: "dropdownBorder",
34+
borderStartColor: "body.medium",
3535
borderTop: 0,
3636
fontSize: "sm",
37-
lineHeight: 1.6,
38-
fontWeight: 400,
37+
spacing: "2",
3938
m: 0,
4039
mt: 2,
4140
mb: 2,
4241
ps: 4,
43-
pe: 1,
4442
pt: 0,
4543
sx: {
4644
// TODO: Flip to object syntax with `lg` token after completion of Chakra migration

0 commit comments

Comments
 (0)