Files
supabase/apps/design-system/registry/default/block/chart-composed-metrics.tsx
Ivan VasilovandJordi Enric 56de26fe22 chore: Migrate the monorepo to use Tailwind v4 (#45318)
This PR migrates the whole monorepo to use Tailwind v4:
- Removed `@tailwindcss/container-queries` plugin since it's included by
default in v4,
- Bump all instances of Tailwind to v4. Made minimal changes to the
shared config to remove non-supported features (`alpha` mentions),
- Migrate all apps to be compatible with v4 configs,
- Fix the `typography.css` import in 3 apps,
- Add missing rules which were included by default in v3,
- Run `pnpm dlx @tailwindcss/upgrade` on all apps, which renames a lot
of classes
- Rename all misnamed classes according to
https://tailwindcss.com/docs/upgrade-guide#renamed-utilities in all
apps.

---------

Co-authored-by: Jordi Enric <jordi.err@gmail.com>
2026-04-30 10:53:24 +00:00

101 lines
3.0 KiB
TypeScript

'use client'
import { ExternalLink } from 'lucide-react'
import { useEffect, useState } from 'react'
import { Skeleton } from 'ui'
import {
Chart,
ChartActions,
ChartCard,
ChartContent,
ChartHeader,
ChartMetric,
ChartSparkline,
} from 'ui-patterns/Chart'
export default function ChartComposedMetrics() {
const [data, setData] = useState<Array<{ value: number; timestamp: string }>>([])
const actions = [
{
label: 'Open in Logs Explorer',
onClick: () => {
alert('Ta da! You clicked me! 🎉')
},
icon: <ExternalLink size={12} />,
},
]
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="grid grid-cols-2 gap-6 w-full">
<Chart isLoading={!data.length}>
<ChartCard>
<ChartHeader className="pb-4" align="start">
<ChartMetric label="Slow Queries" value={0} />
<ChartActions actions={actions} />
</ChartHeader>
</ChartCard>
</Chart>
<Chart isLoading={!data.length}>
<ChartCard>
<ChartHeader className="pb-4" align="start">
<ChartMetric label="Sign Ups" value={127} />
<ChartActions actions={actions} />
</ChartHeader>
</ChartCard>
</Chart>
<Chart isLoading={!data.length}>
<ChartCard>
<ChartHeader align="start">
<ChartMetric
label="Active Users"
value={averageValue.toLocaleString(undefined, { maximumFractionDigits: 0 })}
diffValue={diffPercentage.toFixed(2) + '%'}
/>
<ChartActions actions={actions} />
</ChartHeader>
<ChartContent
className="p-0"
loadingState={<Skeleton className="w-full h-24 rounded-none mt-4" />}
>
<ChartSparkline data={data} dataKey="value" />
</ChartContent>
</ChartCard>
</Chart>
<Chart isLoading={!data.length}>
<ChartCard>
<ChartHeader align="start">
<ChartMetric
label="Active Users"
value={averageValue.toLocaleString(undefined, { maximumFractionDigits: 0 })}
diffValue={diffPercentage.toFixed(2) + '%'}
/>
<ChartActions actions={actions} />
</ChartHeader>
<ChartContent
className="p-0"
loadingState={<Skeleton className="w-full h-24 rounded-none mt-4" />}
>
<ChartSparkline data={data} dataKey="value" />
</ChartContent>
</ChartCard>
</Chart>
</div>
)
}