Skip to content

feat: Allow config parameter dialog to be resized in width #2838

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 6 commits into
base: alpha
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 47 additions & 2 deletions src/components/Modal/Modal.react.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import React from 'react';
import PropTypes from 'lib/PropTypes';
import styles from 'components/Modal/Modal.scss';
import { useState, useEffect, useRef } from 'react';

const origin = new Position(0, 0);
const buttonColors = {
Expand All @@ -38,12 +39,55 @@
progress = false,
customFooter,
textModal = false,
width,
width: initialWidth = 500,
continueText,
onContinue,
showContinue,
buttonsInCenter = React.Children.count(children) === 0,
}) => {

const modalRef = useRef(null);

const [currentWidth, setCurrentWidth] = useState(initialWidth);
const resizing = useRef(false);

const handleMouseDown = (e) => {
e.preventDefault();

Check failure on line 55 in src/components/Modal/Modal.react.js

View workflow job for this annotation

GitHub Actions / Lint

Expected indentation of 4 spaces but found 2
resizing.current = true;

Check failure on line 56 in src/components/Modal/Modal.react.js

View workflow job for this annotation

GitHub Actions / Lint

Expected indentation of 4 spaces but found 2
if (modalRef.current) {

Check failure on line 57 in src/components/Modal/Modal.react.js

View workflow job for this annotation

GitHub Actions / Lint

Expected indentation of 4 spaces but found 2
modalRef.current.classList.add(styles.noTransition);

Check failure on line 58 in src/components/Modal/Modal.react.js

View workflow job for this annotation

GitHub Actions / Lint

Expected indentation of 6 spaces but found 4
}

Check failure on line 59 in src/components/Modal/Modal.react.js

View workflow job for this annotation

GitHub Actions / Lint

Expected indentation of 4 spaces but found 2
};

Check failure on line 60 in src/components/Modal/Modal.react.js

View workflow job for this annotation

GitHub Actions / Lint

Expected indentation of 2 spaces but found 0

const handleMouseMove = (e) => {

Check failure on line 62 in src/components/Modal/Modal.react.js

View workflow job for this annotation

GitHub Actions / Lint

Expected indentation of 2 spaces but found 0
if (!resizing.current || !modalRef.current) {

Check failure on line 63 in src/components/Modal/Modal.react.js

View workflow job for this annotation

GitHub Actions / Lint

Expected indentation of 4 spaces but found 2
return;

Check failure on line 64 in src/components/Modal/Modal.react.js

View workflow job for this annotation

GitHub Actions / Lint

Expected indentation of 6 spaces but found 4
}

Check failure on line 65 in src/components/Modal/Modal.react.js

View workflow job for this annotation

GitHub Actions / Lint

Expected indentation of 4 spaces but found 2

const modalLeft = modalRef.current.getBoundingClientRect().left;
const newWidth = e.clientX - modalLeft;

const clampedWidth = Math.min(window.innerWidth, Math.max(initialWidth, newWidth));
setCurrentWidth(clampedWidth);
};

const handleMouseUp = () => {
resizing.current = false;
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);
};
}, []);

if (children) {
children = React.Children.map(children, c => {
if (c && c.type === Field && c.props.label) {
Expand Down Expand Up @@ -81,7 +125,7 @@

return (
<Popover fadeIn={true} fixed={true} position={origin} modal={true} color="rgba(17,13,17,0.8)">
<div className={[styles.modal, styles[type]].join(' ')} style={{ width }}>
<div ref={modalRef} className={[styles.modal, styles[type]].join(' ')} style={{ width: currentWidth }}>
<div className={styles.header}>
<div
style={{
Expand All @@ -100,6 +144,7 @@
</div>
{wrappedChildren}
{footer}
<div className={styles.resizeHandle} onMouseDown={handleMouseDown} />
</div>
</Popover>
);
Expand Down
15 changes: 15 additions & 0 deletions src/components/Modal/Modal.scss
Original file line number Diff line number Diff line change
Expand Up @@ -99,3 +99,18 @@
}

@include modalKeyframes();

.resizeHandle {
width: 16px;
height: 16px;
position: absolute;
bottom: 0;
right: 0;
cursor: se-resize;
background: rgba(255, 255, 255, 0.5);
z-index: 10;
}

.noTransition {
transition: none !important;
}
Loading