Files
sign/apps/web/components/editor/field.tsx

59 lines
1.6 KiB
TypeScript
Raw Normal View History

2023-02-08 15:43:14 +01:00
import { ResizableBox, ResizeCallbackData } from "react-resizable";
2023-02-09 15:48:26 +01:00
import React, { SyntheticEvent, useEffect, useState } from "react";
2023-02-08 15:43:14 +01:00
import Draggable from "react-draggable";
import { CircleStackIcon } from "@heroicons/react/24/outline";
import Logo from "../logo";
2023-02-09 15:48:26 +01:00
const stc = require("string-to-color");
2023-02-08 15:43:14 +01:00
type FieldPropsType = {
2023-02-09 15:48:26 +01:00
field: {
color: string;
type: string;
position: any;
id: string;
recipient: string;
};
2023-02-13 18:04:44 +01:00
onPositionChanged: any;
2023-02-08 15:43:14 +01:00
};
export default function Field(props: FieldPropsType) {
2023-02-09 15:48:26 +01:00
const [field, setField]: any = useState(props.field);
const [position, setPosition]: any = useState(
props.field.position || { x: 0, y: -842 }
);
const nodeRef = React.createRef<HTMLDivElement>();
const onControlledDrag = (e: any, position: any) => {
const { x, y } = position;
setPosition({ x, y });
};
const onDragStop = (e: any, position: any) => {
if (!position) return;
const { x, y } = position;
2023-02-13 18:04:44 +01:00
props.onPositionChanged({ x, y }, props.field.id);
2023-02-09 15:48:26 +01:00
};
2023-02-08 15:43:14 +01:00
return (
2023-02-09 15:48:26 +01:00
<Draggable
nodeRef={nodeRef}
bounds="parent"
position={position}
onDrag={onControlledDrag}
onStop={onDragStop}
>
<div
ref={nodeRef}
style={{ background: stc(props.field.recipient) }}
2023-02-13 18:12:03 +01:00
className="cursor-move opacity-80 p-2 m-auto w-auto flex-row-reverse text-lg font-bold text-center absolute"
2023-02-08 15:43:14 +01:00
>
2023-02-08 15:54:17 +01:00
<div className="m-auto w-auto flex-row-reverse text-lg font-bold text-center">
{/* todo icons */}
2023-02-08 15:43:14 +01:00
Signature
2023-02-09 15:48:26 +01:00
<div className="text-xs text-center">{props.field.recipient}</div>
2023-02-08 15:43:14 +01:00
</div>
2023-02-09 15:48:26 +01:00
</div>
2023-02-08 15:43:14 +01:00
</Draggable>
);
}