— Engines & connectors · @vitus-labs/connector-styler · @vitus-labs/connector-styled-components · @vitus-labs/connector-emotion · @vitus-labs/connector-native

One init(). Any engine.

Every ui-system component styles itself through @vitus-labs/core, never through an engine directly. A connector is the adapter you hand to init(): styler, styled-components, Emotion, or React Native, where CSS strings become style objects. Swap it, and the components stay as they are.

@vitus-labs/connector-stylerv2.9.1 · MIT
npm i @vitus-labs/core @vitus-labs/connector-styler
connectors, web and native
4
required members: css, styled, provider
3
line names the engine
1

— Why connectors

Components that don't pick an engine.

01

The engine is named once

Elements, rocketstyle, unistyle and coolgrid read css and styled from core's config. Your app's entry point calls init(connector), and that is the only file that knows which engine runs.

02

Import order doesn't matter

Core's css and styled are stable delegates. Before init() runs, css returns a thunk and styled returns a lazy component that resolves the engine on first render, so module-level const { styled, css } = config is safe.

03

Types follow the engine

Core exposes an empty CSSEngineResult interface, and the styler, styled-components and native connectors augment it with their own result type. css returns the type of the engine you installed, without core depending on any engine.

04

The same components on React Native

connector-native parses CSS template strings into React Native style objects and applies them through style. Pass View and Text as the base components, and breakpoints resolve against the window width.

— Before / after

Same card. Engine named once.

A styled card in a component library. The question is where the CSS engine is named.

beforeEngine in every file
Card.tsx
import styled from 'styled-components'

export const Card = styled.div`
  padding: 16px;
  border-radius: 12px;
  background: ${({ theme }) => theme.surface};
`

// switching to Emotion:
// import styled from '@emotion/styled'   ← in every component

Every component imports the engine. Moving to another one, or to React Native, means touching each file.

after@vitus-labs/core + a connector
Card.tsx · main.tsx
// Card.tsx: no engine import
import { config } from '@vitus-labs/core'

const { styled } = config

export const Card = styled.div`
  padding: 16px;
  border-radius: 12px;
  background: ${({ theme }) => theme.surface};
`

// main.tsx: the only place the engine is named
import { init } from '@vitus-labs/core'
import * as connector from '@vitus-labs/connector-emotion'

init(connector)

Components read styled from core. The entry point picks the engine; changing it is a one-line diff.

— Features

Four adapters, one shape.

  • connector-styler

    re-exports @vitus-labs/styler; the only web connector that also ships useCSS

  • connector-styled-components

    re-exports styled-components 6 or newer, with css typed from styled-components' own return type

  • connector-emotion

    wraps Emotion's css so fragments compose like styled-components: functions, arrays and nested css resolve with props

  • Emotion globals & keyframes

    createGlobalStyle renders Emotion's <Global> with the theme injected; keyframes objects are kept intact, not stringified

  • connector-native

    CSS strings to React Native style objects: kebab-case to camelCase, px to numbers, !important stripped

  • Shorthand expansion

    padding: 8px 16px, margin, inset, border-width and border-radius expand to React Native longhands

  • Native breakpoints

    createMediaQueries checks the window width when styles resolve, and dynamic components re-render on rotation

  • Static native styles

    templates without function interpolations are parsed once and skip the window and theme hooks entirely

  • Lazy delegates

    css and styled from core work before init(); they bind to the engine at first use

  • CSSEngineResult

    an empty interface each connector augments, so css is typed as the active engine's result

  • Clean engine swaps

    a full init() drops keyframes, createGlobalStyle and useTheme the new connector doesn't provide

  • Platform config

    component and textComponent default to div and span; React Native passes View and Text

— API

Three required members. Four adapters.

Every name links to its reference in the docs.

— Honest limits

Where the engines differ.

