您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

ToolboxButtonWithPopup.tsx 2.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  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. * Aria label for the Icon.
  7. */
  8. ariaLabel?: string;
  9. /**
  10. * The decorated component (ToolboxButton).
  11. */
  12. children: React.ReactNode;
  13. /**
  14. * Icon of the button.
  15. */
  16. icon?: Function;
  17. /**
  18. * Flag used for disabling the small icon.
  19. */
  20. iconDisabled?: boolean;
  21. /**
  22. * Popover close callback.
  23. */
  24. onPopoverClose: Function;
  25. /**
  26. * Popover open callback.
  27. */
  28. onPopoverOpen: Function;
  29. /**
  30. * The content that will be displayed inside the popover.
  31. */
  32. popoverContent: React.ReactNode;
  33. /**
  34. * Additional styles.
  35. */
  36. styles?: Object;
  37. /**
  38. * Whether the trigger for open/ close should be click or hover.
  39. */
  40. trigger?: 'hover' | 'click';
  41. /**
  42. * Whether or not the popover is visible.
  43. */
  44. visible: boolean;
  45. }
  46. /**
  47. * Displays the `ToolboxButtonWithIcon` component.
  48. *
  49. * @param {Object} props - Component's props.
  50. * @returns {ReactElement}
  51. */
  52. export default function ToolboxButtonWithPopup(props: IProps) {
  53. const {
  54. ariaLabel,
  55. children,
  56. icon,
  57. iconDisabled,
  58. onPopoverClose,
  59. onPopoverOpen,
  60. popoverContent,
  61. styles,
  62. trigger,
  63. visible
  64. } = props;
  65. if (!icon) {
  66. return (
  67. <div
  68. className = 'settings-button-container'
  69. style = { styles }>
  70. <Popover
  71. content = { popoverContent }
  72. headingLabel = { ariaLabel }
  73. onPopoverClose = { onPopoverClose }
  74. onPopoverOpen = { onPopoverOpen }
  75. position = 'top'
  76. trigger = { trigger }
  77. visible = { visible }>
  78. {children}
  79. </Popover>
  80. </div>
  81. );
  82. }
  83. return (
  84. <div
  85. className = 'settings-button-container'
  86. style = { styles }>
  87. {children}
  88. <div className = 'settings-button-small-icon-container'>
  89. <Popover
  90. content = { popoverContent }
  91. headingLabel = { ariaLabel }
  92. onPopoverClose = { onPopoverClose }
  93. onPopoverOpen = { onPopoverOpen }
  94. position = 'top'
  95. visible = { visible }>
  96. <Icon
  97. alt = { ariaLabel }
  98. className = { `settings-button-small-icon ${iconDisabled
  99. ? 'settings-button-small-icon--disabled'
  100. : ''}` }
  101. size = { 16 }
  102. src = { icon } />
  103. </Popover>
  104. </div>
  105. </div>
  106. );
  107. }