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-basic-modal-dialog

v0.1.4

Published

A simple modal dialog react component built with the HTML dialog element.

Downloads

21

Readme

React basic modal dialog

A simple modal dialog react component built with the HTML dialog element.

Disclaimer and acknowledgement

This package was created as a training project. The code is inspired from this article.

Features

  • Generic
  • Lightweight
  • Accessible
  • Closes with outside click or ESC key (consider adding a close button for accessibility)
  • Easy to style
  • Includes a ::backdrop pseudo-element for behind the element

Installation

Install the package from npm

$ npm install react-basic-modal-dialog

Examples

Basic example

import { useState } from "react";
import ModalDialog from "react-basic-modal-dialog";

export default function Example() {
  // The only two required props for the modal dialog are isDialogVisible
  // (to indicate whether the dialog should be visible or not) and closeDialog
  // (a function setting isDialogVisible to false). Let's create them below.

  const [isDialogVisible, setIsDialogVisible] = useState(false);
  const openDialog = () => setIsDialogVisible(true);
  const closeDialog = () => setIsDialogVisible(false);

  // And here is a simple silly example of the modal dialog being used

  return (
    <>
      <button onClick={openDialog}>Open modal dialog</button>

      <ModalDialog isDialogVisible={isDialogVisible} closeDialog={closeDialog}>
        <p>You can put whatever content you want here.</p>
        <p>A button to close the dialog sounds like a good idea.</p>
        <button onClick={closeDialog}>Close</button>
      </ModalDialog>
    </>
  );
}

Styling with classes (using tailwind css in this example)

import { useState } from "react";
import ModalDialog from "react-basic-modal-dialog";

export default function Example() {
  const [isDialogVisible, setIsDialogVisible] = useState(false);
  const openDialog = () => setIsDialogVisible(true);
  const closeDialog = () => setIsDialogVisible(false);

  return (
    <>
      <button onClick={openDialog}>Open modal dialog</button>
      <ModalDialog
        isDialogVisible={isDialogVisible}
        closeDialog={closeDialog}
        dialogClassName="max-w-md rounded-xl p-0 backdrop:bg-black/60"
        contentClassName="flex flex-col p-6 gap-2 justify-between items-center"
      >
        <h2 className="text-lg font-semibold">A dialog with class</h2>
        <p className="text-sm text-gray-600	text-center">
          I'm a dialog that's been styled using tailwind css classes
        </p>
        <button
          className="w-full bg-gray-600 text-white font-semibold p-2.5 mt-4 rounded-lg"
          onClick={closeDialog}
        >
          Close
        </button>
      </ModalDialog>
    </>
  );
}

Properties

<ModalDialog

  isDialogVisible={
  /* Boolean describing if the dialog should be shown or not */}

  closeDialog={
  /* Function that closes the dialog (sets isDialogVisible to false) */}

  dialogClassName={
  /* String with space-separated class names that will be applied to the dialog element */}

  contentClassName={
  /* String with space-separated class names that will be applied to the content div
  inside the dialog element */}

>

</ModalDialog>