Where it isn't the right fit, and what to reach for instead.

  • React Native isn't a browser

    Nested blocks such as &:hover and @media are dropped, there is no keyframes or createGlobalStyle, styled.View shorthand doesn't exist (use styled(View)), and rem values stay strings. Overlay and Portal aren't exported on native. For web-only features, keep those components on the web.

  • useCSS is styler-only

    The styled-components and Emotion connectors don't export useCSS: neither engine can turn a css fragment into an inserted class without a styled wrapper. Use styled(), or the styler connector.

  • Emotion's css isn't typed as an object

    The Emotion connector's css returns a string or a function, which can't augment CSSEngineResult, so the interface stays empty there. Pass results as interpolations, as Emotion expects.

  • One engine per app

    The configuration is a singleton and components created after init() bind to that engine directly. Two engines side by side in one tree aren't supported; call init() once at the entry point.

  • SSR comes from the engine

    Collector-free SSR through <style precedence> is a styler feature. With styled-components or Emotion, set up that engine's server rendering as you normally would.

— Recipes

Copy, paste, ship.

01

A web app on styler

Import the connector as a namespace and spread it: connectors have named exports only. This site is set up exactly this way.

setup.ts
import { init } from '@vitus-labs/core'
import * as connector from '@vitus-labs/connector-styler'

init({ ...connector, component: 'div', textComponent: 'span' })

// import './setup' once, before anything renders
02

Keep an existing styled-components app

The connector re-exports styled-components itself, so the ui-system renders through the copy your app already uses.

main.tsx
import { init } from '@vitus-labs/core'
import * as connector from '@vitus-labs/connector-styled-components'
import { createRoot } from 'react-dom/client'
import App from './App'

init(connector)

createRoot(document.getElementById('root')!).render(<App />)
03

React Native with Expo

Hand core the native base components. The native styled takes a component, not a tag name, and filters $-props, as and data-* before they reach it.

init.ts · Badge.tsx
import { init } from '@vitus-labs/core'
import * as connector from '@vitus-labs/connector-native'
import { Text, View } from 'react-native'

init({ ...connector, component: View, textComponent: Text })

// Badge.tsx
import { styled } from '@vitus-labs/connector-native'

export const Badge = styled(View)`
  padding: 6px 12px;
  border-radius: 999px;
  background-color: ${({ theme }) => theme.accent};
  opacity: ${({ $muted }) => ($muted ? 0.5 : 1)};
`

— FAQ

Questions, answered.

Why `import * as connector`?

Connectors have no default export. A namespace import collects their named exports (css, styled, provider and the optional ones) into the object init() expects.

What happens if I forget init()?

Components created before init() are lazy, so nothing breaks at import time. Rendering one with no engine configured throws an error that shows the init() call to add.

Can I switch engines later?

Call init() once, at startup. Components created after it bind to that engine directly, so a later swap only affects components created afterwards. A full swap also clears optional members the new connector doesn't provide.

Do I need component and textComponent?

On the web they default to div and span, so init(connector) is enough. On React Native pass View and Text, because the primitives render them.

Which connector should I choose?

For a new web app, styler: it is the smallest engine and the only one with useCSS and collector-free React 19 SSR. If styled-components or Emotion is already in your app, use its connector and keep one engine in the bundle.

— @vitus-labs/connector-styler · @vitus-labs/connector-styled-components · @vitus-labs/connector-emotion · @vitus-labs/connector-native

Pick an engine. Keep the components.

