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

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. /* @flow */
  2. import Tooltip from '@atlaskit/tooltip';
  3. import React from 'react';
  4. import { Icon } from '../../../base/icons';
  5. import AbstractToolbarButton from '../AbstractToolbarButton';
  6. import type { Props as AbstractToolbarButtonProps }
  7. from '../AbstractToolbarButton';
  8. /**
  9. * The type of the React {@code Component} props of {@link ToolbarButton}.
  10. */
  11. type Props = AbstractToolbarButtonProps & {
  12. /**
  13. * The text to display in the tooltip.
  14. */
  15. tooltip: string,
  16. /**
  17. * From which direction the tooltip should appear, relative to the
  18. * button.
  19. */
  20. tooltipPosition: string
  21. };
  22. /**
  23. * Represents a button in the toolbar.
  24. *
  25. * @extends AbstractToolbarButton
  26. */
  27. class ToolbarButton extends AbstractToolbarButton<Props> {
  28. /**
  29. * Default values for {@code ToolbarButton} component's properties.
  30. *
  31. * @static
  32. */
  33. static defaultProps = {
  34. tooltipPosition: 'top'
  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. aria-label = { this.props.accessibilityLabel }
  48. className = 'toolbox-button'
  49. onClick = { this.props.onClick }>
  50. { this.props.tooltip
  51. ? <Tooltip
  52. content = { this.props.tooltip }
  53. position = { this.props.tooltipPosition }>
  54. { children }
  55. </Tooltip>
  56. : children }
  57. </div>
  58. );
  59. }
  60. /**
  61. * Renders the icon of this {@code ToolbarButton}.
  62. *
  63. * @inheritdoc
  64. */
  65. _renderIcon() {
  66. return (
  67. <div className = { `toolbox-icon ${this.props.toggled ? 'toggled' : ''}` }>
  68. <Icon src = { this.props.icon } />
  69. </div>
  70. );
  71. }
  72. }
  73. export default ToolbarButton;