Skip to content

Commit 276a027

Browse files
authored
Merge pull request #1849 from IgniteUI/bem-elem-muiltimods
feat(BEM): add support for multiple modifiers in elements
2 parents 5fcb7d9 + 8be132f commit 276a027

File tree

1 file changed

+41
-17
lines changed
  • projects/igniteui-angular/src/lib/core/styles/base/utilities

1 file changed

+41
-17
lines changed

projects/igniteui-angular/src/lib/core/styles/base/utilities/_bem.scss

Lines changed: 41 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -204,34 +204,58 @@ $bem--sep-mod-val: if(variable-exists(bem--sep-mod-val), $bem--sep-mod-val, '-')
204204
/// @param {String} $elem - The sub-element name.
205205
/// @param {String} $m - The modifier name.
206206
/// @param {String} $mod - An alias of `$m`.
207-
@mixin bem-elem($elem, $m: null, $mod: null) {
207+
@mixin bem-elem($elem, $m: null, $mod: null, $mods: null) {
208208
$this: bem--selector-to-string(&);
209+
$block: bem--extract-block($this);
210+
$first: bem--extract-first-selector($this);
211+
$nested: bem--contains-pseudo($this) or bem--contains-mod($this);
212+
213+
$mod: $m or $mod;
214+
$mx: ();
215+
209216
@if $this == '' {
210217
@error 'Detected an Element that is not inside a Block: #{$elem}';
211218
}
219+
212220
@if bem--contains-elem($this) {
213221
@error 'Detected a multi-level nested Element (#{$this} #{$elem})! Bemerald doesn\'t support nested ' + 'elements because they do not have BEM nature (www.getbem.com/faq/#css-nested-elements). ' + 'If you must do it, use a hardcoded selector like &__subsubelem ';
214222
}
215-
$mod: $m or $mod;
216-
$block: bem--extract-block($this);
217-
$first: bem--extract-first-selector($this);
218-
@if not (bem--contains-pseudo($this) or bem--contains-mod($this)) {
223+
224+
@if $mods != null and type-of($mods) == 'list' {
225+
@each $i in $mods {
226+
$mx: append($mx, #{bem-selector($block, $e: ($elem, $i))})
227+
}
228+
}
229+
230+
@if not($nested) {
219231
// Normal case, no pseudo-selector present or mod, so no nesting.
220-
// .myblock__myelem { ... }
232+
// .block__elem { ... }
221233
@at-root {
222-
#{bem-selector($block, $e: ($elem, $mod))} {
223-
@content;
234+
@if $mods == null {
235+
#{bem-selector($block, $e: ($elem, $mod))} {
236+
@content;
237+
}
238+
} @else {
239+
#{implode($mx)} {
240+
@content;
241+
}
224242
}
225243
}
226244
} @else {
227245
// pseudo-element or mod present, so we have nesting.
228-
// .myblock:active .myblock__myelem { ... }
229-
// .myblock--mymod .myblock__myelem { ... }
246+
// .block:active .block__elem { ... }
247+
// .block--mod .block__elem { ... }
230248
@at-root {
231-
$selector: bem--extract-first-selector($this) + ' ' + bem-selector($block, $e: ($elem, $mod));
249+
$selector: $first + ' ' + bem-selector($block, $e: ($elem, $mod));
232250

233-
#{$selector} {
234-
@content;
251+
@if $mods == null {
252+
#{$selector} {
253+
@content;
254+
}
255+
} @else {
256+
#{$first} #{implode($mx)} {
257+
@content;
258+
}
235259
}
236260
}
237261
}
@@ -304,8 +328,8 @@ $bem--sep-mod-val: if(variable-exists(bem--sep-mod-val), $bem--sep-mod-val, '-')
304328
}
305329

306330
/// @alias bem-elem
307-
@mixin elem($elem, $m: null, $mod: null) {
308-
@include bem-elem($elem, $m: $m, $mod: $mod) {
331+
@mixin elem($elem, $m: null, $mod: null, $mods: null) {
332+
@include bem-elem($elem, $m: $m, $mod: $mod, $mods: $mods) {
309333
@content;
310334
}
311335
}
@@ -332,8 +356,8 @@ $bem--sep-mod-val: if(variable-exists(bem--sep-mod-val), $bem--sep-mod-val, '-')
332356
}
333357

334358
/// @alias bem-elem
335-
@mixin e($elem, $m: null, $mod: null) {
336-
@include bem-elem($elem, $m: $m, $mod: $mod) {
359+
@mixin e($elem, $m: null, $mod: null, $mods: null) {
360+
@include bem-elem($elem, $m: $m, $mod: $mod, $mods: $mods) {
337361
@content;
338362
}
339363
}

0 commit comments

Comments
 (0)