Security News
tea.xyz Spam Plagues npm and RubyGems Package Registries
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
modal-top
Advanced tools
Readme
$ npm install react-top-modal
$ yarn install react-top-modal
Link to access the package here
Import the Modal component and useModal Hook in your React components:
import { Modal, useModal } from "react-top-modal";
After you've imported the Modal component and useModal Hook, you're ready to start using Modal inside your components! 🎉 (isOpen & close are required)
import React from "react";
import Modal, { useModal } from "react-top-modal";
const App = () => {
const { showModal, activeModal, handleOpenModal, handleCloseModal } = useModal();
return (
<>
<button type="button" className="buttonDefault" onClick={() => handleOpenModal("classic")}>
Modal (classic Modal)
</button>
<Modal isOpen={showModal && activeModal === "classic"} close={handleCloseModal}>
<h2>classic</h2>
</Modal>
</>
);
};
export default App;
Props | Type | Required | Default | Description |
---|---|---|---|---|
isOpen | Object | Required | - | An object containing two props, 'showModal' & 'activeModal', this object passed to modal allows to display it |
showModal | Bool | Required | False | State allows you to display the modal |
activeModal | String | Required | - | Add a string to identify which modal should be opened |
Close | Function | Required | - | Function allows you to remove the modal |
addCloseEscape | Bool | Optional | False | Allows to add the functionality of modal closure using the 'Esc' key |
addCloseOverlay | Bool | Optional | False | Allows to add the functionality of modal closing by clicking on the overlay |
addCloseIcon | Bool | Optional | True | If true, a closing icon will be displayed in the header of the modal |
customClassName | String | Optional | - | Allows you to customize the class name of each element |
addFooterButton | Bool | Optional | False | If true, a close button will be displayed in the footer of the modal |
spinner | Bool | Optional | False | Allows to add a loader which will be displayed during the loading of the modal |
You have the possibility to add the functionality of modal closure using the 'Esc' key by adding the props 'addCloseEsc' with the value 'true'.
import React from "react";
import Modal, { useModal } from "react-top-modal";
const App = () => {
const { showModal, activeModal, handleOpenModal, handleCloseModal } = useModal();
return (
<>
<button type="button" className="buttonDefault" onClick={() => handleOpenModal("closeEscape")}>
Modal (with closeEscape)
</button>
<Modal isOpen={showModal && activeModal === "closeEscape"} close={handleCloseModal} addCloseEscape={true}>
<h2>closeEscape</h2>
</Modal>
</>
);
};
export default App;
You have the option to add the functionality of modal closing using the overlay click by adding the props 'addCloseOverlay' with the value 'true'.
import React from "react";
import Modal, { useModal } from "react-top-modal";
const App = () => {
const { showModal, activeModal, handleOpenModal, handleCloseModal } = useModal();
return (
<>
<button type="button" className="buttonDefault" onClick={() => handleOpenModal("closeOverlay")}>
Modal (with closeOverlay)
</button>
<Modal isOpen={showModal && activeModal === "closeOverlay"} close={handleCloseModal} addCloseOverlay={true}>
<h2>closeOverlay</h2>
</Modal>
</>
);
};
export default App;
You have the possibility to add a close button in the footer by adding the props 'addFooterButton' with the value 'true'.
import React from "react";
import Modal, { useModal } from "react-top-modal";
const App = () => {
const { showModal, activeModal, handleOpenModal, handleCloseModal } = useModal();
return (
<>
<button type="button" className="buttonDefault" onClick={() => handleOpenModal("footerButton")}>
Modal (with footerButton)
</button>
<Modal isOpen={showModal && activeModal === "footerButton"} close={handleCloseModal} addFooterButton={true} addCloseIcon={false}>
<h2>footerButton</h2>
</Modal>
</>
);
};
export default App;
You have the option to add a spinner when you expect an asynchronous function. Launch the spinner, the toggle will automatically close it and make the modal appear once your data has been recovered.
import React from "react";
import Modal, { useModal } from "react-top-modal";
const App = () => {
const { showModal, activeModal, handleOpenModal, handleCloseModal, isLoading, toggleSpinner } = useModal();
const spinnerTimer = () => {
toggleSpinner();
setTimeout(() => {
handleOpenModal("spinner");
}, 1000);
};
return (
<>
<button type="button" className="buttonDefault" onClick={spinnerTimer}>
Modal (with spinner 1s)
</button>
<Modal isOpen={showModal && activeModal === "spinner"} close={handleCloseModal} spinner={isLoading}>
<h2>spinner</h2>
</Modal>
</>
);
};
export default App;
FAQs
React component to easily create customizable modals
The npm package modal-top receives a total of 1 weekly downloads. As such, modal-top popularity was classified as not popular.
We found that modal-top demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
Security News
As cyber threats become more autonomous, AI-powered defenses are crucial for businesses to stay ahead of attackers who can exploit software vulnerabilities at scale.
Security News
UnitedHealth Group disclosed that the ransomware attack on Change Healthcare compromised protected health information for millions in the U.S., with estimated costs to the company expected to reach $1 billion.