@adaptabletools/adaptable
Version:
Powerful AG Grid extension which provides advanced, cutting-edge functionality to meet all DataGrid requirements
48 lines (47 loc) • 2.25 kB
JavaScript
import { jsx as _jsx } from "react/jsx-runtime";
import { getBarStyleCellTextSlotPresence, hasBarStyleCellTextConfigured, resolveBarStyleCellTextSlots, } from '../../../../../Utilities/Helpers/StyledColumns/BarStylesHelper';
import { Box, Flex } from '../../../../../components/Flex';
const HORIZONTAL_ORDER = ['Left', 'Center', 'Right'];
const HORIZONTAL_JUSTIFY = {
Left: 'flex-start',
Center: 'center',
Right: 'flex-end',
};
const HORIZONTAL_TEXT_ALIGN = {
Left: 'left',
Center: 'center',
Right: 'right',
};
const CellTextRow = ({ className, style, slots }) => (_jsx(Flex, { className: className, alignItems: "center", style: { ...style, width: '100%', gap: 4 }, children: HORIZONTAL_ORDER.map((horizontal) => {
const slot = slots.find((s) => s.horizontal === horizontal);
return (_jsx(Box, { className: "twa:truncate", style: {
flex: 1,
minWidth: 0,
display: 'flex',
justifyContent: HORIZONTAL_JUSTIFY[horizontal],
alignItems: 'center',
textAlign: HORIZONTAL_TEXT_ALIGN[horizontal],
}, children: slot?.text ?? '' }, horizontal));
}) }));
export const BarStyleCellTextPreview = ({ className, style, cellTextProperties, labels, mergedOverlayClassName, vertical }) => {
if (!labels.cellValue && !labels.percentage) {
return null;
}
const slots = resolveBarStyleCellTextSlots(cellTextProperties, labels);
if (!slots.length) {
return null;
}
const bandSlots = vertical ? slots.filter((s) => s.vertical === vertical) : slots;
if (!bandSlots.length) {
return null;
}
const usedClassName = vertical === 'Merged' ? mergedOverlayClassName ?? className : className;
return (_jsx(CellTextRow, { className: usedClassName, style: style, slots: bandSlots.map((s) => ({ horizontal: s.horizontal, text: s.text })) }));
};
export const shouldShowBarStyleCellTextOutsideBar = (cellTextProperties, hasCellText) => {
if (!hasCellText || !hasBarStyleCellTextConfigured(cellTextProperties)) {
return false;
}
const { hasAbove, hasBelow } = getBarStyleCellTextSlotPresence(cellTextProperties);
return hasAbove || hasBelow;
};