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 2.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  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. * aria label for the Icon.
  32. */
  33. ariaLabel?: string,
  34. /**
  35. * whether the element has a popup
  36. */
  37. ariaHasPopup?: boolean,
  38. /**
  39. * whether the element popup is expanded
  40. */
  41. ariaExpanded?: boolean,
  42. /**
  43. * The id of the element this button icon controls
  44. */
  45. ariaControls?: string,
  46. /**
  47. * keydown handler for icon.
  48. */
  49. onIconKeyDown?: Function,
  50. /**
  51. * The ID of the icon button
  52. */
  53. iconId: string
  54. };
  55. /**
  56. * Displays the `ToolboxButtonWithIcon` component.
  57. *
  58. * @param {Object} props - Component's props.
  59. * @returns {ReactElement}
  60. */
  61. export default function ToolboxButtonWithIcon(props: Props) {
  62. const {
  63. children,
  64. icon,
  65. iconDisabled,
  66. iconTooltip,
  67. onIconClick,
  68. onIconKeyDown,
  69. styles,
  70. ariaLabel,
  71. ariaHasPopup,
  72. ariaControls,
  73. ariaExpanded,
  74. iconId
  75. } = props;
  76. const iconProps = {};
  77. if (iconDisabled) {
  78. iconProps.className
  79. = 'settings-button-small-icon settings-button-small-icon--disabled';
  80. } else {
  81. iconProps.className = 'settings-button-small-icon';
  82. iconProps.onClick = onIconClick;
  83. iconProps.onKeyDown = onIconKeyDown;
  84. iconProps.role = 'button';
  85. iconProps.tabIndex = 0;
  86. iconProps.ariaControls = ariaControls;
  87. iconProps.ariaExpanded = ariaExpanded;
  88. iconProps.containerId = iconId;
  89. }
  90. return (
  91. <div
  92. className = 'settings-button-container'
  93. styles = { styles }>
  94. {children}
  95. <div>
  96. <Tooltip
  97. content = { iconTooltip }
  98. position = 'top'>
  99. <Icon
  100. { ...iconProps }
  101. ariaHasPopup = { ariaHasPopup }
  102. ariaLabel = { ariaLabel }
  103. size = { 9 }
  104. src = { icon } />
  105. </Tooltip>
  106. </div>
  107. </div>
  108. );
  109. }