aboutsummaryrefslogtreecommitdiffstats
path: root/src/bem/_theme.scss
blob: a49981c1dec214f30126eab8e0cc2337ae8fdb18 (plain) (blame)
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
////
/// @group BEM
///
/// @access public
////

/// 
/// Declare new rules for the current block for when this theme is active.
///
/// @param {string} $name  - First theme block name
/// @param {string} $names - More theme block names
///
/// @content
///
@mixin iro-bem-at-theme($name, $names...) {
    $result:   iro-bem-at-theme($name, $names...);
    $selector: nth($result, 1);
    $context:  nth($result, 2);

    @include iro-bem-validate(
        'at-theme',
        (name: $name, names: $names),
        $selector,
        $context
    );

    @include iro-context-push($iro-bem-context-id, $context...);
    @at-root #{$selector} {
        @content;
    }
    @include iro-context-pop($iro-bem-context-id);
}

///
/// Declare new rules for the current block for when this theme is active.
/// 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-at-theme
///
@function iro-bem-at-theme($name, $names...) {
    $noop: iro-context-assert-stack-must-contain($iro-bem-context-id, 'block');

    $parent-context:  iro-context-get($iro-bem-context-id, 'block');
    $parent-selector: map-get(nth($parent-context, 2), 'selector');

    //@if not iro-selector-suffix-match(&, $parent-selector) {
    //    @error 'An at-theme rule must be an immediate child of a block';
    //}

    $selector: iro-bem-theme-selector($name, $names...);
    $selector: selector-nest($selector, &);

    $context: 'at-theme', (
        'name':     join($name, $names),
        'selector': $selector
    );

    @return $selector $context;
}