Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

ToolboxButtonWithPopup.tsx 3.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  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 the trigger for open/ close should be click or hover.
  55. */
  56. trigger?: 'hover' | 'click';
  57. /**
  58. * Whether or not the popover is visible.
  59. */
  60. visible: boolean;
  61. }
  62. /**
  63. * Displays the `ToolboxButtonWithIcon` component.
  64. *
  65. * @param {Object} props - Component's props.
  66. * @returns {ReactElement}
  67. */
  68. export default function ToolboxButtonWithPopup(props: IProps) {
  69. const {
  70. ariaControls,
  71. ariaExpanded,
  72. ariaHasPopup,
  73. ariaLabel,
  74. children,
  75. icon,
  76. iconDisabled,
  77. iconId,
  78. onPopoverClose,
  79. onPopoverOpen,
  80. popoverContent,
  81. styles,
  82. trigger,
  83. visible
  84. } = props;
  85. if (!icon) {
  86. return (
  87. <div
  88. className = 'settings-button-container'
  89. style = { styles }>
  90. <Popover
  91. content = { popoverContent }
  92. headingLabel = { ariaLabel }
  93. onPopoverClose = { onPopoverClose }
  94. onPopoverOpen = { onPopoverOpen }
  95. position = 'top'
  96. trigger = { trigger }
  97. visible = { visible }>
  98. {children}
  99. </Popover>
  100. </div>
  101. );
  102. }
  103. const iconProps: any = {};
  104. if (iconDisabled) {
  105. iconProps.className
  106. = 'settings-button-small-icon settings-button-small-icon--disabled';
  107. } else {
  108. iconProps.className = 'settings-button-small-icon';
  109. iconProps.role = 'button';
  110. iconProps.tabIndex = 0;
  111. iconProps.ariaControls = ariaControls;
  112. iconProps.ariaExpanded = ariaExpanded;
  113. iconProps.containerId = iconId;
  114. }
  115. return (
  116. <div
  117. className = 'settings-button-container'
  118. style = { styles }>
  119. {children}
  120. <div className = 'settings-button-small-icon-container'>
  121. <Popover
  122. content = { popoverContent }
  123. headingLabel = { ariaLabel }
  124. onPopoverClose = { onPopoverClose }
  125. onPopoverOpen = { onPopoverOpen }
  126. position = 'top'
  127. visible = { visible }>
  128. <Icon
  129. { ...iconProps }
  130. ariaHasPopup = { ariaHasPopup }
  131. ariaLabel = { ariaLabel }
  132. size = { 16 }
  133. src = { icon } />
  134. </Popover>
  135. </div>
  136. </div>
  137. );
  138. }