ts-container-panel.md 4.0 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 6
> **NOTE**
>
Z
zengyawen 已提交
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

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

None

Z
zengyawen 已提交
14 15

## Child Components
Z
zengyawen 已提交
16 17 18

This component can contain child components.

Z
zengyawen 已提交
19 20 21 22 23

## APIs

Panel(value:{show:boolean})

E
ester.zhou 已提交
24
- Parameters
25
  | Name | Type | Mandatory | Default Value | Description |
Z
zengyawen 已提交
26
  | -------- | -------- | -------- | -------- | -------- |
27
  | show | boolean | Yes | - | Whether to show or hide the panel. |
Z
zengyawen 已提交
28 29 30 31


## Attributes

E
ester.zhou 已提交
32
| Name | Type | Default Value | Description |
Z
zengyawen 已提交
33
| -------- | -------- | -------- | -------- |
E
ester.zhou 已提交
34 35
| type | PanelType | PanelType.Foldable | Type of the panel. |
| mode | PanelMode | - | Initial status of the panel. |
36
| dragBar | boolean | true | Whether to enable a drag bar. The value **true** means to display the drag bar, and **false** means the opposite. |
E
ester.zhou 已提交
37 38 39
| fullHeight | Length | - | Panel height in the **PanelMode.Full** mode. |
| halfHeight | Length | - | Panel height in the **PanelMode.Half** mode. The default value is half of the screen height. |
| miniHeight | Length | - | Panel height in the **PanelMode.Mini** mode. |
E
ester.zhou 已提交
40
| backgroundMask<sup>9+</sup>|(color: ResourceColor)| - |Background mask of the panel.|
Z
zengyawen 已提交
41 42

- PanelType enums
43
  | Name | Description |
Z
zengyawen 已提交
44
  | -------- | -------- |
45 46 47
  | Minibar | A minibar panel that displays content in the minibar area or a large (fullscreen-like) area. |
  | Foldable | A foldable panel that displays permanent content in a large (fullscreen-like), medium-sized (halfscreen-like), or small area. |
  | Temporary | A temporary panel that displays content in a large (fullscreen-like) or medium-sized (halfscreen-like) area. |
Z
zengyawen 已提交
48 49

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


## Events

E
ester.zhou 已提交
59
| Name | Description |
Z
zengyawen 已提交
60
| -------- | -------- |
E
ester.zhou 已提交
61 62
| onChange(callback: (width: number, height: number, mode: PanelMode) =&gt; void) | Triggered when the panel status changes. The returned **height** value is the height of the content area. When the value of **dragbar** is **true**, the panel height is the height of the drag bar plus the height of the content area. |
| onHeightChange(callback: (value: number) => void)<sup>9+</sup> |Triggered when the panel height changes. The returned **height** value is the height of the content area. When the value of **dragbar** is **true**, the panel height is the height of the drag bar 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 已提交
63 64 65

## Example

Z
zengyawen 已提交
66

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

  build() {
E
ester.zhou 已提交
75
    Stack() {
Z
zengyawen 已提交
76 77 78 79 80 81 82 83 84 85 86 87 88 89
      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
        })
      Panel(this.show) { // Display the agenda.
        Column() {
          Text('Today Calendar')
          Divider()
          Text('1. afternoon 4:00 The project meeting')
        }
      }
      .type(PanelType.Foldable).mode(PanelMode.Half)
90 91
      .dragBar(true) // The drag bar is enabled by default.
      .halfHeight(500) // The default value is half of the screen height.
E
ester.zhou 已提交
92 93
      .onChange((width: number, height: number, mode: PanelMode) => {
        console.info(`width:${width},height:${height},mode:${mode}`)
Z
zengyawen 已提交
94 95 96 97 98 99
      })
    }.width('100%').height('100%').backgroundColor(0xDCDCDC).padding({ top: 5 })
  }
}
```

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