-
Notifications
You must be signed in to change notification settings - Fork 0
/
_utils.scss
68 lines (62 loc) · 1.77 KB
/
_utils.scss
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
@use 'sass:map';
@use 'sass:string';
@use 'sass:list';
@use './map' as *;
// Shamelessly yoinked from: https://stackoverflow.com/a/42295154/12689721
@function split($string, $separator) {
$split-arr: ();
$index: string.index($string, $separator);
@while $index != null {
$item: string.slice($string, 1, $index - 1);
$split-arr: append($split-arr, $item);
$string: string.slice($string, $index + 1);
$index: string.index($string, $separator);
}
$split-arr: append($split-arr, $string);
@return $split-arr;
}
@function remove-nth($list, $index, $split: '|') {
$result: ();
$index: if($index < 0, list.length($list) + $index + 1, $index);
@for $i from 1 through list.length($list) {
@if $i != $index {
$result: append($result, nth($list, $i));
}
}
@return split(list.nth($result, 1), $split);
}
// Shamelessly yoinked from: https://stackoverflow.com/a/62698329/12689721
@function str-trim($string) {
@if (str-slice($string, 1, 1) == ' ') {
@return str-trim(str-slice($string, 2));
} @else if (str-slice($string, str-length($string), -1) == ' ') {
@return str-trim(str-slice($string, 1, -2));
} @else {
@return $string;
}
}
@function join-list($list, $join: '') {
$string: null;
@each $key in $list {
$string: if($string != null, $string + $join + $key, $key);
}
@return string.unquote($string);
}
@function get-class($map, $keys) {
@each $key in split($keys, '.') {
$class: map.get($map, $key);
@if not $class {
@error 'Unknown element \"#{$key}\" in query: #{$keys}';
}
$map: map.get($map, $key);
}
@return $map;
}
@function css-selector($keys, $char) {
$classes: '';
@each $class in split($keys, $char) {
$_class: get-class($classmap, $class);
$classes: if(string.length($classes) == 0, $_class, $classes + $char + $_class);
}
@return $classes;
}