-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathConnectedDatePicker.js
166 lines (151 loc) · 4.7 KB
/
ConnectedDatePicker.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
import DatePicker from 'element-ui/lib/date-picker'
import noop from 'lodash/noop'
import get from 'lodash/get'
import camelCase from 'lodash/camelCase'
import ConnectedControlMixin from '../mixins/ConnectedControl'
/**
* DatePicker Component connected to @detools/vue-form
* @see http://element.eleme.io/#/en-US/component/date-picker#date-formats
*
* @param {Object} props Passed props
* @param {Boolean} readonly [false] whether DatePicker is read only
* @param {Boolean} disabled [false] whether DatePicker is disabled
* @param {Enum} size (large/small/mini) size of input
* @param {Boolean} editable [true] whether DatePicker is editable
* @param {Boolean} clearable whether to show clear button
* @param {String} placeholder only in non-range mode
* @param {String} startPlaceholder for the start date in range mode
* @param {String} endPlaceholder for the end date in range mode
* @param {Enum} type (year/month/date/dates/datetime/week/datetimerange/daterange) [date] type
* @param {String} format [yyyy-MM-dd] format of the displayed value in the input box
* @param {Enum} align (left/center/right) alignment
* @param {Object} pickerOptions additional options, see — PickerOptions
* @param {String} rangeSeparator [-] range-separator
* @param {Date} defaulValue (anything accepted by new Date()) default date of the calendar
* @param {Array<String>} defaultTime default time of the calendar
* @param {String} valueFormat [Date] format of binding value
* @param {String} name same as "native" in native input
*
* PickerOptions
* @param {Array<Object>} shortcuts a { text, onClick } shortcut options, see — Shortcuts
* @param {Function} disabledDate returns a boolean — disabled date or not
* @param {Number} firstDayOfWeek first day of week
* @param {Function} onPick a callback that triggers when the selected date is changed
*
* Shortcuts
* @param {String} text title of the shortcut
* @param {Function} onClick callback on that click
*/
const ConnectedDatePicker = {
props: {
name: {
type: String,
required: true,
},
value: [Date, String, Number],
readonly: Boolean,
disabled: Boolean,
size: String,
editable: {
type: Boolean,
default: true,
},
clearable: Boolean,
placeholder: String,
startPlaceholder: String,
endPlaceholder: String,
type: String,
format: {
type: String,
default: 'M/d/yyyy',
},
align: String,
popperClass: String,
pickerOptions: Object,
rangeSeparator: String,
defaultValue: [Date, String, Number],
defaultTime: String,
valueFormat: {
type: String,
default: 'yyyy-MM-dd',
},
unlinkPanels: Boolean,
prefixIcon: String,
clearIcon: String,
validators: Array,
asyncValidators: Array,
handleFocus: {
type: Function,
default: noop,
},
handleBlur: {
type: Function,
default: noop,
},
handleChange: {
type: Function,
default: noop,
},
handleClear: {
type: Function,
default: noop,
},
},
mixins: [ConnectedControlMixin],
updated() {
if (!this.picker) {
this.picker = get(this.$refs, 'datepicker.picker')
if (this.picker) {
this.picker.$on('pick', this.handleFieldClear)
}
}
},
beforeUnmount() {
if (this.picker) {
this.picker.$off('pick', this.handleFieldClear)
}
},
methods: {
handleFieldClear(value) {
if (value === null) {
this.handleClear()
}
},
renderComponent(value, setValue) {
return (
<DatePicker
class={this.class}
name={camelCase(this.name)}
value={value}
ref="datepicker"
readonly={this.readonly}
disabled={this.isFieldDisabled}
size={this.controlSize}
editable={this.editable}
clearable={this.clearable}
placeholder={this.placeholder}
start-placeholder={this.startPlaceholder}
end-placeholder={this.endPlaceholder}
type={this.type}
format={this.format}
align={this.align}
popper-class={this.popperClass}
picker-options={this.pickerOptions}
range-separator={this.rangeSeparator}
default-value={this.defaultValue}
default-time={this.defaultTime}
value-format={this.valueFormat}
unlink-panels={this.unlinkPanels}
prefix-icon={this.prefixIcon}
clear-icon={this.clearIcon}
on-input={setValue}
on-focus={this.handleFocus}
on-blur={this.handleFieldBlur}
on-change={this.handleFieldChange}
on-pick={this.handleFieldClear}
/>
)
},
},
}
export default ConnectedDatePicker