UNPKG

plot-plan-designer

Version:

Design Editor Tools with React.js + ant.design + fabric.js

50 lines (49 loc) 2.58 kB
import React, { useEffect, useRef, useState } from 'react'; import PropTypes from 'prop-types'; import { Modal, Form, Input } from 'antd'; import Canvas from '../../canvas/Canvas'; import DataSourceProperty from '../properties/DataSourceProperty'; const DataSourceModal = ({ visible, animation = {}, onOk, onCancel, onChange, validateTitle }) => { const [form] = Form.useForm(); const containerRef = useRef(null); const canvasRef = useRef(null); const [dimensions, setDimensions] = useState({ width: 150, height: 150 }); useEffect(() => { const waitForContainerRender = (container) => { if (!container) { setTimeout(() => waitForContainerRender(containerRef.current), 5); return; } const width = container.clientWidth; const height = container.clientHeight; setDimensions({ width, height }); }; if (visible) { waitForContainerRender(containerRef.current); } }, [visible]); useEffect(() => { if (visible) { form.resetFields(); } }, [animation, visible, form]); return (React.createElement(Modal, { open: visible, onOk: onOk, onCancel: onCancel, title: "Data Source", destroyOnClose: true }, React.createElement(Form, { form: form, layout: "vertical" }, React.createElement(Form.Item, { label: "Title", required: true, hasFeedback: true, colon: false, help: validateTitle === null || validateTitle === void 0 ? void 0 : validateTitle.help, validateStatus: validateTitle === null || validateTitle === void 0 ? void 0 : validateTitle.validateStatus }, React.createElement(Input, { value: animation.title, onChange: (e) => { const updatedTitle = e.target.value; onChange === null || onChange === void 0 ? void 0 : onChange(null, { animation: { title: updatedTitle } }, { animation: Object.assign(Object.assign({}, animation), { title: updatedTitle }) }); } })), DataSourceProperty.render(canvasRef.current, form, { animation })), React.createElement("div", { ref: containerRef }, React.createElement(Canvas, { ref: canvasRef, editable: false, width: dimensions.width, height: dimensions.height })))); }; DataSourceModal.propTypes = { visible: PropTypes.bool, animation: PropTypes.object, onOk: PropTypes.func, onCancel: PropTypes.func, onChange: PropTypes.func, validateTitle: PropTypes.object, }; export default DataSourceModal;