aboutsummaryrefslogtreecommitdiffstats
path: root/src/bem/_theme.scss
blob: ff1ba493390c542a857ac1249a283d5afaa7c193 (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
62
63
64
65
66
////
/// @group BEM
///
/// @access public
////

@use './functions';
@use './validators';
@use './vars';
@use '../contexts';

/// 
/// 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 at-theme($name, $names...) {
    $result:   at-theme($name, $names...);
    $selector: nth($result, 1);
    $context:  nth($result, 2);

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

    @include contexts.push(vars.$context-id, $context...);
    @at-root #{$selector} {
        @content;
    }
    @include contexts.pop(vars.$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} at-theme
///
@function at-theme($name, $names...) {
    $noop: contexts.assert-stack-must-contain(vars.$context-id, 'block');

    $parent-context:  contexts.get(vars.$context-id, 'block');
    $parent-selector: map-get(nth($parent-context, 2), 'selector');

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

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

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

    @return $selector $context;
}