Skip to content
This repository was archived by the owner on Nov 30, 2022. It is now read-only.

Commit aefeeaf

Browse files
committed
feat(stepper): add helper functions
* closeFirst, closeLast * openFirst, openLast * completeAndCloseStep
1 parent 1d3ae0f commit aefeeaf

3 files changed

Lines changed: 54 additions & 12 deletions

File tree

projects/core/src/lib/step-content/step-content.component.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,12 @@
1-
import { Component, OnInit, ViewChild, Input, Output, EventEmitter, ChangeDetectorRef } from '@angular/core';
1+
import {
2+
Component,
3+
OnInit,
4+
ViewChild,
5+
Input,
6+
Output,
7+
EventEmitter,
8+
ChangeDetectorRef
9+
} from '@angular/core';
210
import { FivStepHeader } from '../step-header/step-header.component';
311
import { FivExpandable } from '../expandable/expandable.component';
412

@@ -35,7 +43,11 @@ export class FivStepContent implements OnInit {
3543
close() {
3644
this.isOpen = false;
3745
this.change.detectChanges();
46+
}
3847

48+
completeAndClose() {
49+
this.close();
50+
this.complete();
3951
}
4052

4153
complete() {

projects/core/src/lib/stepper/stepper.component.ts

Lines changed: 29 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -29,26 +29,34 @@ export class FivStepper implements OnInit {
2929
open(index: number) {
3030
if (this.mode === 'horizontal') {
3131
this.currentIndex = index;
32-
console.log('+#+#+');
32+
// console.log('+#+#+');
3333
this.horizontal.open(index);
3434
} else {
35-
console.log('###open', this.steps, this.steps.toArray(), index, this.steps.toArray()[index]);
35+
// console.log('###open', this.steps, this.steps.toArray(), index, this.steps.toArray()[index]);
3636
if (this.steps.toArray()[index]) {
3737
if (this.steps.toArray()[index].isOpen) {
38-
console.log('is already open', this.steps.toArray()[index].isOpen);
38+
// console.log('is already open', this.steps.toArray()[index].isOpen);
3939
this.close(index);
4040
} else {
41-
console.log('is closed', this.steps.toArray()[index].isOpen);
41+
// console.log('is closed', this.steps.toArray()[index].isOpen);
4242
this.currentIndex = index;
4343
this.steps.toArray()[index].open();
4444
}
4545
} else {
46-
console.log('####', index, this.steps, this.steps.toArray());
46+
// console.log('####', index, this.steps, this.steps.toArray());
4747
}
4848

4949
}
5050
}
5151

52+
openFirst() {
53+
this.open(0);
54+
}
55+
56+
openLast() {
57+
this.open(this.steps.toArray().length - 1);
58+
}
59+
5260
close(index: number, param?: any) {
5361
this.param = param;
5462
if (this.mode === 'horizontal') {
@@ -58,15 +66,21 @@ export class FivStepper implements OnInit {
5866
this.currentIndex = - 1;
5967
this.steps.toArray()[index].close();
6068
}
69+
}
70+
71+
closeFirst() {
72+
this.close(0);
73+
}
6174

75+
closeLast() {
76+
this.close(this.steps.toArray().length - 1);
6277
}
6378

6479
select(index: number) {
65-
console.log('select', index);
80+
// console.log('select', index);
6681
if (index >= 0 && index < this.contents.length) {
6782
if (this.mode === 'vertical') {
6883
this.closeAll();
69-
7084
}
7185
this.open(index);
7286
}
@@ -85,23 +99,28 @@ export class FivStepper implements OnInit {
8599

86100
next() {
87101
const next = this.currentIndex < this.steps.length ? this.currentIndex + 1 : -1;
88-
console.log('next index', next);
102+
// console.log('next index', next);
89103
this.select(next);
90104
}
91105

92106
previous() {
93107
const next = this.currentIndex > 0 ? this.currentIndex + -1 : -1;
94-
console.log('next index', next);
95108
this.select(next);
96109
}
97110

98111
completeStep(index: number) {
99112
if (this.mode === 'horizontal') {
100113
// not yet impletented
101-
102114
} else {
103115
this.steps.toArray()[index].complete();
116+
}
117+
}
104118

119+
completeAndCloseStep(index: number) {
120+
if (this.mode === 'horizontal') {
121+
// not yet impletented
122+
} else {
123+
this.steps.toArray()[index].completeAndClose();
105124
}
106125
}
107126

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
import { Component, OnInit } from '@angular/core';
1+
import { FivStepper } from './../../../../projects/core/src/lib/stepper/stepper.component';
2+
import { Component, OnInit, ViewChild } from '@angular/core';
3+
import { timer } from 'rxjs';
24

35
@Component({
46
selector: 'app-stepper',
@@ -7,9 +9,18 @@ import { Component, OnInit } from '@angular/core';
79
})
810
export class StepperPage implements OnInit {
911

12+
@ViewChild('stepperV') stepperV: FivStepper;
13+
1014
constructor() { }
1115

1216
ngOnInit() {
17+
18+
}
19+
20+
ionViewDidEnter() {
21+
// this.stepperV.openLast();
22+
23+
// timer(1000).subscribe(() => this.stepperV.closeLast());
1324
}
1425

1526
}

0 commit comments

Comments
 (0)