tx styling
When to use
- Editing components that use the
txprop ortxtemplate literals. - Integrating
@landfolk/txinto a React/Next.js app. - Debugging grouping, Tailwind extraction, or linting around
tx.
Core rules
- Prefer
txoverclassNamefor Tailwind classes. - Use arrays for conditional styles; avoid string concatenation.
- Use grouping syntax like
hover:(bg-blue-500 text-white). - Do not forward
txprops; only forwardclassName. - For styleable components, merge
classNameintotx.
Tooling overview
- SWC plugin rewrites
txtoclassNameat compile time. - Tailwind transformer expands grouped classes for JIT extraction.
- ESLint rule sorts and validates classes.
Grouping syntax
Example:
tsx1<div tx="hover:(bg-blue-500 text-white)" />
Compiles to className="hover:bg-blue-500 hover:text-white".
Groups can be nested.
SWC transform
tx="..."becomesclassName="...".- Arrays like
tx={[cond && tx...]}become joinedclassNamearrays. - Tagged
txtemplates expand at compile time. - In dev, class strings can be wrapped with a conflict checker if registered.
Register the dev-only conflict checker once:
ts1import '@landfolk/tx/checkConflicts'
Tailwind transformer
The transformer scans tx attributes and template literals to expand grouped
syntax into full class lists so Tailwind JIT sees every class.
ESLint rule
@landfolk/tx/optimize-tailwind-classes:
- Expands grouped syntax and re-compacts in a stable order.
- Sorts classes using Tailwind's internal order.
- Normalizes whitespace in arbitrary values.
- Can validate class names when given a Tailwind config path.
Getting started
See getting-started.md for install, config, and Next.js compatibility.