11import React from 'react'
22import PropTypes from 'prop-types'
33import classNames from 'classnames'
4- import styled from 'styled-components'
5- import { darken } from 'polished'
4+ import styled , { css } from 'styled-components'
65import handleRef from './internal/handleRef'
7- import defaultTheme from './style/defaultTheme'
6+ import * as defaultTheme from './style/defaultTheme'
7+ import { th , mixin } from './utils'
88
9- const ButtonComponent = ( { className, size, ...props } ) => (
9+ const variants = [
10+ 'primary' ,
11+ 'secondary' ,
12+ 'success' ,
13+ 'danger' ,
14+ 'warning' ,
15+ 'info' ,
16+ 'light' ,
17+ 'dark' ,
18+ ]
19+
20+ const ButtonComponent = ( { className, size, theme, variant, ...props } ) => (
1021 < button
1122 { ...props }
1223 className = { classNames (
1324 'sui-button' ,
1425 {
1526 [ `sui-button-${ size } ` ] : size ,
27+ [ `sui-button-${ variant } ` ] : variant ,
1628 } ,
1729 className ,
1830 ) }
@@ -21,50 +33,50 @@ const ButtonComponent = ({ className, size, ...props }) => (
2133
2234const Button = styled ( handleRef ( ButtonComponent ) ) `
2335 display: inline-block;
24- padding: ${ props => props . theme . textControlPadding . sm } ;
25- z-index: ${ props => props . theme . zIndexes . control } ;
26- border-radius: ${ props => props . theme . borderRadius . md } ;
27- font-size: 1rem;
28- line-height: 1.5;
29- background-color: ${ props => props . theme . colors . primary } ;
30- color: ${ props => props . theme . colors . white } ;
31- border: 0;
36+ padding: ${ th ( 'btnPaddingY' ) } ${ th ( 'btnPaddingX' ) } ;
37+ z-index: ${ th ( 'zIndexControl' ) } ;
38+ border-radius: ${ th ( 'borderRadius' ) } ;
39+ font-size: ${ th ( 'fontSizeBase' ) } ;
40+ line-height: ${ th ( 'lineHeightBase' ) } ;
41+ color: ${ th ( 'white' ) } ;
42+ border-width: ${ th ( 'btnBorderWidth' ) } ;
3243 cursor: pointer;
33- transition: background-color 300ms;
34-
35- &:focus {
36- ${ props => props . theme . mixins . controlFocus } ;
37- }
44+ transition: ${ th ( 'transitionBase' ) } ;
3845
39- &:not(:disabled):hover,
40- &:not(:disabled):active {
41- background-color: ${ props => darken ( 0.05 , props . theme . colors . primary ) } ;
46+ &.sui-button-sm {
47+ padding: ${ th ( 'btnPaddingYSm' ) } ${ th ( 'btnPaddingXSm' ) } ;
48+ font-size: ${ th ( 'fontSizeSm' ) } ;
49+ border-radius: ${ th ( 'borderRadiusSm' ) } ;
4250 }
4351
4452 &.sui-button-lg {
45- padding: ${ props => props . theme . textControlPadding . lg } ;
46- font-size: ${ props => props . theme . controlFontSize . lg } ;
47- border-radius: ${ props => props . theme . borderRadius . lg } ;
48- }
49-
50- &.sui-button-sm {
51- padding: ${ props => props . theme . textControlPadding . sm } ;
52- font-size: ${ props => props . theme . controlFontSize . sm } ;
53- border-radius: ${ props => props . theme . borderRadius . sm } ;
53+ padding: ${ th ( 'btnPaddingYLg' ) } ${ th ( 'btnPaddingXLg' ) } ;
54+ font-size: ${ th ( 'fontSizeLg' ) } ;
55+ border-radius: ${ th ( 'borderRadiusLg' ) } ;
5456 }
5557
5658 &:disabled {
57- opacity: 0.8 ;
59+ opacity: ${ th ( 'btnDisabledOpacity' ) } ;
5860 }
61+
62+ ${ variants . map (
63+ variant => css `
64+ & .sui-button- ${ variant } {
65+ ${ mixin ( 'btnVariant' , variant ) } ;
66+ }
67+ ` ,
68+ ) } ;
5969`
6070
6171Button . propTypes = {
62- size : PropTypes . oneOf ( [ 'sm' , 'lg' ] ) ,
6372 disabled : PropTypes . bool ,
73+ size : PropTypes . oneOf ( [ 'sm' , 'lg' ] ) ,
74+ variant : PropTypes . oneOf ( variants ) ,
6475 theme : PropTypes . object ,
6576}
6677
6778Button . defaultProps = {
79+ variant : 'primary' ,
6880 theme : defaultTheme ,
6981}
7082
0 commit comments