1e41f4b71Sopenharmony_ci# Popup 2e41f4b71Sopenharmony_ci 3e41f4b71Sopenharmony_ciThe popup component is used to display popups in a specific style. 4e41f4b71Sopenharmony_ci 5e41f4b71Sopenharmony_ci> **NOTE** 6e41f4b71Sopenharmony_ci> 7e41f4b71Sopenharmony_ci> - This component is supported since API version 11. Updates will be marked with a superscript to indicate their earliest API version. 8e41f4b71Sopenharmony_ci> 9e41f4b71Sopenharmony_ci> - Use this component with the custom popup features in [popup control](ts-universal-attributes-popup.md) for best results. 10e41f4b71Sopenharmony_ci 11e41f4b71Sopenharmony_ci## Modules to Import 12e41f4b71Sopenharmony_ci 13e41f4b71Sopenharmony_ci``` 14e41f4b71Sopenharmony_ciimport { Popup, PopupOptions, PopupTextOptions, PopupButtonOptions, PopupIconOptions } from '@kit.ArkUI'; 15e41f4b71Sopenharmony_ci``` 16e41f4b71Sopenharmony_ci 17e41f4b71Sopenharmony_ci## Child Components 18e41f4b71Sopenharmony_ci 19e41f4b71Sopenharmony_ciNot supported 20e41f4b71Sopenharmony_ci 21e41f4b71Sopenharmony_ci## Popup 22e41f4b71Sopenharmony_ci 23e41f4b71Sopenharmony_ciPopup(options: PopupOptions) 24e41f4b71Sopenharmony_ci 25e41f4b71Sopenharmony_ci**Decorator**: @Builder 26e41f4b71Sopenharmony_ci 27e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12. 28e41f4b71Sopenharmony_ci 29e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full 30e41f4b71Sopenharmony_ci 31e41f4b71Sopenharmony_ci**Parameters** 32e41f4b71Sopenharmony_ci 33e41f4b71Sopenharmony_ci| Name | Type | Mandatory| Description | 34e41f4b71Sopenharmony_ci| ------- | ----------------------------- | ---- | --------------------- | 35e41f4b71Sopenharmony_ci| options | [PopupOptions](#popupoptions) | Yes | Parameters of the popup.| 36e41f4b71Sopenharmony_ci 37e41f4b71Sopenharmony_ci## PopupOptions 38e41f4b71Sopenharmony_ci 39e41f4b71Sopenharmony_ciDefines the style parameters of the popup. 40e41f4b71Sopenharmony_ci 41e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12. 42e41f4b71Sopenharmony_ci 43e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full 44e41f4b71Sopenharmony_ci 45e41f4b71Sopenharmony_ci| Name | Type | Mandatory | Description | 46e41f4b71Sopenharmony_ci| ----------- | ---------- | ------| --------------------------------- | 47e41f4b71Sopenharmony_ci| icon | [PopupIconOptions](#popupiconoptions) | No | Icon of the popup.<br>**NOTE**<br>The icon is not displayed when **size** is set to an invalid value or **0**.| 48e41f4b71Sopenharmony_ci| title | [PopupTextOptions](#popuptextoptions) | No | Title of the popup. | 49e41f4b71Sopenharmony_ci| message | [PopupTextOptions](#popuptextoptions) | Yes | Content of the popup.<br>**NOTE**<br>**fontWeight** is not available for **messages**.| 50e41f4b71Sopenharmony_ci| showClose | boolean \| [Resource](ts-types.md#resource) | No | Whether to show the close button.<br>Default value: **true**| 51e41f4b71Sopenharmony_ci| onClose | () => void | No | Callback for the popup close button.| 52e41f4b71Sopenharmony_ci| buttons | [[PopupButtonOptions](#popupbuttonoptions)?,[PopupButtonOptions](#popupbuttonoptions)?] | No | Buttons of the popup. A maximum of two buttons can be set.| 53e41f4b71Sopenharmony_ci| direction<sup>12+</sup> | [Direction](ts-appendix-enums.md#direction) | No | Layout direction.<br>Default value: **Direction.Auto** | 54e41f4b71Sopenharmony_ci 55e41f4b71Sopenharmony_ci## PopupTextOptions 56e41f4b71Sopenharmony_ci 57e41f4b71Sopenharmony_ciDefines the text parameters of the popup. 58e41f4b71Sopenharmony_ci 59e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12. 60e41f4b71Sopenharmony_ci 61e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full 62e41f4b71Sopenharmony_ci 63e41f4b71Sopenharmony_ci| Name | Type | Mandatory| Description | 64e41f4b71Sopenharmony_ci| ---------- | ------------------------------------------------------------ | ---- | ------------------ | 65e41f4b71Sopenharmony_ci| text | [ResourceStr](ts-types.md#resourcestr) | Yes | Text content. | 66e41f4b71Sopenharmony_ci| fontSize | number \| string \| [Resource](ts-types.md#resource) | No | Text font size.<br>Default value: **$r('sys.float.ohos_id_text_size_body2')** | 67e41f4b71Sopenharmony_ci| fontColor | [ResourceColor](ts-types.md#resourcecolor) | No | Text font color.<br>Default value: **$r('sys.color.ohos_id_color_text_secondary')**| 68e41f4b71Sopenharmony_ci| fontWeight | number \| [FontWeight](ts-appendix-enums.md#fontweight) \| string | No | Text font weight.<br>Default value: **FontWeight.Regular**| 69e41f4b71Sopenharmony_ci 70e41f4b71Sopenharmony_ci## PopupButtonOptions 71e41f4b71Sopenharmony_ci 72e41f4b71Sopenharmony_ciDefines the button attributes and events. 73e41f4b71Sopenharmony_ci 74e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12. 75e41f4b71Sopenharmony_ci 76e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full 77e41f4b71Sopenharmony_ci 78e41f4b71Sopenharmony_ci| Name | Type | Mandatory| Description | 79e41f4b71Sopenharmony_ci| --------- | ---------------------------------------------------- | ---- | ---------------------- | 80e41f4b71Sopenharmony_ci| text | [ResourceStr](ts-types.md#resourcestr) | Yes | Text of the button. | 81e41f4b71Sopenharmony_ci| action | () => void | No | Click callback of the button.| 82e41f4b71Sopenharmony_ci| fontSize | number \| string \| [Resource](ts-types.md#resource) | No | Font size of the button text.<br>Default value: **$r('sys.float.ohos_id_text_size_button2')**| 83e41f4b71Sopenharmony_ci| fontColor | [ResourceColor](ts-types.md#resourcecolor) | No | Font color of the button text.<br>Default value: **$r('sys.color.ohos_id_color_text_primary_activated')**| 84e41f4b71Sopenharmony_ci 85e41f4b71Sopenharmony_ci## PopupIconOptions 86e41f4b71Sopenharmony_ci 87e41f4b71Sopenharmony_ciDefines the attributes of the icon (in the upper right corner). 88e41f4b71Sopenharmony_ci 89e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12. 90e41f4b71Sopenharmony_ci 91e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full 92e41f4b71Sopenharmony_ci 93e41f4b71Sopenharmony_ci| Name | Type | Mandatory| Description | 94e41f4b71Sopenharmony_ci| ------------ | ------------------------------------------------------------ | ---- | ---------------------------------- | 95e41f4b71Sopenharmony_ci| image | [ResourceStr](ts-types.md#resourcestr) | Yes | Icon content. | 96e41f4b71Sopenharmony_ci| width | [Dimension](ts-types.md#dimension10) | No | Icon width.<br>Default value: **32VP**| 97e41f4b71Sopenharmony_ci| height | [Dimension](ts-types.md#dimension10) | No | Icon height.<br>Default value: **32VP**| 98e41f4b71Sopenharmony_ci| fillColor | [ResourceColor](ts-types.md#resourcecolor) | No | Icon fill color. | 99e41f4b71Sopenharmony_ci| borderRadius | [Length](ts-types.md#length) \| [BorderRadiuses](ts-types.md#borderradiuses9) | No | Rounded corner of the icon.<br>Default value: **$r('sys.float.ohos_id_corner_radius_default_s')** | 100e41f4b71Sopenharmony_ci 101e41f4b71Sopenharmony_ci## Example 102e41f4b71Sopenharmony_ci 103e41f4b71Sopenharmony_ci```ts 104e41f4b71Sopenharmony_ci// xxx.ets 105e41f4b71Sopenharmony_ciimport { Popup, PopupTextOptions, PopupButtonOptions, PopupIconOptions } from '@kit.ArkUI'; 106e41f4b71Sopenharmony_ci 107e41f4b71Sopenharmony_ci@Entry 108e41f4b71Sopenharmony_ci@Component 109e41f4b71Sopenharmony_cistruct PopupExample { 110e41f4b71Sopenharmony_ci 111e41f4b71Sopenharmony_ci build() { 112e41f4b71Sopenharmony_ci Row() { 113e41f4b71Sopenharmony_ci // Define a popup. 114e41f4b71Sopenharmony_ci Popup({ 115e41f4b71Sopenharmony_ci // Set the icon through PopupIconOptions. 116e41f4b71Sopenharmony_ci icon: { 117e41f4b71Sopenharmony_ci image: $r('app.media.icon'), 118e41f4b71Sopenharmony_ci width:32, 119e41f4b71Sopenharmony_ci height:32, 120e41f4b71Sopenharmony_ci fillColor:Color.White, 121e41f4b71Sopenharmony_ci borderRadius: 16 122e41f4b71Sopenharmony_ci } as PopupIconOptions, 123e41f4b71Sopenharmony_ci // Set the text through PopupTextOptions. 124e41f4b71Sopenharmony_ci title: { 125e41f4b71Sopenharmony_ci text: 'This is a popup with PopupOptions', 126e41f4b71Sopenharmony_ci fontSize: 20, 127e41f4b71Sopenharmony_ci fontColor: Color.Black, 128e41f4b71Sopenharmony_ci fontWeight: FontWeight.Normal 129e41f4b71Sopenharmony_ci } as PopupTextOptions, 130e41f4b71Sopenharmony_ci // Set the text through PopupTextOptions. 131e41f4b71Sopenharmony_ci message: { 132e41f4b71Sopenharmony_ci text: 'This is the message', 133e41f4b71Sopenharmony_ci fontSize: 15, 134e41f4b71Sopenharmony_ci fontColor: Color.Black 135e41f4b71Sopenharmony_ci } as PopupTextOptions, 136e41f4b71Sopenharmony_ci showClose: false, 137e41f4b71Sopenharmony_ci onClose: () => { 138e41f4b71Sopenharmony_ci console.info('close Button click') 139e41f4b71Sopenharmony_ci }, 140e41f4b71Sopenharmony_ci // Set the button through PopupButtonOptions. 141e41f4b71Sopenharmony_ci buttons: [{ 142e41f4b71Sopenharmony_ci text: 'confirm', 143e41f4b71Sopenharmony_ci action: () => { 144e41f4b71Sopenharmony_ci console.info('confirm button click') 145e41f4b71Sopenharmony_ci }, 146e41f4b71Sopenharmony_ci fontSize: 15, 147e41f4b71Sopenharmony_ci fontColor: Color.Black, 148e41f4b71Sopenharmony_ci }, 149e41f4b71Sopenharmony_ci { 150e41f4b71Sopenharmony_ci text: 'cancel', 151e41f4b71Sopenharmony_ci action: () => { 152e41f4b71Sopenharmony_ci console.info('cancel button click') 153e41f4b71Sopenharmony_ci }, 154e41f4b71Sopenharmony_ci fontSize: 15, 155e41f4b71Sopenharmony_ci fontColor: Color.Black 156e41f4b71Sopenharmony_ci },] as [PopupButtonOptions?, PopupButtonOptions?] 157e41f4b71Sopenharmony_ci }) 158e41f4b71Sopenharmony_ci } 159e41f4b71Sopenharmony_ci .width(300) 160e41f4b71Sopenharmony_ci .height(200) 161e41f4b71Sopenharmony_ci .borderWidth(2) 162e41f4b71Sopenharmony_ci .justifyContent(FlexAlign.Center) 163e41f4b71Sopenharmony_ci } 164e41f4b71Sopenharmony_ci} 165e41f4b71Sopenharmony_ci``` 166e41f4b71Sopenharmony_ci 167e41f4b71Sopenharmony_ci 168e41f4b71Sopenharmony_ci 169e41f4b71Sopenharmony_ci## Example 2 170e41f4b71Sopenharmony_ciThis example shows a mirrored layout of the popup. 171e41f4b71Sopenharmony_ci 172e41f4b71Sopenharmony_ci```ts 173e41f4b71Sopenharmony_ci// xxx.ets 174e41f4b71Sopenharmony_ciimport { Popup, PopupTextOptions, PopupButtonOptions, PopupIconOptions } from '@kit.ArkUI' 175e41f4b71Sopenharmony_ci 176e41f4b71Sopenharmony_ci@Entry 177e41f4b71Sopenharmony_ci@Component 178e41f4b71Sopenharmony_cistruct PopupPage { 179e41f4b71Sopenharmony_ci @State currentDirection: Direction = Direction.Rtl 180e41f4b71Sopenharmony_ci 181e41f4b71Sopenharmony_ci build() { 182e41f4b71Sopenharmony_ci Column() { 183e41f4b71Sopenharmony_ci // Define a popup. 184e41f4b71Sopenharmony_ci Popup({ 185e41f4b71Sopenharmony_ci // Set the icon through PopupIconOptions. 186e41f4b71Sopenharmony_ci direction: this.currentDirection, 187e41f4b71Sopenharmony_ci icon: { 188e41f4b71Sopenharmony_ci image: $r('app.media.icon'), 189e41f4b71Sopenharmony_ci width: 32, 190e41f4b71Sopenharmony_ci height: 32, 191e41f4b71Sopenharmony_ci fillColor: Color.White, 192e41f4b71Sopenharmony_ci borderRadius: 16, 193e41f4b71Sopenharmony_ci } as PopupIconOptions, 194e41f4b71Sopenharmony_ci // Set the text through PopupTextOptions. 195e41f4b71Sopenharmony_ci title: { 196e41f4b71Sopenharmony_ci text: 'This is a popup with PopupOptions', 197e41f4b71Sopenharmony_ci fontSize: 20, 198e41f4b71Sopenharmony_ci fontColor: Color.Black, 199e41f4b71Sopenharmony_ci fontWeight: FontWeight.Normal, 200e41f4b71Sopenharmony_ci 201e41f4b71Sopenharmony_ci } as PopupTextOptions, 202e41f4b71Sopenharmony_ci // Set the text through PopupTextOptions. 203e41f4b71Sopenharmony_ci message: { 204e41f4b71Sopenharmony_ci text: 'This is the message', 205e41f4b71Sopenharmony_ci fontSize: 15, 206e41f4b71Sopenharmony_ci fontColor: Color.Black, 207e41f4b71Sopenharmony_ci } as PopupTextOptions, 208e41f4b71Sopenharmony_ci showClose: true, 209e41f4b71Sopenharmony_ci onClose: () => { 210e41f4b71Sopenharmony_ci console.info('close Button click') 211e41f4b71Sopenharmony_ci }, 212e41f4b71Sopenharmony_ci // Set the button through PopupButtonOptions. 213e41f4b71Sopenharmony_ci buttons: [{ 214e41f4b71Sopenharmony_ci text: 'confirm', 215e41f4b71Sopenharmony_ci action: () => { 216e41f4b71Sopenharmony_ci console.info('confirm button click') 217e41f4b71Sopenharmony_ci }, 218e41f4b71Sopenharmony_ci fontSize: 15, 219e41f4b71Sopenharmony_ci fontColor: Color.Black, 220e41f4b71Sopenharmony_ci 221e41f4b71Sopenharmony_ci }, 222e41f4b71Sopenharmony_ci { 223e41f4b71Sopenharmony_ci text: 'cancel', 224e41f4b71Sopenharmony_ci action: () => { 225e41f4b71Sopenharmony_ci console.info('cancel button click') 226e41f4b71Sopenharmony_ci }, 227e41f4b71Sopenharmony_ci fontSize: 15, 228e41f4b71Sopenharmony_ci fontColor: Color.Black, 229e41f4b71Sopenharmony_ci },] as [PopupButtonOptions?, PopupButtonOptions?], 230e41f4b71Sopenharmony_ci }) 231e41f4b71Sopenharmony_ci 232e41f4b71Sopenharmony_ci } 233e41f4b71Sopenharmony_ci .justifyContent(FlexAlign.Center) 234e41f4b71Sopenharmony_ci .width('100%') 235e41f4b71Sopenharmony_ci .height('100%') 236e41f4b71Sopenharmony_ci } 237e41f4b71Sopenharmony_ci} 238e41f4b71Sopenharmony_ci``` 239e41f4b71Sopenharmony_ci 240e41f4b71Sopenharmony_ci 241