diff options
| author | s-ol <s-ol@users.noreply.github.com> | 2021-02-05 18:32:12 +0000 |
|---|---|---|
| committer | s-ol <s-ol@users.noreply.github.com> | 2021-02-05 18:42:02 +0000 |
| commit | 464174b7e5e4e5c389c896173e8c7ab21badda8a (patch) | |
| tree | 0f88ffc3db86026f86cb2941e4a05bd8a2753903 /src/ui/Links.js | |
| parent | links leave shadow (diff) | |
| download | fedidag-464174b7e5e4e5c389c896173e8c7ab21badda8a.tar.gz fedidag-464174b7e5e4e5c389c896173e8c7ab21badda8a.zip | |
clean up UI code
Diffstat (limited to 'src/ui/Links.js')
| -rw-r--r-- | src/ui/Links.js | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/src/ui/Links.js b/src/ui/Links.js new file mode 100644 index 0000000..dfd981f --- /dev/null +++ b/src/ui/Links.js @@ -0,0 +1,50 @@ +import { render, h, Fragment } from 'preact'; +import { useRef, useLayoutEffect } from 'preact/hooks'; + +export const Links = ({ links, ...props }) => { + const canvas = useRef(null); + + useLayoutEffect(() => { + const ctx = canvas.current.getContext('2d'); + ctx.lineWidth = 4; + ctx.lineCap = 'round'; + ctx.lineJoin = 'round'; + ctx.strokeStyle = '#696969'; + ctx.fillStyle = '#696969'; + ctx.shadowBlur = 2; + ctx.shadowOffsetX = 2; + ctx.shadowOffsetY = 4; + + ctx.clearRect(0, 0, canvas.current.width, canvas.current.height); + + for (const points of links) { + ctx.shadowColor = 'rgba(0,0,0, 0.7)'; + ctx.beginPath(); + ctx.moveTo(...points[1]); + for (let i = 4; i < points.length; i += 3) { + const [ax, ay] = points[i - 2]; + const [bx, by] = points[i - 1]; + const [x, y] = points[i]; + ctx.bezierCurveTo(ax, ay, bx, by, x, y); + } + ctx.stroke(); + + const [lx, ly] = points[points.length - 1]; + const [tx, ty] = points[0]; + const [dx, dy] = [tx - lx, ty - ly]; + const [hx, hy] = [dy*0.7, dx*-0.7]; + + ctx.shadowColor = 'transparent'; + ctx.beginPath(); + ctx.moveTo(lx + dx*0.8, ly + dy*0.8); + ctx.lineTo(lx - dx*0.5 + hx, ly - dy*0.5 + hy); + ctx.lineTo(lx - dx*0.5 - hx, ly - dy*0.5 - hy); + ctx.fill(); + } + }); + + return ( + <canvas {...props} ref={canvas} /> + ); +}; + |
