aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnton Dubik <anton.dubik33@gmail.com>2020-01-04 01:19:50 +0300
committerGitHub <noreply@github.com>2020-01-04 01:19:50 +0300
commit1a3c02e2fb77d7cc253d05b5b198c1fe75279926 (patch)
treec044f7cd6c2b2a829e09372859f25efafe54b440
parente41a613afa7fba8c89c6d88a3607bfc6e5081bb7 (diff)
parenta7b17c6f460031c8caf0b3f6173b817b4a6cc8fa (diff)
downloadchrono-cube-ui-1a3c02e2fb77d7cc253d05b5b198c1fe75279926.tar.gz
Merge pull request #14 from Eug-VS/theme
Create theme and style existing components
-rw-r--r--package-lock.json117
-rw-r--r--package.json4
-rw-r--r--src/components/Header/Header.js44
-rw-r--r--src/components/Scoreboard/Scoreboard.js12
-rw-r--r--src/components/Scoreboard/Solution.js76
-rw-r--r--src/components/Timer/Timer.js30
-rw-r--r--src/index.js40
-rw-r--r--src/theme.js40
8 files changed, 168 insertions, 195 deletions
diff --git a/package-lock.json b/package-lock.json
index 647c38b..df69def 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -1005,24 +1005,6 @@
"resolved": "https://registry.npmjs.org/@emotion/hash/-/hash-0.7.4.tgz",
"integrity": "sha512-fxfMSBMX3tlIbKUdtGKxqB1fyrH6gVrX39Gsv3y8lRYKUqlgDt3UMqQyGnR1bQMa2B8aGnhLZokZgg8vT0Le+A=="
},
- "@emotion/is-prop-valid": {
- "version": "0.8.6",
- "resolved": "https://registry.npmjs.org/@emotion/is-prop-valid/-/is-prop-valid-0.8.6.tgz",
- "integrity": "sha512-mnZMho3Sq8BfzkYYRVc8ilQTnc8U02Ytp6J1AwM6taQStZ3AhsEJBX2LzhA/LJirNCwM2VtHL3VFIZ+sNJUgUQ==",
- "requires": {
- "@emotion/memoize": "0.7.4"
- }
- },
- "@emotion/memoize": {
- "version": "0.7.4",
- "resolved": "https://registry.npmjs.org/@emotion/memoize/-/memoize-0.7.4.tgz",
- "integrity": "sha512-Ja/Vfqe3HpuzRsG1oBtWTHk2PGZ7GR+2Vz5iYGelAw8dx32K0y7PjVuxK6z1nMpZOqAFsRUPCkK1YjJ56qJlgw=="
- },
- "@emotion/unitless": {
- "version": "0.7.5",
- "resolved": "https://registry.npmjs.org/@emotion/unitless/-/unitless-0.7.5.tgz",
- "integrity": "sha512-OWORNpfjMsSSUBVrRBVGECkhWcULOAJz9ZW8uK9qgxD+87M7jHRcvh/A96XXNhXTLmKcoYSQtBEX7lHMO7YRwg=="
- },
"@hapi/address": {
"version": "2.1.4",
"resolved": "https://registry.npmjs.org/@hapi/address/-/address-2.1.4.tgz",
@@ -1269,6 +1251,14 @@
"react-transition-group": "^4.3.0"
}
},
+ "@material-ui/icons": {
+ "version": "4.5.1",
+ "resolved": "https://registry.npmjs.org/@material-ui/icons/-/icons-4.5.1.tgz",
+ "integrity": "sha512-YZ/BgJbXX4a0gOuKWb30mBaHaoXRqPanlePam83JQPZ/y4kl+3aW0Wv9tlR70hB5EGAkEJGW5m4ktJwMgxQAeA==",
+ "requires": {
+ "@babel/runtime": "^7.4.4"
+ }
+ },
"@material-ui/styles": {
"version": "4.8.2",
"resolved": "https://registry.npmjs.org/@material-ui/styles/-/styles-4.8.2.tgz",
@@ -2455,22 +2445,6 @@
"resolved": "https://registry.npmjs.org/babel-plugin-named-asset-import/-/babel-plugin-named-asset-import-0.3.5.tgz",
"integrity": "sha512-sGhfINU+AuMw9oFAdIn/nD5sem3pn/WgxAfDZ//Q3CnF+5uaho7C7shh2rKLk6sKE/XkfmyibghocwKdVjLIKg=="
},
- "babel-plugin-styled-components": {
- "version": "1.10.6",
- "resolved": "https://registry.npmjs.org/babel-plugin-styled-components/-/babel-plugin-styled-components-1.10.6.tgz",
- "integrity": "sha512-gyQj/Zf1kQti66100PhrCRjI5ldjaze9O0M3emXRPAN80Zsf8+e1thpTpaXJXVHXtaM4/+dJEgZHyS9Its+8SA==",
- "requires": {
- "@babel/helper-annotate-as-pure": "^7.0.0",
- "@babel/helper-module-imports": "^7.0.0",
- "babel-plugin-syntax-jsx": "^6.18.0",
- "lodash": "^4.17.11"
- }
- },
- "babel-plugin-syntax-jsx": {
- "version": "6.18.0",
- "resolved": "https://registry.npmjs.org/babel-plugin-syntax-jsx/-/babel-plugin-syntax-jsx-6.18.0.tgz",
- "integrity": "sha1-CvMqmm4Tyno/1QaeYtew9Y0NiUY="
- },
"babel-plugin-syntax-object-rest-spread": {
"version": "6.13.0",
"resolved": "https://registry.npmjs.org/babel-plugin-syntax-object-rest-spread/-/babel-plugin-syntax-object-rest-spread-6.13.0.tgz",
@@ -3062,11 +3036,6 @@
"resolved": "https://registry.npmjs.org/camelcase/-/camelcase-5.3.1.tgz",
"integrity": "sha512-L28STB170nwWS63UjtlEOE3dldQApaJXZkOI1uMFfzf3rRuPegHaHesyee+YxQ+W6SvRDQV6UrdOdRiR153wJg=="
},
- "camelize": {
- "version": "1.0.0",
- "resolved": "https://registry.npmjs.org/camelize/-/camelize-1.0.0.tgz",
- "integrity": "sha1-FkpUg+Yw+kMh5a8HAg5TGDGyYJs="
- },
"caniuse-api": {
"version": "3.0.0",
"resolved": "https://registry.npmjs.org/caniuse-api/-/caniuse-api-3.0.0.tgz",
@@ -4172,11 +4141,6 @@
"postcss": "^7.0.5"
}
},
- "css-color-keywords": {
- "version": "1.0.0",
- "resolved": "https://registry.npmjs.org/css-color-keywords/-/css-color-keywords-1.0.0.tgz",
- "integrity": "sha1-/qJhbcZ2spYmhrOvjb2+GAskTgU="
- },
"css-color-names": {
"version": "0.0.4",
"resolved": "https://registry.npmjs.org/css-color-names/-/css-color-names-0.0.4.tgz",
@@ -4267,23 +4231,6 @@
"resolved": "https://registry.npmjs.org/css-select-base-adapter/-/css-select-base-adapter-0.1.1.tgz",
"integrity": "sha512-jQVeeRG70QI08vSTwf1jHxp74JoZsr2XSgETae8/xC8ovSnL2WF87GTLO86Sbwdt2lK4Umg4HnnwMO4YF3Ce7w=="
},
- "css-to-react-native": {
- "version": "2.3.2",
- "resolved": "https://registry.npmjs.org/css-to-react-native/-/css-to-react-native-2.3.2.tgz",
- "integrity": "sha512-VOFaeZA053BqvvvqIA8c9n0+9vFppVBAHCp6JgFTtTMU3Mzi+XnelJ9XC9ul3BqFzZyQ5N+H0SnwsWT2Ebchxw==",
- "requires": {
- "camelize": "^1.0.0",
- "css-color-keywords": "^1.0.0",
- "postcss-value-parser": "^3.3.0"
- },
- "dependencies": {
- "postcss-value-parser": {
- "version": "3.3.1",
- "resolved": "https://registry.npmjs.org/postcss-value-parser/-/postcss-value-parser-3.3.1.tgz",
- "integrity": "sha512-pISE66AbVkp4fDQ7VHBwRNXzAAKJjw4Vw7nWI/+Q3vuly7SNfgYXvm6i5IgFylHGK5sP/xHAbB7N49OS4gWNyQ=="
- }
- }
- },
"css-tree": {
"version": "1.0.0-alpha.37",
"resolved": "https://registry.npmjs.org/css-tree/-/css-tree-1.0.0-alpha.37.tgz",
@@ -7118,11 +7065,6 @@
"resolved": "https://registry.npmjs.org/is-typedarray/-/is-typedarray-1.0.0.tgz",
"integrity": "sha1-5HnICFjfDBsR3dppQPlgEfzaSpo="
},
- "is-what": {
- "version": "3.5.0",
- "resolved": "https://registry.npmjs.org/is-what/-/is-what-3.5.0.tgz",
- "integrity": "sha512-00pwt/Jf7IaRh5m2Dp93Iw8LG2cd3OpDj3NrD1XPNUpAWVxPvBP296p4IiGmIU4Ur0f3f56IoIM+fS2pFYF+tQ=="
- },
"is-windows": {
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/is-windows/-/is-windows-1.0.2.tgz",
@@ -8767,11 +8709,6 @@
"p-is-promise": "^2.0.0"
}
},
- "memoize-one": {
- "version": "5.1.1",
- "resolved": "https://registry.npmjs.org/memoize-one/-/memoize-one-5.1.1.tgz",
- "integrity": "sha512-HKeeBpWvqiVJD57ZUAsJNm71eHTykffzcLZVYWiVfQeI1rJtuEaS7hQiEpWfVVk18donPwJEcFKIkCmPJNOhHA=="
- },
"memory-fs": {
"version": "0.4.1",
"resolved": "https://registry.npmjs.org/memory-fs/-/memory-fs-0.4.1.tgz",
@@ -8805,14 +8742,6 @@
}
}
},
- "merge-anything": {
- "version": "2.4.4",
- "resolved": "https://registry.npmjs.org/merge-anything/-/merge-anything-2.4.4.tgz",
- "integrity": "sha512-l5XlriUDJKQT12bH+rVhAHjwIuXWdAIecGwsYjv2LJo+dA1AeRTmeQS+3QBpO6lEthBMDi2IUMpLC1yyRvGlwQ==",
- "requires": {
- "is-what": "^3.3.1"
- }
- },
"merge-deep": {
"version": "3.0.2",
"resolved": "https://registry.npmjs.org/merge-deep/-/merge-deep-3.0.2.tgz",
@@ -12841,26 +12770,6 @@
"schema-utils": "^2.0.1"
}
},
- "styled-components": {
- "version": "4.4.1",
- "resolved": "https://registry.npmjs.org/styled-components/-/styled-components-4.4.1.tgz",
- "integrity": "sha512-RNqj14kYzw++6Sr38n7197xG33ipEOktGElty4I70IKzQF1jzaD1U4xQ+Ny/i03UUhHlC5NWEO+d8olRCDji6g==",
- "requires": {
- "@babel/helper-module-imports": "^7.0.0",
- "@babel/traverse": "^7.0.0",
- "@emotion/is-prop-valid": "^0.8.1",
- "@emotion/unitless": "^0.7.0",
- "babel-plugin-styled-components": ">= 1",
- "css-to-react-native": "^2.2.2",
- "memoize-one": "^5.0.0",
- "merge-anything": "^2.2.4",
- "prop-types": "^15.5.4",
- "react-is": "^16.6.0",
- "stylis": "^3.5.0",
- "stylis-rule-sheet": "^0.0.10",
- "supports-color": "^5.5.0"
- }
- },
"stylehacks": {
"version": "4.0.3",
"resolved": "https://registry.npmjs.org/stylehacks/-/stylehacks-4.0.3.tgz",
@@ -12883,16 +12792,6 @@
}
}
},
- "stylis": {
- "version": "3.5.4",
- "resolved": "https://registry.npmjs.org/stylis/-/stylis-3.5.4.tgz",
- "integrity": "sha512-8/3pSmthWM7lsPBKv7NXkzn2Uc9W7NotcwGNpJaa3k7WMM1XDCA4MgT5k/8BIexd5ydZdboXtU90XH9Ec4Bv/Q=="
- },
- "stylis-rule-sheet": {
- "version": "0.0.10",
- "resolved": "https://registry.npmjs.org/stylis-rule-sheet/-/stylis-rule-sheet-0.0.10.tgz",
- "integrity": "sha512-nTbZoaqoBnmK+ptANthb10ZRZOGC+EmTLLUxeYIuHNkEKcmKgXX1XWKkUBT2Ac4es3NybooPe0SmvKdhKJZAuw=="
- },
"supports-color": {
"version": "5.5.0",
"resolved": "https://registry.npmjs.org/supports-color/-/supports-color-5.5.0.tgz",
diff --git a/package.json b/package.json
index 185f490..de99244 100644
--- a/package.json
+++ b/package.json
@@ -4,14 +4,14 @@
"private": true,
"dependencies": {
"@material-ui/core": "^4.8.2",
+ "@material-ui/icons": "^4.5.1",
"@testing-library/jest-dom": "^4.2.4",
"@testing-library/react": "^9.4.0",
"@testing-library/user-event": "^7.2.1",
"axios": "^0.19.0",
"react": "^16.12.0",
"react-dom": "^16.12.0",
- "react-scripts": "3.3.0",
- "styled-components": "^4.4.1"
+ "react-scripts": "3.3.0"
},
"scripts": {
"start": "react-scripts start",
diff --git a/src/components/Header/Header.js b/src/components/Header/Header.js
index 9bfe5c4..1c4e77d 100644
--- a/src/components/Header/Header.js
+++ b/src/components/Header/Header.js
@@ -5,38 +5,38 @@ import {
Tab,
Typography
} from "@material-ui/core";
-import styled from 'styled-components';
+import { makeStyles } from '@material-ui/core/styles';
+
+const useStyles = makeStyles(theme => ({
+ header: {
+ backgroundColor: theme.palette.primary.dark,
+ },
+ logo: {
+ color: theme.palette.orange.main,
+ margin: theme.spacing(2, 3, 2, 2)
+ },
+}));
+
const Header = ({ setPage }) => {
+ const classes = useStyles();
const handleChange = (event, newPage) => {
setPage(newPage);
};
+ const menuItems = ['app', 'profile', 'scoreboard', 'news'];
+
return (
- <AppBar position="static">
- <TabsWrapper onChange={handleChange}>
- <Typography variant="h4" id="logo"> ChronoCube </Typography>
- <Tab label="App" value="app"/>
- <Tab label="Profile" value="profile"/>
- <Tab label="Scoreboard" value="scoreboard"/>
- <Tab label="News" value="news"/>
- </TabsWrapper>
+ <AppBar position="sticky" className={classes.header}>
+ <Tabs onChange={handleChange}>
+ <Typography variant="h4" className={classes.logo}> ChronoCube </Typography>
+ { menuItems.map(menuItem => (
+ <Tab label={menuItem} value={menuItem}/>
+ ))}
+ </Tabs>
</AppBar>
);
};
-const TabsWrapper = styled(Tabs)`
- border-bottom: 1px solid black;
- & .MuiTab-wrapper {
- padding: 10px;
- }
- & .MuiTypography-root {
- font-weight: bold;
- padding: 10px;
- margin-right: 50px;
- margin-left: 30px;
- }
-`;
-
export default Header;
diff --git a/src/components/Scoreboard/Scoreboard.js b/src/components/Scoreboard/Scoreboard.js
index 1ebca90..1235f9a 100644
--- a/src/components/Scoreboard/Scoreboard.js
+++ b/src/components/Scoreboard/Scoreboard.js
@@ -1,5 +1,6 @@
-import React, {useEffect, useState} from 'react';
+import React, { useEffect, useState } from 'react';
+import { Container, Typography } from "@material-ui/core";
import { get } from "../../requests";
import Solution from "./Solution";
@@ -19,10 +20,11 @@ const Scoreboard = () => {
return (
- <div>
- { solutions.map(solution => <Solution solution={solution}/>) }
- </div>
+ <Container maxWidth="sm">
+ <Typography variant="h3" style={{textAlign: 'center'}}>Scoreboard</Typography>
+ {solutions.map(solution => (<Solution solution={solution}/>))}
+ </Container>
);
};
-export default Scoreboard; \ No newline at end of file
+export default Scoreboard;
diff --git a/src/components/Scoreboard/Solution.js b/src/components/Scoreboard/Solution.js
index 3f46eb5..6f87723 100644
--- a/src/components/Scoreboard/Solution.js
+++ b/src/components/Scoreboard/Solution.js
@@ -1,32 +1,72 @@
import React from 'react';
import {
- Card,
- CardContent,
Typography,
- Paper,
+ Card,
+ Container,
+ Box,
+ ExpansionPanelSummary,
+ ExpansionPanel,
+ ExpansionPanelDetails,
} from "@material-ui/core";
-import styled from "styled-components";
+import { makeStyles } from "@material-ui/core/styles";
+import TimerIcon from '@material-ui/icons/Timer';
+import ExpandMoreIcon from '@material-ui/icons/ExpandMore';
+
+
+const useStyles = makeStyles(theme => ({
+ item: {
+ backgroundColor: theme.palette.secondary.dark,
+ margin: theme.spacing(3),
+ width: theme.spacing(60),
+
+ '& .MuiBox-root': {
+ display: 'flex',
+ justifyContent: 'center',
+ alignItems: 'center',
+ },
+
+ '& .MuiTypography-h2': {
+ color: theme.palette.orange.main,
+ margin: theme.spacing(2),
+ },
+ },
+
+}));
const Solution = ({ solution }) => {
+ const classes = useStyles();
const author = solution.author? solution.author : 'anonymous';
return (
- <PaperWrapper elevation={2} style={{backgroundColor: "#ddbea3"}}>
- <Typography variant="h4" style={{fontWeight: "bold"}}>
- { solution.result }
- </Typography>
- <Typography>
- by {author}
- </Typography>
- </PaperWrapper>
+ <Card elevation={4} className={classes.item}>
+ <Container maxWidth="xs">
+ <Box>
+ <TimerIcon/>
+ <Typography variant="h2">
+ { solution.result }
+ </Typography>
+ </Box>
+ </Container>
+
+ <ExpansionPanel>
+ <ExpansionPanelSummary expandIcon={<ExpandMoreIcon style={{color: 'white'}}/>}>
+ <Typography variant="h6">
+ By {author}
+ </Typography>
+ </ExpansionPanelSummary>
+ <ExpansionPanelDetails>
+ <Typography>
+ Lorem ipsum dolor sit amet, consectetur adipiscing elit.
+ Suspendisse malesuada lacus ex, sit amet blandit leo lobortis eget.
+ Lorem ipsum dolor sit amet, consectetur adipiscing elit.
+ Suspendisse malesuada lacus ex, sit amet blandit leo lobortis eget.
+ </Typography>
+ </ExpansionPanelDetails>
+ </ExpansionPanel>
+ </Card>
)
};
-const PaperWrapper = styled(Card)`
- padding: 10px;
- margin: 25px;
-`;
-
-export default Solution; \ No newline at end of file
+export default Solution;
diff --git a/src/components/Timer/Timer.js b/src/components/Timer/Timer.js
index 62924f0..f840429 100644
--- a/src/components/Timer/Timer.js
+++ b/src/components/Timer/Timer.js
@@ -1,18 +1,18 @@
import React, { useState, useEffect } from 'react';
-import styled from 'styled-components';
import { post } from '../../requests';
+import { Typography } from '@material-ui/core';
+
const Timer = () => {
const SPACE = 32;
const maxCountdown = 15000;
- const [time, setTime] = useState("00:15:00");
+ const [time, setTime] = useState('00:15:00');
const [isRunning, setIsRunning] = useState(false);
const [timer, setTimer] = useState(0);
const [isCountdown, setIsCountdown] = useState(false);
let startingTime;
-
const handleKeyPress = event => {
if (event.keyCode === SPACE && !isRunning ) {
if (!isCountdown) {
@@ -51,33 +51,24 @@ const Timer = () => {
};
useEffect(() => {
- window.addEventListener("keyup", handleKeyUp);
- window.addEventListener("keypress", handleKeyPress);
+ window.addEventListener('keyup', handleKeyUp);
+ window.addEventListener('keypress', handleKeyPress);
return () => {
- window.removeEventListener("keyup", handleKeyUp);
- window.removeEventListener("keypress", handleKeyPress);
-
+ window.removeEventListener('keyup', handleKeyUp);
+ window.removeEventListener('keypress', handleKeyPress);
};
});
return (
- <Root>
- <span>{time}</ span>
- </Root>
+ <Typography variant="h2"> {time} </Typography>
);
};
-const Root = styled.div`
- background-color: skyblue;
- padding: 8px;
- display: inline-block;
- font-size: 32px;
- color: pink;
-`;
+
const convertTimeToString = timeDiff => {
- let resultTime = "";
+ let resultTime = '';
const minute = Math.floor(timeDiff / 60000);
if (minute < 10) resultTime += '0';
@@ -96,3 +87,4 @@ const convertTimeToString = timeDiff => {
};
export default Timer;
+
diff --git a/src/index.js b/src/index.js
index 725d270..e88b342 100644
--- a/src/index.js
+++ b/src/index.js
@@ -3,22 +3,30 @@ import ReactDOM from 'react-dom';
import {
Typography,
- Paper,
- Container,
+ Box,
} from "@material-ui/core";
+import CssBaseline from '@material-ui/core/CssBaseline';
+import { ThemeProvider, makeStyles } from '@material-ui/core/styles';
-import styled from 'styled-components';
-import CssBaseline from '@material-ui/core/CssBaseline'
-
+import theme from "./theme";
import Header from './components/Header/Header';
import Timer from './components/Timer/Timer';
import Scoreboard from "./components/Scoreboard/Scoreboard";
+const useStyles = makeStyles(theme => ({
+ root: {
+ padding: theme.spacing(2),
+ },
+}));
+
+
const App = () => {
const [page, setPage] = useState('app');
+ const classes = useStyles();
+
const getPageComponent = page => {
switch (page) {
case 'app':
@@ -36,22 +44,14 @@ const App = () => {
};
return (
- <Root>
+ <ThemeProvider theme={theme}>
<CssBaseline/>
- <Header setPage={setPage} />
- <Container maxWidth="xl">
- <Paper elevation={4} style={{backgroundColor: "bisque"}}>
- <Typography variant="h4"> This is the {page} page! </Typography>
- { getPageComponent(page) }
- </Paper>
- </Container>
- </Root>
-);
+ <Header setPage={setPage}/>
+ <Box className={classes.root}>
+ { getPageComponent(page) }
+ </Box>
+ </ThemeProvider>
+ );
};
-const Root = styled.div`
- background: cornsilk;
- padding-bottom: 25px;
-`;
-
ReactDOM.render(<App />, document.getElementById('root'));
diff --git a/src/theme.js b/src/theme.js
new file mode 100644
index 0000000..350fc49
--- /dev/null
+++ b/src/theme.js
@@ -0,0 +1,40 @@
+import { createMuiTheme } from '@material-ui/core/styles'
+import createPalette from "@material-ui/core/styles/createPalette";
+
+const colorScheme = {
+ dark: '#232020',
+ grey: '#3a3535',
+ white: '#f4f4f4',
+ orange: '#ff7315',
+};
+
+const palette = createPalette({
+ primary: {
+ main: colorScheme.dark,
+ },
+ secondary: {
+ main: colorScheme.grey,
+ },
+ white: {
+ main: colorScheme.white,
+ },
+ orange: {
+ main: colorScheme.orange,
+ },
+});
+
+palette.background = {
+ default: palette.secondary.main,
+ paper: palette.secondary.dark,
+};
+
+palette.text = {
+ primary: palette.white.main,
+ secondary: palette.orange.main,
+};
+
+const theme = createMuiTheme({
+ palette
+});
+
+export default theme;