Skip to content

Commit a286f9b

Browse files
committed
Merge branch 'Kikobeats-patch-1' into dev
* Kikobeats-patch-1: Small fixes Update AppBar.js Add possibility to render component as AppBar title
2 parents d86f774 + 56a730e commit a286f9b

File tree

2 files changed

+37
-23
lines changed

2 files changed

+37
-23
lines changed

components/app_bar/AppBar.js

Lines changed: 36 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import React, { PropTypes } from 'react';
2-
import classnames from 'classnames';
2+
import cn from 'classnames';
33
import { themr } from 'react-css-themr';
44
import { APP_BAR } from '../identifiers';
55
import InjectIconButton from '../button/IconButton';
@@ -32,7 +32,10 @@ const factory = (IconButton) => {
3232
scrollHide: PropTypes.string,
3333
title: PropTypes.string,
3434
}),
35-
title: PropTypes.node,
35+
title: PropTypes.oneOfType([
36+
PropTypes.string,
37+
PropTypes.element,
38+
]),
3639
};
3740

3841
static defaultProps = {
@@ -66,16 +69,16 @@ const factory = (IconButton) => {
6669
}
6770
}
6871

69-
initializeScroll = () => {
72+
initializeScroll() {
7073
window.addEventListener('scroll', this.handleScroll);
7174
const { height } = this.rootNode.getBoundingClientRect();
7275
this.curScroll = window.scrollY;
7376
this.setState({ height });
74-
};
77+
}
7578

76-
endScroll = () => {
79+
endScroll() {
7780
window.removeEventListener('scroll', this.handleScroll);
78-
};
81+
}
7982

8083
handleScroll = () => {
8184
const scrollDiff = this.curScroll - window.scrollY;
@@ -96,35 +99,46 @@ const factory = (IconButton) => {
9699
theme,
97100
title,
98101
} = this.props;
99-
const className = classnames(theme.appBar, {
102+
103+
const className = cn(theme.appBar, {
100104
[theme.fixed]: this.props.fixed,
101105
[theme.flat]: this.props.flat,
102106
[theme.scrollHide]: this.state.hidden,
103107
}, this.props.className);
104108

109+
const renderedTitle = typeof title === 'string'
110+
? <h1 className={cn(theme.title)}>{title}</h1>
111+
: title;
112+
113+
const renderedLeftIcon = leftIcon && (
114+
<IconButton
115+
inverse
116+
className={cn(theme.leftIcon)}
117+
onClick={onLeftIconClick}
118+
icon={leftIcon}
119+
/>
120+
);
121+
122+
const renderedRightIcon = rightIcon && (
123+
<IconButton
124+
inverse
125+
className={cn(theme.rightIcon)}
126+
onClick={onRightIconClick}
127+
icon={rightIcon}
128+
/>
129+
);
130+
105131
return (
106132
<header
107133
className={className}
108134
data-react-toolbox="app-bar"
109135
ref={(node) => { this.rootNode = node; }}
110136
>
111137
<div className={theme.inner}>
112-
{leftIcon && <IconButton
113-
inverse
114-
className={classnames(theme.leftIcon)}
115-
onClick={onLeftIconClick}
116-
icon={leftIcon}
117-
/>
118-
}
119-
{title && <h1 className={classnames(theme.title)}>{title}</h1>}
138+
{renderedLeftIcon}
139+
{renderedTitle}
120140
{children}
121-
{rightIcon && <IconButton
122-
inverse
123-
className={classnames(theme.rightIcon)}
124-
onClick={onRightIconClick}
125-
icon={rightIcon}
126-
/>
127-
}
141+
{renderedRightIcon}
128142
</div>
129143
</header>
130144
);

components/app_bar/readme.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ The `AppBar` component provides properties for the common use cases of `title`,
3636
| `fixed` | `Bool` | `false` | Determine if the bar should have position `fixed` or `relative`.|
3737
| `flat` | `Bool` | `false` | If true, the AppBar doesn't show a shadow.|
3838
| `theme` | `Object` | `null` | Classnames object defining the component style.|
39-
| `title` | `Element` | `null` | Title used for the appbar.|
39+
| `title` | `String|Element` | `null` | Title used for the appbar.|
4040
| `leftIcon` | `String|Element` | `null` | Left icon.|
4141
| `onLeftIconClick` | `Function` | `null` | Called on left icon click event.|
4242
| `rightIcon` | `String|Element` | `null` | Right icon.|

0 commit comments

Comments
 (0)