moving board
This commit is contained in:
1 parent
91704c3da2
commit
4c21dc6090
2 files changed
+69
-28
No files matched your search
@@ -0,0 +1,32 @@
|
||||
.board-btn {
|
||||
position: absolute;
|
||||
}
|
||||
.board-btn:hover {
|
||||
background: #5e44444f;
|
||||
cursor: pointer;
|
||||
}
|
||||
.board-btn.right {
|
||||
right: 0;
|
||||
top: 0;
|
||||
height: 100%;
|
||||
width: 5%;
|
||||
}
|
||||
.board-btn.left {
|
||||
left: 0;
|
||||
top: 0;
|
||||
height: 100%;
|
||||
width: 5%;
|
||||
}
|
||||
.board-btn.top {
|
||||
left: 0;
|
||||
top: 0;
|
||||
height: 5%;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.board-btn.bottom {
|
||||
left: 0;
|
||||
bottom: 0;
|
||||
height: 5%;
|
||||
width: 100%;
|
||||
}
|
||||
@@ -1,40 +1,49 @@
|
||||
import { FC } from "react";
|
||||
import "./Board.css";
|
||||
import { FC, useState } from 'react';
|
||||
import { Point } from 'types/graphs';
|
||||
import useWindowSize from "utils/useWindowSize";
|
||||
import { useBoardStyles } from "./styles";
|
||||
|
||||
|
||||
export const SVGBoard: FC<{
|
||||
graphHeight?: number,
|
||||
}> =({
|
||||
children?: JSX.Element;
|
||||
}> = ({
|
||||
children,
|
||||
graphHeight = 300,
|
||||
}) => {
|
||||
|
||||
// state
|
||||
const { ratioWbh } = useWindowSize();
|
||||
const { classes, theme } = useBoardStyles({});
|
||||
// state
|
||||
const { ratioWbh } = useWindowSize();
|
||||
const { classes, theme } = useBoardStyles({});
|
||||
const [[offX, offY], setOffset] = useState<Point>([0, 0])
|
||||
|
||||
// alias
|
||||
const graphWidth = Math.round(graphHeight * ratioWbh);
|
||||
// alias
|
||||
const graphWidth = Math.round(graphHeight * ratioWbh);
|
||||
|
||||
// render
|
||||
return <div className={classes.root} style={{
|
||||
flexDirection: ratioWbh >= 0.75 ? 'row' : 'column'
|
||||
}}>
|
||||
<div className={classes.dag}>
|
||||
<svg
|
||||
className={classes.svg}
|
||||
viewBox={[0, 0, graphWidth, graphHeight].join(" ")}
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
>
|
||||
<defs>
|
||||
<marker id="arrow" viewBox="0 0 10 10" refX="10" refY="5"
|
||||
markerWidth="6" markerHeight="6"
|
||||
orient="auto-start-reverse">
|
||||
<path d="M 0 0 L 10 5 L 0 10 z" fill={theme.secondaryAccent} />
|
||||
</marker>
|
||||
</defs>
|
||||
{children}
|
||||
</svg>
|
||||
// render
|
||||
return <div className={classes.root} style={{
|
||||
flexDirection: ratioWbh >= 0.75 ? 'row' : 'column'
|
||||
}}>
|
||||
<div className={classes.dag}>
|
||||
<svg
|
||||
className={classes.svg}
|
||||
viewBox={[offX, offY, graphWidth + offX, graphHeight + offY].join(" ")}
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
>
|
||||
<defs>
|
||||
<marker id="arrow" viewBox="0 0 10 10" refX="10" refY="5"
|
||||
markerWidth="6" markerHeight="6"
|
||||
orient="auto-start-reverse">
|
||||
<path d="M 0 0 L 10 5 L 0 10 z" fill={theme.secondaryAccent} />
|
||||
</marker>
|
||||
</defs>
|
||||
{children}
|
||||
</svg>
|
||||
</div>
|
||||
<div className="board-btn top" onClick={() => setOffset([offX, offY - 10])}></div>
|
||||
<div className="board-btn left" onClick={() => setOffset([offX - 10, offY])}></div>
|
||||
<div className="board-btn right" onClick={() => setOffset([offX + 10, offY])}></div>
|
||||
<div className="board-btn bottom" onClick={() => setOffset([offX, offY + 10])}></div>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user