|
// Gagnleg Stylus föll/mixin |
|
|
|
|
|
// =============================================================================== |
|
// Percentage helper |
|
|
|
// Converts a fraction to a percentage. Defaults to `%` but can also do `vw`/`vh` |
|
// |
|
// Usage: |
|
// width: pct(720/1440); // width: 50%; |
|
// width: pct(720/1440, vw); // width: 50vw; |
|
// |
|
pct($fraction, $pct='%') { |
|
return unit(100*$fraction, $pct); |
|
} |
|
|
|
|
|
// =============================================================================== |
|
// CSS `calc()` helper |
|
|
|
// ...because Stylus makes it difficult to use `calc()` |
|
// |
|
// Usage: |
|
// width: csscalc(50%, 50px); // width: calc(50% + 50px); |
|
// width: csscalc(50%, -50px); // width: calc(50% - 50px); |
|
// width: csscalc(30%, 20px, -1em); // width: calc(30% + 20px - 1em); |
|
// |
|
csscalc($first, $rest...) { |
|
$values = $first; |
|
for $arg in $rest { |
|
$values = $values + ($arg<0 ? ' - ' : ' + ') + abs($arg); |
|
} |
|
return s('calc('+ $values +')'); |
|
} |
|
|
|
|
|
|
|
|
|
// =============================================================================== |
|
// Variable Percentage values |
|
|
|
// Returns margin/padding/font-size/etc. value calc() function that delivers |
|
// approximately: |
|
// * $min pixels when the element's container is $minWidth pixels wide |
|
// * $max pixels when the element's container is $maxWidth pixels wide. |
|
// |
|
// Defaults to `%` values, but can be instructed to use `vw` or `vh` instead. |
|
// |
|
// Usage: |
|
// |
|
// html { |
|
// font-size: 15px; |
|
// @media screen and (min-width: 480px) { |
|
// font-size: between( 15,480, 20,1440, vw ); |
|
// } |
|
// } |
|
// body { |
|
// padding-left: between(20,320, 200,1440 ) |
|
// padding-right: @padding-left; |
|
// } |
|
// |
|
between( $min, $minWidth, $max, $maxWidth, $pct='%') { |
|
$slope = ($max - $min) / ($maxWidth - $minWidth); |
|
$intercept = $max - ($slope * $maxWidth); |
|
if ( $intercept == 0 ) { |
|
return unit($slope*100, $pct); |
|
} |
|
else { |
|
return csscalc( unit($slope*100, $pct), ($intercept)px ); |
|
} |
|
} |
|
|
|
|
|
|
|
// =============================================================================== |
|
// Triangles mixin |
|
|
|
// CSS triangles for tooltip pins, etc. |
|
// |
|
// Usage: |
|
// |
|
// .box::after { |
|
// _triangle( |
|
// $dir, // <-- top, bottom, left, right. |
|
// $color, // arrow color |
|
// $h, // the "Length" of the arrow. |
|
// $w, // total width of the arrow. (Defaults to twice the @height) |
|
// $pos, // sideways placement along the edge of the container. (Defaults to 50%.) |
|
// $posFrom, // edge from which the side-offset is calculated. (Defaults to left or top respectively.) |
|
// $shift // shift along the "height" axis, away or towards the container. (Defaults to 0) |
|
// ); |
|
// } |
|
// |
|
_triangle($dir=top, $color=#fff, $h=10px, $w=(2*$h), $pos=50%, $posFrom=null, $shift=0) { |
|
_triangleBasic(); |
|
_triangleShape($dir, $color, $h, $w, $pos, $posFrom, $shift); |
|
} |
|
_triangleBasic() { |
|
content: ''; |
|
width: 0; |
|
height: 0; |
|
min-width: 0; |
|
min-height: 0; |
|
position: absolute; |
|
border: 0 solid transparent; |
|
} |
|
_triangleShape($dir=top, $color=#fff, $h=10px, $w=(2*$h), $pos=50%, $posFrom=null, $shift=0) { |
|
isVertical($dir) { return $dir==top or $dir==bottom; } |
|
$posFrom = $posFrom || ( isVertical($dir) ? left : top ); |
|
|
|
{$dir}: - $h; |
|
{$posFrom}: $pos; |
|
margin: (- $w/2); |
|
margin-{$dir}: - $shift; |
|
border-width: isVertical($dir) ? $h ($w/2) : ($w/2) $h; |
|
border-{opposite-position($dir)}-color: $color; |
|
border-{$dir}-width: 0; |
|
} |
|
|
|
|
|
|
|
// =============================================================================== |
|
// Relative color fader |
|
|
|
// Example: |
|
// $fadedBlue = rgba(#00f, .6); |
|
// color: $fadedBlue; // color: rgba(0,0,255, .6); |
|
// color: rgba($fadedBlue, .5); // color: rgba(0,0,255, .5); |
|
// color: fade($fadedBlue, .5); // color: rgba(0,0,255, .3); |
|
// |
|
fade($color, $opacity) { |
|
return rgba( $color, alpha($color)*$opacity ); |
|
} |
|
|
|
|