|
65 | 65 | /// `$rmd-theme-dark-class` variable to either set the styles with a media
|
66 | 66 | /// query or only when the dark class has been enabled on a parent element.
|
67 | 67 | ///
|
| 68 | +/// Note: This will have a higher specificity than other variables so the colors |
| 69 | +/// might not be as expected. It is recommended to set a custom CSS variable |
| 70 | +/// instead of using this mixin. |
| 71 | +/// |
| 72 | +/// @example scss - Simple Example |
| 73 | +/// $rmd-theme-dark-elevation: true; |
| 74 | +/// // OVERRIDE_VARIABLES |
| 75 | +/// |
| 76 | +/// .container { |
| 77 | +/// @include rmd-theme-dark-elevation-styles { |
| 78 | +/// background-color: red; |
| 79 | +/// } |
| 80 | +/// } |
| 81 | +/// |
| 82 | +/// @include rmd-theme-dark-elevation-styles($selector: null) { |
| 83 | +/// --container-bg: orange; |
| 84 | +/// } |
| 85 | +/// |
| 86 | +/// @include rmd-theme-dark-elevation-styles($selector: '.rmd-menu') { |
| 87 | +/// --container-bg: blue; |
| 88 | +/// } |
| 89 | +/// |
| 90 | +/// .container-2 { |
| 91 | +/// background-color: var(--container-bg, red); |
| 92 | +/// } |
| 93 | +/// |
| 94 | +/// @example scss - Simple Prefers Color Scheme |
| 95 | +/// $rmd-theme-dark-elevation: true; |
| 96 | +/// $rmd-theme-dark-class: 'prefers-color-scheme'; |
| 97 | +/// // OVERRIDE_VARIABLES |
| 98 | +/// |
| 99 | +/// .container { |
| 100 | +/// @include rmd-theme-dark-elevation-styles { |
| 101 | +/// background-color: red; |
| 102 | +/// } |
| 103 | +/// } |
| 104 | +/// |
| 105 | +/// @include rmd-theme-dark-elevation-styles($selector: ':root') { |
| 106 | +/// --container-bg: orange; |
| 107 | +/// } |
| 108 | +/// |
| 109 | +/// @include rmd-theme-dark-elevation-styles($selector: '.rmd-menu') { |
| 110 | +/// --container-bg: blue; |
| 111 | +/// } |
| 112 | +/// |
| 113 | +/// .container-2 { |
| 114 | +/// background-color: var(--container-bg, red); |
| 115 | +/// } |
| 116 | +/// |
| 117 | +/// @example scss - CSS Module Example |
| 118 | +/// $rmd-theme-dark-elevation: true; |
| 119 | +/// // OVERRIDE_VARIABLES |
| 120 | +/// |
| 121 | +/// .container { |
| 122 | +/// @include rmd-theme-dark-elevation-styles(true) { |
| 123 | +/// background-color: red; |
| 124 | +/// } |
| 125 | +/// } |
| 126 | +/// |
| 127 | +/// @include rmd-theme-dark-elevation-styles(true, null) { |
| 128 | +/// --container-bg: orange; |
| 129 | +/// } |
| 130 | +/// |
| 131 | +/// @include rmd-theme-dark-elevation-styles(true, '.rmd-menu') { |
| 132 | +/// --container-bg: blue; |
| 133 | +/// } |
| 134 | +/// |
| 135 | +/// .container-2 { |
| 136 | +/// background-color: var(--container-bg, red); |
| 137 | +/// } |
| 138 | +/// |
| 139 | +/// @example scss - CSS Module Prefers Color Scheme Example |
| 140 | +/// $rmd-theme-dark-elevation: true; |
| 141 | +/// $rmd-theme-dark-class: 'prefers-color-scheme'; |
| 142 | +/// // OVERRIDE_VARIABLES |
| 143 | +/// |
| 144 | +/// .container { |
| 145 | +/// @include rmd-theme-dark-elevation-styles(true) { |
| 146 | +/// background-color: red; |
| 147 | +/// } |
| 148 | +/// } |
| 149 | +/// |
| 150 | +/// @include rmd-theme-dark-elevation-styles(true, ':root') { |
| 151 | +/// --container-bg: orange; |
| 152 | +/// } |
| 153 | +/// |
| 154 | +/// @include rmd-theme-dark-elevation-styles(true, '.rmd-menu') { |
| 155 | +/// --container-bg: blue; |
| 156 | +/// } |
| 157 | +/// |
| 158 | +/// .container-2 { |
| 159 | +/// background-color: var(--container-bg, red); |
| 160 | +/// } |
| 161 | +/// |
68 | 162 | /// @since 2.5.4
|
69 | 163 | /// @param {Boolean} css-modules [false] - Boolean if this is being used within
|
70 | 164 | /// CSS Modules which will update the selector to work correctly by wrapping
|
71 | 165 | /// different parts with `:global` and `:local`.
|
72 |
| -@mixin rmd-theme-dark-elevation-styles($css-modules: false) { |
| 166 | +/// @param {String} selector ['&'] - An optional selector to use if the |
| 167 | +/// `$rmd-theme-dark-class` is `'prefers-color-scheme'`. Otherwise, setting this |
| 168 | +/// to a value other than `'&'` will be joined to the `$rmd-theme-dark-class`. |
| 169 | +@mixin rmd-theme-dark-elevation-styles($css-modules: false, $selector: '&') { |
73 | 170 | @if $rmd-theme-dark-elevation {
|
74 | 171 | @if $rmd-theme-dark-class == 'prefers-color-scheme' {
|
75 | 172 | @media (prefers-color-scheme: dark) {
|
76 |
| - & { |
| 173 | + #{$selector} { |
77 | 174 | @content;
|
78 | 175 | }
|
79 | 176 | }
|
80 | 177 | } @else {
|
81 |
| - @include rmd-utils-optional-css-modules( |
| 178 | + $parent-selector: $selector == '&'; |
| 179 | + $class-name: if( |
| 180 | + $parent-selector or not $selector, |
82 | 181 | $rmd-theme-dark-class,
|
83 |
| - $css-modules |
| 182 | + $rmd-theme-dark-class + ' ' + $selector |
| 183 | + ); |
| 184 | + |
| 185 | + @include rmd-utils-optional-css-modules( |
| 186 | + $class-name, |
| 187 | + $css-modules, |
| 188 | + $parent-selector |
84 | 189 | ) {
|
85 | 190 | @content;
|
86 | 191 | }
|
|
91 | 196 | /// This mixin should normally be used with the `rmd-elevation` mixin to change
|
92 | 197 | /// the background color based on the current elevation in dark themes.
|
93 | 198 | ///
|
| 199 | +/// Note: This will have a higher specificity than other variables so the colors |
| 200 | +/// might not be as expected. It is recommended to set a custom CSS variable |
| 201 | +/// instead of using this mixin. |
| 202 | +/// |
| 203 | +/// @example scss - All z-values |
| 204 | +/// $rmd-theme-dark-elevation: true; |
| 205 | +/// // OVERRIDE_VARIABLES |
| 206 | +/// |
| 207 | +/// .container { |
| 208 | +/// @for $i from 0 to 24 { |
| 209 | +/// @include rmd-theme-dark-elevation($i); |
| 210 | +/// } |
| 211 | +/// } |
| 212 | +/// |
| 213 | +/// @example scss - All z-values with CSS Modules |
| 214 | +/// $rmd-theme-dark-elevation: true; |
| 215 | +/// // OVERRIDE_VARIABLES |
| 216 | +/// |
| 217 | +/// .container { |
| 218 | +/// @for $i from 0 to 24 { |
| 219 | +/// @include rmd-theme-dark-elevation($i, true); |
| 220 | +/// } |
| 221 | +/// } |
| 222 | +/// |
94 | 223 | /// @since 2.1.0
|
95 | 224 | /// @param {Number} z-value - This should be a number between 0 and 24
|
96 | 225 | /// representing the current elevation.
|
|
0 commit comments