diff --git a/packages/react/src/components/Card/CardWrap.js b/packages/react/src/components/Card/CardWrap.js index 56b408a6f..0822bc137 100644 --- a/packages/react/src/components/Card/CardWrap.js +++ b/packages/react/src/components/Card/CardWrap.js @@ -1,9 +1,9 @@ import { createElement, forwardRef, useContext } from 'react' import styled, { css } from 'styled-components' -import { media, isLarge } from '../../utils' -import { font, animation, speed } from '../../theme' import { GlobalContext } from '../../context/GlobalState' +import { font, animation, speed } from '../../theme' +import { media, isLarge } from '../../utils' const HEIGHT = '382px' @@ -61,7 +61,6 @@ const baseStyle = css( transition-duration: ${speed.medium}; transition-timing-function: ${animation.medium}; - &:active, &:hover { outline: 0; @@ -69,29 +68,32 @@ const baseStyle = css( ` ) -const createEl = el => - styled(el)( - baseStyle, - ({ isLoading, contrast }) => !isLoading && !contrast && hoverStyle, - ({ cardSize }) => isLarge(cardSize) && largeStyle, - ({ direction }) => direction === 'rtl' && rtlStyle, - ({ backgroundColor, color, contrast }) => - contrast && color && backgroundColor && contrastStyle, - ({ backgroundColor, color, contrast }) => - contrast && (!color || !backgroundColor) && hoverStyle - ) +const Element = styled('a')( + baseStyle, + ({ isLoading, contrast }) => !isLoading && !contrast && hoverStyle, + ({ cardSize }) => isLarge(cardSize) && largeStyle, + ({ direction }) => direction === 'rtl' && rtlStyle, + ({ backgroundColor, color, contrast }) => + contrast && color && backgroundColor && contrastStyle, + ({ backgroundColor, color, contrast }) => + contrast && (!color || !backgroundColor) && hoverStyle +) const CardWrap = forwardRef(({ href, rel, target, ...restProps }, ref) => { const { state: { backgroundColor, color, title }, props: { size: cardSize } } = useContext(GlobalContext) - const props = { ...restProps, backgroundColor, cardSize, color, ref, title } - return createElement( - createEl(props.as), - props.as === 'a' ? { href, rel, target, ...props } : props - ) + return createElement(Element, { + ...(restProps.as === 'a' ? { href, rel, target } : undefined), + ...restProps, + backgroundColor, + cardSize, + color, + ref, + title + }) }) CardWrap.defaultProps = { diff --git a/packages/react/stories/__snapshots__/stories.test.js.snap b/packages/react/stories/__snapshots__/stories.test.js.snap index 20a84ec64..20d9457f4 100644 --- a/packages/react/stories/__snapshots__/stories.test.js.snap +++ b/packages/react/stories/__snapshots__/stories.test.js.snap @@ -25,7 +25,7 @@ exports[`Storyshots media audio 1`] = ` align-items: stretch; } -.c12 { +.c11 { display: -webkit-box; display: -webkit-flex; display: -ms-flexbox; @@ -49,7 +49,7 @@ exports[`Storyshots media audio 1`] = ` align-items: center; } -.c16 { +.c15 { display: -webkit-box; display: -webkit-flex; display: -ms-flexbox; @@ -104,7 +104,7 @@ exports[`Storyshots media audio 1`] = ` transition: opacity 150ms cubic-bezier(.25,.8,.25,1); } -.c11 { +.c10 { background: transparent no-repeat center center / cover; display: block; overflow: hidden; @@ -115,13 +115,13 @@ exports[`Storyshots media audio 1`] = ` flex: 0 0 48px; } -.c11::before { +.c10::before { content: ''; padding-bottom: 100%; display: block; } -.c11::after { +.c10::after { content: ''; position: absolute; left: 0; @@ -135,7 +135,7 @@ exports[`Storyshots media audio 1`] = ` transition: opacity 150ms cubic-bezier(.25,.8,.25,1); } -.c15 { +.c14 { background: transparent no-repeat center center / cover; display: block; overflow: hidden; @@ -146,17 +146,17 @@ exports[`Storyshots media audio 1`] = ` flex: 1; } -.c15::before { +.c14::before { content: ''; padding-bottom: 100%; display: block; } -.c15::before { +.c14::before { padding-bottom: 0; } -.c15::after { +.c14::after { content: ''; position: absolute; left: 0; @@ -171,8 +171,8 @@ exports[`Storyshots media audio 1`] = ` } .c5 { - -webkit-animation: PfPAm 1.25s linear infinite; - animation: PfPAm 1.25s linear infinite; + -webkit-animation: kHwByW 1.25s linear infinite; + animation: kHwByW 1.25s linear infinite; } .c7 { @@ -182,19 +182,19 @@ exports[`Storyshots media audio 1`] = ` background: #e1e8ed; margin: 2px 0 8px; opacity: 0.8; - -webkit-animation: bmjNQl .75s linear infinite; - animation: bmjNQl .75s linear infinite; + -webkit-animation: ibPKPZ .75s linear infinite; + animation: ibPKPZ .75s linear infinite; } -.c13 { +.c12 { height: 16px; width: 75%; display: block; background: #e1e8ed; margin: 0 20px 0 0; opacity: 0.8; - -webkit-animation: bmjNQl .75s linear infinite; - animation: bmjNQl .75s linear infinite; + -webkit-animation: ibPKPZ .75s linear infinite; + animation: ibPKPZ .75s linear infinite; } .c8 { @@ -205,8 +205,8 @@ exports[`Storyshots media audio 1`] = ` margin-bottom: 12px; opacity: 0.8; position: relative; - -webkit-animation: bmjNQl .75s linear infinite; - animation: bmjNQl .75s linear infinite; + -webkit-animation: ibPKPZ .75s linear infinite; + animation: ibPKPZ .75s linear infinite; -webkit-animation-delay: 0.125s; animation-delay: 0.125s; } @@ -224,7 +224,7 @@ exports[`Storyshots media audio 1`] = ` top: 14px; } -.c17 { +.c16 { height: 33px; width: 95%; display: block; @@ -232,13 +232,13 @@ exports[`Storyshots media audio 1`] = ` margin-bottom: 12px; opacity: 0.8; position: relative; - -webkit-animation: bmjNQl .75s linear infinite; - animation: bmjNQl .75s linear infinite; + -webkit-animation: ibPKPZ .75s linear infinite; + animation: ibPKPZ .75s linear infinite; -webkit-animation-delay: 0.125s; animation-delay: 0.125s; } -.c17::before { +.c16::before { content: ''; position: absolute; left: -1px; @@ -247,7 +247,7 @@ exports[`Storyshots media audio 1`] = ` background: #fff; } -.c17::before { +.c16::before { top: 14px; } @@ -257,37 +257,12 @@ exports[`Storyshots media audio 1`] = ` display: block; background: #e1e8ed; opacity: 0.8; - -webkit-animation: bmjNQl .75s linear infinite; - animation: bmjNQl .75s linear infinite; + -webkit-animation: ibPKPZ .75s linear infinite; + animation: ibPKPZ .75s linear infinite; -webkit-animation-delay: .25s; animation-delay: .25s; } -.c0 { - display: -webkit-box; - display: -webkit-flex; - display: -ms-flexbox; - display: flex; - -webkit-flex-direction: column; - -ms-flex-direction: column; - flex-direction: column; - padding-bottom: 32px; - margin-bottom: 32px; -} - -.c0:not(:last-child):not(:only-child) { - border-bottom: 1px solid #e0e0e0; -} - -.c1 { - color: #0366d6; - margin-bottom: 32px; -} - -.c3:not(:last-child):not(:only-child) { - margin-bottom: 32px; -} - .c2 { max-width: 500px; background-color: #fff; @@ -316,7 +291,7 @@ exports[`Storyshots media audio 1`] = ` outline: 0; } -.c10 { +.c13 { max-width: 500px; background-color: #fff; border-width: 1px; @@ -337,43 +312,40 @@ exports[`Storyshots media audio 1`] = ` transition-duration: 150ms; -webkit-transition-timing-function: cubic-bezier(.25,.8,.25,1); transition-timing-function: cubic-bezier(.25,.8,.25,1); + -webkit-flex-direction: column; + -ms-flex-direction: column; + flex-direction: column; + height: 382px; } -.c10:active, -.c10:hover { +.c13:active, +.c13:hover { outline: 0; } -.c14 { - max-width: 500px; - background-color: #fff; - border-width: 1px; - border-style: solid; - border-color: #e1e8ed; - overflow: hidden; - color: #181919; - font-family: InterUI,-apple-system,BlinkMacSystemFont,'Helvetica Neue','Segoe UI',Oxygen,Ubuntu,Cantarell,'Open Sans',sans-serif; +.c0 { display: -webkit-box; display: -webkit-flex; display: -ms-flexbox; display: flex; - -webkit-text-decoration: none; - text-decoration: none; - opacity: 1; - position: relative; - -webkit-transition-duration: 150ms; - transition-duration: 150ms; - -webkit-transition-timing-function: cubic-bezier(.25,.8,.25,1); - transition-timing-function: cubic-bezier(.25,.8,.25,1); -webkit-flex-direction: column; -ms-flex-direction: column; flex-direction: column; - height: 382px; + padding-bottom: 32px; + margin-bottom: 32px; } -.c14:active, -.c14:hover { - outline: 0; +.c0:not(:last-child):not(:only-child) { + border-bottom: 1px solid #e0e0e0; +} + +.c1 { + color: #0366d6; + margin-bottom: 32px; +} + +.c3:not(:last-child):not(:only-child) { + margin-bottom: 32px; } @media (max-width:48em) { @@ -395,11 +367,7 @@ exports[`Storyshots media audio 1`] = ` } @media (max-width:48em) { - -} - -@media (max-width:48em) { - .c14 { + .c13 { height: calc(382px * 7/9); } } @@ -438,20 +406,20 @@ exports[`Storyshots media audio 1`] = `