@@ -4,33 +4,21 @@ import {
44 Button ,
55 ButtonGroup ,
66 CssBaseline ,
7- Divider ,
8- Drawer ,
97 FormControl ,
108 Grid ,
11- IconButton ,
129 InputLabel ,
1310 MenuItem ,
1411 Select ,
1512 SelectChangeEvent ,
1613 Snackbar ,
17- styled ,
18- Toolbar ,
19- Typography ,
20- useTheme ,
2114} from "@mui/material" ;
2215import { useContext , useEffect , useState } from "react" ;
2316import { AnimationDurationOptions } from "../../../consts/AnimationDurationOptions" ;
2417import { PossibleTransitionValues } from "../../../consts/PossibleTransitionValues" ;
2518import PlayArrowRoundedIcon from "@mui/icons-material/PlayArrowRounded" ;
2619import PauseRoundedIcon from "@mui/icons-material/PauseRounded" ;
2720import ReplayRoundedIcon from "@mui/icons-material/ReplayRounded" ;
28- import MuiAppBar , { AppBarProps as MuiAppBarProps } from "@mui/material/AppBar" ;
29- import ChevronLeftIcon from "@mui/icons-material/ChevronLeft" ;
30- import ChevronRightIcon from "@mui/icons-material/ChevronRight" ;
31- import TableChartOutlinedIcon from "@mui/icons-material/TableChartOutlined" ;
3221import { ToolsTransitionTableProps } from "../tools/props/TransitionTableProps" ;
33- import { ToolsTransitionTable } from "../tools/TransitionTable" ;
3422import { DataContext } from "../../../components/Editor" ;
3523import { MinimizedDfaProps } from "./props/MinimizedDfaProps" ;
3624import { ToolsPlayground } from "../tools/Playground" ;
@@ -41,74 +29,15 @@ import {
4129 TransitionModel ,
4230} from "../../../models" ;
4331import { StyledTransitionLabel } from "../playground/StyledTransitionLabel" ;
44- import {
45- appBarBackgroundColor ,
46- drawerHeaderBoxShadow ,
47- } from "../../../consts/Colors" ;
4832import { MinimizedDfaStateId } from "../../../consts/StateIdsExtensions" ;
33+ import { AppBarAndDrawer } from "../../../common/AppBarAndDrawer" ;
34+ import { AppBarAndDrawerProps } from "../../../common/props/AppBarAndDrawerProps" ;
35+ import { MainContent } from "../../../common/MainContent" ;
36+ import { DrawerHeader } from "../../../common/DrawerHeader" ;
4937
50- const drawerWidth = 300 ;
5138let sliceIndex = 0 ; // index of such row (of Equivalence table) is saved where more than one Ticks are present
5239let transitionIndex = 0 ; // used to keep track of which (transition table's) row's transitions are being animated
5340
54- const Main = styled ( "main" , { shouldForwardProp : ( prop ) => prop !== "open" } ) < {
55- open ?: number ;
56- } > ( ( { theme, open } ) => ( {
57- flexGrow : 1 ,
58- padding : theme . spacing ( 3 ) ,
59-
60- ...( open === 0 && {
61- transition : theme . transitions . create ( "margin" , {
62- easing : theme . transitions . easing . sharp ,
63- duration : theme . transitions . duration . leavingScreen ,
64- } ) ,
65- } ) ,
66- marginLeft : `-${ drawerWidth } px` ,
67-
68- transition : theme . transitions . create ( "margin" , {
69- easing : theme . transitions . easing . easeOut ,
70- duration : theme . transitions . duration . enteringScreen ,
71- } ) ,
72- ...( open === 1 && {
73- marginLeft : 0 ,
74- } ) ,
75- } ) ) ;
76-
77- interface AppBarProps extends MuiAppBarProps {
78- open ?: number ;
79- }
80-
81- const AppBar = styled ( MuiAppBar , {
82- shouldForwardProp : ( prop ) => prop !== "open" ,
83- } ) < AppBarProps > ( ( { theme, open } ) => ( {
84- transition : theme . transitions . create ( [ "margin" , "width" ] , {
85- easing : theme . transitions . easing . easeOut ,
86- duration : theme . transitions . duration . enteringScreen ,
87- } ) ,
88- top : "auto" ,
89- backgroundColor : appBarBackgroundColor ,
90- position : "absolute" ,
91-
92- ...( open === 0 && {
93- transition : theme . transitions . create ( [ "margin" , "width" ] , {
94- easing : theme . transitions . easing . sharp ,
95- duration : theme . transitions . duration . leavingScreen ,
96- } ) ,
97- } ) ,
98- ...( open === 1 && {
99- width : `calc(100% - ${ drawerWidth } px)` ,
100- marginLeft : drawerWidth ,
101- } ) ,
102- } ) ) ;
103-
104- const DrawerHeader = styled ( "div" ) ( ( { theme } ) => ( {
105- display : "flex" ,
106- alignItems : "center" ,
107- padding : theme . spacing ( 0 , 1 ) ,
108- // necessary for content to be below app bar
109- ...theme . mixins . toolbar ,
110- } ) ) ;
111-
11241export const MinimizedDfa = ( props : MinimizedDfaProps ) => {
11342 console . log ( "re rendering MinimizedDfa, props: " , props ) ;
11443
@@ -144,17 +73,8 @@ export const MinimizedDfa = (props: MinimizedDfaProps) => {
14473 const [ openSnackbar , setOpenSnackbar ] = useState ( false ) ;
14574 const [ snackbarMessage , setSnackbarMessage ] = useState ( "" ) ;
14675
147- const theme = useTheme ( ) ;
14876 const [ open , setOpen ] = useState ( 1 ) ;
14977
150- const handleTableOpen = ( ) => {
151- setOpen ( 1 ) ;
152- } ;
153-
154- const handleTableClose = ( ) => {
155- setOpen ( 0 ) ;
156- } ;
157-
15878 const handleSnackbarClose = (
15979 event : React . SyntheticEvent | Event ,
16080 reason ?: string
@@ -505,6 +425,13 @@ export const MinimizedDfa = (props: MinimizedDfaProps) => {
505425 stateSize : props . stateSize ,
506426 } ;
507427
428+ const appBarAndDrawerProps : AppBarAndDrawerProps = {
429+ title : "Minimized DFA" ,
430+ open,
431+ setOpen,
432+ transitionTableProps,
433+ } ;
434+
508435 return (
509436 < >
510437 < Box sx = { { display : "flex" } } >
@@ -540,86 +467,9 @@ export const MinimizedDfa = (props: MinimizedDfaProps) => {
540467 </ Alert >
541468 </ Snackbar >
542469
543- < AppBar open = { open } >
544- < Toolbar >
545- < Grid container >
546- < Grid item xs = { 5 } >
547- < IconButton
548- color = "secondary"
549- aria-label = "open transition table"
550- onClick = { handleTableOpen }
551- // edge="start"
552- sx = { { ml : - 1 , ...( open === 1 && { mr : 2 , display : "none" } ) } }
553- >
554- < TableChartOutlinedIcon />
555- </ IconButton >
556- </ Grid >
557- < Grid item xs = { 7 } >
558- < Typography
559- noWrap
560- variant = "h5"
561- fontWeight = { "bold" }
562- color = { "black" }
563- sx = { {
564- ...( open === 0 && { mt : 0.5 } ) ,
565- } }
566- >
567- Minimized DFA
568- </ Typography >
569- </ Grid >
570- </ Grid >
571- </ Toolbar >
572- </ AppBar >
573-
574- < Drawer
575- sx = { {
576- width : drawerWidth ,
577- flexShrink : 0 ,
578- "& .MuiDrawer-paper" : {
579- position : "relative" ,
580- width : drawerWidth ,
581- boxSizing : "border-box" ,
582- backgroundColor : "#f5f5f5" ,
583- } ,
584- } }
585- variant = "persistent"
586- anchor = "left"
587- open = { open === 1 }
588- >
589- < DrawerHeader
590- sx = { {
591- justifyContent : "space-evenly" ,
592- backgroundColor : appBarBackgroundColor ,
593- boxShadow : drawerHeaderBoxShadow ,
594- } }
595- >
596- < Typography
597- noWrap
598- variant = "overline"
599- align = "center"
600- fontWeight = { "bold" }
601- >
602- Transition Table
603- </ Typography >
604- < IconButton onClick = { handleTableClose } >
605- { theme . direction === "ltr" ? (
606- < ChevronLeftIcon />
607- ) : (
608- < ChevronRightIcon />
609- ) }
610- </ IconButton >
611- </ DrawerHeader >
612- < Divider />
613- < Box
614- sx = { {
615- marginTop : "40%" ,
616- } }
617- >
618- < ToolsTransitionTable { ...transitionTableProps } />
619- </ Box >
620- </ Drawer >
470+ < AppBarAndDrawer { ...appBarAndDrawerProps } />
621471
622- < Main open = { open } >
472+ < MainContent open = { open } >
623473 < DrawerHeader />
624474 < Grid container >
625475 { /* Grid for Add a Row button and Tools */ }
@@ -675,7 +525,7 @@ export const MinimizedDfa = (props: MinimizedDfaProps) => {
675525 </ Grid >
676526 </ Grid >
677527 </ Grid >
678- </ Main >
528+ </ MainContent >
679529 </ Box >
680530 </ >
681531 ) ;
0 commit comments