Skip to content

Every analytics tool wants a subscription. And your data. I built Twiligent instead. YouTube stats. Instagram stats. One dashboard. Runs locally on your machine.

1.1 KB
Raw Blame
import React from 'react';
import SurfaceBox from './SurfaceBox';
import ChartFigure from './ChartFigure';

// Titled chart container. Pass `empty` to show a quiet message instead of an empty plot.
export interface ChartPanelProps {
  title?: React.ReactNode;
  subheader?: React.ReactNode;
  // read by screen readers in place of the plot
  description?: string;
  height?: number;
  empty?: boolean;
  emptyMessage?: React.ReactNode;
  className?: string;
  children: React.ReactNode;
}

export default function ChartPanel({ title, subheader, description, height = 280, empty = false, emptyMessage = 'Not enough data yet', className, children }: ChartPanelProps) {
  return (
    <SurfaceBox title={title} subheader={subheader} className={className} contentClassName="px-3 pt-4 pb-3">
      {empty ? (
        <p className="flex items-center justify-center text-small text-ink-faint" style={{ height }}>{emptyMessage}</p>
      ) : (
        <ChartFigure label={typeof title === 'string' ? title : undefined} description={description}>{children}</ChartFigure>
      )}
    </SurfaceBox>
  );
}