SAP / spartacus

Spartacus is a lean, Angular-based JavaScript storefront for SAP Commerce Cloud that communicates exclusively through the Commerce REST API.
Apache License 2.0
744 stars 389 forks source link

Come up with list of css variables #439

Closed LTiger14 closed 5 years ago

LTiger14 commented 5 years ago

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.

LTiger14 commented 5 years ago

Draft 1:

Css variables (custom properties)

.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.
tobi-or-not-tobi commented 5 years ago

@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:

Component variables:

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...

tobi-or-not-tobi commented 5 years ago

I'd prefer to transition this ticket and have it more focused on getting the list.

LTiger14 commented 5 years ago

Like @tobi-or-not-tobi mentioned, we should have to groups of css variables.

Theme 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 :

Component variables:

tobi-or-not-tobi commented 5 years ago

Documentation added