silphius/app/react-components/dom/slot.jsx

50 lines
1018 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 08:14:32 -05:00
export default function Slot({
2024-06-28 14:10:44 -05:00
icon,
2024-06-24 08:14:32 -05:00
onClick,
onDragEnter,
onDragOver,
onDragStart,
onDrop,
2024-06-28 16:37:15 -05:00
onMouseDown,
onMouseUp,
2024-06-24 08:14:32 -05:00
qty = 1,
}) {
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}
2024-06-24 08:14:32 -05:00
draggable
2024-06-10 22:42:30 -05:00
onClick={onClick}
2024-06-24 08:14:32 -05:00
onDragEnter={onDragEnter}
onDragOver={onDragOver}
onDragStart={onDragStart}
onDrop={onDrop}
onKeyDown={(event) => {
event.preventDefault();
}}
2024-06-28 16:37:15 -05:00
onMouseDown={onMouseDown}
onMouseUp={onMouseUp}
2024-06-10 22:42:30 -05:00
>
<div
className={styles.slotInner}
2024-06-28 14:10:44 -05:00
style={icon ? {backgroundImage: `url(${icon})`} : {}}
2024-06-10 22:42:30 -05:00
>
{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
);
}