123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130 |
- // @flow
-
- import React from 'react';
-
- import { Icon } from '../../../icons';
- import { Tooltip } from '../../../tooltip';
-
- type Props = {
-
- /**
- * The decorated component (ToolboxButton).
- */
- children: React$Node,
-
- /**
- * Icon of the button.
- */
- icon: Function,
-
- /**
- * Flag used for disabling the small icon.
- */
- iconDisabled: boolean,
-
- /**
- * Click handler for the small icon.
- */
- onIconClick: Function,
-
- /**
- * The tooltip used for the icon.
- */
- iconTooltip: string,
-
- /**
- * Additional styles.
- */
- styles?: Object,
-
- /**
- * aria label for the Icon.
- */
- ariaLabel?: string,
-
- /**
- * whether the element has a popup
- */
- ariaHasPopup?: boolean,
-
- /**
- * whether the element popup is expanded
- */
- ariaExpanded?: boolean,
-
- /**
- * The id of the element this button icon controls
- */
- ariaControls?: string,
-
- /**
- * keydown handler for icon.
- */
- onIconKeyDown?: Function,
-
- /**
- * The ID of the icon button
- */
- iconId: string
- };
-
- /**
- * Displays the `ToolboxButtonWithIcon` component.
- *
- * @param {Object} props - Component's props.
- * @returns {ReactElement}
- */
- export default function ToolboxButtonWithIcon(props: Props) {
- const {
- children,
- icon,
- iconDisabled,
- iconTooltip,
- onIconClick,
- onIconKeyDown,
- styles,
- ariaLabel,
- ariaHasPopup,
- ariaControls,
- ariaExpanded,
- iconId
- } = props;
-
- const iconProps = {};
-
- if (iconDisabled) {
- iconProps.className
- = 'settings-button-small-icon settings-button-small-icon--disabled';
- } else {
- iconProps.className = 'settings-button-small-icon';
- iconProps.onClick = onIconClick;
- iconProps.onKeyDown = onIconKeyDown;
- iconProps.role = 'button';
- iconProps.tabIndex = 0;
- iconProps.ariaControls = ariaControls;
- iconProps.ariaExpanded = ariaExpanded;
- iconProps.containerId = iconId;
- }
-
-
- return (
- <div
- className = 'settings-button-container'
- styles = { styles }>
- {children}
-
- <div>
- <Tooltip
- content = { iconTooltip }
- position = 'top'>
- <Icon
- { ...iconProps }
- ariaHasPopup = { ariaHasPopup }
- ariaLabel = { ariaLabel }
- size = { 9 }
- src = { icon } />
- </Tooltip>
- </div>
- </div>
- );
- }
|