-
Notifications
You must be signed in to change notification settings - Fork 1
Context()
esr360 edited this page Jan 17, 2020
·
8 revisions
This mixin is part of Cell Query
This mixin allows you generate styles when the target element is within a parent module or component, optionally filtered by one or more modifier(s)/pseudo-state(s).
@include context($block, $context);
In the below example,
$this
is a global variable that output's the current module's name, which in this case would be'accordion'
(learn more)
@include module('accordion') {
@include component('content') {
display: none;
@include context(($this, 'panel'), 'active') {
display: block;
}
}
}
Which is equivalent to (in the sense they output the same CSS):
@include module('accordion') {
@include component('panel') {
@include is('active') {
@include component('content') {
display: block;
}
}
}
@include component('content') {
display: none;
}
}
<div class="accordion">
<div class="accordion__panel">
<div class="accordion_title">...</div>
<div class="accordion__content">
...
</div>
</div>
<div class="accordion__panel--active">
<div class="accordion_title">...</div>
<div class="accordion__content">
...
</div>
</div>
</div>
.accordion__content,
[class*="accordion__content--"] {
display: none;
}
[class*="accordion__panel--"][class*="--active"] .accordion__content,
[class*="accordion__panel--"][class*="--active"] [class*="accordion__content--"] {
display: block;
}
Type |
String | List
|
Description | The name of a module or a list that will be concatenated to a BEM component selector |
Default | undefined |
.foo {
@include context('myModule') {
color: red;
}
}
.myModule .foo {
color: red;
}
[class*="myModule--"] .foo {
color: red;
}
.foo {
@include context('myModule', 'fizz', 'buzz') {
color: red;
}
}
.myModule__fizz__buzz .foo {
color: red;
}
[class*="myModule__fizz__buzz--"] .foo {
color: red;
}
Type |
String | List
|
Description | The name of a modifier of pseudo-state (pseudo-state must be prepended with : ) |
Default | null |
.foo {
@include context('myModule', ('active', ':hover')) {
color: blue;
}
}
[class*="myModule--"][class*="--active"] .foo {
color: blue;
}
.myModule:hover .foo {
color: blue;
}
[class*="myModule--"]:hover .foo {
color: blue;
}