2016-10-05 14:36:59 +00:00
|
|
|
import React, { Component } from 'react';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Abstract (base) class for a button in Toolbar.
|
|
|
|
*
|
|
|
|
* @abstract
|
|
|
|
*/
|
|
|
|
export default class AbstractToolbarButton extends Component {
|
2016-12-01 01:52:39 +00:00
|
|
|
/**
|
|
|
|
* AbstractToolbarButton component's property types.
|
|
|
|
*
|
|
|
|
* @static
|
|
|
|
*/
|
|
|
|
static propTypes = {
|
|
|
|
/**
|
|
|
|
* The name of the Icon of this AbstractToolbarButton.
|
|
|
|
*/
|
|
|
|
iconName: React.PropTypes.string,
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The style of the Icon of this AbstractToolbarButton.
|
|
|
|
*/
|
|
|
|
iconStyle: React.PropTypes.object,
|
2017-03-31 17:54:58 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* On click handler.
|
|
|
|
*/
|
2016-12-01 01:52:39 +00:00
|
|
|
onClick: React.PropTypes.func,
|
2017-03-31 17:54:58 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Toolbar button styles.
|
|
|
|
*/
|
2016-12-01 01:52:39 +00:00
|
|
|
style:
|
|
|
|
React.PropTypes.oneOfType([
|
|
|
|
React.PropTypes.array,
|
|
|
|
React.PropTypes.object
|
|
|
|
]),
|
2017-03-31 17:54:58 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The color underlaying the button.
|
|
|
|
*/
|
2016-12-01 01:52:39 +00:00
|
|
|
underlayColor: React.PropTypes.any
|
|
|
|
}
|
2016-10-05 14:36:59 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Implements React's {@link Component#render()}.
|
|
|
|
*
|
|
|
|
* @inheritdoc
|
|
|
|
* @returns {ReactElement}
|
|
|
|
*/
|
|
|
|
render() {
|
|
|
|
return this._renderButton(this._renderIcon());
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Renders the icon of this Toolbar button.
|
|
|
|
*
|
|
|
|
* @param {string|ReactClass} type - The React Component type of the icon to
|
|
|
|
* be rendered.
|
|
|
|
* @protected
|
|
|
|
* @returns {ReactElement} The icon of this Toolbar button.
|
|
|
|
*/
|
|
|
|
_renderIcon(type) {
|
|
|
|
const props = {};
|
|
|
|
|
|
|
|
'iconName' in this.props && (props.name = this.props.iconName);
|
|
|
|
'iconStyle' in this.props && (props.style = this.props.iconStyle);
|
|
|
|
|
|
|
|
return React.createElement(type, props);
|
|
|
|
}
|
|
|
|
}
|