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.

ToolbarButtonV2.web.js 1.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. import Tooltip from '@atlaskit/tooltip';
  2. import PropTypes from 'prop-types';
  3. import React from 'react';
  4. import AbstractToolbarButton from './AbstractToolbarButton';
  5. /**
  6. * Represents a button in the toolbar.
  7. *
  8. * @extends AbstractToolbarButton
  9. */
  10. class ToolbarButtonV2 extends AbstractToolbarButton {
  11. /**
  12. * Default values for {@code ToolbarButtonV2} component's properties.
  13. *
  14. * @static
  15. */
  16. static defaultProps = {
  17. tooltipPosition: 'top'
  18. };
  19. /**
  20. * {@code ToolbarButtonV2} component's property types.
  21. *
  22. * @static
  23. */
  24. static propTypes = {
  25. ...AbstractToolbarButton.propTypes,
  26. /**
  27. * The text to display in the tooltip.
  28. */
  29. tooltip: PropTypes.string,
  30. /**
  31. * From which direction the tooltip should appear, relative to the
  32. * button.
  33. */
  34. tooltipPosition: PropTypes.string
  35. }
  36. /**
  37. * Renders the button of this {@code ToolbarButton}.
  38. *
  39. * @param {Object} children - The children, if any, to be rendered inside
  40. * the button. Presumably, contains the icon of this {@code ToolbarButton}.
  41. * @protected
  42. * @returns {ReactElement} The button of this {@code ToolbarButton}.
  43. */
  44. _renderButton(children) {
  45. return (
  46. <div
  47. className = 'toolbox-button'
  48. onClick = { this.props.onClick }>
  49. <Tooltip
  50. description = { this.props.tooltip }
  51. position = { this.props.tooltipPosition }>
  52. { children }
  53. </Tooltip>
  54. </div>
  55. );
  56. }
  57. /**
  58. * Renders the icon of this {@code ToolbarButton}.
  59. *
  60. * @inheritdoc
  61. */
  62. _renderIcon() {
  63. return (
  64. <div className = 'toolbox-icon'>
  65. <i className = { this.props.iconName } />
  66. </div>
  67. );
  68. }
  69. }
  70. export default ToolbarButtonV2;