-
Notifications
You must be signed in to change notification settings - Fork 9
/
range-datepicker.js
155 lines (146 loc) · 4.49 KB
/
range-datepicker.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
import { PolymerElement } from '@polymer/polymer/polymer-element';
import { html } from '@polymer/polymer/lib/utils/html-tag';
import '@polymer/iron-flex-layout/iron-flex-layout-classes';
import RangeDatepickerBehavior from './range-datepicker-behavior';
import './range-datepicker-calendar';
/* global RangeDatepickerBehavior */
/**
* `range-datepicker`
*
* @customElement
* @polymer
* @demo demo/index.html
*/
class RangeDatepicker extends RangeDatepickerBehavior(PolymerElement) {
static get template() {
return html`
<style include="iron-flex iron-flex-alignment">
:host {
display: block;
}
#firstDatePicker {
margin-right: 16px;
}
</style>
<iron-media-query query="(max-width: 650px)" query-matches="{{narrow}}"></iron-media-query>
<dom-if if="[[!forceNarrow]]">
<template>
<dom-if if="[[!narrow]]">
<template>
<div class="layout vertical center-justified">
<div class="layout horizontal">
<range-datepicker-calendar disabled-days="[[disabledDays]]" min="[[min]]" max="[[max]]" on-new-year-is-manually-selected="_handleNewYearSelected" enable-year-change="[[enableYearChange]]" prev no-range="[[noRange]]" on-prev-month="_handlePrevMonth" hovered-date="{{_hoveredDate}}" date-to="{{dateTo}}" date-from="{{dateFrom}}" id="firstDatePicker" locale="[[locale]]" month="[[month]]" year="[[year]]">
</range-datepicker-calendar>
<range-datepicker-calendar disabled-days="[[disabledDays]]" min="[[min]]" max="[[max]]" on-new-year-is-manually-selected="_handleNewYearSelected" enable-year-change="[[enableYearChange]]" next no-range="[[noRange]]" on-next-month="_handleNextMonth" hovered-date="{{_hoveredDate}}" date-to="{{dateTo}}" date-from="{{dateFrom}}" locale="[[locale]]" month="[[_monthPlus]]" year="[[_yearPlus]]">
</range-datepicker-calendar>
</div>
</div>
</template>
</dom-if>
</template>
</dom-if>
<dom-if if="[[_isNarrow(forceNarrow, narrow)]]">
<template>
<range-datepicker-calendar disabled-days="[[disabledDays]]" min="[[min]]" max="[[max]]" on-new-year-is-manually-selected="_handleNewYearSelected" enable-year-change="[[enableYearChange]]" no-range="[[noRange]]" narrow="[[_isNarrow(forceNarrow, narrow)]]" hovered-date="{{_hoveredDate}}" date-to="{{dateTo}}" date-from="{{dateFrom}}" locale="[[locale]]" prev next month="[[month]]" year="[[year]]">
</range-datepicker-calendar>
</template>
</dom-if>
`;
}
static get is() {
return 'range-datepicker';
}
static get properties() {
return {
/**
* If setted only one date can be selected.
*/
noRange: {
type: Boolean,
value: false,
observer: '_noRangeChanged',
},
/**
* Force display one month.
*/
forceNarrow: {
type: Boolean,
value: false,
},
/**
* If true, only one month is displayed.
*/
narrow: {
type: Boolean,
value: false,
notify: true,
},
/**
* Set locale of the calendar.
* Default is 'en'.
*/
locale: {
type: String,
value: 'en',
observer: '_localeChanged',
},
/**
* Set month.
* Format is MM (example: 07 for July, 12 for january).
* Default is current month.
*/
month: String,
_monthPlus: String,
_yearPlus: Number,
/**
* Set year.
* Default is current year.
*/
year: String,
/**
* Date from.
* Format is Unix timestamp.
*/
dateFrom: {
type: String,
notify: true,
},
/**
* Date to.
* Format is Unix timestamp.
*/
dateTo: {
type: String,
notify: true,
},
/**
* Current hovered date.
* Format is Unix timestamp.
*/
_hoveredDate: String,
enableYearChange: {
type: Boolean,
value: false,
},
/**
* Minimal date.
* Format is Unix timestamp.
*/
min: Number,
/**
* Maximal date.
* Format is Unix timestamp.
*/
max: Number,
/**
* Array of disabled days.
* Format is Unix timestamp.
*/
disabledDays: Array,
};
}
static get observers() {
return ['_monthChanged(month, year)'];
}
}
window.customElements.define(RangeDatepicker.is, RangeDatepicker);