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

85 lines
1.7 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, { isNot } 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;
flex-basis: ${remcalc(90)};
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('collapsed')`
flex-grow: 6;
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-08-28 22:21:08 +03:00
const _children = isString(children) ? <Span>{children}</Span> : children;
2017-01-09 14:13:12 +02:00
2017-08-28 22:21:08 +03:00
const render = ({ collapsed = false, active = true, fromHeader = false }) => (
2017-01-09 14:13:12 +02:00
<Container
collapsed={collapsed}
2017-02-27 17:41:08 +02:00
fromHeader={fromHeader}
active={active}
name="card-title"
2017-02-27 17:41:08 +02:00
xs={collapsed ? 6 : 12}
{...rest}
2017-08-28 22:21:08 +03:00
name="container"
2017-01-09 14:13:12 +02:00
>
{_children}
2017-08-28 22:21:08 +03:00
</Container>
2017-02-27 17:41:08 +02:00
);
2017-08-28 22:21:08 +03:00
return <Subscriber channel="card">{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);