Skip to content

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
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions src/components/Modal/Modal.jsx
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) => {
Copy link
Contributor

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 the ESLint plugin from this link;

Copy link
Contributor

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 the master and then push the code.

Copy link
Author

@rosensteinsamuel1 rosensteinsamuel1 Jul 8, 2020

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 uses 7.4.0. Did you see this?
Screen Shot 2020-07-08 at 4 34 02 PM
I deleted the node_modules and package-lock.json and reinstalled but it didn't help. Thanks for the help.

Copy link
Contributor

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.

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 = {
isOpen: PropTypes.bool,
};

Modal.defaultProps = {
isOpen: false,
};
31 changes: 31 additions & 0 deletions src/components/Modal/Modal.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
.modal__wrapper {
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;
}
11 changes: 11 additions & 0 deletions src/components/Modal/Modal.test.jsx
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();
});
});
5 changes: 0 additions & 5 deletions src/demos/DemoDisplay.jsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
/* eslint-disable no-console */
import React from 'react';
import PropTypes from 'prop-types';

import './DemoDisplay.scss';

const importView = (DemoComponentName) =>
React.lazy(() =>
Expand Down
42 changes: 42 additions & 0 deletions src/demos/ModalDemo.jsx
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;
13 changes: 6 additions & 7 deletions src/docs/avatar.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
## Usage
## Usage

```
import React from 'react'
Expand All @@ -17,11 +17,10 @@ export default App;

### Properties

| Property | Type | Required | Default value | Description |
|----------|--------|----------|---------------|------------|
| name | string | yes | \- |Alternative text description of the image or Title avatar|
| src | string | no | \- |Image to display.|
| size | string | no | md | sx, sm, md, lg and xl font sizes. |

| Property | Type | Required | Default value | Description |
| -------- | ------ | -------- | ------------- | --------------------------------------------------------- |
| name | string | yes | \- | Alternative text description of the image or Title avatar |
| src | string | no | \- | Image to display. |
| size | string | no | md | sx, sm, md, lg and xl font sizes. |

### Sample
54 changes: 54 additions & 0 deletions src/docs/modal.md
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
1 change: 1 addition & 0 deletions src/exports/exports.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ export { default as SimpleButtonDemo } from '../demos/SimpleButtonDemo';
export { default as HeadingDemo } from '../demos/HeadingDemo';
export { default as AvatarDemo } from '../demos/AvatarDemo';
export { default as ProgressBarDemo } from '../demos/ProgressBarDemo';