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.

ToolbarButton.js 2.0KB

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