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 🙏

© 2026 – Pkg Stats / Ryan Hefner

@hirotoshioi/hiraku-base-ui

v0.0.6

Published

Modal state management library for Base UI based components

Readme


Features

  • Open from anywhere - Call modal.open() from any file, even outside React components
  • 🔒 Type-safe - Strongly typed
  • 🎯 Base UI native - First-class support for Dialog, Sheet, and AlertDialog
  • 🪶 Lightweight - Depends on @hirotoshioi/hiraku-core (zustand-based)

Installation

npm install @hirotoshioi/hiraku-base-ui

Base UI is required as a peer dependency:

npm install @base-ui/react

Quick Start

1. Add the Provider

// app.tsx
import { ModalProvider } from "@hirotoshioi/hiraku-base-ui";

function App() {
  return (
    <>
      <YourApp />
      <ModalProvider />
    </>
  );
}

2. Create a modal

// modals/confirm-dialog.tsx
import { Dialog } from "@base-ui/react/dialog";
import { createDialog } from "@hirotoshioi/hiraku-base-ui";

interface ConfirmDialogProps {
  title: string;
  message: string;
}

function ConfirmDialog({ title, message }: ConfirmDialogProps) {
  return (
    <Dialog.Portal>
      <Dialog.Backdrop />
      <Dialog.Popup>
        <Dialog.Title>{title}</Dialog.Title>
        <Dialog.Description>{message}</Dialog.Description>

        <button onClick={() => void confirmDialog.close({ role: "cancel" })}>
          Cancel
        </button>
        <button onClick={() => void confirmDialog.close({ data: true, role: "confirm" })}>
          Confirm
        </button>
      </Dialog.Popup>
    </Dialog.Portal>
  );
}

export const confirmDialog = createDialog(ConfirmDialog).returns<boolean>();

3. Open from anywhere

import { confirmDialog } from "./modals/confirm-dialog";

async function handleDelete() {
  await confirmDialog.open({
    title: "Delete item?",
    message: "This action cannot be undone.",
  });

  const { data, role } = await confirmDialog.onDidClose();

  if (role === "confirm" && data) {
    // Perform delete
  }
}

Examples

See the example app in this repository: examples/base-ui/.

API

Factory Functions

| Function | Description | | ------------------------------ | ----------------------------------------- | | createDialog(Component) | Create a modal using Base UI Dialog | | createSheet(Component) | Create a modal using Base UI (Dialog.Root)| | createAlertDialog(Component) | Create a modal using Base UI AlertDialog |

Modal Controller

const myModal = createDialog(MyComponent).returns<ResultType>();

myModal.open(props)            // Open the modal (returns Promise)
myModal.close({ data, role })  // Close the modal with result
myModal.onDidClose()           // Get Promise that resolves when closed
myModal.isOpen()               // Check if modal is open

useModal Hook

import { useModal } from "@hirotoshioi/hiraku-base-ui";

function MyComponent() {
  const modal = useModal(confirmDialog);

  return (
    <>
      <button onClick={() => modal.open({ title: "Hello", message: "World" })}>
        Open
      </button>
      <p>isOpen: {modal.isOpen}</p>
      <p>result: {JSON.stringify(modal.data)}</p>
      <p>role: {modal.role}</p>
    </>
  );
}

Global Controller

import { modalController } from "@hirotoshioi/hiraku-base-ui";

modalController.closeAll()    // Close all open modals
modalController.getCount()    // Get count of open modals
modalController.isOpen()      // Check if any modal is open
modalController.getTop()      // Get the topmost modal