Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add color-scheme mixin #32763

Merged
merged 3 commits into from
Apr 10, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions scss/_mixins.scss
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

// Helpers
@import "mixins/breakpoints";
@import "mixins/color-scheme";
@import "mixins/image";
@import "mixins/resize";
@import "mixins/visually-hidden";
Expand Down
17 changes: 17 additions & 0 deletions scss/mixins/_color-scheme.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// scss-docs-start mixin-color-scheme
@mixin color-scheme($name) {
@if $name == dark {
@media (prefers-color-scheme: dark) {
@content;
}
} @else if $name == light {
@media (prefers-color-scheme: light) {
@content;
}
} @else {
@media (prefers-color-scheme: #{$name}) {
@content;
}
}
}
// scss-docs-end mixin-color-scheme
22 changes: 22 additions & 0 deletions site/content/docs/5.0/customize/sass.md
Original file line number Diff line number Diff line change
Expand Up @@ -276,3 +276,25 @@ $border-width: 0;
border-radius: subtract($border-radius, $border-width);
}
```

## Mixins

Our `scss/mixins/` directory has a ton of mixins that power parts of Bootstrap and can also be used across your own project.

### Color schemes

A shorthand mixin for the `prefers-color-scheme` media query is available with support for `light`, `dark`, and custom color schemes.

{{< scss-docs name="mixin-color-scheme" file="scss/mixins/_color-scheme.scss" >}}

```scss
.custom-element {
@include color-scheme(dark) {
// Insert dark mode styles here
}

@include color-scheme(custom-named-scheme) {
// Insert custom color scheme styles here
}
}
```