You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Drop color(), theme-color() & gray() functions (#29083)
Drop `color()`, `theme-color()` & `gray()` functions in favor of variables. The functions just called a `map-get()` of a map where just the variables were defined.
Also the `theme-color-level()` now accepts any color you want instead of only `$theme-colors` colors. The first value now is a variable instead of the `$theme-colors` key.
Copy file name to clipboardExpand all lines: site/content/docs/4.3/getting-started/theming.md
+18-34Lines changed: 18 additions & 34 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -100,12 +100,19 @@ Some of our Sass maps are merged into empty ones by default. This is done to all
100
100
101
101
#### Modify map
102
102
103
-
To modify an existing color in our `$theme-colors` map, add the following to your custom Sass file:
103
+
All variables in the `$theme-colors` map are defined as standalone variables. To modify an existing color in our `$theme-colors` map, add the following to your custom Sass file:
104
+
105
+
{{< highlight scss >}}
106
+
$primary: #0074d9;
107
+
$danger: #ff4136;
108
+
{{< /highlight >}}
109
+
110
+
Later on, theses variables are set in Bootstrap's `$theme-colors` map:
104
111
105
112
{{< highlight scss >}}
106
113
$theme-colors: (
107
-
"primary": #0074d9,
108
-
"danger": #ff4136
114
+
"primary": $primary,
115
+
"danger": $danger
109
116
);
110
117
{{< /highlight >}}
111
118
@@ -146,36 +153,19 @@ For example, we use the `primary`, `success`, and `danger` keys from `$theme-col
146
153
147
154
### Functions
148
155
149
-
Bootstrap utilizes several Sass functions, but only a subset are applicable to general theming. We've included three functions for getting values from the color maps:
150
-
151
-
{{< highlight scss >}}
152
-
@function color($key: "blue") {
153
-
@return map-get($colors, $key);
154
-
}
155
-
156
-
@function theme-color($key: "primary") {
157
-
@return map-get($theme-colors, $key);
158
-
}
159
-
160
-
@function gray($key: "100") {
161
-
@return map-get($grays, $key);
162
-
}
163
-
{{< /highlight >}}
164
-
165
-
These allow you to pick one color from a Sass map much like how you'd use a color variable from v3.
156
+
In Bootstrap 5, we've dropped the `color()`, `theme-color()` and `gray()` functions because the values are also available as standalone variables. So instead of using `theme-color("primary")`, you can now just use the `$primary` variable.
166
157
167
158
{{< highlight scss >}}
168
159
.custom-element {
169
-
color: gray("100");
170
-
background-color: theme-color("dark");
160
+
color: $gray-100;
161
+
background-color: $dark;
171
162
}
172
163
{{< /highlight >}}
173
164
174
-
We also have another function for getting a particular _level_ of color from the `$theme-colors` map. Negative level values will lighten the color, while higher levels will darken.
165
+
We also have a function for getting a particular _level_ of color. Negative level values will lighten the color, while higher levels will darken.
@@ -187,12 +177,10 @@ In practice, you'd call the function and pass in two parameters: the name of the
187
177
188
178
{{< highlight scss >}}
189
179
.custom-element {
190
-
color: theme-color-level(primary, -10);
180
+
color: color-level($primary, -10);
191
181
}
192
182
{{< /highlight >}}
193
183
194
-
Additional functions could be added in the future or your own custom Sass to create level functions for additional Sass maps, or even a generic one if you wanted to be more verbose.
195
-
196
184
### Color contrast
197
185
198
186
An additional function we include in Bootstrap is the color contrast function, `color-yiq`. It utilizes the [YIQ color space](https://en.wikipedia.org/wiki/YIQ) to automatically return a light (`#fff`) or dark (`#111`) contrast color based on the specified base color. This function is especially useful for mixins or loops where you're generating multiple classes.
@@ -219,7 +207,7 @@ You can also specify a base color with our color map functions:
- Removed print styles and `$enable-print-styles` variable. Print display classes, however, have remained intact. [See #28339](https://github.com/twbs/bootstrap/pull/28339).
36
+
- Dropped `color()`, `theme-color()` & `gray()` functions in favor of variables. [See #29083](https://github.com/twbs/bootstrap/pull/29083)
37
+
- The `theme-color-level()` function is renamed to `color-level()` and now accepts any color you want instead of only `$theme-color` colors. [See #29083](https://github.com/twbs/bootstrap/pull/29083)
0 commit comments