Skip to content
@pyreon/primitives
core · cross-platform UI

One Toggle. The real iOS switch and the real Android switch.

One name per idea: Stack, Text, Field, Toggle, Modal and the rest. On the web they render plain DOM; in a native build the compiler emits the platform's own SwiftUI and Jetpack Compose views from the same .tsx.

bun add @pyreon/primitives
Documentation
primitives
22 canonicalGesture, Canvas, Select, Tabs and Split arrive in the next release. Plus Transition, TransitionGroup, WebView and three escape hatches.
targets
DOM · SwiftUI · Jetpack Compose
tokens
one scale, same numbers everywheregap="md" is 12 px on the web, 12 pt on iOS, 12 dp on Android.
status
native targets experimentalDevice-tested in CI with XCUITest and Compose UI tests.
One Toggle in TSX becomes the web, iOS and Android switch One <Toggle value onChange> in a .tsx file on the left. Lines run to three targets on the right: a web input with role="switch", a SwiftUI Toggle on iOS and a Jetpack Compose Switch on Android. When the value flips, all three switches flip together. Native targets are experimental. @PYREON/PRIMITIVES · ONE NAME, THREE VIEWS WifiSetting.tsx const on = signal(true) <Toggle value={on()} onChange={(v) => on.set(v)} /> on() === true on() === false web <input type="checkbox" role="switch"> iOS · SwiftUI Toggle("", isOn: Binding(…)) Android · Compose Switch(checked = …, onCheckedChange = …) native targets are experimental accessibilityLabel → all three
why teams pick it

Learn one vocabulary. Ship three kinds of UI.

  1. One name per idea

    <Stack>, not View, VStack, Column or div. onPress on every target, not onClick here and action there. value plus onChangeText for every text field.

  2. Native, not imitated

    <Toggle> becomes SwiftUI Toggle and Compose Switch. <Modal> becomes a .sheet and a Dialog. <Field kind="password"> becomes SecureField. When the OS restyles its controls, your app follows.

  3. Accessibility that reaches the device

    accessibilityLabel becomes aria-label, SwiftUI .accessibilityLabel and a Compose contentDescription. data-testid becomes an accessibility identifier and a testTag, so one id drives Playwright, XCUITest and Compose tests.

  4. Escape hatches included

    <Web>, <NativeIOS> and <NativeAndroid> render a branch on one target only. useNativeModule calls your own Swift or Kotlin. <WebView> hosts a web-only component, with data in and onMessage out.

the difference

One screen. Today you write it three times.

web/Signup.tsx · ios/Signup.swift · android/Signup.kt

The same sign-up form in React, SwiftUI and Compose. Three files, three state models, three reviews for every change.

// web/Signup.tsx (React)
import { useState } from 'react'

export function Signup({ onSubmit }: { onSubmit: (email: string) => void }) {
  const [email, setEmail] = useState('')
  return (
    <div style={{ display: 'flex', flexDirection: 'column', gap: 12, padding: 16 }}>
      <b>Create your account</b>
      <input type="email" value={email} onChange={(e) => setEmail(e.target.value)} />
      <button disabled={email === ''} onClick={() => onSubmit(email)}>Continue</button>
    </div>
  )
}

// ios/Signup.swift
struct Signup: View {
  let onSubmit: (String) -> Void
  @State private var email = ""
  var body: some View {
    VStack(spacing: 12) {
      Text("Create your account").bold()
      TextField("", text: $email).keyboardType(.emailAddress)
      Button("Continue") { onSubmit(email) }.disabled(email.isEmpty)
    }
    .padding(16)
  }
}

// android/Signup.kt
@Composable
fun Signup(onSubmit: (String) -> Unit) {
  var email by remember { mutableStateOf("") }
  Column(verticalArrangement = Arrangement.spacedBy(12.dp), modifier = Modifier.padding(16.dp)) {
    Text("Create your account", fontWeight = FontWeight.Bold)
    TextField(
      value = email,
      onValueChange = { email = it },
      keyboardOptions = KeyboardOptions(keyboardType = KeyboardType.Email),
    )
    Button(onClick = { onSubmit(email) }, enabled = email.isNotEmpty()) { Text("Continue") }
  }
}
src/Signup.tsx

