Add SquareButton component
This commit is contained in:
parent
6fcc0eaf79
commit
989f66f7de
4 changed files with 55 additions and 19 deletions
|
@ -1,26 +1,16 @@
|
|||
import { ButtonProps } from "@material-ui/core/Button";
|
||||
import ButtonBase from "@material-ui/core/ButtonBase";
|
||||
import makeStyles from "@material-ui/core/styles/makeStyles";
|
||||
import ArrowIcon from "@material-ui/icons/ArrowBack";
|
||||
import classNames from "classnames";
|
||||
import React from "react";
|
||||
|
||||
import SquareButton from "../SquareButton";
|
||||
|
||||
const useStyles = makeStyles(
|
||||
theme => ({
|
||||
arrow: {
|
||||
transition: theme.transitions.duration.shortest + "ms"
|
||||
},
|
||||
root: {
|
||||
"&:hover, &:focus": {
|
||||
background: "#daedeb"
|
||||
},
|
||||
background: theme.palette.background.paper,
|
||||
borderRadius: 16,
|
||||
color: theme.palette.primary.main,
|
||||
height: 48,
|
||||
transition: theme.transitions.duration.shortest + "ms",
|
||||
width: 48
|
||||
},
|
||||
shrunk: {
|
||||
transform: "scaleX(-1)"
|
||||
}
|
||||
|
@ -34,21 +24,17 @@ export interface ExpandButtonProps extends ButtonProps {
|
|||
isShrunk: boolean;
|
||||
}
|
||||
|
||||
const ExpandButton: React.FC<ExpandButtonProps> = ({
|
||||
className,
|
||||
isShrunk,
|
||||
...rest
|
||||
}) => {
|
||||
const ExpandButton: React.FC<ExpandButtonProps> = ({ isShrunk, ...rest }) => {
|
||||
const classes = useStyles({});
|
||||
|
||||
return (
|
||||
<ButtonBase className={classNames(classes.root, className)} {...rest}>
|
||||
<SquareButton {...rest}>
|
||||
<ArrowIcon
|
||||
className={classNames(classes.arrow, {
|
||||
[classes.shrunk]: isShrunk
|
||||
})}
|
||||
/>
|
||||
</ButtonBase>
|
||||
</SquareButton>
|
||||
);
|
||||
};
|
||||
|
||||
|
|
14
src/components/SquareButton/SquareButton.stories.tsx
Normal file
14
src/components/SquareButton/SquareButton.stories.tsx
Normal file
|
@ -0,0 +1,14 @@
|
|||
import CloseIcon from "@material-ui/icons/Close";
|
||||
import Decorator from "@saleor/storybook/Decorator";
|
||||
import { storiesOf } from "@storybook/react";
|
||||
import React from "react";
|
||||
|
||||
import SquareButton from "./SquareButton";
|
||||
|
||||
storiesOf("Generics / Square Button", module)
|
||||
.addDecorator(Decorator)
|
||||
.add("default", () => (
|
||||
<SquareButton>
|
||||
<CloseIcon />
|
||||
</SquareButton>
|
||||
));
|
34
src/components/SquareButton/SquareButton.tsx
Normal file
34
src/components/SquareButton/SquareButton.tsx
Normal file
|
@ -0,0 +1,34 @@
|
|||
import ButtonBase, { ButtonBaseProps } from "@material-ui/core/ButtonBase";
|
||||
import makeStyles from "@material-ui/core/styles/makeStyles";
|
||||
import classNames from "classnames";
|
||||
import React from "react";
|
||||
|
||||
const useStyles = makeStyles(
|
||||
theme => ({
|
||||
root: {
|
||||
"&:hover, &:focus": {
|
||||
background: "#daedeb"
|
||||
},
|
||||
background: theme.palette.background.paper,
|
||||
borderRadius: 16,
|
||||
color: theme.palette.primary.main,
|
||||
height: 48,
|
||||
transition: theme.transitions.duration.shortest + "ms",
|
||||
width: 48
|
||||
}
|
||||
}),
|
||||
{
|
||||
name: "ExpandButton"
|
||||
}
|
||||
);
|
||||
|
||||
const SquareButton: React.FC<ButtonBaseProps> = ({ className, ...rest }) => {
|
||||
const classes = useStyles({});
|
||||
|
||||
return (
|
||||
<ButtonBase className={classNames(classes.root, className)} {...rest} />
|
||||
);
|
||||
};
|
||||
|
||||
SquareButton.displayName = "SquareButton";
|
||||
export default SquareButton;
|
2
src/components/SquareButton/index.ts
Normal file
2
src/components/SquareButton/index.ts
Normal file
|
@ -0,0 +1,2 @@
|
|||
export * from "./SquareButton";
|
||||
export { default } from "./SquareButton";
|
Loading…
Reference in a new issue