|
314 | 314 | } |
315 | 315 | } |
316 | 316 |
|
| 317 | +/// This mixin should mostally be used internally within react-md so that |
| 318 | +/// react-md mixins that use a `rmd-` prefixed class work correctly if included |
| 319 | +/// from a css module file. This basically prefixes the react-md class with |
| 320 | +/// `:global` and suffixes with `:local &`. |
| 321 | +/// |
| 322 | +/// @param {String} class-name - The class name that should be optionally |
| 323 | +/// prefixed with `:global` when the `$css-modules` parameter is `true`. |
| 324 | +/// @param {Boolean} css-modules [false] - Boolean if the class name should be |
| 325 | +/// updated to be used with css modules. |
| 326 | +/// @param {Boolean} parent-selector [true] - Boolean if the selector should end |
| 327 | +/// with the parent selector ` & ` so that the `$class-name` is a parent of the |
| 328 | +/// current class. |
| 329 | +@mixin rmd-utils-optional-css-modules($class-name, $css-modules: false, $parent-selector: true) { |
| 330 | + $selector: if($css-modules, ':global #{$class-name} :local', $class-name); |
| 331 | + $selector: if($parent-selector, '#{$selector} &', $selector); |
| 332 | + |
| 333 | + #{$selector} { |
| 334 | + @content; |
| 335 | + } |
| 336 | +} |
| 337 | + |
317 | 338 | /// This mixin allows you to add styles to an element only when the user is |
318 | 339 | /// interacting with your app on a touch device. |
319 | 340 | /// |
|
335 | 356 | /// } |
336 | 357 | /// } |
337 | 358 | /// |
338 | | -/// @param {Boolean} css-modules [false] - Boolean if this is being used within CSS |
339 | | -/// Modules which will update the selector to work correctly by wrapping |
| 359 | +/// @param {Boolean} css-modules [false] - Boolean if this is being used within |
| 360 | +/// CSS Modules which will update the selector to work correctly by wrapping |
340 | 361 | /// different parts with `:global` and `:local`. |
341 | 362 | @mixin rmd-utils-touch-only($css-modules: false) { |
342 | | - @if $css-modules { |
343 | | - :global .rmd-utils--touch :local & { |
344 | | - @content; |
345 | | - } |
346 | | - } @else { |
347 | | - .rmd-utils--touch & { |
348 | | - @content; |
349 | | - } |
| 363 | + @include rmd-utils-optional-css-modules('.rmd-utils--touch', $css-modules) { |
| 364 | + @content; |
350 | 365 | } |
351 | 366 | } |
352 | 367 |
|
|
371 | 386 | /// } |
372 | 387 | /// } |
373 | 388 | /// |
374 | | -/// @param {Boolean} css-modules [false] - Boolean if this is being used within CSS |
375 | | -/// Modules which will update the selector to work correctly by wrapping |
| 389 | +/// @param {Boolean} css-modules [false] - Boolean if this is being used within |
| 390 | +/// CSS Modules which will update the selector to work correctly by wrapping |
376 | 391 | /// different parts with `:global` and `:local`. |
377 | 392 | @mixin rmd-utils-keyboard-only($css-modules: false) { |
378 | | - @if $css-modules { |
379 | | - :global .rmd-utils--keyboard :local & { |
380 | | - @content; |
381 | | - } |
382 | | - } @else { |
383 | | - .rmd-utils--keyboard & { |
384 | | - @content; |
385 | | - } |
| 393 | + @include rmd-utils-optional-css-modules('.rmd-utils--keyboard', $css-modules) { |
| 394 | + @content; |
386 | 395 | } |
387 | 396 | } |
388 | 397 |
|
|
407 | 416 | /// } |
408 | 417 | /// } |
409 | 418 | /// |
410 | | -/// @param {Boolean} css-modules [false] - Boolean if this is being used within CSS |
411 | | -/// Modules which will update the selector to work correctly by wrapping |
| 419 | +/// @param {Boolean} css-modules [false] - Boolean if this is being used within |
| 420 | +/// CSS Modules which will update the selector to work correctly by wrapping |
412 | 421 | /// different parts with `:global` and `:local`. |
413 | 422 | @mixin rmd-utils-mouse-only($css-modules: false) { |
414 | | - @if $css-modules { |
415 | | - :global .rmd-utils--mouse :local & { |
416 | | - @content; |
417 | | - } |
418 | | - } @else { |
419 | | - .rmd-utils--mouse & { |
420 | | - @content; |
421 | | - } |
| 423 | + @include rmd-utils-optional-css-modules('.rmd-utils--mouse', $css-modules) { |
| 424 | + @content; |
422 | 425 | } |
423 | 426 | } |
424 | 427 |
|
|
0 commit comments