Hi! I was working on the PR for XWIKI-21584: Mentions do not have enough contrast and figured out a codestyle rule would have made it easier to fix.
Proposal
All colors must be defined for either a foregound or a background. To name those, use color
for foreground color, and background
or bg
for background colors.
Explanation
This codestyle contains 2 parts:
A. All colors must be background OR foreground.
B. Naming convention for background and foreground colors.
Keeping contrast correct on all elements is not easy without such a standard. Here is an example for part A. :
Dev1 defined
color1
andbg1
to style UI1. Later on, Dev1 does not respect the codestyle proposal A., and usescolor1
as a background color, withcolor2
as a foreground color for UI2. On the theme of Dev1, the contrast is okay. However, Admin1 uses its own corporate color theme. They saw howcolor1
andbg1
were used in UI1, and updated those colors to fit their color theme. However, when they update their instance and get to see UI2, it looks broken. Making sure the colors used have correct contrast will be difficult for Admin1: just changingcolor2
is not enough becausecolor1
is too dark as a background… Here, in order to make sure it’s easy to migrate, Dev1 should have introduced a new variablebg2
to style UI2 (even if it has the exact same value ascolor1
in the default colortheme).
Part B. is just to make sure it’s easy to apply and respect part A. It makes sure we don’t have half the pairs named as color+background
and the other half named as foreground+color
.
Note that we already respect this codestyle in most places in xwiki-platform. In my opinion we should add it as a codestyle to make sure we have a better consistency.
Conclusion
Do you agree with adding this codestyle to our CSS Codestyle, right after don't hard code colors in properties
?
Note that this rule should also be generalized to the content of color variables defined in other files. IMO it makes the most sense to have it in the CSS codestyle rules, but we might also want to put it in XWiki XML Files Code Style but I’d rather not duplicate the doc.