UNPKG

@adaptabletools/adaptable

Version:

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

29 lines (28 loc) 1.46 kB
import * as React from 'react'; import { Box, Flex } from 'rebass'; import { Tag } from '../../../../../components/Tag'; import { DEFAULT_INTEGER_DISPLAY_VALUE, DEFAULT_STRING_DISPLAY_VALUE, } from '../../../../../Utilities/Constants/GeneralConstants'; import { useAdaptable } from '../../../../AdaptableContext'; import { Badge } from '../../../../Components/Badge'; export const StyledColumnBadgePreview = ({ data }) => { const adaptable = useAdaptable(); const badgeStyle = data.BadgeStyle; if (!badgeStyle || badgeStyle.Badges.length === 0) { return React.createElement("div", null, "No Badges Defined"); } const value = adaptable.api.columnApi.getColumnDataTypeForColumnId(data.ColumnId) === 'number' ? DEFAULT_INTEGER_DISPLAY_VALUE : DEFAULT_STRING_DISPLAY_VALUE; return (React.createElement(Flex, { flexDirection: "column" }, badgeStyle.Badges.map((badge, index) => { let ruleString = 'No Rule'; if (badge.Predicate) { ruleString = adaptable.api.predicateApi.predicateToString(badge.Predicate); } if (badge.Expression) { ruleString = badge.Expression.BooleanExpression; } return (React.createElement(Box, { mb: 1, key: index }, React.createElement(Badge, { icon: badge.Icon, adaptableStyle: badge.Style, iconPosition: badge.IconPosition }, value), React.createElement(Tag, { ml: 2 }, ruleString))); }))); };