npm i @vitus-labs/core @vitus-labs/connector-styler
Sources · 39 claims, each traced to v2.9.1 code or docs
  1. CSSEngineConnector: css, styled, provider required; keyframes, createGlobalStyle, useTheme optionalui-system:packages/core/src/config.ts
  2. Elements read styled/css/component from core's config, not an engineui-system:packages/elements/src/helpers/Wrapper/styled.ts
  3. Rocketstyle imports from @vitus-labs/coreui-system:packages/rocketstyle/src/rocketstyle.tsx
  4. css/styled are stable delegates safe to destructure before init(); css returns a thunk, styled a lazy componentui-system:packages/core/src/config.ts
  5. Components created after init() bind to the engine directly (fast path)ui-system:packages/core/src/config.ts
  6. Rendering without an engine throws an error showing the init() callui-system:packages/core/src/config.ts
  7. Configuration is a singletonui-system:packages/core/src/config.ts
  8. A full init() drops optional members the new connector doesn't provideui-system:packages/core/src/config.ts
  9. component/textComponent default to 'div'/'span'ui-system:packages/core/src/config.ts
  10. CSSEngineResult is an empty interface augmented by connectors via declaration mergingui-system:packages/core/src/config.ts
  11. connector-styler re-exports styler and augments CSSEngineResult with CSSResultnpm:@vitus-labs/connector-styler/lib/index.d.ts
  12. connector-styler exports useCSS; provider = ThemeProvider; named exports onlynpm:@vitus-labs/connector-styler/lib/index.d.ts
  13. connector-styled-components re-exports styled-components; css typed from its own return type; no useCSSui-system:packages/connector-styled-components/src/index.ts
  14. connector-styled-components derives css result type from styled-componentsui-system:packages/connector-styled-components/src/index.ts
  15. styled-components peer >= 6ui-system:packages/connector-styled-components/package.json
  16. connector-emotion wraps Emotion's css for styled-components-style composition (functions, arrays, nesting)ui-system:packages/connector-emotion/src/index.ts
  17. Emotion createGlobalStyle uses <Global> and injects the context themeui-system:packages/connector-emotion/src/index.ts
  18. Emotion keyframes objects kept as-is, not stringifiedui-system:packages/connector-emotion/src/index.ts
  19. Emotion connector doesn't export useCSSui-system:packages/connector-emotion/src/index.ts
  20. Emotion css returns string | function; CSSEngineResult not augmentedui-system:packages/connector-emotion/src/index.ts
  21. connector-native exports css, styled, provider/ThemeProvider, useTheme, createMediaQueries; augments CSSEngineResultui-system:packages/connector-native/src/index.ts
  22. Native: kebab-case to camelCase, px to numbersui-system:packages/connector-native/src/parse.ts
  23. Native: !important strippedui-system:packages/connector-native/src/parse.ts
  24. Native: multi-value shorthands (margin, padding, inset, borderWidth, border-radius) expand to longhandsui-system:packages/connector-native/src/parse.ts
  25. Native: nested blocks (&:hover, @media) droppedui-system:packages/connector-native/src/parse.ts
  26. Native: rem/em values not convertedui-system:packages/connector-native/src/parse.ts
  27. Native styled: filters as, $-prefixed, data-* by default; shouldForwardPropui-system:packages/connector-native/src/styled.ts
  28. Native styled takes a component (no styled.View shorthand)ui-system:packages/connector-native/src/styled.ts
  29. Native static templates skip window/theme hooksui-system:packages/connector-native/src/styled.ts
  30. Native dynamic components subscribe to useWindowDimensions (re-render on rotation)ui-system:packages/connector-native/src/styled.ts
  31. Native createMediaQueries checks window width at resolve timeui-system:packages/connector-native/src/createMediaQueries.ts
  32. Native connector has no keyframes or createGlobalStyle (docs comparison table)site:content/docs/connectors/native.mdx
  33. Elements native entry excludes Portal and Overlaynpm:@vitus-labs/elements/README.md
  34. Expo example: init with connector-native, View and Textui-system:examples/expo-native/src/init.ts
  35. Vite styled-components example: init(connector) via namespace importui-system:examples/vite-styled-components/src/main.tsx
  36. Next.js Emotion example: init(connector)ui-system:examples/nextjs-emotion/app/setup.ts
  37. This site initializes styler through connector-styler with a namespace importsite:src/ui/init.ts
  38. Collector-free SSR via <style precedence> is styler'sui-system:packages/styler/src/styled.ts
  39. styler is the smallest engine (6.98 KB vs styled-components 17.89 KB, Emotion 16.59 KB)npm:@vitus-labs/styler/README.md