-
Notifications
You must be signed in to change notification settings - Fork 34
/
csstyle.scss
101 lines (87 loc) · 2.5 KB
/
csstyle.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
// csstyle for sass
// Clean, Simple Styling for the Web
// http://www.csstyle.io
// Copyright (c) 2014 Dave Geddes
// https://twitter.com/geddski
// https://github.com/geddski
$csstyle-component-symbol: '' !default;
$csstyle-option-symbol: '\\--' !default;
$csstyle-part-symbol: '__' !default;
$csstyle-tweak-symbol: '\\+' !default;
$csstyle-location-symbol: '\\@' !default;
$csstyle-root-id: 'csstyle' !default;
// build selectors
@function _build_selector($prefix, $names){
$selector: "";
@for $i from 1 through length($names){
$selector: $selector + $prefix + nth($names, $i);
@if($i != length($names)){
$selector: $selector + ",";
}
}
@return $selector;
}
// components
@mixin component($names...){
#{_build_selector("." + $csstyle-component-symbol, $names)}{
@content;
}
}
// options
// override components
@mixin option($names...){
#{_build_selector("&." + $csstyle-option-symbol, $names)}{
@content;
}
}
// parts
// make up the structure of a component
// override components
@mixin part($names...){
// check if nested in an option
$optionIndex: str-index(#{&}, "." + $csstyle-option-symbol);
@if str-index($csstyle-option-symbol, "\\") == 1 and $optionIndex == null {
$optionIndex: str-index(#{&}, "." + str-slice($csstyle-option-symbol, 2));
}
$optionIndex: 0 !default;
$optionIndex: $optionIndex - 1;
// check if nested in another part
$partIndex: str-index(#{&}, $csstyle-part-symbol);
$partIndex: 0 !default;
$partIndex: $partIndex - 1;
$component: str-slice(#{&}, 0, $optionIndex);
// part is nested in an option
@if $optionIndex > 0 {
// part is also nested in another part
@if ($partIndex > 0){
#{_build_selector("&" + $csstyle-part-symbol, $names)}{
@content;
}
}
@else{
#{_build_selector("& " + $component + $csstyle-part-symbol, $names)}{
@content;
}
}
}
@else {
#{_build_selector("&" + $csstyle-part-symbol, $names)}{
@content;
}
}
}
// tweaks
// override components, options, and modifiers
@mixin tweak($names...){
#{_build_selector("#" + $csstyle-root-id + " ." + $csstyle-tweak-symbol, $names)}{
@content;
}
}
// locations
// override components, parts, options, and tweaks
@mixin location($names...){
@warn "locations will be deprecated soon. Please use components instead.";
#{_build_selector("#" + $csstyle-root-id + " ." + $csstyle-location-symbol, $names)}{
@content;
}
}