Skip to content

Commit

Permalink
feat(media): add media module with function to add @content dependi…
Browse files Browse the repository at this point in the history
…ng on `$color-scheme`.
  • Loading branch information
sciborrudnicki committed Sep 7, 2023
1 parent a4b9f63 commit 439305e
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
1 change: 1 addition & 0 deletions media/_index.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
@forward 'media.color-scheme-content.mixin';
35 changes: 35 additions & 0 deletions media/_media.color-scheme-content.mixin.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// Sass.
@use 'sass:list';

// Modules.
@use '../color/scheme';

// Status: DONE
// The `media.color-scheme-content()` mixin.
// $detect: boolean if true then it's sensitive to the `$color-scheme` argument.
// @param `$color-scheme`
// @param `$detect`
@mixin color-scheme-content($color-scheme, $detect: false) {
@if list.index(dark light normal, $color-scheme) {
@if list.index(dark light, $color-scheme) {
@if not $detect or ($detect and scheme.is($color-scheme)) {
@media (prefers-color-scheme: $color-scheme) {
@content;
}
}
} @else {
@if not $detect or ($detect and scheme.is($color-scheme)) {
@content;
}
}
} @else {
@content;
}
}

// Examples.
// div {
// @include color-scheme-content(dark) { color: orange; }
// @include color-scheme-content(light) { color: red; }
// @include color-scheme-content(light, true) { color: red; }
// }

0 comments on commit 439305e

Please sign in to comment.