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

@domglyph/primitives

v2.1.0

Published

[![npm version](https://img.shields.io/npm/v/@domglyph/primitives?color=0ea5e9)](https://www.npmjs.com/package/@domglyph/primitives) [![License: MIT](https://img.shields.io/badge/license-MIT-green.svg)](../../LICENSE)

Downloads

206

Readme

@domglyph/primitives (formerly @cortexui/primitives)

npm version License: MIT

Low-level accessible UI primitives. The foundation of DOMglyph components.


Overview

@domglyph/primitives provides the base layer of the DOMglyph architecture. Understanding the three-layer model helps clarify where each package fits:

┌─────────────────────────────────────┐
│  @domglyph/components               │  ← AI contract + visual design
│  ActionButton, FormField, DataTable  │
├─────────────────────────────────────┤
│  @domglyph/primitives               │  ← Behavior + accessibility
│  Box, Stack, Text, ButtonBase, …    │
├─────────────────────────────────────┤
│  HTML elements + ARIA               │  ← DOM
└─────────────────────────────────────┘

Primitives handle behavior and accessibility. They manage focus management, keyboard interaction, ARIA roles, and layout — the hard, invisible work that makes a UI actually accessible.

Primitives do NOT add data-ai-* attributes. That is the responsibility of the component layer. This separation means primitives are reusable for any purpose, while components carry the full AI contract.


Installation

npm install @domglyph/primitives

Peer dependencies:

npm install react@^18 react-dom@^18

Primitives

Box

A polymorphic container element. Renders as any HTML element via the as prop, defaulting to div. The base building block for layout.

import { Box } from '@domglyph/primitives';

<Box as="section" style={{ padding: '24px' }}>
  Page content here
</Box>

<Box as="article" style={{ maxWidth: '640px', margin: '0 auto' }}>
  Article content
</Box>

<Box as="header">
  Site header
</Box>

Box forwards all standard HTML attributes and refs. It has no opinion about styling.


Stack

A flexbox layout primitive for stacking children vertically or horizontally with consistent spacing.

import { Stack } from '@domglyph/primitives';

// Vertical stack with gap
<Stack direction="column" gap="16px">
  <FormField id="name" fieldType="text" label="Full name" />
  <FormField id="email" fieldType="email" label="Email" />
  <ActionButton action="submit-form" state="idle" label="Submit" />
</Stack>

// Horizontal stack
<Stack direction="row" gap="8px" align="center">
  <StatusIcon />
  <Text size="sm">3 items selected</Text>
</Stack>

Text

A semantic typography primitive. Renders as any text-level HTML element via the as prop. Use it for labels, headings, captions, and body copy.

import { Text } from '@domglyph/primitives';

// Form label
<Text as="label" size="sm" weight="medium">
  Full name
</Text>

// Heading
<Text as="h2" size="xl" weight="bold">
  Account settings
</Text>

// Caption
<Text as="span" size="xs" color="muted">
  Last updated 2 minutes ago
</Text>

ButtonBase

An accessible button primitive with no visual styling. Handles keyboard events (Enter, Space), ARIA attributes, and disabled state management. The foundation of ActionButton.

When building custom components on ButtonBase, you are responsible for adding data-ai-* attributes:

import { ButtonBase } from '@domglyph/primitives';

<ButtonBase
  onClick={handleClick}
  disabled={isDisabled}
  aria-label="Close dialog"
  data-ai-role="action"
  data-ai-id="close-dialog"
  data-ai-action="close-dialog"
  data-ai-state="idle"
>
  <CloseIcon />
</ButtonBase>

ButtonBase always renders as a native <button> element. It does not use role="button" on a <div>. This ensures correct keyboard behaviour, screen reader support, and form interaction without extra work.


InputBase

An accessible input primitive with no visual styling. Handles value state, change events, and ARIA attributes for error and required states. The foundation of FormField.

import { InputBase } from '@domglyph/primitives';

<InputBase
  type="email"
  value={value}
  onChange={(e) => setValue(e.target.value)}
  aria-label="Email address"
  aria-required="true"
  aria-invalid={hasError}
  data-ai-role="field"
  data-ai-id="user-email"
  data-ai-field-type="email"
  data-ai-required="true"
  data-ai-state={hasError ? 'error' : 'idle'}
/>

DialogBase

An accessible dialog primitive with focus trapping, scroll locking, and Escape key dismissal. Renders as a native <dialog> element. The foundation of ConfirmDialog.

import { DialogBase } from '@domglyph/primitives';

<DialogBase
  open={isOpen}
  onClose={handleClose}
  aria-labelledby="dialog-title"
  aria-describedby="dialog-description"
  data-ai-role="modal"
  data-ai-id="confirm-delete"
  data-ai-state={isOpen ? 'expanded' : 'idle'}
>
  <h2 id="dialog-title">Confirm deletion</h2>
  <p id="dialog-description">This cannot be undone.</p>
  <ButtonBase onClick={handleClose}>Cancel</ButtonBase>
  <ButtonBase onClick={handleConfirm}>Confirm</ButtonBase>
</DialogBase>

DialogBase traps focus within the dialog while it is open and restores focus to the trigger element when it closes.


When to use primitives directly

Use @domglyph/primitives directly when:

  • You are building a custom component that needs DOMglyph's accessibility guarantees but has unique visual requirements not served by the components package
  • You need a polymorphic container (Box) or layout primitive (Stack) without pulling in a full component

When you build on primitives directly, you are responsible for adding data-ai-* attributes to make the component inspectable by the AI runtime. See @domglyph/ai-contract for the full attribute specification and @domglyph/testing for validation utilities to use in your tests.


Part of DOMglyph

@domglyph/primitives is part of the DOMglyph design system.


☕ Support

If you find DOMglyph useful, you can support the project:

👉 https://buymeacoffee.com/nishchya

It helps keep the project alive and growing.