2018-10-30 05:02:23 +00:00
|
|
|
/* @flow */
|
|
|
|
|
2019-08-30 16:39:06 +00:00
|
|
|
import { Component } from 'react';
|
2016-10-05 14:36:59 +00:00
|
|
|
|
|
|
|
/**
|
2018-10-30 05:02:23 +00:00
|
|
|
* The type of the React {@code Component} props of
|
|
|
|
* {@link AbstractToolbarButton}.
|
2016-10-05 14:36:59 +00:00
|
|
|
*/
|
2018-10-30 05:02:23 +00:00
|
|
|
export type Props = {
|
|
|
|
|
2016-12-01 01:52:39 +00:00
|
|
|
/**
|
2018-10-30 05:02:23 +00:00
|
|
|
* A succinct description of what the button does. Used by accessibility
|
|
|
|
* tools and torture tests.
|
|
|
|
*/
|
|
|
|
accessibilityLabel: string,
|
|
|
|
|
|
|
|
/**
|
2019-08-30 16:39:06 +00:00
|
|
|
* The Icon of this {@code AbstractToolbarButton}.
|
2018-10-30 05:02:23 +00:00
|
|
|
*/
|
2019-08-30 16:39:06 +00:00
|
|
|
icon: Object,
|
2018-10-30 05:02:23 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The style of the Icon of this {@code AbstractToolbarButton}.
|
|
|
|
*/
|
|
|
|
iconStyle?: Object,
|
|
|
|
|
|
|
|
/**
|
|
|
|
* On click handler.
|
2016-12-01 01:52:39 +00:00
|
|
|
*/
|
2018-10-30 05:02:23 +00:00
|
|
|
onClick: Function,
|
2016-10-05 14:36:59 +00:00
|
|
|
|
2018-10-30 05:02:23 +00:00
|
|
|
/**
|
|
|
|
* {@code AbstractToolbarButton} styles.
|
|
|
|
*/
|
|
|
|
style?: Array<string> | Object,
|
|
|
|
|
2019-08-30 16:39:06 +00:00
|
|
|
/**
|
|
|
|
* An optional modifier to render the button toggled.
|
|
|
|
*/
|
|
|
|
toggled?: boolean,
|
|
|
|
|
2018-10-30 05:02:23 +00:00
|
|
|
/**
|
|
|
|
* The color underlaying the button.
|
|
|
|
*/
|
|
|
|
underlayColor?: any
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Abstract (base) class for a button in {@link Toolbar}.
|
|
|
|
*
|
|
|
|
* @abstract
|
|
|
|
*/
|
|
|
|
export default class AbstractToolbarButton<P: Props> extends Component<P> {
|
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.
|
|
|
|
*/
|
2018-10-30 05:02:23 +00:00
|
|
|
constructor(props: P) {
|
2017-07-19 21:26:27 +00:00
|
|
|
super(props);
|
|
|
|
|
|
|
|
// Bind event handlers so they are only bound once per instance.
|
|
|
|
this._onClick = this._onClick.bind(this);
|
|
|
|
}
|
|
|
|
|
2018-10-30 05:02:23 +00:00
|
|
|
_onClick: (any) => any;
|
|
|
|
|
2017-07-19 21:26:27 +00:00
|
|
|
/**
|
|
|
|
* 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());
|
|
|
|
}
|
|
|
|
|
2019-08-30 16:39:06 +00:00
|
|
|
_renderButton: (React$Element<any> | null) => React$Element<any>;
|
2018-10-30 05:02:23 +00:00
|
|
|
|
2019-08-30 16:39:06 +00:00
|
|
|
_renderIcon: () => React$Element<any> | null;
|
2016-10-05 14:36:59 +00:00
|
|
|
}
|