2017-10-31 12:03:44 +02:00
|
|
|
import React from 'react';
|
|
|
|
import { Broadcast } from 'joy-react-broadcast';
|
|
|
|
import styled, { css } from 'styled-components';
|
|
|
|
import PropTypes from 'prop-types';
|
|
|
|
import is, { isNot } from 'styled-is';
|
|
|
|
import remcalc from 'remcalc';
|
|
|
|
|
2017-05-18 21:21:33 +03:00
|
|
|
import Baseline from '../baseline';
|
2017-10-10 13:15:35 +03:00
|
|
|
import { bottomShadow, bottomShadowDarker } from '../boxes';
|
2017-05-18 21:21:33 +03:00
|
|
|
|
2017-10-31 12:03:44 +02:00
|
|
|
const paperEffect = css`
|
|
|
|
margin-bottom: ${remcalc(16)};
|
|
|
|
box-shadow: 0 ${remcalc(8)} 0 ${remcalc(-5)}
|
|
|
|
${props => props.theme.background},
|
|
|
|
0 ${remcalc(8)} ${remcalc(1)} ${remcalc(-4)} ${props => props.theme.grey},
|
|
|
|
0 ${remcalc(16)} 0 ${remcalc(-10)} ${props => props.theme.background},
|
|
|
|
0 ${remcalc(16)} ${remcalc(1)} ${remcalc(-9)} ${props => props.theme.grey};
|
|
|
|
`;
|
2017-05-18 21:21:33 +03:00
|
|
|
|
2017-10-31 12:03:44 +02:00
|
|
|
export const BaseCard = styled.div`
|
|
|
|
box-sizing: content-box;
|
|
|
|
display: flex;
|
|
|
|
flex: 1 0 auto;
|
|
|
|
flex-direction: column;
|
2017-07-26 18:11:23 +03:00
|
|
|
|
2017-10-31 12:03:44 +02:00
|
|
|
height: auto;
|
|
|
|
min-height: ${remcalc(125)};
|
|
|
|
position: relative;
|
2017-05-18 21:21:33 +03:00
|
|
|
|
2017-10-31 12:03:44 +02:00
|
|
|
border-width: ${remcalc(1)};
|
|
|
|
border-style: solid;
|
2017-09-20 12:30:53 +03:00
|
|
|
|
2017-11-09 13:27:32 +02:00
|
|
|
transition: all 300ms ease;
|
|
|
|
|
2017-10-31 12:03:44 +02:00
|
|
|
/* primary */
|
|
|
|
color: ${props => props.theme.text};
|
|
|
|
background-color: ${props => props.theme.white};
|
|
|
|
border-color: ${props => props.theme.grey};
|
|
|
|
|
|
|
|
${is('shadow')`
|
|
|
|
/* primary */
|
|
|
|
box-shadow: ${bottomShadow};
|
|
|
|
|
|
|
|
/* if disabled, shadow is the same */
|
|
|
|
${isNot('disabled')`
|
|
|
|
${is('secondary')`
|
|
|
|
box-shadow: ${bottomShadowDarker};
|
|
|
|
`};
|
|
|
|
|
|
|
|
${is('tertiary')`
|
|
|
|
box-shadow: 0 ${remcalc(2)} 0 rgba(0, 0, 0, 0.05);
|
|
|
|
`};
|
|
|
|
|
|
|
|
${is('stacked')`
|
|
|
|
box-shadow: ${paperEffect};
|
|
|
|
`};
|
|
|
|
`};
|
2017-09-20 12:30:53 +03:00
|
|
|
`};
|
|
|
|
|
2017-10-31 12:03:44 +02:00
|
|
|
${is('secondary')`
|
|
|
|
color: ${props => props.theme.white};
|
|
|
|
background-color: ${props => props.theme.primary};
|
|
|
|
border-color: ${props => props.theme.primaryActive};
|
2017-09-20 12:30:53 +03:00
|
|
|
`};
|
|
|
|
|
2017-10-31 12:03:44 +02:00
|
|
|
${is('tertiary')`
|
|
|
|
color: ${props => props.theme.text};
|
|
|
|
background-color: ${props => props.theme.background};
|
|
|
|
border-color: ${props => props.theme.grey};
|
|
|
|
border-radius: ${remcalc(4)};
|
|
|
|
min-width: ${remcalc(292)};
|
|
|
|
|
|
|
|
${is('active')`
|
|
|
|
border-color: ${props => props.theme.primary};
|
|
|
|
background: ${props => props.theme.tertiaryActive};
|
|
|
|
box-shadow: none;
|
|
|
|
`};
|
2017-09-20 12:30:53 +03:00
|
|
|
`};
|
|
|
|
|
2017-10-31 12:03:44 +02:00
|
|
|
${is('actionable')`
|
2017-09-18 17:08:55 +03:00
|
|
|
cursor: pointer;
|
2017-05-18 21:21:33 +03:00
|
|
|
`};
|
2017-08-14 13:21:45 +03:00
|
|
|
|
2017-10-09 16:35:52 +03:00
|
|
|
${is('disabled')`
|
2017-10-31 12:03:44 +02:00
|
|
|
border-color: ${props => props.theme.grey};
|
2017-10-09 16:35:52 +03:00
|
|
|
background-color: ${props => props.theme.disabled};
|
2017-10-31 12:03:44 +02:00
|
|
|
color: ${props => props.theme.text};
|
|
|
|
cursor: default;
|
2017-10-09 16:35:52 +03:00
|
|
|
`};
|
|
|
|
|
2017-10-31 12:03:44 +02:00
|
|
|
${is('collapsed')`
|
|
|
|
min-height: auto;
|
|
|
|
height: ${remcalc(46)};
|
|
|
|
flex: 0 0 ${remcalc(46)};
|
2017-08-14 13:21:45 +03:00
|
|
|
`};
|
2017-11-09 13:27:32 +02:00
|
|
|
|
|
|
|
${is('bottomless')`
|
|
|
|
border-bottom-width: 0;
|
|
|
|
`};
|
2017-05-18 21:21:33 +03:00
|
|
|
`;
|
|
|
|
|
|
|
|
/**
|
2017-10-31 12:03:44 +02:00
|
|
|
* @example ./demo.md
|
2017-05-18 21:21:33 +03:00
|
|
|
*/
|
2017-11-09 13:27:32 +02:00
|
|
|
const Card = ({
|
|
|
|
children,
|
|
|
|
secondary,
|
|
|
|
tertiary,
|
|
|
|
collapsed,
|
|
|
|
disabled,
|
|
|
|
stacked,
|
|
|
|
active,
|
|
|
|
shadow,
|
|
|
|
actionable,
|
|
|
|
...rest
|
|
|
|
}) => {
|
|
|
|
const newValue = {
|
|
|
|
secondary,
|
|
|
|
tertiary,
|
|
|
|
collapsed,
|
|
|
|
disabled,
|
|
|
|
stacked,
|
|
|
|
active,
|
|
|
|
shadow,
|
|
|
|
actionable
|
|
|
|
};
|
|
|
|
|
|
|
|
return (
|
|
|
|
<Broadcast channel="card" value={newValue}>
|
|
|
|
<BaseCard {...rest} {...newValue} name="card">
|
|
|
|
{children}
|
|
|
|
</BaseCard>
|
|
|
|
</Broadcast>
|
|
|
|
);
|
|
|
|
};
|
2017-05-18 21:21:33 +03:00
|
|
|
|
|
|
|
Card.propTypes = {
|
|
|
|
children: PropTypes.node,
|
2017-10-31 12:03:44 +02:00
|
|
|
secondary: PropTypes.bool,
|
|
|
|
tertiary: PropTypes.bool,
|
2017-05-18 21:21:33 +03:00
|
|
|
collapsed: PropTypes.bool,
|
2017-10-31 12:03:44 +02:00
|
|
|
disabled: PropTypes.bool,
|
2017-09-14 14:26:57 +03:00
|
|
|
stacked: PropTypes.bool,
|
2017-10-31 12:03:44 +02:00
|
|
|
active: PropTypes.bool,
|
|
|
|
shadow: PropTypes.bool,
|
|
|
|
actionable: PropTypes.bool
|
2017-10-23 17:09:49 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
Card.defaultProps = {
|
2017-10-31 12:03:44 +02:00
|
|
|
children: null,
|
2017-10-23 17:09:49 +03:00
|
|
|
collapsed: false,
|
2017-10-31 12:03:44 +02:00
|
|
|
secondary: false,
|
|
|
|
tertiary: false,
|
|
|
|
disabled: false,
|
2017-10-23 17:09:49 +03:00
|
|
|
stacked: false,
|
2017-10-31 12:03:44 +02:00
|
|
|
active: false,
|
|
|
|
shadow: false,
|
|
|
|
actionable: false
|
2017-05-18 21:21:33 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
export default Baseline(Card);
|