Files
grungnet/src/components/token/Tokens.js

66 lines
1.6 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";
2020-03-19 21:40:29 +11:00
import ListToken from "./ListToken";
import ProxyToken from "./ProxyToken";
import NumberInput from "../NumberInput";
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
onCreateMapToken({
...token,
id: shortid.generate(),
size: tokenSize,
label: "",
2020-04-13 23:42:18 +10:00
status: "",
});
}
}
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" }}>
<ListToken image={image} className={listTokenClassName} />
2020-04-07 11:47:06 +10:00
</Box>
))}
</SimpleBar>
<Box pt={1} bg="muted" sx={{ height: "58px" }}>
<NumberInput
value={tokenSize}
onChange={setTokenSize}
title="Size"
min={1}
max={9}
/>
2020-04-07 11:47:06 +10:00
</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;