From 3aeeb4149feed8a73a9f9424e490850a4b7249b4 Mon Sep 17 00:00:00 2001 From: 59naga Date: Mon, 16 May 2016 07:32:40 +0900 Subject: [PATCH] [AppBar] Add iconStyleLeft prop (fix #3667) - Add export `getStyles` of app-bar.js for test --- src/AppBar/AppBar.js | 13 ++++++++++--- src/AppBar/AppBar.spec.js | 38 +++++++++++++++++++++++++++++++++++++- 2 files changed, 47 insertions(+), 4 deletions(-) diff --git a/src/AppBar/AppBar.js b/src/AppBar/AppBar.js index 9c92e8934f96ee..7dc94763a96fce 100644 --- a/src/AppBar/AppBar.js +++ b/src/AppBar/AppBar.js @@ -5,7 +5,7 @@ import Paper from '../Paper'; import propTypes from '../utils/propTypes'; import warning from 'warning'; -function getStyles(props, context) { +export function getStyles(props, context) { const { appBar, button: { @@ -92,6 +92,10 @@ class AppBar extends Component { * Similiar to the iconElementLeft prop except that this element is displayed on the right of the app bar. */ iconElementRight: PropTypes.element, + /** + * Override the inline-styles of the element displayed on the left side of the app bar. + */ + iconStyleLeft: PropTypes.object, /** * Override the inline-styles of the element displayed on the right side of the app bar. */ @@ -178,6 +182,7 @@ class AppBar extends Component { const { title, titleStyle, + iconStyleLeft, iconStyleRight, showMenuIconButton, iconElementLeft, @@ -206,6 +211,8 @@ class AppBar extends Component { style: prepareStyles(Object.assign(styles.title, styles.mainElement, titleStyle)), }, title); + const iconLeftStyle = Object.assign({}, styles.iconButtonStyle, iconStyleLeft); + if (showMenuIconButton) { let iconElementLeftNode = iconElementLeft; @@ -220,7 +227,7 @@ class AppBar extends Component { } menuElementLeft = ( -
+
{iconElementLeftNode}
); @@ -228,7 +235,7 @@ class AppBar extends Component { const child = iconClassNameLeft ? '' : ; menuElementLeft = ( ', () => { const muiTheme = getMuiTheme(); @@ -171,4 +172,39 @@ describe('', () => { assert.equal(wrapper.find('Paper').get(0).props.zDepth, 2, 'should have zDepth to 2'); }); + + it('menuElementLeft\'s style should be iconButtonStyle', () => { + const wrapper = shallowWithContext( + + ); + + const menuElementLeft = wrapper.find(IconButton).get(0); + const style = menuElementLeft.props.style; + const iconButtonStyle = getStyles(wrapper.props(), wrapper.context()).iconButtonStyle; + assert.deepEqual(style, iconButtonStyle, 'style should be iconButtonStyle'); + }); + + it('if pass iconStyleLeft={marginTop}, change the marginTop only', () => { + const wrapper = shallowWithContext( + + ); + + const menuElementLeft = wrapper.find(IconButton).get(0); + const style = menuElementLeft.props.style; + const iconButtonStyle = getStyles(wrapper.props(), wrapper.context()).iconButtonStyle; + const expectedStyle = Object.assign({}, iconButtonStyle, {marginTop: 99}); + assert.deepEqual(style, expectedStyle, 'should be change style.marginTop only'); + }); + + it('if pass iconElementLeft and iconStyleLeft={marginTop}, change the marginTop/muiPrepared only', () => { + const wrapper = shallowWithContext( + foo} iconStyleLeft={{marginTop: 99}} /> + ); + + const menuElementLeft = wrapper.find('div').get(0); + const style = menuElementLeft.props.style; + const iconButtonStyle = getStyles(wrapper.props(), wrapper.context()).iconButtonStyle; + const expectedStyle = Object.assign({}, iconButtonStyle, {marginTop: 99, muiPrepared: true}); + assert.deepEqual(style, expectedStyle, 'should be change style.marginTop/muiPrepared only'); + }); });