2020-05-27 15:26:42 +10:00
|
|
|
import React, { useState } from "react";
|
2020-05-26 15:43:46 +10:00
|
|
|
import { IconButton } from "theme-ui";
|
|
|
|
|
|
2020-05-28 13:06:33 +10:00
|
|
|
import SelectDiceIcon from "../../icons/SelectDiceIcon";
|
|
|
|
|
import SelectDiceModal from "../../modals/SelectDiceModal";
|
2020-05-26 15:43:46 +10:00
|
|
|
|
2020-08-11 18:56:56 +10:00
|
|
|
function SelectDiceButton({ onDiceChange, currentDice, disabled }) {
|
2020-05-26 15:43:46 +10:00
|
|
|
const [isModalOpen, setIsModalOpen] = useState(false);
|
|
|
|
|
|
|
|
|
|
function openModal() {
|
|
|
|
|
setIsModalOpen(true);
|
|
|
|
|
}
|
|
|
|
|
function closeModal() {
|
|
|
|
|
setIsModalOpen(false);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function handleDone(dice) {
|
|
|
|
|
onDiceChange(dice);
|
|
|
|
|
closeModal();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<>
|
2020-05-27 11:24:17 +10:00
|
|
|
<IconButton
|
|
|
|
|
aria-label="Select Dice Style"
|
|
|
|
|
title="Select Dice Style"
|
|
|
|
|
onClick={openModal}
|
2020-08-11 18:56:56 +10:00
|
|
|
disabled={disabled}
|
2020-05-27 11:24:17 +10:00
|
|
|
>
|
2020-05-26 15:43:46 +10:00
|
|
|
<SelectDiceIcon />
|
|
|
|
|
</IconButton>
|
|
|
|
|
<SelectDiceModal
|
|
|
|
|
isOpen={isModalOpen}
|
|
|
|
|
onRequestClose={closeModal}
|
|
|
|
|
defaultDice={currentDice}
|
|
|
|
|
onDone={handleDone}
|
|
|
|
|
/>
|
|
|
|
|
</>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export default SelectDiceButton;
|