Last active
August 29, 2015 14:17
-
-
Save jelbourn/b1a4c5b163429b1ccbfa to your computer and use it in GitHub Desktop.
Flexible shadow component styling
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// The "modifier", such as '.md-primary' or '.md-fab' is applied to the | |
// *host* element, but the style actually needs to be applied to an element | |
// within the shadow root. We can use a mixin to cover both native shadow DOM | |
// and emulated / polyfilled shadow DOM at the same time. | |
// Base mixin for general use. | |
@mixin host-context($element, $modifier, $target) { | |
:host(#{$modifier}) #{$target}, | |
#{$element}#{$modifier} #{$target} { | |
@content | |
} | |
} | |
// Component-specifc wrapper for readability. | |
@mixin md-button($modifier) { | |
@include host-context(md-button, $modifier, ".md-button") { | |
@content | |
} | |
} | |
// Actual style definitions. | |
@include md-button(".md-primary") { | |
color: blue; | |
} | |
@include md-button(".md-raised") { | |
position: absolute; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
:host(.md-primary) .md-button, | |
md-button.md-primary .md-button { | |
color: blue; | |
} | |
:host(.md-raised) .md-button, | |
md-button.md-raised .md-button { | |
position: absolute; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment