2016-10-05 14:36:59 +00:00
|
|
|
import React, { Component } from 'react';
|
|
|
|
|
|
|
|
/**
|
2017-07-19 21:25:06 +00:00
|
|
|
* Abstract (base) class for a button in {@link Toolbar}.
|
2016-10-05 14:36:59 +00:00
|
|
|
*
|
|
|
|
* @abstract
|
|
|
|
*/
|
|
|
|
export default class AbstractToolbarButton extends Component {
|
2016-12-01 01:52:39 +00:00
|
|
|
/**
|
|
|
|
* AbstractToolbarButton component's property types.
|
|
|
|
*
|
|
|
|
* @static
|
|
|
|
*/
|
|
|
|
static propTypes = {
|
|
|
|
/**
|
2017-07-19 21:25:06 +00:00
|
|
|
* The name of the Icon of this {@code AbstractToolbarButton}.
|
2016-12-01 01:52:39 +00:00
|
|
|
*/
|
|
|
|
iconName: React.PropTypes.string,
|
|
|
|
|
|
|
|
/**
|
2017-07-19 21:25:06 +00:00
|
|
|
* The style of the Icon of this {@code AbstractToolbarButton}.
|
2016-12-01 01:52:39 +00:00
|
|
|
*/
|
|
|
|
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
|
|
|
|
|
|
|
/**
|
2017-07-19 21:25:06 +00:00
|
|
|
* {@code AbstractToolbarButton} styles.
|
2017-03-31 17:54:58 +00:00
|
|
|
*/
|
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
|
2017-06-02 02:01:50 +00:00
|
|
|
};
|
2016-10-05 14:36:59 +00:00
|
|
|
|
2017-07-19 21:26:27 +00:00
|
|
|
/**
|
|
|
|
* Initializes a new {@code AbstractToolbarButton} instance.
|
|
|
|
*
|
|
|
|
* @param {Object} props - The React {@code Component} props to initialize
|
|
|
|
* the new {@code AbstractToolbarButton} instance with.
|
|
|
|
*/
|
|
|
|
constructor(props) {
|
|
|
|
super(props);
|
|
|
|
|
|
|
|
// Bind event handlers so they are only bound once per instance.
|
|
|
|
this._onClick = this._onClick.bind(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handles clicking/pressing this {@code AbstractToolbarButton} by
|
|
|
|
* forwarding the event to the {@code onClick} prop of this instance if any.
|
|
|
|
*
|
|
|
|
* @protected
|
|
|
|
* @returns {*} The result returned by the invocation of the {@code onClick}
|
|
|
|
* prop of this instance if any.
|
|
|
|
*/
|
|
|
|
_onClick(...args) {
|
|
|
|
const { onClick } = this.props;
|
|
|
|
|
|
|
|
return onClick && onClick(...args);
|
|
|
|
}
|
|
|
|
|
2016-10-05 14:36:59 +00:00
|
|
|
/**
|
|
|
|
* Implements React's {@link Component#render()}.
|
|
|
|
*
|
|
|
|
* @inheritdoc
|
|
|
|
* @returns {ReactElement}
|
|
|
|
*/
|
|
|
|
render() {
|
|
|
|
return this._renderButton(this._renderIcon());
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2017-07-19 21:25:06 +00:00
|
|
|
* Renders the icon of this {@code AbstractToolbarButton}.
|
2016-10-05 14:36:59 +00:00
|
|
|
*
|
|
|
|
* @param {string|ReactClass} type - The React Component type of the icon to
|
|
|
|
* be rendered.
|
|
|
|
* @protected
|
2017-07-19 21:25:06 +00:00
|
|
|
* @returns {ReactElement} The icon of this {@code AbstractToolbarButton}.
|
2016-10-05 14:36:59 +00:00
|
|
|
*/
|
|
|
|
_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);
|
|
|
|
}
|
|
|
|
}
|