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

@ui-construction-library/primitives

v0.1.3

Published

Headless overlay primitives for @ui-construction-library — Dialog, Popover, ContextMenu, Accordion, Tabs, Slider, Switch.

Readme

@ui-construction-library/primitives

Headless overlay primitives for the UI Construction Library. Provides unstyled, accessible Dialog, Popover, ContextMenu, Accordion, Tabs, Slider, and Switch components with full keyboard navigation and focus management.

When to use

Use this package when you are building a custom overlay component (e.g. a date picker, colour picker, or custom combobox) and need the headless behaviour — focus trapping, controlled state, portal rendering — without the core styling layer.

For most use cases, use @ui-construction-library/core instead. It wraps these primitives with the library's design system.

Installation

pnpm add @ui-construction-library/primitives

Peer dependencies

{
  "react": ">=18.0.0",
  "react-dom": ">=18.0.0"
}

Minimal example — custom dialog

import { Dialog } from '@ui-construction-library/primitives';
import { useState } from 'react';

function CustomDialog() {
  const [open, setOpen] = useState(false);

  return (
    <Dialog.Root open={open} onOpenChange={setOpen}>
      <Dialog.Trigger>
        <button type="button">Open</button>
      </Dialog.Trigger>
      <Dialog.Portal>
        <Dialog.Overlay style={{ position: 'fixed', inset: 0, background: 'rgba(0,0,0,0.4)' }} />
        <Dialog.Content style={{ position: 'fixed', top: '50%', left: '50%', transform: 'translate(-50%,-50%)', background: '#fff', padding: '1.5rem', borderRadius: '8px' }}>
          <Dialog.Title>Custom dialog</Dialog.Title>
          <Dialog.Description>This dialog traps focus and closes on Escape.</Dialog.Description>
          <Dialog.Close>
            <button type="button">Close</button>
          </Dialog.Close>
        </Dialog.Content>
      </Dialog.Portal>
    </Dialog.Root>
  );
}

Utilities

trapFocus

Traps keyboard focus within a container. Returns a cleanup function.

import { trapFocus } from '@ui-construction-library/primitives';

const cleanup = trapFocus(containerElement, () => setOpen(false));
// Call cleanup() on unmount or when the overlay closes

useControllableState

Supports both controlled and uncontrolled usage in custom components.

import { useControllableState } from '@ui-construction-library/primitives';

const [value, setValue] = useControllableState({
  value: controlledValue,   // undefined = uncontrolled
  defaultValue: false,
  onChange: onValueChange,
});

Available primitives

| Primitive | Description | |---|---| | Dialog | Modal dialog with focus trap, Escape close, and portal rendering | | Popover | Positioned popover with optional focus trap (modal prop) | | ContextMenu | Right-click context menu with keyboard navigation | | Accordion | Collapsible sections with ARIA contract | | Tabs | Tab panel with keyboard navigation | | Slider | Range slider with ARIA value attributes | | Switch | Toggle switch with role="switch" |

Controlled state contract

All root components accept the same open-state contract:

<Dialog.Root open={open} defaultOpen={false} onOpenChange={setOpen}>
<Popover.Root open={open} defaultOpen={false} onOpenChange={setOpen} modal={false}>
<ContextMenu.Root open={open} defaultOpen={false} onOpenChange={setOpen}>

Compatibility

  • React 18 and 19
  • TypeScript 5.x and 6.x
  • No CSS shipped — fully unstyled

Public API

import { Dialog, Popover, ContextMenu, Accordion, Tabs, Slider, Switch } from '@ui-construction-library/primitives';
import { trapFocus, getFocusableElements, useControllableState } from '@ui-construction-library/primitives';

Troubleshooting

Focus not trapped — confirm the container element is mounted and visible before calling trapFocus. The container must contain at least one focusable element.

Dialog not closing on Escape — pass an onEscape callback as the second argument to trapFocus, or use Dialog.Content which handles this automatically.