aboutsummaryrefslogtreecommitdiffstats
path: root/language-web/src/main/js
diff options
context:
space:
mode:
authorLibravatar Kristóf Marussy <marussy@mit.bme.hu>2021-07-01 23:54:32 +0200
committerLibravatar Kristóf Marussy <marussy@mit.bme.hu>2021-07-02 00:12:15 +0200
commitef73394c3c8554719412c3bf763e2f8c90ffed56 (patch)
tree28f2635848c2540cef2d1200b753a1d8083ea956 /language-web/src/main/js
parentAdd material-ui and mobx integration (diff)
downloadrefinery-ef73394c3c8554719412c3bf763e2f8c90ffed56.tar.gz
refinery-ef73394c3c8554719412c3bf763e2f8c90ffed56.tar.zst
refinery-ef73394c3c8554719412c3bf763e2f8c90ffed56.zip
Material UI theming WIP
Diffstat (limited to 'language-web/src/main/js')
-rw-r--r--language-web/src/main/js/App.jsx61
-rw-r--r--language-web/src/main/js/RootStore.jsx2
-rw-r--r--language-web/src/main/js/editor/Editor.jsx2
-rw-r--r--language-web/src/main/js/editor/EditorButtons.jsx67
-rw-r--r--language-web/src/main/js/editor/EditorStore.jsx6
-rw-r--r--language-web/src/main/js/index.jsx16
6 files changed, 118 insertions, 36 deletions
diff --git a/language-web/src/main/js/App.jsx b/language-web/src/main/js/App.jsx
index 61ded943..a0920823 100644
--- a/language-web/src/main/js/App.jsx
+++ b/language-web/src/main/js/App.jsx
@@ -2,7 +2,7 @@ import React from 'react';
2import { makeStyles } from '@material-ui/core/styles'; 2import { makeStyles } from '@material-ui/core/styles';
3import AppBar from '@material-ui/core/AppBar'; 3import AppBar from '@material-ui/core/AppBar';
4import Box from '@material-ui/core/Box'; 4import Box from '@material-ui/core/Box';
5import Fab from '@material-ui/core/Fab'; 5import Button from '@material-ui/core/Button';
6import IconButton from '@material-ui/core/IconButton'; 6import IconButton from '@material-ui/core/IconButton';
7import Toolbar from '@material-ui/core/Toolbar'; 7import Toolbar from '@material-ui/core/Toolbar';
8import Typography from '@material-ui/core/Typography'; 8import Typography from '@material-ui/core/Typography';
@@ -13,30 +13,32 @@ import Editor from './editor/Editor';
13import EditorButtons from './editor/EditorButtons'; 13import EditorButtons from './editor/EditorButtons';
14 14
15const useStyles = makeStyles(theme => ({ 15const useStyles = makeStyles(theme => ({
16 container: {
17 maxHeight: '100vh',
18 },
16 menuButton: { 19 menuButton: {
17 marginRight: theme.spacing(2), 20 marginRight: theme.spacing(2),
18 }, 21 },
19 title: { 22 title: {
20 flexGrow: 1, 23 flexGrow: 1,
21 }, 24 },
22 fab: { 25 editorBox: {
23 position: 'fixed', 26 overflow: 'auto',
24 right: theme.spacing(3),
25 bottom: theme.spacing(3),
26 zIndex: 1000,
27 }, 27 },
28 extendedIcon: {
29 marginRight: theme.spacing(1),
30 }
31})); 28}));
32 29
33export default () => { 30export default () => {
34 const classes = useStyles(); 31 const classes = useStyles();
35 32
36 return ( 33 return (
37 <> 34 <Box
35 display='flex'
36 flexDirection='column'
37 className={classes.container}
38 >
38 <AppBar 39 <AppBar
39 position='static' 40 position='static'
41 color='inherit'
40 > 42 >
41 <Toolbar> 43 <Toolbar>
42 <IconButton 44 <IconButton
@@ -56,18 +58,35 @@ export default () => {
56 </Typography> 58 </Typography>
57 </Toolbar> 59 </Toolbar>
58 </AppBar> 60 </AppBar>
59 <Box> 61 <Box
60 <EditorButtons/> 62 display='flex'
63 justifyContent='space-between'
64 alignItems='center'
65 p={1}
66 >
67 <Box
68 display='flex'
69 alignItems='center'
70 >
71 <EditorButtons/>
72 </Box>
73 <Box>
74 <Button
75 variant='outlined'
76 color='primary'
77 startIcon={<PlayArrowIcon/>}
78 >
79 Generate
80 </Button>
81 </Box>
61 </Box> 82 </Box>
62 <Editor/> 83 <Box
63 <Fab 84 flexGrow={1}
64 variant='extended' 85 flexShrink={1}
65 color='secondary' 86 className={classes.editorBox}
66 className={classes.fab}
67 > 87 >
68 <PlayArrowIcon className={classes.extendedIcon}/> 88 <Editor/>
69 Generate 89 </Box>
70 </Fab> 90 </Box>
71 </>
72 ); 91 );
73}; 92};
diff --git a/language-web/src/main/js/RootStore.jsx b/language-web/src/main/js/RootStore.jsx
index 1ee2823d..a437fdd0 100644
--- a/language-web/src/main/js/RootStore.jsx
+++ b/language-web/src/main/js/RootStore.jsx
@@ -1,4 +1,3 @@
1import { makeAutoObservable } from 'mobx';
2import React, { createContext, useContext } from 'react'; 1import React, { createContext, useContext } from 'react';
3 2
4import EditorStore from './editor/EditorStore'; 3import EditorStore from './editor/EditorStore';
@@ -8,7 +7,6 @@ export default class RootStore {
8 7
9 constructor() { 8 constructor() {
10 this.editorStore = new EditorStore(); 9 this.editorStore = new EditorStore();
11 makeAutoObservable(this);
12 } 10 }
13} 11}
14 12
diff --git a/language-web/src/main/js/editor/Editor.jsx b/language-web/src/main/js/editor/Editor.jsx
index c4b2e183..98cf2715 100644
--- a/language-web/src/main/js/editor/Editor.jsx
+++ b/language-web/src/main/js/editor/Editor.jsx
@@ -12,6 +12,8 @@ export default observer(() => {
12 const codeMirrorOptions = { 12 const codeMirrorOptions = {
13 mode: 'xtext/problem', 13 mode: 'xtext/problem',
14 indentUnit: 2, 14 indentUnit: 2,
15 theme: 'material-darker',
16 lineNumbers: editorStore.showLineNumbers,
15 }; 17 };
16 18
17 const xtextOptions = { 19 const xtextOptions = {
diff --git a/language-web/src/main/js/editor/EditorButtons.jsx b/language-web/src/main/js/editor/EditorButtons.jsx
index b9f0d076..62f82f29 100644
--- a/language-web/src/main/js/editor/EditorButtons.jsx
+++ b/language-web/src/main/js/editor/EditorButtons.jsx
@@ -1,27 +1,70 @@
1import { observer } from 'mobx-react-lite'; 1import { observer } from 'mobx-react-lite';
2import React from 'react'; 2import React from 'react';
3import IconButton from '@material-ui/core/IconButton'; 3import { makeStyles } from '@material-ui/core/styles';
4import Button from '@material-ui/core/Button';
5import ButtonGroup from '@material-ui/core/ButtonGroup';
6import Divider from '@material-ui/core/Divider';
7import FormatListNumberedIcon from '@material-ui/icons/FormatListNumbered';
4import RedoIcon from '@material-ui/icons/Redo'; 8import RedoIcon from '@material-ui/icons/Redo';
5import UndoIcon from '@material-ui/icons/Undo'; 9import UndoIcon from '@material-ui/icons/Undo';
6 10import ToggleButton from '@material-ui/lab/ToggleButton';
7import { useRootStore } from '../RootStore'; 11import { useRootStore } from '../RootStore';
8 12
13const useStyles = makeStyles(theme => ({
14 iconButton: {
15 padding: 8,
16 minWidth: 36,
17 '&.MuiButtonGroup-groupedTextHorizontal': {
18 borderRight: 0,
19 },
20 },
21 flatToggleButton: {
22 padding: 8,
23 border: 0,
24 color: theme.palette.text.primary,
25 },
26 divider: {
27 margin: theme.spacing(0.5),
28 }
29}));
30
9export default observer(() => { 31export default observer(() => {
10 const editorStore = useRootStore().editorStore; 32 const editorStore = useRootStore().editorStore;
33 const classes = useStyles();
11 return ( 34 return (
12 <> 35 <>
13 <IconButton 36 <ButtonGroup
14 disabled={!editorStore.canUndo} 37 variant='text'
15 onClick={() => editorStore.undo()}
16 > 38 >
17 <UndoIcon fontSize='small'/> 39 <Button
18 </IconButton> 40 disabled={!editorStore.canUndo}
19 <IconButton 41 onClick={() => editorStore.undo()}
20 disabled={!editorStore.canRedo} 42 className={classes.iconButton}
21 onClick={() => editorStore.redo()} 43 >
44 <UndoIcon fontSize='small'/>
45 </Button>
46 <Button
47 disabled={!editorStore.canRedo}
48 onClick={() => editorStore.redo()}
49 className={classes.iconButton}
50 >
51 <RedoIcon fontSize='small'/>
52 </Button>
53 </ButtonGroup>
54 <Divider
55 flexItem
56 orientation='vertical'
57 className={classes.divider}
58 />
59 <ToggleButton
60 value='Show line numbers'
61 selected={editorStore.showLineNumbers}
62 onChange={() => editorStore.toggleLineNumbers()}
63 size='small'
64 className={classes.flatToggleButton}
22 > 65 >
23 <RedoIcon fontSize='small'/> 66 <FormatListNumberedIcon fontSize='small'/>
24 </IconButton> 67 </ToggleButton>
25 </> 68 </>
26 ); 69 );
27}); 70});
diff --git a/language-web/src/main/js/editor/EditorStore.jsx b/language-web/src/main/js/editor/EditorStore.jsx
index 9c286c28..6b03b383 100644
--- a/language-web/src/main/js/editor/EditorStore.jsx
+++ b/language-web/src/main/js/editor/EditorStore.jsx
@@ -7,6 +7,8 @@ export default class EditorStore {
7 editor = null; 7 editor = null;
8 /** @type {string} */ 8 /** @type {string} */
9 value = ''; 9 value = '';
10 /** @type {boolean} */
11 showLineNumbers = false;
10 12
11 constructor() { 13 constructor() {
12 this.atom = createAtom('EditorStore'); 14 this.atom = createAtom('EditorStore');
@@ -72,4 +74,8 @@ export default class EditorStore {
72 redo() { 74 redo() {
73 this.editor.redo(); 75 this.editor.redo();
74 } 76 }
77
78 toggleLineNumbers() {
79 this.showLineNumbers = !this.showLineNumbers;
80 }
75} 81}
diff --git a/language-web/src/main/js/index.jsx b/language-web/src/main/js/index.jsx
index 17e6aef2..7b807c77 100644
--- a/language-web/src/main/js/index.jsx
+++ b/language-web/src/main/js/index.jsx
@@ -46,7 +46,21 @@ scope Family = 1, Person += 5..10.
46const rootStore = new RootStore(); 46const rootStore = new RootStore();
47rootStore.editorStore.updateValue(initialValue); 47rootStore.editorStore.updateValue(initialValue);
48 48
49const theme = createMuiTheme(); 49const theme = createMuiTheme({
50 palette: {
51 type: 'dark',
52 background: {
53 default: '#212121',
54 paper: '#333333',
55 },
56 primary: {
57 main: '#82aaff',
58 },
59 secondary: {
60 main: '#ff5370',
61 },
62 },
63});
50 64
51const app = ( 65const app = (
52 <ThemeProvider theme={theme}> 66 <ThemeProvider theme={theme}>