Skip to content

Commit

Permalink
s
Browse files Browse the repository at this point in the history
  • Loading branch information
agsulimko committed Sep 15, 2023
1 parent e084393 commit 555c549
Show file tree
Hide file tree
Showing 5 changed files with 196 additions and 63 deletions.
17 changes: 13 additions & 4 deletions src/components/App.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React, { Component } from 'react'
import Searchbar from './Searchbar/Searchbar'
// import Modal from './Modal/Modal'
import Modal from './Modal/Modal'
// import Button from './Button/Button';
import ImageGallery from './ImageGallery/ImageGallery';
// import styled from 'styled-components'
Expand All @@ -18,10 +18,19 @@ import Searchbar from './Searchbar/Searchbar'
currentPage: 1,
error: null,
isLoading: false,
// isShowModal: false,
};

componentDidMount;

state = { }

// toggleModal = () => {
// this.setState((prev) => ({ isShowModal: !prev.isShowModal }))
// }



componentDidUpdate(prevProps, prevState) {
if (
this.state.currentPage !== prevState.currentPage ||
Expand Down Expand Up @@ -79,11 +88,11 @@ render() {
{/* <Button /> */}
{/* <Loader /> */}

{/*
{showModal && <Modal onClose={this.toggleModal} > <h2>Modal Hallo</h2>
<Modal> </Modal>
{/* {showModal && <Modal onClose={this.toggleModal} > <h2>Modal Hallo</h2>
<p>Lorem, ipsum dolor sit amet consectetur adipisicing elit. Reprehenderit, molestias assumenda aliquid incidunt corrupti a pariatur ratione rerum numquam alias omnis in non totam voluptatum quas voluptatem! Non, aspernatur? Suscipit!</p>
<button type='button' onClick={this.toggleModal}>Close modal</button>
</Modal> } */}
</Modal> } */}

</Container>
)
Expand Down
141 changes: 82 additions & 59 deletions src/components/Modal/Modal.jsx
Original file line number Diff line number Diff line change
@@ -1,78 +1,101 @@
// import * as React from 'react';
import React, { Component } from 'react'
import css from './Modal.module.css'
import {createPortal} from 'react-dom';
import Box from '@mui/material/Box';
import Button from '@mui/material/Button';
import Typography from '@mui/material/Typography';
import Modal from '@mui/material/Modal';

const style = {
position: 'absolute',
top: '50%',
left: '50%',
transform: 'translate(-50%, -50%)',
width: 400,
bgcolor: 'background.paper',
border: '2px solid #000',
boxShadow: 24,
p: 4,
};

export default function BasicModal() {
const [open, setOpen] = React.useState(false);
const handleOpen = () => setOpen(true);
const handleClose = () => setOpen(false);

const modalRoot= document.querySelector('#modal-root');
export default class Modal extends Component {
return (
<div>
<Button onClick={handleOpen}>Open modal</Button>
<Modal
open={open}
onClose={handleClose}
aria-labelledby="modal-modal-title"
aria-describedby="modal-modal-description"
>
<Box sx={style}>
<Typography id="modal-modal-title" variant="h6" component="h2">
<img src="https://cdn.pixabay.com/user/2018/06/27/01-23-02-27_250x250.jpg" alt="Image" style={{ width: '100%' }} />
Text in a modal
</Typography>
<Typography id="modal-modal-description" sx={{ mt: 2 }}>
Duis mollis, est non commodo luctus, nisi erat porttitor ligula.
</Typography>
</Box>
</Modal>
</div>
);
}




// import React, { Component } from 'react'
// import css from './Modal.module.css'
// import {createPortal} from 'react-dom';



// const modalRoot= document.querySelector('#modal-root');
// export default class Modal extends Component {


componentDidMount() {
console.log(' modal DidMount');
// componentDidMount() {
// console.log(' modal DidMount');

document.addEventListener('keydown', this.handleKeyEsc);
};
// document.addEventListener('keydown', this.handleKeyEsc);
// };


componentWillUnmount() {
console.log('modal WillUnmount ');
document.removeEventListener('keydown', this.handleKeyEsc)
}
// componentWillUnmount() {
// console.log('modal WillUnmount ');
// document.removeEventListener('keydown', this.handleKeyEsc)
// }

handleKeyEsc = (e) => {
if (e.code === 'Escape') this.props.onClose()
// console.log('Esc');
}
handlBackdropClick= event =>{
console.log('BackdropClick');
if(event.target===event.currentTarget) {
this.props.onClose();
}
}
// handleKeyEsc = (e) => {
// if (e.code === 'Escape') this.props.onClose()
// // console.log('Esc');
// }
// handlBackdropClick= event =>{
// console.log('BackdropClick');
// if(event.target===event.currentTarget) {
// this.props.onClose();
// }
// }

// const { children, toggleModal } = this.props
render() {
return createPortal(
<div className={css.modalBackdrop} onClick={this.handlBackdropClick}>
<div className={css.modalContent}>{this.props.children} </div>
</div>,
modalRoot,
);
}

}

