Skip to content

Commit

Permalink
feat(sort): add sorting indicator animation (angular#5831)
Browse files Browse the repository at this point in the history
  • Loading branch information
yhorbachov authored and jelbourn committed Aug 30, 2017
1 parent 950edcc commit 70bd5fc
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 15 deletions.
3 changes: 1 addition & 2 deletions src/lib/sort/sort-header.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@

<div *ngIf="_isSorted()"
class="mat-sort-header-arrow"
[class.mat-sort-header-asc]="_sort.direction == 'asc'"
[class.mat-sort-header-desc]="_sort.direction == 'desc'">
[@indicatorRotate]="_sort.direction">
<div class="mat-sort-header-stem"></div>
<div class="mat-sort-header-pointer-left"></div>
<div class="mat-sort-header-pointer-right"></div>
Expand Down
13 changes: 1 addition & 12 deletions src/lib/sort/sort-header.scss
Original file line number Diff line number Diff line change
Expand Up @@ -25,28 +25,17 @@ $mat-sort-header-arrow-thickness: 2px;
}

.mat-sort-header-arrow {
display: none;
height: $mat-sort-header-arrow-container-size;
width: $mat-sort-header-arrow-container-size;
position: relative;
margin: 0 0 0 $mat-sort-header-arrow-margin;
transform: rotate(45deg);

.mat-sort-header-position-before & {
margin: 0 $mat-sort-header-arrow-margin 0 0;
}
}

.mat-sort-header-asc {
display: block;
transform: rotate(45deg);
}

.mat-sort-header-desc {
display: block;
transform: rotate(225deg);
top: $mat-sort-header-arrow-thickness;
}

.mat-sort-header-stem {
background: currentColor;
transform: rotate(135deg);
Expand Down
15 changes: 15 additions & 0 deletions src/lib/sort/sort-header.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,21 @@ import {
ViewEncapsulation
} from '@angular/core';
import {coerceBooleanProperty} from '@angular/cdk/coercion';
import {
trigger,
state,
style,
animate,
transition
} from '@angular/animations';
import {CdkColumnDef} from '@angular/cdk/table';
import {Subscription} from 'rxjs/Subscription';
import {merge} from 'rxjs/observable/merge';
import {MdSort, MdSortable} from './sort';
import {MdSortHeaderIntl} from './sort-header-intl';
import {getMdSortHeaderNotContainedWithinMdSortError} from './sort-errors';


/**
* Applies sorting behavior (click to change sort) and styles to an element, including an
* arrow to display the current sort direction.
Expand All @@ -42,6 +50,13 @@ import {getMdSortHeaderNotContainedWithinMdSortError} from './sort-errors';
},
encapsulation: ViewEncapsulation.None,
changeDetection: ChangeDetectionStrategy.OnPush,
animations: [
trigger('indicatorRotate', [
state('asc', style({transform: 'rotate(45deg)'})),
state('desc', style({transform: 'rotate(225deg)'})),
transition('asc <=> desc', animate('225ms cubic-bezier(0.4, 0.0, 0.2, 1)'))
])
]
})
export class MdSortHeader implements MdSortable {
private _rerenderSubscription: Subscription;
Expand Down
3 changes: 2 additions & 1 deletion src/lib/sort/sort.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {async, ComponentFixture, TestBed, inject} from '@angular/core/testing';
import {Component, ElementRef, ViewChild} from '@angular/core';
import {By} from '@angular/platform-browser';
import {NoopAnimationsModule} from '@angular/platform-browser/animations';
import {MdSort, MdSortHeader, Sort, SortDirection, MdSortModule, MdSortHeaderIntl} from './index';
import {DataSource, CollectionViewer} from '@angular/cdk/collections';
import {CdkTableModule} from '@angular/cdk/table';
Expand All @@ -21,7 +22,7 @@ describe('MdSort', () => {

beforeEach(async(() => {
TestBed.configureTestingModule({
imports: [MdSortModule, MdTableModule, CdkTableModule],
imports: [MdSortModule, MdTableModule, CdkTableModule, NoopAnimationsModule],
declarations: [
SimpleMdSortApp,
CdkTableMdSortApp,
Expand Down

0 comments on commit 70bd5fc

Please sign in to comment.