One file. The Swift and Kotlin the compiler emits for it have the same shape as the hand-written two on the left: VStack(spacing: 12), Column with spacedBy(12.dp), a TextField with the email keyboard.

import { signal } from '@pyreon/reactivity'
import { Stack, Text, Field, Button } from '@pyreon/primitives'

export function Signup(props: { onSubmit: (email: string) => void }) {
  const email = signal('')
  return (
    <Stack gap="md" padding={4}>
      <Text weight="bold">Create your account</Text>
      <Field kind="email" value={email()} onChangeText={(t) => email.set(t)} />
      <Button onPress={() => props.onSubmit(email())} disabled={email() === ''}>
        Continue
      </Button>
    </Stack>
  )
}
pairs with

Design System

Primitives keep a small, fixed token scale so every target agrees on the numbers. When you want your own look, wrap them: styled(Stack) and rocketstyle chains over a primitive lower to SwiftUI and Compose as well. Web-only apps that need breakpoints and theme-aware CSS use the Design System's elements directly.

coming from

Coming from React Native?

The names feel familiar. What ships is different.

React Native
import { useState } from 'react'
import { View, TextInput, Switch, Pressable, Text } from 'react-native'

export function Profile() {
  const [name, setName] = useState('')
  const [publicProfile, setPublicProfile] = useState(true)
  return (
    <View style={{ gap: 12, padding: 16 }}>
      <TextInput value={name} onChangeText={setName} placeholder="Name" />
      <Switch value={publicProfile} onValueChange={setPublicProfile} accessibilityLabel="Public profile" />
      <Pressable onPress={() => setName('')}>
        <Text>Clear</Text>
      </Pressable>
    </View>
  )
}
Pyreon

onPress and onChangeText carry over. React Native runs your JavaScript on the device; here the compiler emits SwiftUI and Compose source and the import is only a type anchor. The trade: only a declarative subset of TypeScript compiles, and compiled code cannot be updated over the air. The same file also renders as a web page.

import { signal } from '@pyreon/reactivity'
import { Stack, Field, Toggle, Button } from '@pyreon/primitives'

export function Profile() {
  const name = signal('')
  const publicProfile = signal(true)
  return (
    <Stack gap="md" padding={4}>
      <Field value={name()} onChangeText={(t) => name.set(t)} placeholder="Name" />
      <Toggle value={publicProfile()} onChange={(v) => publicProfile.set(v)} accessibilityLabel="Public profile" />
      <Button variant="ghost" onPress={() => name.set('')}>Clear</Button>
    </Stack>
  )
}
try it

Pick a primitive, see all three outputs.

What each primitive becomes on each platform, taken from the compiler's own output (abridged: the real emit adds tokens, accessibility and modifiers).

primitive
web · DOM, live
<input type="checkbox"
  role="switch">

on = true

iOS · SwiftUI
Toggle("", isOn: Binding(…))
Android · Compose
Switch(checked = on,
  onCheckedChange = { … })

