2022-12-11 13:12:39 +01:00
|
|
|
import { Button, Flex, Grid, NumberInput, Select, SelectItem } from '@mantine/core';
|
2022-12-08 22:17:33 +01:00
|
|
|
import { useForm } from '@mantine/form';
|
2022-12-10 15:00:16 +01:00
|
|
|
import { useConfigContext } from '../../../../config/provider';
|
2022-12-11 13:12:39 +01:00
|
|
|
|
|
|
|
|
interface ChangePositionModalProps {
|
|
|
|
|
initialX: number;
|
|
|
|
|
initialY: number;
|
|
|
|
|
initialWidth: number;
|
|
|
|
|
initialHeight: number;
|
|
|
|
|
widthData: SelectItem[];
|
|
|
|
|
heightData: SelectItem[];
|
|
|
|
|
onSubmit: (x: number, y: number, width: number, height: number) => void;
|
|
|
|
|
onCancel: () => void;
|
|
|
|
|
}
|
2022-12-08 22:17:33 +01:00
|
|
|
|
|
|
|
|
export const ChangePositionModal = ({
|
2022-12-11 13:12:39 +01:00
|
|
|
initialX,
|
|
|
|
|
initialY,
|
|
|
|
|
initialWidth,
|
|
|
|
|
initialHeight,
|
|
|
|
|
widthData,
|
|
|
|
|
heightData,
|
|
|
|
|
onCancel,
|
|
|
|
|
onSubmit,
|
|
|
|
|
}: ChangePositionModalProps) => {
|
2022-12-10 15:00:16 +01:00
|
|
|
const { name: configName } = useConfigContext();
|
|
|
|
|
|
2022-12-11 13:12:39 +01:00
|
|
|
const form = useForm<FormType>({
|
2022-12-08 22:17:33 +01:00
|
|
|
initialValues: {
|
2022-12-11 13:12:39 +01:00
|
|
|
x: initialX,
|
|
|
|
|
y: initialY,
|
|
|
|
|
width: initialWidth,
|
|
|
|
|
height: initialHeight,
|
2022-12-08 22:17:33 +01:00
|
|
|
},
|
2022-12-10 15:00:16 +01:00
|
|
|
validateInputOnChange: true,
|
|
|
|
|
validateInputOnBlur: true,
|
2022-12-08 22:17:33 +01:00
|
|
|
});
|
|
|
|
|
|
2022-12-11 13:12:39 +01:00
|
|
|
const handleSubmit = () => {
|
2022-12-10 15:00:16 +01:00
|
|
|
if (!configName) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2022-12-11 13:12:39 +01:00
|
|
|
onSubmit(form.values.x, form.values.y, form.values.width, form.values.height);
|
2022-12-10 15:00:16 +01:00
|
|
|
};
|
|
|
|
|
|
2022-12-08 22:17:33 +01:00
|
|
|
return (
|
2022-12-11 13:12:39 +01:00
|
|
|
<form onSubmit={form.onSubmit(handleSubmit)}>
|
2022-12-08 22:17:33 +01:00
|
|
|
<Grid>
|
|
|
|
|
<Grid.Col xs={12} md={6}>
|
2022-12-10 15:00:16 +01:00
|
|
|
<NumberInput
|
|
|
|
|
max={99}
|
|
|
|
|
min={0}
|
|
|
|
|
label="X Position"
|
|
|
|
|
description="0 or higher"
|
2022-12-11 13:12:39 +01:00
|
|
|
{...form.getInputProps('x')}
|
2022-12-10 15:00:16 +01:00
|
|
|
/>
|
2022-12-08 22:17:33 +01:00
|
|
|
</Grid.Col>
|
|
|
|
|
|
|
|
|
|
<Grid.Col xs={12} md={6}>
|
2022-12-10 15:00:16 +01:00
|
|
|
<NumberInput
|
|
|
|
|
max={99}
|
|
|
|
|
min={0}
|
|
|
|
|
label="Y Position"
|
|
|
|
|
description="0 or higher"
|
2022-12-11 13:12:39 +01:00
|
|
|
{...form.getInputProps('y')}
|
2022-12-10 15:00:16 +01:00
|
|
|
/>
|
2022-12-08 22:17:33 +01:00
|
|
|
</Grid.Col>
|
|
|
|
|
</Grid>
|
2022-12-10 15:00:16 +01:00
|
|
|
|
|
|
|
|
<Grid>
|
|
|
|
|
<Grid.Col xs={12} md={6}>
|
2022-12-11 13:12:39 +01:00
|
|
|
<Select
|
|
|
|
|
data={widthData}
|
2022-12-10 15:00:16 +01:00
|
|
|
max={24}
|
|
|
|
|
min={1}
|
|
|
|
|
label="Width"
|
2022-12-11 13:12:39 +01:00
|
|
|
description={`Between ${widthData.at(0)?.label} and ${widthData.at(-1)?.label}`}
|
|
|
|
|
{...form.getInputProps('width')}
|
2022-12-10 15:00:16 +01:00
|
|
|
/>
|
|
|
|
|
</Grid.Col>
|
|
|
|
|
|
|
|
|
|
<Grid.Col xs={12} md={6}>
|
2022-12-11 13:12:39 +01:00
|
|
|
<Select
|
|
|
|
|
data={heightData}
|
2022-12-10 15:00:16 +01:00
|
|
|
max={24}
|
|
|
|
|
min={1}
|
|
|
|
|
label="Height"
|
2022-12-11 13:12:39 +01:00
|
|
|
description={`Between ${heightData.at(0)?.label} and ${heightData.at(-1)?.label}`}
|
|
|
|
|
{...form.getInputProps('height')}
|
2022-12-10 15:00:16 +01:00
|
|
|
/>
|
|
|
|
|
</Grid.Col>
|
|
|
|
|
</Grid>
|
|
|
|
|
|
|
|
|
|
<Flex justify="end" gap="sm" mt="md">
|
2022-12-11 13:12:39 +01:00
|
|
|
<Button onClick={() => onCancel()} variant="light" color="gray">
|
2022-12-10 15:00:16 +01:00
|
|
|
Cancel
|
|
|
|
|
</Button>
|
2022-12-11 13:12:39 +01:00
|
|
|
<Button type="submit">Save</Button>
|
2022-12-10 15:00:16 +01:00
|
|
|
</Flex>
|
|
|
|
|
</form>
|
2022-12-08 22:17:33 +01:00
|
|
|
);
|
|
|
|
|
};
|
2022-12-11 13:12:39 +01:00
|
|
|
|
|
|
|
|
type FormType = {
|
|
|
|
|
x: number;
|
|
|
|
|
y: number;
|
|
|
|
|
width: number;
|
|
|
|
|
height: number;
|
|
|
|
|
};
|