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-radix-ui

v0.0.6

Published

Modal state management library for Radix UI based components

Downloads

6,067

Readme


📦 Migrating from @hirotoshioi/hiraku?

If you're using the old package name @hirotoshioi/hiraku, please see the Migration Guide.

Quick summary:

  1. npm install @hirotoshioi/hiraku-radix-ui
  2. Update imports: from '@hirotoshioi/hiraku'from '@hirotoshioi/hiraku-radix-ui'
  3. Done! (No API changes)

Features

  • Open from anywhere - Call modal.open() from any file, even outside React components
  • 🔒 Type-safe - Strongly typed
  • 🎯 Radix UI native - First-class support for Dialog, Sheet, and AlertDialog
  • 🪶 Lightweight - ~3KB gzipped, only zustand as dependency
  • 🎨 shadcn/ui ready - Works seamlessly with your existing components
  • 😃 Migrate with ease - Migrate your existing modals with minimal changes

Installation

npm install @hirotoshioi/hiraku-radix-ui

Radix UI dialog primitives are required as peer dependencies:

npm install @radix-ui/react-dialog @radix-ui/react-alert-dialog

Quick Start

1. Add the Provider

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

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

2. Create a modal

// modals/confirm-dialog.tsx
import { DialogContent, DialogHeader, DialogTitle, DialogFooter } from "@/components/ui/dialog";
import { Button } from "@/components/ui/button";
import { createDialog } from "@hirotoshioi/hiraku-radix-ui";

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

// No need to wrap with Dialog.Root, hiraku will take care of it
function ConfirmDialog({ title, message }: ConfirmDialogProps) {
  return (
    <DialogContent>
      <DialogHeader>
        <DialogTitle>{title}</DialogTitle>
      </DialogHeader>
      <p>{message}</p>
      <DialogFooter>
        <Button variant="outline" onClick={() => confirmDialog.close({ role: "cancel" })}>
          Cancel
        </Button>
        <Button onClick={() => confirmDialog.close({ data: true, role: "confirm" })}>
          Confirm
        </Button>
      </DialogFooter>
    </DialogContent>
  );
}

// Create a modal controller
export const confirmDialog = createDialog(ConfirmDialog).returns<boolean>();

3. Open from anywhere

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

async function handleDelete() {
  // Open the modal and wait for it
  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 full example project in the repository: hiraku Example on GitHub

Or open it in StackBlitz:

Open in StackBlitz

API

Factory Functions

| Function | Description | | ------------------------------ | -------------------------------------- | | createDialog(Component) | Create a modal using Radix Dialog | | createSheet(Component) | Create a modal using Radix Sheet | | createAlertDialog(Component) | Create a modal using Radix AlertDialog |

Modal Controller

API for controllers created by createDialog and other factories:

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

// Methods
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

React hook for using modals within components:

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

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

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

Global Controller

import { modalController } from "@hirotoshioi/hiraku-radix-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

shadcn/ui Integration

hiraku works seamlessly with shadcn/ui components. Just implement Content and below — hiraku manages the Root for you:

import { SheetContent, SheetHeader, SheetTitle } from "@/components/ui/sheet";
import { createSheet } from "@hirotoshioi/hiraku-radix-ui";

function MySheet({ title }: { title: string }) {
  return (
    <SheetContent>
      <SheetHeader>
        <SheetTitle>{title}</SheetTitle>
      </SheetHeader>
      {/* ... */}
    </SheetContent>
  );
}

export const mySheet = createSheet(MySheet);

Why hiraku?

With traditional patterns, modal components are often controlled by their parent for open/close state. That tight coupling hurts readability and maintainability.

If you've built React apps, you've probably seen something like this:

import { MyDialog } from "./MyDialog";
function Parent() {
  // Managing modal state in the parent makes the code cumbersome
  const [isOpen, setIsOpen] = useState(false);
  return (
    <>
      <button onClick={() => setIsOpen(true)}>Open Dialog</button>
      {/* The Dialog has to receive isOpen from the parent */}
      <MyDialog isOpen={isOpen} onClose={() => setIsOpen(false)} />
    </>
  );
}

The modal wants its open/close state managed by the parent, but doing so makes the parent code cumbersome.

hiraku's Approach

hiraku resolves that dilemma. With hiraku, modals can be opened from anywhere in your application without needing to pass down state or handlers through props. This decouples modal logic from your component hierarchy, leading to cleaner and more maintainable code.

import { myDialog } from "./modals/my-dialog";

function Parent() {
  // const [isOpen, setIsOpen] = useState(false); <-- No need to manage state!
  return (
    <>
      <button onClick={() => myDialog.open()}>
        Open Dialog
      </button>
    </>
  );
}

Other UI Frameworks

hiraku is part of a monorepo supporting multiple UI frameworks:

License

MIT © Hiroto Shioi