Files
supabase/apps/design-system/registry/default/example/metric-card.tsx
Ivan Vasilov 1cd1ebfc7f chire: Sort imports in all packages, cms, design-system and ui-library apps (#41610)
Sorted all imports in all packages, `cms`, `design-system` and
`ui-library` apps by running `pnpm format` on them.

All changes in this PR are done by the script.
2026-02-05 13:54:10 +01:00

54 lines
1.7 KiB
TypeScript

'use client'
import { useEffect, useState } from 'react'
import {
MetricCard,
MetricCardContent,
MetricCardDifferential,
MetricCardHeader,
MetricCardLabel,
MetricCardSparkline,
MetricCardValue,
} from 'ui-patterns/MetricCard'
export default function MetricsCardDemo() {
const [data, setData] = useState<Array<{ value: number; timestamp: string }>>([])
useEffect(() => {
const now = new Date()
setData(
Array.from({ length: 12 }, (_, i) => ({
value: Math.floor(4000 + i * 100 + (Math.random() * 2000 - 800)),
timestamp: new Date(now.getTime() - (11 - i) * 60 * 60 * 1000).toISOString(),
}))
)
}, [])
const averageValue = data.reduce((acc, curr) => acc + curr.value, 0) / data.length
const diff = data[data.length - 1]?.value - data[0]?.value || 0
const diffPercentage = (diff / averageValue) * 100
return (
<div className="w-1/2">
<MetricCard isLoading={!data.length}>
<MetricCardHeader href="https://www.supabase.io">
<MetricCardLabel tooltip="The number of active users over the last 24 hours">
Active Users
</MetricCardLabel>
</MetricCardHeader>
<MetricCardContent>
<MetricCardValue>
{averageValue.toLocaleString(undefined, { maximumFractionDigits: 0 })}
</MetricCardValue>
<MetricCardDifferential variant={diffPercentage > 0 ? 'positive' : 'negative'}>
{diffPercentage > 0 ? '+' : '-'}
{Math.abs(diffPercentage).toFixed(1)}%
</MetricCardDifferential>
</MetricCardContent>
<MetricCardSparkline data={data} dataKey="value" />
</MetricCard>
</div>
)
}