@descope/web-components-ui 1.0.378 → 1.0.380
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/cjs/index.cjs.js +3166 -1257
- package/dist/cjs/index.cjs.js.map +1 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.esm.js +4738 -2826
- package/dist/index.esm.js.map +1 -1
- package/dist/umd/1224.js +1 -1
- package/dist/umd/1438.js +3 -3
- package/dist/umd/1612.js +1 -1
- package/dist/umd/2773.js +4 -4
- package/dist/umd/3830.js +1 -1
- package/dist/umd/3951.js +1 -1
- package/dist/umd/3966.js +319 -0
- package/dist/umd/4024.js +1 -1
- package/dist/umd/4052.js +1 -1
- package/dist/umd/4392.js +1 -1
- package/dist/umd/4525.js +1 -1
- package/dist/umd/4978.js +1 -1
- package/dist/umd/5135.js +2 -2
- package/dist/umd/5517.js +1 -1
- package/dist/umd/5778.js +275 -0
- package/dist/umd/5806.js +1 -1
- package/dist/umd/5977.js +140 -0
- package/dist/umd/5977.js.LICENSE.txt +29 -0
- package/dist/umd/63.js +4 -4
- package/dist/umd/6770.js +1 -1
- package/dist/umd/7056.js +3 -3
- package/dist/umd/7284.js +1 -1
- package/dist/umd/7541.js +449 -0
- package/dist/umd/7541.js.LICENSE.txt +17 -0
- package/dist/umd/7911.js +2 -2
- package/dist/umd/{4028.js → 8060.js} +3 -3
- package/dist/umd/8137.js +1 -1
- package/dist/umd/8191.js +2 -2
- package/dist/umd/8655.js +123 -0
- package/dist/umd/9314.js +2 -2
- package/dist/umd/9423.js +6 -6
- package/dist/umd/9562.js +1 -1
- package/dist/umd/DescopeDev.js +1 -1
- package/dist/umd/descope-apps-list-index-js.js +1 -1
- package/dist/umd/descope-avatar-index-js.js +1 -1
- package/dist/umd/descope-button-index-js.js +1 -1
- package/dist/umd/descope-combo-box-index-js.js +5 -5
- package/dist/umd/descope-date-field-descope-calendar-index-js.js +1 -0
- package/dist/umd/descope-date-field-index-js.js +1 -0
- package/dist/umd/descope-email-field-index-js.js +1 -1
- package/dist/umd/descope-grid-descope-grid-custom-column-index-js.js +2 -2
- package/dist/umd/descope-grid-descope-grid-item-details-column-index-js.js +2 -2
- package/dist/umd/descope-grid-descope-grid-selection-column-index-js.js +1 -1
- package/dist/umd/descope-grid-descope-grid-text-column-index-js.js +4 -4
- package/dist/umd/descope-new-password-index-js.js +1 -1
- package/dist/umd/descope-number-field-index-js.js +1 -1
- package/dist/umd/descope-passcode-index-js.js +1 -1
- package/dist/umd/descope-radio-group-index-js.js +1 -1
- package/dist/umd/descope-text-field-index-js.js +1 -1
- package/dist/umd/index.js +1 -1
- package/dist/umd/mapping-fields-descope-mappings-field-index-js.js +1 -1
- package/dist/umd/phone-fields-descope-phone-field-descope-phone-field-internal-index-js.js +1 -1
- package/dist/umd/phone-fields-descope-phone-field-index-js.js +1 -1
- package/dist/umd/phone-fields-descope-phone-input-box-field-descope-phone-input-box-internal-index-js.js +1 -1
- package/dist/umd/phone-fields-descope-phone-input-box-field-index-js.js +1 -1
- package/package.json +11 -5
- package/src/components/descope-combo-box/ComboBoxClass.js +7 -1
- package/src/components/descope-date-field/DateCounterClass.js +83 -0
- package/src/components/descope-date-field/DateFieldClass.js +675 -0
- package/src/components/descope-date-field/consts.js +55 -0
- package/src/components/descope-date-field/descope-calendar/CalendarClass.js +666 -0
- package/src/components/descope-date-field/descope-calendar/helpers.js +186 -0
- package/src/components/descope-date-field/descope-calendar/index.js +9 -0
- package/src/components/descope-date-field/formats.js +49 -0
- package/src/components/descope-date-field/helpers.js +72 -0
- package/src/components/descope-date-field/icons.js +14 -0
- package/src/components/descope-date-field/index.js +10 -0
- package/src/components/descope-text-field/textFieldMappings.js +2 -0
- package/src/index.cjs.js +2 -0
- package/src/index.d.ts +2 -0
- package/src/index.js +2 -1
- package/src/mixins/inputValidationMixin.js +8 -2
- package/src/mixins/portalMixin.js +6 -3
- package/src/theme/components/calendar.js +94 -0
- package/src/theme/components/dateField.js +63 -0
- package/src/theme/components/index.js +4 -0
- package/src/theme/components/inputWrapper.js +6 -0
- package/src/theme/components/textField.js +1 -0
- package/dist/umd/4746.js +0 -124
- package/dist/umd/7531.js +0 -319
- package/dist/umd/8866.js +0 -275
- package/dist/umd/9092.js +0 -1086
- package/dist/umd/9092.js.LICENSE.txt +0 -27
- package/dist/umd/descope-date-picker-index-js.js +0 -1
- package/src/components/descope-date-picker/index.js +0 -20
- /package/dist/umd/{7531.js.LICENSE.txt → 3966.js.LICENSE.txt} +0 -0
- /package/dist/umd/{8866.js.LICENSE.txt → 5778.js.LICENSE.txt} +0 -0
- /package/dist/umd/{4028.js.LICENSE.txt → 8060.js.LICENSE.txt} +0 -0
- /package/dist/umd/{4746.js.LICENSE.txt → 8655.js.LICENSE.txt} +0 -0
@@ -0,0 +1,55 @@
|
|
1
|
+
export const SUPPORTED_FORMATS = ['MM/DD/YYYY', 'DD/MM/YYYY', 'YYYY/MM/DD'];
|
2
|
+
|
3
|
+
export const DEFAULT_FORMAT = SUPPORTED_FORMATS[0];
|
4
|
+
|
5
|
+
export const NATIVE_FORMAT = 'YYYY-MM-DD';
|
6
|
+
|
7
|
+
export const YEARS_RANGE = 100;
|
8
|
+
|
9
|
+
export const DIVIDER = '/';
|
10
|
+
|
11
|
+
export const COUNTER_SUPPORTED_KEYS = [
|
12
|
+
'Backspace',
|
13
|
+
'ArrowLeft',
|
14
|
+
'ArrowRight',
|
15
|
+
'ArrowDown',
|
16
|
+
'ArrowUp',
|
17
|
+
'PageUp',
|
18
|
+
'PageDown',
|
19
|
+
'Meta',
|
20
|
+
];
|
21
|
+
|
22
|
+
export const months = [
|
23
|
+
'January',
|
24
|
+
'February',
|
25
|
+
'March',
|
26
|
+
'April',
|
27
|
+
'May',
|
28
|
+
'June',
|
29
|
+
'July',
|
30
|
+
'August',
|
31
|
+
'September',
|
32
|
+
'October',
|
33
|
+
'November',
|
34
|
+
'December',
|
35
|
+
];
|
36
|
+
|
37
|
+
export const weekdays = [
|
38
|
+
'Sunday',
|
39
|
+
'Monday',
|
40
|
+
'Tuesday',
|
41
|
+
'Wednesday',
|
42
|
+
'Thursday',
|
43
|
+
'Friday',
|
44
|
+
'Saturday',
|
45
|
+
];
|
46
|
+
|
47
|
+
export const counterConfig = {
|
48
|
+
MONTH: { id: 'month', min: 1, max: 12, placeholder: 'MM', count: 5, shiftCount: 10 },
|
49
|
+
DAY: { id: 'day', min: 1, max: 31, placeholder: 'DD', count: 5, shiftCount: 10 },
|
50
|
+
YEAR: { id: 'year', min: 0, max: 9999, placeholder: 'YYYY', count: 10, shiftCount: 100 },
|
51
|
+
};
|
52
|
+
|
53
|
+
export const BUTTON_LABEL_DONE = 'Done';
|
54
|
+
export const BUTTON_LABEL_CANCEL = 'Cancel';
|
55
|
+
export const CALENDAR_LABEL_TODAY = 'Today';
|
@@ -0,0 +1,666 @@
|
|
1
|
+
import { createBaseInputClass } from '../../../baseClasses/createBaseInputClass';
|
2
|
+
import { compose } from '../../../helpers';
|
3
|
+
import { forwardAttrs, getComponentName } from '../../../helpers/componentHelpers';
|
4
|
+
import { inputFloatingLabelStyle } from '../../../helpers/themeHelpers/resetHelpers';
|
5
|
+
import { componentNameValidationMixin, createStyleMixin, draggableMixin } from '../../../mixins';
|
6
|
+
import {
|
7
|
+
getCurrentDay,
|
8
|
+
getTimestampParts,
|
9
|
+
isValidTimestamp,
|
10
|
+
newDate,
|
11
|
+
formatTimestamp,
|
12
|
+
getCurrentTime,
|
13
|
+
getFullYear,
|
14
|
+
getMonth,
|
15
|
+
} from '../helpers';
|
16
|
+
import { arrowLeftIcon, arrowRightIcon } from '../icons';
|
17
|
+
import {
|
18
|
+
BUTTON_LABEL_CANCEL,
|
19
|
+
BUTTON_LABEL_DONE,
|
20
|
+
CALENDAR_LABEL_TODAY,
|
21
|
+
NATIVE_FORMAT,
|
22
|
+
YEARS_RANGE,
|
23
|
+
} from '../consts';
|
24
|
+
import {
|
25
|
+
createMonthView,
|
26
|
+
createInputs,
|
27
|
+
getYearOptions,
|
28
|
+
initComboBox,
|
29
|
+
ensureMonthNamesArr,
|
30
|
+
isViewVisible,
|
31
|
+
ensureWeekdayNamesArr,
|
32
|
+
truncateWeekdays,
|
33
|
+
prevMonth,
|
34
|
+
nextMonth,
|
35
|
+
} from './helpers';
|
36
|
+
import { ButtonClass } from '../../descope-button/ButtonClass';
|
37
|
+
|
38
|
+
export const componentName = getComponentName('calendar');
|
39
|
+
|
40
|
+
const observedAttrs = [
|
41
|
+
'initial-value',
|
42
|
+
'initial-year',
|
43
|
+
'initial-month',
|
44
|
+
'years-range',
|
45
|
+
'calendar-months',
|
46
|
+
'calendar-weekdays',
|
47
|
+
'calendar-label-today',
|
48
|
+
'st-host-direction',
|
49
|
+
'disabled',
|
50
|
+
'full-width',
|
51
|
+
];
|
52
|
+
|
53
|
+
const calendarUiAttrs = ['calendar-label-submit', 'calendar-label-cancel'];
|
54
|
+
|
55
|
+
const BaseInputClass = createBaseInputClass({ componentName, baseSelector: 'div' });
|
56
|
+
|
57
|
+
class RawCalendar extends BaseInputClass {
|
58
|
+
static get observedAttributes() {
|
59
|
+
return [].concat(BaseInputClass.observedAttributes || [], observedAttrs, calendarUiAttrs);
|
60
|
+
}
|
61
|
+
|
62
|
+
// preview state timestamp
|
63
|
+
preview;
|
64
|
+
|
65
|
+
// value timestamp
|
66
|
+
timestamp;
|
67
|
+
|
68
|
+
constructor() {
|
69
|
+
super();
|
70
|
+
|
71
|
+
this.attachShadow({ mode: 'open' }).innerHTML = `
|
72
|
+
<style>
|
73
|
+
:host {
|
74
|
+
display: inline-block;
|
75
|
+
box-sizing: border-box;
|
76
|
+
max-width: 100%;
|
77
|
+
user-select: none;
|
78
|
+
-webkit-user-select: none;
|
79
|
+
}
|
80
|
+
|
81
|
+
:host ::slotted {
|
82
|
+
padding: 0;
|
83
|
+
}
|
84
|
+
|
85
|
+
[data-toggle-calendar] {
|
86
|
+
cursor: pointer;
|
87
|
+
display: flex;
|
88
|
+
align-self: center;
|
89
|
+
z-index: 1;
|
90
|
+
}
|
91
|
+
|
92
|
+
[data-disabled="true"] {
|
93
|
+
pointer-events: none;
|
94
|
+
}
|
95
|
+
|
96
|
+
.calendar .day {
|
97
|
+
display: flex;
|
98
|
+
align-items: center;
|
99
|
+
justify-content: center;
|
100
|
+
}
|
101
|
+
|
102
|
+
.nav {
|
103
|
+
display: flex;
|
104
|
+
align-items: center;
|
105
|
+
box-sizing: border-box;
|
106
|
+
}
|
107
|
+
|
108
|
+
.selectors,
|
109
|
+
.selectors span {
|
110
|
+
display: flex;
|
111
|
+
justify-content: center;
|
112
|
+
}
|
113
|
+
|
114
|
+
descope-button {
|
115
|
+
padding: 0;
|
116
|
+
${ButtonClass.cssVarList.horizontalPadding}: 0;
|
117
|
+
${ButtonClass.cssVarList.verticalPadding}: 0;
|
118
|
+
${ButtonClass.cssVarList.outlineWidth}: 0;
|
119
|
+
}
|
120
|
+
|
121
|
+
${inputFloatingLabelStyle()}
|
122
|
+
</style>
|
123
|
+
<div>
|
124
|
+
<nav class="nav top-nav">
|
125
|
+
<div class="nav-prev">
|
126
|
+
<descope-icon></descope-icon>
|
127
|
+
</div>
|
128
|
+
<div class="selectors"></div>
|
129
|
+
<div class="nav-next">
|
130
|
+
<descope-icon></descope-icon>
|
131
|
+
</div>
|
132
|
+
</nav>
|
133
|
+
<div class="calendar"></div>
|
134
|
+
<nav class="nav bottom-nav">
|
135
|
+
<descope-button class="cancel-button" variant="link" mode="primary">Cancel</descope-button>
|
136
|
+
<descope-button class="submit-button" variant="link" mode="primary" disabled="true">Done</descope-button>
|
137
|
+
</nav>
|
138
|
+
</div>
|
139
|
+
`;
|
140
|
+
}
|
141
|
+
|
142
|
+
set value(val) {
|
143
|
+
if (!val) return;
|
144
|
+
|
145
|
+
const timestamp = newDate(val).getTime();
|
146
|
+
|
147
|
+
if (!isValidTimestamp(timestamp) || timestamp === this.timestmap) {
|
148
|
+
return;
|
149
|
+
}
|
150
|
+
|
151
|
+
this.timestamp = timestamp;
|
152
|
+
|
153
|
+
this.renderCalendar();
|
154
|
+
}
|
155
|
+
|
156
|
+
get value() {
|
157
|
+
return this.timestamp ? formatTimestamp(this.timestamp, NATIVE_FORMAT) : '';
|
158
|
+
}
|
159
|
+
|
160
|
+
get isSelectedView() {
|
161
|
+
return isViewVisible(this.preview, this.timestamp);
|
162
|
+
}
|
163
|
+
|
164
|
+
get isTodayView() {
|
165
|
+
return isViewVisible(getCurrentTime(), this.preview);
|
166
|
+
}
|
167
|
+
|
168
|
+
get monthNames() {
|
169
|
+
return ensureMonthNamesArr(this.getAttribute('calendar-months'));
|
170
|
+
}
|
171
|
+
|
172
|
+
get weekdayNames() {
|
173
|
+
return ensureWeekdayNamesArr(this.getAttribute('calendar-weekdays'));
|
174
|
+
}
|
175
|
+
|
176
|
+
get hasYearValue() {
|
177
|
+
return !!this.yearInput.value;
|
178
|
+
}
|
179
|
+
|
180
|
+
get hasMonthValue() {
|
181
|
+
return !!this.monthInput.value;
|
182
|
+
}
|
183
|
+
|
184
|
+
get yearsRange() {
|
185
|
+
const range = this.getAttribute('years-range')?.split('-');
|
186
|
+
|
187
|
+
if (range?.length === 2) {
|
188
|
+
const [start, end] = range.map(Number);
|
189
|
+
if (start <= end) return [start, end];
|
190
|
+
}
|
191
|
+
|
192
|
+
const currentYear = newDate().getFullYear();
|
193
|
+
|
194
|
+
return [currentYear, currentYear + YEARS_RANGE];
|
195
|
+
}
|
196
|
+
|
197
|
+
init() {
|
198
|
+
super.init?.();
|
199
|
+
this.initCalendar();
|
200
|
+
this.renderCalendar();
|
201
|
+
}
|
202
|
+
|
203
|
+
initCalendar() {
|
204
|
+
this.calendar = this.shadowRoot.querySelector('.calendar');
|
205
|
+
|
206
|
+
this.navPrevEle = this.shadowRoot.querySelector('.nav-prev');
|
207
|
+
this.navNextEle = this.shadowRoot.querySelector('.nav-next');
|
208
|
+
this.submitButton = this.shadowRoot.querySelector('.submit-button');
|
209
|
+
this.cancelButton = this.shadowRoot.querySelector('.cancel-button');
|
210
|
+
|
211
|
+
this.initInputs();
|
212
|
+
this.initNav();
|
213
|
+
|
214
|
+
this.addEventListener('day-changed', () => this.submitButton.removeAttribute('disabled'));
|
215
|
+
// This is a workaround for descope-components inside Vaadin's Popover component.
|
216
|
+
// When we sync attributes, the `disabled` attribute is being compared to the attribute
|
217
|
+
// on Vaadin component; since the Vaadin component has no `disabled` attribute, we sync
|
218
|
+
// that back to our component. This happens when using Popover, and for specific attributes,
|
219
|
+
// namely `disabled`. This is pending a more generic fix in the way we sync attibutes.
|
220
|
+
this.submitButton.shadowRoot.querySelector('vaadin-button').setAttribute('disabled', 'true');
|
221
|
+
}
|
222
|
+
|
223
|
+
initInputs() {
|
224
|
+
const ele = createInputs(this.monthNames, this.yearsRange);
|
225
|
+
this.shadowRoot.querySelector('.selectors').appendChild(ele);
|
226
|
+
|
227
|
+
this.monthInput = initComboBox(
|
228
|
+
this.shadowRoot.querySelector('.month-input'),
|
229
|
+
this.onMonthChange.bind(this),
|
230
|
+
this.onMonthInputBlur.bind(this)
|
231
|
+
);
|
232
|
+
|
233
|
+
this.yearInput = initComboBox(
|
234
|
+
this.shadowRoot.querySelector('.year-input'),
|
235
|
+
this.onYearChange.bind(this),
|
236
|
+
this.onYearInputBlur.bind(this)
|
237
|
+
);
|
238
|
+
|
239
|
+
[this.monthInput, this.yearInput].forEach((selector) =>
|
240
|
+
forwardAttrs(this, selector, {
|
241
|
+
includeAttrs: ['disabled', 'size', 'st-host-direction'],
|
242
|
+
})
|
243
|
+
);
|
244
|
+
}
|
245
|
+
|
246
|
+
initNav() {
|
247
|
+
this.navPrevEle.addEventListener('click', this.navPrevMonth.bind(this));
|
248
|
+
this.navNextEle.addEventListener('click', this.navNextMonth.bind(this));
|
249
|
+
this.cancelButton.addEventListener('click', this.onCancel.bind(this));
|
250
|
+
this.submitButton.addEventListener('click', this.onSubmit.bind(this));
|
251
|
+
|
252
|
+
[this.navPrevEle, this.navNextEle].forEach((btn) =>
|
253
|
+
forwardAttrs(this, btn, {
|
254
|
+
includeAttrs: ['size'],
|
255
|
+
})
|
256
|
+
);
|
257
|
+
|
258
|
+
this.shadowRoot.querySelector('.nav-next descope-icon').innerHTML = arrowRightIcon;
|
259
|
+
this.shadowRoot.querySelector('.nav-prev descope-icon').innerHTML = arrowLeftIcon;
|
260
|
+
}
|
261
|
+
|
262
|
+
onSubmit() {
|
263
|
+
if (this.isDisabled) return;
|
264
|
+
if (!this.value) return;
|
265
|
+
this.dispatchEvent(new CustomEvent('date-submit', { detail: newDate(this.preview) }));
|
266
|
+
}
|
267
|
+
|
268
|
+
onCancel() {
|
269
|
+
if (this.isDisabled) return;
|
270
|
+
this.dispatchEvent(new CustomEvent('cancel'));
|
271
|
+
this.dispatchEvent(new CustomEvent('date-cancel'));
|
272
|
+
this.clearSelectedDay();
|
273
|
+
}
|
274
|
+
|
275
|
+
clearSelectedDay() {
|
276
|
+
this.getSelectedDayEle()?.removeAttribute('data-selected');
|
277
|
+
this.submitButton.setAttribute('disabled', 'true');
|
278
|
+
this.timestamp = '';
|
279
|
+
}
|
280
|
+
|
281
|
+
updateInputs() {
|
282
|
+
if (this.yearInput && this.monthInput) {
|
283
|
+
const timestamp = this.preview || getCurrentTime();
|
284
|
+
const year = getFullYear(timestamp);
|
285
|
+
const month = getMonth(timestamp);
|
286
|
+
this.monthInput.value = month;
|
287
|
+
// For the yearInput we update the base element directly to properly trigger the change event
|
288
|
+
// since this can be a custom value
|
289
|
+
this.yearInput.baseElement.value = year;
|
290
|
+
}
|
291
|
+
}
|
292
|
+
|
293
|
+
renderCalendar() {
|
294
|
+
const date = newDate(this.preview || getCurrentTime());
|
295
|
+
const timestamp = date.getTime();
|
296
|
+
|
297
|
+
const [year, month] = getTimestampParts(timestamp);
|
298
|
+
|
299
|
+
if (this.calendar) {
|
300
|
+
this.calendar.innerHTML = createMonthView(year, month, truncateWeekdays(this.weekdayNames));
|
301
|
+
}
|
302
|
+
|
303
|
+
Array.from(this.calendar?.querySelectorAll('.day-entry .day') || []).forEach((ele) =>
|
304
|
+
ele.addEventListener('click', this.onDayChange.bind(this))
|
305
|
+
);
|
306
|
+
|
307
|
+
this.updateInputs();
|
308
|
+
this.setSelectedDay();
|
309
|
+
this.setCurrentDay();
|
310
|
+
}
|
311
|
+
|
312
|
+
onDayChange(e) {
|
313
|
+
if (this.isDisabled) return;
|
314
|
+
const date = newDate(this.preview);
|
315
|
+
date.setDate(Number(e.target.getAttribute('data-date-day')));
|
316
|
+
this.value = formatTimestamp(date.getTime(), NATIVE_FORMAT);
|
317
|
+
this.dispatchEvent(new CustomEvent('day-changed', { detail: date }));
|
318
|
+
}
|
319
|
+
|
320
|
+
onYearChange(e) {
|
321
|
+
if (!e.target.value) return;
|
322
|
+
const date = newDate(this.preview);
|
323
|
+
date.setFullYear(Number(e.target.value.trim()));
|
324
|
+
this.preview = date.getTime();
|
325
|
+
this.renderCalendar();
|
326
|
+
this.dispatchEvent(new CustomEvent('year-changed', { detail: date }));
|
327
|
+
}
|
328
|
+
|
329
|
+
onMonthChange(e) {
|
330
|
+
if (!e.target.value) return;
|
331
|
+
const date = newDate(this.preview);
|
332
|
+
date.setMonth(Number(e.target.value) - 1);
|
333
|
+
this.preview = date.getTime();
|
334
|
+
this.renderCalendar();
|
335
|
+
this.dispatchEvent(new CustomEvent('month-changed', { detail: date }));
|
336
|
+
}
|
337
|
+
|
338
|
+
onYearInputBlur(e) {
|
339
|
+
this.yearInput.baseElement.value = e.target.value || getFullYear(this.preview);
|
340
|
+
}
|
341
|
+
|
342
|
+
onMonthInputBlur(e) {
|
343
|
+
this.monthInput.baseElement.value = e.target.value || getMonth(this.preview);
|
344
|
+
}
|
345
|
+
|
346
|
+
getSelectedDayEle() {
|
347
|
+
const day = newDate(this.timestamp).getDate();
|
348
|
+
return this.calendar?.querySelector(`[data-date-day="${day}"]`);
|
349
|
+
}
|
350
|
+
|
351
|
+
getCurrentDayEle() {
|
352
|
+
return this.calendar?.querySelector(`[data-date-day="${getCurrentDay()}"]`);
|
353
|
+
}
|
354
|
+
|
355
|
+
clearSelectedDays() {
|
356
|
+
const cells = this.calendar?.querySelectorAll(`[data-selected]`);
|
357
|
+
if (!cells) return;
|
358
|
+
cells.forEach((c) => c.removeAttribute('data-selected'));
|
359
|
+
}
|
360
|
+
|
361
|
+
setSelectedDay() {
|
362
|
+
this.clearSelectedDays();
|
363
|
+
if (this.value && this.isSelectedView) {
|
364
|
+
this.getSelectedDayEle().setAttribute('data-selected', 'true');
|
365
|
+
}
|
366
|
+
}
|
367
|
+
|
368
|
+
setCurrentDay() {
|
369
|
+
if (this.isTodayView) {
|
370
|
+
const ele = this.getCurrentDayEle();
|
371
|
+
const title = this.getAttribute('calendar-label-today') || CALENDAR_LABEL_TODAY;
|
372
|
+
ele.setAttribute('data-current-day', 'true');
|
373
|
+
ele.setAttribute('title', title);
|
374
|
+
}
|
375
|
+
}
|
376
|
+
|
377
|
+
navPrevMonth() {
|
378
|
+
if (this.isDisabled) {
|
379
|
+
return;
|
380
|
+
}
|
381
|
+
const date = prevMonth(this.preview);
|
382
|
+
this.preview = date.getTime();
|
383
|
+
this.renderCalendar();
|
384
|
+
}
|
385
|
+
|
386
|
+
navNextMonth() {
|
387
|
+
if (this.isDisabled) {
|
388
|
+
return;
|
389
|
+
}
|
390
|
+
const date = nextMonth(this.preview);
|
391
|
+
this.preview = date.getTime();
|
392
|
+
this.renderCalendar();
|
393
|
+
}
|
394
|
+
|
395
|
+
clearValue() {
|
396
|
+
this.timestamp = '';
|
397
|
+
this.value = '';
|
398
|
+
this.removeAttribute('preview');
|
399
|
+
this.submitButton.setAttribute('disabled', 'true');
|
400
|
+
}
|
401
|
+
|
402
|
+
onInitialValueChange(newValue) {
|
403
|
+
// if component already has a value don't re-set value
|
404
|
+
if (this.value) {
|
405
|
+
return;
|
406
|
+
}
|
407
|
+
|
408
|
+
const date = newDate(newValue);
|
409
|
+
const timestamp = date.getTime();
|
410
|
+
|
411
|
+
if (isValidTimestamp(timestamp)) {
|
412
|
+
this.timestamp = timestamp;
|
413
|
+
this.preview = timestamp;
|
414
|
+
} else {
|
415
|
+
this.clearValue();
|
416
|
+
}
|
417
|
+
}
|
418
|
+
|
419
|
+
onYearsRangeChange() {
|
420
|
+
setTimeout(() => {
|
421
|
+
if (this.yearInput) {
|
422
|
+
this.yearInput.innerHTML = getYearOptions(this.yearsRange);
|
423
|
+
}
|
424
|
+
});
|
425
|
+
}
|
426
|
+
|
427
|
+
onMonthNamesChange() {
|
428
|
+
Array.from(this.monthInput?.children || []).forEach((child, index) => {
|
429
|
+
const month = this.monthNames[index];
|
430
|
+
child.setAttribute('data-name', month);
|
431
|
+
// eslint-disable-next-line no-param-reassign
|
432
|
+
child.textContent = month;
|
433
|
+
});
|
434
|
+
}
|
435
|
+
|
436
|
+
onSubmitLabelChange(newValue) {
|
437
|
+
if (this.submitButton) {
|
438
|
+
this.submitButton.textContent = newValue || BUTTON_LABEL_DONE;
|
439
|
+
}
|
440
|
+
}
|
441
|
+
|
442
|
+
onCancelLabelChange(newValue) {
|
443
|
+
if (this.cancelButton) {
|
444
|
+
this.cancelButton.textContent = newValue || BUTTON_LABEL_CANCEL;
|
445
|
+
}
|
446
|
+
}
|
447
|
+
|
448
|
+
onInitialMonthChange(val) {
|
449
|
+
const currYear = getFullYear(this.preview);
|
450
|
+
this.preview = newDate(`${currYear}/${val}/1`).getTime();
|
451
|
+
}
|
452
|
+
|
453
|
+
onInitialYearChange(val) {
|
454
|
+
const currMonth = getMonth(this.preview);
|
455
|
+
this.preview = newDate(`${val}/${currMonth}/1`).getTime();
|
456
|
+
}
|
457
|
+
|
458
|
+
attributeChangedCallback(attrName, oldValue, newValue) {
|
459
|
+
super.attributeChangedCallback(attrName, oldValue, newValue);
|
460
|
+
if (oldValue !== newValue) {
|
461
|
+
// attrs for which affect static ui parts doesn't require calendar re-render
|
462
|
+
if (calendarUiAttrs.includes(attrName)) {
|
463
|
+
if (attrName === 'calendar-label-submit') {
|
464
|
+
this.onSubmitLabelChange(newValue);
|
465
|
+
}
|
466
|
+
if (attrName === 'calendar-label-cancel') {
|
467
|
+
this.onCancelLabelChange(newValue);
|
468
|
+
}
|
469
|
+
} else {
|
470
|
+
// we want to render the calendar for each of these attr change
|
471
|
+
|
472
|
+
if (newValue && attrName === 'initial-value') {
|
473
|
+
this.onInitialValueChange(newValue);
|
474
|
+
}
|
475
|
+
if (newValue && attrName === 'initial-month') {
|
476
|
+
this.onInitialMonthChange(newValue);
|
477
|
+
}
|
478
|
+
if (newValue && attrName === 'initial-year') {
|
479
|
+
this.onInitialYearChange(newValue);
|
480
|
+
}
|
481
|
+
if (attrName === 'years-range') {
|
482
|
+
this.onYearsRangeChange(Number(newValue));
|
483
|
+
}
|
484
|
+
if (attrName === 'calendar-months') {
|
485
|
+
this.onMonthNamesChange();
|
486
|
+
}
|
487
|
+
if (attrName === 'calendar-label-today') {
|
488
|
+
this.setCurrentDay(newValue);
|
489
|
+
}
|
490
|
+
if (attrName === 'disabled') {
|
491
|
+
setTimeout(() => {
|
492
|
+
this.cancelButton?.setAttribute('disabled', newValue === 'true');
|
493
|
+
});
|
494
|
+
}
|
495
|
+
|
496
|
+
this.renderCalendar();
|
497
|
+
}
|
498
|
+
}
|
499
|
+
}
|
500
|
+
|
501
|
+
getValidity() {
|
502
|
+
if (this.isRequired && !this.value) {
|
503
|
+
return { valueMissing: true };
|
504
|
+
}
|
505
|
+
return {};
|
506
|
+
}
|
507
|
+
}
|
508
|
+
|
509
|
+
const {
|
510
|
+
calendar,
|
511
|
+
day,
|
512
|
+
dayEntry,
|
513
|
+
currentDay,
|
514
|
+
selectedDay,
|
515
|
+
disabledDay,
|
516
|
+
weekday,
|
517
|
+
topNav,
|
518
|
+
topNavSelectors,
|
519
|
+
bottomNav,
|
520
|
+
navPrev,
|
521
|
+
navNext,
|
522
|
+
navPrevRTL,
|
523
|
+
navNextRTL,
|
524
|
+
yearInput,
|
525
|
+
monthInput,
|
526
|
+
} = {
|
527
|
+
calendar: { selector: () => '.calendar' },
|
528
|
+
topNav: { selector: () => '.nav.top-nav' },
|
529
|
+
topNavSelectors: { selector: () => '.nav.top-nav .selectors > span' },
|
530
|
+
bottomNav: { selector: () => '.nav.bottom-nav' },
|
531
|
+
day: { selector: () => '.day' },
|
532
|
+
dayEntry: { selector: () => '.day-entry' },
|
533
|
+
currentDay: { selector: () => '.day-entry[data-current-day] .day' },
|
534
|
+
selectedDay: { selector: () => '.day-entry[data-selected] .day' },
|
535
|
+
disabledDay: { selector: () => '.day-entry[data-disabled="true"] .day' },
|
536
|
+
weekday: { selector: () => '.weekday' },
|
537
|
+
navPrev: { selector: () => '.nav-prev' },
|
538
|
+
navNext: { selector: () => '.nav-next' },
|
539
|
+
navPrevRTL: { selector: () => ':host(:dir(rtl)) .nav-prev' },
|
540
|
+
navNextRTL: { selector: () => ':host(:dir(rtl)) .nav-next' },
|
541
|
+
yearInput: { selector: () => '.year-input' },
|
542
|
+
monthInput: { selector: () => '.month-input' },
|
543
|
+
};
|
544
|
+
|
545
|
+
export const CalendarClass = compose(
|
546
|
+
createStyleMixin({ componentNameOverride: getComponentName('input-wrapper') }),
|
547
|
+
createStyleMixin({
|
548
|
+
mappings: {
|
549
|
+
fontSize: {},
|
550
|
+
fontFamily: {},
|
551
|
+
hostWidth: [
|
552
|
+
{ selector: () => ':host', property: 'width' },
|
553
|
+
{ selector: 'table', property: 'width' },
|
554
|
+
],
|
555
|
+
hostDirection: { property: 'direction' },
|
556
|
+
|
557
|
+
topNavVerticalPadding: [
|
558
|
+
{ ...topNav, property: 'padding-top' },
|
559
|
+
{ ...topNav, property: 'padding-bottom' },
|
560
|
+
],
|
561
|
+
topNavHorizointalPadding: [
|
562
|
+
{ ...topNav, property: 'padding-right' },
|
563
|
+
{ ...topNav, property: 'padding-left' },
|
564
|
+
],
|
565
|
+
topNavAlignment: { ...topNav, property: 'justify-content' },
|
566
|
+
topNavGap: { ...topNav, property: 'gap' },
|
567
|
+
topNavSelectorsGap: { ...topNavSelectors, property: 'gap' },
|
568
|
+
|
569
|
+
bottomNavVerticalPadding: [
|
570
|
+
{ ...bottomNav, property: 'padding-top' },
|
571
|
+
{ ...bottomNav, property: 'padding-bottom' },
|
572
|
+
],
|
573
|
+
bottomNavHorizontalPadding: [
|
574
|
+
{ ...bottomNav, property: 'padding-right' },
|
575
|
+
{ ...bottomNav, property: 'padding-left' },
|
576
|
+
],
|
577
|
+
bottomNavAlignment: { ...bottomNav, property: 'justify-content' },
|
578
|
+
bottomNavGap: { ...bottomNav, property: 'gap' },
|
579
|
+
|
580
|
+
navMarginBottom: { ...topNav, property: 'margin-bottom' },
|
581
|
+
|
582
|
+
calendarPadding: [
|
583
|
+
{ ...calendar, property: 'padding-bottom' },
|
584
|
+
{ ...calendar, property: 'padding-right' },
|
585
|
+
{ ...calendar, property: 'padding-left' },
|
586
|
+
],
|
587
|
+
|
588
|
+
navBorderBottomWidth: { ...topNav, property: 'border-bottom-width' },
|
589
|
+
navBorderBottomColor: { ...topNav, property: 'border-bottom-color' },
|
590
|
+
navBorderBottomStyle: { ...topNav, property: 'border-bottom-style' },
|
591
|
+
|
592
|
+
weekdayFontSize: { ...weekday, property: 'font-size' },
|
593
|
+
weekdayFontWeight: { ...weekday, property: 'font-weight' },
|
594
|
+
|
595
|
+
currentDayBorderColor: {
|
596
|
+
...currentDay,
|
597
|
+
property: 'border-color',
|
598
|
+
},
|
599
|
+
currentDayBorderWidth: {
|
600
|
+
...currentDay,
|
601
|
+
property: 'border-width',
|
602
|
+
},
|
603
|
+
currentDayBorderStyle: {
|
604
|
+
...currentDay,
|
605
|
+
property: 'border-style',
|
606
|
+
},
|
607
|
+
|
608
|
+
dayHeight: { ...dayEntry, property: 'height' },
|
609
|
+
daySize: [
|
610
|
+
{ ...day, property: 'height' },
|
611
|
+
{ ...day, property: 'width' },
|
612
|
+
],
|
613
|
+
dayPadding: { ...day, property: 'padding' },
|
614
|
+
dayRadius: { ...day, property: 'border-radius' },
|
615
|
+
dayTextAlign: { ...day, property: 'text-align' },
|
616
|
+
dayBlockAlign: { ...day, property: 'margin' },
|
617
|
+
dayTextColor: { ...day, property: 'color' },
|
618
|
+
dayFontWeight: { ...day, property: 'font-weight' },
|
619
|
+
dayBackgroundColor: { ...day, property: 'background-color' },
|
620
|
+
dayCursor: { ...day, property: 'cursor' },
|
621
|
+
dayFontSize: { ...day, property: 'font-size' },
|
622
|
+
|
623
|
+
dayBackgroundColorHover: {
|
624
|
+
selector: () => '.day:hover',
|
625
|
+
property: 'background-color',
|
626
|
+
},
|
627
|
+
|
628
|
+
daySelectedTextdColor: {
|
629
|
+
...selectedDay,
|
630
|
+
property: 'color',
|
631
|
+
},
|
632
|
+
daySelectedBackgroundColor: {
|
633
|
+
...selectedDay,
|
634
|
+
property: 'background-color',
|
635
|
+
},
|
636
|
+
dayDisabledTextdColor: {
|
637
|
+
...disabledDay,
|
638
|
+
property: 'color',
|
639
|
+
},
|
640
|
+
|
641
|
+
yearInputWidth: { ...yearInput, property: 'width' },
|
642
|
+
monthInputWidth: { ...monthInput, property: 'width' },
|
643
|
+
|
644
|
+
navButtonSize: [
|
645
|
+
{ ...navPrev, property: 'width' },
|
646
|
+
{ ...navPrev, property: 'height' },
|
647
|
+
{ ...navNext, property: 'width' },
|
648
|
+
{ ...navNext, property: 'height' },
|
649
|
+
],
|
650
|
+
navButtonCursor: [
|
651
|
+
{ ...navPrev, property: 'cursor' },
|
652
|
+
{ ...navNext, property: 'cursor' },
|
653
|
+
],
|
654
|
+
navButtonRotation: [
|
655
|
+
{ ...navPrevRTL, property: 'transform' },
|
656
|
+
{ ...navNextRTL, property: 'transform' },
|
657
|
+
],
|
658
|
+
navButtonOpacity: [
|
659
|
+
{ ...navPrev, property: 'opacity' },
|
660
|
+
{ ...navNext, property: 'opacity' },
|
661
|
+
],
|
662
|
+
},
|
663
|
+
}),
|
664
|
+
draggableMixin,
|
665
|
+
componentNameValidationMixin
|
666
|
+
)(RawCalendar);
|