Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(typography): treat :host selector the same as :root #65

Merged
merged 2 commits into from
Feb 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions sass/typography/_mixins.scss
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,9 @@
/// @example scss
/// @include typography('Roboto', $my-type-scale);
@mixin typography($font-family, $type-scale) {
$scope: if(is-root(), ':root', '&');
$root: is-root();
$host: is-host();
$scope: if($root, ':root', '&');

#{$scope} {
--ig-font-family: #{string.unquote($font-family)};
Expand All @@ -121,7 +123,7 @@
}
}

@if is-root() {
@if $root or $host {
.ig-typography {
@include type-style-elements();
@include type-style-classes();
Expand Down
19 changes: 18 additions & 1 deletion sass/utils/_meta.scss
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
@use 'sass:selector';

/// Returns true if the scope where it's called is the root of the document.
/// @access private
/// @example scss Check if the current scope is root
Expand All @@ -11,6 +13,21 @@
/// @return {Boolean} - Returns a boolean depending on the scope where it's called
@function is-root() {
@each $selector in & {
@return if($selector == null, true, false);
@return $selector == null;
}
}

/// Returns true if the scope where it's called is :host.
/// @access private
/// @example scss Check if the current scope is :root
/// @mixin smart-mixin() {
/// $host: is-host();
///
/// @if is-host() {
/// /* style rules here */
/// }
/// }
/// @return {Boolean} - Returns a boolean depending on the scope where it's called
@function is-host() {
@return not(is-root()) and selector.is-superselector(':host', &);
}
29 changes: 29 additions & 0 deletions test/_utils.spec.scss
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,35 @@
}
}
}

@include it('should resolve if the call context is :host') {
@include assert() {
@include output($selector: false) {
// called from the :host
:host {
$is-host: is-host();

content: $is-host;
}
}

@include expect($selector: false) {
:host {
content: true;
}
}
}

@include assert() {
@include output($selector: true) {
content: is-root();
}

@include expect($selector: true) {
content: false;
}
}
}
}

@include describe('map') {
Expand Down