Illustrative, abridged: the iOS and Android columns are not compiled live in this page. The web column is the real component.

  • Today, the showcase todo app, in Chromium (the web build: server-rendered HTML, hydrated): a "Today" heading with "2 left", an "Add a todo" field with an ember Add button, and three todos on paper cards (Water the basil, Book the dentist checked off, Call Grandma back), each with a checkbox and a Remove action.Today, the showcase todo app, in Chromium (the web build: server-rendered HTML, hydrated): a "Today" heading with "2 left", an "Add a todo" field with an ember Add button, and three todos on paper cards (Water the basil, Book the dentist checked off, Call Grandma back), each with a checkbox and a Remove action.
    Web · Chromium
  • Today, the showcase todo app, on an iOS Simulator (SwiftUI generated from the same TodayApp.tsx): the "Today" heading with "2 left", an "Add a todo" text field with an ember Add button, and three todos, each with a native iOS switch (Book the dentist on) and a Remove action.Today, the showcase todo app, on an iOS Simulator (SwiftUI generated from the same TodayApp.tsx): the "Today" heading with "2 left", an "Add a todo" text field with an ember Add button, and three todos, each with a native iOS switch (Book the dentist on) and a Remove action.
    iOS · SwiftUI
  • Today, the showcase todo app, on an Android emulator (Jetpack Compose generated from the same TodayApp.tsx): the "Today" heading with "2 left", a Material text field with an ember Add button, and three todos, each with a Material switch (Book the dentist on) and a Remove action.Today, the showcase todo app, on an Android emulator (Jetpack Compose generated from the same TodayApp.tsx): the "Today" heading with "2 left", a Material text field with an ember Add button, and three todos, each with a Material switch (Book the dentist on) and a Remove action.
    Android · Compose
what's included

Everything a cross-platform screen needs.

  • Layout: Stack, Inline, Layer, Scroll and Spacer become VStack, HStack, ZStack and ScrollView on iOS, Column, Row and Box on Android
  • Content: Text, Heading, Image, Icon, Audio and Video; Image loads remote URLs with AsyncImage on both platforms
  • Press: tap, long press and left or right swipes on any element, through each platform's own gesture recognisers on iOS and Android and with Enter and Space on the web
  • Field:next release text, email, number, tel, url, search and password keyboards, plus multiline for a text area
  • Dates and times:next release <Field kind="date" | "time" | "datetime"> with min and max: DatePicker on iOS, Material 3 pickers on Android, a wall-clock string everywhere
  • Select:next release one choice from a list: <select>, a menu Picker, a Material 3 exposed dropdown
  • Tabs and Split:next release tabs stay mounted when you switch away, and createRouter({ tabs }) gives every tab its own back stack
  • Gesture and Canvas:next release pan, pinch and rotate feeding translateX, scale and rotate; vector shapes with full SVG path data
  • Transition and TransitionGroup: seven named presets, animated with CSS on the web, .transition on iOS and AnimatedVisibility on Android
  • WebView: host a chart or editor in the native app, with data pushed in without a reload and onMessage back out
recipes

Things to build with it.

next release
A booking form with each platform's own pickers

A date field bounded to one calendar year and a room picker with one option disabled. iOS gets a DatePicker and a menu Picker, Android gets Material 3 dialogs and an exposed dropdown, the web gets <input type="date"> and <select>. The value is the same YYYY-MM-DD string on all three.

import { signal } from '@pyreon/reactivity'
import { Stack, Field, Select, Button, Text } from '@pyreon/primitives'
import type { SelectOption } from '@pyreon/primitives'

const rooms: SelectOption[] = [
  { value: 'single', label: 'Single room' },
  { value: 'double', label: 'Double room' },
  { value: 'suite', label: 'Suite', disabled: true },
]

export function Booking() {
  const day = signal('')
  const room = signal('')
  return (
    <Stack gap="md" padding={4}>
      <Field kind="date" min="2026-01-01" max="2026-12-31" placeholder="Arrival"
        value={day()} onChangeText={(d) => day.set(d)} />
      <Select value={room()} options={rooms} onChange={(v) => room.set(v)} placeholder="Pick a room" />
      <Button variant="ghost" onPress={() => day.set('')}>Clear</Button>
      <Text>{day() === '' || room() === '' ? 'Pick a day and a room' : `${room()} from ${day()}`}</Text>
    </Stack>
  )
}
A settings screen with a native confirm sheet

A labelled switch pushed to the trailing edge, and a destructive action behind a confirmation. On the web the dialog is a modal <dialog> with focus trapping; on iOS it is a sheet you can swipe away; on Android a Dialog.

