Skip to content

Commit

Permalink
fix(core): selectors applied conditionally (#209)
Browse files Browse the repository at this point in the history
Sass' `&` will output the selector twice,
which is why the linter disallows it,
and our conditional selectors should account for that.
  • Loading branch information
rabelloo authored Jan 20, 2021
1 parent e5c0829 commit e6cc6d5
Show file tree
Hide file tree
Showing 8 changed files with 24 additions and 15 deletions.
10 changes: 2 additions & 8 deletions .stylelintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,9 @@
"scss/no-global-function-names": true,
"order/order": [
[
{
"type": "at-rule",
"name": "include"
},
{
"type": "at-rule",
"name": "extend"
},
"dollar-variables",
{ "type": "at-rule", "name": "include" },
{ "type": "at-rule", "name": "extend" },
"custom-properties",
"declarations",
"rules"
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/mixins/as-text-input.scss
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
@use './with-inner-focus' as mixins;

@mixin as-text-input() {
@include helpers.font('300-regular');

$border-width: 1px;

@include helpers.font('300-regular');

background-color: helpers.color('background-input');
border: $border-width solid helpers.color('border-input');
border-radius: helpers.border-radius('medium');
Expand Down
1 change: 1 addition & 0 deletions packages/core/src/mixins/index.scss
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
@forward './square';
@forward './with-inner-focus';
@forward './with-outer-focus';
@forward './wrap-if';
4 changes: 3 additions & 1 deletion packages/core/src/mixins/interactive.scss
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
@use './wrap-if' as mixins;

@mixin interactive($target: null) {
#{if($target, $target, '&')} {
@include mixins.wrap-if($target) {
cursor: pointer;
user-select: none;
}
Expand Down
3 changes: 2 additions & 1 deletion packages/core/src/mixins/with-inner-focus.scss
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
@use '../helpers';
@use './wrap-if' as mixins;

$_allowed-types: ('action', 'negative');

Expand Down Expand Up @@ -26,7 +27,7 @@ $_max-border-width: $_color-size; // when max, border used instead of color line
$inner-line: inset 0 0 0 $inner-spread helpers.color('border-focus-inner');
$color-line: inset 0 0 0 $color-spread helpers.color('border-#{$type}-focus');

#{if($target, $target, '&')} {
@include mixins.wrap-if($target) {
outline: none;
}

Expand Down
3 changes: 2 additions & 1 deletion packages/core/src/mixins/with-outer-focus.scss
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
@use '../helpers';
@use './wrap-if' as mixins;

$_allowed-types: ('action', 'negative');

Expand All @@ -14,7 +15,7 @@ $_inner-spread: $_color-spread - $_color-size;
$color-line: 0 0 0 $_color-spread helpers.color('border-#{$type}-focus');
$inner-line: 0 0 0 $_inner-spread helpers.color('border-focus-inner');

#{if($target, $target, '&')} {
@include mixins.wrap-if($target) {
outline: none;
}

Expand Down
9 changes: 9 additions & 0 deletions packages/core/src/mixins/wrap-if.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
@mixin wrap-if($selector) {
@if not $selector {
@content;
} @else {
#{$selector} {
@content;
}
}
}
5 changes: 3 additions & 2 deletions packages/core/src/theme/theme.scss
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
@use 'sass:list';
@use '../mixins';
@use './tokens' as castor;

// ...$types: 'class' | 'raw';
@mixin theme($name, $types...) {
$class: list.index($types, 'class');
$raw: list.index($types, 'raw');

$selector: if($class, '.castor-theme--#{$name}', '&');
$selector: if($class, '.castor-theme--#{$name}', null);

#{$selector} {
@include mixins.wrap-if($selector) {
@if not $raw {
@include castor.tokens();
}
Expand Down

0 comments on commit e6cc6d5

Please sign in to comment.