ts-container-alphabet-indexer.md 4.0 KB
Newer Older
Z
zengyawen 已提交
1
# AlphabetIndexer
Z
zengyawen 已提交
2

Z
zengyawen 已提交
3

E
esterzhou 已提交
4
> ![icon-note.gif](public_sys-resources/icon-note.gif) **NOTE**
Z
zengyawen 已提交
5
> This component is supported since API version 7. Updates will be marked with a superscript to indicate their earliest API version.
Z
zengyawen 已提交
6 7


Z
zengyawen 已提交
8
The **<AlphabetIndexer>** component provides an alphabetic index bar.
Z
zengyawen 已提交
9

Z
zengyawen 已提交
10 11

## Required Permissions
Z
zengyawen 已提交
12 13 14

None

Z
zengyawen 已提交
15 16

## Child Components
Z
zengyawen 已提交
17 18 19 20

None


Z
zengyawen 已提交
21
## APIs
Z
zengyawen 已提交
22

Z
zengyawen 已提交
23
AlphabetIndexer(value: {arrayValue : Array<string>, selected : number})
Z
zengyawen 已提交
24

Z
zengyawen 已提交
25
- Parameters
E
esterzhou 已提交
26
    | Name | Type | Mandatory | Default Value | Description | 
Z
zengyawen 已提交
27
  | -------- | -------- | -------- | -------- | -------- |
E
esterzhou 已提交
28 29
  | arrayValue | Array<string> | Yes | - | Array of strings to be displayed in the alphabetic index bar. | 
  | selected | number | Yes | - | ID of a selected item. | 
Z
zengyawen 已提交
30 31


Z
zengyawen 已提交
32
## Attributes
Z
zengyawen 已提交
33

Z
zengyawen 已提交
34 35
  | Name | Type | Description | 
| -------- | -------- | -------- |
E
esterzhou 已提交
36 37 38 39 40 41 42 43 44 45
| selectedColor | Color | Font color of the selected text. | 
| popupColor | Color | Font color of the pop-up text. | 
| selectedBackgroundColor | Color | Background color of the selected text. | 
| popupBackground | Color | Background color of the pop-up text. | 
| usingPopup | boolean | Whether to use pop-up text. | 
| selectedFont | {<br/>size?: number,<br/>weight?: FontWeight,<br/>family?: string,<br/>style?: FontStyle<br/>} | Font style of the selected text. | 
| popupFont | {<br/>size?: number,<br/>weight?: FontWeight,<br/>family?: string,<br/>style?: FontStyle<br/>} | Font style of the pop-up text. | 
| font | {<br/>size?: number,<br/>weight?: FontWeight,<br/>family?: string,<br/>style?: FontStyle<br/>} | Default font style of the alphabetic index bar. | 
| itemSize | Length | Size of an item in the alphabetic index bar. The item is a square, and the side length needs to be set. | 
| alignStyle | IndexerAlign | Alignment style of the alphabetic index bar. Left alignment and right alignment are supported. The alignment style affects the position of the pop-up window. | 
Z
zengyawen 已提交
46

Z
zengyawen 已提交
47 48 49
- IndexerAlign enums
    | Name | Description | 
  | -------- | -------- |
E
esterzhou 已提交
50 51
  | Left | The pop-up window is displayed on the right of the alphabetic indexer bar. | 
  | Right | The pop-up window is displayed on the left of the alphabetic indexer bar. | 
Z
zengyawen 已提交
52 53


Z
zengyawen 已提交
54
## Events
Z
zengyawen 已提交
55

Z
zengyawen 已提交
56 57
  | Name | Description | 
| -------- | -------- |
E
esterzhou 已提交
58 59 60
| onSelected(index: number) =&gt; void | Callback invoked when an item in the alphabetic indexer bar is selected. | 
| onRequestPopupData(callback: (index: number) =&gt; Array&lt;string&gt;)<sup>8+</sup> | Invoked when a request for displaying content in the index prompt window is sent when an item in the alphabetic indexer bar is selected.<br/>The return value is a string array corresponding to the indexes. The string array is displayed vertically in the pop-up window. It can display up to five strings at a time and allows scrolling. | 
| onPopupSelected(callback: (index: number) =&gt; void)<sup>8+</sup> | Invoked when an item in the index pop-up window is selected. | 
Z
zengyawen 已提交
61 62


Z
zengyawen 已提交
63
## Example
Z
zengyawen 已提交
64

Z
zengyawen 已提交
65
  
Z
zengyawen 已提交
66 67 68
```
@Entry
@Component
Z
zengyawen 已提交
69
struct AlphabetIndexerSample {
Z
zengyawen 已提交
70 71 72
  private value: string[] = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z']

  build() {
Z
zengyawen 已提交
73
    AlphabetIndexer({ arrayValue: this.value, selected: 0 })
Z
zengyawen 已提交
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90
      .selectedColor(0xffffff) // Font color of the selected text
      .popupColor(0xFFFAF0) // Font color of the pop-up text
      .selectedBackgroundColor(0xCCCCCC) // Background color of the selected text
      .popupBackground(0xD2B48C) // Background color of the pop-up text
      .usingPopup(true) // Whether to use pop-up text
      .selectedFont({ size: 16, weight: FontWeight.Bolder }) // Font style of the selected text
      .popupFont({ size: 30, weight: FontWeight.Bolder }) // Font style of the pop-up text
      .itemSize(28) // Size of each item (square)
      .alignStyle(IndexerAlign.Left) // Left aligned
      .onSelected((index: number) => {
        console.info(this.value[index] + 'Selected') // Event indicating that an item is selected
      })
      .margin({ left: 50 })
  }
}
```

Z
zengyawen 已提交
91
![en-us_image_0000001212378392](figures/en-us_image_0000001212378392.gif)