AI RESOURCES
AI.md
System instructions and mental models for AI assistants working with Plumeria.
This document is for AI assistants (Claude, Gemini, ChatGPT, and others) generating code with Plumeria. When writing Plumeria code, always follow the rules and patterns described here.
Write Plumeria code with @plumeria/eslint-plugin enabled (plumeria.configs.recommended), and resolve every warning it reports.
Critical Rules (Quick Reference)
The complete rule set, distilled. Each rule is explained with examples in the sections below.
MUST:
- Call
css.create()at module top level, never inside a component. (→ Forbidden Patterns) - Bind styles with the
sxprop, notclassName. (→ Mental Model) - Import
@plumeria/corein every file that uses Plumeria styles, including files that only consume imported styles. It is required in a file that passes a style to a component through a prop other thansx, and safe and fastest everywhere else. (→ Core Usage) - Start nested selector keys with
:(pseudo) or[(attribute). (→ Selector Rules) - Explicitly declare a compound selector when simultaneous pseudo-class states set the same property. (→ Selector Rules)
- Compose with arrays; the right side always wins. (→ Core Usage)
NEVER:
- Pass a raw object to
sx, e.g.sx={{ color: 'red' }}. (→ Forbidden Patterns) - Call
css.create()inside a component body. (→ Forbidden Patterns) - Use the
&self-reference character. (→ Selector Rules) - Use a combinator (
>,+,~, a space) outside a functional pseudo-class. For parent-state or descendant styling, reach forcss.marker()/css.extended()first. (→ Selector Rules, Advanced APIs) - Use class-name keys such as
.title— style child elements directly. (→ Selector Rules) - Nest a pseudo-selector inside another pseudo-selector — write
':hover::before'as one key. (→ Selector Rules) - Nest a media/container query inside a pseudo-selector. The reverse (pseudo inside media) is allowed once. (→ Selector Rules)
- Mix
classNameandsxon the same element. (→ Forbidden Patterns) - Merge
css.use()output with the inlinestyleprop. (→ Dynamic Styling) - Route a function key through
css.use(), inline or through aStyleprop. (→ Dynamic Styling) - Pass a received
Styleprop on to another component. Apply it on the element the component renders. (→ Styling Custom Components) - Join
css.use()output with other class names, including anothercss.use()result passed throughclassName, or pass it to a function such asclsxorcss.use(). Pass every style to onecss.use()call. (→ Forbidden Patterns) - Read a definition from a namespace import by string key, destructuring or a rest element, or pass the namespace as a whole. Read it by name, as in
tokens.blue. (→ Forbidden Patterns) - Read a definition in an argument to a function key. Read it inside
css.create(). (→ Dynamic Styling)
Mental Model
AI assistants often misapply runtime CSS-in-JS habits to Plumeria. Correct your mental model:
- Styles are type schemas, not runtime objects. Plumeria definitions are static schemas read by the compiler; they do not exist as JavaScript objects at runtime.
css.create()is a compiler directive, not an object factory. Everything inside it is statically analyzed — the compiler must be able to read all styling information without executing code.sxis NOTclassName. Plumeria binds styles through its ownsxprop. Never reach forclassNamereflexively.- Zero-byte CSS in the JS bundle. All CSS is resolved at build time. The abstraction layer (your definitions) and the output layer (generated CSS) are completely separated, so Plumeria has no side effects and high referential transparency.
Core Usage
Define styles at module top level with css.create(), bind them with sx:
import * as css from '@plumeria/core';
const styles = css.create({
container: {
display: 'flex',
padding: '16px',
},
active: {
backgroundColor: 'blue',
},
});
export const MyComponent = ({ isActive }) => {
return (
<div sx={[styles.container, isActive && styles.active]}>
Hello Plumeria
</div>
);
};Right-wins composition. sx accepts arrays, ternaries, and conditional expressions. The right-most style always takes precedence: above, styles.active overrides styles.container when isActive is true. css.use() follows the same rule. Within a single style, do not rely on source order to resolve overlapping pseudo-class states; declare their compound selector explicitly (see Selector Rules).
Cross-file imports. Styles can be imported across files. A file that applies them with sx is compiled without further setup, but a file that passes them to a component through any other prop MUST contain import "@plumeria/core"; — the import is how the compiler finds the file. Keeping the import in every consuming file is always correct and is the fastest path, because the compiler accepts such a file without looking further.
Definitions from a package. A package whose exports point a plumeria condition at its TypeScript source, such as @plumeria/wind, is read like a local module by an app that lists it in its dependencies. A package without the condition is not read. A package that reads definitions from another Plumeria package needs both in the app's dependencies. If the app lists only the first, the build succeeds, but declarations that read the second are dropped.
Components from a package. The app's build compiles the components in such a package along with its own files, so an sx the app passes to one is settled at build time, as for a local component, and the bundler plugin needs no configuration for it. Write the component with Pattern 1 or Pattern 2 below: apply the received style on an element it renders. Every file in the directories the exports point to is compiled, so keep tests and stories outside them. A package that also keeps a default condition pointing at a dist gives that dist to apps without Plumeria, where the app's sx is not applied.
Imports that compile away. An import whose names are all compiled away is removed from the output, so a module imported only for its definitions is not loaded through it. If the module also has to run on import, add import './tokens'; beside it. An import still read at runtime, rendered as a component or re-exported stays.
Forbidden Patterns
Never generate these patterns. They break static analysis or cause runtime errors.
Passing an object directly to sx:
<span sx={{ fontSize: '12px' }}>Small Text</span>Creating styles inside a component body:
export const BadComponent = ({ dynamicColor }) => {
const dynamicStyles = css.create({
dynamic: {
color: dynamicColor,
},
});
// ...
};Mixing className and sx on the same element:
<span className="global-class" sx={styles.base}>Text</span>Joining css.use() output with other class names:
// Box.tsx
export const Box = ({ className }: { className?: string }) => (
<div className={css.use(styles.base) + ' ' + className} />
);
// Parent.tsx
<Box className={css.use(styles.blue)} />Strings from separate calls are not merged, so which rule wins depends on stylesheet order. Receive a css.Style prop and pass it to the same call instead, e.g. css.use(styles.base, style). (→ Styling Custom Components)
Reading a definition from a namespace import by anything but its name:
import * as tokens from './tokens';
const { styles } = tokens;
<div sx={tokens['styles'].card} />Every use of a definition is written in place at build time, so the compiler has to see which one is read. tokens.styles.card compiles as import { styles } from './tokens' does. A string key, destructuring, a rest element or passing tokens as a whole stops the build.
Complex JS expressions in style values. Only simple ternary operators are allowed, and only when necessary. Never put complex logic or function calls inside style values.
Selector Rules
Plumeria supports nesting for pseudo-classes, pseudo-elements, and attribute selectors — under strict rules:
- NO
&. Plumeria does not use the&self-reference character. - Nested keys MUST start with
:or[. Pseudo-classes/elements start with:; attribute selectors start with[. - Combinators only inside a functional pseudo-class.
>,+,~and the descendant space are rejected anywhere else.:has(),:is()and:where()are accepted, and a combinator inside one (e.g.':has(> img)') is the escape hatch for markup you do not write. For parent-state or descendant styling, prefer the pairedcss.marker()/css.extended()APIs (see Advanced APIs): they name no DOM path, so moving an element does not break them. - NO class-name keys. Keys like
.titleare not supported. Apply Plumeria styles directly to child elements instead. - NO pseudo inside pseudo. Write a compound pseudo-selector as one key, e.g.
':hover::before'. - NO same-name functional pseudo-class nesting, except
:not().':is(:where(:is(.a)))'stops the build; different names can nest, and':not(:not(.a), .b)'is allowed. A key cannot nest parentheses deeper than 16 levels or hold a stray quote. - Declare overlapping states explicitly. Pseudo-classes such as
:hover,:focus, and:activecan match simultaneously. When two states set the same property, declare their compound selector with the value the intersection should take. If they set different properties, no compound selector is needed. Functional pseudo-classes count too::nth-child(even)and:hoversetting the same property need the compound':nth-child(even):hover'. - Media/container query nesting is one-directional. A pseudo-selector may be nested inside a media/container query exactly once. The reverse — a media/container query inside a pseudo-selector — is forbidden and causes compiler/type errors.
const styles = css.create({
button: {
padding: '16px',
backgroundColor: 'white',
// VALID: Pseudo-classes and elements (starts with :)
':hover': {
boxShadow: '0 4px 12px rgba(0,0,0,0.1)',
},
':active': {
boxShadow: '0 1px 4px rgba(0,0,0,0.2)',
},
// VALID: :hover and :active can match together; the intersection gets its own value
':hover:active': {
boxShadow: '0 2px 6px rgba(0,0,0,0.3)',
},
'::before': {
display: 'block',
content: '""',
},
// VALID: Attribute selectors (starts with [)
'[data-active="true"]': {
borderColor: 'blue',
borderStyle: 'solid',
borderWidth: '2px',
},
// VALID: Pseudo-selector nested inside a media query (allowed once)
'@media (max-width: 768px)': {
padding: '8px',
':hover': {
boxShadow: 'none',
},
},
},
});
// INVALID: media query nested inside a pseudo-selector
const badStyles = css.create({
button: {
':hover': {
'@media (max-width: 768px)': {
backgroundColor: 'blue',
},
},
},
});Dynamic Styling
Function keys
For dynamic values (which would normally require React's inline style prop), define a function key in css.create(). Function keys compile to CSS variables — so unlike inline styles, they fully support @media and @container queries:
const styles = css.create({
palette: (color: string) => ({
backgroundColor: color,
// Media/container queries work on dynamic styles
'@media (max-width: 600px)': {
backgroundColor: 'blue',
},
}),
});
// Usage: <div sx={styles.palette(color)} />An argument reaches the output as written. A Plumeria definition read there, as in styles.palette(tokens.blue[500]), is not compiled and has no value at runtime. Read it inside css.create() instead.
Bracket notation (variants)
The css.variants() API has been removed in favor of standard bracket notation (styles[variant]). The compiler turns these expressions into static lookup tables at build time:
import * as css from '@plumeria/core';
// 1. Define variants in a dedicated, minimal css.create()
const sizeStyles = css.create({
small: {
fontSize: '12px',
},
medium: {
fontSize: '16px',
},
large: {
fontSize: '20px',
},
});
// 2. Type the variant (string literal union or keyof typeof)
type Size = keyof typeof sizeStyles;
interface ButtonProps {
size: Size;
children: React.ReactNode;
}
// 3. Resolve dynamically with bracket notation
export const Button = ({ size, children }: ButtonProps) => {
return <button sx={sizeStyles[size]}>{children}</button>;
};Best practices:
- Keep variant
css.create()calls minimal. Every key in acss.create()used with bracket notation is compiled into the generated lookup table (e.g.{__proto__:null,"small":"...","medium":"..."}[size]). Separate variants into dedicated calls; don't mix them with unrelated static styles. - Variant keys are selector-parsed: no spaces. Every key in a
css.create()— a variant key included — is read as a selector, so a key must not contain a space or combinator characters; a space is a descendant combinator and stops the build (no-combinator). When a display label contains a space, use a slug key and keep a label map for rendering: e.g. the status "On leave" becomes the keyonLeave, withconst statusLabels = { active: 'Active', onLeave: 'On leave', offline: 'Offline' }. - Local variable assignment is supported.
const currentStyle = sizeStyles[size]; <div sx={currentStyle} />works — the compiler traces local style variables and inlines them during JSX extraction.
css.use() returns a static string
css.use() compiles to a static class name string. It has no integration with the inline style prop — never attempt to merge or combine css.use() output with style. A function key cannot go through it, inline or through a Style prop: the value reaches the element as a CSS variable on style, which css.use() never sets.
Advanced APIs
css.marker() and css.extended() (paired descendant styling)
These paired APIs enable context-aware styling (e.g. styling a child when the parent is hovered) without naming a DOM path:
css.marker(id, pseudo)— sets a CSS variable marker on the parent when the pseudo state is active. MUST be spread into the parent style:...css.marker(...).css.extended(id, pseudo)— applies styles to descendants while the linked marker is active. Used as a computed key:[css.extended(...)].
import * as css from '@plumeria/core';
const styles = css.create({
parent: {
// 1. Set a marker with the unique id 'card' for the ':hover' state
...css.marker('card', ':hover'),
padding: '24px',
borderColor: '#ccc',
borderStyle: 'solid',
borderWidth: '1px',
},
child: {
transition: 'color 0.3s ease',
// 2. React to the 'card' marker being active
[css.extended('card', ':hover')]: {
color: 'blue',
// Further pseudo-classes can be nested here
':hover': {
color: 'darkblue',
},
},
},
});
export const Card = () => {
return (
<div sx={styles.parent}>
<span sx={styles.child}>Hover parent to make me blue!</span>
</div>
);
};At build time this compiles to an atomic container style query (@container style(--x1f9k2q1-card-hover: 1)) — zero runtime overhead, zero dependency on DOM hierarchy.
css.createStatic()
Defines static variables (such as media query strings) that are inlined at build time, typically used as computed keys in css.create():
import * as css from '@plumeria/core';
export const breakpoints = css.createStatic({
xs: '@media (max-width: 480px)',
sm: '@media (max-width: 640px)',
md: '@media (max-width: 768px)',
lg: '@media (max-width: 1024px)',
});
export const styles = css.create({
container: {
[breakpoints.sm]: {
padding: 16,
},
[breakpoints.lg]: {
padding: 32,
},
},
});A numeric key, as in a color scale, is quoted: '500': '#3b82f6'. An unquoted number stops the build. Read it as blue[500] or blue['500'].
css.createTheme()
Defines scoped CSS variables for themes. First argument: the selector that activates the theme. Second argument: an object of { default, theme } value pairs. Generated variable names are prefixed with a unique hash, so name collisions are impossible. Theme values are only compiled when actually used in a styling block.
import * as css from '@plumeria/core';
// Class-based theme
export const theme = css.createTheme('.dark', {
text: {
default: '#333',
theme: '#eaeaea',
},
background: {
default: 'white',
theme: 'black',
},
});
// Attribute selectors and media queries are also supported:
// css.createTheme('[data-theme="dark"]', { ... });
// css.createTheme('@media (prefers-color-scheme: dark)', { ... });css.keyframes()
Generates a unique @keyframes animation name (a hash inlined at build time) for use inside style rules:
import * as css from '@plumeria/core';
const fadeIn = css.keyframes({
from: {
opacity: 0,
},
to: {
opacity: 1,
},
});
const styles = css.create({
card: {
transition: 'transform 0.3s ease',
':hover': {
animationName: fadeIn,
animationDuration: '0.5s',
},
},
});css.viewTransitionClass()
Generates a unique view-transition-class, accepting animation definitions (group, imagePair, new, old) to customize View Transitions. Pass it to the default, enter, exit, update or share prop of React's <ViewTransition>, or set it with viewTransitionClass in css.create. The rules are emitted only for those two uses, so pass it to <ViewTransition> directly rather than through a wrapper component:
import * as css from '@plumeria/core';
const fadeIn = css.keyframes({
from: {
opacity: 0,
},
to: {
opacity: 1,
},
});
const fadeOut = css.keyframes({
from: {
opacity: 1,
},
to: {
opacity: 0,
},
});
const longCrossFade = css.viewTransitionClass({
old: {
animationName: fadeOut,
animationDuration: '1.2s',
},
new: {
animationName: fadeIn,
animationDuration: '1.2s',
},
});
// React usage:
// <ViewTransition default={longCrossFade}>...</ViewTransition>
// <ViewTransition name={`photo-${id}`} share={longCrossFade}>...</ViewTransition>css.varType()
Registers a typed custom property with @property and returns its name. Use it as a key to set the value and inside var() to read it. initialValue is required for every syntax but '*', and must not depend on where it is used (no em, rem, container units or var()):
import * as css from '@plumeria/core';
const angle = css.varType({
syntax: '<angle>',
initialValue: '0deg',
});
export const styles = css.create({
ring: {
background: `conic-gradient(from var(${angle}), red, blue)`,
transition: `${angle} 0.6s ease`,
':hover': {
[angle]: '180deg',
},
},
});css.positionTry()
Defines an @position-try rule and returns its dashed name for positionTryFallbacks. It only accepts positionAnchor, positionArea, inset, margin, sizing and self-alignment properties:
import * as css from '@plumeria/core';
const above = css.positionTry({
positionArea: 'top',
marginBottom: 8,
});
export const styles = css.create({
tooltip: {
position: 'absolute',
positionAnchor: '--trigger',
positionArea: 'bottom',
positionTryFallbacks: `${above}, flip-inline`,
},
});Styling Custom Components
There are exactly 2 patterns for applying Plumeria styles to custom components. In both, compilation happens at the sx call sites; the component itself just passes the compiled className / style through to the DOM.
Core principle: Custom props typed as
Styleare statically traced by the compiler, so styles pass seamlessly across component boundaries.
Pattern 1: Direct sx inside the component
The component imports its own styles and applies them internally. Simplest pattern — fully self-contained:
import React from 'react';
import * as css from '@plumeria/core';
const styles = css.create({
button: {
padding: '10px',
color: '#fff',
cursor: 'pointer',
backgroundColor: 'navy',
borderColor: 'currentColor',
borderStyle: 'none',
borderWidth: 'medium',
borderRadius: '4px',
},
});
export const Button = ({ children }: { children: React.ReactNode }) => {
return (
// The compiler transforms sx → className here
<button sx={styles.button}>
{children}
</button>
);
};
// Usage
<Button>Click me</Button>;Pattern 2: Passing a Style prop
A component takes a style through a prop typed as css.Style, named either sx itself or anything else (e.g. styleArray). The compiler reads the component's own parameter list: a prop the component declares is handed the key its lookup table resolves, rather than the class names an element would receive, so the style is traced across the component boundary and applied by the internal element's sx. A component the build never scans — one from a dependency — declares nothing the compiler can read, so an sx written on it is still resolved to class names at the call site, which is what a component forwarding className to its own element needs. Composing as [styles.text, styleArray] lets call-site styles override the component's base styles (right-wins — see Core Usage): below, the call site's fontSize: '24px' overrides the internal fontSize: '12px'.
// --- Button.tsx ---
import React from 'react';
import * as css from '@plumeria/core';
type ButtonProps = {
children: React.ReactNode;
styleArray?: css.Style;
};
// base style
const styles = css.create({
text: {
fontSize: '12px',
},
});
// Pass styleArray directly to the inner element's sx
export const Button = ({ children, styleArray }: ButtonProps) => {
return <button sx={[styles.text, styleArray]}>{children}</button>;
};
// --- Usage (call site) ---
import * as css from '@plumeria/core';
import { Button } from './Button';
const styles = css.create({
primary: {
padding: '10px',
color: '#fff',
backgroundColor: 'navy',
},
text: {
fontSize: '24px',
},
});
// The compiler traces styleArray and resolves it statically
<Button styleArray={[styles.primary, styles.text]}>Click me</Button>;Not a pattern: className={css.use(...)} on your own element
NEVER resolve styles with css.use() to apply them to an element your component renders. sx does the same job, and it also carries function keys, which css.use() cannot. Pattern 1 or Pattern 2 covers every element you render:
// INVALID: sx applies these to an element you render
<button className={css.use(styles.text, styleArray)}>{children}</button>
// VALID
<button sx={[styles.text, styleArray]}>{children}</button>css.use() is for the places sx cannot reach: a third-party component whose props have no Style type, a class name prop with another name such as overlayClassName, and templates that are not JSX (Vue, Svelte, Astro). The opt-in @plumeria/no-use-in-jsx lint rule reports every css.use() in JSX for projects that never need those.
Anti-pattern: relaying a Style prop
A component that receives a Style prop MUST apply it — to sx or through css.use() — on an element it renders. A style prop that is never applied is a build error, which is what happens when it is handed to another component instead.
What decides this is where the style ends up, not how many style props a component takes. Passing styles in is always fine:
// VALID: every value is a style, so any number of style props is fine
<Layout
headerStyle={styles.header}
bodyStyle={styles.body}
buttonStyle={styles.button}
/>Forwarding one onward instead of applying it is not:
// INVALID: headerStyle reaches no element of this component
export const Layout = ({ headerStyle }: { headerStyle?: css.Style }) => {
return <Header headerStyle={headerStyle} />;
};[plumeria] "headerStyle" is a style received through a prop but is never applied
to sx or css.use() here. Apply it on an element this component renders;
a style prop cannot be passed on to another component.Write one of these instead:
// VALID: Apply it on an element this component renders
export const Layout = ({ headerStyle }: { headerStyle?: css.Style }) => {
return <header sx={[styles.base, headerStyle]}>...</header>;
};
// VALID: Or drop the middle component and style the one that owns the element
<Header headerStyle={[styles.base, styles.primary]} />;Merging under a base style — [styles.base, headerStyle] — is the supported shape. What is rejected is the relay: a prop that is only forwarded, never applied.
A received style also cannot go through sx to a component that declares sx, even from another file and even when the same style is applied to an element as well:
// INVALID: Header declares sx
export const Layout = ({ sx }: { sx?: css.Style }) => {
return <Header sx={[styles.base, sx]} />;
};[plumeria] "sx" is a style received through a prop and cannot be passed on
to a component that declares sx. Apply it on an element this component renders.A component the build never scans declares nothing, so a received style composes onto it and resolves to class names at the call site:
// VALID: Dialog.Trigger comes from @plumeria/headlessui, a dependency
export const OpenButton = ({ sx }: { sx?: css.Style }) => {
return <Dialog.Trigger sx={[styles.base, sx]}>Open</Dialog.Trigger>;
};So the valid call site above stays valid only while Layout applies all three props itself. If it routes them onward to a grandchild, each unapplied prop is an error — which is the signal that the styles belong on the components that own those elements.
Prop drilling is an anti-pattern in React on its own terms; here it is also unresolvable, because the compiler would have to trace a style across an arbitrary chain of wrappers to build the lookup table. Rejecting it keeps the boundary decidable and the generated CSS exact.
Summary
| Pattern | Compilation site | Component's role |
|---|---|---|
1. Direct sx | Inside the component | Self-contained styles |
2. Style prop | Traced and compiled | Receives and applies Style |
In both patterns the component applies the style it receives. None of them forward it.
Migrating from Tailwind CSS
Tailwind's model and Plumeria's do not map one-to-one. A utility-by-utility rewrite produces code that fails to compile, silently breaks, or reads like Tailwind reimplemented. Migrate one component at a time, under three rules.
Resolve values from the compiled stylesheet, never from memory. Utility values come from the project's @theme, not from a fixed table: p-4 is calc(var(--spacing) * 4), text-sm sets font-size and a paired line-height, and the color scale is whatever the project defines. Build the project and read the declarations out of the emitted CSS.
NEVER carry a --tw-* variable chain across. shadow-lg compiles to --tw-shadow: … plus box-shadow: var(--tw-inset-shadow), …, var(--tw-shadow), and those variables hold a value only because Tailwind registers them with @property. Copied literally, the declaration is invalid and the shadow disappears. Resolve the chain to its final value instead.
Where a compiled value is Tailwind's default, read it from @plumeria/wind. The package holds the default theme of Tailwind CSS v4 as css.createStatic tokens, and each one compiles into the style that reads it, so nothing reaches the bundle. Install it with pnpm i -D @plumeria/wind and import it with import * as t from '@plumeria/wind'. It knows nothing of the project's @theme, so compare a token with the emitted CSS and keep the emitted value where the two differ. It generates no utility classes, so the key naming below still applies.
| Tailwind | @plumeria/wind |
|---|---|
p-4 | padding: t.spacing[4] |
text-sm | fontSize: t.text.sm, lineHeight: t.textLineHeight.sm |
font-medium | fontWeight: t.fontWeight.medium |
bg-blue-500, text-white | backgroundColor: t.blue[500], color: t.color.white |
rounded-md | borderRadius: t.radius.md |
shadow-lg | boxShadow: t.shadow.lg, which holds the resolved value |
md: | [`@media (width >= ${t.breakpoint.md})`]. The token is a length, so write the query around it; as a key on its own it produces no rule. |
animate-spin | animation: `${t.spin} ${t.animate.spin}` |
Name keys after what the element is, not after the utilities it carried. The class list is the input to the migration, not the output.
// INVALID: Tailwind reimplemented — these names carry no more meaning than the class list did
const styles = css.create({
hoverBgBlue500: {
':hover': {
backgroundColor: '#3b82f6',
},
},
px4: {
paddingInline: '1rem',
},
});
// VALID: One key per thing the component has
const styles = css.create({
submitButton: {
paddingInline: '1rem',
backgroundColor: '#2563eb',
':hover': {
backgroundColor: '#3b82f6',
},
},
});Three variants need restructuring rather than translation. Breakpoints (md:) and data-* variants map directly, to @media and attribute-selector keys. dark: depends on the project: it is @media (prefers-color-scheme: dark) by default, but @custom-variant dark commonly redefines it as a .dark class selector — which belongs in the restructuring set below, not the direct one. Check the compiled output before assuming which.
| Tailwind | Compiles to | Write instead |
|---|---|---|
hover:, focus: | &:hover { @media (hover: hover) { … } } | ':hover': { … }, dropping the @media (hover: hover) wrapper — Plumeria forbids a query inside a pseudo. The styles then apply on touch devices too. |
group-*, peer-* | &:is(:where(.group):hover *) | css.marker() on the parent and css.extended() on the descendant. The .group / .peer class disappears. |
space-x-*, divide-* | :where(& > :not(:last-child)) | The margin or border applied to the children directly — a child combinator is only accepted inside a functional pseudo-class. |
tv() and twMerge()
| Tailwind Variants | Plumeria |
|---|---|
base | Static keys in the component's own css.create() |
variants | One dedicated css.create() per variant group, read with bracket notation (keep these calls minimal — see Bracket notation) |
defaultVariants | Default parameter values |
compoundVariants | An explicit condition in the sx array |
slots | One css.create() per element, not one call carrying every slot |
An external className override becomes a Style prop, not a className. twMerge(button(...), className) exists to let the call site win; Pattern 2 does the same job, because array position is right-wins. NEVER resolve the override away, force it through css.use(), or change the component's public API to avoid the mixing rule.
NEVER guess a class name that was built at runtime. A template literal or a value read from props or state is not statically knowable. Leave the component on Tailwind and report it; a guessed utility compiles and is silently wrong.
// --- Before ---
const button = tv({
base: 'inline-flex rounded font-medium',
variants: {
size: { sm: 'h-8 px-3 text-sm', lg: 'h-12 px-6 text-lg' },
tone: { primary: 'bg-blue-500 text-white', danger: 'bg-red-500 text-white' },
},
compoundVariants: [{ size: 'lg', tone: 'primary', class: 'shadow-lg' }],
defaultVariants: { size: 'sm', tone: 'primary' },
});
<button className={twMerge(button({ size, tone }), className)} />;
// --- After (values resolved from the project's compiled CSS, not recalled) ---
const styles = css.create({
base: {
display: 'inline-flex',
fontWeight: 500,
borderRadius: '4px',
},
lgPrimary: {
boxShadow: '0 10px 15px -3px rgb(0 0 0 / 0.1)',
},
});
const sizeStyles = css.create({
sm: {
height: '32px',
paddingInline: '12px',
fontSize: '14px',
},
lg: {
height: '48px',
paddingInline: '24px',
fontSize: '18px',
},
});
const toneStyles = css.create({
primary: {
color: '#fff',
backgroundColor: '#3b82f6',
},
danger: {
color: '#fff',
backgroundColor: '#ef4444',
},
});
type ButtonProps = {
size?: keyof typeof sizeStyles;
tone?: keyof typeof toneStyles;
styleArray?: css.Style;
};
export const Button = ({ size = 'sm', tone = 'primary', styleArray }: ButtonProps) => (
<button
sx={[
styles.base,
sizeStyles[size],
toneStyles[tone],
size === 'lg' && tone === 'primary' && styles.lgPrimary,
styleArray,
]}
/>
);On a project that keeps the default theme, the same two groups read from @plumeria/wind:
import * as css from '@plumeria/core';
import * as t from '@plumeria/wind';
const sizeStyles = css.create({
sm: {
height: t.spacing[8],
paddingInline: t.spacing[3],
fontSize: t.text.sm,
lineHeight: t.textLineHeight.sm,
},
lg: {
height: t.spacing[12],
paddingInline: t.spacing[6],
fontSize: t.text.lg,
lineHeight: t.textLineHeight.lg,
},
});
const toneStyles = css.create({
primary: {
color: t.color.white,
backgroundColor: t.blue[500],
},
danger: {
color: t.color.white,
backgroundColor: t.red[500],
},
});Testing
NEVER stub @plumeria/core. It publishes types and no runtime. A moduleNameMapper entry or a hand-written mock makes the suite run, but every class name it produces is invented, so the test says nothing about the styles. If a runner cannot resolve the package, that is the signal to test a different layer, not to fake the package.
NEVER assert a generated class name in a component test. xvdv6o3r is one property-value pair, hashed. Adding a property to the style breaks every test that spelled the old list out. Assert what the component renders, holds, or branches on.
To test component behavior, put the transform in the runner's module pipeline. This is the only layer that needs it. Vitest takes the plugin in its config:
export default defineConfig({
plugins: [react(), plumeria.vite()],
test: { environment: 'jsdom' },
});Jest takes @plumeria/swc-jest in place of @swc/jest, ts-jest or babel-jest; SWC options stay in .swcrc or beside the transformer:
module.exports = {
testEnvironment: 'jsdom',
transform: { '^.+\\.(t|j)sx?$': '@plumeria/swc-jest' },
};jsdom applies no stylesheet. document.styleSheets is empty and getComputedStyle returns initial values. A test there can see which classes were attached, never what they do. Anything about the cascade — specificity, @media, marker with extended — belongs in an end-to-end test against a real browser.
Toolchain Notes
Setup. Do not write the configuration by hand. npx @plumeria/init detects the package manager and the bundler, installs the packages, writes plumeria.d.ts and the bundler config, extends the ESLint flat config, and on esbuild and Bun puts plumeria-lint -- in front of the build script. The other bundler plugins lint the build themselves. It shows the plan before it writes, --dry-run stops at the plan, and --yes takes every default without asking, which is what makes it usable without a TTY. A project that is already set up reads as done and nothing is written.
Compiler expectations. The compiler statically extracts css.create() calls, which is why they MUST sit at module top level. Prefer direct, clearly defined references — indirect variable references may be unanalyzable.
ESLint guarantees. @plumeria/eslint-plugin enforces Plumeria's rules. Treat its errors as blocking, and its warnings (such as no-order-dependent-overlap) as defects to resolve rather than noise. It checks:
- CSS property value validation — invalid values are caught at lint time.
- Property sort order — one canonical order is enforced; the full order is specified under Property order below.
- Property formatting — one property per line, with no empty lines between properties; see Property formatting below.
- Unused style detection — unused styles are flagged automatically.
Follow the plugin's rules as documented in its README.md.
Property order. Properties MUST appear in the order sort-properties enforces, and a warning stops the build, so write them in this order from the start — group by group, and within a group in the order listed:
- composes
- all
- position, positionAnchor, positionArea, positionTry, positionTryOrder, positionTryFallbacks, positionVisibility, anchorName, anchorScope, inset, insetBlock, insetBlockStart, insetBlockEnd, insetInline, insetInlineStart, insetInlineEnd, top, right, bottom, left, zIndex, float, clear
- boxSizing, display, visibility
- flex, flexGrow, flexShrink, flexBasis, flexFlow, flexDirection, flexWrap, WebkitBoxOrient
- grid, gridArea, gridTemplate, gridTemplateAreas, gridTemplateRows, gridTemplateColumns, gridRow, gridRowStart, gridRowEnd, gridColumn, gridColumnStart, gridColumnEnd, gridAutoRows, gridAutoColumns, gridAutoFlow, gridGap, gridRowGap, gridColumnGap
- gap, rowGap, columnGap, placeContent, placeItems, placeSelf, alignContent, alignItems, alignSelf, justifyContent, justifyItems, justifySelf
- order
- inlineSize, minInlineSize, maxInlineSize, width, minWidth, maxWidth, blockSize, minBlockSize, maxBlockSize, height, minHeight, maxHeight, aspectRatio
- padding, paddingBlock, paddingBlockStart, paddingBlockEnd, paddingInline, paddingInlineStart, paddingInlineEnd, paddingTop, paddingRight, paddingBottom, paddingLeft, margin, marginBlock, marginBlockStart, marginBlockEnd, marginInline, marginInlineStart, marginInlineEnd, marginTop, marginRight, marginBottom, marginLeft
- overflow, overflowInline, overflowBlock, overflowX, overflowY, scrollbarGutter, WebkitOverflowScrolling, msOverflowX, msOverflowY, msOverflowStyle, textOverflow, WebkitLineClamp, lineClamp, scrollBehavior
- overscrollBehavior, overscrollBehaviorInline, overscrollBehaviorBlock, overscrollBehaviorX, overscrollBehaviorY
- font, fontFamily, fontSize, fontSizeAdjust, fontVariationSettings, fontStyle, fontWeight, fontOpticalSizing, fontStretch, fontFeatureSettings, fontKerning, fontVariant, fontVariantLigatures, fontVariantCaps, fontVariantAlternates, fontVariantNumeric, fontVariantEastAsian, fontVariantPosition, WebkitFontSmoothing, MozOsxFontSmoothing, fontSmooth
- lineHeight, verticalAlign, alignmentBaseline, baselineShift, dominantBaseline
- color, WebkitTextFillColor, WebkitTextStroke, WebkitTextStrokeWidth, WebkitTextStrokeColor
- textAlign, textAlignLast, textJustify, textIndent, textTransform, wordSpacing, letterSpacing, hyphens, wordBreak, textWrap, wordWrap, overflowWrap, tabSize, whiteSpace, whiteSpaceCollapse
- textEmphasis, textEmphasisColor, textEmphasisStyle, textEmphasisPosition, textDecoration, textDecorationLine, textDecorationThickness, textDecorationStyle, textDecorationColor, textUnderlinePosition, textUnderlineOffset, textShadow
- src, fontDisplay, unicodeRange, sizeAdjust, ascentOverride, descentOverride, lineGapOverride
- appearance, accentColor, pointerEvents, msTouchAction, touchAction, cursor, caretColor, zoom, resize, userSelect, WebkitUserSelect, navIndex, navUp, navRight, navDown, navLeft, outline, outlineWidth, outlineStyle, outlineColor, outlineOffset
- colorScheme
- tableLayout, emptyCells, captionSide, borderSpacing, borderCollapse
- content, quotes
- listStyle, listStylePosition, listStyleType, listStyleImage, counterReset, counterSet, counterIncrement
- scrollSnapType, scrollSnapAlign, scrollSnapStop, scrollPadding, scrollPaddingBlock, scrollPaddingBlockStart, scrollPaddingBlockEnd, scrollPaddingInline, scrollPaddingInlineStart, scrollPaddingInlineEnd, scrollPaddingTop, scrollPaddingRight, scrollPaddingBottom, scrollPaddingLeft, scrollMargin, scrollMarginBlock, scrollMarginBlockStart, scrollMarginBlockEnd, scrollMarginInline, scrollMarginInlineStart, scrollMarginInlineEnd, scrollMarginTop, scrollMarginRight, scrollMarginBottom, scrollMarginLeft
- scrollbarColor, scrollbarWidth
- objectFit, objectPosition, msInterpolationMode, imageOrientation, imageRendering, imageResolution
- background, backgroundColor, backgroundImage, backgroundRepeat, backgroundAttachment, backgroundPosition, backgroundPositionX, backgroundPositionY, backgroundClip, backgroundOrigin, backgroundSize, border, borderColor, borderStyle, borderWidth, borderBlock, borderBlockColor, borderBlockStyle, borderBlockWidth, borderBlockStart, borderBlockStartColor, borderBlockStartStyle, borderBlockStartWidth, borderBlockEnd, borderBlockEndColor, borderBlockEndStyle, borderBlockEndWidth, borderInline, borderInlineColor, borderInlineStyle, borderInlineWidth, borderInlineStart, borderInlineStartColor, borderInlineStartStyle, borderInlineStartWidth, borderInlineEnd, borderInlineEndColor, borderInlineEndStyle, borderInlineEndWidth, borderTop, borderTopColor, borderTopStyle, borderTopWidth, borderRight, borderRightColor, borderRightStyle, borderRightWidth, borderBottom, borderBottomColor, borderBottomStyle, borderBottomWidth, borderLeft, borderLeftColor, borderLeftStyle, borderLeftWidth, borderRadius, borderStartStartRadius, borderStartEndRadius, borderEndStartRadius, borderEndEndRadius, borderTopLeftRadius, borderTopRightRadius, borderBottomRightRadius, borderBottomLeftRadius, borderImage, borderImageSource, borderImageSlice, borderImageWidth, borderImageOutset, borderImageRepeat, boxShadow
- backgroundBlendMode, isolation, mixBlendMode
- filter, backdropFilter
- clip, clipPath, maskBorder, maskBorderSource, maskBorderSlice, maskBorderWidth, maskBorderOutset, maskBorderRepeat, maskBorderMode, mask, maskImage, maskMode, maskRepeat, maskPosition, maskClip, maskOrigin, maskSize, maskComposite
- writingMode
- textAnchor, fill, fillRule, fillOpacity, stroke, strokeOpacity, strokeWidth, strokeLinecap, strokeLinejoin, strokeMiterlimit, strokeDasharray, strokeDashoffset, colorInterpolation, colorInterpolationFilters, floodColor, floodOpacity, lightingColor, markerStart, markerMid, markerEnd, stopColor, stopOpacity, shapeRendering
- transform, transformOrigin, rotate, scale, translate, perspective, perspectiveOrigin
- transition, transitionDelay, transitionTimingFunction, transitionDuration, transitionProperty
- animation, animationName, animationDuration, animationTimingFunction, animationDelay, animationIterationCount, animationDirection, animationFillMode, animationPlayState, animationComposition, animationTimeline, animationRange, animationRangeStart, animationRangeEnd
- willChange
- breakBefore, breakAfter, breakInside, widows, orphans
After every plain property, nested keys follow in this order: pseudo selectors (:hover and the like), then & selectors, then @media and @container blocks. A property that does not appear in the list sorts after the listed properties and before the selectors.
Border shorthands. Never write border, borderBlock, borderInline, borderTop, borderRight, borderBottom, borderLeft, borderBlockStart, borderBlockEnd, borderInlineStart or borderInlineEnd. A border shorthand always sets a width, a style and a color at once, even when the value names only one of them, and expand-border-shorthands rejects it. Write the three declarations it stands for instead — borderColor, borderStyle, borderWidth, or the per-side forms such as borderTopColor, borderTopStyle, borderTopWidth. For example, border: 'none' becomes:
borderColor: 'currentColor',
borderStyle: 'none',
borderWidth: 'medium',The per-side forms expand into their own three longhands, and the axis forms (borderBlock, borderInline) expand the same way into borderBlockColor, borderBlockStyle, borderBlockWidth and their borderInline counterparts. For example, borderTop: '1px solid #d1d5db' becomes:
borderTopColor: '#d1d5db',
borderTopStyle: 'solid',
borderTopWidth: '1px',A component the value does not name takes its initial value — width medium, style none, color currentColor — and is still written out, so borderInlineStart: '2px dashed' becomes:
borderInlineStartColor: 'currentColor',
borderInlineStartStyle: 'dashed',
borderInlineStartWidth: '2px',Property formatting. In a style object, every property sits on its own line, and there are no empty lines between properties. format-properties rejects both a shared line and a blank line, and a warning stops the build, so expand compact objects when you write them. A variant map entry such as:
design: { color: '#1d4ed8', backgroundColor: '#dbeafe' },is written:
design: {
color: '#1d4ed8',
backgroundColor: '#dbeafe',
},