11import React from "react" ;
22import propTypes from "prop-types" ;
33
4- import styled from "styled-components" ;
4+ import styled , { css } from "styled-components" ;
55import {
66 createBorderStyles ,
7+ createWellBorderStyles ,
78 createBoxStyles ,
9+ createFlatBoxStyles ,
810 createDisabledTextStyles
911} from "../common" ;
1012import { blockSizes , fontSizes , padding } from "../common/system" ;
1113
12- const StyledButton = styled . button `
13- ${ createBoxStyles ( ) } ;
14+ const commonButtonStyles = css `
1415 position: relative;
1516 display: inline-flex;
1617 align-items: center;
1718 justify-content: center;
18- ${ props =>
19- props . flat
20- ? null
21- : props . active
22- ? createBorderStyles ( true )
23- : createBorderStyles ( false ) }
24- height: ${ props => blockSizes [ props . size ] } ;
25- width: ${ props =>
26- props . fullWidth ? "100%" : props . square ? blockSizes [ props . size ] : "auto" } ;
27- padding: ${ props => ( props . square ? 0 : "0 " + padding . sm ) } ;
19+ height: ${ ( { size } ) => blockSizes [ size ] } ;
20+ width: ${ ( { fullWidth, square, size } ) =>
21+ fullWidth ? "100%" : square ? blockSizes [ size ] : "auto" } ;
22+ padding: ${ ( { square } ) => ( square ? 0 : "0 " + padding . sm ) } ;
2823 font-size: ${ fontSizes . md } ;
29-
30- ${ props => props . isDisabled && createDisabledTextStyles ( ) }
3124 &:active {
32- ${ props => ! props . isDisabled && ! props . flat && createBorderStyles ( true ) }
33-
34- padding-top: ${ props => ! props . isDisabled && "2px" } ;
35-
25+ padding-top: ${ ( { isDisabled } ) => ! isDisabled && "2px" } ;
3626 }
37- padding-top: ${ props => props . active && ! props . isDisabled && "2px" } ;
38- ${ props => props . flat && "border: none;" }
27+ padding-top: ${ ( { active, isDisabled } ) => active && ! isDisabled && "2px" } ;
28+ ` ;
29+
30+ const StyledButton = styled . button `
31+ ${ ( { variant } ) =>
32+ variant === "flat"
33+ ? css `
34+ ${ createFlatBoxStyles ( ) } /* background: none; */
35+ `
36+ : variant === "menu"
37+ ? css `
38+ ${ createBoxStyles ( ) } ;
39+ border: 2px solid transparent;
40+ &:hover {
41+ ${ ( { isDisabled } ) => ! isDisabled && createWellBorderStyles ( false ) }
42+ }
43+ &:active {
44+ ${ ( { isDisabled } ) => ! isDisabled && createWellBorderStyles ( true ) }
45+ }
46+ ${ ( { active } ) => active && createBorderStyles ( true ) }
47+ ${ ( { isDisabled } ) => isDisabled && createDisabledTextStyles ( ) }
48+ `
49+ : css `
50+ ${ createBoxStyles ( ) } ;
51+ ${ ( { active } ) =>
52+ active ? createBorderStyles ( true ) : createBorderStyles ( false ) }
53+ &:active {
54+ ${ ( { isDisabled } ) => ! isDisabled && createBorderStyles ( true ) }
55+ }
56+ ${ ( { isDisabled } ) => isDisabled && createDisabledTextStyles ( ) }
57+ ` }
58+ ${ commonButtonStyles }
3959` ;
4060
4161const Button = ( {
@@ -47,22 +67,22 @@ const Button = ({
4767 size,
4868 square,
4969 active,
50- flat ,
70+ variant ,
5171 className,
5272 children,
5373 ...otherProps
5474} ) => {
5575 return (
5676 < StyledButton
5777 type = { type }
78+ variant = { variant }
5879 onClick = { disabled ? undefined : onClick }
5980 style = { style }
6081 isDisabled = { disabled }
6182 fullWidth = { fullWidth }
6283 size = { size }
6384 square = { square }
6485 active = { active }
65- flat = { flat }
6686 className = { className }
6787 style = { style }
6888 // onTouchStart below to enable button :active style on iOS
@@ -83,7 +103,7 @@ Button.defaultProps = {
83103 size : "md" ,
84104 square : false ,
85105 active : false ,
86- flat : false
106+ variant : "default"
87107} ;
88108
89109Button . propTypes = {
@@ -95,7 +115,7 @@ Button.propTypes = {
95115 size : propTypes . oneOf ( [ "sm" , "md" , "lg" ] ) ,
96116 square : propTypes . bool ,
97117 active : propTypes . bool ,
98- flat : propTypes . bool ,
118+ variant : propTypes . oneOf ( [ "default" , "menu" , "flat" ] ) ,
99119 className : propTypes . string ,
100120 children : propTypes . node . isRequired
101121} ;
0 commit comments