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 🙏

© 2025 – Pkg Stats / Ryan Hefner

easy-dialogs

v0.1.7

Published

Function based dialogs manager for React

Readme

🪟 easy-dialogs

Easy to use, function-based, type safe dialogs manager for React.

View demo / NPM

Installation

# yarn
yarn install easy-dialogs

# npm
npm install easy-dialogs

# pnpm
pnpm install easy-dialogs

Usage

1. Import into your root layout.

import { Dialog } from "easy-dialogs"

function App() {
    return (
        <section>
            {/* ...rest of your root layout */}
            <Dialog />
        </section>
    )
}

export default App

2. Create an array with dialogs list

import DialogComponent from "../components/DialogComponent";

export const dialogs = [
    { id: "test-dialog", component: DialogComponent }
    // Here you can add more dialogs
] as const

3. Import "useDialogManager()" hook inside React component

import { useDialogManager } from "easy-dialogs";
import { dialogs } from "../libs/dialogs";

const List = () => {
    const { callDialog } = useDialogManager(dialogs)
    return (
        <div>
            <button onClick={async () => {
                const result = await callDialog("test-dialog")
                if(result) {
                    alert('Result is success!') 
                }else{
                    alert('Result is failure :(') 
                }
            }}>Call me!</button>
        </div>
    );
}

export default List;

❗ Important notes

  • Dialog components MUST return some value. callDialog() function awaits for the response from the Dialog component.

    Example:

    type ExampleDialogType = {
        onClose: (val: boolean) => void,
        additionalProps?: {
            id: string
        }
    }
    
    const DialogComponent: React.FC<ExampleDialogType> = ({ onClose, additionalProps }) => {
        return (
            <div>
                <h1>Example dialog {additionalProps?.id}</h1>
                <button onClick={() => onClose(true)}>Success!</button>
                <button onClick={() => onClose(false)}>Failure :(</button>
            </div>
        );
    }
    
    export default DialogComponent;
  • To handle Exit Animations in your dialog component, first add the useExitAnimation: true property in dialogs list.

    export const dialogs = [
        { id: "test-dialog", component: DialogComponent, useExitAnimation: true }
        // Here you can add more dialogs
    ] as const

    Then, in your dialog component you need to set the data-state property and the onAnimationEnd() function and pass it into the dialog parent.

    type ExampleDialogType = {
        onClose: (val: boolean) => void,
        ["data-state"]?: string,
        onAnimationEnd?: () => void;
        additionalProps?: {
            id: string
        }
    }
    
    const DialogComponent: React.FC<ExampleDialogType> = ({ onClose, additionalProps, ...rest }) => {
        return (
            <div data-state={rest["data-state"]} onAnimationEnd={rest.onAnimationEnd}>
                ...
            </div>
        );
    }
    
    export default DialogComponent;

    The package will add data-state="closed" attribute while everything has been set up properly. In order to handle animations, you must add exit animation for example using TailwindCSS: data-[state=closed]:!animate-fadeout. When useExitAnimation is set to true and the animation is not set up, then the dialog won't close!

  • For Next.js users: <Dialog /> component MUST be rendered on the client.

Update history

- 0.1.7 - Added `dialogKeyId` property in Dialog instance object
- 0.1.6:
    - Added support for dialog exit animations
    - Added 'getActiveDialogs()' export
- 0.1.5 - Fixed additionalProps type issue
- 0.1.4 - Added support for multiple dialogs rendered at once.

Acknowledgements