You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: packages/datetimepicker/README.md
+46Lines changed: 46 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -112,6 +112,52 @@ You can use css to style the `DatePickerField` and the `TimePickerField`. The fi
112
112
113
113
Here's the css used to achieve the above result, as used in the [demo](https://github.com/NativeScript/nativescript-datetimepicker/blob/master/demo/app/home/home-page.css#L22), [demo-angular](https://github.com/NativeScript/nativescript-datetimepicker/blob/master/demo-angular/src/app/home/home.component.css#L22) and [demo-vue](https://github.com/NativeScript/nativescript-datetimepicker/blob/master/demo-vue/app/components/Home.vue#L350) applications.
114
114
115
+
To apply styles at runtime when opening the DateTimePicker you can do the following:
116
+
117
+
```ts
118
+
import { DateTimePicker, DateTimePickerStyle } from '@nativescript/datetimepicker';
119
+
import { Application, Button } from '@nativescript/core';
120
+
121
+
export function someButtonTapToOpenThePicker(args) {
122
+
const dateTimePickerStyle = DateTimePickerStyle.create(args.object as any);
123
+
124
+
// This example handles styling the calendar for light and dark mode of the device settings
125
+
if (Application.systemAppearance() === 'dark') {
126
+
// style for dark mode
127
+
dateTimePickerStyle.buttonsBackgroundColor = new Color('#202125');
128
+
dateTimePickerStyle.dialogBackgroundColor = new Color('#202125');
129
+
dateTimePickerStyle.titleTextColor = new Color('#fff');
130
+
dateTimePickerStyle.buttonsTextColor = new Color('#0067a6');
131
+
dateTimePickerStyle.spinnersBackgroundColor = new Color('#202125');
132
+
dateTimePickerStyle.spinnersTextColor = new Color('#fff');
133
+
} else {
134
+
// style for light mode
135
+
dateTimePickerStyle.buttonsBackgroundColor = new Color('#fff');
136
+
dateTimePickerStyle.dialogBackgroundColor = new Color('#fff');
137
+
dateTimePickerStyle.titleTextColor = new Color('#0067a6');
138
+
dateTimePickerStyle.buttonsTextColor = new Color('#0067a6');
139
+
dateTimePickerStyle.spinnersBackgroundColor = new Color('#fff');
140
+
dateTimePickerStyle.spinnersTextColor = new Color('#0067a6');
141
+
}
142
+
143
+
DateTimePicker.pickDate(
144
+
{
145
+
context: (args.object as Button)._context,
146
+
date: yourDateValue
147
+
minDate: subYears(new Date(), 10),
148
+
maxDate: new Date(),
149
+
title: 'DatePicker'
150
+
okButtonText: 'Okay',
151
+
cancelButtonText: 'Cancel',
152
+
locale: 'en'
153
+
},
154
+
dateTimePickerStyle
155
+
).then((result) => {
156
+
// handle the result
157
+
})
158
+
}
159
+
```
160
+
115
161
### DateTimePickerFields
116
162
117
163
The `DateTimePickerFields` extends `GridLayout` that contains instances of `DatePickerField` and `TimePickerField`, when tapped, they open a picker dialog that allows date/time selection.
0 commit comments