Skip to content

Commit 6fa9e6f

Browse files
andrewseguinjelbourn
authored andcommitted
fix(sort): reverse directions and better animation (#6802)
1 parent 86ec493 commit 6fa9e6f

File tree

3 files changed

+58
-21
lines changed

3 files changed

+58
-21
lines changed

src/lib/sort/sort-header.html

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,13 @@
55
<ng-content></ng-content>
66
</button>
77

8-
<div *ngIf="_isSorted()"
9-
class="mat-sort-header-arrow"
10-
[@indicatorRotate]="_sort.direction">
8+
<div *ngIf="_isSorted()" class="mat-sort-header-arrow">
119
<div class="mat-sort-header-stem"></div>
12-
<div class="mat-sort-header-pointer-left"></div>
13-
<div class="mat-sort-header-pointer-right"></div>
10+
<div class="mat-sort-header-indicator" [@indicator]="_sort.direction" >
11+
<div class="mat-sort-header-pointer-left" [@leftPointer]="_sort.direction"></div>
12+
<div class="mat-sort-header-pointer-right" [@rightPointer]="_sort.direction"></div>
13+
<div class="mat-sort-header-pointer-middle"></div>
14+
</div>
1415
</div>
1516
</div>
1617

src/lib/sort/sort-header.scss

Lines changed: 35 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
$mat-sort-header-arrow-margin: 6px;
2-
$mat-sort-header-arrow-container-size: 10px;
3-
$mat-sort-header-arrow-pointer-length: 8px;
2+
$mat-sort-header-arrow-container-size: 12px;
3+
$mat-sort-header-arrow-stem-size: 10px;
4+
$mat-sort-header-arrow-pointer-length: 6px;
45
$mat-sort-header-arrow-thickness: 2px;
6+
$mat-sort-header-arrow-transition: 225ms cubic-bezier(0.4, 0, 0.2, 1);
57

68
.mat-sort-header-container {
79
display: flex;
@@ -27,9 +29,9 @@ $mat-sort-header-arrow-thickness: 2px;
2729
.mat-sort-header-arrow {
2830
height: $mat-sort-header-arrow-container-size;
2931
width: $mat-sort-header-arrow-container-size;
30-
position: relative;
3132
margin: 0 0 0 $mat-sort-header-arrow-margin;
32-
transform: rotate(45deg);
33+
position: relative;
34+
display: flex;
3335

3436
.mat-sort-header-position-before & {
3537
margin: 0 $mat-sort-header-arrow-margin 0 0;
@@ -38,26 +40,46 @@ $mat-sort-header-arrow-thickness: 2px;
3840

3941
.mat-sort-header-stem {
4042
background: currentColor;
41-
transform: rotate(135deg);
42-
height: $mat-sort-header-arrow-container-size;
43+
height: $mat-sort-header-arrow-stem-size;
4344
width: $mat-sort-header-arrow-thickness;
4445
margin: auto;
46+
display: flex;
47+
align-items: center;
4548
}
4649

47-
.mat-sort-header-pointer-left {
48-
background: currentColor;
49-
width: $mat-sort-header-arrow-thickness;
50-
height: $mat-sort-header-arrow-pointer-length;
50+
.mat-sort-header-indicator {
51+
width: 100%;
52+
height: $mat-sort-header-arrow-thickness;
53+
display: flex;
54+
align-items: center;
5155
position: absolute;
52-
bottom: 0;
53-
right: 0;
56+
top: 0;
57+
transition: $mat-sort-header-arrow-transition;
5458
}
5559

60+
.mat-sort-header-pointer-middle {
61+
margin: auto;
62+
height: $mat-sort-header-arrow-thickness;
63+
width: $mat-sort-header-arrow-thickness;
64+
background: currentColor;
65+
transform: rotate(45deg);
66+
}
67+
68+
.mat-sort-header-pointer-left,
5669
.mat-sort-header-pointer-right {
5770
background: currentColor;
5871
width: $mat-sort-header-arrow-pointer-length;
5972
height: $mat-sort-header-arrow-thickness;
73+
transition: $mat-sort-header-arrow-transition;
6074
position: absolute;
61-
bottom: 0;
75+
}
76+
77+
.mat-sort-header-pointer-left {
78+
transform-origin: right;
79+
left: 0;
80+
}
81+
82+
.mat-sort-header-pointer-right {
83+
transform-origin: left;
6284
right: 0;
6385
}

src/lib/sort/sort-header.ts

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,10 @@ import {merge} from 'rxjs/observable/merge';
2828
import {MdSort, MdSortable} from './sort';
2929
import {MdSortHeaderIntl} from './sort-header-intl';
3030
import {getMdSortHeaderNotContainedWithinMdSortError} from './sort-errors';
31+
import {AnimationCurves, AnimationDurations} from '../core/animation/animation';
3132

33+
const SORT_ANIMATION_TRANSITION =
34+
AnimationDurations.ENTERING + ' ' + AnimationCurves.STANDARD_CURVE;
3235

3336
/**
3437
* Applies sorting behavior (click to change sort) and styles to an element, including an
@@ -51,10 +54,21 @@ import {getMdSortHeaderNotContainedWithinMdSortError} from './sort-errors';
5154
encapsulation: ViewEncapsulation.None,
5255
changeDetection: ChangeDetectionStrategy.OnPush,
5356
animations: [
54-
trigger('indicatorRotate', [
57+
trigger('indicator', [
58+
state('asc', style({transform: 'translateY(0px)'})),
59+
// 10px is the height of the sort indicator, minus the width of the pointers
60+
state('desc', style({transform: 'translateY(10px)'})),
61+
transition('asc <=> desc', animate(SORT_ANIMATION_TRANSITION))
62+
]),
63+
trigger('leftPointer', [
64+
state('asc', style({transform: 'rotate(-45deg)'})),
65+
state('desc', style({transform: 'rotate(45deg)'})),
66+
transition('asc <=> desc', animate(SORT_ANIMATION_TRANSITION))
67+
]),
68+
trigger('rightPointer', [
5569
state('asc', style({transform: 'rotate(45deg)'})),
56-
state('desc', style({transform: 'rotate(225deg)'})),
57-
transition('asc <=> desc', animate('225ms cubic-bezier(0.4, 0.0, 0.2, 1)'))
70+
state('desc', style({transform: 'rotate(-45deg)'})),
71+
transition('asc <=> desc', animate(SORT_ANIMATION_TRANSITION))
5872
])
5973
]
6074
})

0 commit comments

Comments
 (0)