// // const { children, toggleModal } = this.props
// render() {
// return createPortal(
// <div className={css.modalBackdrop} onClick={this.handlBackdropClick}>
// <div className={css.modalContent}>{this.props.children} </div>
// </div>,
// modalRoot,
// );
// }

// }






// const Modal = ({ children}) => {
// return (
// <div
// className='modal fade show'
// style={{ display: 'block', backdropFilter: 'blur(5px)' }}
// // onClick={toggleModal}
// >
// <div className='modal-dialog'>
// <div className='modal-content'>
// <div className='modal-header'>
// <h5 className='modal-title'> Modal</h5>
// <button
// type='button'
// className='btn-close'
// aria-label='Close'
// // onClick={toggleModal}
// ></button>
// </div>
// <div className='modal-body'>{children}</div>
// </div>
// </div>
// </div>
// )
// }

// export default Modal
78 changes: 78 additions & 0 deletions src/components/ModalOld/Modal.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
import React, { Component } from 'react'
import css from './Modal.module.css'
import {createPortal} from 'react-dom';



const modalRoot= document.querySelector('#modal-root');
export default class Modal extends Component {


componentDidMount() {
console.log(' modal DidMount');

document.addEventListener('keydown', this.handleKeyEsc);
};


componentWillUnmount() {
console.log('modal WillUnmount ');
document.removeEventListener('keydown', this.handleKeyEsc)
}

handleKeyEsc = (e) => {
if (e.code === 'Escape') this.props.onClose()
// console.log('Esc');
}
handlBackdropClick= event =>{
console.log('BackdropClick');
if(event.target===event.currentTarget) {
this.props.onClose();
}
}

// const { children, toggleModal } = this.props
render() {
return createPortal(
<div className={css.modalBackdrop} onClick={this.handlBackdropClick}>
<div className={css.modalContent}>{this.props.children} </div>
</div>,
modalRoot,
);
}

}








// const Modal = ({ children}) => {
// return (
// <div
// className='modal fade show'
// style={{ display: 'block', backdropFilter: 'blur(5px)' }}
// // onClick={toggleModal}
// >
// <div className='modal-dialog'>
// <div className='modal-content'>
// <div className='modal-header'>
// <h5 className='modal-title'> Modal</h5>
// <button
// type='button'
// className='btn-close'
// aria-label='Close'
// // onClick={toggleModal}
// ></button>
// </div>
// <div className='modal-body'>{children}</div>
// </div>
// </div>
// </div>
// )
// }

// export default Modal
23 changes: 23 additions & 0 deletions src/components/ModalOld/Modal.module.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
.modalBackdrop{
position: fixed;
top: 25%;
left: 25%;
width:50% ;
height: 50%;
background-color: rgb(195, 195, 222);
border-radius: 5px;
border: 0.5px solid ;
border-color: brown;
/* z-index: 999; */
}

.modalContent {
position: absolute;
top:50%;
left: 50%;
transform: translate(-50%, -50%);
background-color: white;
/* max-width: 600px;
min-height: 300px;
border-radius: 5px; */
}
File renamed without changes.

0 comments on commit 555c549

Please sign in to comment.