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
|
////
/// @group BEM
///
/// @access public
////
///
/// Create a new state rule.
///
/// @param {string} $state - First state name
/// @param {list} $states - List of more state names
///
/// @content
///
/// @example scss - Using single is-state
/// @include iro-bem-object('menu') {
/// display: none;
///
/// @include iro-bem-state('is', open') {
/// display: block;
/// }
/// }
///
/// // Generates:
///
/// .o-menu {
/// display: none;
/// }
///
/// .o-menu.is-open {
/// display: block;
/// }
///
/// @example scss - Using multiple is-states
/// @include iro-bem-object('menu') {
/// display: none;
///
/// @include iro-bem-state('is', open', 'visible') {
/// display: block;
/// }
/// }
///
/// // Generates:
///
/// .o-menu {
/// display: none;
/// }
///
/// .o-menu.is-open,
/// .o-menu.is-visible {
/// display: block;
/// }
///
@mixin iro-bem-state($prefix, $state, $states...) {
$result: iro-bem-state($prefix, $state, $states...);
$selector: nth($result, 1);
$context: nth($result, 2);
@include iro-bem-validate(
'state',
(prefix: $prefix, state: $state, states: $states),
$selector,
$context
);
@include iro-context-push($iro-bem-context-id, $context...);
@at-root #{$selector} {
@content;
}
@include iro-context-pop($iro-bem-context-id);
}
///
/// Generate a new state.
///
/// @return {list} A list with two items: 1. selector, 2. context or `null`
///
/// @see {mixin} iro-bem-has
///
@function iro-bem-state($prefix, $state, $states...) {
$selector: ();
$parts-data: ();
@each $state in join($state, $states) {
$sel: selector-parse('.#{$prefix}-#{$state}');
@if & {
$sel: selector-append(&, $sel);
}
$selector: join($selector, $sel, comma);
$parts-data: append($parts-data, (
'name': $state,
'selector': $sel
));
}
$context: 'state', (
'parts': $parts-data,
'selector': $selector
);
@return $selector $context;
}
///
/// Create a new has-state modifier.
///
/// It's a shorthand for iro-bem-state('is', $state, $states...).
///
@mixin iro-bem-is($state, $states...) {
@include iro-bem-state('is', $state, $states...) {
@content;
}
}
///
/// Generate a new is-state modifier. Check the respective mixin documentation for more information.
///
/// @return {list} A list with two items: 1. selector, 2. context or `null`
///
/// @see {mixin} iro-bem-is
///
@function iro-bem-is($state, $states...) {
@return iro-bem-state('is', $state, $states...);
}
///
/// Create a new has-state modifier.
///
/// It's a shorthand for iro-bem-state('has', $state, $states...).
///
@mixin iro-bem-has($state, $states...) {
@include iro-bem-state('has', $state, $states...) {
@content;
}
}
///
/// Generate a new has-state modifier. Check the respective mixin documentation for more information.
///
/// @return {list} A list with two items: 1. selector, 2. context or `null`
///
/// @see {mixin} iro-bem-has
///
@function iro-bem-has($state, $states...) {
@return iro-bem-state('has', $state, $states...);
}
|