import { Loader } from './common/Loader'; import { InputButtons } from './common/InputButtons'; import { KEY_ENTER, KEY_ESCAPE } from '../../common/keycodes'; import { useBackend, useLocalState } from '../backend'; import { Box, Button, RestrictedInput, Section, Stack } from '../components'; import { Window } from '../layouts'; type NumberInputData = { init_value: number; large_buttons: boolean; max_value: number | null; message: string; min_value: number | null; timeout: number; title: string; }; export const NumberInputModal = (props, context) => { const { act, data } = useBackend(context); const { init_value, large_buttons, message = '', timeout, title } = data; const [input, setInput] = useLocalState(context, 'input', init_value); const onChange = (value: number) => { if (value === input) { return; } setInput(value); }; const onClick = (value: number) => { if (value === input) { return; } setInput(value); }; // Dynamically changes the window height based on the message. const windowHeight = 140 + (message.length > 30 ? Math.ceil(message.length / 3) : 0) + (message.length && large_buttons ? 5 : 0); return ( {timeout && } { const keyCode = window.event ? event.which : event.keyCode; if (keyCode === KEY_ENTER) { act('submit', { entry: input }); } if (keyCode === KEY_ESCAPE) { act('cancel'); } }}>
{message}
); }; /** Gets the user input and invalidates if there's a constraint. */ const InputArea = (props, context) => { const { act, data } = useBackend(context); const { min_value, max_value, init_value } = data; const { input, onClick, onChange } = props; return (