Uptime Tracker Chart
uptime-tracker-chartuiReact mirror of @uipkge/uptime-tracker-chart — see the Vue registry item for the canonical description.
Installation
$pnpm dlx shadcn@latest add https://uipkge.dev/r/react/uptime-tracker-chart.json$npx shadcn@latest add https://uipkge.dev/r/react/uptime-tracker-chart.json$yarn dlx shadcn@latest add https://uipkge.dev/r/react/uptime-tracker-chart.json$bunx shadcn@latest add https://uipkge.dev/r/react/uptime-tracker-chart.jsonNamed registry:
npx shadcn@latest add @uipkge-react/uptime-tracker-chartInstalls to:components/ui/charts/uptime-tracker-chart/Examples
Loading interactive previews…
Loading interactive previews…
Props
| Name | Type / Values | Default | Required |
|---|---|---|---|
days | StatusDay[] | — | required |
height | number | string | 48 | optional |
gapGap between bars in px. Default 2. | number | 2 | optional |
roundedBar corner radius in px. Default 2. | number | 2 | optional |
showLegendShow the legend row with the computed uptime %. Default true. | boolean | true | optional |
className | string | — | optional |
ariaLabelAccessible name announced for the chart image. Defaults to "Chart". | string | — | optional |
Schema
Type aliases from this item's source — use them to shape the data you pass in.
StatusDayinterface StatusDay {
date: string
status: DayStatus
}npm dependencies
Used by
Files installed (3)
components/ui/charts/uptime-tracker-chart/UptimeTrackerChart.tsx3.1 kB
'use client' import * as React from 'react' import { ChartFrame } from '../shared' // UptimeTrackerChart — dependency-free status bars // ───────────────────────────────────────────────────────────────────────── export type DayStatus = 'up' | 'degraded' | 'down' | 'unknown' export interface StatusDay { date: string status: DayStatus } export interface UptimeTrackerChartProps { days: StatusDay[] height?: number | string /** Gap between bars in px. Default 2. */ gap?: number /** Bar corner radius in px. Default 2. */ rounded?: number /** Show the legend row with the computed uptime %. Default true. */ showLegend?: boolean className?: string /** Accessible name announced for the chart image. Defaults to "Chart". */ ariaLabel?: string } const COLORS: Record<DayStatus, string> = { up: 'var(--chart-2)', degraded: 'var(--chart-4)', down: 'var(--destructive)', unknown: 'var(--border)', } export const UptimeTrackerChart = React.forwardRef<HTMLDivElement, UptimeTrackerChartProps>( ({ days, height = 48, gap = 2, rounded = 2, showLegend = true, className, ariaLabel }, ref) => { const uptime = days.length ? `${((days.filter((d) => d.status === 'up').length / days.length) * 100).toFixed(1)}%` : '—' const summary = `${days.filter((d) => d.status === 'up').length} up, ${days.filter((d) => d.status === 'degraded').length} degraded, ${days.filter((d) => d.status === 'down').length} down days` return ( <ChartFrame ref={ref} height="auto" focusable className={className} ariaLabel={ariaLabel || `Uptime tracker: ${summary}`} > <div className="flex min-h-6 w-full items-stretch" style={{ height: typeof height === 'number' ? `${height}px` : height, gap: `${gap}px` }} > {days.map((d, i) => ( <div key={`${d.date}-${i}`} className="min-w-0 flex-1" style={{ background: COLORS[d.status], borderRadius: `${rounded}px` }} title={`${d.date} — ${d.status}`} /> ))} </div> {showLegend && ( <div className="mt-2 flex items-center gap-3 text-xs"> <span className="text-foreground font-semibold tabular-nums">{uptime} uptime</span> <span className="text-muted-foreground">{days.length} days</span> <span className="ml-auto flex items-center gap-2"> <span className="flex items-center gap-1"> <span className="size-2 rounded-[2px]" style={{ background: COLORS.up }} /> Up </span> <span className="flex items-center gap-1"> <span className="size-2 rounded-[2px]" style={{ background: COLORS.degraded }} /> Degraded </span> <span className="flex items-center gap-1"> <span className="size-2 rounded-[2px]" style={{ background: COLORS.down }} /> Down </span> </span> </div> )} </ChartFrame> ) }, ) UptimeTrackerChart.displayName = 'UptimeTrackerChart'components/ui/charts/uptime-tracker-chart/index.ts0.1 kB
export { UptimeTrackerChart, type UptimeTrackerChartProps, type StatusDay, type DayStatus } from './UptimeTrackerChart'components/ui/charts/shared.tsx3.7 kB
'use client' import * as React from 'react' import * as echartsCore from 'echarts/core' import { use } from 'echarts/core' import { CanvasRenderer } from 'echarts/renderers' import { LineChart as EChartsLineChart, BarChart as EChartsBarChart, PieChart as EChartsPieChart, ScatterChart as EChartsScatterChart, EffectScatterChart as EChartsEffectScatter, PictorialBarChart as EChartsPictorialBar, RadarChart as EChartsRadarChart, GaugeChart as EChartsGaugeChart, HeatmapChart as EChartsHeatmap, TreemapChart as EChartsTreemapChart, FunnelChart as EChartsFunnelChart, BoxplotChart as EChartsBoxplotChart, CandlestickChart as EChartsCandlestickChart, CustomChart as EChartsCustomChart, ChordChart as EChartsChordChart, MapChart as EChartsMapChart, GraphChart as EChartsGraphChart, ParallelChart as EChartsParallelChart, SankeyChart as EChartsSankeyChart, SunburstChart as EChartsSunburstChart, ThemeRiverChart, TreeChart as EChartsTreeChart, } from 'echarts/charts' import { GridComponent, PolarComponent, TooltipComponent, LegendComponent, MarkLineComponent, MarkAreaComponent, MarkPointComponent, GraphicComponent, RadarComponent, VisualMapComponent, CalendarComponent, DataZoomComponent, ParallelComponent, SingleAxisComponent, TitleComponent, } from 'echarts/components' import ReactECharts from 'echarts-for-react/esm/core' import { cn } from '@/lib/utils' export function heightToStyle(height: number | string): string { return /^\d+$/.test(String(height)) ? `${height}px` : String(height) } interface ChartFrameProps { height: number | string className?: string /** Apply the accessible role/tabindex/focus-ring chrome. Some chart * wrappers ship a bare `w-full` frame -- pass `false` for those. */ focusable?: boolean /** Accessible name for role="img". Defaults to "Chart". */ ariaLabel?: string } /** Shared `<div>` wrapper around the ECharts canvas. */ export const ChartFrame = React.forwardRef<HTMLDivElement, ChartFrameProps & { children: React.ReactNode }>( ({ height, className, focusable = true, ariaLabel, children }, ref) => ( <div ref={ref} role="img" aria-label={ariaLabel || 'Chart'} tabIndex={focusable ? 0 : undefined} style={{ height: heightToStyle(height) }} className={ focusable ? cn('focus-visible:ring-ring w-full focus-visible:ring-2 focus-visible:outline-none', className) : cn('w-full', className) } > {children} </div> ), ) ChartFrame.displayName = 'ChartFrame' /** ECharts canvas filling its parent frame. */ export function EChart({ option }: { option: any }) { return ( <ReactECharts echarts={echartsCore as any} option={option} notMerge lazyUpdate style={{ width: '100%', height: '100%' }} /> ) } export const echartsCoreModule = echartsCore // Register every chart type the wrappers need once at module load. use([ CanvasRenderer, EChartsLineChart, EChartsBarChart, EChartsPieChart, EChartsScatterChart, EChartsEffectScatter, EChartsPictorialBar, EChartsRadarChart, EChartsGaugeChart, EChartsHeatmap, EChartsTreemapChart, EChartsFunnelChart, EChartsBoxplotChart, EChartsCandlestickChart, EChartsCustomChart, EChartsChordChart, EChartsMapChart, EChartsGraphChart, EChartsParallelChart, EChartsSankeyChart, EChartsSunburstChart, ThemeRiverChart, EChartsTreeChart, GridComponent, PolarComponent, TooltipComponent, LegendComponent, MarkLineComponent, MarkAreaComponent, MarkPointComponent, GraphicComponent, RadarComponent, VisualMapComponent, CalendarComponent, DataZoomComponent, ParallelComponent, SingleAxisComponent, TitleComponent, ])
Raw manifest:https://uipkge.dev/r/react/uptime-tracker-chart.json