| type Props = { |
| |
| |
| |
| amplitude: number; |
| |
| |
| |
| segments?: number; |
| |
| |
| |
| stroke: string; |
| |
| |
| |
| strokeWidth: number; |
| |
| |
| |
| width: number; |
| |
| |
| |
| height: number; |
| }; |
|
|
| const WavyLine = ({ amplitude, stroke, strokeWidth, width, height, segments = 5 }: Props) => { |
| |
| const generatePath = () => { |
| if (amplitude === 0) { |
| |
| return `M0,${height / 2} L${width},${height / 2}`; |
| } |
|
|
| const clampedAmplitude = Math.min(height / 2, amplitude); |
| const segmentWidth = width / segments; |
| let path = `M0,${height / 2}`; |
|
|
| |
| for (let i = 1; i <= segments; i++) { |
| const x = i * segmentWidth; |
| const y = height / 2 + (i % 2 === 0 ? clampedAmplitude : -clampedAmplitude); |
| path += ` Q${x - segmentWidth / 2},${y} ${x},${height / 2}`; |
| } |
|
|
| return path; |
| }; |
|
|
| return ( |
| <svg width={width} height={height} viewBox={`0 0 ${width} ${height}`} xmlns="http://www.w3.org/2000/svg"> |
| <path d={generatePath()} fill="none" stroke={stroke} strokeWidth={strokeWidth} /> |
| </svg> |
| ); |
| }; |
|
|
| export default WavyLine; |
|
|