ui-js-components-stepper.md 9.7 KB
Newer Older
G
ge-yafang 已提交
1
# <stepper> Development
Z
zengyawen 已提交
2 3


H
HelloCrease 已提交
4
When multiple steps are required to complete a task, you can use the **<stepper>** component to navigate your users through the whole process. For details, see [stepper](../reference/arkui-js/js-components-container-stepper.md).
Z
zengyawen 已提交
5 6


E
ester.zhou 已提交
7 8
> ![icon-note.gif](public_sys-resources/icon-note.gif) **NOTE**
>
G
ge-yafang 已提交
9 10 11 12 13
> This component is supported since API version 5.


## Creating a <stepper> Component

H
HelloCrease 已提交
14
Create a **<stepper>** component in the .hml file under **pages/index**.
G
ge-yafang 已提交
15

Z
zengyawen 已提交
16 17 18
```
<!-- index.hml -->
<div class="container"> 
E
ester.zhou 已提交
19 20
 <stepper>    
   <stepper-item>     
Z
zengyawen 已提交
21 22 23 24 25
     <text>Step 1</text>
   </stepper-item> 
   <stepper-item>     
     <text>Step 2</text>
   </stepper-item> 
E
ester.zhou 已提交
26
 </stepper> 
Z
zengyawen 已提交
27 28 29 30 31 32
</div>
```

```
/* xxx.css */
.container {
E
ester.zhou 已提交
33 34
  width:100%;
  height:100%;
Z
zengyawen 已提交
35 36 37 38 39 40 41 42 43 44 45 46
  flex-direction: column;
  justify-content: center;
  align-items: center;
  background-color: #F1F3F5;
}
text{
  width: 100%;
  height: 100%;
  text-align: center;
}
```

G
ge-yafang 已提交
47 48
![en-us_image_0000001223287656](figures/en-us_image_0000001223287656.gif)

Z
zengyawen 已提交
49

G
ge-yafang 已提交
50 51
## Setting the Index

H
HelloCrease 已提交
52
Set **index** to the index value of the step that you want to display by default.
Z
zengyawen 已提交
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74


```
<!-- index.hml -->
<div class="container"> 
 <stepper index="2">    
   <stepper-item>     
     <text>stepper-item1</text>
   </stepper-item> 
   <stepper-item>     
     <text>stepper-item2</text>
   </stepper-item> 
   <stepper-item>     
     <text>stepper-item3</text>
   </stepper-item> 
  </stepper> 
</div>
```

```
/* index.css */
.container {
E
ester.zhou 已提交
75 76
  width:100%;
  height:100%;
Z
zengyawen 已提交
77
  flex-direction: column;
E
ester.zhou 已提交
78
  background-color: #F1F3F5;
Z
zengyawen 已提交
79 80 81 82 83 84 85 86
}
text{
  width: 100%;
  height: 100%;
  text-align: center;
}
```

G
ge-yafang 已提交
87 88
![en-us_image_0000001267767837](figures/en-us_image_0000001267767837.gif)

H
HelloCrease 已提交
89
Set the **label** attribute to customize the button text for the **&lt;stepper-item&gt;**.
Z
zengyawen 已提交
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113


```
<!-- index.hml -->
<div class="container" style="background-color:#F1F3F5;"> 
 <stepper index="1">    
   <stepper-item label="{{label_1}}">     
     <text>stepper-item1</text>
   </stepper-item> 
   <stepper-item label="{{label_2}}">     
     <text>stepper-item2</text>
   </stepper-item> 
   <stepper-item label="{{label_3}}">     
     <text>stepper-item3</text>
   </stepper-item>
   <stepper-item>     
     <text>stepper-item4</text>
   </stepper-item> 
 </stepper> 
</div>
```

```
/* index.css */
E
ester.zhou 已提交
114 115 116
.container {  
  width:100%;
  height:100%;
Z
zengyawen 已提交
117
  flex-direction: column;
E
ester.zhou 已提交
118
  background-color: #F1F3F5;
Z
zengyawen 已提交
119 120 121 122 123 124 125 126
}
text{
  width: 100%;
  height: 100%;
  text-align: center;
}
```

G
ge-yafang 已提交
127

Z
zengyawen 已提交
128 129 130 131
```
/* index.js */
export default { 
  data: {
E
ester.zhou 已提交
132 133 134
    label_1:{
      nextLabel: 'NEXT',      
      status: 'normal'    
H
HelloCrease 已提交
135
    },
Z
zengyawen 已提交
136 137 138 139 140 141 142 143 144 145 146 147 148 149
    label_2:{
      prevLabel: 'BACK',
      nextLabel: 'NEXT',
      status: 'normal'
    },
    label_3:{
      prevLabel: 'BACK',
      nextLabel: 'END',
      status: 'disabled'
    },
  },
}
```

