Skip to content

Instantly share code, notes, and snippets.

@hc2p
Last active August 16, 2018 08:37
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hc2p/5c091269e5cb902770e2 to your computer and use it in GitHub Desktop.
Save hc2p/5c091269e5cb902770e2 to your computer and use it in GitHub Desktop.
dry icon mixin
$icons: (
follow: 'a',
followed: 'b',
unfollow: 'c',
checkmark: 'e'
);
$Placeholder-Selectors: ();
@mixin icon($name, $color, $extend: true) {
@include icon-static($extend);
&:before {
content: map-get($icons, $name);
@if $color {
color: $color;
}
}
}
@mixin icon-static($extend: true) {
$icon-selector: map-get($Placeholder-Selectors, 'icon');
@if $extend == true {
@if $icon-selector == null {
$icon-selector: unique-id();
$Placeholder-Selectors: map-merge($Placeholder-Selectors, ('icon': $icon-selector)) !global;
@at-root %#{$icon-selector} {
@include icon-static(false);
}
}
@at-root (without: media){
@extend %#{$icon-selector};
}
}
@else {
&:before {
font-family: "iconfont" !important;
font-style: normal !important;
font-weight: normal !important;
font-variant: normal !important;
text-transform: none !important;
speak: none;
line-height: 1;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment