Research
Security News
Kill Switch Hidden in npm Packages Typosquatting Chalk and Chokidar
Socket researchers found several malicious npm packages typosquatting Chalk and Chokidar, targeting Node.js developers with kill switches and data theft.
@types/react-modal
Advanced tools
@types/react-modal provides TypeScript type definitions for the react-modal library, which is a popular library for creating accessible modal dialogs in React applications.
Basic Modal Usage
This code demonstrates the basic usage of react-modal with TypeScript. It shows how to open and close a modal dialog.
import React from 'react';
import Modal from 'react-modal';
const App: React.FC = () => {
const [modalIsOpen, setIsOpen] = React.useState(false);
function openModal() {
setIsOpen(true);
}
function closeModal() {
setIsOpen(false);
}
return (
<div>
<button onClick={openModal}>Open Modal</button>
<Modal
isOpen={modalIsOpen}
onRequestClose={closeModal}
contentLabel="Example Modal"
>
<h2>Hello</h2>
<button onClick={closeModal}>close</button>
</Modal>
</div>
);
};
export default App;
Custom Styles
This code demonstrates how to apply custom styles to the modal dialog using the style prop.
import React from 'react';
import Modal from 'react-modal';
const customStyles = {
content: {
top: '50%',
left: '50%',
right: 'auto',
bottom: 'auto',
marginRight: '-50%',
transform: 'translate(-50%, -50%)'
}
};
const App: React.FC = () => {
const [modalIsOpen, setIsOpen] = React.useState(false);
function openModal() {
setIsOpen(true);
}
function closeModal() {
setIsOpen(false);
}
return (
<div>
<button onClick={openModal}>Open Modal</button>
<Modal
isOpen={modalIsOpen}
onRequestClose={closeModal}
style={customStyles}
contentLabel="Example Modal"
>
<h2>Hello</h2>
<button onClick={closeModal}>close</button>
</Modal>
</div>
);
};
export default App;
Accessibility Features
This code demonstrates how to set the app element for accessibility purposes, ensuring that screen readers can properly interact with the modal.
import React from 'react';
import Modal from 'react-modal';
Modal.setAppElement('#root');
const App: React.FC = () => {
const [modalIsOpen, setIsOpen] = React.useState(false);
function openModal() {
setIsOpen(true);
}
function closeModal() {
setIsOpen(false);
}
return (
<div>
<button onClick={openModal}>Open Modal</button>
<Modal
isOpen={modalIsOpen}
onRequestClose={closeModal}
contentLabel="Example Modal"
>
<h2>Hello</h2>
<button onClick={closeModal}>close</button>
</Modal>
</div>
);
};
export default App;
react-bootstrap provides a set of React components built using Bootstrap. It includes a Modal component that offers similar functionality to react-modal but with Bootstrap styling and additional features.
material-ui is a popular React UI framework that includes a Dialog component. It provides a wide range of customization options and integrates well with the Material Design system.
semantic-ui-react offers a collection of React components based on Semantic UI. It includes a Modal component that provides similar functionality to react-modal with Semantic UI styling.
npm install --save @types/react-modal
This package contains type definitions for react-modal (https://github.com/reactjs/react-modal).
Files were exported from https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/react-modal.
ReactModal
These definitions were written by Rajab Shakirov, Drew Noakes, Thomas B Homburg, Tatu Tamminen, Uwe Wiemer, Peter Blazejewicz, Justin Powell, Juwan Wheatley, and Nitzan Mousan.
FAQs
TypeScript definitions for react-modal
We found that @types/react-modal 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.
Research
Security News
Socket researchers found several malicious npm packages typosquatting Chalk and Chokidar, targeting Node.js developers with kill switches and data theft.
Security News
pnpm 10 blocks lifecycle scripts by default to improve security, addressing supply chain attack risks but sparking debate over compatibility and workflow changes.
Product
Socket now supports uv.lock files to ensure consistent, secure dependency resolution for Python projects and enhance supply chain security.