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

47 lines
1.1 KiB
JavaScript
Raw Normal View History

import React, { useState } from "react";
import { Image, Box } from "theme-ui";
2021-05-14 18:02:50 +10:00
import { useDataURL } from "../../contexts/AssetsContext";
import { tokenSources as defaultTokenSources } from "../../tokens";
import { TokenOutlineSVG } from "./TokenOutline";
const TokenImage = React.forwardRef(({ token, ...props }, ref) => {
2021-05-14 18:02:50 +10:00
const tokenURL = useDataURL(
token,
defaultTokenSources,
undefined,
token.type === "file"
);
const [showOutline, setShowOutline] = useState(true);
return (
<>
{showOutline && (
<Box
title={props.alt}
aria-label={props.alt}
sx={{ width: "100%", height: "100%", minHeight: 0 }}
>
<TokenOutlineSVG
outline={token.outline}
width={token.width}
height={token.height}
/>
</Box>
)}
<Image
onLoad={() => setShowOutline(false)}
src={tokenURL}
ref={ref}
style={showOutline ? { display: "none" } : props.style}
{...props}
/>
</>
);
2021-05-25 16:56:37 +10:00
});
2021-05-14 18:02:50 +10:00
2021-05-25 16:56:37 +10:00
export default TokenImage;