parent
a7ddad4c67
commit
2a5ece19a9
After Width: | Height: | Size: 427 B |
@ -1,33 +1,50 @@
|
||||
import React, {useEffect, useRef} from "react";
|
||||
import React, {useRef} from "react";
|
||||
import "../../style/player.css";
|
||||
import RemoveIcon from "../../assets/icon/remove.svg";
|
||||
import Draggable, {DraggableBounds} from "react-draggable";
|
||||
|
||||
export default function Player({id, x, y, bounds}: {
|
||||
export interface PlayerOptions {
|
||||
id: number,
|
||||
x: number,
|
||||
y: number,
|
||||
bounds: DraggableBounds
|
||||
}) {
|
||||
bounds: DraggableBounds,
|
||||
onRemove: () => void
|
||||
}
|
||||
|
||||
const ref = useRef<HTMLDivElement>(null);
|
||||
useEffect(() => {
|
||||
const playerRect = ref.current!.getBoundingClientRect();
|
||||
bounds.bottom! -= playerRect.height / 2;
|
||||
bounds.right! -= playerRect.width / 2;
|
||||
}, [ref])
|
||||
export default function Player({id, x, y, bounds, onRemove}: PlayerOptions) {
|
||||
|
||||
const ref = useRef<HTMLDivElement>(null);
|
||||
return (
|
||||
<Draggable
|
||||
handle={".player-piece"}
|
||||
nodeRef={ref}
|
||||
bounds={bounds}
|
||||
defaultPosition={{x: x, y: y}}>
|
||||
defaultPosition={{x: x, y: y}}
|
||||
>
|
||||
<div ref={ref}
|
||||
className="player"
|
||||
className={"player"}
|
||||
style={{
|
||||
position: "absolute",
|
||||
}}>
|
||||
<p>{id}</p>
|
||||
|
||||
<div tabIndex={0}
|
||||
className="player-content"
|
||||
onKeyUp={e => {
|
||||
if (e.key == "Delete")
|
||||
onRemove()
|
||||
}}>
|
||||
<div className="player-selection-tab">
|
||||
<RemoveIcon
|
||||
className="player-selection-tab-remove"
|
||||
onClick={() => onRemove()}/>
|
||||
</div>
|
||||
<div
|
||||
className="player-piece">
|
||||
<p>{id}</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</Draggable>
|
||||
|
||||
)
|
||||
|
Loading…
Reference in new issue