Skip to content

feat(sort): show sort indicator on hover/focus/longpress #7608

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 31, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/demo-app/table/table-demo.html
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,8 @@ <h3>MatTable With MatTableDataSource Example</h3>
selected
</div>

<mat-table [dataSource]="matTableDataSource" [trackBy]="userTrackBy" matSort
<mat-table [dataSource]="matTableDataSource" [trackBy]="userTrackBy"
matSort matSortActive="progress" matSortDirection="asc"
#sortForDataSource="matSort">

<!-- Checkbox Column -->
Expand Down
2 changes: 1 addition & 1 deletion src/demo-app/table/table-demo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export class TableDemo {
displayedColumns: UserProperties[] = [];
trackByStrategy: TrackByStrategy = 'reference';
changeReferences = false;
progressSortingDisabled = false;
progressSortingDisabled = true;
highlights = new Set<string>();
wasExpanded = new Set<UserData>();

Expand Down
100 changes: 70 additions & 30 deletions src/lib/sort/sort-animations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
transition,
trigger,
keyframes,
AnimationTriggerMetadata,
AnimationTriggerMetadata, query, animateChild,
} from '@angular/animations';
import {AnimationCurves, AnimationDurations} from '@angular/material/core';

Expand All @@ -24,47 +24,87 @@ export const matSortAnimations: {
readonly indicator: AnimationTriggerMetadata;
readonly leftPointer: AnimationTriggerMetadata;
readonly rightPointer: AnimationTriggerMetadata;
readonly indicatorToggle: AnimationTriggerMetadata;
readonly arrowOpacity: AnimationTriggerMetadata;
readonly arrowPosition: AnimationTriggerMetadata;
readonly allowChildren: AnimationTriggerMetadata;
} = {
/** Animation that moves the sort indicator. */
indicator: trigger('indicator', [
state('asc', style({transform: 'translateY(0px)'})),
state('active-asc, asc', style({transform: 'translateY(0px)'})),
// 10px is the height of the sort indicator, minus the width of the pointers
state('desc', style({transform: 'translateY(10px)'})),
transition('asc <=> desc', animate(SORT_ANIMATION_TRANSITION))
state('active-desc, desc', style({transform: 'translateY(10px)'})),
transition('active-asc <=> active-desc', animate(SORT_ANIMATION_TRANSITION))
]),

/** Animation that rotates the left pointer of the indicator based on the sorting direction. */
leftPointer: trigger('leftPointer', [
state('asc', style({transform: 'rotate(-45deg)'})),
state('desc', style({transform: 'rotate(45deg)'})),
transition('asc <=> desc', animate(SORT_ANIMATION_TRANSITION))
state('active-asc, asc', style({transform: 'rotate(-45deg)'})),
state('active-desc, desc', style({transform: 'rotate(45deg)'})),
transition('active-asc <=> active-desc', animate(SORT_ANIMATION_TRANSITION))
]),

/** Animation that rotates the right pointer of the indicator based on the sorting direction. */
rightPointer: trigger('rightPointer', [
state('asc', style({transform: 'rotate(45deg)'})),
state('desc', style({transform: 'rotate(-45deg)'})),
transition('asc <=> desc', animate(SORT_ANIMATION_TRANSITION))
state('active-asc, asc', style({transform: 'rotate(45deg)'})),
state('active-desc, desc', style({transform: 'rotate(-45deg)'})),
transition('active-asc <=> active-desc', animate(SORT_ANIMATION_TRANSITION))
]),

/** Animation that moves the indicator in and out of view when sorting is enabled/disabled. */
indicatorToggle: trigger('indicatorToggle', [
transition('void => asc', animate(SORT_ANIMATION_TRANSITION, keyframes([
style({transform: 'translateY(25%)', opacity: 0}),
style({transform: 'none', opacity: 1})
]))),
transition('asc => void', animate(SORT_ANIMATION_TRANSITION, keyframes([
style({transform: 'none', opacity: 1}),
style({transform: 'translateY(-25%)', opacity: 0})
]))),
transition('void => desc', animate(SORT_ANIMATION_TRANSITION, keyframes([
style({transform: 'translateY(-25%)', opacity: 0}),
style({transform: 'none', opacity: 1})
]))),
transition('desc => void', animate(SORT_ANIMATION_TRANSITION, keyframes([
style({transform: 'none', opacity: 1}),
style({transform: 'translateY(25%)', opacity: 0})
]))),
])
/** Animation that controls the arrow opacity. */
arrowOpacity: trigger('arrowOpacity', [
state('desc-to-active, asc-to-active, active', style({opacity: 1})),
state('desc-to-hint, asc-to-hint, hint', style({opacity: .54})),
state('hint-to-desc, active-to-desc, desc, hint-to-asc, active-to-asc, asc',
style({opacity: 0})),
// Transition between all states except for immediate transitions
transition('* => asc, * => desc, * => active, * => hint', animate('0ms')),
transition('* <=> *', animate(SORT_ANIMATION_TRANSITION))
]),

/**
* Animation for the translation of the arrow as a whole. States are separated into two
* groups: ones with animations and others that are immediate. Immediate states are asc, desc,
* peek, and active. The other states define a specific animation (source-to-destination)
* and are determined as a function of their prev user-perceived state and what the next state
* should be.
*/
arrowPosition: trigger('arrowPosition', [
// Hidden Above => Hint Center
transition('* => desc-to-hint, * => desc-to-active',
animate(SORT_ANIMATION_TRANSITION, keyframes([
style({transform: 'translateY(-25%)'}),
style({transform: 'translateY(0)'})
]))),
// Hint Center => Hidden Below
transition('* => hint-to-desc, * => active-to-desc',
animate(SORT_ANIMATION_TRANSITION, keyframes([
style({transform: 'translateY(0)'}),
style({transform: 'translateY(25%)'})
]))),
// Hidden Below => Hint Center
transition('* => asc-to-hint, * => asc-to-active',
animate(SORT_ANIMATION_TRANSITION, keyframes([
style({transform: 'translateY(25%)'}),
style({transform: 'translateY(0)'})
]))),
// Hint Center => Hidden Above
transition('* => hint-to-asc, * => active-to-asc',
animate(SORT_ANIMATION_TRANSITION, keyframes([
style({transform: 'translateY(0)'}),
style({transform: 'translateY(-25%)'})
]))),
state('desc-to-hint, asc-to-hint, hint, desc-to-active, asc-to-active, active',
style({transform: 'translateY(0)'})),
state('hint-to-desc, active-to-desc, desc',
style({transform: 'translateY(-25%)'})),
state('hint-to-asc, active-to-asc, asc',
style({transform: 'translateY(25%)'})),
]),

/** Necessary trigger that calls animate on children animations. */
allowChildren: trigger('allowChildren', [
transition('* <=> *', [
query('@*', animateChild(), {optional: true})
])
]),
};
19 changes: 14 additions & 5 deletions src/lib/sort/sort-header.html
Original file line number Diff line number Diff line change
@@ -1,16 +1,25 @@
<div class="mat-sort-header-container"
[class.mat-sort-header-sorted]="_isSorted()"
[class.mat-sort-header-position-before]="arrowPosition == 'before'">
<button class="mat-sort-header-button" type="button"
[attr.disabled]="_isDisabled() || null"
[attr.aria-label]="_intl.sortButtonLabel(id)"
[attr.disabled]="_isDisabled() || null">
(focus)="_setIndicatorHintVisible(true)"
(blur)="_setIndicatorHintVisible(false)">
<ng-content></ng-content>
</button>

