From 1c29dd21096afba6f798af86a8e83c09f9d31999 Mon Sep 17 00:00:00 2001 From: Delucse <46593742+Delucse@users.noreply.github.com> Date: Tue, 15 Sep 2020 17:05:22 +0200 Subject: [PATCH] display statistics as menu, if screen is too small --- src/components/Home.js | 4 +- src/components/WorkspaceFunc.js | 2 +- src/components/WorkspaceStats.js | 165 +++++++++++++++++++++---------- 3 files changed, 116 insertions(+), 55 deletions(-) diff --git a/src/components/Home.js b/src/components/Home.js index 47555f9..3da011d 100644 --- a/src/components/Home.js +++ b/src/components/Home.js @@ -72,8 +72,8 @@ class Home extends Component { render() { return (
-
-
+
+
diff --git a/src/components/WorkspaceFunc.js b/src/components/WorkspaceFunc.js index 117bf68..86a32db 100644 --- a/src/components/WorkspaceFunc.js +++ b/src/components/WorkspaceFunc.js @@ -102,7 +102,7 @@ class WorkspaceFunc extends Component { render() { return ( -
+
({ @@ -19,65 +22,123 @@ const styles = (theme) => ({ marginLeft: '50px', padding: '3px 10px', // borderRadius: '25%' + }, + menu: { + backgroundColor: theme.palette.secondary.main, + color: theme.palette.secondary.contrastText, + width: '40px', + height: '40px', + '&:hover': { + backgroundColor: theme.palette.secondary.main, + color: theme.palette.primary.main, + } } }); class WorkspaceStats extends Component { + state={ + anchor: null + } + + handleClose = () => { + this.setState({ anchor: null }); + } + + handleClick = (event) => { + this.setState({ anchor: event.currentTarget }); + }; + render() { + const bigDisplay = !isWidthDown('xs', this.props.width); const workspace = Blockly.getMainWorkspace(); const remainingBlocksInfinity = workspace ? workspace.remainingCapacity() !== Infinity : null; + const stats =
+ + } + label={workspace ? workspace.getAllBlocks().length : 0}> + + + + } + label={this.props.create > 0 ? this.props.create : 0}> {/* initialXML is created automatically, Block is not part of the statistics */} + + + + } + label={this.props.change}> + + + + } + label={this.props.move > 0 ? this.props.move : 0}> {/* initialXML is moved automatically, Block is not part of the statistics */} + + + + } + label={this.props.delete}> + + + {remainingBlocksInfinity ? + + + + : null} +
return ( -
- - } - label={workspace ? workspace.getAllBlocks().length : 0}> - - - - } - label={this.props.create > 0 ? this.props.create : 0}> {/* initialXML is created automatically, Block is not part of the statistics */} - - - - } - label={this.props.change}> - - - - } - label={this.props.move > 0 ? this.props.move : 0}> {/* initialXML is moved automatically, Block is not part of the statistics */} - - - - } - label={this.props.delete}> - - - {remainingBlocksInfinity ? - - - - : null} -
+ bigDisplay ? +
+ {stats} +
+ : +
+ + this.handleClick(event)} + > + + + + +
+ {stats} +
+
+
); }; } @@ -98,4 +159,4 @@ const mapStateToProps = state => ({ workspaceChange: state.workspace.change }); -export default connect(mapStateToProps, null)(withStyles(styles, { withTheme: true })(WorkspaceStats)); +export default connect(mapStateToProps, null)(withStyles(styles, { withTheme: true })(withWidth()(WorkspaceStats)));