G
ge-yafang 已提交
150
![en-us_image_0000001267767841](figures/en-us_image_0000001267767841.gif)
Z
zengyawen 已提交
151 152


H
HelloCrease 已提交
153
## Setting Styles
G
ge-yafang 已提交
154

E
ester.zhou 已提交
155
By default, the **&lt;stepper&gt;** component fills entire space of its container. The sample code below shows how to set the border and background color using the **border** and **background-color** attributes.
Z
zengyawen 已提交
156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172

```
<!-- index.hml -->
<div class="container" > 
  <div class="stepperContent">
    <stepper class="stepperClass">    
      <stepper-item>     
        <text>stepper-item1</text>
      </stepper-item> 
    </stepper> 
  </div>
</div>
```

```
/* index.css */
.container {
E
ester.zhou 已提交
173 174
  width:100%;
  height:100%;
Z
zengyawen 已提交
175 176 177 178 179 180 181 182 183 184
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background-color:#F1F3F5;
}
.stepperContent{
  width: 300px;
  height: 300px;
}
.stepperClass{
E
ester.zhou 已提交
185
  border:1px solid silver ;
H
HelloCrease 已提交
186
  background-color: white;
Z
zengyawen 已提交
187 188 189 190 191 192 193 194
}
text{
  width: 100%;
  height: 100%;
  text-align: center;
}
```

G
ge-yafang 已提交
195
![en-us_image_0000001223287668](figures/en-us_image_0000001223287668.png)
Z
zengyawen 已提交
196 197


G
ge-yafang 已提交
198
## Adding Events
Z
zengyawen 已提交
199

H
HelloCrease 已提交
200
The **&lt;stepper&gt;** component supports the **finish**, **change**, **next**, **back**, and **skip** events.
G
ge-yafang 已提交
201

H
HelloCrease 已提交
202
- When the **change** and **next** or **back** events exist at the same time, the **next** or **back** event is executed before the **change** event.
G
ge-yafang 已提交
203

H
HelloCrease 已提交
204
- Before resetting the **index** attribute, you must remove the current value. Otherwise, the value change cannot be detected.
Z
zengyawen 已提交
205

H
HelloCrease 已提交
206
  
Z
zengyawen 已提交
207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227
```
<!-- index.hml -->
<div class="container"  style="background-color:#F1F3F5;">
  <div >
    <stepper onfinish="stepperFinish" onchange="stepperChange" onnext="stepperNext" onback="stepperBack" onskip="stepperSkip" id="stepperId" index="{{index}}">
      <stepper-item>
        <text>stepper-item1</text>
        <button value="skip" onclick="skipClick"></button>
      </stepper-item>
      <stepper-item>
         <text>stepper-item2</text>
         <button value="skip" onclick="skipClick"></button>
      </stepper-item>
      <stepper-item>
        <text>stepper-item3</text>
      </stepper-item>
    </stepper>
  </div>
</div>
```

G
ge-yafang 已提交
228

Z
zengyawen 已提交
229 230 231
```
/* xxx.css */
.doc-page {
E
ester.zhou 已提交
232 233
  width:100%;
  height:100%;
Z
zengyawen 已提交
234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256
  flex-direction: column;
  align-items: center;
  justify-content: center;
}
stepper-item{
  width: 100%;
  flex-direction: column;
  align-self: center;
  justify-content: center;
}
text{
  margin-top: 45%;
  justify-content: center;
  align-self: center;
  margin-bottom: 50px;
}
button{
  width: 80%;
  height: 60px;
  margin-top: 20px;
}
```

G
ge-yafang 已提交
257

Z
zengyawen 已提交
258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298
```
/* index.js */
import prompt from '@system.prompt';
export default {
  data: {
    index:0,
  },
   stepperSkip(){
    this.index = null;
    this.index=2;
  },
   skipClick(){
    this.$element('stepperId').setNextButtonStatus({status: 'skip', label: 'SKIP'});
  },
  stepperFinish(){
    prompt.showToast({
      message: 'All Finished'
    })
  },
  stepperChange(e){
    console.log("stepperChange"+e.index)
    prompt.showToast({
      message: 'Previous step: '+e.prevIndex+"-------Current step:"+e.index
    })
  },
  stepperNext(e){
    console.log("stepperNext"+e.index)
    prompt.showToast({
      message: 'Current step:'+e.index+"-------Next step:"+e.pendingIndex
    })
    var index = {pendingIndex:e.pendingIndex }
    return index;
  },
  stepperBack(e){
    console.log("stepperBack"+e.index)
    var index = {pendingIndex: e.pendingIndex }
    return index;
  }
}
```

