import React, { memo, useEffect, useState } from "react"; import { Box, Card, CardContent, Typography, Chip } from "@mui/material"; import { useContext } from "react"; import { DataContext } from "../context/Context"; import ComponentWrapper from "../common/ComponentWrapper"; import { getFieldName } from "../permissions/getFieldName"; import { withJsonFormsControlProps } from "@jsonforms/react"; import { inputProps } from "../interface/inputfieldProps"; import { getComponentProps } from "../common/getComponentProps"; import TrendingUpIcon from '@mui/icons-material/TrendingUp'; import TrendingDownIcon from '@mui/icons-material/TrendingDown'; import ArrowForwardIcon from '@mui/icons-material/ArrowForward' const MetricCard = memo(function ({ uischema, path, data, schema, rootSchema, }: inputProps) { const uischemaData = uischema?.config?.main; const { pageName, permissions, theme, additionalIcons } = useContext(DataContext); const fieldName = getFieldName(path); const [imageSrc, setImageSrc] = useState(data ? data?.url : uischemaData?.url); const label = data?.label || uischemaData?.label || ""; const value = data?.cardValue || uischemaData?.cardValue || "--"; const description = data?.description || uischemaData?.description; const growthRate = data?.growthRate || uischemaData?.growthRate; const color = uischemaData?.color || "#9CA3AF"; useEffect(() => { setImageSrc(data ? data?.url : uischemaData?.url); }, [data, uischemaData?.url]); const GrowthIcon ={ positive: TrendingUpIcon, negative: TrendingDownIcon }[growthRate] return ( {label} {value} {description && ( : undefined} label={description} size="small" sx={{ backgroundColor: color, color: 'white', fontWeight: 600, fontSize: '0.75rem', height: 28, borderRadius: 2, '& .MuiChip-icon': { color: 'white', marginLeft: '8px', }, ...uischema?.config?.style?.descriptionStyle, }} /> )} ); }); export default withJsonFormsControlProps(MetricCard);