@@ -12,7 +12,7 @@ import {
12
12
transition ,
13
13
trigger ,
14
14
keyframes ,
15
- AnimationTriggerMetadata ,
15
+ AnimationTriggerMetadata , query , animateChild ,
16
16
} from '@angular/animations' ;
17
17
import { AnimationCurves , AnimationDurations } from '@angular/material/core' ;
18
18
@@ -24,47 +24,87 @@ export const matSortAnimations: {
24
24
readonly indicator : AnimationTriggerMetadata ;
25
25
readonly leftPointer : AnimationTriggerMetadata ;
26
26
readonly rightPointer : AnimationTriggerMetadata ;
27
- readonly indicatorToggle : AnimationTriggerMetadata ;
27
+ readonly arrowOpacity : AnimationTriggerMetadata ;
28
+ readonly arrowPosition : AnimationTriggerMetadata ;
29
+ readonly allowChildren : AnimationTriggerMetadata ;
28
30
} = {
29
31
/** Animation that moves the sort indicator. */
30
32
indicator : trigger ( 'indicator' , [
31
- state ( 'asc' , style ( { transform : 'translateY(0px)' } ) ) ,
33
+ state ( 'active-asc, asc' , style ( { transform : 'translateY(0px)' } ) ) ,
32
34
// 10px is the height of the sort indicator, minus the width of the pointers
33
- state ( 'desc' , style ( { transform : 'translateY(10px)' } ) ) ,
34
- transition ( 'asc <=> desc' , animate ( SORT_ANIMATION_TRANSITION ) )
35
+ state ( 'active-desc, desc' , style ( { transform : 'translateY(10px)' } ) ) ,
36
+ transition ( 'active- asc <=> active- desc' , animate ( SORT_ANIMATION_TRANSITION ) )
35
37
] ) ,
36
38
37
39
/** Animation that rotates the left pointer of the indicator based on the sorting direction. */
38
40
leftPointer : trigger ( 'leftPointer' , [
39
- state ( 'asc' , style ( { transform : 'rotate(-45deg)' } ) ) ,
40
- state ( 'desc' , style ( { transform : 'rotate(45deg)' } ) ) ,
41
- transition ( 'asc <=> desc' , animate ( SORT_ANIMATION_TRANSITION ) )
41
+ state ( 'active-asc, asc' , style ( { transform : 'rotate(-45deg)' } ) ) ,
42
+ state ( 'active-desc, desc' , style ( { transform : 'rotate(45deg)' } ) ) ,
43
+ transition ( 'active- asc <=> active- desc' , animate ( SORT_ANIMATION_TRANSITION ) )
42
44
] ) ,
43
45
44
46
/** Animation that rotates the right pointer of the indicator based on the sorting direction. */
45
47
rightPointer : trigger ( 'rightPointer' , [
46
- state ( 'asc' , style ( { transform : 'rotate(45deg)' } ) ) ,
47
- state ( 'desc' , style ( { transform : 'rotate(-45deg)' } ) ) ,
48
- transition ( 'asc <=> desc' , animate ( SORT_ANIMATION_TRANSITION ) )
48
+ state ( 'active-asc, asc' , style ( { transform : 'rotate(45deg)' } ) ) ,
49
+ state ( 'active-desc, desc' , style ( { transform : 'rotate(-45deg)' } ) ) ,
50
+ transition ( 'active- asc <=> active- desc' , animate ( SORT_ANIMATION_TRANSITION ) )
49
51
] ) ,
50
52
51
- /** Animation that moves the indicator in and out of view when sorting is enabled/disabled. */
52
- indicatorToggle : trigger ( 'indicatorToggle' , [
53
- transition ( 'void => asc' , animate ( SORT_ANIMATION_TRANSITION , keyframes ( [
54
- style ( { transform : 'translateY(25%)' , opacity : 0 } ) ,
55
- style ( { transform : 'none' , opacity : 1 } )
56
- ] ) ) ) ,
57
- transition ( 'asc => void' , animate ( SORT_ANIMATION_TRANSITION , keyframes ( [
58
- style ( { transform : 'none' , opacity : 1 } ) ,
59
- style ( { transform : 'translateY(-25%)' , opacity : 0 } )
60
- ] ) ) ) ,
61
- transition ( 'void => desc' , animate ( SORT_ANIMATION_TRANSITION , keyframes ( [
62
- style ( { transform : 'translateY(-25%)' , opacity : 0 } ) ,
63
- style ( { transform : 'none' , opacity : 1 } )
64
- ] ) ) ) ,
65
- transition ( 'desc => void' , animate ( SORT_ANIMATION_TRANSITION , keyframes ( [
66
- style ( { transform : 'none' , opacity : 1 } ) ,
67
- style ( { transform : 'translateY(25%)' , opacity : 0 } )
68
- ] ) ) ) ,
69
- ] )
53
+ /** Animation that controls the arrow opacity. */
54
+ arrowOpacity : trigger ( 'arrowOpacity' , [
55
+ state ( 'desc-to-active, asc-to-active, active' , style ( { opacity : 1 } ) ) ,
56
+ state ( 'desc-to-hint, asc-to-hint, hint' , style ( { opacity : .54 } ) ) ,
57
+ state ( 'hint-to-desc, active-to-desc, desc, hint-to-asc, active-to-asc, asc' ,
58
+ style ( { opacity : 0 } ) ) ,
59
+ // Transition between all states except for immediate transitions
60
+ transition ( '* => asc, * => desc, * => active, * => hint' , animate ( '0ms' ) ) ,
61
+ transition ( '* <=> *' , animate ( SORT_ANIMATION_TRANSITION ) )
62
+ ] ) ,
63
+
64
+ /**
65
+ * Animation for the translation of the arrow as a whole. States are separated into two
66
+ * groups: ones with animations and others that are immediate. Immediate states are asc, desc,
67
+ * peek, and active. The other states define a specific animation (source-to-destination)
68
+ * and are determined as a function of their prev user-perceived state and what the next state
69
+ * should be.
70
+ */
71
+ arrowPosition : trigger ( 'arrowPosition' , [
72
+ // Hidden Above => Hint Center
73
+ transition ( '* => desc-to-hint, * => desc-to-active' ,
74
+ animate ( SORT_ANIMATION_TRANSITION , keyframes ( [
75
+ style ( { transform : 'translateY(-25%)' } ) ,
76
+ style ( { transform : 'translateY(0)' } )
77
+ ] ) ) ) ,
78
+ // Hint Center => Hidden Below
79
+ transition ( '* => hint-to-desc, * => active-to-desc' ,
80
+ animate ( SORT_ANIMATION_TRANSITION , keyframes ( [
81
+ style ( { transform : 'translateY(0)' } ) ,
82
+ style ( { transform : 'translateY(25%)' } )
83
+ ] ) ) ) ,
84
+ // Hidden Below => Hint Center
85
+ transition ( '* => asc-to-hint, * => asc-to-active' ,
86
+ animate ( SORT_ANIMATION_TRANSITION , keyframes ( [
87
+ style ( { transform : 'translateY(25%)' } ) ,
88
+ style ( { transform : 'translateY(0)' } )
89
+ ] ) ) ) ,
90
+ // Hint Center => Hidden Above
91
+ transition ( '* => hint-to-asc, * => active-to-asc' ,
92
+ animate ( SORT_ANIMATION_TRANSITION , keyframes ( [
93
+ style ( { transform : 'translateY(0)' } ) ,
94
+ style ( { transform : 'translateY(-25%)' } )
95
+ ] ) ) ) ,
96
+ state ( 'desc-to-hint, asc-to-hint, hint, desc-to-active, asc-to-active, active' ,
97
+ style ( { transform : 'translateY(0)' } ) ) ,
98
+ state ( 'hint-to-desc, active-to-desc, desc' ,
99
+ style ( { transform : 'translateY(-25%)' } ) ) ,
100
+ state ( 'hint-to-asc, active-to-asc, asc' ,
101
+ style ( { transform : 'translateY(25%)' } ) ) ,
102
+ ] ) ,
103
+
104
+ /** Necessary trigger that calls animate on children animations. */
105
+ allowChildren : trigger ( 'allowChildren' , [
106
+ transition ( '* <=> *' , [
107
+ query ( '@*' , animateChild ( ) , { optional : true } )
108
+ ] )
109
+ ] ) ,
70
110
} ;
0 commit comments