mirror of
https://github.com/supabase/supabase.git
synced 2026-12-06 08:29:01 +00:00
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.
59 lines
1.8 KiB
TypeScript
59 lines
1.8 KiB
TypeScript
'use client'
|
|
|
|
import { User2 } from 'lucide-react'
|
|
import { useEffect, useState } from 'react'
|
|
import {
|
|
MetricCard,
|
|
MetricCardContent,
|
|
MetricCardDifferential,
|
|
MetricCardHeader,
|
|
MetricCardIcon,
|
|
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">
|
|
<MetricCardIcon>
|
|
<User2 size={14} strokeWidth={1.5} />
|
|
</MetricCardIcon>
|
|
<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>
|
|
)
|
|
}
|