grungnet/src/components/Tokens.js

45 lines
998 B
JavaScript
Raw Normal View History

import React from "react";
import { Flex } from "theme-ui";
import shortid from "shortid";
2020-03-19 06:40:29 -04:00
import * as tokens from "../tokens";
import Token from "./Token";
import ProxyToken from "./ProxyToken";
2020-03-19 22:33:12 -04:00
const listTokenClassName = "list-token";
2020-03-19 22:33:12 -04:00
function Tokens({ onCreateMapToken }) {
function handleProxyDragEnd(isOnMap, token) {
if (isOnMap && onCreateMapToken) {
// Give the token an id
2020-03-19 22:33:12 -04:00
onCreateMapToken({ ...token, id: shortid.generate() });
}
}
2020-03-19 06:40:29 -04:00
return (
<>
<Flex
bg="background"
sx={{
width: "80px",
minWidth: "80px",
flexDirection: "column",
overflowY: "auto"
}}
px={2}
>
{Object.entries(tokens).map(([id, image]) => (
2020-03-19 22:33:12 -04:00
<Token key={id} image={image} className={listTokenClassName} />
))}
</Flex>
<ProxyToken
2020-03-19 22:33:12 -04:00
tokenClassName={listTokenClassName}
onProxyDragEnd={handleProxyDragEnd}
/>
</>
2020-03-19 06:40:29 -04:00
);
}
export default Tokens;