Skip to content

Commit

Permalink
refactor: use param to toggle host context / root context (#544)
Browse files Browse the repository at this point in the history
  • Loading branch information
davidlj95 authored May 21, 2024
1 parent 1cf386c commit c305690
Show file tree
Hide file tree
Showing 19 changed files with 41 additions and 41 deletions.
2 changes: 1 addition & 1 deletion src/app/header/header.component.scss
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ header {
@include borders.panel(bottom);
background-color: var(--app-color-toolbar-background);

@include animations.when-motion-host-context {
@include animations.when-motion {
@include animations.multiple-transitions(
(background-color, border-color),
animations.$emphasized-style
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ button {
}
}

@include animations.when-motion-host-context {
@include animations.when-motion {
@include animations.single-transition(color, animations.$emphasized-style);
}

Expand Down
2 changes: 1 addition & 1 deletion src/app/header/tab/tab.component.scss
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
}
}

@include animations.when-motion-host-context {
@include animations.when-motion {
@include animations.multiple-transitions(
(border-bottom-color, color),
animations.$emphasized-style
Expand Down
4 changes: 2 additions & 2 deletions src/app/resume-page/attribute/attribute.component.scss
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
cursor: pointer;
color: var(--ui-text);

@include animations.when-motion-host-context {
@include animations.when-motion {
@include animations.single-transition(color);
}

Expand All @@ -29,7 +29,7 @@
visibility: hidden;
right: 150%;
opacity: 0;
@include animations.when-motion-host-context {
@include animations.when-motion {
@include animations.multiple-transitions(
(right, opacity, visibility, background-color, color, border-color),
animations.$emphasized-style
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
:host {
font-size: 1rem;
color: var(--ui-text);
@include animations.when-motion-host-context {
@include animations.when-motion {
@include animations.single-transition(color, animations.$emphasized-style);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
img {
border-radius: card-header-image.$size;
filter: var(--img-filter);
@include animations.when-motion-host-context {
@include animations.when-motion {
@include animations.single-transition(filter, animations.$emphasized-style);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
font-size: 1.15rem;
color: var(--ui-text);

@include animations.when-motion-host-context {
@include animations.when-motion {
@include animations.single-transition(color, animations.$emphasized-style);
}
}
2 changes: 1 addition & 1 deletion src/app/resume-page/card/card.component.scss
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
@include borders.panel;
background-color: var(--sys-color-surface1);

@include animations.when-motion-host-context {
@include animations.when-motion {
@include animations.multiple-transitions(
(background-color, border-color),
animations.$emphasized-style
Expand Down
2 changes: 1 addition & 1 deletion src/app/resume-page/chip/chip.component.scss
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
color: var(--sys-color-on-surface);
border-color: var(--adorner-border-color);

@include animations.when-motion-host-context {
@include animations.when-motion {
@include animations.multiple-transitions(
(background-color, color, border-color),
animations.$emphasized-style
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
padding: paddings.$s;
background-color: var(--sys-color-surface3);

@include animations.when-motion-host-context {
@include animations.when-motion {
@include animations.multiple-transitions(
(background-color, border-color),
animations.$emphasized-style
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ code {
font-weight: bold;
font-size: math.div(3 * card-header-image.$size, 8);

@include animations.when-motion-host-context {
@include animations.when-motion {
@include animations.multiple-transitions(
(background-color),
animations.$emphasized-style
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ li {
&:hover {
color: var(--sys-color-on-surface);
}
@include animations.when-motion-host-context {
@include animations.when-motion {
@include animations.single-transition(
color,
animations.$emphasized-style
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ img {
border-color: var(--sys-color-divider);
filter: var(--img-filter);

@include animations.when-motion-host-context {
@include animations.when-motion {
transition: animations.transition(opacity),
animations.transition(visibility),
animations.transition(filter, animations.$emphasized-style),
Expand Down Expand Up @@ -78,7 +78,7 @@ img {
padding: paddings.$s;
border-radius: paddings.$s;

@include animations.when-motion-host-context {
@include animations.when-motion {
@include animations.multiple-transitions((opacity, visibility));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
background-color: var(--app-color-toolbar-background);
color: var(--ui-text);

@include animations.when-motion-host-context {
@include animations.when-motion {
@include animations.multiple-transitions(
(color, background-color, border-color),
animations.$emphasized-style
Expand Down
4 changes: 2 additions & 2 deletions src/app/sports-page/sports-page.component.scss
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@
@include texts.page;

img.sports-equation {
@include theming.when-dark-mode-host-context {
@include theming.when-dark-mode {
filter: invert(1);
}
@include animations.when-motion-host-context {
@include animations.when-motion {
@include animations.single-transition(filter, animations.$emphasized-style);
}
}
Expand Down
19 changes: 3 additions & 16 deletions src/sass/_animations.scss
Original file line number Diff line number Diff line change
Expand Up @@ -53,23 +53,10 @@ $emphasized-style: (

$_reduced-motion-attribute-selector: '[data-reduced-motion]';
$_no-reduced-motion-selector: ':not(#{$_reduced-motion-attribute-selector})';
@mixin when-motion-host-context() {
@include root-attribute.host-context($_no-reduced-motion-selector) {
@include no-reduced-motion-preference {
@mixin when-motion($hostContext: true) {
@include root-attribute.context($_no-reduced-motion-selector, $hostContext) {
@media (prefers-reduced-motion: no-preference) {
@content;
}
}
}
@mixin when-motion() {
@include root-attribute.context($_no-reduced-motion-selector) {
@include no-reduced-motion-preference {
@content;
}
}
}

@mixin no-reduced-motion-preference() {
@media (prefers-reduced-motion: no-preference) {
@content;
}
}
6 changes: 3 additions & 3 deletions src/sass/_theming.scss
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,11 @@

$_no-color-scheme-attribute-selector: ':not([data-color-scheme])';
$_dark-mode-attribute-selector: '[data-color-scheme="dark"]';
@mixin when-dark-mode-host-context {
@include root-attribute.host-context($_dark-mode-attribute-selector) {
@mixin when-dark-mode {
@include root-attribute.context($_dark-mode-attribute-selector) {
@content;
}
@include root-attribute.host-context($_no-color-scheme-attribute-selector) {
@include root-attribute.context($_no-color-scheme-attribute-selector) {
@media (prefers-color-scheme: dark) {
@content;
}
Expand Down
17 changes: 15 additions & 2 deletions src/sass/helpers/_root-attribute.scss
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,20 @@
@use 'sass:string';

$_root-selector: 'html'; // could use :root 🤷
@mixin host-context($attributeSelector) {

@mixin context($attributeSelector, $hostContext: true) {
@if ($hostContext) {
@include _host-context($attributeSelector) {
@content;
}
} @else {
@include _root-context($attributeSelector) {
@content;
}
}
}

@mixin _host-context($attributeSelector) {
@at-root {
// 👇 Angular adds [_nghost-ng-g4rb4g3] when using :host-context(selector) twice to:
// - Match selector in host: `selector:host`
Expand All @@ -24,7 +37,7 @@ $_root-selector: 'html'; // could use :root 🤷
}
}

@mixin context($attributeSelector) {
@mixin _root-context($attributeSelector) {
@at-root {
#{selector.nest(_root-attribute-selector($attributeSelector), &)} {
@content;
Expand Down
4 changes: 2 additions & 2 deletions src/styles.scss
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ body {
// Do not allow scroll "bounce" effect
overscroll-behavior: none;

@include animations.when-motion {
@include animations.when-motion($hostContext: false) {
@include animations.multiple-transitions(
(color, background-color),
animations.$emphasized-style
Expand All @@ -51,7 +51,7 @@ a {
text-decoration-line: underline;
text-decoration-thickness: 1px;

@include animations.when-motion {
@include animations.when-motion($hostContext: false) {
@include animations.multiple-transitions(
(color, text-decoration-color),
animations.$emphasized-style
Expand Down

0 comments on commit c305690

Please sign in to comment.