Implement ToolboxItem features: disabled, tooltip with label

This commit is contained in:
Bettenbuk Zoltan 2018-06-28 15:25:58 +02:00 committed by Saúl Ibarra Corretgé
parent baa2c217de
commit e59761baa2
4 changed files with 31 additions and 20 deletions

View File

@ -120,6 +120,12 @@
height: 22px;
padding: 5px 12px;
div {
display: flex;
flex-direction: row;
align-items: center;
}
&:hover {
background: #313D52;
}

View File

@ -114,7 +114,7 @@ export default class AbstractButton<P: Props, S: *> extends Component<P, S> {
*
* @abstract
*/
tooltip: string;
tooltip: ?string;
/**
* Initializes a new {@code AbstractButton} instance.

View File

@ -75,7 +75,7 @@ export type Props = {
/**
* The text to display in the tooltip. Used only on web.
*/
tooltip: string,
tooltip: ?string,
/**
* From which direction the tooltip should appear, relative to the

View File

@ -21,23 +21,40 @@ export default class ToolboxItem extends AbstractToolboxItem<Props> {
*/
_renderItem() {
const {
disabled,
onClick,
showLabel
showLabel,
tooltipPosition
} = this.props;
const className = showLabel ? 'overflow-menu-item' : 'toolbox-button';
const props = {
'aria-label': this.accessibilityLabel,
className: showLabel ? 'overflow-menu-item' : 'toolbox-button',
onClick
className: className + (disabled ? ' disabled' : ''),
onClick: disabled ? undefined : onClick
};
const elementType = showLabel ? 'li' : 'div';
const useTooltip = this.tooltip && this.tooltip.length > 0;
// eslint-disable-next-line no-extra-parens
const children = (
let children = (
<Fragment>
{ this._renderIcon() }
{ showLabel && this.label }
{ showLabel && <span>
{ this.label }
</span> }
</Fragment>
);
if (useTooltip) {
// eslint-disable-next-line no-extra-parens
children = (
<Tooltip
content = { this.tooltip }
position = { tooltipPosition }>
{ children }
</Tooltip>
);
}
return React.createElement(elementType, props, children);
}
@ -48,25 +65,13 @@ export default class ToolboxItem extends AbstractToolboxItem<Props> {
* @returns {ReactElement}
*/
_renderIcon() {
const { iconName, tooltipPosition, showLabel } = this.props;
const { iconName, showLabel } = this.props;
const icon = <i className = { iconName } />;
const elementType = showLabel ? 'span' : 'div';
const className
= showLabel ? 'overflow-menu-item-icon' : 'toolbox-icon';
const iconWrapper
= React.createElement(elementType, { className }, icon);
const tooltip = this.tooltip;
const useTooltip = !showLabel && tooltip && tooltip.length > 0;
if (useTooltip) {
return (
<Tooltip
content = { tooltip }
position = { tooltipPosition }>
{ iconWrapper }
</Tooltip>
);
}
return iconWrapper;
}