1
0
mirror of https://github.com/yldio/copilot.git synced 2024-11-15 15:50:06 +02:00
copilot/packages/ui-toolkit/src/card/description.js

64 lines
1.3 KiB
JavaScript
Raw Normal View History

2017-02-27 17:41:08 +02:00
import { Subscriber } from 'react-broadcast';
import Baseline from '../baseline';
import typography from '../typography';
import is, { isNot } from 'styled-is';
import remcalc from 'remcalc';
import styled from 'styled-components';
import PropTypes from 'prop-types';
import Title from './title';
import React from 'react';
2017-01-09 14:13:12 +02:00
const StyledTitle = styled(Title)`
${typography.fontFamily};
${typography.normal};
flex-grow: 2;
2017-02-27 17:41:08 +02:00
${isNot('collapsed')`
position: absolute;
bottom: 0;
padding-bottom: ${remcalc(12)};
padding-top: 0;
`};
2017-01-09 14:13:12 +02:00
`;
const InnerDescription = styled.div`
justify-content: flex-start;
${is('collapsed')`
justify-content: flex-end;
2017-02-27 17:41:08 +02:00
margin-left: auto;
`};
2017-01-09 14:13:12 +02:00
`;
const Description = ({ children, ...rest }) => {
const render = ({ collapsed = false }) => (
2017-02-27 17:41:08 +02:00
<StyledTitle
collapsed={collapsed}
name="card-description"
2017-02-27 17:41:08 +02:00
xs={collapsed ? 6 : 12}
{...rest}
2017-02-27 17:41:08 +02:00
>
<InnerDescription collapsed={collapsed}>
{children}
</InnerDescription>
</StyledTitle>
);
return (
<Subscriber channel="card">
2017-02-27 17:41:08 +02:00
{render}
</Subscriber>
);
};
2017-01-09 14:13:12 +02:00
Description.propTypes = {
children: PropTypes.node,
/**
* @ignore
*/
collapsed: PropTypes.bool
2017-01-09 14:13:12 +02:00
};
export default Baseline(Description);