-
Notifications
You must be signed in to change notification settings - Fork 10
/
px-rangepicker-content.html
226 lines (213 loc) · 6.62 KB
/
px-rangepicker-content.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
<!--
Copyright (c) 2018, General Electric
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<link rel="import" href="../polymer/polymer.html"/>
<link rel="import" href="../px-datetime-common/px-datetime-range-behavior.html"/>
<link rel="import" href="../px-datetime-range-panel/px-datetime-range-panel.html"/>
<link rel="import" href="../px-datetime-common/px-datetime-button-behavior.html"/>
<link rel="import" href="../iron-dropdown/iron-dropdown.html"/>
<link rel="import" href="css/px-rangepicker-content-styles.html"/>
<!--
We needed to split the rangepicker into two different components
because of the way we hoist the panel
-->
<dom-module id="px-rangepicker-content">
<template>
<style include="px-rangepicker-content-styles"></style>
<iron-dropdown
id="dropdown"
opened="{{opened}}"
vertical-align="auto"
horizontal-align="auto"
scroll-action="{{scrollAction}}"
dynamic-align
vertical-offset="50"
position-target="[[positionTarget]]">
<px-datetime-range-panel
id="panel"
time-is-valid="{{timeIsValid}}"
slot="dropdown-content"
class$="{{_handleIsValid(isValid)}}"
from-moment="{{fromMoment}}"
to-moment="{{toMoment}}"
time-format="{{timeFormat}}"
hide-time="{{hideTime}}"
hide-presets="{{hidePresets}}"
show-buttons="{{showButtons}}"
block-future-dates="{{blockFutureDates}}"
block-past-dates="{{blockPastDates}}"
preset-ranges="{{presetRanges}}"
time-zone="[[timeZone]]"
day-week-start-index="[[dayWeekStartIndex]]"
resources="[[resources]]"
language="[[language]]"
formats="[[formats]]"
min-date="[[minDate]]"
max-date="[[maxDate]]">
</px-datetime-range-panel>
</iron-dropdown>
</template>
</dom-module>
<script>
Polymer({
is: 'px-rangepicker-content',
behaviors: [
PxDatetimeBehavior.TempRange,
PxDatetimeBehavior.Buttons
],
properties: {
/**
* Whether the panel is opened
*/
opened: {
type: Boolean,
notify: true
},
/**
* Moment format used to format the date
*/
dateFormat: {
type: String
},
/**
* Moment format used to format the time
*/
timeFormat: {
type: String
},
/**
* Whether to allow time selection as well in this date picker
*/
hideTime: {
type: Boolean
},
/**
* Whether to show the preset date/time ranges
*/
hidePresets: {
type: Boolean
},
/**
* Controls whether the calendar/clock icon should be hidden
*/
hideIcon: {
type: Boolean
},
/**
* Whether to allow the range field to wrap at smaller screen resolutions / parent container sizes.
*/
allowWrap: {
type: Boolean
},
/**
* This will remove the `to` inbetween the fields and
* add titles above the fields. This allows for a
* more flexable design.
*/
showFieldTitles: {
type: Boolean
},
/**
* Controls if the page can be scrolled when the
* panel is open.
* Sets the `scrollAction` property on `iron-dropdown`
*
* lock - blocks scrolling from happening
* refit - computes the new position of the panel
* cancel - causes the overlay to close
*/
scrollAction: {
type: String,
reflectToAttribute: true
},
/**
* Whether the currently selected date is valid
*/
isValid: {
type: Boolean,
observer: '_updatedStyleOnValid'
},
/**
* Whether the currently selected date is valid
*/
timeIsValid: {
type: Boolean
},
/**
* Boolean stating if the range field is required.
* Will result in an error if left blank.
*/
required: {
type: Boolean
},
/**
* Hides the validation messages if set to true
*/
hideValidationMessages: {
type: Boolean
},
/**
* Timezone display format
* - 'dropdown': shows the timezone as a dropdown with which the user can select a different timezone. Contains only a subset of all timezones.
* - 'extendedDropdown': shows the timezone as a dropdown with which user can select a different timezone. Contains all existing timezones (588 total).
* - 'text': shows the timezone as text, non-editable.
* - 'abbreviatedText': shows the timezone as abbreviated text, non-editable (e.g. UTC, PST, EST).
*/
showTimeZone: {
type: String
},
/**
* The preset date/time ranges to be displayed.
*
* @default Last 7 Days + This Month + Last Month
*/
presetRanges: {
type: Object
},
positionTarget: HTMLElement
},
/**
* Opens the calendar if closed, closes it if opened
* called in `px-rangepicker.html`
*/
_toggleBoxOpen: function() {
this.$.dropdown.toggle();
},
/**
* Sets the `allowApply` prop on `px-datetime-range-panel`
* called in `px-rangepicker.html`
*/
_handleValidation: function (isValid) {
this.$.panel.allowApply = isValid;
},
/**
* helper function to added the invalid class on the range panel
* if the rangepicker is invalid
*/
_handleIsValid: function(isValid) {
return isValid ? "" : "invalid";
},
/**
* needed for polymer 1 only.
* The implementation of the css-custom-properties is different form polymer 1 to polymer 2.
* In polymer 1 css-custom-properties are not always dynamic. In this specific case when
* the `invalid` class is applied to `px-datetime-range-panel`, I want the css variables in
* `px-calendar-picker` to update.
* I am forcing an `updateStyles` so that the styles cross the tree will be reapplied.
* This allows for the new css-variables to be applied to the sub-component. It is
* generally a last resort to for `updateStyles`.
*/
_updatedStyleOnValid: function() {
this.updateStyles();
}
});
</script>