Files
grungnet/src/components/Tokens.js

54 lines
1.4 KiB
JavaScript
Raw Normal View History

2020-04-07 11:47:06 +10:00
import React, { useState } from "react";
import { Box } from "theme-ui";
import shortid from "shortid";
import SimpleBar from "simplebar-react";
2020-03-19 21:40:29 +11:00
import * as tokens from "../tokens";
import Token from "./Token";
import ProxyToken from "./ProxyToken";
2020-04-07 11:47:06 +10:00
import SizeInput from "./SizeInput";
2020-03-20 13:33:12 +11:00
const listTokenClassName = "list-token";
2020-03-20 13:33:12 +11:00
function Tokens({ onCreateMapToken }) {
2020-04-07 11:47:06 +10:00
const [tokenSize, setTokenSize] = useState(1);
function handleProxyDragEnd(isOnMap, token) {
if (isOnMap && onCreateMapToken) {
// Give the token an id
2020-04-07 11:47:06 +10:00
onCreateMapToken({ ...token, id: shortid.generate(), size: tokenSize });
}
}
2020-03-19 21:40:29 +11:00
return (
<>
<Box
sx={{
height: "100%",
width: "80px",
minWidth: "80px",
overflow: "hidden",
}}
>
<SimpleBar style={{ height: "calc(100% - 58px)", overflowX: "hidden" }}>
2020-04-07 11:47:06 +10:00
{Object.entries(tokens).map(([id, image]) => (
<Box key={id} my={2} mx={3} sx={{ width: "48px", height: "48px" }}>
2020-04-07 11:47:06 +10:00
<Token image={image} className={listTokenClassName} />
</Box>
))}
</SimpleBar>
<Box pt={1} bg="muted" sx={{ height: "58px" }}>
2020-04-07 11:47:06 +10:00
<SizeInput value={tokenSize} onChange={setTokenSize} />
</Box>
</Box>
<ProxyToken
2020-03-20 13:33:12 +11:00
tokenClassName={listTokenClassName}
onProxyDragEnd={handleProxyDragEnd}
/>
</>
2020-03-19 21:40:29 +11:00
);
}
export default Tokens;