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' ;
@@ -80,27 +80,16 @@ const factory = (IconButton) => {
8080 window . removeEventListener ( 'scroll' , this . handleScroll ) ;
8181 }
8282
83- handleScroll ( ) {
83+ handleScroll = ( ) => {
8484 const scrollDiff = this . curScroll - window . scrollY ;
8585 const hidden = scrollDiff < 0
8686 && window . scrollY !== undefined
8787 && window . scrollY > this . state . height ;
8888 this . setState ( { hidden } ) ;
8989 this . curScroll = window . scrollY ;
90- }
91-
92- renderTitle ( ) {
93- const { props } = this ;
94- const { title, theme } = props ;
95- if ( ! title ) return undefined ;
96-
97- return typeof ( title ) === 'string'
98- ? < h1 className = { classnames ( theme . title ) } > { title } </ h1 >
99- : React . createElement ( title , props ) ;
100- }
90+ } ;
10191
10292 render ( ) {
103- const { props, renderTitle } = this ;
10493 const {
10594 children,
10695 leftIcon,
@@ -109,36 +98,47 @@ const factory = (IconButton) => {
10998 rightIcon,
11099 theme,
111100 title,
112- } = props ;
113- const className = classnames ( theme . appBar , {
101+ } = this . props ;
102+
103+ const className = cn ( theme . appBar , {
114104 [ theme . fixed ] : this . props . fixed ,
115105 [ theme . flat ] : this . props . flat ,
116106 [ theme . scrollHide ] : this . state . hidden ,
117107 } , this . props . className ) ;
118108
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+
119131 return (
120132 < header
121133 className = { className }
122134 data-react-toolbox = "app-bar"
123135 ref = { ( node ) => { this . rootNode = node ; } }
124136 >
125137 < div className = { theme . inner } >
126- { leftIcon && < IconButton
127- inverse
128- className = { classnames ( theme . leftIcon ) }
129- onClick = { onLeftIconClick }
130- icon = { leftIcon }
131- />
132- }
133- { renderTitle ( title ) }
138+ { renderedLeftIcon }
139+ { renderedTitle }
134140 { children }
135- { rightIcon && < IconButton
136- inverse
137- className = { classnames ( theme . rightIcon ) }
138- onClick = { onRightIconClick }
139- icon = { rightIcon }
140- />
141- }
141+ { renderedRightIcon }
142142 </ div >
143143 </ header >
144144 ) ;
0 commit comments