CountdownTimerRadial.tsx 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. import { PolarGrid, RadialBar, RadialBarChart } from 'recharts'
  2. import { ChartConfig, ChartContainer } from 'ui'
  3. interface CountdownTimerRadialProps {
  4. progress: number
  5. }
  6. const chartConfig = {
  7. timeRemaining: {
  8. label: 'timeRemaining',
  9. color: 'hsl(var(--warning-default))',
  10. },
  11. hand: {
  12. label: 'hand',
  13. color: 'hsl(var(--warning-default))',
  14. },
  15. } satisfies ChartConfig
  16. const CountdownTimerRadial = ({ progress }: CountdownTimerRadialProps) => {
  17. return (
  18. <div className="relative w-12 h-12">
  19. {/* timer ring */}
  20. <ChartContainer config={chartConfig} className="absolute w-12 h-12">
  21. <RadialBarChart
  22. data={[{ timeRemaining: 100, fill: 'var(--color-timeRemaining)' }]}
  23. startAngle={90}
  24. endAngle={90 - (progress * 360) / 100}
  25. innerRadius={21}
  26. outerRadius={14}
  27. >
  28. <PolarGrid
  29. gridType="circle"
  30. radialLines={false}
  31. stroke="none"
  32. className="first:fill-foreground-muted/50 last:fill-background-200"
  33. polarRadius={[16, 11]}
  34. />
  35. <RadialBar dataKey="timeRemaining" cornerRadius={2} />
  36. </RadialBarChart>
  37. </ChartContainer>
  38. <ChartContainer config={chartConfig} className="absolute top-1 left-1 w-10 h-10">
  39. <RadialBarChart
  40. data={[{ hand: 100, fill: 'var(--color-hand)' }]}
  41. // Adjust the angles to create a small hand
  42. startAngle={80 - (progress * 360) / 100}
  43. endAngle={140 - (progress * 360) / 100}
  44. innerRadius={14}
  45. outerRadius={5}
  46. >
  47. <RadialBar dataKey="hand" cornerRadius={2} isAnimationActive={true} />
  48. </RadialBarChart>
  49. </ChartContainer>
  50. </div>
  51. )
  52. }
  53. export default CountdownTimerRadial