diff --git a/components/SnackBar/SnackBar.jsx b/components/SnackBar/SnackBar.jsx index fc869e432..771a8d17d 100644 --- a/components/SnackBar/SnackBar.jsx +++ b/components/SnackBar/SnackBar.jsx @@ -1,39 +1,87 @@ import React from 'react'; import ReactDOM from 'react-dom'; -import styled from 'styled-components'; -import PropTypes, { oneOf } from 'prop-types'; -import Colors from '../Colors'; +import styled, { css } from 'styled-components'; +import PropTypes from 'prop-types'; import Button from '../Button'; import { Row, Col } from '../Grid'; import uniqId from '../shared/uniqId'; +import { + components, + spacing, + colors, + baseFontSize as defaultBaseFontSize, +} from '../shared/theme'; const ID_GENERATOR = uniqId('snackbar-dialog-'); -const a11yFocusTab = `outline: auto;`; +const a11yFocusTab = props => { + const { text } = getBackgroundAndTextColorBySkin(props); -const getBackgroundBySkin = skin => { - const color = skin.toUpperCase(); - const indexColor = skin === 'cobalt' ? '500' : '700'; return ` - background-color: ${Colors[color][indexColor]} + outline: 1px solid ${text}; `; }; +const getBackgroundAndTextColorBySkin = ({ + skin, + theme: { + components: { + snackbar: { + skins: { + [skin]: { text, background }, + }, + }, + }, + }, + inverted, +}) => { + if (inverted) { + const [textInverted, backgroundInverted] = [background, text]; + + return { + background: backgroundInverted, + text: textInverted, + }; + } + + return { + background, + text, + }; +}; + const SnackBarDialog = styled.div` align-items: center; border-radius: 4px; - color: ${Colors.WHITE}; display: flex; justify-content: space-between; min-height: 48px; - padding: 13px 16px; + ${({ theme: { spacing } }) => ` + padding: ${spacing.small}px ${spacing.medium}px; + `} + + ${props => { + const { background, text } = getBackgroundAndTextColorBySkin(props); + return ` + background-color: ${background}; + color: ${text}; + `; + }} - ${({ skin }) => getBackgroundBySkin(skin)} + :focus { + ${a11yFocusTab} + } `; const TextContainer = styled.strong` font-weight: normal; - padding-right: 8px; + ${({ + theme: { + spacing: { xsmall }, + }, + }) => ` + padding-right: ${xsmall}px; + `} :focus { ${a11yFocusTab} @@ -43,19 +91,42 @@ const TextContainer = styled.strong` const CloseIcon = styled(Button.Icon).attrs({ icon: 'close', })` - color: ${Colors.WHITE}; + ${props => { + const { text } = getBackgroundAndTextColorBySkin(props); - :hover, - :focus { - background-color: transparent; - box-shadow: none; - color: ${Colors.WHITE}; - ${a11yFocusTab} - } + return css` + color: ${text}; + + :hover, + :focus { + background-color: transparent; + box-shadow: none; + color: ${text}; + ${a11yFocusTab} + } + `; + }} `; const ActionButton = styled(Button)` - color: ${Colors.WHITE}; + ${props => { + const { text } = getBackgroundAndTextColorBySkin(props); + + return ` + border: 1px solid ${text}; + color: ${text}; + + :hover, + :focus { + border: 1px solid ${text}; + color: ${text}; + text-decoration: none; + background-color: transparent; + } + `; + }}; + + background-color: transparent; font-weight: bold; text-transform: uppercase; white-space: nowrap; @@ -63,7 +134,7 @@ const ActionButton = styled(Button)` :hover, :focus { text-decoration: none; - color: ${Colors.WHITE}; + background-color: transparent; } :focus { @@ -129,6 +200,9 @@ class SnackBar extends React.Component { onClose, closeButtonAriaLabel, actionTrigger, + theme, + skin, + inverted, ...rest } = this.props; return ReactDOM.createPortal( @@ -144,22 +218,37 @@ class SnackBar extends React.Component { > - {text} + + {text} + {actionTrigger && ( {actionTrigger.title} {onClose && ( {}, secondsToClose: 6, - skin: 'cobalt', + skin: 'neutral', text: 'Text of SnackBar component', actionTrigger: { title: 'ACTION', callbackFn: () => {}, }, + inverted: false, id: undefined, + theme: { + colors, + baseFontSize: defaultBaseFontSize, + spacing, + components: { + snackbar: components.snackbar, + }, + }, }; export default SnackBar;