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.tsx 3.0KB

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