-
Notifications
You must be signed in to change notification settings - Fork 4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(module:timeline): fix reverse bug (#4690)
* fix(module:timeline): fix reverse bug * fix: fix test * chore: cleanup code * fix: some consts * test: refactor test close #4509
- Loading branch information
Wendell
authored
Feb 28, 2020
1 parent
ca02a07
commit 09bf8f4
Showing
10 changed files
with
291 additions
and
294 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
/** | ||
* @license | ||
* Copyright Alibaba.com All Rights Reserved. | ||
* | ||
* Use of this source code is governed by an MIT-style license that can be | ||
* found in the LICENSE file at https://github.com/NG-ZORRO/ng-zorro-antd/blob/master/LICENSE | ||
*/ | ||
|
||
import { | ||
ChangeDetectionStrategy, | ||
ChangeDetectorRef, | ||
Component, | ||
Input, | ||
OnChanges, | ||
SimpleChanges, | ||
TemplateRef, | ||
ViewChild, | ||
ViewEncapsulation | ||
} from '@angular/core'; | ||
|
||
import { NzTimelineMode } from './timeline.component'; | ||
|
||
const TimelineTimeDefaultColors = ['red', 'blue', 'green', 'grey', 'gray'] as const; | ||
export type NzTimelineItemColor = typeof TimelineTimeDefaultColors[number]; | ||
|
||
function isDefaultColor(color?: string): boolean { | ||
return TimelineTimeDefaultColors.findIndex(i => i === color) !== -1; | ||
} | ||
|
||
@Component({ | ||
changeDetection: ChangeDetectionStrategy.OnPush, | ||
encapsulation: ViewEncapsulation.None, | ||
preserveWhitespaces: false, | ||
selector: 'nz-timeline-item, [nz-timeline-item]', | ||
exportAs: 'nzTimelineItem', | ||
template: ` | ||
<ng-template #template> | ||
<li | ||
class="ant-timeline-item" | ||
[class.ant-timeline-item-right]="position === 'right'" | ||
[class.ant-timeline-item-left]="position === 'left'" | ||
[class.ant-timeline-item-last]="isLast" | ||
> | ||
<div class="ant-timeline-item-tail"></div> | ||
<div | ||
class="ant-timeline-item-head" | ||
[class.ant-timeline-item-head-red]="nzColor === 'red'" | ||
[class.ant-timeline-item-head-blue]="nzColor === 'blue'" | ||
[class.ant-timeline-item-head-green]="nzColor === 'green'" | ||
[class.ant-timeline-item-head-gray]="nzColor === 'gray'" | ||
[class.ant-timeline-item-head-custom]="!!nzDot" | ||
[style.border-color]="borderColor" | ||
> | ||
<ng-container *nzStringTemplateOutlet="nzDot">{{ nzDot }}</ng-container> | ||
</div> | ||
<div class="ant-timeline-item-content"> | ||
<ng-content></ng-content> | ||
</div> | ||
</li> | ||
</ng-template> | ||
` | ||
}) | ||
export class NzTimelineItemComponent implements OnChanges { | ||
@ViewChild('template', { static: false }) template: TemplateRef<void>; | ||
|
||
@Input() nzColor: NzTimelineItemColor = 'blue'; | ||
@Input() nzDot: string | TemplateRef<void>; | ||
|
||
isLast = false; | ||
borderColor: string | null = null; | ||
position: NzTimelineMode | undefined; | ||
|
||
constructor(private cdr: ChangeDetectorRef) {} | ||
|
||
ngOnChanges(changes: SimpleChanges): void { | ||
if (changes.nzColor) { | ||
this.updateCustomColor(); | ||
} | ||
} | ||
|
||
detectChanges(): void { | ||
this.cdr.detectChanges(); | ||
} | ||
|
||
private updateCustomColor(): void { | ||
this.borderColor = isDefaultColor(this.nzColor) ? null : this.nzColor; | ||
} | ||
} |
Oops, something went wrong.