Refactored component folder structure to be a little clearer

This commit is contained in:
Mitchell McCaffrey
2020-04-23 10:09:12 +10:00
parent 65c3620732
commit f2a92f2ccd
19 changed files with 42 additions and 42 deletions

View File

@@ -0,0 +1,66 @@
import React, { useRef } from "react";
import { Box, Image } from "theme-ui";
import TokenLabel from "../token/TokenLabel";
import TokenStatus from "../token/TokenStatus";
import usePreventTouch from "../../helpers/usePreventTouch";
function MapToken({ token, tokenSizePercent, className }) {
const imageRef = useRef();
// Stop touch to prevent 3d touch gesutre on iOS
usePreventTouch(imageRef);
return (
<Box
style={{
transform: `translate(${token.x * 100}%, ${token.y * 100}%)`,
width: "100%",
height: "100%",
}}
sx={{
position: "absolute",
pointerEvents: "none",
}}
>
<Box
style={{
width: `${tokenSizePercent * (token.size || 1)}%`,
}}
sx={{
position: "absolute",
pointerEvents: "all",
}}
>
<Box
sx={{
position: "absolute",
display: "flex", // Set display to flex to fix height being calculated wrong
width: "100%",
flexDirection: "column",
}}
>
<Image
className={className}
sx={{
userSelect: "none",
touchAction: "none",
width: "100%",
}}
src={token.image}
// pass data into the dom element used to pass state to the ProxyToken
data-id={token.id}
data-size={token.size}
data-label={token.label}
data-status={token.status}
ref={imageRef}
/>
{token.status && <TokenStatus statuses={token.status.split(" ")} />}
{token.label && <TokenLabel label={token.label} />}
</Box>
</Box>
</Box>
);
}
export default MapToken;