<div *ngIf="_isSorted()" class="mat-sort-header-arrow" [@indicatorToggle]="_sort.direction">
<!-- Disable animations while a current animation is running -->
<div class="mat-sort-header-arrow"
[@arrowOpacity]="_getArrowViewState()"
[@arrowPosition]="_getArrowViewState()"
[@allowChildren]="_getArrowDirectionState()"
(@arrowPosition.start)="_disableViewStateAnimation = true"
(@arrowPosition.done)="_disableViewStateAnimation = false">
<div class="mat-sort-header-stem"></div>
<div class="mat-sort-header-indicator" [@indicator]="_sort.direction" >
<div class="mat-sort-header-pointer-left" [@leftPointer]="_sort.direction"></div>
<div class="mat-sort-header-pointer-right" [@rightPointer]="_sort.direction"></div>
<div class="mat-sort-header-indicator" [@indicator]="_getArrowDirectionState()">
<div class="mat-sort-header-pointer-left" [@leftPointer]="_getArrowDirectionState()"></div>
<div class="mat-sort-header-pointer-right" [@rightPointer]="_getArrowDirectionState()"></div>
<div class="mat-sort-header-pointer-middle"></div>
</div>
</div>
Expand Down
4 changes: 1 addition & 3 deletions src/lib/sort/sort-header.scss
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ $mat-sort-header-arrow-container-size: 12px;
$mat-sort-header-arrow-stem-size: 10px;
$mat-sort-header-arrow-pointer-length: 6px;
$mat-sort-header-arrow-thickness: 2px;
$mat-sort-header-arrow-transition: 225ms cubic-bezier(0.4, 0, 0.2, 1);
$mat-sort-header-arrow-hint-opacity: 0.38;

.mat-sort-header-container {
display: flex;
Expand Down Expand Up @@ -60,7 +60,6 @@ $mat-sort-header-arrow-transition: 225ms cubic-bezier(0.4, 0, 0.2, 1);
position: absolute;
top: 0;
left: 0;
transition: $mat-sort-header-arrow-transition;
}

.mat-sort-header-pointer-middle {
Expand All @@ -76,7 +75,6 @@ $mat-sort-header-arrow-transition: 225ms cubic-bezier(0.4, 0, 0.2, 1);
background: currentColor;
width: $mat-sort-header-arrow-pointer-length;
height: $mat-sort-header-arrow-thickness;
transition: $mat-sort-header-arrow-transition;
position: absolute;
top: 0;
}
Expand Down
Loading