1
1
import Vue from '../../vue'
2
2
import { NAME_FORM_DATEPICKER } from '../../constants/components'
3
3
import {
4
- CALENDAR_LONG ,
5
- CALENDAR_NARROW ,
6
- CALENDAR_SHORT ,
7
- DATE_FORMAT_NUMERIC
8
- } from '../../constants/date'
9
- import { arrayIncludes } from '../../utils/array'
10
- import { BVFormBtnLabelControl , dropdownProps } from '../../utils/bv-form-btn-label-control'
4
+ BVFormBtnLabelControl ,
5
+ props as BVFormBtnLabelControlProps
6
+ } from '../../utils/bv-form-btn-label-control'
11
7
import { makePropsConfigurable } from '../../utils/config'
12
8
import { createDate , constrainDate , formatYMD , parseYMD } from '../../utils/date'
13
9
import { attemptBlur , attemptFocus } from '../../utils/dom'
14
10
import { isUndefinedOrNull } from '../../utils/inspect'
15
- import { pick } from '../../utils/object'
11
+ import { pick , omit } from '../../utils/object'
12
+ import { pluckProps } from '../../utils/props'
16
13
import idMixin from '../../mixins/id'
17
14
import { BButton } from '../button/button'
18
- import { BCalendar , props as calendarProps } from '../calendar/calendar'
15
+ import { BCalendar , props as BCalendarProps } from '../calendar/calendar'
19
16
import { BIconCalendar , BIconCalendarFill } from '../../icons/icons'
20
17
21
18
// --- Main component ---
@@ -30,100 +27,16 @@ export const BFormDatepicker = /*#__PURE__*/ Vue.extend({
30
27
} ,
31
28
props : makePropsConfigurable (
32
29
{
33
- value : {
34
- type : [ String , Date ] ,
35
- default : null
36
- } ,
37
- valueAsDate : {
38
- type : Boolean ,
39
- default : false
40
- } ,
30
+ ...BCalendarProps ,
31
+ ...omit ( BVFormBtnLabelControlProps , [ 'id' , 'value' , 'formattedValue' , 'rtl' , 'lang' ] ) ,
41
32
resetValue : {
42
33
type : [ String , Date ]
43
34
// default: null
44
35
} ,
45
- initialDate : {
46
- // This specifies the calendar year/month/day that will be shown when
47
- // first opening the datepicker if no v-model value is provided
48
- // Default is the current date (or `min`/`max`)
49
- // Passed directly to <b-calendar>
50
- type : [ String , Date ]
51
- // default: null
52
- } ,
53
- placeholder : {
54
- type : String
55
- // Defaults to `labelNoDateSelected` from calendar context
56
- // default: null
57
- } ,
58
- size : {
59
- type : String
60
- // default: null
61
- } ,
62
- min : {
63
- type : [ String , Date ]
64
- // default: null
65
- } ,
66
- max : {
67
- type : [ String , Date ]
68
- // default: null
69
- } ,
70
- disabled : {
71
- type : Boolean ,
72
- default : false
73
- } ,
74
- readonly : {
75
- type : Boolean ,
76
- default : false
77
- } ,
78
- required : {
79
- // If true adds the `aria-required` attribute
80
- type : Boolean ,
81
- default : false
82
- } ,
83
- name : {
84
- type : String
85
- // default: null
86
- } ,
87
- form : {
88
- type : String
89
- // default: null
90
- } ,
91
- state : {
92
- // Tri-state prop: `true`, `false` or `null`
93
- type : Boolean ,
94
- default : null
95
- } ,
96
- dateDisabledFn : {
97
- type : Function
98
- // default: null
99
- } ,
100
36
noCloseOnSelect : {
101
37
type : Boolean ,
102
38
default : false
103
39
} ,
104
- hideHeader : {
105
- type : Boolean ,
106
- default : false
107
- } ,
108
- showDecadeNav : {
109
- // When `true` enables the decade navigation buttons
110
- type : Boolean ,
111
- default : false
112
- } ,
113
- locale : {
114
- type : [ String , Array ]
115
- // default: null
116
- } ,
117
- startWeekday : {
118
- // `0` (Sunday), `1` (Monday), ... `6` (Saturday)
119
- // Day of week to start calendar on
120
- type : [ Number , String ] ,
121
- default : 0
122
- } ,
123
- direction : {
124
- type : String
125
- // default: null
126
- } ,
127
40
buttonOnly : {
128
41
type : Boolean ,
129
42
default : false
@@ -138,12 +51,6 @@ export const BFormDatepicker = /*#__PURE__*/ Vue.extend({
138
51
type : String ,
139
52
default : '270px'
140
53
} ,
141
- ...pick ( calendarProps , [ 'selectedVariant' , 'todayVariant' , 'navButtonVariant' ] ) ,
142
- noHighlightToday : {
143
- // Disable highlighting today's date
144
- type : Boolean ,
145
- default : false
146
- } ,
147
54
todayButton : {
148
55
type : Boolean ,
149
56
default : false
@@ -180,62 +87,11 @@ export const BFormDatepicker = /*#__PURE__*/ Vue.extend({
180
87
type : String ,
181
88
default : 'outline-secondary'
182
89
} ,
183
- dateInfoFn : {
184
- // Passed through to b-calendar
185
- type : Function
186
- // default: undefined
187
- } ,
188
- // Labels for buttons and keyboard shortcuts
189
- // These pick BCalendar global config if no BFormDate global config
190
- ...pick ( calendarProps , [
191
- 'labelPrevDecade' ,
192
- 'labelPrevYear' ,
193
- 'labelPrevMonth' ,
194
- 'labelCurrentMonth' ,
195
- 'labelNextMonth' ,
196
- 'labelNextYear' ,
197
- 'labelToday' ,
198
- 'labelSelected' ,
199
- 'labelNoDateSelected' ,
200
- 'labelCalendar' ,
201
- 'labelNav' ,
202
- 'labelHelp'
203
- ] ) ,
204
- dateFormatOptions : {
205
- // `Intl.DateTimeFormat` object
206
- // Note: This value is *not* to be placed in the global config
207
- type : Object ,
208
- default : ( ) => ( {
209
- year : DATE_FORMAT_NUMERIC ,
210
- month : CALENDAR_LONG ,
211
- day : DATE_FORMAT_NUMERIC ,
212
- weekday : CALENDAR_LONG
213
- } )
214
- } ,
215
- weekdayHeaderFormat : {
216
- // Format of the weekday names at the top of the calendar
217
- // Note: This value is *not* to be placed in the global config
218
- type : String ,
219
- // `short` is typically a 3 letter abbreviation,
220
- // `narrow` is typically a single letter
221
- // `long` is the full week day name
222
- // Although some locales may override this (i.e `ar`, etc.)
223
- default : CALENDAR_SHORT ,
224
- validator ( value ) {
225
- return arrayIncludes ( [ CALENDAR_LONG , CALENDAR_SHORT , CALENDAR_NARROW ] , value )
226
- }
227
- } ,
228
90
// Dark mode
229
91
dark : {
230
92
type : Boolean ,
231
93
default : false
232
- } ,
233
- // extra dropdown stuff
234
- menuClass : {
235
- type : [ String , Array , Object ]
236
- // default: null
237
- } ,
238
- ...dropdownProps
94
+ }
239
95
} ,
240
96
NAME_FORM_DATEPICKER
241
97
) ,
@@ -258,47 +114,6 @@ export const BFormDatepicker = /*#__PURE__*/ Vue.extend({
258
114
// Returns the `YYYY-MM` portion of the active calendar date
259
115
return this . activeYMD . slice ( 0 , - 3 )
260
116
} ,
261
- calendarProps ( ) {
262
- // Use self for better minification, as `this` won't
263
- // minimize and we reference it many times below
264
- const self = this
265
- return {
266
- hidden : ! self . isVisible ,
267
- value : self . localYMD ,
268
- min : self . min ,
269
- max : self . max ,
270
- initialDate : self . initialDate ,
271
- readonly : self . readonly ,
272
- disabled : self . disabled ,
273
- locale : self . locale ,
274
- startWeekday : self . startWeekday ,
275
- direction : self . direction ,
276
- width : self . calendarWidth ,
277
- dateDisabledFn : self . dateDisabledFn ,
278
- selectedVariant : self . selectedVariant ,
279
- todayVariant : self . todayVariant ,
280
- navButtonVariant : self . navButtonVariant ,
281
- dateInfoFn : self . dateInfoFn ,
282
- hideHeader : self . hideHeader ,
283
- showDecadeNav : self . showDecadeNav ,
284
- noHighlightToday : self . noHighlightToday ,
285
- labelPrevDecade : self . labelPrevDecade ,
286
- labelPrevYear : self . labelPrevYear ,
287
- labelPrevMonth : self . labelPrevMonth ,
288
- labelCurrentMonth : self . labelCurrentMonth ,
289
- labelNextMonth : self . labelNextMonth ,
290
- labelNextYear : self . labelNextYear ,
291
- labelNextDecade : self . labelNextDecade ,
292
- labelToday : self . labelToday ,
293
- labelSelected : self . labelSelected ,
294
- labelNoDateSelected : self . labelNoDateSelected ,
295
- labelCalendar : self . labelCalendar ,
296
- labelNav : self . labelNav ,
297
- labelHelp : self . labelHelp ,
298
- dateFormatOptions : self . dateFormatOptions ,
299
- weekdayHeaderFormat : self . weekdayHeaderFormat
300
- }
301
- } ,
302
117
computedLang ( ) {
303
118
return ( this . localLocale || '' ) . replace ( / - u - .* $ / i, '' ) || null
304
119
} ,
@@ -401,10 +216,7 @@ export const BFormDatepicker = /*#__PURE__*/ Vue.extend({
401
216
}
402
217
} ,
403
218
render ( h ) {
404
- const $scopedSlots = this . $scopedSlots
405
- const localYMD = this . localYMD
406
- const disabled = this . disabled
407
- const readonly = this . readonly
219
+ const { localYMD, disabled, readonly, dark, $props, $scopedSlots } = this
408
220
const placeholder = isUndefinedOrNull ( this . placeholder )
409
221
? this . labelNoDateSelected
410
222
: this . placeholder
@@ -479,7 +291,11 @@ export const BFormDatepicker = /*#__PURE__*/ Vue.extend({
479
291
key : 'calendar' ,
480
292
ref : 'calendar' ,
481
293
staticClass : 'b-form-date-calendar w-100' ,
482
- props : this . calendarProps ,
294
+ props : {
295
+ ...pluckProps ( BCalendarProps , $props ) ,
296
+ value : localYMD ,
297
+ hidden : ! this . isVisible
298
+ } ,
483
299
on : {
484
300
selected : this . onSelected ,
485
301
input : this . onInput ,
@@ -504,16 +320,14 @@ export const BFormDatepicker = /*#__PURE__*/ Vue.extend({
504
320
ref : 'control' ,
505
321
staticClass : 'b-form-datepicker' ,
506
322
props : {
507
- // This adds unneeded props, but reduces code size:
508
- ...this . $props ,
509
- // Overridden / computed props
323
+ ...pluckProps ( BVFormBtnLabelControlProps , $props ) ,
510
324
id : this . safeId ( ) ,
325
+ value : localYMD ,
326
+ formattedValue : localYMD ? this . formattedValue : '' ,
327
+ placeholder,
511
328
rtl : this . isRTL ,
512
329
lang : this . computedLang ,
513
- value : localYMD || '' ,
514
- formattedValue : localYMD ? this . formattedValue : '' ,
515
- placeholder : placeholder || '' ,
516
- menuClass : [ { 'bg-dark' : ! ! this . dark , 'text-light' : ! ! this . dark } , this . menuClass ]
330
+ menuClass : [ { 'bg-dark' : ! ! dark , 'text-light' : ! ! dark } , this . menuClass ]
517
331
} ,
518
332
on : {
519
333
show : this . onShow ,
0 commit comments