File tree 2 files changed +57
-3
lines changed
2 files changed +57
-3
lines changed Original file line number Diff line number Diff line change 1
1
import { MenuItem } from '@mui/material'
2
+ import { useState } from 'react'
3
+ import MessageDialog from './MessageDialog'
2
4
3
5
interface AppMenuItemProps {
4
6
title : string
@@ -13,13 +15,30 @@ interface AppMenuItemProps {
13
15
*/
14
16
const AppMenuItem = ( {
15
17
title = 'Simple Menu Example' ,
18
+ handleClose,
16
19
} : AppMenuItemProps ) : JSX . Element => {
20
+ const [ dialogOpen , setDialogOpen ] = useState ( false )
21
+
22
+ const handleCloseDialog = ( ) => {
23
+ setDialogOpen ( false )
24
+ handleClose && handleClose ( )
25
+ }
26
+
17
27
const handleClick = ( ) : void => {
18
- console . log ( 'Click detected in external app' )
19
- alert ( 'Hello from the external app! (AppMenuItem)' )
28
+ console . log ( 'Click detected in Simple Menu app' )
29
+ setDialogOpen ( true )
20
30
}
21
31
22
- return < MenuItem onClick = { handleClick } > { title } </ MenuItem >
32
+ return (
33
+ < >
34
+ < MenuItem onClick = { handleClick } > { title } </ MenuItem >
35
+ < MessageDialog
36
+ open = { dialogOpen }
37
+ onClose = { handleCloseDialog }
38
+ message = "Hello from the Simple Menu app! (AppMenuItem)"
39
+ />
40
+ </ >
41
+ )
23
42
}
24
43
25
44
export default AppMenuItem
Original file line number Diff line number Diff line change
1
+ import React from 'react'
2
+ import Dialog from '@mui/material/Dialog'
3
+ import DialogTitle from '@mui/material/DialogTitle'
4
+ import DialogContent from '@mui/material/DialogContent'
5
+ import DialogContentText from '@mui/material/DialogContentText'
6
+ import DialogActions from '@mui/material/DialogActions'
7
+ import Button from '@mui/material/Button'
8
+
9
+ interface MessageDialogProps {
10
+ open : boolean
11
+ onClose : ( ) => void
12
+ message : string
13
+ }
14
+
15
+ const MessageDialog : React . FC < MessageDialogProps > = ( {
16
+ open,
17
+ onClose,
18
+ message,
19
+ } ) => {
20
+ return (
21
+ < Dialog open = { open } onClose = { onClose } >
22
+ < DialogTitle > Simple Menu App</ DialogTitle >
23
+ < DialogContent >
24
+ < DialogContentText > { message } </ DialogContentText >
25
+ </ DialogContent >
26
+ < DialogActions >
27
+ < Button onClick = { onClose } color = "primary" >
28
+ Close
29
+ </ Button >
30
+ </ DialogActions >
31
+ </ Dialog >
32
+ )
33
+ }
34
+
35
+ export default MessageDialog
You can’t perform that action at this time.
0 commit comments