ts-container-panel.md 3.9 KB
Newer Older
Z
zengyawen 已提交
1
# Panel
Z
zengyawen 已提交
2

E
ester.zhou 已提交
3
The **<Panel\>** component is a slidable panel that presents lightweight content with flexible sizes.
Z
zengyawen 已提交
4

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

Z
zengyawen 已提交
9 10

## Child Components
Z
zengyawen 已提交
11

E
ester.zhou 已提交
12
Supported
Z
zengyawen 已提交
13

Z
zengyawen 已提交
14 15 16

## APIs

E
ester.zhou 已提交
17
Panel(show: boolean)
Z
zengyawen 已提交
18

E
ester.zhou 已提交
19 20 21 22 23
**Parameters**

| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| show | boolean | Yes| Whether the panel is shown or hidden.|
Z
zengyawen 已提交
24 25 26 27


## Attributes

E
ester.zhou 已提交
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
| Name| Type| Description|
| -------- | -------- | -------- |
| type | PanelType | Type of the panel.<br>Default value: **PanelType.Foldable**|
| mode | PanelMode | Initial status of the panel.|
| dragBar | boolean | Whether to enable a drag bar. The value **true** means that the drag bar will be displayed, and **false** means the opposite.<br>Default value: **true**|
| fullHeight | string \| number | Panel height in the **PanelMode.Full** mode.|
| halfHeight | string \| number | Panel height in the **PanelMode.Half** mode. The default value is half of the screen height.|
| miniHeight | string \| number | Panel height in the **PanelMode.Mini** mode.|
| show | boolean | Whether to show the panel.|
| backgroundMask<sup>9+</sup>|[ResourceColor](ts-types.md#resourcecolor)|Background mask of the panel.|

## PanelType

| Name| Description|
| -------- | -------- |
| Minibar | A minibar panel displays content in the minibar area or a large (fullscreen-like) area.|
| Foldable | A foldable panel displays permanent content in a large (fullscreen-like), medium-sized (halfscreen-like), or small area.|
| Temporary | A temporary panel displays content in a large (fullscreen-like) or medium-sized (halfscreen-like) area.|

## PanelMode

| Name| Description|
| -------- | -------- |
| Mini | Displays a **minibar** or **foldable** panel in its minimum size. This attribute does not take effect for **temporary** panels.|
| Half | Displays a **foldable** or **temporary** panel in a medium-sized (halfscreen-like) area. This attribute does not take effect for **minibar** panels.|
| Full | Displays a panel in a large (fullscreen-like) area.|
Z
zengyawen 已提交
54 55 56 57


## Events

E
ester.zhou 已提交
58
| Name| Description|
Z
zengyawen 已提交
59
| -------- | -------- |
E
ester.zhou 已提交
60 61
| onChange(event: (width: number, height: number, mode: PanelMode) =&gt; void) | Triggered when the status of the panel changes. The returned height value is the height of the content area. When the value of **dragBar** is **true**, the height of the panel is the **dragBar** height plus the height of the content area.|
| onHeightChange(callback: (value: number) => void)<sup>9+</sup> |Triggered when the status of the panel changes. The returned height value is the height of the content area. When the value of **dragBar** is **true**, the height of the panel is the **dragBar** height plus the height of the content area. For user experience purposes, the panel can be slid to only this height: **fullHeight** - 8 vp.|
Z
zengyawen 已提交
62 63 64

## Example

E
ester.zhou 已提交
65 66
```ts
// xxx.ets
Z
zengyawen 已提交
67 68 69 70 71 72
@Entry
@Component
struct PanelExample {
  @State show: boolean = false

  build() {
E
ester.zhou 已提交
73
    Stack() {
Z
zengyawen 已提交
74 75 76 77 78 79
      Text('2021-09-30    Today Calendar: 1.afternoon......Click for details')
        .width('90%').height(50).borderRadius(10)
        .backgroundColor(0xFFFFFF).padding({ left: 20 })
        .onClick(() => {
          this.show = !this.show
        })
E
ester.zhou 已提交
80
            Panel(this.show) { // Display the agenda.
Z
zengyawen 已提交
81 82 83 84 85 86 87
        Column() {
          Text('Today Calendar')
          Divider()
          Text('1. afternoon 4:00 The project meeting')
        }
      }
      .type(PanelType.Foldable).mode(PanelMode.Half)
E
ester.zhou 已提交
88 89
      .dragBar(true) // The dragbar is enabled by default.
      .halfHeight(500) // The panel height is half of the screen height by default.
E
ester.zhou 已提交
90 91
      .onChange((width: number, height: number, mode: PanelMode) => {
        console.info(`width:${width},height:${height},mode:${mode}`)
Z
zengyawen 已提交
92 93 94 95 96 97
      })
    }.width('100%').height('100%').backgroundColor(0xDCDCDC).padding({ top: 5 })
  }
}
```

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