Initial commit
[editorial.git] / assets / main / sass / libs / _functions.scss
1 /// Removes a specific item from a list.
2 /// @author Hugo Giraudel
3 /// @param {list} $list List.
4 /// @param {integer} $index Index.
5 /// @return {list} Updated list.
6 @function remove-nth($list, $index) {
7
8 $result: null;
9
10 @if type-of($index) != number {
11 @warn "$index: #{quote($index)} is not a number for `remove-nth`.";
12 }
13 @else if $index == 0 {
14 @warn "List index 0 must be a non-zero integer for `remove-nth`.";
15 }
16 @else if abs($index) > length($list) {
17 @warn "List index is #{$index} but list is only #{length($list)} item long for `remove-nth`.";
18 }
19 @else {
20
21 $result: ();
22 $index: if($index < 0, length($list) + $index + 1, $index);
23
24 @for $i from 1 through length($list) {
25
26 @if $i != $index {
27 $result: append($result, nth($list, $i));
28 }
29
30 }
31
32 }
33
34 @return $result;
35
36 }
37
38 /// Gets a value from a map.
39 /// @author Hugo Giraudel
40 /// @param {map} $map Map.
41 /// @param {string} $keys Key(s).
42 /// @return {string} Value.
43 @function val($map, $keys...) {
44
45 @if nth($keys, 1) == null {
46 $keys: remove-nth($keys, 1);
47 }
48
49 @each $key in $keys {
50 $map: map-get($map, $key);
51 }
52
53 @return $map;
54
55 }
56
57 /// Gets a duration value.
58 /// @param {string} $keys Key(s).
59 /// @return {string} Value.
60 @function _duration($keys...) {
61 @return val($duration, $keys...);
62 }
63
64 /// Gets a font value.
65 /// @param {string} $keys Key(s).
66 /// @return {string} Value.
67 @function _font($keys...) {
68 @return val($font, $keys...);
69 }
70
71 /// Gets a misc value.
72 /// @param {string} $keys Key(s).
73 /// @return {string} Value.
74 @function _misc($keys...) {
75 @return val($misc, $keys...);
76 }
77
78 /// Gets a palette value.
79 /// @param {string} $keys Key(s).
80 /// @return {string} Value.
81 @function _palette($keys...) {
82 @return val($palette, $keys...);
83 }
84
85 /// Gets a size value.
86 /// @param {string} $keys Key(s).
87 /// @return {string} Value.
88 @function _size($keys...) {
89 @return val($size, $keys...);
90 }