NoDataPlaceholder.tsx 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. import { BarChart2 } from 'lucide-react'
  2. import { cn } from 'ui'
  3. import { ChartHeader } from './ChartHeader'
  4. import { useChartSize } from './Charts.utils'
  5. interface NoDataPlaceholderProps {
  6. title?: string
  7. attribute?: string
  8. format?: string | ((value: unknown) => string)
  9. message?: string
  10. description?: string
  11. className?: string
  12. size: Parameters<typeof useChartSize>[0]
  13. isFullHeight?: boolean
  14. titleTooltip?: string
  15. hideTotalPlaceholder?: boolean
  16. }
  17. const NoDataPlaceholder = ({
  18. attribute,
  19. message = 'No data to show',
  20. description,
  21. format,
  22. className = '',
  23. size,
  24. isFullHeight = false,
  25. titleTooltip,
  26. hideTotalPlaceholder = false,
  27. }: NoDataPlaceholderProps) => {
  28. const { minHeight } = useChartSize(size)
  29. return (
  30. <div className={cn(isFullHeight && 'h-full')}>
  31. {attribute !== undefined && (
  32. <ChartHeader
  33. title={attribute}
  34. format={format}
  35. highlightedValue={hideTotalPlaceholder ? undefined : 0}
  36. titleTooltip={titleTooltip}
  37. />
  38. )}
  39. <div
  40. className={cn(
  41. 'border-control flex grow w-full flex-col items-center justify-center space-y-2 border border-dashed text-center',
  42. isFullHeight && 'h-full',
  43. className
  44. )}
  45. // extra 20 px for the x ticks
  46. style={{ minHeight: minHeight + 20 }}
  47. >
  48. <BarChart2 size={20} className="text-border-stronger" />
  49. <div className="px-1">
  50. <p className="text-foreground-light text-xs">{message}</p>
  51. {description && <p className="text-foreground-lighter text-xs">{description}</p>}
  52. </div>
  53. </div>
  54. </div>
  55. )
  56. }
  57. export default NoDataPlaceholder