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

ToolboxButtonWithIcon.tsx 3.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. import React from 'react';
  2. import { NOTIFY_CLICK_MODE } from '../../../../toolbox/constants';
  3. import Icon from '../../../icons/components/Icon';
  4. import Tooltip from '../../../tooltip/components/Tooltip';
  5. interface IProps {
  6. /**
  7. * The id of the element this button icon controls.
  8. */
  9. ariaControls?: string;
  10. /**
  11. * Whether the element popup is expanded.
  12. */
  13. ariaExpanded?: boolean;
  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 button's key.
  24. */
  25. buttonKey?: string;
  26. /**
  27. * The decorated component (ToolboxButton).
  28. */
  29. children: React.ReactNode;
  30. /**
  31. * Icon of the button.
  32. */
  33. icon: Function;
  34. /**
  35. * Flag used for disabling the small icon.
  36. */
  37. iconDisabled: boolean;
  38. /**
  39. * The ID of the icon button.
  40. */
  41. iconId: string;
  42. /**
  43. * The tooltip used for the icon.
  44. */
  45. iconTooltip: string;
  46. /**
  47. * Notify mode for `toolbarButtonClicked` event -
  48. * whether to only notify or to also prevent button click routine.
  49. */
  50. notifyMode?: string;
  51. /**
  52. * Click handler for the small icon.
  53. */
  54. onIconClick: Function;
  55. /**
  56. * Keydown handler for icon.
  57. */
  58. onIconKeyDown?: Function;
  59. /**
  60. * Additional styles.
  61. */
  62. styles?: Object;
  63. }
  64. /**
  65. * Displays the `ToolboxButtonWithIcon` component.
  66. *
  67. * @param {Object} props - Component's props.
  68. * @returns {ReactElement}
  69. */
  70. export default function ToolboxButtonWithIcon(props: IProps) {
  71. const {
  72. children,
  73. icon,
  74. iconDisabled,
  75. iconTooltip,
  76. buttonKey,
  77. notifyMode,
  78. onIconClick,
  79. onIconKeyDown,
  80. styles,
  81. ariaLabel,
  82. ariaHasPopup,
  83. ariaControls,
  84. ariaExpanded,
  85. iconId
  86. } = props;
  87. const iconProps: any = {};
  88. let className = '';
  89. if (iconDisabled) {
  90. className
  91. = 'settings-button-small-icon settings-button-small-icon--disabled';
  92. } else {
  93. className = 'settings-button-small-icon';
  94. iconProps.onClick = (e: React.MouseEvent) => {
  95. if (typeof APP !== 'undefined' && notifyMode) {
  96. APP.API.notifyToolbarButtonClicked(
  97. buttonKey, notifyMode === NOTIFY_CLICK_MODE.PREVENT_AND_NOTIFY
  98. );
  99. }
  100. if (notifyMode !== NOTIFY_CLICK_MODE.PREVENT_AND_NOTIFY) {
  101. onIconClick(e);
  102. }
  103. };
  104. iconProps.onKeyDown = onIconKeyDown;
  105. iconProps.role = 'button';
  106. iconProps.tabIndex = 0;
  107. iconProps.ariaControls = ariaControls;
  108. iconProps.ariaExpanded = ariaExpanded;
  109. iconProps.containerId = iconId;
  110. }
  111. return (
  112. <div
  113. className = 'settings-button-container'
  114. style = { styles }>
  115. {children}
  116. <div>
  117. <Tooltip
  118. containerClassName = { className }
  119. content = { iconTooltip }
  120. position = 'top'>
  121. <Icon
  122. { ...iconProps }
  123. ariaHasPopup = { ariaHasPopup }
  124. ariaLabel = { ariaLabel }
  125. size = { 16 }
  126. src = { icon } />
  127. </Tooltip>
  128. </div>
  129. </div>
  130. );
  131. }