1# Calendar Picker Dialog Box (CalendarPickerDialog) 2 3A calendar picker dialog box is a dialog box that allows users to select a date from a calendar picker. 4 5> **NOTE** 6> 7> This component is supported since API version 10. Updates will be marked with a superscript to indicate their earliest API version. 8> 9> The functionality of this module depends on UI context. This means that the APIs of this module cannot be used where the UI context is unclear. For details, see [UIContext](../js-apis-arkui-UIContext.md#uicontext). 10 11## CalendarPickerDialog 12 13### show 14 15static show(options?: CalendarDialogOptions) 16 17Shows a calendar picker dialog box. 18 19**Atomic service API**: This API can be used in atomic services since API version 11. 20 21**System capability**: SystemCapability.ArkUI.ArkUI.Full 22 23**Parameters** 24 25| Name | Type | Mandatory| Description | 26| ------- | ------------------------------------------------------- | ---- | -------------------------- | 27| options | [CalendarDialogOptions](#calendardialogoptions) | No | Parameters of the calendar picker dialog box.| 28 29## CalendarDialogOptions 30 31Inherits from [CalendarOptions](ts-basic-components-calendarpicker.md#calendaroptions). 32 33**System capability**: SystemCapability.ArkUI.ArkUI.Full 34 35| Name | Type | Mandatory| Description | 36| ---------- | ----------------------------------------------- | ---- | ------------------------------------------------------------ | 37| onAccept | [Callback](ts-types.md#callback12)\<Date> | No | Triggered when the OK button in the dialog box is clicked.<br>The selected date value is returned.<br>**Atomic service API**: This API can be used in atomic services since API version 11.| 38| onCancel | [VoidCallback](ts-types.md#voidcallback12) | No | Triggered when the Cancel button in the dialog box is clicked.<br>**Atomic service API**: This API can be used in atomic services since API version 11. | 39| onChange | [Callback](ts-types.md#callback12)\<Date> | No | Triggered when the selection in the picker changes the selected date.<br>The selected date value is returned.<br>**Atomic service API**: This API can be used in atomic services since API version 11.| 40| backgroundColor<sup>11+</sup> | [ResourceColor](ts-types.md#resourcecolor) | No| Backplane color of the dialog box.<br>Default value: **Color.Transparent**<br>**NOTE**<br>When **backgroundColor** is set to a non-transparent color, **backgroundBlurStyle** must be set to **BlurStyle.NONE**; otherwise, the color display may not meet the expected effect.<br>**Atomic service API**: This API can be used in atomic services since API version 12.| 41| backgroundBlurStyle<sup>11+</sup> | [BlurStyle](ts-universal-attributes-background.md#blurstyle9) | No| Background blur style of the dialog box.<br>Default value: **BlurStyle.COMPONENT_ULTRA_THICK**<br>**NOTE**<br>Setting this parameter to **BlurStyle.NONE** disables the background blur. When **backgroundBlurStyle** is set to a value other than **NONE**, do not set **backgroundColor**. If you do, the color display may not produce the expected visual effect.<br>**Atomic service API**: This API can be used in atomic services since API version 12.| 42| acceptButtonStyle<sup>12+</sup> | [PickerDialogButtonStyle](ts-methods-datepicker-dialog.md#pickerdialogbuttonstyle12) | No| Style of the accept button.<br>**NOTE**<br>In the **acceptButtonStyle** and **cancelButtonStyle** configurations, only one **primary** field can be set to **true** at most. If both the **primary** fields are set to **true**, neither will take effect.<br>**Atomic service API**: This API can be used in atomic services since API version 12.| 43| cancelButtonStyle<sup>12+</sup> | [PickerDialogButtonStyle](ts-methods-datepicker-dialog.md#pickerdialogbuttonstyle12) | No| Style of the cancel button.<br>**NOTE**<br>In the **acceptButtonStyle** and **cancelButtonStyle** configurations, only one **primary** field can be set to **true** at most. If both the **primary** fields are set to **true**, neither will take effect.<br>**Atomic service API**: This API can be used in atomic services since API version 12.| 44| onDidAppear<sup>12+</sup> | [VoidCallback](ts-types.md#voidcallback12) | No| Event callback when the dialog box appears.<br>**NOTE**<br>1. The normal timing sequence is as follows: onWillAppear > onDidAppear > (onAccept/onCancel/onChange) > onWillDisappear > onDidDisappear.<br>2. You can set the callback event for changing the dialog box display effect in **onDidAppear**. The settings take effect next time the dialog box appears.<br>3. If the user dismisses the dialog box immediately after it appears, **onWillDisappear** is invoked before **onDidAppear**.<br>4. If the dialog box is dismissed before its entrance animation is finished, this callback is not invoked.<br>**Atomic service API**: This API can be used in atomic services since API version 12.| 45| onDidDisappear<sup>12+</sup> | [VoidCallback](ts-types.md#voidcallback12) | No| Event callback when the dialog box disappears.<br>**NOTE**<br>1. The normal timing sequence is as follows: onWillAppear > onDidAppear > (onAccept/onCancel/onChange) > onWillDisappear > onDidDisappear.<br>**Atomic service API**: This API can be used in atomic services since API version 12.| 46| onWillAppear<sup>12+</sup> | [VoidCallback](ts-types.md#voidcallback12) | No| Event callback when the dialog box is about to appear.<br>**NOTE**<br>1. The normal timing sequence is as follows: onWillAppear > onDidAppear > (onAccept/onCancel/onChange) > onWillDisappear > onDidDisappear.<br>2. You can set the callback event for changing the dialog box display effect in **onWillAppear**. The settings take effect next time the dialog box appears.<br>**Atomic service API**: This API can be used in atomic services since API version 12.| 47| onWillDisappear<sup>12+</sup> | [VoidCallback](ts-types.md#voidcallback12) | No| Event callback when the dialog box is about to disappear.<br>**NOTE**<br>1. The normal timing sequence is as follows: onWillAppear > onDidAppear > (onAccept/onCancel/onChange) > onWillDisappear > onDidDisappear.<br>2. If the user closes the dialog box immediately after it appears, **onWillDisappear** is invoked before **onDidAppear**.<br>**Atomic service API**: This API can be used in atomic services since API version 12.| 48| shadow<sup>12+</sup> | [ShadowOptions](ts-universal-attributes-image-effect.md#shadowoptions) \| [ShadowStyle](ts-universal-attributes-image-effect.md#shadowstyle10) | No | Shadow of the dialog box.<br> Default value on 2-in-1 devices: **ShadowStyle.OUTER_FLOATING_MD** when the dialog box is focused and **ShadowStyle.OUTER_FLOATING_SM** otherwise<br>**Atomic service API**: This API can be used in atomic services since API version 12.| 49| enableHoverMode<sup>14+</sup> | boolean | No | Whether to enable the hover mode.<br>Default value: **false**, meaning not to enable the hover mode.| 50| hoverModeArea<sup>14+</sup> | [HoverModeAreaType](ts-appendix-enums.md#hovermodeareatype14) | No | Display area of the dialog box in hover mode.<br>Default value: **HoverModeAreaType.BOTTOM_SCREEN**| 51 52> **NOTE** 53> 54> When the application window is resized, the width of the dialog box is continuously compressed. If the window width is reduced below a certain threshold, the content of the dialog box may not be fully visible. To ensure that the content of the **CalendarPickerDialog** component is fully displayed, the minimum window width required is 386 vp. 55 56## Example 57 58### Example 1: Displaying a Calendar Picker Dialog Box 59 60This example demonstrates how to display a calendar picker dialog box when a button is touched. 61 62```ts 63// xxx.ets 64@Entry 65@Component 66struct CalendarPickerDialogExample { 67 private selectedDate: Date = new Date('2024-04-23') 68 69 build() { 70 Column() { 71 Button("Show CalendarPicker Dialog") 72 .margin(20) 73 .onClick(() => { 74 console.info("CalendarDialog.show") 75 CalendarPickerDialog.show({ 76 selected: this.selectedDate, 77 onAccept: (value) => { 78 console.info("calendar onAccept:" + JSON.stringify(value)) 79 }, 80 onCancel: () => { 81 console.info("calendar onCancel") 82 }, 83 onChange: (value) => { 84 console.info("calendar onChange:" + JSON.stringify(value)) 85 }, 86 onDidAppear: () => { 87 console.info("calendar onDidAppear") 88 }, 89 onDidDisappear: () => { 90 console.info("calendar onDidDisappear") 91 }, 92 onWillAppear: () => { 93 console.info("calendar onWillAppear") 94 }, 95 onWillDisappear: () => { 96 console.info("calendar onWillDisappear") 97 } 98 }) 99 }) 100 }.width('100%') 101 } 102} 103``` 104 105 106 107### Example 2: Customizing the Button Style 108 109This example demonstrates how to customize the button style using **acceptButtonStyle** and **cancelButtonStyle**. 110 111```ts 112// xxx.ets 113@Entry 114@Component 115struct CalendarPickerDialogExample { 116 private selectedDate: Date = new Date() 117 build() { 118 Column() { 119 Button("Show CalendarPicker Dialog") 120 .margin(20) 121 .onClick(() => { 122 console.info("CalendarDialog.show") 123 CalendarPickerDialog.show({ 124 selected: this.selectedDate, 125 acceptButtonStyle: { type: ButtonType.Normal, style: ButtonStyleMode.NORMAL, role: ButtonRole.NORMAL, fontColor: Color.Red, 126 fontSize: '26fp', fontWeight: FontWeight.Bolder, fontStyle: FontStyle.Normal, fontFamily: 'sans-serif', backgroundColor:'#80834511', 127 borderRadius: 20 }, 128 cancelButtonStyle: { type: ButtonType.Normal, style: ButtonStyleMode.NORMAL, role: ButtonRole.NORMAL, fontColor: Color.Blue, 129 fontSize: '16fp', fontWeight: FontWeight.Normal, fontStyle: FontStyle.Italic, fontFamily: 'sans-serif', backgroundColor:'#50182431', 130 borderRadius: 10 }, 131 onAccept: (value) => { 132 console.info("calendar onAccept:" + JSON.stringify(value)) 133 }, 134 onCancel: () => { 135 console.info("calendar onCancel") 136 }, 137 onChange: (value) => { 138 console.info("calendar onChange:" + JSON.stringify(value)) 139 }, 140 onDidAppear: () => { 141 console.info("calendar onDidAppear") 142 }, 143 onDidDisappear: () => { 144 console.info("calendar onDidDisappear") 145 }, 146 onWillAppear: () => { 147 console.info("calendar onWillAppear") 148 }, 149 onWillDisappear: () => { 150 console.info("calendar onWillDisappear") 151 } 152 }) 153 }) 154 }.width('100%') 155 } 156} 157``` 158 159 160 161### Example 3: Configuring a Dialog Box in the Hover State 162 163This example demonstrates how to set the layout area of a dialog box in hover mode on a foldable device. 164 165```ts 166@Entry 167@Component 168struct CalendarPickerDialogExample { 169 private selectedDate: Date = new Date('2024-04-23'); 170 171 build() { 172 Column() { 173 Button("Show CalendarPicker Dialog") 174 .margin(20) 175 .onClick(() => { 176 console.info("CalendarDialog.show") 177 CalendarPickerDialog.show({ 178 selected: this.selectedDate, 179 onAccept: (value) => { 180 console.info("calendar onAccept:" + JSON.stringify(value)) 181 }, 182 onCancel: () => { 183 console.info("calendar onCancel") 184 }, 185 onChange: (value) => { 186 console.info("calendar onChange:" + JSON.stringify(value)) 187 }, 188 onDidAppear: () => { 189 console.info("calendar onDidAppear") 190 }, 191 onDidDisappear: () => { 192 console.info("calendar onDidDisappear") 193 }, 194 onWillAppear: () => { 195 console.info("calendar onWillAppear") 196 }, 197 onWillDisappear: () => { 198 console.info("calendar onWillDisappear") 199 }, 200 enableHoverMode: true, 201 hoverModeArea: HoverModeAreaType.TOP_SCREEN, 202 }) 203 }) 204 }.width('100%') 205 } 206} 207``` 208 209 210