@@ -12,6 +12,7 @@ import {
12
12
import type { Box , Highlight , HighlightOptions , RawHighlightOptions } from './types' ;
13
13
import {
14
14
createElement ,
15
+ createIcon ,
15
16
getEventDetails ,
16
17
hidePopover ,
17
18
isOverMenu ,
@@ -28,54 +29,6 @@ const menuId = 'storybook-highlights-menu';
28
29
const rootId = 'storybook-highlights-root' ;
29
30
const storybookRootId = 'storybook-root' ;
30
31
31
- const chevronLeft = ( ) =>
32
- createElement (
33
- 'svg' ,
34
- { width : '14' , height : '14' , viewBox : '0 0 14 14' , xmlns : 'http://www.w3.org/2000/svg' } ,
35
- [
36
- createElement ( 'path' , {
37
- 'fill-rule' : 'evenodd' ,
38
- 'clip-rule' : 'evenodd' ,
39
- d : 'M9.10355 10.1464C9.29882 10.3417 9.29882 10.6583 9.10355 10.8536C8.90829 11.0488 8.59171 11.0488 8.39645 10.8536L4.89645 7.35355C4.70118 7.15829 4.70118 6.84171 4.89645 6.64645L8.39645 3.14645C8.59171 2.95118 8.90829 2.95118 9.10355 3.14645C9.29882 3.34171 9.29882 3.65829 9.10355 3.85355L5.95711 7L9.10355 10.1464Z' ,
40
- fill : 'currentColor' ,
41
- } ) ,
42
- ]
43
- ) ;
44
-
45
- const chevronRight = ( ) =>
46
- createElement (
47
- 'svg' ,
48
- { width : '14' , height : '14' , viewBox : '0 0 14 14' , xmlns : 'http://www.w3.org/2000/svg' } ,
49
- [
50
- createElement ( 'path' , {
51
- 'fill-rule' : 'evenodd' ,
52
- 'clip-rule' : 'evenodd' ,
53
- d : 'M4.89645 10.1464C4.70118 10.3417 4.70118 10.6583 4.89645 10.8536C5.09171 11.0488 5.40829 11.0488 5.60355 10.8536L9.10355 7.35355C9.29882 7.15829 9.29882 6.84171 9.10355 6.64645L5.60355 3.14645C5.40829 2.95118 5.09171 2.95118 4.89645 3.14645C4.70118 3.34171 4.70118 3.65829 4.89645 3.85355L8.04289 7L4.89645 10.1464Z' ,
54
- fill : 'currentColor' ,
55
- } ) ,
56
- ]
57
- ) ;
58
-
59
- const info = ( ) =>
60
- createElement (
61
- 'svg' ,
62
- { width : '14' , height : '14' , viewBox : '0 0 14 14' , xmlns : 'http://www.w3.org/2000/svg' } ,
63
- [
64
- createElement ( 'path' , {
65
- 'fill-rule' : 'evenodd' ,
66
- 'clip-rule' : 'evenodd' ,
67
- d : 'M7 5.5a.5.5 0 01.5.5v4a.5.5 0 01-1 0V6a.5.5 0 01.5-.5zM7 4.5A.75.75 0 107 3a.75.75 0 000 1.5z' ,
68
- fill : 'currentColor' ,
69
- } ) ,
70
- createElement ( 'path' , {
71
- 'fill-rule' : 'evenodd' ,
72
- 'clip-rule' : 'evenodd' ,
73
- d : 'M7 14A7 7 0 107 0a7 7 0 000 14zm0-1A6 6 0 107 1a6 6 0 000 12z' ,
74
- fill : 'currentColor' ,
75
- } ) ,
76
- ]
77
- ) ;
78
-
79
32
export const useHighlights = ( channel : Channel ) => {
80
33
if ( globalThis . __STORYBOOK_HIGHLIGHT_INITIALIZED ) {
81
34
return ;
@@ -395,7 +348,7 @@ export const useHighlights = (channel: Channel) => {
395
348
font-family: inherit;
396
349
font-size: inherit;
397
350
}
398
- #${ menuId } button:focus {
351
+ #${ menuId } button:focus-visible {
399
352
outline-color: #029CFD;
400
353
}
401
354
#${ menuId } button:hover {
@@ -415,7 +368,7 @@ export const useHighlights = (channel: Channel) => {
415
368
margin: 1px;
416
369
color: #73828C;
417
370
}
418
- #${ menuId } li > button:hover svg, #${ menuId } li > button:focus svg {
371
+ #${ menuId } li > button:hover svg, #${ menuId } li > button:focus-visible svg {
419
372
color: #029CFD;
420
373
}
421
374
#${ menuId } .element-list li svg {
@@ -441,6 +394,7 @@ export const useHighlights = (channel: Channel) => {
441
394
#${ menuId } .menu-item-content {
442
395
display: flex;
443
396
flex-direction: column;
397
+ flex-grow: 1;
444
398
}
445
399
` ,
446
400
] )
@@ -480,9 +434,9 @@ export const useHighlights = (channel: Channel) => {
480
434
const asButton = selectable || selectedElement ;
481
435
return createElement ( 'li' , props , [
482
436
createElement ( asButton ? 'button' : 'div' , asButton ? { type : 'button' } : { } , [
483
- selectedElement ? chevronLeft ( ) : null ,
437
+ selectedElement ? createIcon ( 'chevronLeft' ) : null ,
484
438
createElement ( 'code' , { } , [ target . element . outerHTML ] ) ,
485
- selectable ? chevronRight ( ) : null ,
439
+ selectable ? createIcon ( 'chevronRight' ) : null ,
486
440
] ) ,
487
441
] ) ;
488
442
} )
@@ -507,25 +461,28 @@ export const useHighlights = (channel: Channel) => {
507
461
createElement (
508
462
'ul' ,
509
463
{ class : 'menu-items' } ,
510
- menuItems . map ( ( { id, title, description, icon, clickEvent : event } ) => {
511
- const onClick =
512
- event && ( ( ) => channel . emit ( event , id , getEventDetails ( target ) ) ) ;
513
- return createElement ( 'li' , { } , [
514
- createElement (
515
- onClick ? 'button' : 'div' ,
516
- onClick
517
- ? { class : 'menu-item' , type : 'button' , onClick }
518
- : { class : 'menu-item' } ,
519
- [
520
- icon === 'info' ? info ( ) : null ,
521
- createElement ( 'div' , { class : 'menu-item-content' } , [
522
- createElement ( description ? 'strong' : 'span' , { } , [ title ] ) ,
523
- description && createElement ( 'span' , { } , [ description ] ) ,
524
- ] ) ,
525
- ]
526
- ) ,
527
- ] ) ;
528
- } )
464
+ menuItems . map (
465
+ ( { id, title, description, iconLeft, iconRight, clickEvent : event } ) => {
466
+ const onClick =
467
+ event && ( ( ) => channel . emit ( event , id , getEventDetails ( target ) ) ) ;
468
+ return createElement ( 'li' , { } , [
469
+ createElement (
470
+ onClick ? 'button' : 'div' ,
471
+ onClick
472
+ ? { class : 'menu-item' , type : 'button' , onClick }
473
+ : { class : 'menu-item' } ,
474
+ [
475
+ iconLeft ? createIcon ( iconLeft ) : null ,
476
+ createElement ( 'div' , { class : 'menu-item-content' } , [
477
+ createElement ( description ? 'strong' : 'span' , { } , [ title ] ) ,
478
+ description && createElement ( 'span' , { } , [ description ] ) ,
479
+ ] ) ,
480
+ iconRight ? createIcon ( iconRight ) : null ,
481
+ ]
482
+ ) ,
483
+ ] ) ;
484
+ }
485
+ )
529
486
) ,
530
487
] )
531
488
)
0 commit comments