diff options
Diffstat (limited to 'src/bem/_suffix.scss')
-rw-r--r-- | src/bem/_suffix.scss | 95 |
1 files changed, 49 insertions, 46 deletions
diff --git a/src/bem/_suffix.scss b/src/bem/_suffix.scss index 2ddb54d..93e4066 100644 --- a/src/bem/_suffix.scss +++ b/src/bem/_suffix.scss | |||
@@ -4,6 +4,9 @@ | |||
4 | /// @access public | 4 | /// @access public |
5 | //// | 5 | //// |
6 | 6 | ||
7 | @use 'sass:list'; | ||
8 | @use 'sass:map'; | ||
9 | @use 'sass:selector'; | ||
7 | @use './validators'; | 10 | @use './validators'; |
8 | @use './vars'; | 11 | @use './vars'; |
9 | @use '../functions'; | 12 | @use '../functions'; |
@@ -54,22 +57,22 @@ | |||
54 | /// } | 57 | /// } |
55 | /// | 58 | /// |
56 | @mixin suffix($name) { | 59 | @mixin suffix($name) { |
57 | $result: suffix($name); | 60 | $result: suffix($name); |
58 | $selector: nth($result, 1); | 61 | $selector: list.nth($result, 1); |
59 | $context: nth($result, 2); | 62 | $context: list.nth($result, 2); |
60 | 63 | ||
61 | @include validators.validate( | 64 | @include validators.validate( |
62 | 'suffix', | 65 | 'suffix', |
63 | (name: $name), | 66 | (name: $name), |
64 | $selector, | 67 | $selector, |
65 | $context | 68 | $context |
66 | ); | 69 | ); |
67 | 70 | ||
68 | @include contexts.push(vars.$context-id, $context...); | 71 | @include contexts.push(vars.$context-id, $context...); |
69 | @at-root #{$selector} { | 72 | @at-root #{$selector} { |
70 | @content; | 73 | @content; |
71 | } | 74 | } |
72 | @include contexts.pop(vars.$context-id); | 75 | @include contexts.pop(vars.$context-id); |
73 | } | 76 | } |
74 | 77 | ||
75 | /// | 78 | /// |
@@ -80,44 +83,44 @@ | |||
80 | /// @see {mixin} suffix | 83 | /// @see {mixin} suffix |
81 | /// | 84 | /// |
82 | @function suffix($name) { | 85 | @function suffix($name) { |
83 | // | 86 | // |
84 | // Suffixes can be used on block, element and modifier. | 87 | // Suffixes can be used on block, element and modifier. |
85 | // | 88 | // |
86 | 89 | ||
87 | $noop: contexts.assert-stack-count(vars.$context-id, vars.$max-depth); | 90 | $noop: contexts.assert-stack-count(vars.$context-id, vars.$max-depth); |
88 | $noop: contexts.assert-stack-must-contain(vars.$context-id, 'block'); | 91 | $noop: contexts.assert-stack-must-contain(vars.$context-id, 'block'); |
89 | $noop: contexts.assert-stack-must-not-contain(vars.$context-id, 'suffix'); | 92 | $noop: contexts.assert-stack-must-not-contain(vars.$context-id, 'suffix'); |
90 | 93 | ||
91 | $parent-context: contexts.get(vars.$context-id, 'block' 'element' 'modifier'); | 94 | $parent-context: contexts.get(vars.$context-id, 'block' 'element' 'modifier'); |
92 | $parent-selector: map-get(nth($parent-context, 2), 'selector'); | 95 | $parent-selector: map.get(list.nth($parent-context, 2), 'selector'); |
93 | 96 | ||
94 | @if not functions.selector-suffix-match(&, $parent-selector) { | 97 | @if not functions.selector-suffix-match(&, $parent-selector) { |
95 | // | 98 | // |
96 | // The current selector doesn't match the parent selector. | 99 | // The current selector doesn't match the parent selector. |
97 | // The user manually added a selector between parent context and this suffix call. | 100 | // The user manually added a selector between parent context and this suffix call. |
98 | // This case is forbidden because any outcome semantically wouldn't make sense: | 101 | // This case is forbidden because any outcome semantically wouldn't make sense: |
99 | // - {b,e,m} [manual selector] {b,e,m}@suffix | 102 | // - {b,e,m} [manual selector] {b,e,m}@suffix |
100 | // - {b,e,m}@suffix [manual selector] | 103 | // - {b,e,m}@suffix [manual selector] |
101 | // The first case would make the modifier behave like an element. | 104 | // The first case would make the modifier behave like an element. |
102 | // The second case is unintuitive, the code would be more clear by nesting the manual | 105 | // The second case is unintuitive, the code would be more clear by nesting the manual |
103 | // selector in the suffix instead. | 106 | // selector in the suffix instead. |
104 | // | 107 | // |
105 | 108 | ||
106 | @error 'A suffix must be an immediate child of the parent context'; | 109 | @error 'A suffix must be an immediate child of the parent context'; |
107 | } | 110 | } |
108 | 111 | ||
109 | // | 112 | // |
110 | // The suffix part can simply be appended. | 113 | // The suffix part can simply be appended. |
111 | // Possible outcomes: | 114 | // Possible outcomes: |
112 | // - {b,e,m}@suffix | 115 | // - {b,e,m}@suffix |
113 | // | 116 | // |
114 | 117 | ||
115 | $selector: selector-append(&, vars.$suffix-separator + $name); | 118 | $selector: selector.append(&, vars.$suffix-separator + $name); |
116 | 119 | ||
117 | $context: 'suffix', ( | 120 | $context: 'suffix', ( |
118 | 'name': $name, | 121 | 'name': $name, |
119 | 'selector': $selector | 122 | 'selector': $selector |
120 | ); | 123 | ); |
121 | 124 | ||
122 | @return $selector $context; | 125 | @return $selector $context; |
123 | } | 126 | } |