You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

AbstractToolbarButton.js 1.4KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. import React, { Component } from 'react';
  2. /**
  3. * Abstract (base) class for a button in Toolbar.
  4. *
  5. * @abstract
  6. */
  7. export default class AbstractToolbarButton extends Component {
  8. /**
  9. * Implements React's {@link Component#render()}.
  10. *
  11. * @inheritdoc
  12. * @returns {ReactElement}
  13. */
  14. render() {
  15. return this._renderButton(this._renderIcon());
  16. }
  17. /**
  18. * Renders the icon of this Toolbar button.
  19. *
  20. * @param {string|ReactClass} type - The React Component type of the icon to
  21. * be rendered.
  22. * @protected
  23. * @returns {ReactElement} The icon of this Toolbar button.
  24. */
  25. _renderIcon(type) {
  26. const props = {};
  27. 'iconName' in this.props && (props.name = this.props.iconName);
  28. 'iconStyle' in this.props && (props.style = this.props.iconStyle);
  29. return React.createElement(type, props);
  30. }
  31. }
  32. /**
  33. * AbstractToolbarButton component's property types.
  34. *
  35. * @static
  36. */
  37. AbstractToolbarButton.propTypes = {
  38. /**
  39. * The name of the Icon of this AbstractToolbarButton.
  40. */
  41. iconName: React.PropTypes.string,
  42. /**
  43. * The style of the Icon of this AbstractToolbarButton.
  44. */
  45. iconStyle: React.PropTypes.object,
  46. onClick: React.PropTypes.func,
  47. style:
  48. React.PropTypes.oneOfType([
  49. React.PropTypes.array,
  50. React.PropTypes.object
  51. ]),
  52. underlayColor: React.PropTypes.any
  53. };