Files
supabase/apps/design-system/registry/default/block/chart-composed-basic.tsx
kemal.earth ec6f55c00b feat(design-system): charts defrag (#41026)
* feat: remove unused chart files

* chore: regenerate registry

* fix: logs bar chart positioning

* feat: add charts page to ui patterns

* chore: alphabetise ui patterns nav

* feat: base composable chart components

* chore: prettier for charts.mdx

* chore: slowly putting example together

* feat: add chart header components

* feat: add chart content wrapper

* feat: add recharts to source

* feat: add empty state handling

* feat: add loading state for content area as well

* feat: starting on actual recharts pieces

* feat: add basic api to documentation

* feat: add disabled state too

* feat: couple of basic chart types

* chore: tidy up for now

* feat: modify eslint rules for our demo files

* fix: recharts logo colour on light mode

* feat: absorb metric card into chart

* feat: align prop for chart header

* feat: refactor chart content

* feat: example with table

* chore: format for prettier

* fix: pkg lock merge conflict

* fix: small bits from danny

* feat: add link in ui pattern intro to charts

* chore: remove charts link from atoms

* chore: update metric padding to saxon suggestion

* feat: table footer overrides by default

* feat: update api props in table

* chore: formating
2025-12-10 13:10:18 +00:00

123 lines
3.1 KiB
TypeScript

'use client'
import {
Chart,
ChartActions,
ChartCard,
ChartContent,
ChartHeader,
ChartTitle,
ChartEmptyState,
ChartLoadingState,
ChartBar,
ChartLine,
} from 'ui-patterns/Chart'
import { BarChart2, ExternalLink } from 'lucide-react'
import { useState, useEffect } from 'react'
export default function ComposedChartBasic() {
const [isLoading, setIsLoading] = useState(true)
const actions = [
{
label: 'Open in Logs Explorer',
onClick: () => {
alert('Ta da! You clicked me! 🎉')
},
icon: <ExternalLink size={12} />,
},
]
const data = Array.from({ length: 46 }, (_, i) => {
const date = new Date()
date.setMinutes(date.getMinutes() - i * 5) // Each point 5 minutes apart
return {
timestamp: date.toISOString(),
standard_score: Math.floor(Math.random() * 100),
}
}).reverse()
useEffect(() => {
setTimeout(() => {
setIsLoading(false)
}, 1000)
}, [])
return (
<div className="flex flex-col gap-6 w-8/12">
<Chart isLoading={isLoading}>
<ChartCard>
<ChartHeader>
<ChartTitle tooltip="This is a tooltip">Standard Bar Chart</ChartTitle>
<ChartActions actions={actions} />
</ChartHeader>
<ChartContent
isEmpty={data.length === 0}
emptyState={
<ChartEmptyState
icon={<BarChart2 size={16} />}
title="No data to show"
description="It may take up to 24 hours for data to refresh"
/>
}
loadingState={<ChartLoadingState />}
>
<div className="h-40">
<ChartBar
data={data}
dataKey="standard_score"
showGrid={false}
showYAxis={true}
YAxisProps={{
tickFormatter: (value) => `${value}k`,
width: 80,
}}
isFullHeight={true}
/>
</div>
</ChartContent>
</ChartCard>
</Chart>
<Chart isLoading={isLoading}>
<ChartCard>
<ChartHeader>
<ChartTitle tooltip="This is a tooltip">Standard Line Chart</ChartTitle>
<ChartActions actions={actions} />
</ChartHeader>
<ChartContent
isEmpty={data.length === 0}
emptyState={
<ChartEmptyState
icon={<BarChart2 size={16} />}
title="No data to show"
description="It may take up to 24 hours for data to refresh"
/>
}
loadingState={<ChartLoadingState />}
>
<div className="h-40">
<ChartLine
data={data}
dataKey="standard_score"
showGrid={true}
showYAxis={true}
YAxisProps={{
tickFormatter: (value) => `${value}k`,
width: 80,
}}
isFullHeight={true}
/>
</div>
</ChartContent>
</ChartCard>
</Chart>
</div>
)
}