forked from vaadin/vaadin-date-picker
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvaadin-date-picker.html
342 lines (294 loc) · 10.9 KB
/
vaadin-date-picker.html
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
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
<!--
@license
Copyright (c) 2016 Vaadin Ltd.
This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
-->
<!--
`<vaadin-date-picker>` is a date selection field which includes a scrollable
month calendar view.
```html
<vaadin-date-picker label="Birthday"></vaadin-date-picker>
```
```js
datePicker.value = '2016-03-02';
```
When the selected `value` is changed, a `value-changed` event is triggered.
This element is also extended with the `IronFormElementBehavior` to
enable usage within an `iron-form`.
### Styling
The following custom properties and mixins are available for styling:
Custom property | Description | Default
----------------|-------------|----------
`--vaadin-date-picker-overlay` | Mixin applied to the overlay | `{}`
`--vaadin-date-picker-yearscroller` | Mixin applied to the year scroller | `{}`
`--vaadin-date-picker-yearscroller-indicator` | Mixin applied to the year scroller indicator | `{}`
`--vaadin-date-picker-calendar-icon` | Mixin applied to the calendar icon | `{}`
`--vaadin-date-picker-clear-icon` | Mixin applied to the clear icon | `{}`
`--vaadin-date-picker-scrollers-fade` | Mixin applied to the scrollers fade element | `{}`
`--vaadin-date-picker-header` | Mixin applied to the picker header | `{}`
`--vaadin-date-picker-toolbar` | Mixin applied to the picker toolbar | `{}`
`--vaadin-date-picker-toolbar-icon` | Mixin applied to the picker toolbar icon | `{}`
`--vaadin-date-picker-footer` | Mixin applied to the picker footer | `{}`
`--vaadin-date-picker-calendar` | Mixin applied to a month calendar element | `{}`
`--vaadin-date-picker-calendar-title` | Mixin applied to a month calendar title | `{}`
`--vaadin-date-picker-calendar-cell` | Mixin applied to a month calendar cell | `{}`
`--vaadin-date-picker-calendar-date-cell` | Mixin applied to a month calendar date cell | `{}`
`--vaadin-date-picker-calendar-weekday-cell` | Mixin applied to a month calendar weekday cell | `{}`
`--vaadin-date-picker-calendar-cell-today` | Mixin applied to a month calendar today cell | `{}`
`--vaadin-date-picker-calendar-cell-selected` | Mixin applied to a month calendar selected cell | `{}`
`--vaadin-date-picker-calendar-cell-focused` | Mixin applied to a month calendar focused cell | `{}`
`--vaadin-date-picker-calendar-cell-today-selected` | Mixin applied to a month calendar selected today cell | `{}`
`--vaadin-date-picker-calendar-cell-disabled` | Mixin applied to a month calendar disabled cell | `{}`
`--vaadin-date-picker-calendar-weeknumber-cell` | Mixin applied to a month calendar weeknumber cell | `{}`
`--vaadin-date-picker-calendar-focused-cell-focused` | Mixin applied to a focused month calendar focused cell | `{}`
See paper-input-container documentation for styling the included input fields
If you want to replace the default input field with a custom implementation, you should use the
[`<vaadin-date-picker-light>`](#vaadin-date-picker-light) element.
@element vaadin-date-picker
@demo demo/index.html
-->
<link rel="import" href="../polymer/polymer.html">
<link rel="import" href="../iron-dropdown/iron-dropdown.html">
<link rel="import" href="../paper-input/paper-input-container.html">
<link rel="import" href="../paper-input/paper-input-error.html">
<link rel="import" href="../iron-input/iron-input.html">
<link rel="import" href="../iron-icon/iron-icon.html">
<link rel="import" href="../paper-ripple/paper-ripple.html">
<link rel="import" href="../iron-media-query/iron-media-query.html">
<link rel="import" href="vaadin-date-picker-overlay.html">
<link rel="import" href="vaadin-date-picker-behavior.html">
<link rel="import" href="vaadin-date-picker-helper.html">
<link rel="import" href="vaadin-date-picker-icons.html">
<dom-module id="vaadin-date-picker">
<template>
<style>
:host {
display: block;
}
:host([opened]) {
pointer-events: auto;
}
#overlay {
height: 100vh;
width: 420px;
}
#inputcontainer,
#inputcontainer input {
cursor: pointer;
}
#inputcontainer:focus {
outline: none;
}
paper-input-container div[suffix] {
box-sizing: content-box;
position: absolute;
right: -4px;
bottom: -4px;
width: 24px;
height: 24px;
padding: 4px;
text-align: center;
}
paper-input-container iron-icon {
fill: rgba(0, 0, 0, .26);
cursor: pointer;
--iron-icon-width: 20px;
--iron-icon-height: 20px;
margin-top: -1px;
transition: fill 0.2s;
}
paper-input-container paper-ripple {
color: rgba(0, 0, 0, .54);
}
:host([opened]) paper-input-container {
--paper-input-container-underline-focus: {
-webkit-transform: none;
transform: none;
}
}
paper-input-container iron-icon:hover,
:host([opened]) paper-input-container iron-icon {
fill: rgba(0, 0, 0, .54);
}
:host([opened]) paper-input-container iron-icon:hover {
fill: rgba(0, 0, 0, .86);
}
#input[no-input] {
pointer-events: none;
}
#clear {
right: 28px;
}
#clear iron-icon {
@apply(--vaadin-date-picker-clear-icon);
}
#calendar iron-icon {
@apply(--vaadin-date-picker-calendar-icon);
}
:host([disabled]) #calendar,
:host([readonly]) #calendar,
:host(:not([has-value])) #clear,
:host([readonly]) #clear,
:host([disabled]) #clear {
display: none;
}
#input {
box-sizing: border-box;
padding-right: 28px;
}
#input::-ms-clear {
display: none;
}
:host([opened][has-value]) #input {
padding-right: 60px;
margin-right: -32px;
}
</style>
<paper-input-container id="inputcontainer"
auto-validate$="[[autoValidate]]"
invalid$="[[invalid]]"
disabled$="[[disabled]]"
role="application"
always-float-label="[[_computeAlwaysFloatLabel(placeholder)]]">
<label id="label" aria-hidden="true">[[label]]</label>
<input id="input"
is="iron-input"
autocomplete="off"
type="text"
on-focus="_focus"
value="{{_userInputValue::input}}"
name$="[[name]]"
placeholder$="[[placeholder]]"
aria-label$="[[label]]"
invalid="{{invalid}}"
required$="[[required]]"
validator="[[validator]]"
disabled$="[[disabled]]"
readonly$="[[readonly]]"
no-input$="[[_noInput]]" />
<div suffix id="clear" on-tap="_clear" role="button" aria-label$="[[i18n.clear]]">
<iron-icon icon="vaadin-date-picker:clear"></iron-icon>
<paper-ripple class="circle" center></paper-ripple>
</div>
<div suffix id="calendar" on-tap="_toggle" role="button" aria-label$="[[i18n.calendar]]" aria-expanded$="[[_getAriaExpanded(opened)]]">
<iron-icon icon="vaadin-date-picker:event"></iron-icon>
<paper-ripple class="circle" center></paper-ripple>
</div>
<template is="dom-if" if="[[errorMessage]]">
<paper-input-error aria-live="assertive">[[errorMessage]]</paper-input-error>
</template>
</paper-input-container>
<iron-dropdown
id="dropdown"
fullscreen$=[[_fullscreen]]
allow-outside-scroll
on-iron-overlay-opened="_onOverlayOpened"
on-iron-overlay-closed="_onOverlayClosed"
on-iron-overlay-canceled="_preventCancelOnComponentAccess"
opened="{{opened}}"
no-auto-focus>
<vaadin-date-picker-overlay
id="overlay" i18n="[[i18n]]"
fullscreen$="[[_fullscreen]]"
label="[[label]]"
selected-date="{{_selectedDate}}"
class="dropdown-content"
focused-date="{{_focusedDate}}"
show-week-numbers="[[showWeekNumbers]]"
min-date="[[_minDate]]"
max-date="[[_maxDate]]"
role="dialog">
</vaadin-date-picker-overlay>
</iron-dropdown>
<iron-media-query
query="[[_fullscreenMediaQuery]]"
query-matches="{{_fullscreen}}">
</iron-media-query>
</template>
<script>
Polymer({
is: 'vaadin-date-picker',
behaviors: [
vaadin.elements.datepicker.DatePickerBehavior
],
properties: {
/**
* Set to true to auto-validate the input value.
*/
autoValidate: {
type: Boolean,
value: false
},
/**
* Set to true to disable this element.
*/
disabled: {
type: Boolean,
value: false,
reflectToAttribute: true
},
/**
* Set to true to make this element read-only.
*/
readonly: {
type: Boolean,
value: false,
reflectToAttribute: true
},
/**
* A placeholder string in addition to the label. If this is set, the label will always float.
*/
placeholder: String,
/**
* The error message to display when the input is invalid.
*/
errorMessage: String,
_userInputValue: String
},
observers: [
'_userInputValueChanged(_userInputValue)'
],
// TODO: revisit this in order to use validatable-behavior for both the full and
// the light component. Consider auto-validate, and validate(value) signature.
/**
* Override the IronValidatableBehavior._getValidity implementation, replacing
* it with the iron-input validation.
*/
_getValidity: function() {
var inputValid = !this._inputValue || (this._selectedDate && this._inputValue === this.i18n.formatDate(this._selectedDate));
var minMaxValid = !this._selectedDate ||
vaadin.elements.datepicker.DatePickerHelper._dateAllowed(this._selectedDate, this._minDate, this._maxDate);
return this.inputElement.validate() && inputValid && minMaxValid;
},
_clear: function(e) {
e.stopPropagation();
this.value = '';
this.close();
},
_toggle: function(e) {
e.stopPropagation();
this[this.$.dropdown.opened ? 'close' : 'open']();
},
_input: function() {
return this.$.input;
},
/**
* label and placeholder will go on top of each other if always-float-label isn't set
* This is the similar behavior as paper-input has:
* PolymerElements/paper-input/blob/d248dad17af3ee46a0701a664e0f304c1619770d/paper-input-behavior.html#L502
*/
_computeAlwaysFloatLabel: function(placeholder) {
return Boolean(placeholder);
},
set _inputValue(value) {
this.inputElement.bindValue = value;
},
get _inputValue() {
return this.inputElement.bindValue;
},
_getAriaExpanded: function(opened) {
return Boolean(opened).toString();
}
});
</script>
</dom-module>