Created
April 4, 2018 06:53
-
-
Save devatrox/ee2503389e6e16b06b0069a72511f37d to your computer and use it in GitHub Desktop.
Useful Sass mixins
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
@mixin state($states...) { | |
$list: (); | |
$selectors: (); | |
$FULL_STATES: ( | |
'none': (''), | |
'active': (':active', '.active'), | |
'hover': (':hover'), | |
'focus': (':focus', '.focus'), | |
'visited': (':visited'), | |
'valid': (':valid', '.valid'), | |
'invalid': (':invalid', '.invalid'), | |
'enabled': ('[enabled]', ':enabled', '.enabled'), | |
'disabled': ('[disabled]', ':disabled', '.disabled'), | |
'required': ('[required]', ':required', '.required') | |
); | |
@each $state in $states { | |
@if map-get($FULL_STATES, $state) { | |
$list: join($list, map-get($FULL_STATES, $state), comma); | |
} | |
@else if type-of($state) == string { | |
$list: join($list, '.#{$state}', comma); | |
} | |
} | |
@each $item in $list { | |
$prefixed-item: str-insert($item, '&', 1); | |
$selectors: append($selectors, $prefixed-item, comma); | |
} | |
#{$selectors} { | |
@content; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment