Skip to content

Use typed helpers

Use the narrowest helper when the style is intended for a single primitive:

  • viewStyle
  • textStyle
  • imageStyle

For finite utility scales, use defineProperties and createSprinkles from the same authoring entrypoint. Declare the primitive domain explicitly so a view utility cannot accidentally carry text-only or image-only properties.

import { createSprinkles, defineProperties } from "@opsydyn/crumbs-css/style"
const viewProperties = defineProperties({
primitives: ["view"] as const,
properties: {
paddingLeft: { sm: 8, lg: 24 },
paddingRight: { sm: 8, lg: 24 },
},
shorthands: { px: ["paddingLeft", "paddingRight"] as const },
})
export const sprinkles = createSprinkles(viewProperties)
export const card = sprinkles({ px: "sm", paddingLeft: "lg" })

Selections are applied in object order. The paddingLeft longhand therefore wins over the earlier px alias, while paddingRight stays at 8. Scale values must be finite and property-compatible; domain-branded theme tokens are accepted only by compatible properties.

When a component chooses a utility at runtime, generate a lookup plan in the authored module and resolve it from the theme runtime. The plan is finite and non-Cartesian: it stores one compiled reference per property and scale.

spacing.css.ts
import { createSprinklesLookupPlan } from "@opsydyn/crumbs-css/style"
export const sprinklesPlan = createSprinklesLookupPlan(viewProperties, "spacing")
import { createSprinklesResolver } from "@opsydyn/crumbs-css/theme"
import { useThemedStyles } from "@opsydyn/crumbs-css/theme/core"
import { useMemo } from "react"
function Card({ compact }: { compact: boolean }) {
const themed = useThemedStyles({ sprinklesPlan })
const resolve = useMemo(
() => createSprinklesResolver(themed.sprinklesPlan),
[themed.sprinklesPlan],
)
return <View style={resolve({ px: compact ? "sm" : "lg" })} />
}

The resolver preserves selection and shorthand target order, returns a readonly style array, and exposes a bounded local cache with getCacheStats, clearCache, and dispose controls. createSprinkles remains the static authored path; NativeSprinklesLookupPlan and NativeSprinklesResolver keep the two phases distinct in public types.

import { imageStyle, textStyle, viewStyle } from "@opsydyn/crumbs-css/style"
export const panel = viewStyle({
padding: 24,
})
export const title = textStyle({
fontSize: 18,
fontWeight: "700",
})
export const crest = imageStyle({
height: 48,
resizeMode: "cover",
width: 48,
})
const copy = textStyle({ color: "black", fontSize: 16 })
export const heading = textStyle([copy, [{ fontSize: 24, fontWeight: "700" }]])

Later authored entries override the same native property. Crumbs helpers accept multiple bases, repeated bases and nested readonly arrays, with the same primitive inline property checks. styleVariants also accepts composed values. Use the Crumbs authoring entrypoint for this ordered native contract; direct vanilla-extract composition retains upstream class-list processing.

Finite utility values can drive mapped state variants and recipes without casting the generated styles:

const sizes = { compact: "sm", roomy: "lg" } as const
export const sizeStates = styleVariants(sizes, (scale) => sprinkles({ px: scale }))
export const card = recipe({
base: sprinkles({ px: "sm" }),
variants: { size: sizeStates },
})

The mapper preserves the utility’s primitive result and token-backed payload. Recipe bases, branches, and compound styles use the same native composition path, so later authored declarations retain deterministic precedence.

Physical padding/margin, their horizontal/vertical aliases, and gap normalize identically for tokens and literals before merging. Later declarations replace overlapping longhands both within a rule and across compositions. Compiled artifacts now expose physical side keys and rowGap/columnGap, rather than their shorthand keys. Regenerate dependent compiled modules together and pass complete style objects to React Native; raw runtime style objects do not receive this normalization. Logical/RTL declarations, border/flex families and mixed multi-value token expressions remain outside this coverage.

They improve type safety for native styles:

  • obvious cross-kind props fail earlier
  • theme tokens remain supported
  • intent is clearer to readers and tooling

Use style when a single export intentionally mixes properties across style kinds or you want a generic native style surface.