Skip to content

Commit 0c91212

Browse files
limatgansoliviertassinari
authored andcommitted
[docs] Migrated Customization/Components to ts
1 parent 30670fd commit 0c91212

File tree

3 files changed

+125
-0
lines changed

3 files changed

+125
-0
lines changed
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
import React from 'react';
2+
import clsx from 'clsx';
3+
import { makeStyles } from '@material-ui/core/styles';
4+
import Button from '@material-ui/core/Button';
5+
import FormControlLabel from '@material-ui/core/FormControlLabel';
6+
import Switch from '@material-ui/core/Switch';
7+
8+
const useStyles = makeStyles({
9+
button: {
10+
background: 'linear-gradient(45deg, #FE6B8B 30%, #FF8E53 90%)',
11+
borderRadius: 3,
12+
border: 0,
13+
color: 'white',
14+
height: 48,
15+
padding: '0 30px',
16+
boxShadow: '0 3px 5px 2px rgba(255, 105, 135, .3)',
17+
},
18+
buttonBlue: {
19+
background: 'linear-gradient(45deg, #2196F3 30%, #21CBF3 90%)',
20+
boxShadow: '0 3px 5px 2px rgba(33, 203, 243, .3)',
21+
},
22+
});
23+
24+
export default function DynamicClassName() {
25+
const classes = useStyles();
26+
const [color, setColor] = React.useState('default');
27+
28+
const handleChange = (event: React.ChangeEvent<HTMLInputElement>) => {
29+
setColor(event.target.checked ? 'blue' : 'default');
30+
};
31+
32+
return (
33+
<React.Fragment>
34+
<FormControlLabel
35+
control={
36+
<Switch
37+
checked={color === 'blue'}
38+
onChange={handleChange}
39+
color="primary"
40+
value="dynamic-class-name"
41+
/>
42+
}
43+
label="Blue"
44+
/>
45+
<Button
46+
className={clsx(classes.button, {
47+
[classes.buttonBlue]: color === 'blue',
48+
})}
49+
>
50+
{'Class name branch'}
51+
</Button>
52+
</React.Fragment>
53+
);
54+
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
import React from 'react';
2+
import Button from '@material-ui/core/Button';
3+
import { createMuiTheme, ThemeProvider } from '@material-ui/core/styles';
4+
import FormControlLabel from '@material-ui/core/FormControlLabel';
5+
import { blue } from '@material-ui/core/colors';
6+
import Switch from '@material-ui/core/Switch';
7+
8+
const defaultTheme = createMuiTheme();
9+
10+
export default function DynamicThemeNesting() {
11+
const [color, setColor] = React.useState('default');
12+
13+
const handleChange = (event: React.ChangeEvent<HTMLInputElement>) => {
14+
setColor(event.target.checked ? 'blue' : 'default');
15+
};
16+
17+
return (
18+
<React.Fragment>
19+
<FormControlLabel
20+
control={
21+
<Switch
22+
checked={color === 'blue'}
23+
onChange={handleChange}
24+
color="primary"
25+
value="dynamic-class-name"
26+
/>
27+
}
28+
label="Blue"
29+
/>
30+
<ThemeProvider
31+
theme={
32+
color === 'blue'
33+
? {
34+
...defaultTheme,
35+
palette: {
36+
...defaultTheme.palette,
37+
secondary: {
38+
main: blue[500],
39+
contrastText: '#fff',
40+
},
41+
},
42+
}
43+
: defaultTheme
44+
}
45+
>
46+
<Button variant="contained" color="secondary">
47+
{'Theme nesting'}
48+
</Button>
49+
</ThemeProvider>
50+
</React.Fragment>
51+
);
52+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import React from 'react';
2+
import Button from '@material-ui/core/Button';
3+
4+
// We can use inline-style
5+
const style = {
6+
background: 'linear-gradient(45deg, #FE6B8B 30%, #FF8E53 90%)',
7+
borderRadius: 3,
8+
border: 0,
9+
color: 'white',
10+
height: 48,
11+
padding: '0 30px',
12+
boxShadow: '0 3px 5px 2px rgba(255, 105, 135, .3)',
13+
};
14+
15+
function InlineStyle() {
16+
return <Button style={style}>inline-style</Button>;
17+
}
18+
19+
export default InlineStyle;

0 commit comments

Comments
 (0)