Socket
Socket
Sign inDemoInstall

@types/react-modal

Package Overview
Dependencies
Maintainers
1
Versions
43
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@types/react-modal

TypeScript definitions for react-modal


Version published
Weekly downloads
742K
decreased by-2.21%
Maintainers
1
Weekly downloads
 
Created

What is @types/react-modal?

@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.

What are @types/react-modal's main functionalities?

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;

Other packages similar to @types/react-modal

FAQs

Package last updated on 07 Nov 2023

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc