Skip to Content
vitus·labs
Elements

Elements

Base UI primitives for building React interfaces — Element, Text, List, Overlay, and Portal.

@vitus-labs/elements provides the foundational building blocks for the UI system. Every higher-level component (rocketstyle, coolgrid) is built on top of these primitives.

What's new in 2.9

Bug fixes from the November 2026 elements audit, with no API changes:

  • Overlay: with nested modals, only the topmost focus trap handles Tab. The trap skips input[type="hidden"] and controls inside [hidden] / [inert] subtrees.
  • Overlay: when centered content (alignX="center" / alignY="center") would overflow, it now aligns to the trigger edge on the overflowing side, which pulls it back on-screen.
  • Overlay: a hover overlay no longer stays open after a nested overlay closes if the pointer left while the nested one was open.
  • Overlay: a closed click-to-open overlay listens for clicks on its trigger only. It adds a document listener only while it is open.
  • List / Iterator: in children mode, false / null children no longer count toward first / last / position, and items of a nested .map() array each get itemProps and their own position.
  • Element: gap margins are placed on the correct side for reverseInline / reverseRows.

See the Overlay and List pages for details.

Installation

npm install @vitus-labs/elements

Components

On React Native, index.native.ts exports Element, Text, List, Util and Provider. Overlay and Portal depend on react-dom and are web-only.

ComponentPurpose
ElementCore 3-section flex layout (beforeContent / content / afterContent)
TextSemantic text rendering primitive
ListData-driven list renderer with extended item props
OverlayPositioning system for dropdowns, tooltips, popovers, modals
PortalDOM portal for rendering outside the component hierarchy
UtilNon-rendering wrapper that injects className/style into children

Responsive Values

All layout props across Element, Text, and List support responsive values in three formats:

// Single value
<Element gap={10} />

// Array (mobile-first, one per breakpoint)
<Element gap={[8, 12, 16, 20]} />

// Breakpoint object
<Element gap={{ xs: 8, md: 12, lg: 16 }} />

CSS Props

Components accept CSS via ExtendCss in multiple formats:

// Template literal
<Element css={css`padding: 16px;`} />

// Callback (access to css function)
<Element css={(css) => css`
  padding: 16px;
  background: ${(props) => props.theme.bg};
`} />

// Responsive
<Element css={{
  xs: `padding: 8px;`,
  md: `padding: 16px;`,
}} />

Try It Live

Quick Example

import { Element, Text, List } from '@vitus-labs/elements'

function Card({ icon, title, items }) {
  return (
    <Element
      tag="article"
      direction="rows"
      gap={16}
      css={(css) => css`
        padding: 24px;
        border-radius: 8px;
        border: 1px solid #e0e0e0;
      `}
    >
      <Element beforeContent={icon} gap={8} alignY="center">
        <Text tag="h3">{title}</Text>
      </Element>

      <List
        rootElement
        component={({ children }) => <Text>{children}</Text>}
        data={items}
        valueName="children"
        gap={4}
        direction="rows"
      />
    </Element>
  )
}

Util

A non-rendering wrapper that injects className and style into its single child without adding any DOM nodes:

import { Util } from '@vitus-labs/elements'

<Util className="highlight" style={{ color: 'red' }}>
  <span>Styled child</span>
</Util>
// Renders: <span class="highlight" style="color: red;">Styled child</span>
PropTypeDescription
childrenReactNodeSingle child element
classNamestring | string[]CSS class(es) to inject (arrays are joined)
styleobjectInline styles to merge

Uses render() from @vitus-labs/core to clone the child with the injected props.

VLStatic Interface

Every component in this package implements the VLStatic interface:

interface VLStatic {
  displayName?: string
  pkgName?: string
  VITUS_LABS__COMPONENT?: `@vitus-labs/${string}`
}

This enables identification and metadata access across the ecosystem. For example, rocketstyle uses VITUS_LABS__COMPONENT to verify that components originate from @vitus-labs/elements.

Iterator Types

These types power the data-driven rendering in List (and can be imported for custom use):

ExtendedProps

Positional metadata injected into each rendered item:

type ExtendedProps = {
  index: number    // 0-based array index
  position: number // 1-based position (index + 1)
  first: boolean   // true if position === 1
  last: boolean    // true if position === length
  odd: boolean     // true if position is odd (1, 3, 5...)
  even: boolean    // true if position is even (2, 4, 6...)
}

ObjectValue

Data object shape for object arrays in List's data prop:

type ObjectValue = Partial<{
  key: SimpleValue      // Fallback key (priority 1)
  id: SimpleValue       // Fallback key (priority 2)
  itemId: SimpleValue   // Fallback key (priority 3)
  component: ElementType // Per-item component override
}> & Record<string, unknown>

The fallback keys are used only when no itemKey is given; if none is present the array index is used. The component property is consumed by the iterator and not passed to the rendered component. All other properties are spread as props.

PropsCallback

Type for itemProps and wrapProps — can be a static object or a function receiving item data and positional metadata:

type PropsCallback =
  | Record<string, unknown>                              // Static props
  | ((
      itemProps: Record<string, unknown> | ObjectValue,  // Item data
      extendedProps: ExtendedProps,                       // Positional metadata
    ) => Record<string, unknown>)

IteratorProps (generic Props<T>)

The Iterator's public type is a generic Props<T> that discriminates on the element type of data:

type Props<T = unknown> = unknown extends T
  ? LooseProps                       // no narrowing → today's loose backwards-compatible shape
  : T extends string | number
    ? SimpleProps<T>                 // primitive items → valueName REQUIRED
    : T extends ObjectValue
      ? ObjectProps<T>               // object items → valueName FORBIDDEN, itemKey is keyof T | (item) => …
      : ChildrenProps                // no data, just children

T is inferred at the JSX call site from the data array, so consumers usually don't write the generic explicitly:

<List data={['a', 'b']} component={Tag} valueName="label" />          // T inferred as string
<List data={[{ id: 1, name: 'Alice' }]} component={Row} itemKey="id" />  // T inferred as object, itemKey gets keyof T

The legacy LooseProps shape (the union of everything) is the fallback when T can't be narrowed — existing call sites continue to type-check without changes.

Exports

import {
  Element,
  Text,
  List,
  Overlay,
  Portal,
  Util,
  Provider,
  useOverlay,
  OverlayProvider,
} from '@vitus-labs/elements'

import type {
  ElementProps,
  TextProps,
  ListProps,
  OverlayProps,
  PortalProps,
  UtilProps,
  UseOverlayProps,
  IteratorProps,
  AlignX,
  AlignY,
  Direction,
  Content,
  ExtendCss,
  Responsive,
  ResponsiveBoolType,
  ContentBoolean,
  InnerRef,
  VLStatic,
  PropsCallback,
  ObjectValue,
  ExtendedProps,
  ElementType,
} from '@vitus-labs/elements'
Edit on GitHub

Last updated on

On this page