Style variables
Currently, XWiki Standard with its Flamingo Skin support three kinds of style variables. They are (ranging from the oldest to the newest):
- The old colorTheme variables
- The LESS variables (Flamingo colorTheme + design system inherited from bootstrap + Misc additions from the Flamingo skin)
- XWiki 17.3.0+ The CSS properties
Migrating from LESS to CSS properties
This section contains a few points that could be important when migrating LESS styles to using the CSS properties. Those are not community rules to be followed, but just indications to make it easier to migrate
Syntax sugar
Native CSS is a bit more wordy than LESS:
- Variables start with a double dash (--) instead of an arobase (@)
- All use of a CSS variable should be made in a var block.
- All operations that you could write in your LESS must be made in a calc block.
--popover-arrow-outer-width: calc(var(--popover-arrow-width) + 1px);
Units in CSS calculus
LESS doesn't have any clearly defined unit system. CSS has a very strict unit system (some improvements to make it a bit looser and easier to use are discussed though). If a formula doesn't work in CSS, it's probably because the units do not respect the constraint of the operators:
- Addition and substraction, both values must have the same unit
- Multiplications and divisions, only one value has an unit, the second one is unitless.
The exact rules are more precise than that.
Migrating color functions
To migrate LESS color functions, you can use the CSS color or hsl functions:
HSL is useful for most operations, color is really only useful for transparency calculations.
LESS color functions work directly with additions: darken(@well-bg, 7%) is the same as the snippet above. This is slightly different from calc( l * (1-0.07)) which was how I assumed LESS handled its operations at first.
Using CSS variables in LESS
Sometimes you want to start migrating a file without being able to move it all at once. In this kind of situation, you'll need to know about how to use CSS variables in a LESS file.
The LESS parser we use in XWiki standard is not maintained enough to ensure a good compatibility with current CSS. It does not work well with CSS variables directly. The usual solution to escape things in LESS works well for most cases: a tilde and the escaped content in between quotes.
-/**/-navbar-default-border: ~"color-mix(in srgb, var(--navbar-default-bg), black 6.5%)";
But, a quirk of the parser is that this syntax does not work when we're trying to use it for an assignation. One hack that's not too bad looking that works for those variable assignations is to add an empty comment block in the middle. It prevents the LESS parser from associating the two dashes together and assume this is the end of an HTML comment. You can see this workaround in the example above.