import React from 'react' import { Card, CardBody, CardHeader } from '@brudi/react-panel' import { twMerge } from 'tailwind-merge' import BarGauge from './metric-card-bar-gauge' import Footer from './metric-card-footer' // TODO replace CardProps once from @brudi/react-panel type CardProps = { className?: string hoverable?: boolean } export interface MetricCardProps extends CardProps { title: string | React.ReactNode value: number | React.ReactElement unit?: string locale?: string digits: number loading: boolean } const defaultProps = { className: '', locale: 'de-CH', digits: 2, loading: false } const Skeleton: React.FC<{ className?: string }> = ({ className }) => { return
} type NativeAttrs = Omit, keyof MetricCardProps> export type RowProps = MetricCardProps & typeof defaultProps & NativeAttrs const Container: React.FC> = ({ children, title, value, unit, className, locale, digits, loading, ...props }) => { const valueComponent = React.isValidElement(value) ? value : value.toLocaleString(locale, { maximumFractionDigits: digits }) return ( {title && {loading ? : title}}
{loading ? : valueComponent} {!loading && unit && {unit}}
{children &&
{children}
}
) } type MemoCardComponent

= React.NamedExoticComponent

& { BarGauge: typeof BarGauge Footer: typeof Footer } type ComponentProps = CardProps & Partial & Omit & NativeAttrs export default React.memo(Container) as MemoCardComponent