File tree Expand file tree Collapse file tree 2 files changed +100
-0
lines changed
chartlets.js/packages/lib/src/plugins/mui Expand file tree Collapse file tree 2 files changed +100
-0
lines changed Original file line number Diff line number Diff line change 1+ import {
2+ Dialog as MuiDialog ,
3+ DialogActions ,
4+ DialogContent ,
5+ type DialogContentProps ,
6+ DialogContentText ,
7+ type DialogProps as MuiDialogProps ,
8+ DialogTitle ,
9+ type DialogTitleProps ,
10+ } from "@mui/material" ;
11+
12+ import type { TypographyProps } from "@mui/material/Typography" ;
13+ import { Children , type ComponentProps , type ComponentState } from "@/index" ;
14+
15+ interface DialogState extends ComponentState {
16+ open ?: boolean ;
17+ title ?: string ;
18+ titleProps ?: DialogTitleProps & TypographyProps ;
19+ content ?: string ;
20+ contentProps ?: DialogContentProps & TypographyProps ;
21+ disableEscapeKeyDown ?: boolean ;
22+ fullScreen ?: boolean ;
23+ fullWidth ?: boolean ;
24+ maxWidth ?: MuiDialogProps [ "maxWidth" ] ;
25+ scroll ?: MuiDialogProps [ "scroll" ] ;
26+ ariaLabel ?: string ;
27+ ariaDescribedBy ?: string ;
28+ }
29+
30+ interface DialogProps extends ComponentProps , DialogState { }
31+
32+ export const Dialog = ( {
33+ id,
34+ type,
35+ style,
36+ open,
37+ title,
38+ titleProps,
39+ content,
40+ contentProps,
41+ disableEscapeKeyDown,
42+ fullScreen,
43+ fullWidth,
44+ maxWidth,
45+ scroll,
46+ ariaLabel,
47+ ariaDescribedBy,
48+ children : nodes ,
49+ onChange,
50+ } : DialogProps ) => {
51+ if ( ! open ) {
52+ return ;
53+ }
54+ const handleClose : MuiDialogProps [ "onClose" ] = ( _event , _reason ) => {
55+ if ( id ) {
56+ onChange ( {
57+ componentType : type ,
58+ id : id ,
59+ property : "open" ,
60+ value : false ,
61+ } ) ;
62+ }
63+ } ;
64+
65+ return (
66+ < MuiDialog
67+ id = { id }
68+ style = { style }
69+ open = { open }
70+ onClose = { handleClose }
71+ disableEscapeKeyDown = { disableEscapeKeyDown }
72+ fullScreen = { fullScreen }
73+ fullWidth = { fullWidth }
74+ maxWidth = { maxWidth }
75+ scroll = { scroll }
76+ aria-label = { ariaLabel }
77+ aria-describedby = { ariaDescribedBy }
78+ >
79+ { title && (
80+ < >
81+ < DialogTitle { ...titleProps } > { title } </ DialogTitle >
82+ </ >
83+ ) }
84+ { content && (
85+ < >
86+ < DialogContent { ...contentProps } >
87+ < DialogContentText > { content } </ DialogContentText >
88+ </ DialogContent >
89+ </ >
90+ ) }
91+ { nodes && (
92+ < DialogActions >
93+ < Children nodes = { nodes } onChange = { onChange } />
94+ </ DialogActions >
95+ ) }
96+ </ MuiDialog >
97+ ) ;
98+ } ;
Original file line number Diff line number Diff line change @@ -11,6 +11,7 @@ import { Switch } from "./Switch";
1111import { Tabs } from "./Tabs" ;
1212import { Typography } from "./Typography" ;
1313import { Slider } from "./Slider" ;
14+ import { Dialog } from "@/plugins/mui/Dialog" ;
1415
1516export default function mui ( ) : Plugin {
1617 return {
@@ -19,6 +20,7 @@ export default function mui(): Plugin {
1920 [ "Button" , Button ] ,
2021 [ "Checkbox" , Checkbox ] ,
2122 [ "CircularProgress" , CircularProgress ] ,
23+ [ "Dialog" , Dialog ] ,
2224 [ "IconButton" , IconButton ] ,
2325 [ "LinearProgress" , LinearProgress ] ,
2426 [ "RadioGroup" , RadioGroup ] ,
You can’t perform that action at this time.
0 commit comments