-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbem-sass-mixins.sass
35 lines (30 loc) · 1.1 KB
/
bem-sass-mixins.sass
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
$bemSeparators: (element: '__', modifier: '--', pseudo: ':') !default
// Return nest-in-state element if block has modifier class.
@function _nestInState($parent)
$parent: str-slice(inspect($parent), 0) // To string.
$modifierAt: str-index($parent, map-get($bemSeparators, 'modifier'))
@if $modifierAt != null
@return #{$parent + ' ' + str-slice($parent, 0, $modifierAt - 1)}
@else
$modifierAt: str-index($parent, map-get($bemSeparators, 'pseudo'))
@if $modifierAt != null
@return #{$parent + ' ' + str-slice($parent, 0, $modifierAt - 1)}
@return $parent
// Generate prefixes for block(s) or element(s).
@function bemify($items, $type)
$output: ()
@each $parent in &
@each $item in $items
@if $type == 'element'
$parent: _nestInState($parent)
$output: append($output, #{$parent + map-get($bemSeparators, $type) + $item}, comma)
@return $output
=e($elements)
@at-root #{bemify($elements, 'element')}
@content
=m($modifiers)
@at-root #{bemify($modifiers, 'modifier')}
@content
=pseudo($pseudos)
@at-root #{bemify($pseudos, 'pseudo')}
@content