diff --git a/package.json b/package.json index 0aee006..45a527b 100644 --- a/package.json +++ b/package.json @@ -16,8 +16,10 @@ "@emotion/react": "^11.14.0", "@emotion/styled": "^11.14.0", "@mui/material": "^7.0.1", + "re-resizable": "^6.11.2", "react": "19.1.0", "react-dom": "19.1.0", + "react-draggable": "^4.4.6", "react-hook-form": "^7.55.0" }, "exports": { diff --git a/src/drag-modal/index.tsx b/src/drag-modal/index.tsx new file mode 100644 index 0000000..0a767c2 --- /dev/null +++ b/src/drag-modal/index.tsx @@ -0,0 +1,65 @@ +import { useRef } from 'react'; +import Draggable from 'react-draggable'; +import { clsxMerge } from '../clsx'; +import { Resizable } from 're-resizable'; + +type DragModalProps = { + title?: React.ReactNode; + content?: React.ReactNode; + onClose?: () => void; + containerClassName?: string; + handleClassName?: string; + contentClassName?: string; + /** + * 默认大小, 单位为px + * width: defaultSize.width || 320 + * height: defaultSize.height || 400 + */ + defaultSize?: { + width: number; + height: number; + }; + style?: React.CSSProperties; +}; +export const DragModal = (props: DragModalProps) => { + const dragRef = useRef(null); + + return ( + { + console.log(e, data); + }} + handle='.handle' + grid={[1, 1]} + scale={1} + bounds='parent' + defaultPosition={{ + x: 0, + y: 0, + }}> +
+
{props.title || 'Move'}
+ { + // console.log(e, direction, ref, d); + }} + enable={{ + bottom: true, + right: true, + bottomRight: true, + }}> + {props.content} + +
+
+ ); +}; diff --git a/src/render/ReactRender.tsx b/src/render/ReactRender.tsx new file mode 100644 index 0000000..b953030 --- /dev/null +++ b/src/render/ReactRender.tsx @@ -0,0 +1,40 @@ +import React from 'react'; +import { createRoot } from 'react-dom/client'; + +export class ReactRenderer { + component: any; + element: HTMLElement; + ref: React.RefObject; + props: any; + root: any; + + constructor(component: any, { props }: any) { + this.component = component; + this.element = document.createElement('div'); + this.ref = React.createRef(); + this.props = { + ...props, + ref: this.ref, + }; + this.root = createRoot(this.element); + this.render(); + } + + updateProps(props: any) { + this.props = { + ...this.props, + ...props, + }; + this.render(); + } + + render() { + this.root.render(React.createElement(this.component, this.props)); + } + + destroy() { + this.root.unmount(); + } +} + +export default ReactRenderer;