Added Title component for the layout

This commit is contained in:
Jori Lallo
2016-05-15 16:44:17 -05:00
parent 25af2e9152
commit 2006a64e24
8 changed files with 74 additions and 27 deletions

View File

@@ -1,5 +1,4 @@
import React from 'react';
import _truncate from 'lodash/truncate';
import { connect } from 'react-redux';
import Link from 'react-router/lib/Link';
@@ -11,7 +10,7 @@ import styles from './Layout.scss';
class Layout extends React.Component {
static propTypes = {
actions: React.PropTypes.node,
title: React.PropTypes.string,
title: React.PropTypes.node,
}
render() {
@@ -22,11 +21,7 @@ class Layout extends React.Component {
<Link to="/">{ this.props.teamName }</Link>
</div>
<Flex align="center" className={ styles.title }>
{ this.props.title ? (
<span title={this.props.title}>{ _truncate(this.props.title, 60) }</span>
) : (
<span className={ styles.untitled }>Untitled document</span>
)}
{ this.props.title }
</Flex>
<Flex direction="row">
<Flex align="center" className={ styles.actions }>

View File

@@ -33,15 +33,7 @@
justify-content: center;
}
.title {
color: #444;
}
.actions a {
text-decoration: none;
margin-right: 15px;
}
.untitled {
color: #ccc;
}

View File

@@ -0,0 +1,38 @@
import React from 'react';
import _truncate from 'lodash/truncate';
import styles from './Title.scss';
import classNames from 'classnames/bind';
const cx = classNames.bind(styles);
const Title = (props) => {
let title;
if (props.truncate) {
title = _truncate(props.children, props.truncate);
} else {
title = props.children;
}
let usePlaceholder;
if (props.children === null && props.placeholder) {
title = props.placeholder;
usePlaceholder = true;
}
return(
<span
title={ props.children }
className={ cx(styles.title, { untitled: usePlaceholder })}
>
{ title }
</span>
);
};
Title.propTypes = {
children: React.PropTypes.string,
truncate: React.PropTypes.number,
placeholder: React.PropTypes.string,
}
export default Title;

View File

@@ -0,0 +1,7 @@
.title {
color: #444;
}
.untitled {
color: #ccc;
}

View File

@@ -0,0 +1,2 @@
import Title from './Title';
export default Title;

View File

@@ -1,2 +1,8 @@
import Layout from './Layout';
export default Layout;
import Title from './components/Title';
export default Layout;
export {
Title,
};