@@ -32,24 +32,26 @@ import {
3232 MenuDisclosure ,
3333 MenuList ,
3434 MenuItem ,
35- ModalContext ,
35+ Dialog ,
3636 MenuGroup ,
3737 Paragraph ,
3838 Card ,
3939 Flex ,
4040 IconButton ,
41+ MenuContext ,
4142} from '@looker/components'
43+ import { FlexItem } from '@looker/components/src'
4244const FancyMenuItem = ( {
4345 text,
4446 current,
4547} : {
4648 text : string
4749 current ?: boolean
4850} ) => {
49- const { closeModal } = useContext ( ModalContext )
51+ const { setOpen } = useContext ( MenuContext )
5052 const handleClick = ( ) => {
5153 alert ( `You picked ${ text } ` )
52- closeModal && closeModal ( )
54+ setOpen && setOpen ( false )
5355 }
5456 return (
5557 < MenuItem icon = "FavoriteOutline" onClick = { handleClick } current = { current } >
@@ -60,30 +62,54 @@ const FancyMenuItem = ({
6062
6163const HoverMenu = ( ) => {
6264 const hoverRef = React . useRef < HTMLDivElement > ( null )
65+ const [ modalIsOpen , setOpen ] = React . useState ( false )
66+ function openModal ( ) {
67+ setOpen ( true )
68+ }
69+ function closeModal ( ) {
70+ setOpen ( false )
71+ }
6372 return (
6473 < Card ref = { hoverRef } p = "large" raised height = "auto" >
6574 < Flex justifyContent = "space-between" >
66- < Paragraph >
75+ < FlexItem flex = { 1 } >
6776 Hovering in this card will show the button that triggers the menu.
68- </ Paragraph >
69- < Menu hoverDisclosureRef = { hoverRef } >
70- < MenuDisclosure >
71- < IconButton
72- icon = "DotsVert"
73- label = "More Options"
74- aria-haspopup = "true"
75- />
76- </ MenuDisclosure >
77- < MenuList compact >
78- < FancyMenuItem text = "Gouda" />
79- < FancyMenuItem text = "Swiss" current />
80- < MenuGroup compact = { false } >
81- < FancyMenuItem text = "Gouda w/ Space" />
82- < FancyMenuItem text = "Swiss w/ Space" />
83- </ MenuGroup >
84- </ MenuList >
85- </ Menu >
77+ </ FlexItem >
78+ < FlexItem >
79+ < Menu hoverDisclosureRef = { hoverRef } >
80+ < MenuContext . Consumer >
81+ { ( { showDisclosure, isOpen } ) =>
82+ ( showDisclosure || isOpen ) && (
83+ < IconButton
84+ icon = "AddAlerts"
85+ label = "Add Alert"
86+ mr = "small"
87+ onClick = { openModal }
88+ />
89+ )
90+ }
91+ </ MenuContext . Consumer >
92+ < MenuDisclosure >
93+ < IconButton
94+ icon = "DotsVert"
95+ label = "More Options"
96+ aria-haspopup = "true"
97+ />
98+ </ MenuDisclosure >
99+ < MenuList compact >
100+ < FancyMenuItem text = "Gouda" />
101+ < FancyMenuItem text = "Swiss" current />
102+ < MenuGroup compact = { false } >
103+ < FancyMenuItem text = "Gouda w/ Space" />
104+ < FancyMenuItem text = "Swiss w/ Space" />
105+ </ MenuGroup >
106+ </ MenuList >
107+ </ Menu >
108+ </ FlexItem >
86109 </ Flex >
110+ < Dialog isOpen = { modalIsOpen } onClose = { closeModal } >
111+ < Box p = "large" > Alert icon should be hidden now.</ Box >
112+ </ Dialog >
87113 </ Card >
88114 )
89115}
0 commit comments