UNPKG

@adaptabletools/adaptable-cjs

Version:

Powerful data-agnostic HTML5 AG Grid extension which provides advanced, cutting-edge functionality to meet all DataGrid requirements

35 lines (34 loc) 2.24 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.CustomDashboardButton = void 0; const tslib_1 = require("tslib"); const React = tslib_1.__importStar(require("react")); const react_1 = require("react"); const SimpleButton_1 = tslib_1.__importDefault(require("../../components/SimpleButton")); const kebabCase_1 = tslib_1.__importDefault(require("lodash/kebabCase")); const CustomDashboardButton = (props) => { const { button } = props; const [componentRevision, setComponentRevision] = (0, react_1.useState)(1); // TODO: variants of this mapping are present in several places (just search for api.internalApi.getStyleForButton() usages) // with the next opportunity we should abstract it const dashboardContext = { ...props.api.internalApi.buildBaseContext(), dashboardState: props.api.dashboardApi.getDashboardState(), }; const buttonIcon = props.api.internalApi.getIconForButton(button, dashboardContext); let buttonStyle = props.api.internalApi.getStyleForButton(button, dashboardContext); let buttonLabel = props.api.internalApi.getLabelForButton(button, dashboardContext); let buttonTooltip = props.api.internalApi.getTooltipForButton(button, dashboardContext); if (button.hidden && button.hidden(button, dashboardContext)) { return null; } const disabled = button.disabled && button.disabled(button, dashboardContext); return (React.createElement(SimpleButton_1.default, { key: buttonLabel, "aria-label": buttonLabel, variant: buttonStyle && buttonStyle.variant ? buttonStyle.variant : 'text', tone: buttonStyle && buttonStyle.tone ? buttonStyle.tone : 'none', className: `ab-DashboardToolbar__Home__${(0, kebabCase_1.default)(buttonLabel)} ${buttonStyle?.className || ''}`, tooltip: buttonTooltip, icon: buttonIcon, disabled: disabled || props.accessLevel == 'ReadOnly', onClick: () => { button.onClick?.(button, dashboardContext); setTimeout(() => { // mutate state to force a re-rendering setComponentRevision(componentRevision + 1); }, 16); }, accessLevel: 'Full' }, buttonLabel)); }; exports.CustomDashboardButton = CustomDashboardButton;