MCPcopy Create free account
hub / github.com/DTStack/dt-react-component / InternalModal

Function InternalModal

src/modal/modal.tsx:34–149  ·  view source on GitHub ↗
({
    bodyStyle,
    banner,
    size = 'default',
    children,
    width,
    className,
    draggable = false,
    position,
    resizable = false,
    rect,
    loading = false,
    onRectChange,
    onPositionChange,
    modalRender,
    ...rest
}: ModalProps)

Source from the content-addressed store, hash-verified

32};
33
34export default function InternalModal({
35 bodyStyle,
36 banner,
37 size = 'default',
38 children,
39 width,
40 className,
41 draggable = false,
42 position,
43 resizable = false,
44 rect,
45 loading = false,
46 onRectChange,
47 onPositionChange,
48 modalRender,
49 ...rest
50}: ModalProps) {
51 const mergedDraggable = useMergeOption(draggable, { handle: '.ant-modal-header' });
52 const mergedResizable = useMergeOption(resizable, {
53 axis: 'both',
54 resizeHandles: ['s', 'w', 'e', 'n', 'ne', 'nw', 'sw', 'se'],
55 width: 400,
56 height: 400,
57 minConstraints: [400, 400],
58 handle: <Handler />,
59 });
60
61 const final = useMemo(() => {
62 if (mergedResizable.disabled)
63 return { width: width ?? getWidthFromSize(size), height: 'auto' };
64 return {
65 width: rect?.width || mergedResizable.options.width || 0,
66 height: rect?.height || mergedResizable.options.height || 0,
67 };
68 }, [mergedResizable, width, size, rect]);
69
70 const handleResize: ResizableProps['onResize'] = (e, data) => {
71 mergedResizable.options.onResize?.(e, data);
72
73 const nextSize = { width: data.size.width, height: data.size.height };
74 onRectChange?.(nextSize);
75
76 if (mergedDraggable.disabled || !position) return;
77 const vertical = data.handle.includes('n');
78 const horizontal = data.handle.includes('w');
79 const offsetY = vertical ? nextSize.height - (final.height as number) : 0;
80 const offsetX = horizontal ? nextSize.width - (final.width as number) : 0;
81 const after = {
82 x: position.x - offsetX,
83 y: position.y - offsetY,
84 };
85 // Prevent unnecessary update
86 if (after.x === position.x && after.y === position.y) return;
87 onPositionChange?.(after);
88 };
89
90 const handleRenderModal = (modal: React.ReactNode) => {
91 const container = modalRender?.(modal) || modal;

Callers

nothing calls this directly

Calls 3

isAlertObjectPropsFunction · 0.90
useMergeOptionFunction · 0.85
getWidthFromSizeFunction · 0.70

Tested by

no test coverage detected