11import React , { PropTypes } from 'react' ;
2- import classnames from 'classnames' ;
2+ import cn from 'classnames' ;
33import { themr } from 'react-css-themr' ;
44import { APP_BAR } from '../identifiers' ;
55import 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 ) ;
0 commit comments