Closed LTiger14 closed 5 years ago
Css variables (custom properties)
margin: var(--cx-margin, 0 10px 0 10px);
..test {
Margin: var(--cx-color);
}
Ok
:root {
--cx-color: red;
}
.test { Margin: var(--cx-color); }
Most css variables will be scoped to a class or element but we should still aim to provide variables with a global scope. To distinguish the two types of variables, we should use a separate naming convention for global variables. These variables should be named --cx-theme-{name of the rule}.
### Bonus
_Suggestion:_ Use css variables in the theme. At the moment, we are mostly using sass variables with at static value. These values should be replaced with a css var and a fallback. This allows easier customisation for theme variables used inside of the styles lib rather than outside. For example, the font sizes are used inside the type mixin. Therefore there is no easy way to change the value of those variables so they have an effect inside the mixin. To fix this, we can do : `$h1-font-size: var(--cx-theme-h1, $font-size-base * 2.25);`. Afterwards, this variable can be modified in the :root of the app styles.
@LTiger14 I actually thought this ticket was going to be only about the list of css variables :) That being said, this list is also needed, and should be based on https://github.com/SAP/cloud-commerce-spartacus-storefront/issues/11#issuecomment-438174669.
we could either change this ticket, or start with a new one to come up with the css variable list. Where I think we should have 2 groups:
Theme variables:
--cx-theme-border-radius
--cx-theme-transition-time
Component variables:
--cx-width
--cx-margin
The effort of this/that ticket would be to come up with an initial list.
btw. I wouldn't mind to find a shortcut for --cx-theme
...
I'd prefer to transition this ticket and have it more focused on getting the list.
Like @tobi-or-not-tobi mentioned, we should have to groups of css variables.
Side note: In the styles library theme, there are multiple variables that aren't !default
and therefore can't be easily overridden in their use within the styles lib. If the objective is also to override them we could add the following:
Similarly :
Documentation added
Come up with naming conventions and rules for the new css variables that will be added in the style refactoring. Also come up with general practices for the new styles after the refactoring.