silphius/app/react-components/slot.jsx
2024-06-10 23:55:06 -05:00

30 lines
661 B
JavaScript

import styles from './slot.module.css';
/**
* An inventory slot. Displays an item image and the quantity of the item if > 1.
*/
export default function Slot({image, onClick, qty = 1}) {
return (
<div
className={styles.slot}
onClick={onClick}
>
<div
className={styles.slotInner}
style={image ? {backgroundImage: `url(${image})`} : {}}
>
{qty > 1 && (
<span
className={
[styles.qty, `q-${Math.round(Math.log10(qty))}`]
.filter(Boolean).join(' ')
}
>
{qty}
</span>
)}
</div>
</div>
);
}