//// /// @group BEM /// /// @access public //// /// /// Create a new state rule. /// /// @param {string} $state - First state name /// @param {list} $states - List of more state names /// /// @content /// /// @example scss - Using single is-state /// @include iro-bem-object('menu') { /// display: none; /// /// @include iro-bem-state('is', open') { /// display: block; /// } /// } /// /// // Generates: /// /// .o-menu { /// display: none; /// } /// /// .o-menu.is-open { /// display: block; /// } /// /// @example scss - Using multiple is-states /// @include iro-bem-object('menu') { /// display: none; /// /// @include iro-bem-state('is', open', 'visible') { /// display: block; /// } /// } /// /// // Generates: /// /// .o-menu { /// display: none; /// } /// /// .o-menu.is-open, /// .o-menu.is-visible { /// display: block; /// } /// @mixin iro-bem-state($prefix, $state, $states...) { $result: iro-bem-state($prefix, $state, $states...); $selector: nth($result, 1); $context: nth($result, 2); @include iro-bem-validate( 'state', (prefix: $prefix, state: $state, states: $states), $selector, $context ); @include iro-context-push($iro-bem-context-id, $context...); @at-root #{$selector} { @content; } @include iro-context-pop($iro-bem-context-id); } /// /// Generate a new state. /// /// @return {list} A list with two items: 1. selector, 2. context or `null` /// /// @see {mixin} iro-bem-has /// @function iro-bem-state($prefix, $state, $states...) { $selector: (); $parts-data: (); @each $state in join($state, $states) { $sel: selector-parse('.#{$prefix}-#{$state}'); @if & { $sel: selector-append(&, $sel); } $selector: join($selector, $sel, comma); $parts-data: append($parts-data, ( 'name': $state, 'selector': $sel )); } $context: 'state', ( 'parts': $parts-data, 'selector': $selector ); @return $selector $context; } /// /// Create a new has-state modifier. /// /// It's a shorthand for iro-bem-state('is', $state, $states...). /// @mixin iro-bem-is($state, $states...) { @include iro-bem-state('is', $state, $states...) { @content; } } /// /// Generate a new is-state modifier. 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-is /// @function iro-bem-is($state, $states...) { @return iro-bem-state('is', $state, $states...); } /// /// Create a new has-state modifier. /// /// It's a shorthand for iro-bem-state('has', $state, $states...). /// @mixin iro-bem-has($state, $states...) { @include iro-bem-state('has', $state, $states...) { @content; } } /// /// Generate a new has-state modifier. 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-has /// @function iro-bem-has($state, $states...) { @return iro-bem-state('has', $state, $states...); }