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.5KB

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