Skip to content

Commit 702c7c6

Browse files
feat(lib): Add a customizable root for Boosted
1 parent be01f2f commit 702c7c6

File tree

11 files changed

+47
-11
lines changed

11 files changed

+47
-11
lines changed

scss/_grid.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
//
33
// Rows contain your columns.
44

5-
:root {
5+
#{$root-selector} { // Boosted mod: instead of `:root`
66
@each $name, $value in $grid-breakpoints {
77
--#{$prefix}breakpoint-#{$name}: #{$value};
88
}

scss/_reboot.scss

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
// Ability to the value of the root font sizes, affecting the value of `rem`.
2626
// null by default, thus nothing is generated.
2727

28-
:root {
28+
#{$root-selector} { // Boosted mod: instead of `:root`
2929
// Boosted mod: Improve focus visibility when fixed/sticky header is used
3030
// See https://caniuse.com/?search=scroll-padding
3131
// scss-docs-start scroll-offset
@@ -61,7 +61,7 @@
6161
// See https://developer.mozilla.org/fr/docs/Web/CSS/font-synthesis
6262

6363
// scss-docs-start reboot-body-rules
64-
body {
64+
#{$root-selector} > * { // Boosted mod: instead of `body`
6565
position: relative; // Boosted mod: required for back-to-top component
6666
margin: 0; // 1
6767
font-family: var(--#{$prefix}body-font-family);

scss/_root.scss

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// Boosted mod
2-
:root,
2+
#{$root-selector},
33
[data-bs-theme] {
44
color: var(--#{$prefix}body-color);
55
background-color: var(--#{$prefix}body-bg);
@@ -8,8 +8,7 @@
88
// Note that some of the following variables in `:root, [data-bs-theme="light"]` could be extracted into `:root` only selector since they are not modified by other color modes!
99
// End mod
1010

11-
:root,
12-
[data-bs-theme="light"] {
11+
@include color-mode(light, true) {
1312
color-scheme: light; // Boosted mod
1413

1514
// Note: Custom variable values only support SassScript inside `#{}`.

scss/_variables.scss

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -450,6 +450,7 @@ $color-mode-type: data !default; // `data` or `media-query`
450450

451451
// Prefix for :root CSS variables
452452

453+
$root-selector: ":root" !default; // Boosted mod
453454
$variable-prefix: bs- !default; // Deprecated in v5.2.0 for the shorter `$prefix`
454455
$prefix: $variable-prefix !default;
455456
// fusv-disable

scss/mixins/_color-mode.scss

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
@if $color-mode-type == "media-query" {
44
@if $root == true {
55
@media (prefers-color-scheme: $mode) {
6-
:root {
6+
#{$root-selector} {
77
@content;
88
}
99
}
@@ -12,6 +12,11 @@
1212
@content;
1313
}
1414
}
15+
} @else if $root == true and $mode == light {
16+
#{$root-selector},
17+
[data-bs-theme="#{$mode}"] {
18+
@content;
19+
}
1520
} @else {
1621
[data-bs-theme="#{$mode}"] {
1722
@content;

site/src/content/docs/customize/color-modes.mdx

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,31 @@ For example, you can create a “blue theme” with the selector `data-bs-theme=
213213
</div>
214214
```
215215

216+
### Change the root selector
217+
218+
You can also change the root selector from where the theme variables are set. By default, it's set to `:root`, but you can change it to any other selector. This is useful if you want to apply the theme to another element, for instance in Angular where you can't access easily the `<html>` element.
219+
220+
```scss
221+
$root-selector: "#app";
222+
223+
@include "boosted";
224+
```
225+
226+
Outputs to:
227+
228+
```css
229+
#app,
230+
[data-bs-theme="light"] {
231+
/* Your light mode variables definition */
232+
}
233+
234+
[data-bs-theme="dark"] {
235+
/* Your dark mode variables definition */
236+
}
237+
238+
/* Further Boosted CSS */
239+
```
240+
216241
## JavaScript
217242

218243
To allow visitors or users to toggle color modes, you’ll need to create a toggle element to control the `data-bs-theme` attribute on the root element, `<html>`. We’ve built a toggler in our documentation that initially defers to a user’s current system color mode, but provides an option to override that and pick a specific color mode.

site/src/content/docs/migration.mdx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,12 @@ aliases:
77
toc: true
88
---
99

10+
## v5.3.8
11+
12+
### Core
13+
14+
- <span class="badge text-bg-warning">Warning</span> The root selector have been tweaked for more flexibility on JS frameworks. You can change it by defining `$root-selector`, before the Boosted custom call in Scss. More information in our [color modes documentation]([[docsref:/customize/color-modes#change-the-root-selector]]). Please don’t hesitate to contact us if you find any issue with it. Nonetheless, note that it shouldn’t change anything for a normal usage of Boosted.
15+
1016
## v5.3.7
1117

1218
## v5.3.6

site/src/scss/_boosted.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// stylelint-disable selector-max-id
2-
:root {
2+
#{$root-selector} { // Boosted mod: instead of `:root`
33
scroll-padding-top: $offset-top * .5;
44

55
@include media-breakpoint-up(lg) {

site/src/scss/_search.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
// Boosted mod: the entire file is modified and is specific to Boosted
44

5-
:root {
5+
#{$root-selector} { // Boosted mod: instead of `:root`
66
// All available CSS vars and specific modifications for Boosted
77
--docsearch-primary-color: var(--bs-primary);
88
--docsearch-text-color: var(--bs-body-color);

site/src/scss/_syntax.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// Note: Bootstrap stops at --base0F
22

3-
:root,
3+
#{$root-selector}, // Boosted mod: instead of `:root`
44
[data-bs-theme="light"] {
55
--base00: #{$white};
66
--base01: #{$gray-700};

0 commit comments

Comments
 (0)