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
Update Sass and Theme docs to document mixins and functions better (#42173)
* Update Sass and Theme docs to document mixins and functions better
Also remove some unused functions while we're here.
* document it instead
* Fix cspell, add local cspell so i can test in dev
We use CSS variables `var(--bs-white)` and `var(--bs-black)` to prevent LightningCSS from converting the real-time mixing into static `lab()` values. Unfortunately, this feature cannot be disabled in LightningCSS at this time.
96
+
</Callout>
97
+
80
98
## Customizing
81
99
82
100
You can customize the colors by adding or removing colors from the `$colors` map. You can also customize the tint and shade stops, the `color-mix()` color space, and the mix colors. Say you want to add another blue-gray color, like slate.
@@ -360,31 +360,15 @@ For `$theme-colors`, the `primary`, `success`, and `danger` keys are required fo
360
360
361
361
### Defaults
362
362
363
-
The `defaults()` function is the backbone of Bootstrap's customization system. It merges user overrides on top of built-indefaults and strips any `null` entries from the result. Every token map, sizemap, and variantmap uses it:
363
+
The `defaults()` function is the backbone of Bootstrap's customization system. It merges user overrides on top of built-indefault tokens and strips any `null` entries from the result. Every token map, sizemap, and variantmap uses it:
364
364
365
365
```scss
366
366
@functiondefaults($defaults, $overrides) { ... }
367
367
```
368
368
369
369
It accepts either amap or alist as the first argument. Lists are automatically converted to maps with `true` values, which is how size maps like `$button-sizes` work with a clean `("xs", "sm", "lg")` syntax.
370
370
371
-
### Colors
372
-
373
-
Base colors are defined as `oklch()` values and expanded into full scales via `color-mix()`. Each hue generates steps from `025` to `975`:
374
-
375
-
```scss
376
-
// Example generated custom properties from _colors.scss
You can reference any colorscale step as a CSS custom property: `var(--blue-500)`, `var(--red-200)`, `var(--gray-900)`, etc.
371
+
`defaults()` are generated on specific selectors with the [`tokens()` mixin](#tokens).
388
372
389
373
### Color contrast
390
374
@@ -406,47 +390,119 @@ For example, to generate color swatches from our `$theme-colors` map:
406
390
407
391
We use the `escape-svg` function to escape the `<`, `>` and `#` characters for SVG background images. When using the `escape-svg` function, data URIs must be quoted.
// After escape-svg(), the <, >, and # characters are percent-encoded
398
+
// so the data URI works reliably as a CSS background-image
399
+
.element {
400
+
background-image: escape-svg($icon);
401
+
}
402
+
```
403
+
404
+
### Map helpers
410
405
411
-
We use the `add` and `subtract` functions to wrap the CSS `calc` function. The primary purpose of these functions is to avoid errors when a "unitless" `0` value is passed into a `calc` expression. Expressions like `calc(10px-0)` will return an error in all browsers, despite being mathematically correct.
406
+
We include several Sass functions for working with maps beyond what Sass provides natively.
412
407
413
-
Example where the calc is valid:
408
+
<BsTable>
409
+
| Function | Description |
410
+
| --- | --- |
411
+
| `map-merge-multiple($maps...)` | Merges any number of maps into one, processing them left to right. |
412
+
| `map-get-multiple($map, $values)` | Returns a subset of a map filtered to only the keys listed in `$values`. |
413
+
| `map-get-nested($map, $nested-key)` | Extracts a single property from every nested map entry, returning a flat map. |
Turns a map into its negativevariant by prefixing each key with `n` and negating the value. Keys equal to `0` are skipped. This is used internally to generate negative spacer utilities (e.g., `n1`, `n2`, etc.) from the `$spacers` map.
450
+
451
+
```scss
452
+
@function negativify-map($map) { ... }
453
+
454
+
// Example: generate negative spacers from a spacers map
The [`theme-color-values($key)`]([[docsref:/customize/theme]]) function in `scss/_theme.scss` extracts a specific sub-key from every entry in the `$theme-colors` map, returning a flat map of color names to values. Since each theme color is a nested map with sub-keys like `base`, `text`, `bg`, `border`, etc., this function lets you pull one of those sub-keys across all colors at once. It powers most of the color-related utilities in `_utilities.scss`:
463
+
464
+
```scss
465
+
// In _utilities.scss — generate .focus-ring-{color} classes
466
+
"focus-ring": (
467
+
property: --focus-ring-color,
468
+
class: focus-ring,
469
+
values: theme-color-values("focus-ring"),
470
+
),
471
+
472
+
// Merge theme color backgrounds with semantic border tokens for .border-{color} classes
The [`theme-opacity-values($color-var, $opacities)`]([[docsref:/customize/theme]]) function in `scss/_theme.scss` generates a map of opacity variants for a CSS custom property using `color-mix()`. The `$opacities` argument defaults to `$util-opacity` (10 through 100 in steps of 10). At `100`, it returns the variable directly; for all other steps, it mixes the variable against `transparent`:
486
+
487
+
```scss
488
+
// In _utilities.scss — generate .border-{opacity} classes
489
+
"border-opacity": (
490
+
class: border,
491
+
property: border-color,
492
+
values: theme-opacity-values(--border-color)
493
+
),
494
+
495
+
// Generate .fg-{opacity} classes
496
+
"fg-opacity": (
497
+
class: fg,
498
+
property: color,
499
+
values: theme-opacity-values(--fg)
500
+
),
445
501
```
446
502
447
503
## Mixins
448
504
449
-
Our `scss/mixins/` directory has a ton of mixins that power parts of Bootstrap and can also be used across your own project.
505
+
Our `scss/mixins/` directory has snippets of code that power Bootstrap and can also be used across your own project.
450
506
451
507
### Tokens
452
508
@@ -478,3 +534,15 @@ A shorthand mixin for the `prefers-color-scheme` media query is available with s
478
534
}
479
535
}
480
536
```
537
+
538
+
### Theme classes
539
+
540
+
The `generate-theme-classes()` mixin loops over the `$theme-colors` map and outputs a `.theme-*` class for each color. Each class maps generic `--theme-*` custom properties to the color's specific values, so components can reference `--theme-base`, `--theme-bg`, etc., and pick up the right palette from a parent `.theme-*` class:
Copy file name to clipboardExpand all lines: site/src/content/docs/migration.mdx
+1Lines changed: 1 addition & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -69,6 +69,7 @@ Bootstrap 6 is a major release with many breaking changes to modernize our codeb
69
69
- Dropped support for Node Sass, including no longer testing any of our source CSS against it.
70
70
- Rearranged several Sass files in the process.
71
71
- Removed `add()` and `subtract()` functions. Use `calc()` instead.
72
+
- Removed `create-css-vars()` mixin (unused).
72
73
-**CSS variable prefixing now handled by PostCSS.** The `$prefix` Sass variable has been removed. CSS custom properties are now written without a prefix in the Sass source and prefixed automatically via `postcss-prefix-custom-properties` during the build. To customize the prefix, update your PostCSS configuration instead of Sass.
73
74
-**Removes all deprecated Sass variables and values:**
74
75
- Removed `$nested-kbd-font-weight`, no replacement.
0 commit comments