~bigbes/lethe

ref: e6173cab1e231b1f4128025ba53075b3b186e564 lethe/web/src/primitives/Spark.tsx -rw-r--r-- 613 bytes
e6173cab — Eugene Blikh docs: add roadmap TODO and lethe-web-ui-aggregates design a month ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
import type React from 'react'

interface SparkProps {
  points: number[]
  w?: number
  h?: number
  accent?: boolean
}

export function Spark({ points, w = 60, h = 16, accent = false }: SparkProps): React.JSX.Element {
  const ptStr = points
    .map((v, i) => `${((i / Math.max(points.length - 1, 1)) * w).toFixed(1)},${v.toFixed(1)}`)
    .join(' ')

  return (
    <svg
      width={w}
      height={h}
      viewBox={`0 0 ${w} ${h}`}
      preserveAspectRatio="none"
      style={{ display: 'block' }}
    >
      <polyline points={ptStr} className={'spark' + (accent ? ' accent' : '')} />
    </svg>
  )
}