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-html-dialog

v0.0.13

Published

This library allows you to easily use the HTML `<dialog>` in your react applications. Uses are similar to most Modal/Dialog libraries except this uses the native `<dialog>` element.

Downloads

5

Readme

React HTML-dialog

This library allows you to easily use the HTML <dialog> in your react applications. Uses are similar to most Modal/Dialog libraries except this uses the native <dialog> element.

Installation

You can install react-html-dialog via npm or yarn:

npm install react-html-dialog
# or
yarn add react-html-dialog

How to use

To use the component in your code, you can import the code in your app like this

import Dialog from "react-html-dialog";

Then you render the component with the dialog content as the children.

<Dialog open={false} handleClose={closeHandler}>
  <h2>Dialog Title</h2>
  <p>
    Lorem ipsum dolor sit amet, consectetur adipisicing elit. A quasi natus quas
    dolore alias optio tenetur perferendis, cupiditate animi ex, omnis quibusdam
    non est, ullam saepe doloremque aperiam quia. Recusandae.
  </p>
  <button>Close Modal</button>
</Dialog>

The component has two required props open and handleClose.

open: A boolean indicating whether the dialog is open or closed.

handleClose: A callback function to handle closing the dialog.

closeOnClickAway: An optional prop to close the dialog when clicking outside it

This library also provides you with some hooks you might love to use with the Dialog

import Dialog from "react-html-dialog";
import { useDialogControls } from "react-html-dialog/hooks";

function App() {
  const { open, openDialog, closeDialog } = useDialogControls();

  return (
    <>
      <button onClick={openDialog}>Open</button>
      <Dialog open={open} handleClose={closeDialog}>
        <p>
          Lorem ipsum dolor sit amet, consectetur adipisicing elit. A quasi
          natus quas dolore alias optio tenetur perferendis, cupiditate animi
          ex, omnis quibusdam non est, ullam saepe doloremque aperiam quia.
          Recusandae.
        </p>
        <button onClick={closeDialog}>Close Modal</button>
      </Dialog>
    </>
  );
}

It's not required to use the hooks from the package but if you find it helpful, why not.

Styling

Adding styles to the Dialog component is as easy as adding styles to the <dialog> element.

  • Style the backdrop with dialog::backdrop selector
  • You can style the dialog and the div element inside to add styles to the modal
  • All styling solutions are allowed

See usage example on codesandbox

API Documentation

Props for the Dialog Component

| Props | Description | | ------------------ | --------------------------------------------------------------------------- | | open | A boolean indicating whether the dialog is open or closed | | ref | A forwarded ref to the <dialog> element | | contentRef | A forwarded ref to the dialog content (<div> element inside the dialog) | | className | ClassName for the <dialog> element | | contentClassName | ClassName for the dialog content (<div> element inside the dialog) | | handleClose | A callback function to handle closing the dialog | | closeOnClickAway | Prop to close the dialog when clicking outside it |

Available Hooks

useDialogControls

| Return Values | Description | | ------------- | --------------------------------------------------------- | | open | A boolean indicating whether the dialog is open or closed | | openDialog | A function for setting the open boolean to true | | closeDialog | A function for setting the open boolean to false |

Why react-html-dialog?

  • Utilizes the native HTML <dialog> element for lightweight, accessible modals.
  • Offers flexibility in handling dialog states and behavior with the useDialogControls hook.
  • Seamlessly integrates into React applications without additional dependencies.

Contributing

We welcome contributions! Feel free to submit bug fixes, suggestions, or feature enhancements through issues and pull requests.