Skip to content

Instantly share code, notes, and snippets.

@lmartins
Created January 27, 2014 19:25
Show Gist options
  • Save lmartins/8655610 to your computer and use it in GitHub Desktop.
Save lmartins/8655610 to your computer and use it in GitHub Desktop.
Creating SASS mixins aliases
<button>Alerted</button>
// ----
// libsass (v0.7.0)
// ----
// Long mixin name from a library, probably prefixed with a
// namespace to avoid naming clashes. This is a pain to type
// out all the time
@mixin i-am-a-mixin-with-a-long-name($arg1, $arg2) {
body:after {
content: $arg2;
}
}
// Create a alias mixin with a shorter name that passes
// through all the arguments to the longer named mixin
// The docs for what the ... syntax is can be found at
// http://sass-lang.com/documentation/file.SASS_REFERENCE.html#variable_arguments
@mixin alias($args...) {
@include i-am-a-mixin-with-a-long-name($args...)
}
// Now you can reference your short alias in your project!
@include alias('blah', 'hai');
body:after {
content: 'hai'; }
<button>Alerted</button>
@andrefelipe
Copy link

hi @remisture found the solution.

I struggle too much with the Bootstrap 4 "media-breakpoint-up" and "media-breakpoint-down", they are just too long. So I created these:

@mixin media-from($name, $breakpoints: $grid-breakpoints) {
  @include media-breakpoint-up($name, $breakpoints) {
    @content;
  }
}

@mixin media-max($name, $breakpoints: $grid-breakpoints) {
  @include media-breakpoint-down($name, $breakpoints) {
    @content;
  }
}

@mixin media-between($lower, $upper, $breakpoints: $grid-breakpoints) {
  @include media-breakpoint-between($lower, $upper, $breakpoints) {
    @content;
  }
}

@mixin media-only($name, $breakpoints: $grid-breakpoints) {
  @include media-breakpoint-only($name, $breakpoints) {
    @content;
  }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment