Material UI is a Material Design library made for React.
It’s a set of React components that have Material Design styles.
In this article, we’ll look at how to add buttons Material Design.
We can add more complex buttons with the ButtonBase
component.
For instance, we can write:
import React from "react";
import { makeStyles } from "@material-ui/core/styles";
import ButtonBase from "@material-ui/core/ButtonBase";
import Typography from "@material-ui/core/Typography";
const useStyles = makeStyles(theme => ({
root: {
"& > *": {
margin: theme.spacing(1)
}
},
image: {
position: "relative",
height: 200,
[theme.breakpoints.down("xs")]: {
width: "100% !important",
height: 100
},
"&:hover, &$focusVisible": {
zIndex: 1,
"& $imageBackdrop": {
opacity: 0.15
},
"& $imageMarked": {
opacity: 0
},
"& $imageTitle": {
border: "4px solid currentColor"
}
}
},
focusVisible: {},
imageButton: {
position: "absolute",
left: 0,
right: 0,
top: 0,
bottom: 0,
display: "flex",
alignItems: "center",
justifyContent: "center",
color: theme.palette.common.white
},
imageSrc: {
position: "absolute",
left: 0,
right: 0,
top: 0,
bottom: 0,
backgroundSize: "cover",
backgroundPosition: "center 40%"
},
imageBackdrop: {
position: "absolute",
left: 0,
right: 0,
top: 0,
bottom: 0,
backgroundColor: theme.palette.common.black,
opacity: 0.4,
transition: theme.transitions.create("opacity")
},
imageTitle: {
position: "relative",
padding: `${theme.spacing(2)}px ${theme.spacing(4)}px ${theme.spacing(1) +
6}px`
},
imageMarked: {
height: 3,
width: 18,
backgroundColor: theme.palette.common.white,
position: "absolute",
bottom: -2,
left: "calc(50% - 9px)",
transition: theme.transitions.create("opacity")
}
}));
export default function App() {
const classes = useStyles();
return (
<div className={classes.root}>
<ButtonBase
focusRipple
className={classes.image}
focusVisibleClassName={classes.focusVisible}
style={{
width: "200px"
}}
>
<span
className={classes.imageSrc}
style={{
backgroundImage: `url(http://placekitten.com/200/200)`
}}
/>
<span className={classes.imageBackdrop} />
<span className={classes.imageButton}>
<Typography
component="span"
variant="subtitle"
color="inherit"
className={classes.imageTitle}
>
{"Cat"}
<span className={classes.imageMarked} />
</Typography>
</span>
</ButtonBase>
</div>
);
}
#javascript #technology #web-development #software-development #programming