G
ge-yafang 已提交
299 300
![en-us_image_0000001267607869](figures/en-us_image_0000001267607869.gif)

Z
zengyawen 已提交
301

G
ge-yafang 已提交
302
## Example Scenario
Z
zengyawen 已提交
303 304 305

Select the options displayed on the page. Your selection will be shown in real time. Click the next button to dynamically change the font color and font size on the page.

G
ge-yafang 已提交
306 307
Use the &lt;stepper&gt; component to navigate through the steps. Create a [&lt;toggle&gt;](../reference/arkui-js/js-components-basic-toggle.md) component to implement the functions of selection and displaying the selection result. Then use the [&lt;select&gt;](../reference/arkui-js/js-components-basic-select.md) component to dynamically change the font color or size of the selected options.

Z
zengyawen 已提交
308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352

```
<div class="container">
  <stepper id="mystep" index="0" onfinish="back" style="text-color: indigo;">
    <stepper-item label="{{label1}}">
      <div style="flex-direction: column;padding: 0px 10px;">
        <text class="text" style="margin-top: 10%;text-align: center;width: 100%;">Select error types:</text>
        <text style="margin-top: 20px;padding: 10px">
          <span>{{error}}</span>
        </text>
        <div style="justify-content: space-around;flex-wrap: wrap;">
          <toggle for="{{togglelist1}}" value="{{$item}}" class="tog" onchange="multiTog({{$item}})"></toggle>
        </div>
      </div>
    </stepper-item>
    <stepper-item label="{{label2}}">
      <div style="flex-direction: column;align-items: center;">
        <text class="txt" style="margin-top: 10%;">Toggle</text>
        <div style="justify-content: space-around;flex-wrap: wrap;;margin-top:10%">
          <toggle class="tog" for="{{togglelist1}}" value="{{$item}}" style="text-color: {{tcolor}};font-size: {{tsize}}; font-style: {{tstyle}};font-weight: {{tweight}};font-family: {{tfamily}};">
          </toggle>
        </div>
        <div style="flex-wrap: wrap;width: 700px;margin-top:10%">
          <div style="flex-direction: column;width: 350px;height: 185px;align-items: center;">
            <text class="txt">text-color</text>
            <select onchange="settcolor">
              <option for="{{color_list}}" value="{{$item}}">{{$item}}</option>
            </select>
          </div>
          <div style="flex-direction: column;width: 350px;height: 185px;align-items: center;">
            <text class="txt">font-size</text>
            <select onchange="settsize">
              <option for="{{size_list}}" value="{{$item}}">{{$item}}</option>
            </select>
          </div>
        </div>
      </div>
    </stepper-item>
  </stepper>
</div>
```

```
/* xxx.css */
.container {
E
ester.zhou 已提交
353 354
  width:100%;
  height:100%;
Z
zengyawen 已提交
355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background-color:#F1F3F5;
}
.dvd {
  stroke-width: 8px;
  color: orangered;
  margin: 65px;
}
.tog{
  margin-right: 20px;
  margin-top: 30px;
}
```

G
ge-yafang 已提交
371

Z
zengyawen 已提交
372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413
```
/* index.js */
import prompt from '@system.prompt';
import router from '@system.router';
let myset = new Set();
export default {
  data: {
    error: '',
    tcolor:'#FF4500',
    color_list:['#FF4500','#5F9EA0','#0000FF'],
    tsize: '12px',
    size_list: ['12px', '30px', '8px', '50px'],
    label1: {
      prevLabel: 'The text on the left of the starting step is invalid.',
      nextLabel: 'Toggle'
    },
    label2: {
      prevLabel: 'toggle',
      nextLabel: 'END'
    },
    togglelist1:['Program error', 'Software', 'System', 'Application'],
  },
  multiTog(arg, e) {
    this.error = ' '
    if (e.checked) {
      myset.add(arg)
    } else {
      myset.delete(arg)
    }
    for (let item of myset) {
      this.error += item + ' '
    }
  },
  settcolor(e) {
    this.tcolor = e.newValue
  },
  settsize(e) {
    this.tsize = e.newValue
  }
}
```

414
![en-us_image_0000001267887817](figures/en-us_image_0000001267887817.gif)