Hello!
Context
Having a class in a generic place is useful to provide information about the state of the UI to different stylesheets.
This is especially useful when we have access in velocity to state info that changes the styles.
For a long time, the body node on XWiki pages have contained information about the state of panels (.hideright, .hideleft), drawer position (.drawer) and the current Skin (.flamingo-skin).
I think it’s an appropriate solution to a few situations, and I personally used it in some more recent developments: panel-left-width-<X> and preference-underlining-only-inline-link. I plan to use this again to convey the “isAdvancedUser” info at https://github.com/xwiki/xwiki-platform/pull/5001 .
Note that another solution for those situations would be to use CSS variables to contain this info. This is a more powerful system, but it’s more fragile (any stylesheet can change the value to what it wants and influence other stylesheets…). IMO it’s out of the question as long as we support LESS stylesheets because they do not work well with CSS variables and there’s no easy parallel solution we could make with LESS variables.
Proposals
- Set the
<body>classes as API. - Add the
advanced-userclass to the<body>
Details
- This entails updating the documentation. I’d take time to take care of it of course.
- This means that any change forward on the classes available on the body object should be proposed/voted and documented.
- We should eventually add automated tests to cover that those classes are available (at the very least for a standard use-case).
Explanation
This is a very stable implementation. I’d rather have custom stylesheets rely on these than anything else. Without an API, we end up having to repeat this state information in the velocity templates for every component that needs it, which can be innefficient computationally (e.g. check edit rights a few times through the templates for the page, one should be enough to provide enough info for CSS to work as expected). In addition, it clutters the code and generated HTML.
This would be the first HTML API as far as I know (it’s a bit different from indications found on front end components docs). We can use the experience on this to see what works/what are the limits of doing this.
Here’s my +1 for proposals 1. and 2.
@mleduc What do you think of this (especially no.1)? How do you do those “conditional styles” in Cristal?
Thank you for your interest in the topic!
Lucas C.

