Add possibility to render component as AppBar title

old
Kiko Beats 2017-04-04 23:54:04 +02:00 committed by GitHub
parent 3dde4c4cda
commit cd3fefc838
1 changed files with 17 additions and 5 deletions

View File

@ -32,7 +32,10 @@ const factory = (IconButton) => {
scrollHide: PropTypes.string,
title: PropTypes.string,
}),
title: PropTypes.node,
title: PropTypes.oneOfType([
PropTypes.string,
PropTypes.element,
])
};
static defaultProps = {
@ -48,7 +51,7 @@ const factory = (IconButton) => {
if (this.props.scrollHide) {
this.initializeScroll();
}
}
};
componentWillReceiveProps(nextProps) {
if (!this.props.scrollHide && nextProps.scrollHide) {
@ -58,13 +61,13 @@ const factory = (IconButton) => {
if (this.props.scrollHide && !nextProps.scrollHide) {
this.endScroll();
}
}
};
componentWillUnmount() {
if (this.props.scrollHide) {
this.endScroll();
}
}
};
initializeScroll = () => {
window.addEventListener('scroll', this.handleScroll);
@ -85,6 +88,15 @@ const factory = (IconButton) => {
this.setState({ hidden });
this.curScroll = window.scrollY;
};
renderTitle = () => {
const {title} = this.props
if (!title) return;
if (typeof(title) === 'function') return title;
return (
<h1 className={classnames(theme.title)}>{title}</h1>
)
};
render() {
const {
@ -116,7 +128,7 @@ const factory = (IconButton) => {
icon={leftIcon}
/>
}
{title && <h1 className={classnames(theme.title)}>{title}</h1>}
{renderTitle(title)}
{children}
{rightIcon && <IconButton
inverse