@@ -125,11 +125,13 @@ function nestContentEntries(entries: Entry[]): NestedEntry[] {
125
125
const position = entry . ref . compareDocumentPosition ( previousEntry . ref ) ;
126
126
127
127
const isAfter = ! ! ( position & Node . DOCUMENT_POSITION_PRECEDING ) ;
128
- const hierarchy =
129
- TAGNAME_ORDER . indexOf ( entry . ref . tagName ) <=
130
- TAGNAME_ORDER . indexOf ( entries [ i - 1 ] ?. ref . tagName ?? '' ) ;
128
+ const shouldNest =
129
+ entry . ref . tagName === entries . at ( 0 ) ?. ref . tagName
130
+ ? false
131
+ : TAGNAME_ORDER . indexOf ( entry . ref . tagName ) <=
132
+ TAGNAME_ORDER . indexOf ( entries [ i - 1 ] ?. ref . tagName ?? '' ) ;
131
133
132
- if ( isAfter && hierarchy && parentEntry ) {
134
+ if ( isAfter && shouldNest && parentEntry ) {
133
135
const parent : NestedEntry = {
134
136
entry,
135
137
children : [ ] ,
@@ -153,9 +155,10 @@ export function StoryTableOfContents() {
153
155
const nestedEntries = useMemo ( ( ) => nestContentEntries ( entries ) , [ entries ] ) ;
154
156
const [ activeId , setActiveId ] = useActiveSection ( entries ) ;
155
157
158
+ if ( nestedEntries . length === 0 ) return null ;
156
159
return (
157
160
< StoryIndexContainer >
158
- < StoryIndexTitle > Contents </ StoryIndexTitle >
161
+ < StoryIndexTitle > On this page </ StoryIndexTitle >
159
162
< StoryIndexListContainer >
160
163
< StoryIndexList >
161
164
{ nestedEntries . map ( entry => (
@@ -192,16 +195,14 @@ function StoryContentsList({
192
195
child . children . some ( grandChild => grandChild . entry . ref . id === activeId )
193
196
) ;
194
197
195
- // Apply active styling if this entry is active OR if any child is active
196
- const shouldShowActive = isActive || hasActiveChild ;
197
-
198
198
const LinkComponent = isChild ? StyledChildLink : StyledLink ;
199
199
200
200
return (
201
201
< li >
202
202
< LinkComponent
203
203
href = { `#${ entry . entry . ref . id } ` }
204
- isActive = { shouldShowActive }
204
+ isActive = { isActive }
205
+ hasActiveChild = { hasActiveChild }
205
206
onClick = { ( ) => setActiveId ( entry . entry . ref . id ) }
206
207
>
207
208
< TextOverflow > { entry . entry . title } </ TextOverflow >
@@ -236,95 +237,75 @@ const StoryIndexContainer = styled('div')`
236
237
}
237
238
` ;
238
239
239
- const StoryIndexListContainer = styled ( 'div' ) `
240
- > ul {
241
- padding-left: 0;
242
- margin-top: ${ space ( 1 ) } ;
243
- }
244
-
245
- > ul > li {
246
- padding-left: 0;
247
- margin-top: ${ space ( 0.5 ) } ;
248
-
249
- > a {
250
- margin-bottom: ${ space ( 0.25 ) } ;
251
- }
252
- }
253
- ` ;
240
+ const StoryIndexListContainer = styled ( 'div' ) `` ;
254
241
255
242
const StoryIndexTitle = styled ( 'div' ) `
256
243
line-height: 1.25;
257
- font-size: ${ p => p . theme . fontSize . lg } ;
258
- font-weight: ${ p => p . theme . fontWeight . bold } ;
259
- color: ${ p => p . theme . headingColor } ;
260
- border-bottom: 2px solid ${ p => p . theme . border } ;
261
- padding: 0 0 ${ space ( 1 ) } 0 ;
262
- margin: 0 0 ${ space ( 1 ) } 0 ;
244
+ font-size: ${ p => p . theme . fontSize . md } ;
245
+ font-weight: ${ p => p . theme . fontWeight . normal } ;
246
+ color: ${ p => p . theme . tokens . content . primary } ;
247
+ height: 28px ;
248
+ display: flex ;
249
+ align-items: center ;
263
250
` ;
264
251
265
252
const StoryIndexList = styled ( 'ul' ) `
266
253
list-style: none;
267
254
padding-left: ${ space ( 1 ) } ;
255
+ border-left: 1px solid ${ p => p . theme . tokens . border . muted } ;
268
256
margin: 0;
269
- width: 200px;
270
-
271
- li {
272
- margin-bottom: ${ space ( 0.5 ) } ;
273
-
274
- ul {
275
- margin-top: ${ space ( 0.5 ) } ;
276
- margin-bottom: ${ space ( 0.5 ) } ;
277
-
278
- li {
279
- margin-bottom: ${ space ( 0.25 ) } ;
280
- }
281
- }
257
+ margin-left: -${ space ( 2 ) } ;
258
+ min-width: 200px;
259
+ display: flex;
260
+ flex-direction: column;
261
+
262
+ ul {
263
+ margin-left: -${ space ( 1 ) } ;
264
+ padding-left: ${ space ( 1 ) } ;
265
+ border-left: none;
282
266
}
283
267
` ;
284
268
285
- const StyledLink = styled ( 'a' ) < { isActive : boolean } > `
286
- padding: ${ space ( 0.5 ) } ${ space ( 0.75 ) } ;
269
+ const StyledLink = styled ( 'a' ) < { hasActiveChild : boolean ; isActive : boolean } > `
287
270
display: block;
288
- color: ${ p => p . theme . textColor } ;
271
+ color: ${ p => p . theme . tokens . content . muted } ;
289
272
text-decoration: none;
273
+ line-height: 1;
290
274
font-size: ${ p => p . theme . fontSize . md } ;
291
- line-height: 1.4;
292
- transition: all 0.15s ease;
275
+ padding: ${ space ( 1 ) } ;
276
+ transition: color 80ms ease-out;
277
+ border-radius: ${ p => p . theme . borderRadius } ;
293
278
position: relative;
294
279
295
280
&:hover {
296
- background: ${ p => p . theme . hover } ;
281
+ background: ${ p => p . theme . tokens . background . tertiary } ;
297
282
color: ${ p => p . theme . textColor } ;
298
283
}
299
284
300
285
${ p =>
301
286
p . isActive &&
302
287
`
303
- color: ${ p . theme . textColor } ;
304
- font-weight: ${ p . theme . fontWeight . bold } ;
288
+ color: ${ p . theme . tokens . content . accent } ;
289
+ &::before {
290
+ content: '';
291
+ display: block;
292
+ position: absolute;
293
+ left: -${ space ( 1 ) } ;
294
+ width: 4px;
295
+ height: 16px;
296
+ border-radius: 4px;
297
+ transform: translateX(-2px);
298
+ background: ${ p . theme . tokens . graphics . accent } ;
299
+ }
305
300
` }
306
- ` ;
307
-
308
- const StyledChildLink = styled ( 'a' ) < { isActive : boolean } > `
309
- font-size: ${ p => p . theme . fontSize . sm } ;
310
- padding: ${ space ( 0.25 ) } ${ space ( 0.5 ) } ;
311
- margin-left: ${ space ( 0.5 ) } ;
312
- border-left: 2px solid transparent;
313
- display: block;
314
- color: ${ p => p . theme . textColor } ;
315
- text-decoration: none;
316
- line-height: 1.4;
317
- transition: all 0.15s ease;
318
-
319
- &:hover {
320
- background: ${ p => p . theme . hover } ;
321
- color: ${ p => p . theme . textColor } ;
322
- border-left-color: ${ p => p . theme . activeText } ;
323
- }
324
-
325
301
${ p =>
326
- p . isActive &&
302
+ p . hasActiveChild &&
327
303
`
328
- border-left- color: ${ p . theme . activeText } ;
304
+ color: ${ p . theme . tokens . content . primary } ;
329
305
` }
330
306
` ;
307
+
308
+ const StyledChildLink = styled ( StyledLink ) < { isActive : boolean } > `
309
+ margin-left: ${ space ( 2 ) } ;
310
+ border-left: 0;
311
+ ` ;
0 commit comments