Files
grungnet/src/components/token/TokenTile.js
T

102 lines
2.5 KiB
JavaScript
Raw Normal View History

import React from "react";
2020-05-19 19:03:36 +10:00
import { Flex, Image, Text, Box, IconButton } from "theme-ui";
2020-05-21 22:57:05 +10:00
import RemoveTokenIcon from "../../icons/RemoveTokenIcon";
2020-05-19 19:03:36 +10:00
import useDataSource from "../../helpers/useDataSource";
import {
tokenSources as defaultTokenSources,
unknownSource,
} from "../../tokens";
function TokenTile({ token, isSelected, onTokenSelect, onTokenRemove, large }) {
const tokenSource = useDataSource(token, defaultTokenSources, unknownSource);
2020-05-19 19:03:36 +10:00
const isDefault = token.type === "default";
return (
<Flex
2020-05-19 19:03:36 +10:00
onClick={() => onTokenSelect(token)}
sx={{
position: "relative",
width: large ? "49%" : "32%",
height: "0",
paddingTop: large ? "49%" : "32%",
borderRadius: "4px",
justifyContent: "center",
alignItems: "center",
cursor: "pointer",
overflow: "hidden",
}}
my={1}
bg="muted"
>
<Image
sx={{
width: "100%",
height: "100%",
objectFit: "contain",
position: "absolute",
top: 0,
left: 0,
}}
src={tokenSource}
/>
<Flex
sx={{
position: "absolute",
top: 0,
left: 0,
right: 0,
bottom: 0,
background:
"linear-gradient(to bottom, rgba(0,0,0,0) 70%, rgba(0,0,0,0.65) 100%);",
alignItems: "flex-end",
justifyContent: "center",
}}
p={2}
>
<Text
as="p"
variant="heading"
color="hsl(210, 50%, 96%)"
sx={{ textAlign: "center" }}
>
{token.name}
</Text>
</Flex>
<Box
sx={{
width: "100%",
height: "100%",
position: "absolute",
top: 0,
left: 0,
borderColor: "primary",
borderStyle: isSelected ? "solid" : "none",
borderWidth: "4px",
pointerEvents: "none",
borderRadius: "4px",
}}
/>
2020-05-19 19:03:36 +10:00
{isSelected && !isDefault && (
<Box sx={{ position: "absolute", top: 0, right: 0 }}>
<IconButton
2020-07-02 17:01:08 +10:00
aria-label="Remove Token"
title="Remove Token"
2020-05-19 19:03:36 +10:00
onClick={() => {
onTokenRemove(token.id);
}}
bg="overlay"
sx={{ borderRadius: "50%" }}
m={2}
2020-05-19 19:03:36 +10:00
>
2020-05-21 22:57:05 +10:00
<RemoveTokenIcon />
2020-05-19 19:03:36 +10:00
</IconButton>
</Box>
)}
</Flex>
);
}
export default TokenTile;