-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.scss
248 lines (235 loc) · 6.84 KB
/
index.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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
/// The prefix added to classes and custom properties
/// @type {string}
$selector-prefix: '' !default;
/// The separator used for BEM child elements
/// @type {string}
$element-separator: '__' !default;
/// The separator used for BEM modifiers
/// @type {string}
$modifier-separator: '--' !default;
/// The default prefix for state classes
/// @type {string}
$state-prefix: 'is' !default;
/// Should state classes be added as qualifiers like in SMACSS
/// (e.g., `.base-class.is-state`) this increasing specificity
/// or as a single class like in classic BEM (e.g. `.base-class--is-state`)
/// thus retaining flatters specificity.
/// @type {boolean}
$qualify-state: true !default;
////////////////////////////////////////////////////////////////////////
// Prefixed Custom Properties //
////////////////////////////////////////////////////////////////////////
/// Create a prefixed custom property
/// ---
/// Create custom properties that are prefixed to avoid name
/// collusion but without the syntactic verbosity of repeatedly doing:
/// --#{$selector-prefix}variable-name: variable-value;
/// @param {String} $name
/// The custom-property's name
/// @param {any} $value
/// The value assigned to the custom-property
/// ---
/// @example
/// .foo {
/// @include create-var(primary, red);
/// }
/// // Assuming `$selector-prefix: p-`, will generate:
/// // .foo { --p-primary: red; }
@mixin create-var($name, $value) {
--#{$selector-prefix}#{$name}: #{$value};
}
/// Use a prefixed custom properties to avoid name collusion
/// but without the syntactic verbosity of repeatedly doing:
/// color: var(--#{$selector-prefix}color1);
/// ---
/// @param {String} $name
/// The _unprefixed_ name of the variable to use. Usually one defined
/// using the `css-var` mixin.
/// ---
/// @return {String} Prefixed custom property reference
/// ---
/// @example
/// .foo {
/// color: use-var(primary);
/// }
/// // Assuming `$selector-prefix: p-`, will generate:
/// // .foo { color: var(--p-primary); }
@function use-var($name) {
@return var(--#{$selector-prefix}#{$name});
}
////////////////////////////////////////////////////////////////////////
// BEM Helpers //
// create idiomatic Bem hierarchy //
////////////////////////////////////////////////////////////////////////
/// Create a prefixed class selector
/// ---
/// Create class selectors that are prefixed to avoid name
/// collusion but without the syntactic verbosity of repeatedly doing:
/// .#{$selector-prefix}name { ... }.
///
/// Can be used to create any class, but designed chiefly to be used as
/// an idiomatic way to create `BEM` block rulesets (hense, aliased as `b`)
/// ---
/// @param {arglist} $names
/// Unprefixed class name(s) to create the selector from
/// ---
/// @example
/// // Single class:
/// @include class(foo) { color: red; }
/// // Assuming `$selector-prefix: p-`, will generate:
/// // .p-foo { color: red; }
///
/// @example
/// // Multiple class:
/// @include class(foo, bar) { color: red; }
/// // Assuming `$selector-prefix: p-`, will generate:
/// // .p-foo, .p-bar { color: red; }
///
/// @example
/// // Scoped:
/// .scope {
/// @include class(foo) { color: red; }
/// }
/// // Assuming `$selector-prefix: p-`, will generate:
/// // .scope {.p-foo { color: red; } }
/// ---
/// @alias b
/// ---
/// @see {variable} $selector-prefix
@mixin class($names...) {
$prefixed-selectors: ();
@each $name in $names {
$prefixed-selector: unquote('.#{$selector-prefix}#{$name}');
$prefixed-selectors: append($prefixed-selectors, $prefixed-selector, comma);
}
#{$prefixed-selectors} {
@content;
}
}
// `b` for block in BEM.
// An alias of the `@include class()` mixin
@mixin b($names...) {
@include class($names...) { @content; }
}
/// Idiomatically create BEM element rulesets
/// Can be nested inside modifiers or other elements to infinite depth
/// ---
/// @param {string} $name
/// The element's name
/// ---
/// @example
/// @include b(block) {
/// ...
/// @include e(element) { ... } // -> .block__element { ... }
/// }
/// ---
/// @alias element
/// ---
/// @see {variable} $element-separator
@mixin e($name) {
@at-root {
&#{$element-separator}#{$name} {
@content;
}
}
}
// An alias of the `@include e()` mixin
@mixin element($name) {
@include e($name) { @content }
}
/// Idiomatically create BEM modifier rulesets
/// Can be nested inside elements or other modifiers to infinite depth
/// ---
/// @param {string} $name
/// The modifier's name
/// ---
/// @example
/// @include b(block) {
/// ...
/// @include m(mod) { ... } // -> .block--mod { ... }
/// }
/// @alias modifier
/// ---
/// @see {variable} $modifier-separator
@mixin m($name) {
@at-root {
&#{$modifier-separator}#{$name} {
@content;
}
}
}
// An alias of the `include m()` mixin
@mixin modifier($name) {
@include m($name) { @content }
}
/// Idiomatically create state qualifier classes of a parent selector
/// ---
/// @param {string} $state
/// The represented state
/// @param {string} $prefix [$state-prefix]
/// The string to use when prefixing `$state`,
/// e.g, `@include is(open, is) { ... }` will create an `.is-open`
/// qualifier.
/// @param {boolean} $qualify [$qualify-state]
/// Should state classes be added as qualifiers like in SMACSS
/// (e.g., `.base-class.is-state`) thus increasing specificity
/// or as a single class like in classic BEM (e.g. `.base-class--is-state`)
/// thus retaining flatters specificity.
/// ---
/// @example
/// html {
/// ...
/// @include is(app) { ... } // -> .html.is-app { ... }
/// }
/// ---
/// @alias state
/// ---
/// @see {variable} $state-prefix
/// @see {variable} $qualify-state
@mixin is($state, $prefix: $state-prefix, $qualify: $qualify-state) {
@if $qualify == true {
@at-root {
&.#{$prefix}-#{$state} {
@content;
}
}
}
@else {
@at-root {
&#{$modifier-separator}#{$prefix}-#{$state} {
@content;
}
}
}
}
@mixin state($args...) {
@include is($args...) { @content; }
}
////////////////////////////////////////////////////////////////////////
// Qualifiers //
////////////////////////////////////////////////////////////////////////
/// Qualify a selector with another selector to increase specificity
/// ---
/// @param {String} $qualifier
/// ---
/// @example
/// // Qualify element with a class:
/// button {
/// @include when-is(.large) { ... } // -> button.large {...}
/// }
/// @example
/// // Qualify class when a certain element:
/// .button {
/// @include when-is(a) { ... } // -> a.button {...}
/// }
/// ---
/// @alias qualify
/// ---
@mixin when-is($qualifier) {
@at-root #{selector-unify(&, $qualifier)} {
@content;
}
}
@mixin qualify($arg...) {
@include when-is($args...) { @content; }
}