Skip to content

Commit

Permalink
fix(atoms): remove state from the modal
Browse files Browse the repository at this point in the history
  • Loading branch information
ej9x committed Aug 23, 2018
1 parent 5749210 commit e998a4b
Showing 1 changed file with 7 additions and 19 deletions.
26 changes: 7 additions & 19 deletions src/atoms/Modal/Modal.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import { createStyledTag, createTheme } from '../../utils';
type ModalProps = {
children: React$Node,
isOpen?: boolean,
onOpen?: (any) => void,
onClose?: (any) => void,
shouldCloseOnOverlayClick?: boolean,
};
Expand Down Expand Up @@ -36,18 +35,18 @@ const theme = createTheme(name, {
},
});

const OverlayTag = createStyledTag(name, {
const OverlayTag = createStyledTag(name, (props): * => ({
alignItems: 'center',
background: 'rgba(0, 0, 0, 0.5)',
bottom: 0,
display: 'flex',
justifyContent: 'center',
left: 0,
position: 'fixed',
right: 0,
top: 0,
zIndex: 1000,
});
background: 'rgba(0, 0, 0, 0.5)',
zIndex: props.theme.Z_INDEX.MODAL,
}));

const ModalTag = createStyledTag(name, {});

Expand All @@ -59,10 +58,6 @@ class Modal extends PureComponent<ModalProps, ModalState> {
isOpen: false,
};

state = {
isOpen: false,
};

componentDidMount() {
if (this.props.isOpen) {
this.openModal();
Expand All @@ -82,21 +77,15 @@ class Modal extends PureComponent<ModalProps, ModalState> {
}

openModal() {
if (!this.state.isOpen) {
if (!this.props.isOpen) {
Modal.openedModals += 1;

this.setState({ isOpen: true });

if (typeof this.props.onOpen === 'function') {
this.props.onOpen();
}

this.updateBlurClass();
}
}

closeModal() {
if (this.state.isOpen) {
if (this.props.isOpen) {
Modal.openedModals -= 1;

this.setState({ isOpen: false });
Expand Down Expand Up @@ -140,8 +129,7 @@ class Modal extends PureComponent<ModalProps, ModalState> {
};

render() {
const { children } = this.props;
const { isOpen } = this.state;
const { children, isOpen } = this.props;

return (
<If condition={ isOpen }>
Expand Down

0 comments on commit e998a4b

Please sign in to comment.