Skip to content
This repository was archived by the owner on Jan 13, 2025. It is now read-only.

Commit 79328c9

Browse files
sayriscopybara-github
authored andcommitted
refactor(tooltip): Tooltip enter/exit animation timing is moved into _tooltip-theme.scss allowing users to configure their own animation timing.
PiperOrigin-RevId: 350466445
1 parent bcff8a6 commit 79328c9

File tree

3 files changed

+43
-20
lines changed

3 files changed

+43
-20
lines changed

packages/mdc-tooltip/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,8 @@ Mixin | Description
160160
`shape-radius($radius, $rtl-reflexive)` | Sets the rounded shape to tooltip surface with given radius size. Set `$rtl-reflexive` to true to flip radius values in RTL context, defaults to false.
161161
`word-break($value, $fallbackValue)` | Sets the `word-break` property for the tooltip label. This is used to force-wrap long tooltip labels that lack spaces and hyphens. The optional $fallbackValue param can be used for IE11 as it does not support the `break-word` option. Users for IE11 who do not want their tooltip labels to be broken in the middle of the word can use this mixin to remove the default IE11 behavior of `break-all`.
162162
`z-index($z-index)` | Sets the z-index of the tooltip.
163+
`show-transition($enter-duration)` | Sets the duration for the animation that shows the tooltip.
164+
`exit-transition($exit-duration)` | Sets the duration for the animation that hides the tooltip.
163165

164166
### `MDCTooltip` Methods
165167

packages/mdc-tooltip/_tooltip-theme.scss

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,10 @@
2121
//
2222

2323
// Selector '.mdc-*' should only be used in this project.
24-
// stylelint-disable selector-class-pattern
24+
// stylelint-disable selector-class-pattern --
25+
// Internal styling for Tooltip MDC component.
2526

27+
@use '@material/animation/functions' as animation-functions;
2628
@use '@material/feature-targeting/feature-targeting';
2729
@use '@material/shape/mixins' as shape-mixins;
2830
@use '@material/theme/theme';
@@ -34,6 +36,9 @@ $background-color: rgba(black, theme-color.text-emphasis(medium));
3436
$border-radius: small;
3537
$label-color: text-primary-on-dark;
3638

39+
$enter-duration: 150ms;
40+
$exit-duration: 75ms;
41+
3742
// Rich Tooltip variables
3843
$rich-background-color: rgba(white, theme-color.text-emphasis(medium));
3944
$rich-title-text-color: text-primary-on-light;
@@ -149,3 +154,28 @@ $z-index: 2;
149154
}
150155
}
151156
}
157+
158+
// Sets the duration for the animation that shows the tooltip.
159+
// @param {Number} $enter-duration
160+
@mixin show-transition($enter-duration, $query: feature-targeting.all()) {
161+
$feat-animation: feature-targeting.create-target($query, animation);
162+
163+
@include feature-targeting.targets($feat-animation) {
164+
.mdc-tooltip--showing-transition .mdc-tooltip__surface {
165+
transition: animation-functions.enter(opacity, $enter-duration),
166+
animation-functions.enter(transform, $enter-duration);
167+
}
168+
}
169+
}
170+
171+
// Sets the duration for the animation that hides the tooltip.
172+
// @param {Number} $exit-duration
173+
@mixin hide-transition($exit-duration, $query: feature-targeting.all()) {
174+
$feat-animation: feature-targeting.create-target($query, animation);
175+
176+
@include feature-targeting.targets($feat-animation) {
177+
.mdc-tooltip--hide-transition .mdc-tooltip__surface {
178+
transition: animation-functions.exit-permanent(opacity, $exit-duration);
179+
}
180+
}
181+
}

packages/mdc-tooltip/_tooltip.scss

Lines changed: 10 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@
2121
//
2222

2323
// Selector '.mdc-*' should only be used in this project.
24-
// stylelint-disable selector-class-pattern
24+
// stylelint-disable selector-class-pattern --
25+
// Internal styling for Tooltip MDC component.
2526

26-
@use '@material/animation/functions' as animation-functions;
2727
@use '@material/elevation/mixins' as elevation-mixins;
2828
@use '@material/feature-targeting/feature-targeting';
2929
@use '@material/rtl/rtl' as rtl;
@@ -49,12 +49,8 @@ $_content-margin-x: 8px;
4949
$_content-type-scale: body1;
5050
$_title-type-scale: subtitle2;
5151

52-
$enter-duration: 150ms;
53-
$exit-duration: 75ms;
54-
5552
@mixin core-styles($query: feature-targeting.all()) {
5653
$feat-structure: feature-targeting.create-target($query, structure);
57-
$feat-animation: feature-targeting.create-target($query, animation);
5854

5955
@include tooltip-theme.shape-radius(
6056
tooltip-theme.$border-radius,
@@ -74,6 +70,14 @@ $exit-duration: 75ms;
7470
$query: $query
7571
);
7672
@include tooltip-theme.z-index(tooltip-theme.$z-index, $query: $query);
73+
@include tooltip-theme.show-transition(
74+
tooltip-theme.$enter-duration,
75+
$query: $query
76+
);
77+
@include tooltip-theme.hide-transition(
78+
tooltip-theme.$exit-duration,
79+
$query: $query
80+
);
7781

7882
.mdc-tooltip {
7983
@include feature-targeting.targets($feat-structure) {
@@ -164,25 +168,12 @@ $exit-duration: 75ms;
164168
}
165169
}
166170

167-
.mdc-tooltip--showing-transition & {
168-
@include feature-targeting.targets($feat-animation) {
169-
transition: animation-functions.enter(opacity, $enter-duration),
170-
animation-functions.enter(transform, $enter-duration);
171-
}
172-
}
173-
174171
.mdc-tooltip--hide & {
175172
@include feature-targeting.targets($feat-structure) {
176173
transform: scale(1);
177174
}
178175
}
179176

180-
.mdc-tooltip--hide-transition & {
181-
@include feature-targeting.targets($feat-animation) {
182-
transition: animation-functions.exit-permanent(opacity, $exit-duration);
183-
}
184-
}
185-
186177
.mdc-tooltip__title {
187178
@include typography.text-baseline($top: 20px, $query: $query);
188179
@include typography.typography(

0 commit comments

Comments
 (0)