Skip to content

Commit 5322e4c

Browse files
committed
docs: add Sass modules support documentation
1 parent a732bec commit 5322e4c

File tree

10 files changed

+234
-1
lines changed

10 files changed

+234
-1
lines changed

docs/content/customize/color-modes.md

+41-1
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,46 @@ Adding a new color in `$theme-colors` is not enough for some of our components l
195195

196196
This is a manual process because Sass cannot generate its own Sass variables from an existing variable or map. In future versions of Bootstrap, we'll revisit this setup to reduce the duplication.
197197

198+
{{< callout-dart-sass-modules >}}
199+
200+
```scss
201+
// Required
202+
@use "sass:map";
203+
@use "variables" as *;
204+
@use "maps" as *;
205+
206+
// Add a custom color to $theme-colors
207+
$custom-colors: (
208+
"custom-color": #712cf9
209+
);
210+
$theme-colors: map.merge($theme-colors, $custom-colors);
211+
// Add a custom color to new theme maps
212+
213+
// Light mode
214+
$custom-colors-text: ("custom-color": #712cf9);
215+
$custom-colors-bg-subtle: ("custom-color": #e1d2fe);
216+
$custom-colors-border-subtle: ("custom-color": #bfa1fc);
217+
218+
$theme-colors-text: map.merge($theme-colors-text, $custom-colors-text);
219+
$theme-colors-bg-subtle: map.merge($theme-colors-bg-subtle, $custom-colors-bg-subtle);
220+
$theme-colors-border-subtle: map.merge($theme-colors-border-subtle, $custom-colors-border-subtle);
221+
222+
// Dark mode
223+
$custom-colors-text-dark: ("custom-color": #e1d2f2);
224+
$custom-colors-bg-subtle-dark: ("custom-color": #8951fa);
225+
$custom-colors-border-subtle-dark: ("custom-color": #e1d2f2);
226+
227+
$theme-colors-text-dark: map.merge($theme-colors-text-dark, $custom-colors-text-dark);
228+
$theme-colors-bg-subtle-dark: map.merge($theme-colors-bg-subtle-dark, $custom-colors-bg-subtle-dark);
229+
$theme-colors-border-subtle-dark: map.merge($theme-colors-border-subtle-dark, $custom-colors-border-subtle-dark);
230+
231+
// Import CoreUI
232+
@use "coreui";
233+
234+
```
235+
236+
{{< callout-dart-sass-deprecations >}}
237+
198238
```scss
199239
// Required
200240
@import "functions";
@@ -231,7 +271,7 @@ $theme-colors-text-dark: map-merge($theme-colors-text-dark, $custom-colors-text-
231271
$theme-colors-bg-subtle-dark: map-merge($theme-colors-bg-subtle-dark, $custom-colors-bg-subtle-dark);
232272
$theme-colors-border-subtle-dark: map-merge($theme-colors-border-subtle-dark, $custom-colors-border-subtle-dark);
233273

234-
// Remainder of Bootstrap imports
274+
// Remainder of CoreUI for Bootstrap imports
235275
@import "root";
236276
@import "reboot";
237277
// etc

docs/content/customize/color.md

+32
Original file line numberDiff line numberDiff line change
@@ -477,6 +477,38 @@ Bootstrap doesn't include `color` and `background-color` utilities for every col
477477

478478
Here's an example that generates text color utilities (e.g., `.text-purple-500`) using the above steps.
479479

480+
{{< callout-dart-sass-modules >}}
481+
482+
```scss
483+
@use "sass:map";
484+
@use "@coreui/coreui/scss/functions/maps" as *;
485+
@use "@coreui/coreui/scss/variables" as *;
486+
@use "@coreui/coreui/scss/utilities" as *;
487+
488+
$all-colors: map-merge-multiple($blues, $indigos, $purples, $pinks, $reds, $oranges, $yellows, $greens, $teals, $cyans);
489+
490+
$utilities: map-merge(
491+
$utilities,
492+
(
493+
"color": map-merge(
494+
map-get($utilities, "color"),
495+
(
496+
values: map-merge(
497+
map-get(map-get($utilities, "color"), "values"),
498+
(
499+
$all-colors
500+
),
501+
),
502+
),
503+
),
504+
)
505+
);
506+
507+
@use "@coreui/coreui/scss/utilities/api";
508+
```
509+
510+
{{< callout-dart-sass-deprecations >}}
511+
480512
```scss
481513
@import "@coreui/coreui/scss/functions";
482514
@import "@coreui/coreui/scss/variables";

