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


G
ge-yafang 已提交
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


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


## Creating a <stepper> Component

Create a <stepper> component in the .hml file under pages/index.

Z
zengyawen 已提交
15 16 17 18

```
<!-- index.hml -->
<div class="container"> 
G
ge-yafang 已提交
19
 <stepper>    <stepper-item>     
Z
zengyawen 已提交
20 21 22 23 24 25 26 27 28
     <text>Step 1</text>
   </stepper-item> 
   <stepper-item>     
     <text>Step 2</text>
   </stepper-item> 
 </stepper> 
</div>
```

G
ge-yafang 已提交
29

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

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

Z
zengyawen 已提交
47

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

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


```
<!-- 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>
```

G
ge-yafang 已提交
70

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

G
ge-yafang 已提交
84 85 86
![en-us_image_0000001267767837](figures/en-us_image_0000001267767837.gif)

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


```
<!-- 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>
```

G
ge-yafang 已提交
109

Z
zengyawen 已提交
110 111 112 113 114 115 116 117 118 119 120 121 122
```
/* index.css */
.container {
  flex-direction: column;
  background-color:#F1F3F5;
}
text{
  width: 100%;
  height: 100%;
  text-align: center;
}
```

G
ge-yafang 已提交
123

Z
zengyawen 已提交
124 125 126 127
```
/* index.js */
export default { 
  data: {
G
ge-yafang 已提交
128
    label_1:{      nextLabel: 'NEXT',      status: 'normal'    },
Z
zengyawen 已提交
129 130 131 132 133 134 135 136 137 138 139 140 141 142
    label_2:{
      prevLabel: 'BACK',
      nextLabel: 'NEXT',
      status: 'normal'
    },
    label_3:{
      prevLabel: 'BACK',
      nextLabel: 'END',
      status: 'disabled'
    },
  },
}
```

G
ge-yafang 已提交
143
![en-us_image_0000001267767841](figures/en-us_image_0000001267767841.gif)
Z
zengyawen 已提交
144 145


G
ge-yafang 已提交
146 147 148
## Setting the Style

  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 已提交
149 150 151 152 153 154 155 156 157 158 159 160 161 162

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

G
ge-yafang 已提交
163

Z
zengyawen 已提交
164 165 166 167 168 169 170 171 172 173 174 175 176
```
/* index.css */
.container {
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background-color:#F1F3F5;
}
.stepperContent{
  width: 300px;
  height: 300px;
}
.stepperClass{
G
ge-yafang 已提交
177
  border:1px solid silver ;  background-color: white;
Z
zengyawen 已提交
178 179 180 181 182 183 184 185
}
text{
  width: 100%;
  height: 100%;
  text-align: center;
}
```

G
ge-yafang 已提交
186
![en-us_image_0000001223287668](figures/en-us_image_0000001223287668.png)
Z
zengyawen 已提交
187 188


G
ge-yafang 已提交
189
## Adding Events
Z
zengyawen 已提交
190

G
ge-yafang 已提交
191 192 193 194 195
The &lt;stepper&gt; component supports the finish, change, next, back, and skip events.

- When the change and next or back events exist at the same time, the next or back event is executed before the change event.

- Before resetting the index attribute, you must remove the current value. Otherwise, the value change cannot be detected.
Z
zengyawen 已提交
196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217

```
<!-- 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 已提交
218

Z
zengyawen 已提交
219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244
```
/* xxx.css */
.doc-page {
  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 已提交
245

Z
zengyawen 已提交
246 247 248 249 250 251 252 253 254 255 256 257 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
```
/* 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 已提交
287 288
![en-us_image_0000001267607869](figures/en-us_image_0000001267607869.gif)

Z
zengyawen 已提交
289

G
ge-yafang 已提交
290
## Example Scenario
Z
zengyawen 已提交
291 292 293

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 已提交
294 295
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 已提交
296 297 298 299 300 301 302 303 304 305 306 307 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

```
<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>
```

G
ge-yafang 已提交
338

Z
zengyawen 已提交
339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357
```
/* xxx.css */
.container {
  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 已提交
358

Z
zengyawen 已提交
359 360 361 362 363 364 365 366 367 368 369 370 371 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
```
/* 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
  }
}
```

G
ge-yafang 已提交
401
![en-us_image_0000001267887817](figures/en-us_image_0000001267887817.gif)