diff --git a/packages/react/src/components/buttons/abstract-button.tsx b/packages/react/src/components/buttons/abstract-button.tsx index 9b32da86b3..75a7d31230 100755 --- a/packages/react/src/components/buttons/abstract-button.tsx +++ b/packages/react/src/components/buttons/abstract-button.tsx @@ -1,4 +1,4 @@ -import styled, { css, FlattenInterpolation, ThemeProps, DefaultTheme } from 'styled-components'; +import styled, { css, FlattenInterpolation, ThemeProps } from 'styled-components'; import { Theme } from '../../themes/theme'; import { focus } from '../../utils/css-state'; @@ -39,85 +39,94 @@ type ButtonType = 'primary' | 'secondary' | 'tertiary' | 'destructive'; interface ButtonTypeStyles { buttonType: ButtonType; - inversed?: boolean; + inverted?: boolean; theme: Theme; } -export const getButtonTypeStyles: (props: ButtonTypeStyles) => FlattenInterpolation> = (props: ButtonTypeStyles) => css` +const getPrimaryButtonStyles: (props: ButtonTypeStyles) => FlattenInterpolation> = ({ theme }) => css` + background-color: ${theme.main['primary-1.1']}; + border-color: ${theme.main['primary-1.1']}; + color: ${theme.greys.white}; + + &:hover { + background-color: ${theme.main['primary-1.3']}; + border-color: ${theme.main['primary-1.3']}; + } + + &:disabled { + background-color: ${theme.main['primary-1.2']}; + border-color: ${theme.main['primary-1.2']}; + } +`; + +const getSecondaryButtonStyles: (props: ButtonTypeStyles) => FlattenInterpolation> = ({ theme }) => css` + background-color: transparent; + border-color: ${theme.main['primary-1.1']}; + color: ${theme.main['primary-1.1']}; + + &:hover { + border-color: ${theme.main['primary-1.3']}; + color: ${theme.main['primary-1.3']}; + } + + &:disabled { + border-color: ${theme.main['primary-1.2']}; + color: ${theme.main['primary-1.2']}; + } +`; + +const getTertiaryButtonStyles: (props: ButtonTypeStyles) => FlattenInterpolation> = ({ theme }) => css` + background-color: transparent; + border-color: transparent; + color: ${theme.greys['dark-grey']}; + + &:hover { + background-color: ${theme.greys.grey}; + color: ${theme.greys.black}; + } + + &:disabled { + background-color: transparent; + color: ${theme.greys['mid-grey']}; + } +`; + +const getDestructiveButtonStyles: (props: ButtonTypeStyles) => FlattenInterpolation> = ({ inverted, theme }) => css` + background-color: ${inverted ? theme.greys.white : theme.notifications['error-2.1']}; + border-color: ${inverted ? theme.greys.white : theme.notifications['error-2.1']}; + color: ${inverted ? theme.notifications['error-2.1'] : theme.greys.white}; + + &:hover { + /* TODO change colors when updating thematization */ + background-color: ${inverted ? theme.greys.white : '#62071b'}; + border-color: ${inverted ? theme.greys.white : '#62071b'}; + color: ${inverted ? '#62071b' : theme.greys.white}; + } + + &:disabled { + &, + &:focus, + &:hover { + /* TODO change colors when updating thematization */ + background-color: ${inverted ? theme.greys.white : '#ea8da3'}; + border-color: ${inverted ? theme.greys.white : '#ea8da3'}; + color: ${inverted ? '#ea8da3' : theme.greys.white}; + } + } +`; + +export const getButtonTypeStyles: (props: ButtonTypeStyles) => FlattenInterpolation> = (props) => css` ${focus(props, true)}; ${() => { - const { buttonType, theme, inversed } = props; - switch (buttonType) { + switch (props.buttonType) { case 'primary': - return ` - background-color: ${theme.main['primary-1.1']}; - border-color: ${theme.main['primary-1.1']}; - color: ${theme.greys.white}; - - &:hover { - background-color: ${theme.main['primary-1.3']}; - border-color: ${theme.main['primary-1.3']}; - } - - &:disabled { - background-color: ${theme.main['primary-1.2']}; - border-color: ${theme.main['primary-1.2']}; - } - `; + return getPrimaryButtonStyles(props); case 'secondary': - return ` - background-color: transparent; - border-color: ${theme.main['primary-1.1']}; - color: ${theme.main['primary-1.1']}; - - &:hover { - border-color: ${theme.main['primary-1.3']}; - color: ${theme.main['primary-1.3']}; - } - - &:disabled { - border-color: ${theme.main['primary-1.2']}; - color: ${theme.main['primary-1.2']}; - } - `; + return getSecondaryButtonStyles(props); case 'tertiary': - return ` - background-color: transparent; - border-color: transparent; - color: ${theme.greys['dark-grey']}; - - &:hover { - background-color: ${theme.greys.grey}; - color: ${theme.greys.black}; - } - - &:disabled { - background-color: transparent; - color: ${theme.greys['mid-grey']}; - } - `; + return getTertiaryButtonStyles(props); case 'destructive': - // TODO change colors when updating thematization - return ` - background-color: ${inversed ? theme.greys.white : theme.notifications['error-2.1']}; - border-color: ${inversed ? theme.greys.white : theme.notifications['error-2.1']}; - color: ${inversed ? theme.notifications['error-2.1'] : theme.greys.white}; - - &:hover { - background-color: ${inversed ? theme.greys.white : '#62071b'}; - color: ${inversed ? '#62071b' : theme.greys.white}; - } - - &:disabled { - &, - &:focus, - &:hover { - background-color: ${inversed ? theme.greys.white : '#ea8da3'}; - border-color: ${inversed ? theme.greys.white : '#ea8da3'}; - color: ${inversed ? '#ea8da3' : theme.greys.white}; - } - } - `; + return getDestructiveButtonStyles(props); } }} `; diff --git a/packages/react/src/components/buttons/add-button.tsx b/packages/react/src/components/buttons/add-button.tsx index 1a641a0ba3..589529b3a3 100644 --- a/packages/react/src/components/buttons/add-button.tsx +++ b/packages/react/src/components/buttons/add-button.tsx @@ -20,7 +20,7 @@ interface ButtonProps { buttonType: ButtonType; className?: string; disabled?: boolean; - inversed?: boolean; + inverted?: boolean; label?: string; type?: Type; @@ -32,7 +32,7 @@ export function AddButton({ type = 'submit', buttonType, disabled, - inversed, + inverted, label, onClick, }: ButtonProps): ReactElement { @@ -45,7 +45,7 @@ export function AddButton({ buttonType={buttonType} onClick={onClick} disabled={disabled} - inversed={inversed} + inverted={inverted} label={label} > diff --git a/packages/react/src/components/buttons/button.test.tsx b/packages/react/src/components/buttons/button.test.tsx index 5fcfb656a1..3296a7b656 100644 --- a/packages/react/src/components/buttons/button.test.tsx +++ b/packages/react/src/components/buttons/button.test.tsx @@ -69,9 +69,9 @@ describe('Button', () => { expect(tree).toMatchSnapshot(); }); - test('has destructive styles (inversed)', () => { + test('has destructive styles (inverted)', () => { const tree = renderWithProviders( -