4
4
-->
5
5
6
6
<docs>
7
- > We're wrapping the awesome datepicker library here https://github.com/mengxiong10/vue-datepicker-next
8
- > Please check there for all the available options.
7
+ In general it is recommended to use the native date picker (see `NcDateTimePickerNative` which is based on `<input type="date">`).
8
+ But some use cases are not covered by the native date selector, like selecting ranges or selecting a timezone.
9
+ For those cases this component can be used.
9
10
10
- ### Defaults
11
- - cleareable: false
12
- - minute-step: 10
13
-
14
- ### Example
11
+ ### General examples
15
12
```vue
16
13
<template>
17
14
<div class="wrapper">
@@ -54,6 +51,11 @@ export default {
54
51
```
55
52
56
53
### Example with confirm button
54
+
55
+ By default the date is applied as soon as you select the day in the calendar.
56
+ Sometimes - especially when selecting date and time - it is required to only emit the selected date when the flow is finished.
57
+ For this the `confirm` prop can be used, this will add a confirmation button to the selector.
58
+
57
59
```vue
58
60
<template>
59
61
<span>
@@ -76,24 +78,57 @@ export default {
76
78
```
77
79
78
80
### Range picker
81
+
82
+ The most common use case for the `NcDateTimePicker` is picking a range, as this is not supported by the native date picker.
83
+
84
+ When selecting the range picker type, the model value type will change from `Date` to `[Date, Date]`.
85
+ Meaning an array with two dates is used, the first date is the range start and the second date is the range end.
86
+
79
87
```vue
80
88
<template>
81
- <span>
89
+ <div>
90
+ <fieldset class="type-select">
91
+ <legend>Picker mode</legend>
92
+ <NcCheckboxRadioSwitch v-model="type" type="radio" value="range">Date</NcCheckboxRadioSwitch>
93
+ <NcCheckboxRadioSwitch v-model="type" type="radio" value="range-datetime">Date and time</NcCheckboxRadioSwitch>
94
+ </fieldset>
95
+
82
96
<NcDateTimePicker
83
97
v-model="time"
84
- type="range-datetime" />
85
- {{ time }}
86
- </span>
98
+ :type />
99
+ <div>
100
+ <div>Start: {{ formatDate(time[0]) }}</div>
101
+ <div>End: {{ formatDate(time[1]) }}</div>
102
+ </div>
103
+ </div>
87
104
</template>
88
105
<script>
89
106
export default {
90
107
data() {
91
108
return {
92
- time: null,
109
+ time: [new Date(2025, 3, 18), new Date(2025, 3, 21)],
110
+ type: 'range',
93
111
}
94
112
},
113
+ methods: {
114
+ formatDate(date) {
115
+ const text = `${date.getFullYear()}-${String(date.getMonth() + 1).padStart(2, '0')}-${String(date.getDate()).padStart(2, '0')}`
116
+ if (this.type === 'range') {
117
+ return text
118
+ }
119
+ return `${text} ${String(date.getHours()).padStart(2, '0')}:${String(date.getMinutes()).padStart(2, '0')}`
120
+ },
121
+ },
95
122
}
96
123
</script>
124
+
125
+ <style scoped>
126
+ .type-select {
127
+ display: flex;
128
+ flex-direction: row;
129
+ flex-wrap: wrap;
130
+ }
131
+ </style>
97
132
```
98
133
99
134
### Time zone aware date picker
0 commit comments