import { signal } from '@pyreon/reactivity'
import { Stack, Inline, Toggle, Text, Button, Modal, Spacer } from '@pyreon/primitives'

export function Settings() {
  const notify = signal(true)
  const confirm = signal(false)
  return (
    <Stack gap="md" padding={4}>
      <Inline gap="sm" align="center">
        <Text>Notifications</Text>
        <Spacer />
        <Toggle value={notify()} onChange={(v) => notify.set(v)} accessibilityLabel="Notifications" />
      </Inline>
      <Button variant="danger" onPress={() => confirm.set(true)}>Delete account</Button>
      <Modal open={confirm()} onClose={() => confirm.set(false)}>
        <Stack gap="md" padding={4}>
          <Text>Delete your account? This cannot be undone.</Text>
          <Button variant="ghost" onPress={() => confirm.set(false)}>Cancel</Button>
        </Stack>
      </Modal>
    </Stack>
  )
}
api

Every primitive and its helpers.

Every export has a reference page with its signature, an example and the mistakes people make with it.

layout · 5
  • Stack
  • Inline
  • Layer
  • Scroll
  • Spacer
content · 6
  • Text
  • Heading
  • Image
  • Icon
  • Audio
  • Video
interaction · 3
  • Button
  • Press
  • Link
input · 3
  • Field
  • Toggle
  • Modal
gestures and drawing (next release) · 7
  • Gesture
  • Canvas
  • CanvasRect
  • CanvasCircle
  • CanvasLine
  • CanvasPath
  • CanvasText
choice and navigation (next release) · 4
  • Select
  • Tabs
  • Tab
  • Split
animation and web content · 4
  • Transition
  • TransitionGroup
  • WebView
  • connectWebHost
platform · 7
  • Web
  • NativeIOS
  • NativeAndroid
  • defineNativeModule
  • useNativeModule
  • hasNativeModule
  • init
good to know

Good to know before you start.

The compiler reads your source, not npm

Native builds lower your components in a declarative subset of TypeScript. Code outside it almost always gets a named warning; DOM-bound libraries stay on the web or go in a <WebView>.

A fixed token scale

Spacing, colour and radius come from one built-in scale with no responsive props. For breakpoints and theme-aware CSS on the web, use the Design System's elements directly.

Some props are web-only

justify and wrap on a Stack have no SwiftUI equivalent, so iOS and Android ignore them and the compiler says so. Put a <Spacer /> between children to push them apart.

Native is experimental

The multiplatform guide keeps a gated matrix of what is device-proven. Check it before you plan a release around a primitive.

questions

What people ask first.

Is this React Native?

No. React Native runs your JavaScript on the device. Here the compiler reads your .tsx at build time and writes SwiftUI and Compose source; on native targets the @pyreon/primitives import is only there for TypeScript. On the web, the same file renders plain DOM.

Can I use my own theme?

The primitives' own props use a fixed scale (gap="md" is 12 everywhere) so every target agrees. For your own look, styled(Stack) and rocketstyle chains over a primitive also lower to native. Web-only apps with breakpoints and theme-aware CSS should use the Design System's elements instead.

What happens to code that cannot compile to native?

The compiler almost always names it in a warning, for example justify or wrap on a Stack. Code that needs the DOM goes behind <Web> or inside a <WebView>.

Can I drop down to Swift or Kotlin?

Yes, through defineNativeModule and useNativeModule, which call a Swift or Kotlin class you own. <NativeIOS> and <NativeAndroid> only choose which primitives render per platform; they do not take raw Swift.

Is it ready for my production app?

@pyreon/primitives is an Experimental package, so its API can still change in a minor release. The native targets are experimental too, and the multiplatform guide says so in its status line. The device-test matrix there is the source of truth for what is proven.

Write the screen once. Let the compiler learn Swift and Kotlin.

bun add @pyreon/primitives
Read the primitives guide