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 [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>13+</sup>              | boolean | No  | Whether to enable the hover mode.<br>Default value: **false**, meaning not to enable the hover mode.|
50| hoverModeArea<sup>13+</sup>              | [HoverModeAreaType](ts-appendix-enums.md#hovermodeareatype13) | No  | Display area of the dialog box in hover mode.<br>Default value: **HoverModeAreaType.BOTTOM_SCREEN**|
51
52## Example
53
54### Example 1
55
56This example shows the basic usage of **CalendarPickerDialog**.
57
58```ts
59// xxx.ets
60@Entry
61@Component
62struct CalendarPickerDialogExample {
63  private selectedDate: Date = new Date('2024-04-23')
64
65  build() {
66    Column() {
67      Button("Show CalendarPicker Dialog")
68        .margin(20)
69        .onClick(() => {
70          console.info("CalendarDialog.show")
71          CalendarPickerDialog.show({
72            selected: this.selectedDate,
73            onAccept: (value) => {
74              console.info("calendar onAccept:" + JSON.stringify(value))
75            },
76            onCancel: () => {
77              console.info("calendar onCancel")
78            },
79            onChange: (value) => {
80              console.info("calendar onChange:" + JSON.stringify(value))
81            },
82            onDidAppear: () => {
83              console.info("calendar onDidAppear")
84            },
85            onDidDisappear: () => {
86              console.info("calendar onDidDisappear")
87            },
88            onWillAppear: () => {
89              console.info("calendar onWillAppear")
90            },
91            onWillDisappear: () => {
92              console.info("calendar onWillDisappear")
93            }
94          })
95        })
96    }.width('100%')
97  }
98}
99```
100
101![CalendarPickerDialog](figures/CalendarPickerDialog.gif)
102
103### Example 2
104
105This example shows how to customize the button style.
106
107```ts
108// xxx.ets
109@Entry
110@Component
111struct CalendarPickerDialogExample {
112  private selectedDate: Date = new Date()
113  build() {
114    Column() {
115      Button("Show CalendarPicker Dialog")
116        .margin(20)
117        .onClick(() => {
118          console.info("CalendarDialog.show")
119          CalendarPickerDialog.show({
120            selected: this.selectedDate,
121            acceptButtonStyle: { type: ButtonType.Normal, style: ButtonStyleMode.NORMAL, role: ButtonRole.NORMAL, fontColor: Color.Red,
122              fontSize: '26fp', fontWeight: FontWeight.Bolder, fontStyle: FontStyle.Normal, fontFamily: 'sans-serif', backgroundColor:'#80834511',
123              borderRadius: 20 },
124            cancelButtonStyle: { type: ButtonType.Normal, style: ButtonStyleMode.NORMAL, role: ButtonRole.NORMAL, fontColor: Color.Blue,
125              fontSize: '16fp', fontWeight: FontWeight.Normal, fontStyle: FontStyle.Italic, fontFamily: 'sans-serif', backgroundColor:'#50182431',
126              borderRadius: 10 },
127            onAccept: (value) => {
128              console.info("calendar onAccept:" + JSON.stringify(value))
129            },
130            onCancel: () => {
131              console.info("calendar onCancel")
132            },
133            onChange: (value) => {
134              console.info("calendar onChange:" + JSON.stringify(value))
135            },
136            onDidAppear: () => {
137              console.info("calendar onDidAppear")
138            },
139            onDidDisappear: () => {
140              console.info("calendar onDidDisappear")
141            },
142            onWillAppear: () => {
143              console.info("calendar onWillAppear")
144            },
145            onWillDisappear: () => {
146              console.info("calendar onWillDisappear")
147            }
148          })
149        })
150    }.width('100%')
151  }
152}
153```
154
155![CalendarPickerDialog](figures/CalendarPickerDialog_CustomButton.png)
156
157### Example 3
158
159This example demonstrates how to set the layout area of a dialog box in hover mode on a foldable device.
160
161```ts
162@Entry
163@Component
164struct CalendarPickerDialogExample {
165  private selectedDate: Date = new Date('2024-04-23');
166
167  build() {
168    Column() {
169      Button("Show CalendarPicker Dialog")
170        .margin(20)
171        .onClick(() => {
172          console.info("CalendarDialog.show")
173          CalendarPickerDialog.show({
174            selected: this.selectedDate,
175            onAccept: (value) => {
176              console.info("calendar onAccept:" + JSON.stringify(value))
177            },
178            onCancel: () => {
179              console.info("calendar onCancel")
180            },
181            onChange: (value) => {
182              console.info("calendar onChange:" + JSON.stringify(value))
183            },
184            onDidAppear: () => {
185              console.info("calendar onDidAppear")
186            },
187            onDidDisappear: () => {
188              console.info("calendar onDidDisappear")
189            },
190            onWillAppear: () => {
191              console.info("calendar onWillAppear")
192            },
193            onWillDisappear: () => {
194              console.info("calendar onWillDisappear")
195            },
196            enableHoverMode: true,
197            hoverModeArea: HoverModeAreaType.TOP_SCREEN,
198          })
199        })
200    }.width('100%')
201  }
202}
203```
204
205![CalendarPickerDialog](figures/CalendarPickerDialog_HoverMode.gif)
206