-
Notifications
You must be signed in to change notification settings - Fork 26
/
Triangle.tsx
43 lines (37 loc) · 905 Bytes
/
Triangle.tsx
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import React from 'react'
export enum TriangleDirection {
Up,
Down,
Left,
Right,
}
interface TriangeProps {
style: React.CSSProperties
x: number
y: number
dimension: number
direction: TriangleDirection
}
function Triangle({ style, x, y, dimension, direction }: TriangeProps) {
let trianglePath
switch (direction) {
case TriangleDirection.Left:
trianglePath = `M7.5 0 l -5 5 5 5z`
break
case TriangleDirection.Right:
trianglePath = `M2.5 0 l 5 5 -5 5z`
break
case TriangleDirection.Up:
trianglePath = `M0 7.5 l 5 -5 5 5z`
break
case TriangleDirection.Down:
default:
trianglePath = `M0 2.5 l 5 5 5-5z`
}
return (
<svg x={x - dimension / 2} y={y - dimension / 2} viewBox={`0 0 10 10`} width={dimension} height={dimension}>
<path style={style} d={trianglePath} />
</svg>
)
}
export default Triangle