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.

ToolboxButtonWithIcon.js 1.7KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. // @flow
  2. import React from 'react';
  3. import { Icon } from '../../../icons';
  4. import { Tooltip } from '../../../tooltip';
  5. type Props = {
  6. /**
  7. * The decorated component (ToolboxButton).
  8. */
  9. children: React$Node,
  10. /**
  11. * Icon of the button.
  12. */
  13. icon: Function,
  14. /**
  15. * Flag used for disabling the small icon.
  16. */
  17. iconDisabled: boolean,
  18. /**
  19. * Click handler for the small icon.
  20. */
  21. onIconClick: Function,
  22. /**
  23. * The tooltip used for the icon.
  24. */
  25. iconTooltip: string,
  26. /**
  27. * Additional styles.
  28. */
  29. styles?: Object,
  30. };
  31. /**
  32. * Displays the `ToolboxButtonWithIcon` component.
  33. *
  34. * @param {Object} props - Component's props.
  35. * @returns {ReactElement}
  36. */
  37. export default function ToolboxButtonWithIcon(props: Props) {
  38. const {
  39. children,
  40. icon,
  41. iconDisabled,
  42. iconTooltip,
  43. onIconClick,
  44. styles
  45. } = props;
  46. const iconProps = {};
  47. if (iconDisabled) {
  48. iconProps.className
  49. = 'settings-button-small-icon settings-button-small-icon--disabled';
  50. } else {
  51. iconProps.className = 'settings-button-small-icon';
  52. iconProps.onClick = onIconClick;
  53. }
  54. return (
  55. <div
  56. className = 'settings-button-container'
  57. styles = { styles }>
  58. {children}
  59. <div>
  60. <Tooltip
  61. content = { iconTooltip }
  62. position = 'top'>
  63. <Icon
  64. { ...iconProps }
  65. size = { 9 }
  66. src = { icon } />
  67. </Tooltip>
  68. </div>
  69. </div>
  70. );
  71. }