Skip to content

Commit 4aea24a

Browse files
lksilvaeps1lon
authored andcommitted
[docs] Add Media Query TS demo (#17766)
1 parent 21f6033 commit 4aea24a

File tree

2 files changed

+37
-13
lines changed

2 files changed

+37
-13
lines changed
Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
import React from 'react';
2-
import PropTypes from 'prop-types';
3-
import { withStyles } from '@material-ui/core/styles';
2+
import { makeStyles } from '@material-ui/core/styles';
43
import Typography from '@material-ui/core/Typography';
54
import { green } from '@material-ui/core/colors';
65

7-
const styles = theme => ({
6+
const useStyles = makeStyles(theme => ({
87
root: {
98
padding: theme.spacing(1),
109
[theme.breakpoints.down('sm')]: {
@@ -17,11 +16,10 @@ const styles = theme => ({
1716
backgroundColor: green[500],
1817
},
1918
},
20-
});
21-
22-
function MediaQuery(props) {
23-
const { classes } = props;
19+
}));
2420

21+
export default function MediaQuery() {
22+
const classes = useStyles();
2523
return (
2624
<div className={classes.root}>
2725
<Typography variant="subtitle1">{'down(sm): red'}</Typography>
@@ -30,9 +28,3 @@ function MediaQuery(props) {
3028
</div>
3129
);
3230
}
33-
34-
MediaQuery.propTypes = {
35-
classes: PropTypes.object.isRequired,
36-
};
37-
38-
export default withStyles(styles)(MediaQuery);
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import React from 'react';
2+
import { Theme, makeStyles, createStyles } from '@material-ui/core/styles';
3+
import Typography from '@material-ui/core/Typography';
4+
import { green } from '@material-ui/core/colors';
5+
6+
const useStyles = makeStyles((theme: Theme) =>
7+
createStyles({
8+
root: {
9+
padding: theme.spacing(1),
10+
[theme.breakpoints.down('sm')]: {
11+
backgroundColor: theme.palette.secondary.main,
12+
},
13+
[theme.breakpoints.up('md')]: {
14+
backgroundColor: theme.palette.primary.main,
15+
},
16+
[theme.breakpoints.up('lg')]: {
17+
backgroundColor: green[500],
18+
},
19+
},
20+
}),
21+
);
22+
23+
export default function MediaQuery() {
24+
const classes = useStyles();
25+
return (
26+
<div className={classes.root}>
27+
<Typography variant="subtitle1">{'down(sm): red'}</Typography>
28+
<Typography variant="subtitle1">{'up(md): blue'}</Typography>
29+
<Typography variant="subtitle1">{'up(lg): green'}</Typography>
30+
</div>
31+
);
32+
}

0 commit comments

Comments
 (0)