joyent-portal/packages/ui-toolkit/src/card/title.js

98 lines
1.8 KiB
JavaScript
Raw Normal View History

2017-02-27 17:41:08 +02:00
import { Subscriber } from 'react-broadcast';
import isString from 'lodash.isstring';
import typography from '../typography';
import Baseline from '../baseline';
import remcalc from 'remcalc';
import is from 'styled-is';
import styled from 'styled-components';
import PropTypes from 'prop-types';
import React from 'react';
2017-01-09 14:13:12 +02:00
const Container = styled.div`
font-size: ${remcalc(15)};
2017-01-09 14:13:12 +02:00
line-height: 1.5;
color: ${props => props.theme.secondary};
2017-01-09 14:13:12 +02:00
${typography.fontFamily};
${typography.semibold};
2017-02-27 17:41:08 +02:00
2017-01-09 14:13:12 +02:00
display: flex;
flex-direction: row;
justify-content: flex-start;
2017-01-09 14:13:12 +02:00
flex-grow: 2;
width: 100%;
2017-01-09 14:13:12 +02:00
padding: ${remcalc(12)} ${remcalc(18)} 0 ${remcalc(18)};
2017-01-09 14:13:12 +02:00
2017-02-27 17:41:08 +02:00
${is('fromHeader')`
color: ${props => props.theme.white};
2017-02-27 17:41:08 +02:00
`};
${is('disabled')`
color: ${props => props.theme.grey};
`};
${is('collapsed')`
flex-grow: 0;
flex-direction: column;
width: auto;
justify-content: center;
padding: 0 ${remcalc(18)};
`};
`;
2017-01-09 14:13:12 +02:00
const Span = styled.span`
display: inline-block;
2017-01-09 14:13:12 +02:00
flex-direction: column;
justify-content: center;
${is('collapsed')`
display: flex;
`};
2017-01-09 14:13:12 +02:00
`;
const Title = ({ children, ...rest }) => {
2017-07-26 15:50:49 +03:00
const _children = isString(children)
? <Span>
{children}
</Span>
: children;
2017-01-09 14:13:12 +02:00
const render = ({
collapsed = false,
disabled = false,
fromHeader = false
}) =>
2017-01-09 14:13:12 +02:00
<Container
collapsed={collapsed}
2017-02-27 17:41:08 +02:00
fromHeader={fromHeader}
disabled={disabled}
name="card-title"
2017-02-27 17:41:08 +02:00
xs={collapsed ? 6 : 12}
{...rest}
2017-01-09 14:13:12 +02:00
>
{_children}
2017-06-12 01:58:22 +03:00
</Container>;
2017-02-27 17:41:08 +02:00
return (
<Subscriber channel="card">
2017-02-27 17:41:08 +02:00
{render}
</Subscriber>
);
2017-01-09 14:13:12 +02:00
};
Title.propTypes = {
children: PropTypes.node,
/**
* @ignore
*/
collapsed: PropTypes.bool,
/**
* @ignore
*/
fromHeader: PropTypes.bool
2017-01-09 14:13:12 +02:00
};
export default Baseline(Title);