silphius/app/react-components/slot.jsx

34 lines
777 B
React
Raw Normal View History

2024-06-10 22:42:30 -05:00
import styles from './slot.module.css';
/**
* An inventory slot. Displays an item image and the quantity of the item if > 1.
*/
2024-06-24 05:34:02 -05:00
export default function Slot({source, onClick, qty = 1}) {
const image = source + '/icon.png';
2024-06-10 22:42:30 -05:00
return (
2024-06-24 05:34:02 -05:00
<button
2024-06-10 22:42:30 -05:00
className={styles.slot}
onClick={onClick}
onKeyDown={(event) => {
event.preventDefault();
}}
2024-06-10 22:42:30 -05:00
>
<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>
2024-06-24 05:34:02 -05:00
</button>
2024-06-10 22:42:30 -05:00
);
}