Skip to content

Commit 5acc3b9

Browse files
chore(update-plugins): Thu May 2 08:05:33 UTC 2024
1 parent a69767e commit 5acc3b9

File tree

1 file changed

+154
-134
lines changed

1 file changed

+154
-134
lines changed

plugins/datetimepicker.md

Lines changed: 154 additions & 134 deletions
Original file line numberDiff line numberDiff line change
@@ -18,29 +18,31 @@ A plugin that provides the UI elements `DatePickerField`, `TimePickerField` and
1818

1919
## Contents
2020

21-
- [Installation](#installation)
22-
- [Use @nativescript/datetimepicker](#use-nativescriptdatetimepicker)
23-
- [Core](#core)
24-
- [Angular](#angular)
25-
- [Vue](#vue)
26-
- [Set the selected date and time](#set-the-selected-date-and-time)
27-
- [Change the picker titles and buttons labels](#change-the-picker-titles-and-buttons-labels)
28-
- [Set localization](#setlocalization)
29-
- [Format the date and time](#format-the-date-and-time)
30-
- [Set the minimum and maximum dates](#set-the-minimum-and-maximum-dates)
31-
- [DateTimePickerFields pickers orientation](#datetimepickerfields-pickers-orientation)
32-
- [Style the pickers with CSS](#style-the-pickers-with-css)
33-
- [DateTimePicker](#datetimepicker)
34-
- [Create custom pickers manually](#create-custom-pickers-manually)
35-
- [API](#api)
36-
- [DatePickerField](#datepickerfield)
37-
- [TimePickerField](#timepickerfield)
38-
- [DateTimePickerFields](#datetimepickerfields)
39-
- [DateTimePicker Class](#datetimepicker-class)
40-
- [DatePickerOptions](#datepickeroptions)
41-
- [TimePickerOptions](#timepickeroptions)
42-
- [DateTimePickerStyle](#datetimepickerstyle)
43-
- [License](#license)
21+
- [@nativescript/datetimepicker](#nativescriptdatetimepicker)
22+
- [Contents](#contents)
23+
- [Installation](#installation)
24+
- [Use @nativescript/datetimepicker](#use-nativescriptdatetimepicker)
25+
- [Core](#core)
26+
- [Angular](#angular)
27+
- [Vue](#vue)
28+
- [Svelte](#svelte)
29+
- [Set the selected date and time](#set-the-selected-date-and-time)
30+
- [Change the picker titles and buttons labels](#change-the-picker-titles-and-buttons-labels)
31+
- [Set localization](#set-localization)
32+
- [Format the date and time](#format-the-date-and-time)
33+
- [Set the minimum and maximum dates](#set-the-minimum-and-maximum-dates)
34+
- [Set the layout of DateTimePickerFields pickers](#set-the-layout-of-datetimepickerfields-pickers)
35+
- [Style the pickers with CSS](#style-the-pickers-with-css)
36+
- [Create custom pickers manually](#create-custom-pickers-manually)
37+
- [API](#api)
38+
- [DatePickerField](#datepickerfield)
39+
- [TimePickerField](#timepickerfield)
40+
- [DateTimePickerFields](#datetimepickerfields)
41+
- [DateTimePicker Class](#datetimepicker-class)
42+
- [DatePickerOptions](#datepickeroptions)
43+
- [TimePickerOptions](#timepickeroptions)
44+
- [DateTimePickerStyle](#datetimepickerstyle)
45+
- [License](#license)
4446

4547
## Installation
4648

@@ -52,77 +54,77 @@ npm install @nativescript/datetimepicker
5254

5355
### Core
5456

55-
1. Register the plugin namespace with Page's `xmlns` attribute providing your prefix( `datetime`, for example) and setting its value to the plugin name.
57+
1. Register the plugin namespace with Page's `xmlns` attribute providing your prefix (`datetime` for example) and setting its value to the plugin name.
5658

57-
```xml
58-
<Page
59-
xmlns="http://schemas.nativescript.org/tns.xsd"
60-
xmlns:datetime="@nativescript/datetimepicker">
61-
```
59+
```xml
60+
<Page
61+
xmlns="http://schemas.nativescript.org/tns.xsd"
62+
xmlns:datetime="@nativescript/datetimepicker"
63+
/>
64+
```
6265

63-
2. Access the `atePickerField` view through the prefix.
66+
2. Access the `datePickerField` view through the prefix.
6467

65-
```xml
66-
<Page
67-
xmlns="http://schemas.nativescript.org/tns.xsd"
68-
xmlns:datetime="@nativescript/datetimepicker">
69-
<!-- 2. -->
70-
<datetime:DatePickerField hint="select date"/>
71-
<datetime:TimePickerField hint="select time"/>
72-
<datetime:DateTimePickerFields hintDate="select date" hintTime="select time"/>
73-
```
68+
```xml
69+
<Page
70+
xmlns="http://schemas.nativescript.org/tns.xsd"
71+
xmlns:datetime="@nativescript/datetimepicker"
72+
>
73+
<datetime:DatePickerField hint="select date" />
74+
<datetime:TimePickerField hint="select time" />
75+
<datetime:DateTimePickerFields hintDate="select date" hintTime="select time" />
76+
</Page>
77+
```
7478

7579
### Angular
7680

7781
1. Register the plugin by adding the plugin's `NativeScriptDateTimePickerModule` to the `imports` array of the module that contains the component where you want to use the `DatePickerField`:
7882

79-
```ts
80-
import { NativeScriptDateTimePickerModule } from "@nativescript/datetimepicker/angular";
81-
...
82-
@NgModule({
83-
imports: [
84-
NativeScriptCommonModule,
85-
NativeScriptDateTimePickerModule,
86-
...
87-
],
88-
...
89-
```
83+
```ts
84+
import { NativeScriptDateTimePickerModule } from '@nativescript/datetimepicker/angular'
85+
86+
@NgModule({
87+
imports: [
88+
NativeScriptCommonModule,
89+
NativeScriptDateTimePickerModule,
90+
// ...
91+
],
92+
// ...
93+
})
94+
```
9095

9196
2. Use `DatePickerField` in markup as follows:
9297

93-
```html
94-
<DatePickerField hint="select date"></DatePickerField>
95-
<TimePickerField hint="select time"></TimePickerField>
96-
<DateTimePickerFields
97-
hintDate="select date"
98-
hintTime="select time"
99-
></DateTimePickerFields>
100-
```
98+
```xml
99+
<DatePickerField hint="select date"></DatePickerField>
100+
<TimePickerField hint="select time"></TimePickerField>
101+
<DateTimePickerFields
102+
hintDate="select date"
103+
hintTime="select time"
104+
></DateTimePickerFields>
105+
```
101106

102107
### Vue
103108

104109
1. Once the plugin has been installed, register it with your app project, in the `main.ts` file for global access.
105110

106-
```ts
107-
import DateTimePicker from '@nativescript/datetimepicker/vue'
111+
```ts
112+
import DateTimePicker from '@nativescript/datetimepicker/vue'
108113

109-
import Home from './components/Home.vue'
114+
import Home from './components/Home.vue'
110115

111-
const app = createApp(Home).use(DateTimePicker)
116+
const app = createApp(Home).use(DateTimePicker)
112117

113-
app.start()
114-
```
118+
app.start()
119+
```
115120

116121
2. Use the `DatePickerField` in a `template` as follows:
117122

118-
```html
119-
<DatePickerField hint="select date"></DatePickerField>
120-
<TimePickerField hint="select time"></TimePickerField>
121-
<DateTimePickerFields
122-
hintDate="select date"
123-
hintTime="select time"
124-
></DateTimePickerFields>
125-
```
123+
```xml
124+
<DatePickerField hint="select date" />
125+
<TimePickerField hint="select time" />
126+
<DateTimePickerFields hintDate="select date" hintTime="select time" />
127+
```
126128

127129
### Svelte
128130

@@ -193,9 +195,15 @@ To localize the `DatePickerField` and `DateTimePickerFields` components, use the
193195
```xml
194196
<DatePickerField locale="en_GB" hint="select date"></DatePickerField>
195197
<!-- DateTimePickerFields -->
196-
<DateTimePickerFields locale="de_DE" hintDate="datum auswählen" hintTime="zeit wählen"
197-
pickerOkText="Bestätigen" pickerCancelText="Stornieren"
198-
pickerTitleDate="Datum auswählen" pickerTitleTime="Zeit wählen" />
198+
<DateTimePickerFields
199+
locale="de_DE"
200+
hintDate="datum auswählen"
201+
hintTime="zeit wählen"
202+
pickerOkText="Bestätigen"
203+
pickerCancelText="Stornieren"
204+
pickerTitleDate="Datum auswählen"
205+
pickerTitleTime="Zeit wählen"
206+
></DateTimePickerFields>
199207
```
200208

201209
### Format the date and time
@@ -208,7 +216,7 @@ Aside from the default formats that are dependent on the value of the `locale` p
208216

209217
The `TimePickerField` will determine whether to use 12 or 24 hour format (for formatting of the selected time in the field and for the values of the hour spinner) based on the selected region in the settings of the iOS device and based on the `Use 24-Hour Format` setting of the Android device. To change the default setting on Android, you need to use the `timeFormat` property and to change the setting on iOS, you need to use the `locale` property.
210218

211-
```html
219+
```xml
212220
<TimePickerField time="16:00" timeFormat="h:mm a" locale="en_US" />
213221
```
214222

@@ -222,15 +230,19 @@ For the `DateTimePickerFields` picker, use the same properties( `dateFormat`, `t
222230

223231
To set the minimum and maximum dates, use the `minDate` and `maxDate` properties for the `DatePickerField` and `DateTimePickerFields` components.
224232

225-
```html
226-
<DatePickerField minDate="2020/02/02" maxDate="2021/02/02" hint="tap to select" />
233+
```xml
234+
<DatePickerField
235+
minDate="2020/02/02"
236+
maxDate="2021/02/02"
237+
hint="tap to select"
238+
></DatePickerField>
227239
<!-- DateTimePickerFields -->
228240
<DateTimePickerFields
229241
minDate="2020/02/02"
230242
maxDate="2021/02/02"
231243
hintDate="tap to select date"
232244
hintTime="tap to select time"
233-
/>
245+
></DateTimePickerFields>
234246
```
235247

236248
### Set the layout of DateTimePickerFields pickers
@@ -267,39 +279,39 @@ that the iOS native implementation has limited capabilities for the buttons back
267279
```css
268280
timepickerfield,
269281
datepickerfield {
270-
padding: 12 4;
282+
padding: 12 4;
271283
}
272284

273285
timepickerfield.apply-css,
274286
datepickerfield.apply-css {
275-
color: #CDDC39;
276-
background-color: #00796B;
277-
font-size: 20;
278-
font-weight: bold;
279-
padding: 20;
287+
color: #cddc39;
288+
background-color: #00796b;
289+
font-size: 20;
290+
font-weight: bold;
291+
padding: 20;
280292
}
281293

282294
.date-time-picker.apply-css {
283-
color: #00796B;
284-
background-color: #CDDC39;
295+
color: #00796b;
296+
background-color: #cddc39;
285297
}
286298

287299
.date-time-picker-spinners.apply-css {
288-
color: #CDDC39;
289-
background-color: #00796B;
300+
color: #cddc39;
301+
background-color: #00796b;
290302
}
291303

292304
.date-time-picker-buttons.apply-css {
293-
color: #00796B;
305+
color: #00796b;
294306
}
295-
Footer
296307
```
297308

298309
To apply styles at runtime when opening the DateTimePicker you can do the following:
299310

300311
```ts
301312
import { DateTimePicker, DateTimePickerStyle } from '@nativescript/datetimepicker'
302313
import { Application, View } from '@nativescript/core'
314+
303315
function createPicker(args: EventData) {
304316
const dateTimePickerStyle = DateTimePickerStyle.create(args.object as any)
305317

@@ -343,52 +355,60 @@ function createPicker(args: EventData) {
343355
Internally `DatePickerField` and `TimePickerField` call the `pickDate` and `pickTime` methods of the `DateTimePicker` class which are public. You can create custom pickers by calling those methods manually. The `pickDate` method accepts [DatePickerOptions](#datepickeroptions), while the `pickTime` method accepts [TimePickerOptions](#timepickeroptions).
344356

345357
```ts
346-
function onPickDateTap (args: EventData) {
347-
const dateToday = new Date();
348-
const dateTomorrow = new Date(dateToday.getFullYear(), dateToday.getMonth(), dateToday.getDate() + 1);
349-
const dateNextWeek = new Date(dateToday.getFullYear(), dateToday.getMonth(), dateToday.getDate() + 7);
350-
351-
DateTimePicker
352-
.pickDate({
353-
context: args.object._context,
354-
date: dateTomorrow,
355-
minDate: dateTomorrow,
356-
maxDate: dateNextWeek,
357-
okButtonText: "OK",
358-
cancelButtonText: "Cancel",
359-
title: "choose date",
360-
locale: "en_GB"
361-
})
362-
.then(selectedDate => {
363-
if (selectedDate) {
364-
this.dateText = this.getFormattedDate(selectedDate);
365-
}
366-
});
367-
},
358+
function onPickDateTap(args: EventData) {
359+
const dateToday = new Date()
360+
const dateTomorrow = new Date(
361+
dateToday.getFullYear(),
362+
dateToday.getMonth(),
363+
dateToday.getDate() + 1
364+
)
365+
const dateNextWeek = new Date(
366+
dateToday.getFullYear(),
367+
dateToday.getMonth(),
368+
dateToday.getDate() + 7
369+
)
370+
371+
DateTimePicker.pickDate({
372+
context: args.object._context,
373+
date: dateTomorrow,
374+
minDate: dateTomorrow,
375+
maxDate: dateNextWeek,
376+
okButtonText: 'OK',
377+
cancelButtonText: 'Cancel',
378+
title: 'choose date',
379+
locale: 'en_GB'
380+
}).then(selectedDate => {
381+
if (selectedDate) {
382+
this.dateText = this.getFormattedDate(selectedDate)
383+
}
384+
})
385+
}
368386
```
369387

370388
```ts
371-
function onPickTimeTap (args: EventData) {
372-
const dateToday = new Date();
373-
const dateTomorrow = new Date(dateToday.getFullYear(), dateToday.getMonth(), dateToday.getDate() + 1);
374-
dateTomorrow.setHours(8);
375-
dateTomorrow.setMinutes(0);
376-
DateTimePicker
377-
.pickTime({
378-
context: args.object._context,
379-
time: dateTomorrow,
380-
okButtonText: "OK",
381-
cancelButtonText: "Cancel",
382-
title: "choose time",
383-
locale: "en_GB",
384-
is24Hours: true
385-
})
386-
.then(selectedTime => {
387-
if (selectedTime) {
388-
this.timeText = this.getFormattedTime(selectedTime);
389-
}
390-
});
391-
},
389+
function onPickTimeTap(args: EventData) {
390+
const dateToday = new Date()
391+
const dateTomorrow = new Date(
392+
dateToday.getFullYear(),
393+
dateToday.getMonth(),
394+
dateToday.getDate() + 1
395+
)
396+
dateTomorrow.setHours(8)
397+
dateTomorrow.setMinutes(0)
398+
DateTimePicker.pickTime({
399+
context: args.object._context,
400+
time: dateTomorrow,
401+
okButtonText: 'OK',
402+
cancelButtonText: 'Cancel',
403+
title: 'choose time',
404+
locale: 'en_GB',
405+
is24Hours: true
406+
}).then(selectedTime => {
407+
if (selectedTime) {
408+
this.timeText = this.getFormattedTime(selectedTime)
409+
}
410+
})
411+
}
392412
```
393413

394414
## API

0 commit comments

Comments
 (0)