@adaptabletools/adaptable
Version:
Powerful AG Grid extension which provides advanced, cutting-edge functionality to meet all DataGrid requirements
61 lines (60 loc) • 3.07 kB
JavaScript
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
import * as React from 'react';
import { cn } from '../../../../lib/utils';
import { ACCESS_LEVEL_FULL, ACCESS_LEVEL_HIDDEN, } from '../../../../Utilities/Constants/GeneralConstants';
import { Box } from '../../../../components/Flex';
const Glyphicon = ({ glyph, style }) => {
return _jsx("span", { style: style, className: `glyphicon glyphicon-${glyph}` });
};
const baseClassName = 'ab-Button twa:text-current';
export class ButtonBase extends React.Component {
static defaultProps = {
overrideDisableButton: false,
toolTipAndText: '',
glyph: '',
displayMode: 'Glyph+Text',
transformGlyph: false,
accessLevel: ACCESS_LEVEL_FULL,
showDefaultStyle: false,
};
render() {
let isDisabled;
isDisabled = this.props.accessLevel == ACCESS_LEVEL_HIDDEN;
if (this.props.overrideDisableButton || this.props.disabled) {
isDisabled = true;
}
let text = this.props.children || this.props.toolTipAndText;
if (this.props.overrideText) {
text = this.props.overrideText;
}
let tooltip = this.props.toolTipAndText;
if (this.props.overrideTooltip) {
tooltip = this.props.overrideTooltip;
}
let hideToolTip = this.props.hideToolTip ? this.props.hideToolTip : false;
let content;
if (this.props.displayMode == 'Glyph') {
if (this.props.transformGlyph) {
content = _jsx(Glyphicon, { glyph: this.props.glyph, style: { transform: 'scale(-1, 1)' } });
}
else {
content = _jsx(Glyphicon, { glyph: this.props.glyph });
}
}
else if (this.props.displayMode == 'Text') {
content = _jsx("span", { children: text });
}
else if (this.props.displayMode == 'Glyph+Text') {
content = (_jsxs("div", { children: [_jsx(Glyphicon, { glyph: this.props.glyph }), " ", text] }));
}
else if (this.props.displayMode == 'Text+Glyph') {
content = (_jsxs("div", { children: [text, " ", _jsx(Glyphicon, { glyph: this.props.glyph })] }));
}
if (this.props.icon) {
content = (_jsxs(_Fragment, { children: [this.props.iconPosition === 'end' ? text : null, " ", _jsx(Glyphicon, { glyph: this.props.icon }), ' ', this.props.iconPosition !== 'end' ? text : null] }));
}
let button = (_jsx(Box, { ...this.props, as: "button", style: this.props.style, className: cn(baseClassName, `${baseClassName}--size-normal`, `${baseClassName}--style-normal`, isDisabled ? `${baseClassName}--disabled` : `${baseClassName}--enabled`, this.props.className), disabled: isDisabled, onClick: this.props.onClick, onMouseDown: this.props.onMouseDown || ((e) => e.preventDefault()), children: content }));
let buttonwithtooltip = _jsx("div", { children: button });
return hideToolTip ? button : buttonwithtooltip;
}
}