@@ -10,64 +10,110 @@ import React, { useState } from 'react';
1010
1111import { action } from '@storybook/addon-actions' ;
1212import { Meta , StoryObj } from '@storybook/react' ;
13- import { EuiButton } from '../button' ;
13+ import { EuiButton , EuiButtonEmpty , EuiButtonIcon } from '../button' ;
1414import { EuiSpacer } from '../spacer' ;
1515import { EuiText } from '../text' ;
1616import { EuiFlyout } from './flyout' ;
1717import { EuiFlyoutBody } from './flyout_body' ;
1818import { EuiFlyoutMenu , EuiFlyoutMenuProps } from './flyout_menu' ;
19- import { EuiFlyoutMenuContext } from './flyout_menu_context' ;
19+ import { EuiIcon } from '../icon' ;
20+ import { EuiPopover } from '../popover' ;
21+ import { EuiListGroup , EuiListGroupItem } from '../list_group' ;
2022
2123interface Args extends EuiFlyoutMenuProps {
22- showBackButton ? : boolean ;
24+ showBackButton : boolean ;
2325 showCustomActions : boolean ;
26+ showPopover : boolean ;
2427}
2528
2629const meta : Meta < Args > = {
2730 title : 'Layout/EuiFlyout/EuiFlyoutMenu' ,
2831 component : EuiFlyoutMenu ,
2932 argTypes : {
30- 'aria-label' : { table : { disable : true } } ,
31- backButtonProps : { table : { disable : true } } ,
32- customActions : { table : { disable : true } } ,
33- historyItems : { table : { disable : true } } ,
34- showBackButton : { control : 'boolean' } ,
3533 showCustomActions : { control : 'boolean' } ,
34+ customActions : { table : { disable : true } } ,
35+ showPopover : { control : 'boolean' } ,
36+ backButton : { table : { disable : true } } ,
37+ popover : { table : { disable : true } } ,
3638 } ,
3739 args : {
40+ hideCloseButton : false ,
3841 showBackButton : true ,
3942 showCustomActions : true ,
43+ showPopover : true ,
4044 } ,
4145} ;
4246
4347export default meta ;
4448
4549const MenuBarFlyout = ( args : Args ) => {
46- const { showCustomActions : showCustomAction , showBackButton } = args ;
50+ const { showCustomActions, hideCloseButton, showBackButton, showPopover } =
51+ args ;
4752
4853 const [ isFlyoutOpen , setIsFlyoutOpen ] = useState ( true ) ;
4954 const openFlyout = ( ) => setIsFlyoutOpen ( true ) ;
5055 const closeFlyout = ( ) => {
5156 setIsFlyoutOpen ( false ) ;
5257 } ;
5358
54- const historyItems = [ 'First item' , 'Second item' , 'Third item' ] . map (
55- ( title ) => ( {
56- title,
57- onClick : ( ) => {
58- action ( 'history item' ) ( `${ title } clicked` ) ;
59- } ,
60- } )
59+ /* Back button */
60+
61+ // TODO: back button should be internalized in EuiFlyoutMenu when historyItems are passed
62+ const backButton = (
63+ < EuiButtonEmpty size = "xs" color = "text" >
64+ < EuiIcon type = "editorUndo" /> Back
65+ </ EuiButtonEmpty >
66+ ) ;
67+
68+ /* History popover */
69+
70+ const [ isPopoverOpen , setIsPopoverOpen ] = useState ( false ) ;
71+ const handlePopoverButtonClick = ( ) => {
72+ setIsPopoverOpen ( ! isPopoverOpen ) ;
73+ } ;
74+
75+ const historyItems = [
76+ { config : { mainTitle : 'First item' } } ,
77+ { config : { mainTitle : 'Second item' } } ,
78+ { config : { mainTitle : 'Third item' } } ,
79+ ] ;
80+
81+ // TODO: history popover should be internalized in EuiFlyoutMenu when historyItems are passed
82+ const historyPopover = (
83+ < EuiPopover
84+ button = {
85+ < EuiButtonIcon iconType = "arrowDown" color = "text" aria-label = "History" />
86+ }
87+ isOpen = { isPopoverOpen }
88+ onClick = { handlePopoverButtonClick }
89+ closePopover = { ( ) => setIsPopoverOpen ( false ) }
90+ panelPaddingSize = "xs"
91+ anchorPosition = "downLeft"
92+ >
93+ < EuiListGroup gutterSize = "none" >
94+ { historyItems . map ( ( item , index ) => (
95+ < EuiListGroupItem
96+ key = { index }
97+ label = { item . config . mainTitle }
98+ size = "s"
99+ onClick = { ( ) => {
100+ action ( `Clicked ${ item . config . mainTitle } ` ) ( ) ;
101+ setIsPopoverOpen ( false ) ;
102+ } }
103+ >
104+ { item . config . mainTitle }
105+ </ EuiListGroupItem >
106+ ) ) }
107+ </ EuiListGroup >
108+ </ EuiPopover >
61109 ) ;
62110
63111 const customActions = [ 'gear' , 'broom' ] . map ( ( iconType ) => ( {
64112 iconType,
65113 onClick : ( ) => {
66114 action ( 'custom action' ) ( `${ iconType } action clicked` ) ;
67115 } ,
68- 'aria-label' : `${
69- iconType . charAt ( 0 ) . toUpperCase ( ) + iconType . slice ( 1 )
70- } action`,
116+ 'aria-label' : `${ iconType } action` ,
71117 } ) ) ;
72118
73119 return (
@@ -84,20 +130,14 @@ const MenuBarFlyout = (args: Args) => {
84130 type = "overlay"
85131 outsideClickCloses = { false }
86132 ownFocus
133+ flyoutMenuProps = { {
134+ title : 'Flyout title' ,
135+ hideCloseButton,
136+ backButton : showBackButton ? backButton : undefined ,
137+ popover : showPopover ? historyPopover : undefined ,
138+ customActions : showCustomActions ? customActions : undefined ,
139+ } }
87140 >
88- < EuiFlyoutMenuContext . Provider value = { { onClose : closeFlyout } } >
89- < EuiFlyoutMenu
90- title = "Title"
91- showBackButton = { showBackButton }
92- backButtonProps = { {
93- onClick : ( ) => {
94- action ( 'back button' ) ( 'click' ) ;
95- } ,
96- } }
97- historyItems = { historyItems }
98- customActions = { showCustomAction ? customActions : undefined }
99- />
100- </ EuiFlyoutMenuContext . Provider >
101141 < EuiFlyoutBody >
102142 < EuiText >
103143 < p > Simple flyout content.</ p >
0 commit comments