docs/content/customize/sass.md

+95
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,41 @@ your-project/
3737

3838
In your `custom.scss`, you'll import CoreUI's source Sass files. You have two options: include all of CoreUI, or pick the parts you need. We encourage the latter, though be aware there are some requirements and dependencies across our components. You also will need to include some JavaScript for our plugins.
3939

40+
{{< callout-dart-sass-modules >}}
41+
42+
```scss
43+
// Custom.scss
44+
// Option A: Include all of CoreUI
45+
46+
@use "@coreui/coreui/scss/coreui";
47+
48+
// Then add additional custom code here
49+
```
50+
51+
```scss
52+
// Custom.scss
53+
// Option B: Include parts of CoreUI
54+
55+
// 1. Include
56+
@use "@coreui/coreui/scss/root";
57+
58+
// 2. Optionally include any other parts as needed
59+
@use "@coreui/coreui/scss/utilities";
60+
@use "@coreui/coreui/scss/reboot";
61+
@use "@coreui/coreui/scss/type";
62+
@use "@coreui/coreui/scss/images";
63+
@use "@coreui/coreui/scss/containers";
64+
@use "@coreui/coreui/scss/grid";
65+
@use "@coreui/coreui/scss/helpers";
66+
67+
// 3. Optionally include utilities API last to generate classes based on the Sass map in `_utilities.scss`
68+
@use "@coreui/coreui/scss/utilities/api";
69+
70+
// 4. Add additional custom code here
71+
```
72+
73+
{{< callout-dart-sass-deprecations >}}
74+
4075
```scss
4176
// Custom.scss
4277
// Option A: Include all of CoreUI
@@ -125,6 +160,17 @@ Variable overrides must come after our functions are imported, but before the re
125160

126161
Here's an example that changes the `background-color` and `color` for the `<body>` when importing and compiling CoreUI for Bootstrap via npm:
127162

163+
{{< callout-dart-sass-modules >}}
164+
165+
```scss
166+
@use "@coreui/coreui/scss/coreui" with (
167+
$body-bg: #000,
168+
$body-color: #111
169+
)
170+
```
171+
172+
{{< callout-dart-sass-deprecations >}}
173+
128174
```scss
129175
// Required
130176
@import "../node_modules/@coreui/coreui/scss/functions";
@@ -175,6 +221,23 @@ $theme-colors: (
175221

176222
Add new colors to `$theme-colors`, or any other map, by creating a new Sass map with your custom values and merging it with the original map. In this case, we'll create a new `$custom-colors` map and merge it with `$theme-colors`.
177223

224+
{{< callout-dart-sass-modules >}}
225+
226+
```scss
227+
@use "sass:map";
228+
@use "@coreui/coreui/scss/variables" as *;
229+
230+
$custom-colors: (
231+
"custom-color": #900
232+
);
233+
234+
$theme-colors: map.merge($theme-colors, $custom-colors);
235+
236+
@use "@coreui/coreui/scss/coreui";
237+
```
238+
239+
{{< callout-dart-sass-deprecations >}}
240+
178241
```scss
179242
// Create your own map
180243
$custom-colors: (
@@ -189,6 +252,21 @@ $theme-colors: map-merge($theme-colors, $custom-colors);
189252

190253
To remove colors from `$theme-colors`, or any other map, use `map-remove`. Be aware you must insert it between our requirements and options:
191254

255+
{{< callout-dart-sass-modules >}}
256+
257+
```scss
258+
@use "sass:map";
259+
@use "@coreui/coreui/scss/variables" as *;
260+
@use "@coreui/coreui/scss/maps" as *;
261+
262+
$theme-colors: map-remove($theme-colors, "info", "light", "dark");
263+
$theme-colors-border-subtle: map.remove($theme-colors-border-subtle, "info", "light", "dark");
264+
265+
@use "@coreui/coreui/scss/coreui";
266+
```
267+
268+
{{< callout-dart-sass-deprecations >}}
269+
192270
```scss
193271
// Required
194272
@import "../node_modules/@coreui/coreui/scss/functions";
@@ -231,6 +309,8 @@ You can lighten or darken colors with CoreUI for Bootstrap's `tint-color()` and
231309
In practice, you'd call the function and pass in the color and weight parameters.
232310

233311
```scss
312+
@use "@coreui/coreui/scss/functions/color" as *;
313+
234314
.custom-element {
235315
color: tint-color($primary, 10%);
236316
}
@@ -251,9 +331,14 @@ In order to meet the [Web Content Accessibility Guidelines (WCAG)](https://www.w
251331

252332
An additional function we include in CoreUI for Bootstrap is the color contrast function, `color-contrast`. It utilizes the [WCAG 2.0 algorithm](https://www.w3.org/TR/WCAG20-TECHS/G17.html#G17-tests) for calculating contrast thresholds based on [relative luminance](https://www.w3.org/WAI/GL/wiki/Relative_luminance) in a `sRGB` colorspace to automatically return a light (`#fff`), dark (`#212529`) or black (`#000`) contrast color based on the specified base color. This function is especially useful for mixins or loops where you're generating multiple classes.
253333

334+
{{< scss-docs name="color-contrast-function" file="scss/functions/_color-contrast.scss" >}}
335+
254336
For example, to generate color swatches from our `$theme-colors` map:
255337

338+
256339
```scss
340+
@use "@coreui/coreui/scss/functions/color-contrast" as *;
341+
257342
@each $color, $value in $theme-colors {
258343
.swatch-#{$color} {
259344
color: color-contrast($value);
@@ -264,6 +349,8 @@ For example, to generate color swatches from our `$theme-colors` map:
264349
It can also be used for one-off contrast needs:
265350

266351
```scss
352+
@use "@coreui/coreui/scss/functions/color-contrast" as *;
353+
267354
.custom-element {
268355
color: color-contrast(#000); // returns `color: #fff`
269356
}
@@ -272,6 +359,8 @@ It can also be used for one-off contrast needs:
272359
You can also specify a base color with our color map functions:
273360

274361
```scss
362+
@use "@coreui/coreui/scss/functions/color-contrast" as *;
363+
275364
.custom-element {
276365
color: color-contrast($dark); // returns `color: #fff`
277366
}
@@ -288,6 +377,8 @@ We use the `add` and `subtract` functions to wrap the CSS `calc` function. The p
288377
Example where the calc is valid:
289378

290379
```scss
380+
@use "@coreui/coreui/scss/functions/math" as *;
381+
291382
$border-radius: .25rem;
292383
$border-width: 1px;
293384

@@ -305,6 +396,8 @@ $border-width: 1px;
305396
Example where the calc is invalid:
306397

307398
```scss
399+
@use "@coreui/coreui/scss/functions/math" as *;
400+
308401
$border-radius: .25rem;
309402
$border-width: 0;
310403

@@ -330,6 +423,8 @@ A shorthand mixin for the `prefers-color-scheme` media query is available with s
330423
{{< scss-docs name="mixin-color-scheme" file="scss/mixins/_color-scheme.scss" >}}
331424

332425
```scss
426+
@use "@coreui/coreui/scss/mixins/color-scheme" as *;
427+
333428
.custom-element {
334429
@include color-scheme(light) {
335430
// Insert light mode styles here

docs/content/getting-started/parcel.md

+8
Original file line numberDiff line numberDiff line change
@@ -112,8 +112,16 @@ Importing CoreUI into Parcel requires two imports, one into our `styles.scss` an
112112

113113
1. **Import CoreUI's CSS.** Add the following to `src/scss/styles.scss` to import all of CoreUI's source Sass.
114114

115+
{{< callout-dart-sass-modules >}}
116+
115117
```scss
116118
// Import all of CoreUI's CSS
119+
@use "~@coreui/coreui/scss/coreui";
120+
```
121+
122+
{{< callout-dart-sass-deprecations >}}
123+
124+
```scss
117125
@import "~@coreui/coreui/scss/coreui";
118126
```
119127

docs/content/getting-started/rtl.md

+26
Original file line numberDiff line numberDiff line change
@@ -105,9 +105,22 @@ $font-family-sans-serif:
105105

106106
Need both LTR and RTL on the same page? All you have to do is set following variables:
107107

108+
{{< callout-dart-sass-modules >}}
109+
110+
```scss
111+
@use "@coreui/coreui/scss/coreui" with (
112+
$enable-ltr: true,
113+
$enable-rtl: true
114+
);
115+
```
116+
117+
{{< callout-dart-sass-deprecations >}}
118+
108119
```scss
109120
$enable-ltr: true;
110121
$enable-rtl: true;
122+
123+
@import "../node_modules/@coreui/coreui/scss/coreui";
111124
```
112125

113126

@@ -117,9 +130,22 @@ After running Sass, each selector in your CSS files will be prepended by `html:n
117130

118131
By default LTR is enable and RTL is disable, but you can easily change it and use only RTL.
119132

133+
{{< callout-dart-sass-modules >}}
134+
135+
```scss
136+
@use "@coreui/coreui/scss/coreui" with (
137+
$enable-ltr: false,
138+
$enable-rtl: true
139+
);
140+
```
141+
142+
{{< callout-dart-sass-deprecations >}}
143+
120144
```scss
121145
$enable-ltr: false;
122146
$enable-rtl: true;
147+
148+
@import "../node_modules/@coreui/coreui/scss/coreui";
123149
```
124150

125151
## Additional resources

docs/content/getting-started/vite.md

+8
Original file line numberDiff line numberDiff line change
@@ -148,8 +148,16 @@ In the next and final section to this guide, we’ll import all of CoreUI’s CS
148148

149149
2. **Now, let's import CoreUI's CSS.** Add the following to `src/scss/styles.scss` to import all of CoreUI's source Sass.
150150

151+
{{< callout-dart-sass-modules >}}
152+
151153
```scss
152154
// Import all of CoreUI's CSS
155+
@use "~@coreui/coreui/scss/coreui";
156+
```
157+
158+
{{< callout-dart-sass-deprecations >}}
159+
160+
```scss
153161
@import "~@coreui/coreui/scss/coreui";
154162
```
155163

docs/content/getting-started/webpack.md

+8
Original file line numberDiff line numberDiff line change
@@ -184,8 +184,16 @@ Importing CoreUI into Webpack requires the loaders we installed in the first sec
184184

185185
2. **Now, let's import CoreUI's CSS.** Add the following to `src/scss/styles.scss` to import all of CoreUI's source Sass.
186186

187+
{{< callout-dart-sass-modules >}}
188+
187189
```scss
188190
// Import all of CoreUI's CSS
191+
@use "~@coreui/coreui/scss/coreui";
192+
```
193+
194+
{{< callout-dart-sass-deprecations >}}
195+
196+
```scss
189197
@import "~@coreui/coreui/scss/coreui";
190198
```
191199

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<div class="docs-callout docs-callout-warning">
2+
<p>
3+
<strong>Sass <code>@import</code> are deprecated and will be removed in Dart Sass 3.0.0.!</strong>
4+
</p>
5+
<p>You can also use <code>@import</code> rules, but please be aware that they are deprecated and will be removed in Dart Sass 3.0.0, resulting in a compilation warning. You can learn more about this deprecation <a href="https://sass-lang.com/documentation/breaking-changes/import/" target="_blank">here</a>.</p>
6+
</div>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<div class="docs-callout docs-callout-info">
2+
<p>
3+
<strong>Heads up!</strong> Since <code>@coreui/coreui</code> v5.3.0 and <code>@coreui/coreui-pro</code> v5.10.0, we support Sass modules.
4+
</p>
5+
<p>
6+
You can now use the modern <code>@use</code> and <code>@forward</code> rules instead of <code>@import</code>, which is deprecated and will be removed in Dart Sass 3.0.0. Using <code>@import</code> will result in a compilation warning. You can learn more about this transition <a href="https://sass-lang.com/documentation/breaking-changes/import/" target="_blank">here</a>.
7+
</p>
8+
</div>

scss/functions/_color-contrast.scss

+2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
// Color contrast
55
// See https://github.com/twbs/bootstrap/pull/30168
66

7+
// scss-docs-start color-contrast-function
78
@function color-contrast($background, $color-contrast-dark: $color-contrast-dark, $color-contrast-light: $color-contrast-light, $min-contrast-ratio: $min-contrast-ratio) {
89
$foregrounds: $color-contrast-light, $color-contrast-dark, $white, $black;
910
$max-ratio: 0;
@@ -23,3 +24,4 @@
2324

2425
@return $max-ratio-color;
2526
}
27+
// scss-docs-end color-contrast-function

0 commit comments

Comments
 (0)