API Reference
createUi
The Stareezy UI configuration factory — themes, tokens, shorthands, breakpoints, and module augmentation.
Overview
createUi() is the single entry point for configuring Stareezy UI. Call it once at app startup in a stareezy.config.ts file, export the result, and import it wherever you need typed token access.
✦
The recommended pattern is a dedicated
stareezy.config.ts at your project root. The compiler reads this file automatically to pick up your custom shorthands at build time.Full config example
// stareezy.config.ts
import { createUi, token, themes, motion } from '@stareezy-ui/tokens'
export const ui = createUi({
// Register all four built-in themes (+ any custom ones)
themes: {
aurora: themes.aurora,
dark: themes.dark,
light: themes.light,
'steins-gate': themes['steins-gate'],
},
// Custom token groups — fully typed on ui.tokens
tokens: {
brand: {
primary: token('#FF6B35', 'brand-primary'),
secondary: token('#004E89', 'brand-secondary'),
},
},
// Responsive breakpoints (mobile-first, min-width in px)
media: { sm: 480, md: 768, lg: 1024, xl: 1280, '2xl': 1536 },
// Named font configs
fonts: {
inter: {
family: 'Inter, system-ui, sans-serif',
size: { sm: token(14, 'inter-sm'), md: token(16, 'inter-md') },
},
},
// Named animation presets
animations: {
fadeIn: { duration: motion.duration.enter, easing: motion.easing.easeOut },
},
// Global settings
settings: {
allowedStyleValues: 'somewhat-strict',
defaultFont: 'inter',
},
// Prop shorthands — registered as valid BoxProps via module augmentation
shorthands: {
bg: 'backgroundColor',
p: 'padding',
px: 'paddingHorizontal',
py: 'paddingVertical',
m: 'margin',
mx: 'marginHorizontal',
my: 'marginVertical',
br: 'borderRadius',
f: 'flex',
w: 'width',
h: 'height',
} as const, // ← as const is required for module augmentation to work
})
// ── Module augmentation ──────────────────────────────────────────────────
// Makes your shorthands flow into BoxProps as typed props.
// Without this, TypeScript won't know about your custom shorthands.
type AppConfig = typeof ui
declare module '@stareezy-ui/tokens' {
interface SzrCustomConfig extends AppConfig {}
}
export default uiThe
as const on shorthands is required — it tells TypeScript to infer the literal key types so the module augmentation works. Without it, shorthands are typed as Record<string, string> and no props are added.Module augmentation — typed shorthands
The declare module block is what makes custom shorthands appear as valid BoxProps. Once declared, TypeScript autocompletes them everywhere:
// After module augmentation:
<Box bg={t.backgrounds.primary} br={12} f={1} />
// ↑ typed ↑ typed ↑ typed ↑ typed
// Without augmentation — TypeScript error:
<Box br={12} /> // ❌ Property 'br' does not exist on type 'BoxProps'
// With augmentation — valid:
<Box br={12} /> // ✅ br → borderRadius, fully typedui.t — theme-reactive accessor
The returned config exposes ui.t — the same t accessor available from the standalone import. Pass these as component props for theme-reactive colors:
import { ui } from './stareezy.config'
// ui.t is identical to importing t from '@stareezy-ui/tokens'
<Box bg={ui.t.backgrounds.primary} color={ui.t.text.primary} />
// Custom tokens are on ui.tokens
<Box bg={ui.tokens.brand.primary} />
// Both work together
<Box
bg={ui.t.backgrounds.secondary}
borderColor={ui.tokens.brand.primary}
br={12}
/>Framework integration
1
Next.js (App Router)
// stareezy.config.ts — at project root
import { createUi, themes } from '@stareezy-ui/tokens'
export const ui = createUi({ themes: { aurora: themes.aurora } })
type AppConfig = typeof ui
declare module '@stareezy-ui/tokens' {
interface SzrCustomConfig extends AppConfig {}
}
// app/layout.tsx
import { ThemeProvider } from '@stareezy-ui/tokens'
import './stareezy.config' // side-effect: registers singleton
export default function RootLayout({ children }) {
return (
<html lang="en"><body>
<ThemeProvider theme="aurora">{children}</ThemeProvider>
</body></html>
)
}2
Vite / React SPA
// main.tsx
import './stareezy.config' // must be first import
import { ThemeProvider } from '@stareezy-ui/tokens'
import ReactDOM from 'react-dom/client'
import App from './App'
ReactDOM.createRoot(document.getElementById('root')!).render(
<ThemeProvider theme="aurora"><App /></ThemeProvider>
)3
React Native / Expo
// App.tsx
import './stareezy.config' // must be first import
import { ThemeProvider } from '@stareezy-ui/tokens'
export default function App() {
return (
<ThemeProvider theme="aurora">
{/* your app */}
</ThemeProvider>
)
}⚠
Import
stareezy.config.ts exactly once, as the first import in your entry file. Calling createUi() again replaces the global singleton.createUi() options
| Option | Type | Description |
|---|---|---|
themes | Record<string, ThemeTokenMap> | Named themes — aurora, dark, light, steins-gate, or custom. |
tokens | CustomTokenGroups | Custom token namespaces merged with built-in tokens. |
media | Partial<UiBreakpointConfig> | Responsive breakpoints (min-width px, mobile-first). Supersedes breakpoints. |
shorthands | Record<string, string> as const | Prop shorthand mappings. as const required for module augmentation. |
fonts | Record<string, FontConfig> | Named font families with size, weight, lineHeight token scales. |
animations | Record<string, AnimationPreset> | Named animation presets referencing motion token values. |
settings | UiSettings | allowedStyleValues, defaultFont, disableSSR. |
defaultTheme | "light" | "dark" | ThemeOverride | Default theme when no ThemeProvider is present. Defaults to "light". |
UiConfig return value
| Property / Method | Type | Description |
|---|---|---|
t | ThemeTokenAccessor | Theme-reactive token accessor — same as standalone t import. |
tokens | BuiltinTokens & TTokens | All built-in + custom token groups. |
shorthands | Record<string, string> | Registered prop shorthand mappings. |
breakpoints | UiBreakpointConfig | Resolved breakpoint config. |
getTheme(name) | ThemeTokenMap | Full token map for a named theme. Throws ThemeNotFoundError if not registered. |
getFont(name) | FontConfig | Font config for a named font. Throws FontNotFoundError if not registered. |
getMedia() | UiBreakpointConfig | Resolved media query breakpoint map. |
getTokens() | BuiltinTokens & TTokens | Returns the merged token registry. |
registerTokens(t) | UiConfig<T & TNew> | Add more token groups after initial setup. Returns a new typed config. |
updateBreakpoints(o) | void | Mutate breakpoints at runtime and sync to globalThis. |