@@ -2,7 +2,25 @@ import type {Meta, StoryFn} from '@storybook/react'
2
2
import React from 'react'
3
3
import { PageLayout } from '../PageLayout'
4
4
import { NavList } from './NavList'
5
- import { ArrowRightIcon , ArrowLeftIcon , BookIcon , FileDirectoryIcon } from '@primer/octicons-react'
5
+ import {
6
+ type Icon ,
7
+ ArrowRightIcon ,
8
+ ArrowLeftIcon ,
9
+ BookIcon ,
10
+ FileDirectoryIcon ,
11
+ CodeIcon ,
12
+ RepoIcon ,
13
+ IssueOpenedIcon ,
14
+ GitPullRequestIcon ,
15
+ CommentDiscussionIcon ,
16
+ PeopleIcon ,
17
+ GitCommitIcon ,
18
+ PackageIcon ,
19
+ MilestoneIcon ,
20
+ TelescopeIcon ,
21
+ } from '@primer/octicons-react'
22
+ import Octicon from '../Octicon'
23
+ import VisuallyHidden from '../_VisuallyHidden'
6
24
7
25
const meta : Meta = {
8
26
title : 'Components/NavList' ,
@@ -328,4 +346,256 @@ export const WithTrailingActionInSubItem = () => {
328
346
)
329
347
}
330
348
349
+ export const WithExpand : StoryFn = ( ) => {
350
+ const items = [
351
+ { href : '#' , text : 'Item 4' } ,
352
+ { href : '#' , text : 'Item 5' } ,
353
+ { href : '#' , text : 'Item 6' } ,
354
+ { href : '#' , text : 'Item 7' } ,
355
+ { href : '#' , text : 'Item 8' } ,
356
+ { href : '#' , text : 'Item 9' } ,
357
+ ]
358
+
359
+ return (
360
+ < PageLayout >
361
+ < PageLayout . Pane position = "start" >
362
+ < NavList >
363
+ < NavList . Item href = "#" aria-current = "page" >
364
+ Item 1
365
+ </ NavList . Item >
366
+ < NavList . Item href = "#" > Item 2</ NavList . Item >
367
+ < NavList . Item href = "#" > Item 3</ NavList . Item >
368
+ < NavList . GroupExpand label = "Show more" items = { items } />
369
+ </ NavList >
370
+ </ PageLayout . Pane >
371
+ < PageLayout . Content > </ PageLayout . Content >
372
+ </ PageLayout >
373
+ )
374
+ }
375
+
376
+ export const WithExpandAndIcons : StoryFn = ( ) => {
377
+ const items = [
378
+ { href : '#' , text : 'Item 4' } ,
379
+ { href : '#' , text : 'Item 5' } ,
380
+ { href : '#' , text : 'Item 6' } ,
381
+ { href : '#' , text : 'Item 7' } ,
382
+ { href : '#' , text : 'Item 8' } ,
383
+ { href : '#' , text : 'Item 9' } ,
384
+ ]
385
+
386
+ return (
387
+ < PageLayout >
388
+ < PageLayout . Pane position = "start" >
389
+ < NavList >
390
+ < NavList . Item href = "#" aria-current = "page" >
391
+ Item 1
392
+ </ NavList . Item >
393
+ < NavList . Item href = "#" > Item 2</ NavList . Item >
394
+ < NavList . Item href = "#" > Item 3</ NavList . Item >
395
+ < NavList . GroupExpand label = "Show more" items = { items } />
396
+ </ NavList >
397
+ </ PageLayout . Pane >
398
+ < PageLayout . Content > </ PageLayout . Content >
399
+ </ PageLayout >
400
+ )
401
+ }
402
+
403
+ type CustomItemProps = {
404
+ text : string
405
+ leadingVisual ?: Icon
406
+ trailingVisual ?: Icon | string
407
+ }
408
+
409
+ export const ExpandWithCustomItems : StoryFn = ( ) => {
410
+ const items : { href : string ; text : string ; 'aria-current' ?: 'page' } [ ] = [
411
+ { href : '#' , text : 'Item 4' , 'aria-current' : 'page' } ,
412
+ { href : '#' , text : 'Item 5' } ,
413
+ { href : '#' , text : 'Item 6' } ,
414
+ { href : '#' , text : 'Item 7' } ,
415
+ { href : '#' , text : 'Item 8' } ,
416
+ { href : '#' , text : 'Item 9' } ,
417
+ ]
418
+
419
+ const Item = ( { leadingVisual, text, trailingVisual, ...rest } : CustomItemProps ) => {
420
+ return (
421
+ < NavList . Item key = { text } onClick = { ( ) => { } } href = "#" { ...rest } >
422
+ { leadingVisual ? (
423
+ < NavList . LeadingVisual >
424
+ < Octicon icon = { leadingVisual } />
425
+ </ NavList . LeadingVisual >
426
+ ) : null }
427
+ { text }
428
+
429
+ { trailingVisual ? (
430
+ < NavList . TrailingVisual >
431
+ { typeof trailingVisual === 'string' ? (
432
+ trailingVisual
433
+ ) : (
434
+ < Octicon icon = { trailingVisual as React . ElementType } />
435
+ ) }
436
+ < VisuallyHidden > results</ VisuallyHidden >
437
+ </ NavList . TrailingVisual >
438
+ ) : null }
439
+ </ NavList . Item >
440
+ )
441
+ }
442
+
443
+ return (
444
+ < PageLayout >
445
+ < PageLayout . Pane position = "start" >
446
+ < NavList >
447
+ < NavList . Item href = "#" > Item 1</ NavList . Item >
448
+ < NavList . Item href = "#" > Item 2</ NavList . Item >
449
+ < NavList . Item href = "#" > Item 3</ NavList . Item >
450
+ < NavList . GroupExpand label = "Show more" items = { items } renderItem = { Item } />
451
+ </ NavList >
452
+ </ PageLayout . Pane >
453
+ < PageLayout . Content > </ PageLayout . Content >
454
+ </ PageLayout >
455
+ )
456
+ }
457
+
458
+ export const ExpandWithPages : StoryFn = ( ) => {
459
+ const items = [
460
+ { href : '#' , text : 'Item 4' } ,
461
+ { href : '#' , text : 'Item 5' } ,
462
+ { href : '#' , text : 'Item 6' } ,
463
+ { href : '#' , text : 'Item 7' } ,
464
+ { href : '#' , text : 'Item 8' } ,
465
+ { href : '#' , text : 'Item 9' } ,
466
+ ]
467
+
468
+ return (
469
+ < PageLayout >
470
+ < PageLayout . Pane position = "start" >
471
+ < NavList >
472
+ < NavList . Item href = "#" aria-current = "page" >
473
+ Item 1
474
+ </ NavList . Item >
475
+ < NavList . Item href = "#" > Item 2</ NavList . Item >
476
+ < NavList . Item href = "#" > Item 3</ NavList . Item >
477
+ < NavList . GroupExpand pages = { 2 } label = "Show more" items = { items } />
478
+ </ NavList >
479
+ </ PageLayout . Pane >
480
+ < PageLayout . Content > </ PageLayout . Content >
481
+ </ PageLayout >
482
+ )
483
+ }
484
+
485
+ export const WithGroupExpand = ( ) => {
486
+ const items1 = [
487
+ { href : '#' , text : 'Item 1D' } ,
488
+ { href : '#' , text : 'Item 1E' , trailingAction : { label : 'Some action' , icon : ArrowRightIcon } } ,
489
+ ]
490
+
491
+ const items2 = [
492
+ { href : '#' , text : 'Item 2D' , trailingVisual : BookIcon } ,
493
+ { href : '#' , text : 'Item 2E' , trailingVisual : FileDirectoryIcon } ,
494
+ ]
495
+
496
+ return (
497
+ < PageLayout >
498
+ < PageLayout . Pane position = "start" >
499
+ < NavList >
500
+ < NavList . Group title = "Group 1" >
501
+ < NavList . Item aria-current = "true" href = "#" >
502
+ Item 1A
503
+ </ NavList . Item >
504
+ < NavList . Item href = "#" > Item 1B</ NavList . Item >
505
+ < NavList . Item href = "#" > Item 1C</ NavList . Item >
506
+ < NavList . GroupExpand label = "More" items = { items1 } />
507
+ </ NavList . Group >
508
+ < NavList . Group title = "Group 2" >
509
+ < NavList . Item href = "#" > Item 2A</ NavList . Item >
510
+ < NavList . Item href = "#" > Item 2B</ NavList . Item >
511
+ < NavList . Item href = "#" > Item 2C</ NavList . Item >
512
+ < NavList . GroupExpand label = "Show" items = { items2 } />
513
+ </ NavList . Group >
514
+ </ NavList >
515
+ </ PageLayout . Pane >
516
+ < PageLayout . Content > </ PageLayout . Content >
517
+ </ PageLayout >
518
+ )
519
+ }
520
+
521
+ export const GroupWithExpandAndCustomItems = ( ) => {
522
+ const Item = ( { leadingVisual : LeadingVisual , text, trailingVisual : TrailingVisual , ...rest } : CustomItemProps ) => {
523
+ return (
524
+ < NavList . Item onClick = { ( ) => { } } href = "#" { ...rest } key = { text } >
525
+ { LeadingVisual ? (
526
+ < NavList . LeadingVisual >
527
+ < LeadingVisual />
528
+ </ NavList . LeadingVisual >
529
+ ) : null }
530
+ { text }
531
+
532
+ { TrailingVisual ? (
533
+ < NavList . TrailingVisual >
534
+ { typeof TrailingVisual === 'string' ? TrailingVisual : < TrailingVisual /> }
535
+ < VisuallyHidden > results</ VisuallyHidden >
536
+ </ NavList . TrailingVisual >
537
+ ) : null }
538
+ </ NavList . Item >
539
+ )
540
+ }
541
+
542
+ const items = [
543
+ { href : '#' , text : 'Commits' , leadingVisual : GitCommitIcon , trailingVisual : '32k' } ,
544
+ { href : '#' , text : 'Packages' , leadingVisual : PackageIcon , trailingVisual : '1k' } ,
545
+ { href : '#' , text : 'Wikis' , leadingVisual : BookIcon , trailingVisual : '121' } ,
546
+ { href : '#' , text : 'Topics' , leadingVisual : MilestoneIcon , trailingVisual : '12k' } ,
547
+ { href : '#' , text : 'Marketplace' , leadingVisual : TelescopeIcon , trailingVisual : ArrowRightIcon } ,
548
+ ]
549
+
550
+ return (
551
+ < NavList >
552
+ < NavList . Group >
553
+ < NavList . Item aria-current = "page" >
554
+ < NavList . LeadingVisual >
555
+ < CodeIcon />
556
+ </ NavList . LeadingVisual >
557
+ Code
558
+ < NavList . TrailingVisual > 3k</ NavList . TrailingVisual >
559
+ </ NavList . Item >
560
+ < NavList . Item >
561
+ < NavList . LeadingVisual >
562
+ < RepoIcon />
563
+ </ NavList . LeadingVisual >
564
+ Repositories
565
+ < NavList . TrailingVisual > 713</ NavList . TrailingVisual >
566
+ </ NavList . Item >
567
+ < NavList . Item >
568
+ < NavList . LeadingVisual >
569
+ < IssueOpenedIcon />
570
+ </ NavList . LeadingVisual >
571
+ Issues
572
+ < NavList . TrailingVisual > 6k</ NavList . TrailingVisual >
573
+ </ NavList . Item >
574
+ < NavList . Item >
575
+ < NavList . LeadingVisual >
576
+ < GitPullRequestIcon />
577
+ </ NavList . LeadingVisual >
578
+ Pull requests
579
+ < NavList . TrailingVisual > 4k</ NavList . TrailingVisual >
580
+ </ NavList . Item >
581
+ < NavList . Item >
582
+ < NavList . LeadingVisual >
583
+ < CommentDiscussionIcon />
584
+ </ NavList . LeadingVisual >
585
+ Discussions
586
+ < NavList . TrailingVisual > 236</ NavList . TrailingVisual >
587
+ </ NavList . Item >
588
+ < NavList . Item >
589
+ < NavList . LeadingVisual >
590
+ < PeopleIcon />
591
+ </ NavList . LeadingVisual >
592
+ Users
593
+ < NavList . TrailingVisual > 10k</ NavList . TrailingVisual >
594
+ </ NavList . Item >
595
+ < NavList . GroupExpand items = { items } renderItem = { Item } />
596
+ </ NavList . Group >
597
+ </ NavList >
598
+ )
599
+ }
600
+
331
601
export default meta
0 commit comments