10 Mixins & functions

Stylus utils.

10.1 Contrast

Description

Library to manage contrast for a11y.

In this examples $constast = 4.5 and $contrast-high = 7

10.1.1 _contrast_choose($color, $list, $min = $contrast)

Description

Returns first color of the list matching contrast ratio.

Returns false and throws a warning message if no match.

This stylus code

.foo
    background #000
    color _contrast_choose(#000, #888 #aaa #ddd #fff)
    border-bottom 1px solid _contrast_choose(#000, #888 #aaa #ddd #fff, $contrast-high)

Will render this CSS

.foo {
    background: #000;
    color: #888;
    border-bottom: 1px solid #aaa;
}

Parameters

$color: color to compare

$list: list of color to choose the first match

$min ($contrast): minimum contrast ratio

10.2 FontLoad

Description

Write font-family and fallback if $fontload-js is true

Parameters

$family: value of final font-family property (with custom font at fist place)

$weight: weight of font (by default current font-weight or normal)

$style: style of font (by default current font-style or normal)

10.3 Grid

Description

Colette provides mixins to create custom responsive grid layouts.

10.3.1 _column(size)

Description

Generate grid columns.

Parameters

$size: the number of columns (out of 12) it must span

$flt (left): the float direction (if set to none, the property won't be output)

10.3.2 _gridColumn(breakpoint, size)

Description

Generate grid columns according to breakpoints and media queries defined in settings.

Parameters

$breakpoint: the targeted breakpoint

$size: the number of columns (out of 12) it must span

10.3.3 _offset(size)

Description

Generate an offset left margin, based on column width.

Parameters

$size: the number of columns (out of 12) that defines the width of the margin

10.4 _hslVars

Description

Mixin to help to generate variable of colors decomposed in hue, saturation and lightness

:root
    /** red */
    _hslVars(--red, red)
    /** green */
    _hslVars(--green, green)
    /** blue */
    _hslVars(--blue, blue)
:root {
    /** red */
    --red-h: 0deg;
    --red-s: 100%;
    --red-l: 50%;
    --red: hsl(var(--red-h), var(--red-s), var(--red-l));
    /** green */
    --green-h: 120deg;
    --green-s: 100%;
    --green-l: 25.098039215686274%;
    --green: hsl(var(--green-h), var(--green-s), var(--green-l));
    /** blue */
    --blue-h: 240deg;
    --blue-s: 100%;
    --blue-l: 50%;
    --blue: hsl(var(--blue-h), var(--blue-s), var(--blue-l));

10.5 Inline SVG

Description

Returns encoded inline svg

$svg - svg code

.foo
    background-image _inlineSvg('<svg viewBox="0 0 90 30" width="30" height="30"><circle cx="15" cy="15" r="10" class="bounce1"/></svg>')

will return

.foo {
    background-image url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 90 30' width='30' height='30'%3E%3Ccircle cx='15' cy='15' r='10' class='bounce1'/%3E%3C/svg%3E");
}

Deprecated

10.6 Line height (vertical rythm)

Description

Colette provides some mixins to manage vertical rythm based on $lh settings.

10.6.1 _calcLines($lines, $font-size, $line-height = $lh)

Description

Return new number of lines adding some line division if initial $lines parameter is not enough.

Parameters

$lines: the number of lines (Integer)

$font-size: font-size

$line-height: reference line-height

10.6.2 getLh($font-size, $line-height = $lh)

Description

Return line-height value necessary for $font-size.

Parameters

$font-size: font-size

$line-height: reference line-height

10.6.3 _lh($lines, $line-height = $lh)

Description

Return size for a number on lines.

Parameters

$lines: the number of lines (Integer)

$line-height: reference line-height

10.6.4 _lines($font-size, $line-height = $lh)

Description

Return number of lines necessary for $font-size.

Parameters

$font-size: font-size

$line-height: reference line-height

10.7 Map

Description

Creates a new list with the results of calling a function for every list element.

/* my_file.styl */
myList = (1 2 3 4)
myFunc(i)
    return i * 2
map(myList, myFunc)

will compile to

/* my_file.css */
2 4 6 8

Parameters

$list: list of items

$fn: function calling once for every item on the list

10.8 Mask

Description

Hides text but keeps it readable for screen-readers.

Parameters

$important (false): If set to true, makes all rules !important

10.9 Spaces

Description

Spaces mixins return margin and padding properties based on a multiple of the $grid-gutter size.
Note that $grid-gutter value is defined in Colette’s settings, but it can be overridden in your project stylus file.

10.9.1 _m()

Description

Returns a margin based on $grid-gutter value.

/* my_file.styl */
$grid-gutter = 16px // overrides colette’s default value
.one-argument
    _m(1)

.multiple-arguments
    _m(1 2 3 4)

will compile to

/* my_file.css */
.one-argument {
    margin: 1rem;
}

.multiple-arguments {
    margin: 1rem 2rem 3rem 4rem;
}

Parameters

args: multiplier of $grid-gutter

10.9.2 _mb()

Description

Returns a margin-bottom based on $grid-gutter value.

/* my_file.styl */
$grid-gutter = 16px // overrides colette’s default value
.foo
    _mb(1)

will compile to

/* my_file.css */
.foo {
    margin-bottom: 1rem;
}

Parameters

$i: multiplier of $grid-gutter

10.9.3 _ml()

Description

Returns a margin-left based on $grid-gutter value.

/* my_file.styl */
$grid-gutter = 16px // overrides colette’s default value
.foo
    _ml(1)

will compile to

/* my_file.css */
.foo {
    margin-left: 2rem;
}

Parameters

$i: multiplier of $grid-gutter

10.9.4 _mr()

Description

Returns a margin-right based on $grid-gutter value.

/* my_file.styl */
$grid-gutter = 16px // overrides colette’s default value
.foo
    _mr(1)

will compile to

/* my_file.css */
.foo {
    margin-right: 1rem;
}

Parameters

$i: multiplier of $grid-gutter

10.9.5 _mt()

Description

Returns a margin-top based on $grid-gutter value.

/* my_file.styl */
$grid-gutter = 16px // overrides colette’s default value
.foo
    _mt(1)

will compile to

/* my_file.css */
.foo {
    margin-top: 1rem;
}

Parameters

$i: multiplier of $grid-gutter

10.9.6 _p()

Description

Returns a padding based on $grid-gutter value.

/* my_file.styl */
$grid-gutter = 16px // overrides colette’s default value
.one-argument
    _p(1)

.multiple-arguments
    _p(1 2 3 4)

will compile to

/* my_file.css */
.one-argument {
    padding: 1rem;
}

.multiple-arguments {
    padding: 1rem 2rem 3rem 4rem;
}

Parameters

args: multiplier of $grid-gutter

10.9.7 _pb()

Description

Returns a padding-bottom based on $grid-gutter value.

/* my_file.styl */
$grid-gutter = 16px // overrides colette’s default value
.foo
    _pb(1)

will compile to

/* my_file.css */
.foo {
    padding-bottom: 1rem;
}

Parameters

$i: multiplier of $grid-gutter

10.9.8 _pl()

Description

Returns a padding-left based on $grid-gutter value.

/* my_file.styl */
$grid-gutter = 16px // overrides colette’s default value
.foo
    _pl(1)

will compile to

/* my_file.css */
.foo {
    padding-left: 1rem;
}

Parameters

$i: multiplier of $grid-gutter

10.9.9 _pr()

Description

Returns a padding-right based on $grid-gutter value.

/* my_file.styl */
$grid-gutter = 16px // overrides colette’s default value
.foo
    _pr(1)

will compile to

/* my_file.css */
.foo {
    padding-right: 1rem;
}

Parameters

$i: multiplier of $grid-gutter

10.9.10 _pt()

Description

Returns a padding-top based on $grid-gutter value.

/* my_file.styl */
$grid-gutter = 16px // overrides colette’s default value
.foo
    _pt(1)

will compile to

/* my_file.css */
.foo {
    padding-top: 1rem;
}

Parameters

$i: multiplier of $grid-gutter