Skip to content

Commit 4872d08

Browse files
Reduce motion for press effect (#2758)
* pressEffect mixin * apply pressEffect mixin
1 parent 3ade963 commit 4872d08

File tree

6 files changed

+39
-23
lines changed

6 files changed

+39
-23
lines changed

src/components/buttons/_buttons.scss

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ $largeButtonSize: componentSize(l);
1919

2020
.sg-button {
2121
@include applyFocus();
22+
@include applyPressEffect();
2223

2324
position: relative;
2425
display: inline-flex;
@@ -36,26 +37,17 @@ $largeButtonSize: componentSize(l);
3637
color: $white;
3738
text-transform: uppercase;
3839
padding: 0 20px;
39-
will-change: background-color, border-color;
40-
transition-property: background-color, border-color;
41-
transition-duration: 0.2s;
42-
transition-timing-function: ease-in-out;
4340
box-sizing: border-box;
4441
touch-action: manipulation;
4542
-webkit-user-select: none;
4643
-webkit-tap-highlight-color: rgba(0, 0, 0, 0);
4744
user-select: none;
48-
transition: transform $durationModerate2 $easingRegular;
4945
cursor: default;
5046

5147
&[href] {
5248
cursor: pointer;
5349
}
5450

55-
&:active:not([disabled]) {
56-
transform: scale(0.96);
57-
}
58-
5951
&:disabled {
6052
@media (forced-colors: active) {
6153
color: GrayText;
@@ -401,6 +393,7 @@ $largeButtonSize: componentSize(l);
401393
&--icon-only {
402394
padding: 0;
403395
width: $mediumButtonSize;
396+
--pressScale: 0.92;
404397

405398
&.sg-button--s {
406399
width: $smallButtonSize;
@@ -429,10 +422,6 @@ $largeButtonSize: componentSize(l);
429422
clip: rect(0, 0, 0, 0);
430423
border: none;
431424
}
432-
433-
&:active:not([disabled]) {
434-
transform: scale(0.92);
435-
}
436425
}
437426

438427
@media (forced-colors: active) {

src/components/buttons/_buttons_lite.scss

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
.sg-button-lite {
2+
@include applyPressEffect();
3+
24
// color variables
35
--button-lite-solid-background-color: transparent;
46
--button-lite-hover-background-color: var(--gray-50);
@@ -20,7 +22,6 @@
2022
justify-content: center;
2123
align-items: center;
2224
color: var(--button-lite-label-color);
23-
transition: transform $durationModerate2 $easingRegular;
2425
touch-action: manipulation;
2526
-webkit-user-select: none;
2627
-webkit-tap-highlight-color: rgba(0, 0, 0, 0);
@@ -80,8 +81,6 @@
8081
}
8182

8283
&:active {
83-
transform: scale(0.96);
84-
8584
&::before {
8685
background: var(--button-lite-active-background-color);
8786
opacity: 0.2;

src/components/chip/_chip.scss

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
user-select: none;
1111

1212
&__input {
13+
@include applyPressEffect('+ .sg-chip__pill');
14+
1315
width: 100%;
1416
height: 100%;
1517
z-index: 1;
@@ -77,7 +79,6 @@
7779

7880
&:active + .sg-chip__pill {
7981
background-color: rgba($gray-40, 0.2);
80-
transform: scale(0.96);
8182
}
8283
}
8384
}
@@ -94,7 +95,7 @@
9495
border-radius: var(--border-radius-xs);
9596
transition: box-shadow $durationQuick1 $easingExit,
9697
border-color $durationModerate1 $easingLinear,
97-
transform $durationModerate2 $easingRegular,
98+
transform var(--pressTransitionDuration) var(--pressTransitionEasing),
9899
background-color $durationModerate1 $easingLinear;
99100

100101
@media (forced-colors: active) {

src/components/select-menu/_select-menu.scss

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,8 @@
292292
}
293293

294294
&__option {
295+
@include applyPressEffect();
296+
295297
padding: 8px 12px;
296298
width: 100%;
297299
display: flex;
@@ -301,11 +303,7 @@
301303
border-radius: var(--border-radius-xs);
302304
cursor: default;
303305
transition: background-color $durationModerate1 $easingLinear,
304-
transform $durationModerate2 $easingRegular;
305-
306-
&:active:not([disabled]) {
307-
transform: scale(0.96);
308-
}
306+
transform var(--pressTransitionDuration) var(--pressTransitionEasing);
309307

310308
&:hover {
311309
background-color: var(--gray-10);

src/sass/_basics.scss

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,13 @@ $includeHtml: false !default;
3636
--focusInnerWidth: 2px;
3737
--focusOuterWidth: 2px;
3838

39+
--pressTransitionDuration: #{$durationModerate2};
40+
--pressTransitionEasing: #{$easingRegular};
41+
--pressScale: 0.96;
42+
@media (prefers-reduced-motion) {
43+
--pressScale: 1;
44+
}
45+
3946
-webkit-font-smoothing: antialiased;
4047
-moz-osx-font-smoothing: grayscale;
4148

src/sass/_mixins.scss

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,3 +151,25 @@
151151
@mixin sgButtonHoverMix($color1, $color2, $percent) {
152152
background-color: mix($color1, $color2, $percent);
153153
}
154+
155+
@mixin applyPressEffect($nestingSelector: null) {
156+
@if ($nestingSelector) {
157+
& #{$nestingSelector} {
158+
transition-property: transform;
159+
transition-duration: var(--pressTransitionDuration);
160+
transition-timing-function: var(--pressTransitionEasing);
161+
}
162+
163+
&:active:not([disabled]) #{$nestingSelector} {
164+
transform: scale(var(--pressScale));
165+
}
166+
} @else {
167+
transition-property: transform;
168+
transition-duration: var(--pressTransitionDuration);
169+
transition-timing-function: var(--pressTransitionEasing);
170+
171+
&:active:not([disabled]) {
172+
transform: scale(var(--pressScale));
173+
}
174+
}
175+
}

0 commit comments

Comments
 (0)