Panda CSS
UX CSS brings the css() function of Panda CSS to Twig. For the same
configuration, it gives the same class names and the same CSS as Panda. It
does not run Panda: the rules are written in PHP.
How the output is kept identical
The reference is Panda's own test suite. A maintainer script runs it on a
fixed version of Panda and records every css() call it makes: the input,
the configuration, and the classes and CSS that Panda produced. The bundle's
tests replay each recorded call and compare the output. The
CONTRIBUTING.md file of the package explains how to record them again.
What differs on purpose
- Styles are checked when Twig compiles the template, with the rules of Panda's generated TypeScript types, instead of by the TypeScript compiler.
strict_tokensandstrict_property_valuesare enabled by default. Panda disablesstrictTokensandstrictPropertyValuesby default. For the same options, both accept and refuse the same styles, with one exception: the CSS-wide keywords,inherit,initial,unset,revertandrevert-layer, are accepted on every property. Panda's strict types refuse them on properties bound to tokens.- A value can contain quotes only as complete CSS strings, like
content: '""'orgridTemplateAreas: '"nav main"'. It cannot contain;,{,}, a backslash,<or a CSS comment, inside a string or not, nor a line break inside a string. Socontent: '"\2192"'andcontent: '"a'are refused. A selector or at-rule key cannot contain quotes. - For a few unusual values, such as
'0.50', repeated spaces or abasekey at the top of the hash, Panda's runtime and its build step give different class names. UX CSS names the classes of the values written in the template like the build step. That way, they always have their CSS. - The configuration is written in YAML or PHP, under
ux_css. A token is written as its value. Panda's{ value: ... }form is accepted too. css()takes a single hash. Panda'scss(a, b), which merges several style objects, is not supported.- When the default value of a semantic color uses the
/opacity syntax, its values for other conditions, such as_dark, are kept. Panda drops them. - In
static_css,*also works on a shorthand, such asp. - The generated file only declares the layers it writes:
tokensandutilities, plusresetwithpreflight. Panda declares its five layers,reset, base, tokens, recipes, utilities, in the file. Declare the order of all your layers in your own stylesheet, see The css() function. - The
preflightoption is writtenpreflight: trueorpreflight: { scope: '.reset', level: element }, like in Panda. It also takes anenabledkey, as the other options of Symfony bundles that can be turned off.
Not supported yet
These features of Panda CSS have no equivalent yet:
- recipes and slot recipes (
cva), and patterns (stack,grid...); - text styles, layer styles and animation styles;
- themes, and the
hashoption for class names; - global CSS, keyframes and custom utilities in the configuration;
- importing tokens from a W3C design tokens file.
This work, including the code samples, is licensed under a
Creative Commons BY-SA 3.0 license.