ts-container-panel.md 5.2 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

E
ester.zhou 已提交
14 15 16 17
>  **NOTE**
>
>  Built-in components and custom components are allowed, with support for ([if/else](../../quick-start/arkts-rendering-control-ifelse.md), [ForEach](../../quick-start/arkts-rendering-control-foreach.md), and [LazyForEach](../../quick-start/arkts-rendering-control-lazyforeach.md)) rendering control.

Z
zengyawen 已提交
18 19 20

## APIs

E
ester.zhou 已提交
21
Panel(show: boolean)
Z
zengyawen 已提交
22

E
ester.zhou 已提交
23 24 25 26
**Parameters**

| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
E
ester.zhou 已提交
27
| show | boolean | Yes| Whether the panel is shown.<br>**NOTE**<br>The panel is hidden and does not take up space in the layout if this parameter is set to **false** or [Visible.None](ts-universal-attributes-visibility.md) is set.|
Z
zengyawen 已提交
28 29 30

## Attributes

E
ester.zhou 已提交
31 32
In addition to the [universal attributes](ts-universal-attributes-size.md), the following attributes are supported.

E
ester.zhou 已提交
33 34
| Name| Type| Description|
| -------- | -------- | -------- |
E
ester.zhou 已提交
35
| type | [PanelType](#paneltype)| Type of the panel.<br>Default value: **PanelType.Foldable**|
E
ester.zhou 已提交
36
| mode | [PanelMode](#panelmode) | Initial status of the panel.<br>Default value for the Minibar type: **PanelMode.Mini**<br/>Default value for other types: **PanelMode.Half**<br>Since API version 10, this attribute supports [$$](../../quick-start/arkts-two-way-sync.md) for two-way binding of variables. |
E
ester.zhou 已提交
37
| 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**|
E
ester.zhou 已提交
38 39 40
| fullHeight | string \| number | Panel height in the **PanelMode.Full** mode.<br>Default value: main axis height of the panel minus 8 vp<br>**NOTE**<br>This attribute cannot be set in percentage.|
| halfHeight | string \| number | Panel height in the **PanelMode.Half** mode.<br>Default value: half of the main axis height of the panel<br>**NOTE**<br>This attribute cannot be set in percentage.|
| miniHeight | string \| number | Panel height in the **PanelMode.Mini** mode.<br>Default value: **48**<br>Unit: vp<br>**NOTE**<br>This attribute cannot be set in percentage.|
E
ester.zhou 已提交
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
| 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 已提交
59 60 61

## Events

E
ester.zhou 已提交
62 63
In addition to the [universal events](ts-universal-events-click.md), the following events are supported.

E
ester.zhou 已提交
64
| Name| Description|
Z
zengyawen 已提交
65
| -------- | -------- |
E
ester.zhou 已提交
66 67
| 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 panel height is the sum of the drag bar height and content area height.|
| onHeightChange(callback: (value: number) => void)<sup>9+</sup> |Triggered when the height of the panel changes. The returned height value is the height of the content area, in px by default. When the value of **dragBar** is **true**, the panel height is the sum of the drag bar height and content area height. For user experience purposes, the panel can be slid to only this height: **fullHeight** - 8 vp.|
Z
zengyawen 已提交
68 69 70

## Example

E
ester.zhou 已提交
71 72
```ts
// xxx.ets
Z
zengyawen 已提交
73 74 75 76 77 78
@Entry
@Component
struct PanelExample {
  @State show: boolean = false

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

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