Skip to content

Commit

Permalink
with and next relations
Browse files Browse the repository at this point in the history
  • Loading branch information
zgabievi committed Apr 12, 2016
1 parent ff874dc commit c5092fd
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 11 deletions.
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "sass-bem",
"version": "2.5.2",
"version": "2.5.3",
"main": "_bem.scss",
"description": "Amazing package for sass to write bem classes, with namespaces and more advanced features.",
"authors": [
Expand Down
20 changes: 17 additions & 3 deletions helpers/_relations-selector.scss
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@
@return unquote(".#{$block}#{$bem-modifier-separator}#{$modifier} &");
}

/// Selector of with relationship.
/// Selector of adjacent relationship.
///
/// @param {String} $element - Name of element that will come after ".[block]__"
///
/// @returns {String} - & + .[block]__[element]
///
/// @see {mixin} with
/// @see {mixin} next

@function with-selector($element) {
@function next-selector($element) {
$block: get-block(unquote("#{&}"));

@return unquote("& + .#{$block}#{$bem-element-separator}#{$element}");
Expand All @@ -41,6 +41,20 @@
@return unquote("& + #{$last}");
}

/// Selector of sibling relationship.
///
/// @param {String} $element - Name of element that will come after ".[block]__"
///
/// @returns {String} - & ~ .[block]__[element]
///
/// @see {mixin} with

@function with-selector($modifier) {
$block: get-block(unquote("#{&}"));

@return unquote("& ~ .#{$block}#{$bem-element-separator}#{$element}");
}

/// Selector of while relationship.
///
/// @param {String} $modifier - Name of modifier that will come after ".[block]--"
Expand Down
36 changes: 30 additions & 6 deletions mixins/_relations.scss
Original file line number Diff line number Diff line change
Expand Up @@ -24,26 +24,26 @@
}
}

/// Element with another element separated by plus sign
/// Element with next element separated by plus sign
///
/// @param {String} $element - Name of element that will be styled with parent element.
///
/// @example scss - Usage
/// @include b('list') {
/// @include e('item') {
/// @include with('title') {
/// @include next('title') {
/// color: black;
/// }
/// }
/// }
///
/// @example css - Output
/// .list__item .list__title {
/// .list__item + .list__title {
/// color: black;
/// }
@mixin with($element) {
#{with-selector($element)} {
@mixin next($element) {
#{next-selector($element)} {
@content;
}
}
Expand All @@ -70,6 +70,30 @@
}
}

/// Element with sibling elements separated by equivalency sign
///
/// @param {String} $element - Name of element that will be styled with parent element.
///
/// @example scss - Usage
/// @include b('list') {
/// @include e('item') {
/// @include with('title') {
/// color: black;
/// }
/// }
/// }
///
/// @example css - Output
/// .list__item ~ .list__title {
/// color: black;
/// }
@mixin with($element) {
#{with-selector($element)} {
@content;
}
}

/// While two selectors are on same element
///
/// @param {String} $modifier - Name of modifier that will follow parent modifier.
Expand All @@ -92,4 +116,4 @@
#{while-selector($modifier)} {
@content;
}
}
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "sass-bem",
"version": "2.5.2",
"version": "2.5.3",
"description": "Amazing package for sass to write bem classes, with namespaces and more advanced features.",
"main": "_bem.scss",
"repository": {
Expand Down

0 comments on commit c5092fd

Please sign in to comment.