ts-basic-components-stepper.md 3.6 KB
Newer Older
Z
zengyawen 已提交
1 2
# Stepper

3
The **\<Stepper>** component provides a step navigator.
Z
zengyawen 已提交
4 5


E
ester.zhou 已提交
6 7 8
>  **NOTE**
>
>  This component is supported since API version 8. Updates will be marked with a superscript to indicate their earliest API version.
Z
zengyawen 已提交
9 10 11 12


## Child Components

13
Only the child component **\<[StepperItem](ts-basic-components-stepperitem.md)>** is supported.
Z
zengyawen 已提交
14 15 16 17 18 19


## APIs

Stepper(value?: { index?: number })

E
ester.zhou 已提交
20 21 22 23
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| index | number | No| Index of the **\<StepperItem>** that is currently displayed.<br>Default value: **0** |
Z
zengyawen 已提交
24 25 26 27 28 29 30 31 32


## Attributes

None


## Events

E
ester.zhou 已提交
33
| Name| Description|
Z
zengyawen 已提交
34
| -------- | -------- |
35 36
| onFinish(callback: () =&gt; void) | Invoked when the **nextLabel** of the last **\<StepperItem>** in the **\<Stepper>** is clicked. |
| onSkip(callback: () =&gt; void) | Invoked when the current **\<StepperItem>** is **ItemState.Skip** and the **nextLabel** is clicked. |
E
ester.zhou 已提交
37 38 39
| onChange(callback: (prevIndex?: number, index?: number) =&gt; void) | Invoked when the text button on the left or right is clicked to switch between steps.<br>- **prevIndex**: index of the step page before the switching.<br>- **index**: index of the step page after the switching, that is, index of the previous or next page. |
| onNext(callback: (index?: number, pendingIndex?: number) =&gt; void) | Invoked when a user switches to the next step.<br>- **index**: index of the current step page.<br>- **pendingIndex**: index of the next page. |
| onPrevious(callback: (index?: number, pendingIndex?: number) =&gt; void) | Invoked when a user switches to the previous step.<br>- **index**: index of the current step page.<br>- **pendingIndex**: index of the previous page. |
Z
zengyawen 已提交
40 41 42 43


## Example

44 45
```ts
// xxx.ets
Z
zengyawen 已提交
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
@Entry
@Component
struct StepperExample {
  @State currentIndex: number = 0
  @State firstState: ItemState = ItemState.Normal
  @State secondState: ItemState = ItemState.Normal

  build() {
    Stepper({
      index: this.currentIndex
    }) {
      StepperItem() {
        Text('Page One')
          .fontSize(35)
          .fontColor(Color.Blue)
          .width(200)
          .lineHeight(50)
63
          .margin({ top: 250 })
Z
zengyawen 已提交
64 65
      }
      .nextLabel('')
66 67
      .position({ x: '35%', y: 0 })

Z
zengyawen 已提交
68 69 70 71 72 73
      StepperItem() {
        Text('Page Two')
          .fontSize(35)
          .fontColor(Color.Blue)
          .width(200)
          .lineHeight(50)
74 75
          .margin({ top: 250 })
          .onClick(() => {
Z
zengyawen 已提交
76 77 78 79 80 81
            this.firstState = this.firstState === ItemState.Skip ? ItemState.Normal : ItemState.Skip
          })
      }
      .nextLabel('Next')
      .prevLabel('Previous')
      .status(this.firstState)
82 83
      .position({ x: '35%', y: 0 })

Z
zengyawen 已提交
84 85 86 87 88 89
      StepperItem() {
        Text('Page Three')
          .fontSize(35)
          .fontColor(Color.Blue)
          .width(200)
          .lineHeight(50)
90 91
          .margin({ top: 250 })
          .onClick(() => {
Z
zengyawen 已提交
92 93 94
            this.secondState = this.secondState === ItemState.Waiting ? ItemState.Normal : ItemState.Waiting
          })
      }
95
      .position({ x: '35%', y: 0 })
Z
zengyawen 已提交
96
      .status(this.secondState)
97

Z
zengyawen 已提交
98 99 100 101 102 103
      StepperItem() {
        Text('Page four')
          .fontSize(35)
          .fontColor(Color.Blue)
          .width(200)
          .lineHeight(50)
104
          .margin({ top: 250 })
Z
zengyawen 已提交
105
      }
106
      .position({ x: '35%', y: 0 })
Z
zengyawen 已提交
107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124
      .nextLabel('Finish')
    }
    .onFinish(() => {
      console.log('onFinish')
    })
    .onSkip(() => {
      console.log('onSkip')
    })
    .onChange((prevIndex: number, index: number) => {
      this.currentIndex = index
    })
    .align(Alignment.Center)
  }
}
```


![en-us_image_0000001250678457](figures/en-us_image_0000001250678457.gif)