diff --git a/src/components/Modal/Modal.react.js b/src/components/Modal/Modal.react.js index 9ffe0e47ab..73502c1e9e 100644 --- a/src/components/Modal/Modal.react.js +++ b/src/components/Modal/Modal.react.js @@ -10,7 +10,7 @@ import Field from 'components/Field/Field.react'; import Icon from 'components/Icon/Icon.react'; import Popover from 'components/Popover/Popover.react'; import Position from 'lib/Position'; -import React from 'react'; +import React, { useState, useEffect, useRef, useCallback } from 'react'; import PropTypes from 'lib/PropTypes'; import styles from 'components/Modal/Modal.scss'; @@ -39,11 +39,68 @@ const Modal = ({ customFooter, textModal = false, width, + initialWidth = width ?? 500, continueText, onContinue, showContinue, buttonsInCenter = React.Children.count(children) === 0, }) => { + const modalRef = useRef(null); + const [currentWidth, setCurrentWidth] = useState(initialWidth); + const resizing = useRef({ active: false, side: null, startX: 0, startWidth: 0 }); + + // Helper to get min width + const minWidth = initialWidth; + + const handleMouseDown = (side) => (e) => { + e.preventDefault(); + if (!modalRef.current) { + return; + } + resizing.current = { + active: true, + side, + startX: e.clientX, + startWidth: currentWidth, + }; + modalRef.current.classList.add(styles.noTransition); + }; + + const handleMouseMove = useCallback( + (e) => { + if (!resizing.current.active || !modalRef.current) { + return; + } + const { side, startX, startWidth } = resizing.current; + if (side === 'right') { + let newWidth = startWidth + 2 * (e.clientX - startX); + newWidth = Math.max(minWidth, newWidth); + setCurrentWidth(newWidth); + } else if (side === 'left') { + let newWidth = startWidth - 2 * (e.clientX - startX); + newWidth = Math.max(minWidth, newWidth); + setCurrentWidth(newWidth); + } + }, + [minWidth] + ); + + const handleMouseUp = useCallback(() => { + resizing.current = { active: false, side: null, startX: 0, startWidth: 0 }; + if (modalRef.current) { + modalRef.current.classList.remove(styles.noTransition); + } + }, []); + + useEffect(() => { + document.addEventListener('mousemove', handleMouseMove); + document.addEventListener('mouseup', handleMouseUp); + return () => { + document.removeEventListener('mousemove', handleMouseMove); + document.removeEventListener('mouseup', handleMouseUp); + }; + }, [handleMouseMove, handleMouseUp]); + if (children) { children = React.Children.map(children, c => { if (c && c.type === Field && c.props.label) { @@ -81,7 +138,25 @@ const Modal = ({ return ( -
+
+ {/* Left resize handle */} +
+ {/* Right resize handle */} +