An open API service indexing awesome lists of open source software.

https://github.com/oth21dev/oxanatheis_14_15092022_modal

:sparkles: Modal - pop up plugin developped in React and published in npmjs.com
https://github.com/oth21dev/oxanatheis_14_15092022_modal

accessibility css3 dialog html5 javascript keyboard-navigation modal npm-package npm-publish popup react

Last synced: 2 months ago
JSON representation

:sparkles: Modal - pop up plugin developped in React and published in npmjs.com

Awesome Lists containing this project

README

          

[![MADE WITH - JAVASCRIPT](https://img.shields.io/badge/MADE_WITH-JAVASCRIPT-1D75C2?style=for-the-badge)](https://) [![STYLED - CSS](https://img.shields.io/badge/STYLED-CSS-E034BE?style=for-the-badge)](https://) ![BUILT WITH - REACT](https://img.shields.io/badge/BUILT_WITH-REACT-4F28B0?style=for-the-badge)

# Modal app - pop up plugin

This project is a React plugin allowing to display an alert in other words a pop up information.
Contains a smoth animation while appear on the screen and can be controlled by keyboard.

## NPM link
https://www.npmjs.com/package/react-modal-oth

## Installation

$ npm i react-modal-oth

$ yarn add react-modal-oth

## How the plugin works

- Import module :
```
import Modal from "react-modal-oth";
```

- Create your state in your component:
```
const [modalIsOpen, setModalIsOpen] = useState(true);
```

- Render your Modal in your component:

```
return ;
```

### ``` params:```

- icon : svg component used in the Modal (decoration purpose).

Import the svg component as:
```
import icon from "react-modal-oth/dist/assets/icon.svg";
```

- closeIcon : svg component used in the Modal - close icon.

Import the svg component as:
```
import close_icon from "react-modal-oth/dist/assets/close.svg";
```
- show : Boolean state use to show and hide the Modal
- setShow : function that updates the state
- title : Modal heading
- text: additional text information

## Example

```
import "./style.css";

const Modal = ({ icon, closeIcon, show, setShow, title, text }) => {

const handleKeydown = useCallback((e) => {
if (e.type === "click" || e.key === "Escape" || e.key === "Enter") {
setShow(false);
}
}, []);

useEffect(() => {
document.addEventListener("keydown", handleKeydown);

return () => {
document.removeEventListener("keydown", handleKeydown);
};
}, []);

return (
show && (
<>






handleKeydown(e)} onClick={(e) => handleKeydown(e)}>

{title}


{text}



handleKeydown(e)}>
OK{" "}




>
)
);
};
```

![modal](https://user-images.githubusercontent.com/81259062/190851870-c1d58c7e-98a0-45bc-8dd1-b5f760946756.gif)