WindRecipe class final

A Tailwind-Variants tv() Equivalent for Wind

WindRecipe composes a single element's className from a base, a set of variants (one axis per key, each mapping a value to a className), optional compoundVariants (multi-condition rules), and defaultVariants (the selection applied when the caller does not pass an axis).

Resolution

Calling the recipe merges {...defaultVariants, ...selected}. A null in the selection CLEARS the default for that axis (no class emitted), matching tv()'s undefined-clears semantics. The result is joined in STRICT order:

base ++ variant-classes(definition order) ++ matched-compound(array order) ++ caller

Why no dedupe / sort / twMerge

Wind's parser resolves conflicts per family with last-class-wins AT PARSE-TIME (wind_parser.dart findAndGroupClasses). State-prefixed tokens (hover:, dark:, md:) only collapse correctly when their emission order is preserved verbatim, so the recipe NEVER applies toSet(), sort, or a tailwind-merge style resolver. A trailing caller hover:bg-blue-700 must survive next to a base hover:bg-blue-500 for the parser to pick the last.

Same-granularity-override contract

Because parser last-wins is per-family, a variant must override a base token at the SAME granularity (override px-* with px-*, never mix p-* and px-*): the parser would silently keep the shorthand. A debug-only lint (stripped from release via assert) warns when a base and a resolved variant touch a shorthand+longhand pair of the same family.

Example Usage:

final button = WindRecipe(
  base: 'inline-flex items-center rounded font-medium',
  variants: {
    'intent': {
      'primary': 'bg-blue-500 text-white',
      'ghost': 'bg-transparent text-blue-500',
    },
    'size': {'sm': 'px-2 py-1 text-sm', 'lg': 'px-4 py-2'},
  },
  compoundVariants: [
    WindCompoundVariant(
      conditions: {'intent': 'primary', 'size': 'lg'},
      className: 'shadow-lg',
    ),
  ],
  defaultVariants: {'intent': 'primary', 'size': 'sm'},
);

// Variant axis keys are plain strings; pass enum values as `.name`.
button(variants: {'intent': ButtonIntent.ghost.name});
Annotations

Constructors

WindRecipe({String base = '', Map<String, Map<String, String>> variants = const {}, List<WindCompoundVariant> compoundVariants = const [], Map<String, String> defaultVariants = const {}})
Creates a single-element recipe.
const

Properties

base → String
The always-applied base className.
final
compoundVariants → List<WindCompoundVariant>
The compound-variant rules, evaluated in list order.
final
defaultVariants → Map<String, String>
The default selection applied when an axis is not passed by the caller.
final
hashCode → int
The hash code for this object.
no setterinherited
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited
variants → Map<String, Map<String, String>>
The variant axes: axis -> (value -> className). Iteration order of this map fixes the emission order of variant classes.
final

Methods

call({Map<String, String?>? variants, String? className}) → String
Resolves the recipe into a single className string.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() → String
A string representation of this object.
inherited

Operators

operator ==(Object other) → bool
The equality operator.
inherited