-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path_atomic-helpers.scss
65 lines (61 loc) · 1.74 KB
/
_atomic-helpers.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
@use "sass:list";
@use "sass:map";
@use "sass:math";
@use "sass:meta";
$breakpoints: (
"sm": 768,
"md": 1024,
"lg": 1366
) !default;
/// It generates atomic css classes
/// @param {string} $base-class The base rules class
/// @param {map} $config The rules configuration map
///
@mixin atomic-helpers($base-class, $specs) {
$-property: map.get($specs, "property");
$-breakpoints: map.get($specs, "breakpoints");
$-value: map.get($specs, "value");
$-prefix: map.get($specs, "prefix");
// generating basic rules
@if meta.type-of($-property) == "map" {
@each $prop-key, $prop-value in $-property {
$-base-class: if($prop-key == "_", $base-class, $base-class + $prop-key);
@include atomic-helpers($-base-class, (
"prefix": $-prefix,
"property": $prop-value,
"value": $-value
));
}
} @else if meta.type-of($-value) == "map" {
@each $mod, $value in $-value {
$-base-class: if($-prefix, $-prefix + "\\:" + $base-class + "-" + $mod, $base-class + "-" + $mod);
@include atomic-helpers($-base-class, (
"property": $-property,
"value": $value
));
}
} @else {
#{"." + $base-class} {
#{$-property}: $-value;
}
}
// generating responsive rules
@if meta.type-of($-breakpoints) == 'string' {
$-breakpoints: list.append((), $-breakpoints);
}
@if meta.type-of($-breakpoints) == "list" {
@each $-key in $-breakpoints {
$-size: map.get($breakpoints, $-key);
@if math.is-unitless($-size) {
$-size: $-size * 1px;
}
@media screen and (min-width: $-size) {
@include atomic-helpers($base-class, (
"prefix": $-key,
"property": $-property,
"value": $-value
));
}
}
}
}