grungnet/src/modals/SelectDiceModal.tsx
Mitchell McCaffrey ecfab87aa0 More typescript
2021-07-09 16:22:35 +10:00

60 lines
1.3 KiB
TypeScript

import { useState } from "react";
import { Flex, Label, Button } from "theme-ui";
import Modal from "../components/Modal";
import DiceTiles from "../components/dice/DiceTiles";
import { dice } from "../dice";
import useResponsiveLayout from "../hooks/useResponsiveLayout";
import { DefaultDice } from "../types/Dice";
type SelectDiceProps = {
isOpen: boolean;
onRequestClose: () => void;
onDone: (dice: DefaultDice) => void;
defaultDice: DefaultDice;
};
function SelectDiceModal({
isOpen,
onRequestClose,
onDone,
defaultDice,
}: SelectDiceProps) {
const [selectedDice, setSelectedDice] = useState(defaultDice);
const layout = useResponsiveLayout();
return (
<Modal
isOpen={isOpen}
onRequestClose={onRequestClose}
style={{
content: { maxWidth: layout.modalSize, width: "calc(100% - 16px)" },
}}
>
<Flex
sx={{
flexDirection: "column",
}}
>
<Label pt={2} pb={1}>
Select a dice style
</Label>
<DiceTiles
dice={dice}
onDiceSelect={setSelectedDice}
selectedDice={selectedDice}
onDone={onDone}
/>
<Button my={2} variant="primary" onClick={() => onDone(selectedDice)}>
Select
</Button>
</Flex>
</Modal>
);
}
export default SelectDiceModal;