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.

ToolboxButtonWithIconPopup.js 3.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. // @flow
  2. import React from 'react';
  3. import { Icon } from '../../../icons';
  4. import Popover from '../../../popover/components/Popover.web';
  5. type Props = {
  6. /**
  7. * Whether the element popup is expanded.
  8. */
  9. ariaExpanded?: boolean,
  10. /**
  11. * The id of the element this button icon controls.
  12. */
  13. ariaControls?: string,
  14. /**
  15. * Whether the element has a popup.
  16. */
  17. ariaHasPopup?: boolean,
  18. /**
  19. * Aria label for the Icon.
  20. */
  21. ariaLabel?: string,
  22. /**
  23. * The decorated component (ToolboxButton).
  24. */
  25. children: React$Node,
  26. /**
  27. * Icon of the button.
  28. */
  29. icon: Function,
  30. /**
  31. * Flag used for disabling the small icon.
  32. */
  33. iconDisabled: boolean,
  34. /**
  35. * The ID of the icon button.
  36. */
  37. iconId: string,
  38. /**
  39. * Popover close callback.
  40. */
  41. onPopoverClose: Function,
  42. /**
  43. * Popover open callback.
  44. */
  45. onPopoverOpen: Function,
  46. /**
  47. * The content that will be displayed inside the popover.
  48. */
  49. popoverContent: React$Node,
  50. /**
  51. * Additional styles.
  52. */
  53. styles?: Object,
  54. /**
  55. * Whether or not the popover is visible.
  56. */
  57. visible: boolean
  58. };
  59. declare var APP: Object;
  60. /**
  61. * Displays the `ToolboxButtonWithIcon` component.
  62. *
  63. * @param {Object} props - Component's props.
  64. * @returns {ReactElement}
  65. */
  66. export default function ToolboxButtonWithIconPopup(props: Props) {
  67. const {
  68. ariaControls,
  69. ariaExpanded,
  70. ariaHasPopup,
  71. ariaLabel,
  72. children,
  73. icon,
  74. iconDisabled,
  75. iconId,
  76. onPopoverClose,
  77. onPopoverOpen,
  78. popoverContent,
  79. styles,
  80. visible
  81. } = props;
  82. const iconProps = {};
  83. if (iconDisabled) {
  84. iconProps.className
  85. = 'settings-button-small-icon settings-button-small-icon--disabled';
  86. } else {
  87. iconProps.className = 'settings-button-small-icon';
  88. iconProps.role = 'button';
  89. iconProps.tabIndex = 0;
  90. iconProps.ariaControls = ariaControls;
  91. iconProps.ariaExpanded = ariaExpanded;
  92. iconProps.containerId = iconId;
  93. }
  94. return (
  95. <div
  96. className = 'settings-button-container'
  97. styles = { styles }>
  98. {children}
  99. <div className = 'settings-button-small-icon-container'>
  100. <Popover
  101. content = { popoverContent }
  102. headingLabel = { ariaLabel }
  103. onPopoverClose = { onPopoverClose }
  104. onPopoverOpen = { onPopoverOpen }
  105. position = 'top'
  106. visible = { visible }>
  107. <Icon
  108. { ...iconProps }
  109. ariaHasPopup = { ariaHasPopup }
  110. ariaLabel = { ariaLabel }
  111. size = { 16 }
  112. src = { icon } />
  113. </Popover>
  114. </div>
  115. </div>
  116. );
  117. }