Files
editor/src/components/Modal.tsx
Harel M 656264f2bc Migration of jsx files to tsx 3 (#851)
This is in continue to:
- #850
- #848

The last files should be converted as part of this PR, there are only a
handful left.
2023-12-25 15:48:46 +02:00

71 lines
1.9 KiB
TypeScript

import React from 'react'
import {MdClose} from 'react-icons/md'
import AriaModal from 'react-aria-modal'
import classnames from 'classnames';
type ModalProps = {
"data-wd-key"?: string
isOpen: boolean
title: string
onOpenToggle(value: boolean): unknown
underlayClickExits?: boolean
underlayProps?: any
className?: string
};
export default class Modal extends React.Component<ModalProps> {
static defaultProps = {
underlayClickExits: true
}
// See <https://github.com/maputnik/editor/issues/416>
onClose = () => {
if (document.activeElement) {
(document.activeElement as HTMLElement).blur();
}
setTimeout(() => {
this.props.onOpenToggle(false);
}, 0);
}
render() {
if(this.props.isOpen) {
return <AriaModal
titleText={this.props.title}
underlayClickExits={this.props.underlayClickExits}
// @ts-ignore
underlayProps={this.props.underlayProps}
data-wd-key={this.props["data-wd-key"]}
verticallyCenter={true}
onExit={this.onClose}
>
<div className={classnames("maputnik-modal", this.props.className)}
data-wd-key={this.props["data-wd-key"]}
>
<header className="maputnik-modal-header">
<h1 className="maputnik-modal-header-title">{this.props.title}</h1>
<span className="maputnik-modal-header-space"></span>
<button className="maputnik-modal-header-toggle"
title="Close modal"
onClick={this.onClose}
data-wd-key={this.props["data-wd-key"]+".close-modal"}
>
<MdClose />
</button>
</header>
<div className="maputnik-modal-scroller">
<div className="maputnik-modal-content">{this.props.children}</div>
</div>
</div>
</AriaModal>
}
else {
return false;
}
}
}