mirror of
https://github.com/status-im/MyCrypto.git
synced 2025-02-02 22:34:44 +00:00
9cac0298a2
* Manage modal focus * Add isOpen prop to CustomNodeModal * Remove outline overrides * Update outline style for inputs * Fix modal focus management & Cleanup CustomNodeModal * Add aria-label on modal close button * Fix modal scroll to top * Add aria-live property for notifications * Add aria-busy to Spinner component * Fix border styles for generatewallet password inputs * Update token balances inputs * Remove multiple h1's & Update styles * Add alt text to all img elements * Update swap link from bity to shapeshift * Update aria-labels and alt text * Only show keystore password input when required * Revert "Only show keystore password input when required" This reverts commit 7ec5de52da0982cd3131f365b142f6915638d831. * address changes requested
71 lines
1.8 KiB
TypeScript
71 lines
1.8 KiB
TypeScript
import React, { PureComponent } from 'react';
|
|
import { CSSTransition, TransitionGroup } from 'react-transition-group';
|
|
import ModalBody from './ModalBody';
|
|
import './index.scss';
|
|
|
|
export interface IButton {
|
|
text: string | React.ReactElement<string>;
|
|
type?: 'default' | 'primary' | 'success' | 'info' | 'warning' | 'danger' | 'link';
|
|
disabled?: boolean;
|
|
onClick?(): void;
|
|
}
|
|
interface Props {
|
|
isOpen?: boolean;
|
|
title?: string;
|
|
disableButtons?: boolean;
|
|
children: any;
|
|
buttons?: IButton[];
|
|
maxWidth?: number;
|
|
handleClose(): void;
|
|
}
|
|
interface ModalStyle {
|
|
width?: string;
|
|
maxWidth?: string;
|
|
}
|
|
|
|
const Fade = ({ children, ...props }: any) => (
|
|
<CSSTransition {...props} timeout={300} classNames="animate-modal">
|
|
{children}
|
|
</CSSTransition>
|
|
);
|
|
|
|
export default class Modal extends PureComponent<Props, {}> {
|
|
public modalBody: ModalBody;
|
|
|
|
public componentDidUpdate(prevProps: Props) {
|
|
if (prevProps.isOpen !== this.props.isOpen) {
|
|
document.body.classList.toggle('no-scroll', !!this.props.isOpen);
|
|
}
|
|
}
|
|
|
|
public componentWillUnmount() {
|
|
document.body.classList.remove('no-scroll');
|
|
}
|
|
|
|
public render() {
|
|
const { isOpen, title, children, buttons, handleClose, maxWidth } = this.props;
|
|
const hasButtons = buttons && buttons.length;
|
|
const modalStyle: ModalStyle = {};
|
|
|
|
if (maxWidth) {
|
|
modalStyle.width = '100%';
|
|
modalStyle.maxWidth = `${maxWidth}px`;
|
|
}
|
|
|
|
const modalBodyProps = { title, children, modalStyle, hasButtons, buttons, handleClose };
|
|
|
|
return (
|
|
<TransitionGroup>
|
|
{isOpen && (
|
|
<Fade>
|
|
<div>
|
|
<div className="Modal-overlay" onClick={handleClose} />
|
|
<ModalBody {...modalBodyProps} ref={div => (this.modalBody = div as ModalBody)} />
|
|
</div>
|
|
</Fade>
|
|
)}
|
|
</TransitionGroup>
|
|
);
|
|
}
|
|
}
|