-
Notifications
You must be signed in to change notification settings - Fork 23
added Modal component, demo, and docs #47
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
rosensteinsamuel1
wants to merge
3
commits into
NehemiahK:master
Choose a base branch
from
rosensteinsamuel1:modal-branch
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
|
||
import './Modal.scss'; | ||
|
||
const Modal = (props) => { | ||
if (props.isOpen) { | ||
return ( | ||
<div className="modal__wrapper"> | ||
<div className="modal__backdrop" /> | ||
<div className="modal__box">{props.children}</div> | ||
</div> | ||
); | ||
} | ||
return null; | ||
}; | ||
|
||
export default Modal; | ||
|
||
Modal.propTypes = { | ||
rosensteinsamuel1 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
isOpen: PropTypes.bool, | ||
}; | ||
|
||
Modal.defaultProps = { | ||
isOpen: false, | ||
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
.modal__wrapper { | ||
rosensteinsamuel1 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
position: fixed; | ||
top: 0; | ||
bottom: 0; | ||
left: 0; | ||
right: 0; | ||
} | ||
|
||
.modal__backdrop { | ||
position: fixed; | ||
top: 0; | ||
bottom: 0; | ||
left: 0; | ||
right: 0; | ||
z-index: 100; | ||
background-color: rgba(0, 0, 0, 0.3); | ||
} | ||
|
||
.modal__box { | ||
position: relative; | ||
top: 50%; | ||
left: 50%; | ||
transform: translate(-50%, -50%); | ||
height: 70%; | ||
width: 60%; | ||
background-color: white; | ||
box-shadow: 0 0 10px rgba(0, 0, 0, 0.25); | ||
z-index: 101; | ||
overflow-y: auto; | ||
padding: 40px; | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import React from 'react'; | ||
import { render } from '@testing-library/react'; | ||
|
||
import Modal from './Modal'; | ||
|
||
describe('<Modal>', () => { | ||
it('should create the component', () => { | ||
const { container } = render(<Modal />); | ||
expect(container).toBeTruthy(); | ||
}); | ||
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import React, { useState } from 'react'; | ||
import Modal from '../components/Modal/Modal'; | ||
|
||
function App() { | ||
const [isOpen, setIsOpen] = useState(false); | ||
|
||
const closeModalHandler = () => { | ||
setIsOpen(false); | ||
}; | ||
|
||
const openModalHandler = () => { | ||
setIsOpen(true); | ||
}; | ||
|
||
return ( | ||
<div className="App"> | ||
<button className="modal__btn-open" onClick={openModalHandler}> | ||
Open Modal | ||
</button> | ||
<Modal isOpen={isOpen}> | ||
<button className="modal__btn-close" onClick={closeModalHandler}> | ||
Close | ||
</button> | ||
<h1>Modal Header</h1> | ||
<p> | ||
Lorem ipsum dolor sit, amet consectetur adipisicing elit. Sint eum | ||
alias neque fuga asperiores, deleniti pariatur sapiente eligendi | ||
doloremque. Mollitia, facere tempora modi asperiores eum perspiciatis | ||
iste ipsum eaque explicabo. | ||
</p> | ||
<p> | ||
Lorem ipsum dolor sit amet consectetur adipisicing elit. Quasi odit | ||
ducimus similique quo a quis itaque hic, impedit atque voluptatem | ||
doloribus assumenda nulla saepe molestiae aliquid corrupti magnam sint | ||
laboriosam. | ||
</p> | ||
</Modal> | ||
</div> | ||
); | ||
} | ||
|
||
export default App; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
## Usage | ||
|
||
``` | ||
import React, { useState } from 'react'; | ||
import Modal from '../components/Modal/Modal'; | ||
|
||
function App() { | ||
const [isOpen, setIsOpen] = useState(false); | ||
|
||
const closeModalHandler = () => { | ||
setIsOpen(false); | ||
}; | ||
|
||
const openModalHandler = () => { | ||
setIsOpen(true); | ||
}; | ||
|
||
return ( | ||
<div className="App"> | ||
<button className="modal__btn-open" onClick={openModalHandler}> | ||
Open Modal | ||
</button> | ||
<Modal isOpen={isOpen}> | ||
<button className="modal__btn-close" onClick={closeModalHandler}> | ||
Close | ||
</button> | ||
<h1>Modal Header</h1> | ||
<p> | ||
Lorem ipsum dolor sit, amet consectetur adipisicing elit. Sint eum | ||
alias neque fuga asperiores, deleniti pariatur sapiente eligendi | ||
doloremque. Mollitia, facere tempora modi asperiores eum perspiciatis | ||
iste ipsum eaque explicabo. | ||
</p> | ||
<p> | ||
Lorem ipsum dolor sit amet consectetur adipisicing elit. Quasi odit | ||
ducimus similique quo a quis itaque hic, impedit atque voluptatem | ||
doloribus assumenda nulla saepe molestiae aliquid corrupti magnam sint | ||
laboriosam. | ||
</p> | ||
</Modal> | ||
</div> | ||
); | ||
} | ||
|
||
export default App; | ||
``` | ||
|
||
### Properties | ||
|
||
| Property | Type | Required | Default value | Description | | ||
| :------- | :------ | :------- | :------------ | :------------------------------------------ | | ||
| `isOpen` | Boolean | yes | none | set to true if the modal is to be displayed | | ||
|
||
### Sample |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we please destructure the props. Also, make sure the to install the new dependencies using
npm install
and install theESLint
plugin from this link;There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, if required take a pull from the
master
so that you have the latest code. Rebase your branch with themaster
and then push the code.Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@madhuni Thanks for the insights, I have implemented your suggestions. Regarding ES lint, when I start the project after installing the new dependencies I get an error that CRA uses

"eslint": "^6.6.0"
and the project uses7.4.0
. Did you see this?I deleted the node_modules and package-lock.json and reinstalled but it didn't help. Thanks for the help.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okie let me have a look. Will provide you the solution to resolve this. I didn't see any such problem.