Skip to content

Instantly share code, notes, and snippets.

@cahnory
Last active December 20, 2015 04:28
Show Gist options
  • Save cahnory/6070682 to your computer and use it in GitHub Desktop.
Save cahnory/6070682 to your computer and use it in GitHub Desktop.
Next PlastiCSS pin mixin
@mixin pin($top: false, $right: false, $bottom: false, $left: false, $position: absolute, $all: false, $x: false, $y: false) {
// All the same value
@if relevant($all) {
bottom: $all;
left: $all;
right: $all;
top: $all;
}
@else {
// Left == right
@if relevant($x) {
left: $x;
right: $x;
}
// Left != right
@else {
@if relevant($left) {
left: $left;
}
@if relevant($right) {
right: $right;
}
}
// Top == bottom
@if relevant($y) {
bottom: $y;
top: $y;
}
@else {
@if relevant($bottom) {
bottom: $bottom;
}
@if relevant($top) {
top: $top;
}
}
}
@if relevant($position) {
position: $position;
}
}
@function relevant($value, $ignore...) {
@if length($value) == 0 or $value == false or $value == null {
@return false;
}
@each $ignored in $ignore {
@if $value == $ignored
or type-of($value) == color and type-of($ignored) == color and same-color($value, $ignored) {
@return false
}
}
@return true;
}
@function same-color($a, $b, $alpha: true) {
@if $alpha and alpha($a) != alpha($b) {
@return false;
}
@return rgb(red($a), green($a), blue($a)) == rgb(red($b), green($b), blue($b));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment