forked from NG-ZORRO/ng-zorro-antd
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(module:slider): refactor (NG-ZORRO#4730)
* chore(module:slider): refactor slider fix: test fix: remove redundant code feat(module:slider): support change value through keyboard event test: add test chore: hide internal implementation fix: fix import path fix: fix import path fix(module:slider): fix property type close NG-ZORRO#4749 chore(module:slider): refactor slider fix: test fix: remove redundant code feat(module:slider): support change value through keyboard event test: add test chore: hide internal implementation fix: fix import path fix: fix import path fix(module:slider): fix property type close NG-ZORRO#4749 * fix: fix no step situation
- Loading branch information
Showing
17 changed files
with
694 additions
and
637 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 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,117 @@ | ||
/** | ||
* @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, Component, Input, OnChanges, SimpleChanges, ViewEncapsulation } from '@angular/core'; | ||
|
||
import { InputBoolean, NgStyleInterface } from 'ng-zorro-antd/core'; | ||
|
||
import { NzDisplayedMark, NzExtendedMark, NzMark, NzMarkObj } from './typings'; | ||
|
||
@Component({ | ||
changeDetection: ChangeDetectionStrategy.OnPush, | ||
encapsulation: ViewEncapsulation.None, | ||
preserveWhitespaces: false, | ||
selector: 'nz-slider-marks', | ||
exportAs: 'nzSliderMarks', | ||
template: ` | ||
<div class="ant-slider-mark"> | ||
<span | ||
class="ant-slider-mark-text" | ||
*ngFor="let attr of marks; trackBy: trackById" | ||
[class.ant-slider-mark-active]="attr.active" | ||
[ngStyle]="attr.style" | ||
[innerHTML]="attr.label" | ||
> | ||
</span> | ||
</div> | ||
` | ||
}) | ||
export class NzSliderMarksComponent implements OnChanges { | ||
@Input() lowerBound: number | null = null; | ||
@Input() upperBound: number | null = null; | ||
@Input() marksArray: NzExtendedMark[]; | ||
@Input() min: number; | ||
@Input() max: number; | ||
@Input() @InputBoolean() vertical = false; | ||
@Input() @InputBoolean() included = false; | ||
|
||
marks: NzDisplayedMark[]; | ||
|
||
ngOnChanges(changes: SimpleChanges): void { | ||
const { marksArray, lowerBound, upperBound } = changes; | ||
|
||
if (marksArray) { | ||
this.buildMarks(); | ||
} | ||
|
||
if (marksArray || lowerBound || upperBound) { | ||
this.togglePointActive(); | ||
} | ||
} | ||
|
||
trackById(_index: number, mark: NzDisplayedMark): number { | ||
return mark.value; | ||
} | ||
|
||
private buildMarks(): void { | ||
const range = this.max - this.min; | ||
|
||
this.marks = this.marksArray.map(mark => { | ||
const { value, offset, config } = mark; | ||
const style = this.getMarkStyles(value, range, config); | ||
const label = isConfigObject(config) ? config.label : config; | ||
|
||
return { | ||
label, | ||
offset, | ||
style, | ||
value, | ||
config, | ||
active: false | ||
}; | ||
}); | ||
} | ||
|
||
private getMarkStyles(value: number, range: number, config: NzMark): NgStyleInterface { | ||
let style; | ||
|
||
if (this.vertical) { | ||
style = { | ||
marginBottom: '-50%', | ||
bottom: `${((value - this.min) / range) * 100}%` | ||
}; | ||
} else { | ||
style = { | ||
transform: `translate3d(-50%, 0, 0)`, | ||
left: `${((value - this.min) / range) * 100}%` | ||
}; | ||
} | ||
|
||
if (isConfigObject(config) && config.style) { | ||
style = { ...style, ...config.style }; | ||
} | ||
|
||
return style; | ||
} | ||
|
||
private togglePointActive(): void { | ||
if (this.marks && this.lowerBound !== null && this.upperBound !== null) { | ||
this.marks.forEach(mark => { | ||
const value = mark.value; | ||
const isActive = | ||
(!this.included && value === this.upperBound) || (this.included && value <= this.upperBound! && value >= this.lowerBound!); | ||
|
||
mark.active = isActive; | ||
}); | ||
} | ||
} | ||
} | ||
|
||
function isConfigObject(config: NzMark): config is NzMarkObj { | ||
return typeof config !== 'string'; | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.