npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

react-ts-modal

v1.5.9

Published

The simplest modal manager for your react apps.

Downloads

32

Readme

React JS Modal

The simplest modal manager for your react apps.

Installation

You can get react js modal up and running simply with yarn or npm

npm install react-ts-modal --save
yarn add react-ts-modal

QuickStart

To get started, simply import the modal component.

import Modal from "react-ts-modal";

React JS modal also comes with styles you can apply for cool effects and transitions. It comes in both CSS and SCSS, so you can use whichever you prefer.

import "react-ts-modal/css/styles.scss";
// or
import "react-ts-modal/css/styles.css";

It's better to import the styles in a top-most component like App.js in create-react-app.

From there, you can start building your awesome modal.

react-ts-modal also has 100% typescript support as it's completely written in TypeScript.

import Modal from "react-ts-modal";

const MyAwesomeModal = () => {
  return (
    <Modal name="awesome-modal">
      <div>This is the modal content!</div>
    </Modal>
  );
};

const App = () => {
  return (
    <div className="application">
      ... all the stuff on this page
      <MyAwesomeModal />
      {/* used here to make sure it's present in the DOM */}
    </div>
  );
};

From here, you can trigger the modal by simply doing this

import { modal } from "react-ts-modal";

// show modal defined above
modal.show("awesome-modal");

// hide modal
modal.hide("awesome-modal");

// get modal instance in dom
const myModal = modal.find("awesome-modal");

// check if modal is open
modal.isOpen("awesome-modal");

That's it! A very easy to use project.

Watch out: <Modal> requires the name prop. When using TypeScript, the compiler will shout at you if you miss this :-(

Other available props for <Modal>

  • name: string ------------------ The name of the modal (required)
  • className?: string ------------ Modal className (optional)
  • close?: Function -------------- Custom modal close method (optional)
  • closeButton?: boolean --------- Show/hide modal close button (default true)
  • children: any ----------------- Modal contents (required)
  • show?: boolean ---------------- Manually show/hide modal (optional)
  • size?: string ----------------- Size of modal (optional, uses modal styling)
  • pageScroll?: boolean ---------- Enable/Disable page content scroll with modal active

You can find a "real-world" demo here source code here.

Leave a star, contribute or give your feedback on this package. Thanks.

Changelog

v1.1.0 - Apr 19, 2021

Added

  • modal.exists to check if modal exists in DOM

Fixed

Modal close button onClick fixed.

Changed

  • Warnings moved from modal.find to dependent methods.