From 148421be129ed05a01f4f8086ae0c4f7b019226d Mon Sep 17 00:00:00 2001 From: Martijn Cuppens Date: Sat, 15 Feb 2020 14:41:59 +0100 Subject: [PATCH] Remove map merges (#28508) --- scss/_variables.scss | 172 ++++++++---------- site/content/docs/4.3/forms/validation.md | 19 +- .../docs/4.3/getting-started/theming.md | 44 +++-- site/content/docs/4.3/migration.md | 1 + 4 files changed, 107 insertions(+), 129 deletions(-) diff --git a/scss/_variables.scss b/scss/_variables.scss index 7ad08dc825..e4268c3f56 100644 --- a/scss/_variables.scss +++ b/scss/_variables.scss @@ -17,22 +17,19 @@ $gray-800: #343a40 !default; $gray-900: #212529 !default; $black: #000 !default; -$grays: () !default; -// stylelint-disable-next-line scss/dollar-variable-default -$grays: map-merge( - ( - "100": $gray-100, - "200": $gray-200, - "300": $gray-300, - "400": $gray-400, - "500": $gray-500, - "600": $gray-600, - "700": $gray-700, - "800": $gray-800, - "900": $gray-900 - ), - $grays -); +// fusv-disable +$grays: ( + "100": $gray-100, + "200": $gray-200, + "300": $gray-300, + "400": $gray-400, + "500": $gray-500, + "600": $gray-600, + "700": $gray-700, + "800": $gray-800, + "900": $gray-900 +) !default; +// fusv-enable $blue: #0d6efd !default; $indigo: #6610f2 !default; @@ -45,26 +42,21 @@ $green: #28a745 !default; $teal: #20c997 !default; $cyan: #17a2b8 !default; -$colors: () !default; -// stylelint-disable-next-line scss/dollar-variable-default -$colors: map-merge( - ( - "blue": $blue, - "indigo": $indigo, - "purple": $purple, - "pink": $pink, - "red": $red, - "orange": $orange, - "yellow": $yellow, - "green": $green, - "teal": $teal, - "cyan": $cyan, - "white": $white, - "gray": $gray-600, - "gray-dark": $gray-800 - ), - $colors -); +$colors: ( + "blue": $blue, + "indigo": $indigo, + "purple": $purple, + "pink": $pink, + "red": $red, + "orange": $orange, + "yellow": $yellow, + "green": $green, + "teal": $teal, + "cyan": $cyan, + "white": $white, + "gray": $gray-600, + "gray-dark": $gray-800 +) !default; $primary: $blue !default; $secondary: $gray-600 !default; @@ -75,21 +67,16 @@ $danger: $red !default; $light: $gray-100 !default; $dark: $gray-800 !default; -$theme-colors: () !default; -// stylelint-disable-next-line scss/dollar-variable-default -$theme-colors: map-merge( - ( - "primary": $primary, - "secondary": $secondary, - "success": $success, - "info": $info, - "warning": $warning, - "danger": $danger, - "light": $light, - "dark": $dark - ), - $theme-colors -); +$theme-colors: ( + "primary": $primary, + "secondary": $secondary, + "success": $success, + "info": $info, + "warning": $warning, + "danger": $danger, + "light": $light, + "dark": $dark +) !default; // Set a specific jump point for requesting color jumps $theme-color-interval: 8% !default; @@ -237,19 +224,14 @@ $enable-important-utilities: true !default; // You can add more entries to the $spacers map, should you need more variation. $spacer: 1rem !default; -$spacers: () !default; -// stylelint-disable-next-line scss/dollar-variable-default -$spacers: map-merge( - ( - 0: 0, - 1: $spacer * .25, - 2: $spacer * .5, - 3: $spacer, - 4: $spacer * 1.5, - 5: $spacer * 3, - ), - $spacers -); +$spacers: ( + 0: 0, + 1: $spacer * .25, + 2: $spacer * .5, + 3: $spacer, + 4: $spacer * 1.5, + 5: $spacer * 3, +) !default; $negative-spacers: negativify-map($spacers) !default; @@ -357,29 +339,24 @@ $transition-base: all .2s ease-in-out !default; $transition-fade: opacity .15s linear !default; $transition-collapse: height .35s ease !default; -$embed-responsive-aspect-ratios: () !default; -// stylelint-disable-next-line scss/dollar-variable-default -$embed-responsive-aspect-ratios: map-merge( - ( - "21by9": ( - x: 21, - y: 9 - ), - "16by9": ( - x: 16, - y: 9 - ), - "4by3": ( - x: 4, - y: 3 - ), - "1by1": ( - x: 1, - y: 1 - ) +$embed-responsive-aspect-ratios: ( + "21by9": ( + x: 21, + y: 9 ), - $embed-responsive-aspect-ratios -); + "16by9": ( + x: 16, + y: 9 + ), + "4by3": ( + x: 4, + y: 3 + ), + "1by1": ( + x: 1, + y: 1 + ) +) !default; // Typography // @@ -784,21 +761,16 @@ $form-feedback-icon-valid: url("data:image/svg+xml,") !default; -$form-validation-states: () !default; -// stylelint-disable-next-line scss/dollar-variable-default -$form-validation-states: map-merge( - ( - "valid": ( - "color": $form-feedback-valid-color, - "icon": $form-feedback-icon-valid - ), - "invalid": ( - "color": $form-feedback-invalid-color, - "icon": $form-feedback-icon-invalid - ), +$form-validation-states: ( + "valid": ( + "color": $form-feedback-valid-color, + "icon": $form-feedback-icon-valid ), - $form-validation-states -); + "invalid": ( + "color": $form-feedback-invalid-color, + "icon": $form-feedback-icon-invalid + ) +) !default; // Z-index master list // diff --git a/site/content/docs/4.3/forms/validation.md b/site/content/docs/4.3/forms/validation.md index 6abc4d10ba..ea2bdd6cfb 100644 --- a/site/content/docs/4.3/forms/validation.md +++ b/site/content/docs/4.3/forms/validation.md @@ -385,18 +385,15 @@ Please note that we do not recommend customizing these values without also modif {{< highlight scss >}} // Sass map from `_variables.scss` // Override this and recompile your Sass to generate different states -$form-validation-states: map-merge( - ( - "valid": ( - "color": $form-feedback-valid-color, - "icon": $form-feedback-icon-valid - ), - "invalid": ( - "color": $form-feedback-invalid-color, - "icon": $form-feedback-icon-invalid - ) +$form-validation-states: ( + "valid": ( + "color": $form-feedback-valid-color, + "icon": $form-feedback-icon-valid ), - $form-validation-states + "invalid": ( + "color": $form-feedback-invalid-color, + "icon": $form-feedback-icon-invalid + ) ); // Loop from `_forms.scss` diff --git a/site/content/docs/4.3/getting-started/theming.md b/site/content/docs/4.3/getting-started/theming.md index c5ac8cf93f..e8813045ab 100644 --- a/site/content/docs/4.3/getting-started/theming.md +++ b/site/content/docs/4.3/getting-started/theming.md @@ -94,9 +94,9 @@ Repeat as necessary for any variable in Bootstrap, including the global options ### Maps and loops -Bootstrap 4 includes a handful of Sass maps, key value pairs that make it easier to generate families of related CSS. We use Sass maps for our colors, grid breakpoints, and more. Just like Sass variables, all Sass maps include the `!default` flag and can be overridden and extended. +Bootstrap 5 includes a handful of Sass maps, key value pairs that make it easier to generate families of related CSS. We use Sass maps for our colors, grid breakpoints, and more. Just like Sass variables, all Sass maps include the `!default` flag and can be overridden and extended. -Some of our Sass maps are merged into empty ones by default. This is done to allow easy expansion of a given Sass map, but comes at the cost of making _removing_ items from a map slightly more difficult. +From Bootstrap 5, we decided to [ditch the map merges](https://github.com/twbs/bootstrap/pull/28508) we had in `v4`. This way we have more control over removing redundant values. #### Modify map @@ -112,37 +112,45 @@ Later on, theses variables are set in Bootstrap's `$theme-colors` map: {{< highlight scss >}} $theme-colors: ( "primary": $primary, - "danger": $danger + "danger": $danger, + ... ); {{< /highlight >}} #### Add to map -To add a new color to `$theme-colors`, add the new key and value: +To add a new color to `$theme-colors`, add the new key and value. Keep in mind not to remove the existing colors: {{< highlight scss >}} +$my-custom-color: #ffoodd; + +// Make sure to define `$primary`, `$secondary`, ect.. first $theme-colors: ( - "custom-color": #900 + "primary": $primary, + "secondary": $secondary, + "success": $success, + "info": $info, + "warning": $warning, + "danger": $danger, + "light": $light, + "dark": $dark, + "custom-color": $my-custom-color, ); {{< /highlight >}} #### Remove from map -To remove colors from `$theme-colors`, or any other map, use `map-remove`. Be aware you must insert it between our requirements and options: +From Bootstrap 5, this is simplified quite a lot, just remove the redundant items from the Sass map: {{< highlight scss >}} -// Required -@import "../node_modules/bootstrap/scss/functions"; -@import "../node_modules/bootstrap/scss/variables"; -@import "../node_modules/bootstrap/scss/mixins"; - -$theme-colors: map-remove($theme-colors, "info", "light", "dark"); - -// Optional -@import "../node_modules/bootstrap/scss/root"; -@import "../node_modules/bootstrap/scss/reboot"; -@import "../node_modules/bootstrap/scss/type"; -... +// Make sure to define `$primary`, `$secondary`, ect.. first +$theme-colors: ( + "primary": $primary, + "secondary": $secondary, + "success": $success, + "warning": $warning, + "danger": $danger, +); {{< /highlight >}} #### Required keys diff --git a/site/content/docs/4.3/migration.md b/site/content/docs/4.3/migration.md index 4a5d43ede5..61a44061e4 100644 --- a/site/content/docs/4.3/migration.md +++ b/site/content/docs/4.3/migration.md @@ -41,6 +41,7 @@ Changes to our source Sass files and compiled CSS. - Line heights are dropped from several components to simplify our codebase. The `button-size()` and `pagination-size()` do not accept line height parameters anymore. [See #29271](https://github.com/twbs/bootstrap/pull/29271) - The `button-variant()` mixin now accepts 3 optional color parameters, for each button state, to override the color provided by `color-yiq()`. By default, these parameters will find which color provides more contrast against the button state's background color with `color-yiq()`. - The `button-outline-variant()` mixin now accepts an additional argument, `$active-color`, for setting the button's active state text color. By default, this parameter will find which color provides more contrast against the button's active background color with `color-yiq()`. +- Ditch the Sass map merges, which makes it easier to remove redundant values. Keep in mind you now have to define all values in the Sass maps like `$theme-colors`. Check out how to deal with Sass maps on the [theming documentation]({{< docsref "/getting-started/theming#maps-and-loops" >}}). ## JavaScript