Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[docs] Add TS demo for DynamicCSSVariables #17983

Merged
merged 1 commit into from
Oct 22, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 16 additions & 19 deletions docs/src/pages/customization/components/DynamicCSSVariables.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,43 +16,40 @@ const useStyles = makeStyles({
},
});

const blue = {
'--background-start': '#2196F3',
'--background-end': '#21CBF3',
'--box-shadow': 'rgba(33, 203, 243, .3)',
};

const defaultColor = {
'--background-start': '#FE6B8B',
'--background-end': '#FF8E53',
'--box-shadow': 'rgba(255, 105, 135, .3)',
};

export default function DynamicCSSVariables() {
const classes = useStyles();
const [color, setColor] = React.useState('default');
const [color, setColor] = React.useState(defaultColor);

const handleChange = event => {
setColor(event.target.checked ? 'blue' : 'default');
setColor(event.target.checked ? blue : defaultColor);
};

return (
<React.Fragment>
<FormControlLabel
control={
<Switch
checked={color === 'blue'}
checked={color === blue}
onChange={handleChange}
color="primary"
value="dynamic-class-name"
/>
}
label="Blue"
/>
<Button
className={classes.button}
style={
color === 'blue'
? {
'--background-start': '#2196F3',
'--background-end': '#21CBF3',
'--box-shadow': 'rgba(33, 203, 243, .3)',
}
: {
'--background-start': '#FE6B8B',
'--background-end': '#FF8E53',
'--box-shadow': 'rgba(255, 105, 135, .3)',
}
}
>
<Button className={classes.button} style={color}>
{'CSS variables'}
</Button>
</React.Fragment>
Expand Down
57 changes: 57 additions & 0 deletions docs/src/pages/customization/components/DynamicCSSVariables.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import React from 'react';
import { makeStyles } from '@material-ui/core/styles';
import Button from '@material-ui/core/Button';
import FormControlLabel from '@material-ui/core/FormControlLabel';
import Switch from '@material-ui/core/Switch';

const useStyles = makeStyles({
button: {
background: 'linear-gradient(45deg, var(--background-start) 30%, var(--background-end) 90%)',
borderRadius: 3,
border: 0,
color: 'white',
height: 48,
padding: '0 30px',
boxShadow: '0 3px 5px 2px var(--box-shadow)',
},
});

const blue = {
'--background-start': '#2196F3',
'--background-end': '#21CBF3',
'--box-shadow': 'rgba(33, 203, 243, .3)',
} as React.CSSProperties;

const defaultColor = {
'--background-start': '#FE6B8B',
'--background-end': '#FF8E53',
'--box-shadow': 'rgba(255, 105, 135, .3)',
} as React.CSSProperties;

export default function DynamicCSSVariables() {
const classes = useStyles();
const [color, setColor] = React.useState(defaultColor);

const handleChange = (event: React.ChangeEvent<HTMLInputElement>) => {
setColor(event.target.checked ? blue : defaultColor);
};

return (
<React.Fragment>
<FormControlLabel
control={
<Switch
checked={color === blue}
onChange={handleChange}
color="primary"
value="dynamic-class-name"
/>
}
label="Blue"
/>
<Button className={classes.button} style={color}>
{'CSS variables'}
</Button>
</React.Fragment>
);
}