Browse Source

Add stepper.ts

pull/1206/head
Hironsan 3 years ago
parent
commit
ee87ae539f
1 changed files with 48 additions and 0 deletions
  1. 48
      frontend/models/stepper.ts

48
frontend/models/stepper.ts

@ -0,0 +1,48 @@
export class StepCounter {
private step: number
constructor(
private readonly minStep: number = 1,
private readonly maxStep: number = 10
) {
this.step = 1
}
static valueOf(
minStep: number = 1, maxStep: number = 10
): StepCounter {
return new StepCounter(minStep, maxStep)
}
get count(): number {
return this.step
}
set count(val: number) {
this.step = val
}
next(): void {
this.step = Math.min(this.step + 1, this.maxStep)
}
prev(): void {
this.step = Math.max(this.step - 1, this.minStep)
}
hasNext(): boolean {
return this.step !== this.maxStep
}
hasPrev(): boolean {
return this.step !== this.minStep
}
isFirst(): boolean {
return this.step === this.minStep
}
isLast(): boolean {
return this.step === this.maxStep
}
}
Loading…
Cancel
Save