Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move reassigned Sass maps for colors to another stylesheet #34942

Merged
merged 7 commits into from
Nov 15, 2021

Conversation

mdo
Copy link
Member

@mdo mdo commented Sep 9, 2021

Fixes #34756.

The intent of the new CSS variables and the Sass maps that power them was improved customization, but it complicates things and breaks a common workflow. There's no great way around this unfortunately as the problem is how we create new variables and maps based on existing ones. For example, we extend $theme-colors into $theme-colors-rgb and two maps for .text-* and .bg-* utilities. As of v5.1.1, those other maps do not get updated after $theme-colors are modified.

There are two viable solutions I can see:

  1. Re-declare every map, like so:
@import "functions";
@import "variables";
@import "mixins";

$custom: #df711b;

$custom-theme-colors: (
"custom": $custom
);

$theme-colors: map-merge($theme-colors, $custom-theme-colors);
$theme-colors-rgb: map-loop($theme-colors, to-rgb, "$value");
$utilities-colors: map-merge($utilities-colors, $theme-colors-rgb);
$utilities-text-colors: map-loop($utilities-colors, rgba-css-var, "$key", "text");
$utilities-bg-colors: map-loop($utilities-colors, rgba-css-var, "$key", "bg");
  1. Or, as this PR does, split those maps out to another stylesheet so we can have folks place modified values between variables and the new maps so they can be updated accordingly. Like so:
// Configuration
@import "functions";
@import "variables";

$starorange: #df711b !default;

$custom-theme-colors: (
  "starorange": $starorange
) !default;

$theme-colors: map-merge($theme-colors, $custom-theme-colors); // stylelint-disable-line scss/dollar-variable-default

@import "maps";
@import "mixins";
@import "utilities";

// Layout & components
// ...

Todos

  • Document this somewhere
  • Verify other maps that need moving

/cc @twbs/css-review

@ffoodd
Copy link
Member

ffoodd commented Sep 14, 2021

This looks fine to me, and totally makes senses. 👌

It needs some docs indeed, and we must ensure we're not forgetting any example somewhere.

Copy link
Member

@ffoodd ffoodd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, the migration guide is very clear 👌 Thanks!

@XhmikosR XhmikosR merged commit 9f099d3 into main Nov 15, 2021
@XhmikosR XhmikosR deleted the split-vars-maps-import branch November 15, 2021 11:03
@isaumya
Copy link

isaumya commented Dec 1, 2021

Hi @mdo,
Is there any ETA on when the v5.2.0 is going to release? The reason I am asking this is that I am going to start a new project and I thought I can use the new improved overwriting system that is coming in v5.2 instead of using the hacky system we are using now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Updated .bg-* and .text-* utilities break when CSS variables are not enabled in v5.1.0
4 participants