@nectary/components 0.29.1 → 0.30.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/accordion-item/types.d.ts +1 -2
- package/accordion-item/utils.d.ts +2 -1
- package/alert/index.js +1 -1
- package/alert/types.d.ts +1 -2
- package/alert/utils.d.ts +2 -1
- package/alert-button/index.js +1 -1
- package/avatar/types.d.ts +2 -3
- package/avatar/utils.d.ts +3 -2
- package/avatar-status/index.js +1 -3
- package/avatar-status/types.d.ts +1 -2
- package/avatar-status/utils.d.ts +1 -1
- package/button/index.js +1 -1
- package/button/types.d.ts +1 -2
- package/button/utils.d.ts +2 -1
- package/card/index.js +1 -1
- package/card-container/index.js +1 -1
- package/chat-bubble/types.d.ts +2 -3
- package/chat-bubble/utils.d.ts +3 -2
- package/checkbox/index.js +1 -1
- package/colors.json +6 -1
- package/date-picker/index.d.ts +19 -0
- package/date-picker/index.js +419 -0
- package/date-picker/types.d.ts +26 -0
- package/date-picker/types.js +1 -0
- package/date-picker/utils.d.ts +32 -0
- package/date-picker/utils.js +142 -0
- package/dialog/index.js +23 -5
- package/dropdown-checkbox-option/index.js +1 -1
- package/icon-button/index.js +1 -1
- package/icons/create-icon-class.d.ts +1 -307
- package/icons/keyboard-double-arrow-left/index.d.ts +11 -0
- package/icons/keyboard-double-arrow-left/index.js +4 -0
- package/icons/keyboard-double-arrow-right/index.d.ts +11 -0
- package/icons/keyboard-double-arrow-right/index.js +4 -0
- package/icons-branded/chat/index.d.ts +11 -0
- package/icons-branded/chat/index.js +4 -0
- package/icons-branded/create-icon-class.d.ts +1 -311
- package/icons-branded/mms/index.d.ts +11 -0
- package/icons-branded/mms/index.js +4 -0
- package/icons-branded/push/index.d.ts +11 -0
- package/icons-branded/push/index.js +4 -0
- package/icons-branded/rcs/index.d.ts +11 -0
- package/icons-branded/rcs/index.js +4 -0
- package/icons-branded/sms/index.d.ts +11 -0
- package/icons-branded/sms/index.js +4 -0
- package/icons-channel/apple-business-chat-square/index.d.ts +11 -0
- package/icons-channel/apple-business-chat-square/index.js +4 -0
- package/icons-channel/create-icon-class.d.ts +1 -310
- package/icons-channel/create-icon-class.js +1 -1
- package/icons-channel/facebook-messenger-square/index.d.ts +11 -0
- package/icons-channel/facebook-messenger-square/index.js +4 -0
- package/icons-channel/instagram-square/index.d.ts +11 -0
- package/icons-channel/instagram-square/index.js +4 -0
- package/icons-channel/line-square/index.d.ts +11 -0
- package/icons-channel/line-square/index.js +4 -0
- package/icons-channel/talk-square/index.d.ts +11 -0
- package/icons-channel/talk-square/index.js +4 -0
- package/icons-channel/telegram-square/index.d.ts +11 -0
- package/icons-channel/telegram-square/index.js +4 -0
- package/icons-channel/twitter-square/index.d.ts +11 -0
- package/icons-channel/twitter-square/index.js +4 -0
- package/icons-channel/viber-square/index.d.ts +11 -0
- package/icons-channel/viber-square/index.js +4 -0
- package/icons-channel/wechat-square/index.d.ts +11 -0
- package/icons-channel/wechat-square/index.js +4 -0
- package/icons-channel/whatsapp-square/index.d.ts +11 -0
- package/icons-channel/whatsapp-square/index.js +4 -0
- package/illustration/create-illustration-class.d.ts +1 -310
- package/illustration/create-illustration-class.js +20 -3
- package/illustration/phone-and-cat/index.js +1 -1
- package/illustration/types.d.ts +8 -0
- package/illustration/utils.d.ts +3 -0
- package/illustration/utils.js +2 -0
- package/input/index.js +1 -1
- package/input/types.d.ts +4 -5
- package/input/utils.d.ts +2 -1
- package/link/index.js +18 -4
- package/link/types.d.ts +0 -2
- package/logo/create-logo-class.d.ts +1 -311
- package/package.json +1 -1
- package/popover/index.js +76 -47
- package/popover/types.d.ts +1 -2
- package/popover/utils.d.ts +2 -1
- package/search/index.js +1 -1
- package/segment/index.d.ts +1 -0
- package/segment/index.js +109 -6
- package/segment/types.d.ts +4 -0
- package/segment/utils.d.ts +5 -0
- package/segment/utils.js +6 -0
- package/select/index.js +1 -1
- package/spinner/types.d.ts +1 -2
- package/spinner/utils.d.ts +2 -1
- package/table-cell/types.d.ts +4 -5
- package/table-cell/utils.d.ts +2 -1
- package/table-head-cell/types.d.ts +4 -4
- package/tag/index.js +1 -1
- package/tag/types.d.ts +1 -2
- package/tag/utils.d.ts +2 -1
- package/text/index.js +0 -1
- package/text/types.d.ts +1 -2
- package/text/utils.d.ts +1 -1
- package/textarea/index.js +1 -1
- package/theme.css +17 -0
- package/title/index.js +0 -2
- package/title/types.d.ts +2 -3
- package/title/utils.d.ts +4 -3
- package/title/utils.js +21 -0
- package/toggle/index.js +1 -1
- package/tooltip/index.js +1 -1
- package/tooltip/types.d.ts +1 -2
- package/tooltip/utils.d.ts +2 -1
- package/utils.d.ts +4 -0
- package/utils.js +35 -4
|
@@ -0,0 +1,419 @@
|
|
|
1
|
+
import _classPrivateFieldGet from '@babel/runtime/helpers/classPrivateFieldGet';
|
|
2
|
+
import _classPrivateFieldSet from '@babel/runtime/helpers/classPrivateFieldSet';
|
|
3
|
+
|
|
4
|
+
var _$month, _$weeks, _$days, _$weekDayNames, _date, _minDate, _maxDate, _$prevMonth, _$nextMonth, _$prevYear, _$nextYear, _$date, _monthNames, _onPrevMonthClick, _onNextMonthClick, _onPrevYearClick, _onNextYearClick, _onDateClick, _render;
|
|
5
|
+
|
|
6
|
+
function _classPrivateMethodInitSpec(obj, privateSet) { _checkPrivateRedeclaration(obj, privateSet); privateSet.add(obj); }
|
|
7
|
+
|
|
8
|
+
function _classPrivateFieldInitSpec(obj, privateMap, value) { _checkPrivateRedeclaration(obj, privateMap); privateMap.set(obj, value); }
|
|
9
|
+
|
|
10
|
+
function _checkPrivateRedeclaration(obj, privateCollection) { if (privateCollection.has(obj)) { throw new TypeError("Cannot initialize the same private elements twice on an object"); } }
|
|
11
|
+
|
|
12
|
+
function _classPrivateMethodGet(receiver, privateSet, fn) { if (!privateSet.has(receiver)) { throw new TypeError("attempted to get private field on non-instance"); } return fn; }
|
|
13
|
+
|
|
14
|
+
import '../icon-button';
|
|
15
|
+
import '../icons/keyboard-arrow-right';
|
|
16
|
+
import '../icons/keyboard-double-arrow-right';
|
|
17
|
+
import '../icons/keyboard-arrow-left';
|
|
18
|
+
import '../icons/keyboard-double-arrow-left';
|
|
19
|
+
import '../icons/delete-outline';
|
|
20
|
+
import '../icons/today';
|
|
21
|
+
import '../text';
|
|
22
|
+
import { defineCustomElement, getAttribute, getRect, NectaryElement, setClass, updateAttribute, updateBooleanAttribute } from '../utils';
|
|
23
|
+
const templateHTML = '<style>:host{display:block;outline:0}#content{width:fit-content;box-sizing:border-box;padding:16px;display:flex;flex-direction:column;gap:8px}#month{display:flex;flex-direction:column;row-gap:8px}.week{display:flex;flex-direction:row;column-gap:8px}.week.empty{display:none}.day{all:initial;font:var(--sinch-font-text-xs);color:var(--sinch-color-text-default);text-align:center;border-radius:var(--sinch-shape-radius-m);width:24px;height:24px;line-height:22px;cursor:pointer;border:1px solid transparent;background-color:transparent;box-sizing:border-box;user-select:none}.day.today{border:1px solid var(--sinch-color-stormy-500)}.day:disabled{cursor:initial;color:var(--sinch-color-snow-700)}.day:focus-visible{outline:1px solid var(--sinch-color-aqua-400);outline-offset:1px}@supports not selector(:focus-visible){.day:focus{outline:1px solid var(--sinch-color-aqua-400);outline-offset:1px}}.day.selected{background-color:var(--sinch-color-stormy-500);color:var(--sinch-color-snow-100)}.day:hover:not(:disabled):not(.selected){background-color:var(--sinch-color-snow-600)}#week-day-names{display:flex;flex-direction:row;gap:8px;height:24px}.week-day-name{font:var(--sinch-font-text-xs);font-weight:var(--sinch-font-weight-emphasized);color:var(--sinch-color-text-default);text-align:center;width:24px;height:24px;line-height:24px;user-select:none;text-transform:uppercase}#content-header{display:flex;flex-direction:row;height:32px;align-items:center}#date{flex:1;text-align:center;text-transform:capitalize}#prev-year{margin-left:-4px}#next-year{margin-right:-4px}</style><div id="content" slot="content"><div id="content-header"><sinch-icon-button small id="prev-year"><sinch-icon-keyboard-double-arrow-left slot="icon"></sinch-icon-keyboard-double-arrow-left></sinch-icon-button><sinch-icon-button small id="prev-month"><sinch-icon-keyboard-arrow-left slot="icon"></sinch-icon-keyboard-arrow-left></sinch-icon-button><sinch-text type="m" emphasized id="date"></sinch-text><sinch-icon-button small id="next-month"><sinch-icon-keyboard-arrow-right slot="icon"></sinch-icon-keyboard-arrow-right></sinch-icon-button><sinch-icon-button small id="next-year"><sinch-icon-keyboard-double-arrow-right slot="icon"></sinch-icon-keyboard-double-arrow-right></sinch-icon-button></div><div id="week-day-names"><div class="week-day-name"></div><div class="week-day-name"></div><div class="week-day-name"></div><div class="week-day-name"></div><div class="week-day-name"></div><div class="week-day-name"></div><div class="week-day-name"></div></div><div id="month"><div class="week"><button class="day"></button> <button class="day"></button> <button class="day"></button> <button class="day"></button> <button class="day"></button> <button class="day"></button> <button class="day"></button></div><div class="week"><button class="day"></button> <button class="day"></button> <button class="day"></button> <button class="day"></button> <button class="day"></button> <button class="day"></button> <button class="day"></button></div><div class="week"><button class="day"></button> <button class="day"></button> <button class="day"></button> <button class="day"></button> <button class="day"></button> <button class="day"></button> <button class="day"></button></div><div class="week"><button class="day"></button> <button class="day"></button> <button class="day"></button> <button class="day"></button> <button class="day"></button> <button class="day"></button> <button class="day"></button></div><div class="week"><button class="day"></button> <button class="day"></button> <button class="day"></button> <button class="day"></button> <button class="day"></button> <button class="day"></button> <button class="day"></button></div><div class="week"><button class="day"></button> <button class="day"></button> <button class="day"></button> <button class="day"></button> <button class="day"></button> <button class="day"></button> <button class="day"></button></div></div></div>';
|
|
24
|
+
import { areDatesEqual, assertDate, assertLocale, assertMinMax, assertValue, canGoNextMonth, canGoNextYear, canGoPrevMonth, canGoPrevYear, clampMaxDate, clampMinDate, dateToIso, decMonth, decYear, getCalendarMonth, getDayNames, getMonthNames, incMonth, incYear, isDateBetween, isoToDate, isValidDate } from './utils';
|
|
25
|
+
const template = document.createElement('template');
|
|
26
|
+
template.innerHTML = templateHTML;
|
|
27
|
+
defineCustomElement('sinch-date-picker', (_$month = new WeakMap(), _$weeks = new WeakMap(), _$days = new WeakMap(), _$weekDayNames = new WeakMap(), _date = new WeakMap(), _minDate = new WeakMap(), _maxDate = new WeakMap(), _$prevMonth = new WeakMap(), _$nextMonth = new WeakMap(), _$prevYear = new WeakMap(), _$nextYear = new WeakMap(), _$date = new WeakMap(), _monthNames = new WeakMap(), _onPrevMonthClick = new WeakMap(), _onNextMonthClick = new WeakMap(), _onPrevYearClick = new WeakMap(), _onNextYearClick = new WeakMap(), _onDateClick = new WeakMap(), _render = new WeakSet(), class extends NectaryElement {
|
|
28
|
+
constructor() {
|
|
29
|
+
super();
|
|
30
|
+
|
|
31
|
+
_classPrivateMethodInitSpec(this, _render);
|
|
32
|
+
|
|
33
|
+
_classPrivateFieldInitSpec(this, _$month, {
|
|
34
|
+
writable: true,
|
|
35
|
+
value: void 0
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
_classPrivateFieldInitSpec(this, _$weeks, {
|
|
39
|
+
writable: true,
|
|
40
|
+
value: void 0
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
_classPrivateFieldInitSpec(this, _$days, {
|
|
44
|
+
writable: true,
|
|
45
|
+
value: void 0
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
_classPrivateFieldInitSpec(this, _$weekDayNames, {
|
|
49
|
+
writable: true,
|
|
50
|
+
value: void 0
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
_classPrivateFieldInitSpec(this, _date, {
|
|
54
|
+
writable: true,
|
|
55
|
+
value: null
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
_classPrivateFieldInitSpec(this, _minDate, {
|
|
59
|
+
writable: true,
|
|
60
|
+
value: null
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
_classPrivateFieldInitSpec(this, _maxDate, {
|
|
64
|
+
writable: true,
|
|
65
|
+
value: null
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
_classPrivateFieldInitSpec(this, _$prevMonth, {
|
|
69
|
+
writable: true,
|
|
70
|
+
value: void 0
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
_classPrivateFieldInitSpec(this, _$nextMonth, {
|
|
74
|
+
writable: true,
|
|
75
|
+
value: void 0
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
_classPrivateFieldInitSpec(this, _$prevYear, {
|
|
79
|
+
writable: true,
|
|
80
|
+
value: void 0
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
_classPrivateFieldInitSpec(this, _$nextYear, {
|
|
84
|
+
writable: true,
|
|
85
|
+
value: void 0
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
_classPrivateFieldInitSpec(this, _$date, {
|
|
89
|
+
writable: true,
|
|
90
|
+
value: void 0
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
_classPrivateFieldInitSpec(this, _monthNames, {
|
|
94
|
+
writable: true,
|
|
95
|
+
value: void 0
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
_classPrivateFieldInitSpec(this, _onPrevMonthClick, {
|
|
99
|
+
writable: true,
|
|
100
|
+
value: () => {
|
|
101
|
+
decMonth(_classPrivateFieldGet(this, _date), _classPrivateFieldGet(this, _minDate));
|
|
102
|
+
|
|
103
|
+
_classPrivateMethodGet(this, _render, _render2).call(this);
|
|
104
|
+
}
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
_classPrivateFieldInitSpec(this, _onNextMonthClick, {
|
|
108
|
+
writable: true,
|
|
109
|
+
value: () => {
|
|
110
|
+
incMonth(_classPrivateFieldGet(this, _date), _classPrivateFieldGet(this, _maxDate));
|
|
111
|
+
|
|
112
|
+
_classPrivateMethodGet(this, _render, _render2).call(this);
|
|
113
|
+
}
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
_classPrivateFieldInitSpec(this, _onPrevYearClick, {
|
|
117
|
+
writable: true,
|
|
118
|
+
value: () => {
|
|
119
|
+
decYear(_classPrivateFieldGet(this, _date), _classPrivateFieldGet(this, _minDate));
|
|
120
|
+
|
|
121
|
+
_classPrivateMethodGet(this, _render, _render2).call(this);
|
|
122
|
+
}
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
_classPrivateFieldInitSpec(this, _onNextYearClick, {
|
|
126
|
+
writable: true,
|
|
127
|
+
value: () => {
|
|
128
|
+
incYear(_classPrivateFieldGet(this, _date), _classPrivateFieldGet(this, _maxDate));
|
|
129
|
+
|
|
130
|
+
_classPrivateMethodGet(this, _render, _render2).call(this);
|
|
131
|
+
}
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
_classPrivateFieldInitSpec(this, _onDateClick, {
|
|
135
|
+
writable: true,
|
|
136
|
+
value: e => {
|
|
137
|
+
const dateIso = e.target.getAttribute('data-date');
|
|
138
|
+
|
|
139
|
+
if (dateIso === null || dateIso.length === 0) {
|
|
140
|
+
return;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
this.dispatchEvent(new CustomEvent('change', {
|
|
144
|
+
detail: dateIso,
|
|
145
|
+
bubbles: true
|
|
146
|
+
}));
|
|
147
|
+
}
|
|
148
|
+
});
|
|
149
|
+
|
|
150
|
+
const shadowRoot = this.attachShadow();
|
|
151
|
+
shadowRoot.appendChild(template.content.cloneNode(true));
|
|
152
|
+
|
|
153
|
+
_classPrivateFieldSet(this, _$prevMonth, shadowRoot.querySelector('#prev-month'));
|
|
154
|
+
|
|
155
|
+
_classPrivateFieldSet(this, _$nextMonth, shadowRoot.querySelector('#next-month'));
|
|
156
|
+
|
|
157
|
+
_classPrivateFieldSet(this, _$prevYear, shadowRoot.querySelector('#prev-year'));
|
|
158
|
+
|
|
159
|
+
_classPrivateFieldSet(this, _$nextYear, shadowRoot.querySelector('#next-year'));
|
|
160
|
+
|
|
161
|
+
_classPrivateFieldSet(this, _$date, shadowRoot.querySelector('#date'));
|
|
162
|
+
|
|
163
|
+
_classPrivateFieldSet(this, _$month, shadowRoot.querySelector('#month'));
|
|
164
|
+
|
|
165
|
+
_classPrivateFieldSet(this, _$days, []);
|
|
166
|
+
|
|
167
|
+
_classPrivateFieldSet(this, _$weeks, []);
|
|
168
|
+
|
|
169
|
+
_classPrivateFieldSet(this, _monthNames, []);
|
|
170
|
+
|
|
171
|
+
shadowRoot.querySelectorAll('.week').forEach((week, i) => {
|
|
172
|
+
_classPrivateFieldGet(this, _$weeks).push(week);
|
|
173
|
+
|
|
174
|
+
_classPrivateFieldGet(this, _$days)[i] = [];
|
|
175
|
+
week.querySelectorAll('.day').forEach(day => {
|
|
176
|
+
_classPrivateFieldGet(this, _$days)[i].push(day);
|
|
177
|
+
});
|
|
178
|
+
});
|
|
179
|
+
|
|
180
|
+
_classPrivateFieldSet(this, _$weekDayNames, Array.from(shadowRoot.querySelectorAll('#week-day-names > .week-day-name')));
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
connectedCallback() {
|
|
184
|
+
_classPrivateFieldGet(this, _$prevMonth).addEventListener('click', _classPrivateFieldGet(this, _onPrevMonthClick));
|
|
185
|
+
|
|
186
|
+
_classPrivateFieldGet(this, _$nextMonth).addEventListener('click', _classPrivateFieldGet(this, _onNextMonthClick));
|
|
187
|
+
|
|
188
|
+
_classPrivateFieldGet(this, _$prevYear).addEventListener('click', _classPrivateFieldGet(this, _onPrevYearClick));
|
|
189
|
+
|
|
190
|
+
_classPrivateFieldGet(this, _$nextYear).addEventListener('click', _classPrivateFieldGet(this, _onNextYearClick));
|
|
191
|
+
|
|
192
|
+
_classPrivateFieldGet(this, _$month).addEventListener('click', _classPrivateFieldGet(this, _onDateClick));
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
disconnectedCallback() {
|
|
196
|
+
_classPrivateFieldGet(this, _$prevMonth).removeEventListener('click', _classPrivateFieldGet(this, _onPrevMonthClick));
|
|
197
|
+
|
|
198
|
+
_classPrivateFieldGet(this, _$nextMonth).removeEventListener('click', _classPrivateFieldGet(this, _onNextMonthClick));
|
|
199
|
+
|
|
200
|
+
_classPrivateFieldGet(this, _$prevYear).removeEventListener('click', _classPrivateFieldGet(this, _onPrevYearClick));
|
|
201
|
+
|
|
202
|
+
_classPrivateFieldGet(this, _$nextYear).removeEventListener('click', _classPrivateFieldGet(this, _onNextYearClick));
|
|
203
|
+
|
|
204
|
+
_classPrivateFieldGet(this, _$month).removeEventListener('click', _classPrivateFieldGet(this, _onDateClick));
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
static get observedAttributes() {
|
|
208
|
+
return ['value', 'min', 'max', 'locale'];
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
attributeChangedCallback(name, prevValue, newVal) {
|
|
212
|
+
if (newVal === prevValue) {
|
|
213
|
+
return;
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
switch (name) {
|
|
217
|
+
case 'value':
|
|
218
|
+
{
|
|
219
|
+
assertValue(newVal);
|
|
220
|
+
|
|
221
|
+
_classPrivateFieldSet(this, _date, newVal.length > 0 ? isoToDate(newVal) : new Date());
|
|
222
|
+
|
|
223
|
+
if (!isValidDate(_classPrivateFieldGet(this, _date))) {
|
|
224
|
+
_classPrivateFieldSet(this, _date, new Date());
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
if (_classPrivateFieldGet(this, _minDate) !== null) {
|
|
228
|
+
clampMinDate(_classPrivateFieldGet(this, _date), _classPrivateFieldGet(this, _minDate));
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
if (_classPrivateFieldGet(this, _maxDate) !== null) {
|
|
232
|
+
clampMaxDate(_classPrivateFieldGet(this, _date), _classPrivateFieldGet(this, _maxDate));
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
_classPrivateMethodGet(this, _render, _render2).call(this);
|
|
236
|
+
|
|
237
|
+
break;
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
case 'min':
|
|
241
|
+
{
|
|
242
|
+
assertMinMax(newVal, name);
|
|
243
|
+
|
|
244
|
+
_classPrivateFieldSet(this, _minDate, isoToDate(newVal));
|
|
245
|
+
|
|
246
|
+
assertDate(_classPrivateFieldGet(this, _minDate), name, newVal);
|
|
247
|
+
|
|
248
|
+
if (_classPrivateFieldGet(this, _date) !== null) {
|
|
249
|
+
clampMinDate(_classPrivateFieldGet(this, _date), _classPrivateFieldGet(this, _minDate));
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
_classPrivateMethodGet(this, _render, _render2).call(this);
|
|
253
|
+
|
|
254
|
+
break;
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
case 'max':
|
|
258
|
+
{
|
|
259
|
+
assertMinMax(newVal, name);
|
|
260
|
+
|
|
261
|
+
_classPrivateFieldSet(this, _maxDate, isoToDate(newVal));
|
|
262
|
+
|
|
263
|
+
assertDate(_classPrivateFieldGet(this, _maxDate), name, newVal);
|
|
264
|
+
|
|
265
|
+
if (_classPrivateFieldGet(this, _date) !== null) {
|
|
266
|
+
clampMaxDate(_classPrivateFieldGet(this, _date), _classPrivateFieldGet(this, _maxDate));
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
_classPrivateMethodGet(this, _render, _render2).call(this);
|
|
270
|
+
|
|
271
|
+
break;
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
case 'locale':
|
|
275
|
+
{
|
|
276
|
+
assertLocale(newVal);
|
|
277
|
+
const names = getDayNames(newVal);
|
|
278
|
+
|
|
279
|
+
_classPrivateFieldGet(this, _$weekDayNames).forEach(($day, i) => {
|
|
280
|
+
$day.textContent = names[i];
|
|
281
|
+
});
|
|
282
|
+
|
|
283
|
+
_classPrivateFieldSet(this, _monthNames, getMonthNames(newVal));
|
|
284
|
+
|
|
285
|
+
_classPrivateMethodGet(this, _render, _render2).call(this);
|
|
286
|
+
|
|
287
|
+
break;
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
get nodeName() {
|
|
293
|
+
return 'select';
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
set locale(value) {
|
|
297
|
+
updateAttribute(this, 'locale', value);
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
get locale() {
|
|
301
|
+
return getAttribute(this, 'locale');
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
set value(value) {
|
|
305
|
+
updateAttribute(this, 'value', value);
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
get value() {
|
|
309
|
+
return getAttribute(this, 'value', '');
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
set min(value) {
|
|
313
|
+
updateAttribute(this, 'min', value);
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
get min() {
|
|
317
|
+
return getAttribute(this, 'min', '');
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
set max(value) {
|
|
321
|
+
updateAttribute(this, 'max', value);
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
get max() {
|
|
325
|
+
return getAttribute(this, 'max', '');
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
get prevYearButtonRect() {
|
|
329
|
+
return getRect(_classPrivateFieldGet(this, _$prevYear));
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
get nextYearButtonRect() {
|
|
333
|
+
return getRect(_classPrivateFieldGet(this, _$nextYear));
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
get prevMonthButtonRect() {
|
|
337
|
+
return getRect(_classPrivateFieldGet(this, _$prevMonth));
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
get nextMonthButtonRect() {
|
|
341
|
+
return getRect(_classPrivateFieldGet(this, _$nextMonth));
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
nthButtonRect(index) {
|
|
345
|
+
if (index < 0 || index > 30) {
|
|
346
|
+
return null;
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
const indexOffset = _classPrivateFieldGet(this, _$days)[0].findIndex(el => el.getAttribute('data-date') !== null);
|
|
350
|
+
|
|
351
|
+
if (indexOffset < 0) {
|
|
352
|
+
return null;
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
const rowIndex = Math.floor((indexOffset + index) / 7);
|
|
356
|
+
const colIndex = (indexOffset + index) % 7;
|
|
357
|
+
const $el = _classPrivateFieldGet(this, _$days)[rowIndex]?.[colIndex];
|
|
358
|
+
|
|
359
|
+
if ($el == null) {
|
|
360
|
+
return null;
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
return getRect($el);
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
}));
|
|
367
|
+
|
|
368
|
+
function _render2() {
|
|
369
|
+
if (_classPrivateFieldGet(this, _date) === null || _classPrivateFieldGet(this, _minDate) === null || _classPrivateFieldGet(this, _maxDate) === null || this.locale === null) {
|
|
370
|
+
return;
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
const valueDate = isoToDate(this.value);
|
|
374
|
+
const todayDate = new Date();
|
|
375
|
+
const month = getCalendarMonth(_classPrivateFieldGet(this, _date));
|
|
376
|
+
updateBooleanAttribute(_classPrivateFieldGet(this, _$prevMonth), 'disabled', canGoPrevMonth(_classPrivateFieldGet(this, _date), _classPrivateFieldGet(this, _minDate)) === false);
|
|
377
|
+
updateBooleanAttribute(_classPrivateFieldGet(this, _$nextMonth), 'disabled', canGoNextMonth(_classPrivateFieldGet(this, _date), _classPrivateFieldGet(this, _maxDate)) === false);
|
|
378
|
+
updateBooleanAttribute(_classPrivateFieldGet(this, _$prevYear), 'disabled', canGoPrevYear(_classPrivateFieldGet(this, _date), _classPrivateFieldGet(this, _minDate)) === false);
|
|
379
|
+
updateBooleanAttribute(_classPrivateFieldGet(this, _$nextYear), 'disabled', canGoNextYear(_classPrivateFieldGet(this, _date), _classPrivateFieldGet(this, _maxDate)) === false);
|
|
380
|
+
_classPrivateFieldGet(this, _$date).textContent = `${_classPrivateFieldGet(this, _monthNames)[_classPrivateFieldGet(this, _date).getMonth()]} ${_classPrivateFieldGet(this, _date).getFullYear()}`;
|
|
381
|
+
|
|
382
|
+
_classPrivateFieldGet(this, _$days).forEach(($week, wi) => {
|
|
383
|
+
let isEmptyWeek = true;
|
|
384
|
+
$week.forEach(($day, di) => {
|
|
385
|
+
const week = month[wi];
|
|
386
|
+
const day = week?.[di];
|
|
387
|
+
$day.classList.remove('selected');
|
|
388
|
+
$day.classList.remove('today');
|
|
389
|
+
|
|
390
|
+
if (day == null) {
|
|
391
|
+
$day.textContent = '';
|
|
392
|
+
$day.removeAttribute('data-date');
|
|
393
|
+
$day.setAttribute('disabled', '');
|
|
394
|
+
$day.setAttribute('aria-hidden', 'true');
|
|
395
|
+
} else {
|
|
396
|
+
const dayIso = dateToIso(day);
|
|
397
|
+
$day.textContent = day.getDate().toString();
|
|
398
|
+
$day.setAttribute('data-date', dayIso);
|
|
399
|
+
|
|
400
|
+
if (isDateBetween(day, _classPrivateFieldGet(this, _minDate), _classPrivateFieldGet(this, _maxDate))) {
|
|
401
|
+
$day.removeAttribute('disabled');
|
|
402
|
+
$day.removeAttribute('aria-hidden');
|
|
403
|
+
} else {
|
|
404
|
+
$day.setAttribute('disabled', '');
|
|
405
|
+
$day.setAttribute('aria-hidden', 'true');
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
if (areDatesEqual(day, valueDate)) {
|
|
409
|
+
$day.classList.add('selected');
|
|
410
|
+
} else if (areDatesEqual(day, todayDate)) {
|
|
411
|
+
$day.classList.add('today');
|
|
412
|
+
}
|
|
413
|
+
|
|
414
|
+
isEmptyWeek = false;
|
|
415
|
+
}
|
|
416
|
+
});
|
|
417
|
+
setClass(_classPrivateFieldGet(this, _$weeks)[wi], 'empty', isEmptyWeek);
|
|
418
|
+
});
|
|
419
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { TRect, TSinchElementReact } from '../types';
|
|
2
|
+
import type { SyntheticEvent } from 'react';
|
|
3
|
+
export declare type TSinchDatePickerElement = HTMLElement & {
|
|
4
|
+
value: string;
|
|
5
|
+
min: string;
|
|
6
|
+
max: string;
|
|
7
|
+
locale: string;
|
|
8
|
+
readonly prevYearButtonRect: TRect;
|
|
9
|
+
readonly nextYearButtonRect: TRect;
|
|
10
|
+
readonly prevMonthButtonRect: TRect;
|
|
11
|
+
readonly nextMonthButtonRect: TRect;
|
|
12
|
+
nthButtonRect(index: number): TRect | null;
|
|
13
|
+
addEventListener(type: 'change', listener: (e: CustomEvent<string>) => void): void;
|
|
14
|
+
setAttribute(name: 'value', value: string): void;
|
|
15
|
+
setAttribute(name: 'min', value: string): void;
|
|
16
|
+
setAttribute(name: 'max', value: string): void;
|
|
17
|
+
setAttribute(name: 'locale', value: string): void;
|
|
18
|
+
};
|
|
19
|
+
export declare type TSinchDatePickerReact = TSinchElementReact<TSinchDatePickerElement> & {
|
|
20
|
+
locale: string;
|
|
21
|
+
value: string;
|
|
22
|
+
min: string;
|
|
23
|
+
max: string;
|
|
24
|
+
'aria-label': string;
|
|
25
|
+
onChange: (e: SyntheticEvent<TSinchDatePickerElement, CustomEvent<string>>) => void;
|
|
26
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
declare type TCalendarOptions = {
|
|
2
|
+
firstDayOfWeek: 0 | 1 | 2 | 3 | 4 | 5 | 6;
|
|
3
|
+
};
|
|
4
|
+
declare type TMaybeDate = Date | null;
|
|
5
|
+
export declare const getCalendarMonth: (date: Date, options?: TCalendarOptions) => TMaybeDate[][];
|
|
6
|
+
export declare const dateToIso: (date: Date) => string;
|
|
7
|
+
export declare const isoToDate: (value: string) => Date;
|
|
8
|
+
export declare const getDayNames: (locale: string) => string[];
|
|
9
|
+
export declare const getMonthNames: (locale: string) => string[];
|
|
10
|
+
declare type TAssertMinMax = (value: string | null, attrName: string) => asserts value is string;
|
|
11
|
+
export declare const assertMinMax: TAssertMinMax;
|
|
12
|
+
declare type TAssertValue = (value: string | null) => asserts value is string;
|
|
13
|
+
export declare const assertValue: TAssertValue;
|
|
14
|
+
declare type TAssertLocale = (value: string | null) => asserts value is string;
|
|
15
|
+
export declare const assertLocale: TAssertLocale;
|
|
16
|
+
declare type TAssertDate = (value: any, attrName: string, attrValue: string) => asserts value is Date;
|
|
17
|
+
export declare const isValidDate: (value: any) => value is Date;
|
|
18
|
+
export declare const assertDate: TAssertDate;
|
|
19
|
+
export declare const cloneDate: (date: Date) => Date;
|
|
20
|
+
export declare const clampMinDate: (date: Date, min: Date) => void;
|
|
21
|
+
export declare const clampMaxDate: (date: Date, max: Date) => void;
|
|
22
|
+
export declare const incMonth: (date: Date, max: Date) => void;
|
|
23
|
+
export declare const decMonth: (date: Date, min: Date) => void;
|
|
24
|
+
export declare const incYear: (date: Date, max: Date) => void;
|
|
25
|
+
export declare const decYear: (date: Date, min: Date) => void;
|
|
26
|
+
export declare const canGoPrevMonth: (date: Date, min: Date) => boolean;
|
|
27
|
+
export declare const canGoNextMonth: (date: Date, max: Date) => boolean;
|
|
28
|
+
export declare const canGoNextYear: (date: Date, max: Date) => boolean;
|
|
29
|
+
export declare const canGoPrevYear: (date: Date, min: Date) => boolean;
|
|
30
|
+
export declare const isDateBetween: (date: Date, min: Date, max: Date) => boolean;
|
|
31
|
+
export declare const areDatesEqual: (a: Date, b: Date) => boolean;
|
|
32
|
+
export {};
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
const DAYS_IN_WEEK = 7;
|
|
2
|
+
export const getCalendarMonth = (date, options) => {
|
|
3
|
+
const {
|
|
4
|
+
firstDayOfWeek
|
|
5
|
+
} = {
|
|
6
|
+
firstDayOfWeek: 1,
|
|
7
|
+
...options
|
|
8
|
+
};
|
|
9
|
+
const firstDateOfMonth = new Date(date.getFullYear(), date.getMonth(), 1);
|
|
10
|
+
const lastDateOfMonth = new Date(date.getFullYear(), date.getMonth() + 1, 0);
|
|
11
|
+
const firstWeekdayOfMonth = firstDateOfMonth.getDay();
|
|
12
|
+
const lastWeekdayOfMonth = lastDateOfMonth.getDay();
|
|
13
|
+
const daysInMonth = lastDateOfMonth.getDate();
|
|
14
|
+
const daysToPrepend = (firstWeekdayOfMonth - firstDayOfWeek + DAYS_IN_WEEK) % DAYS_IN_WEEK;
|
|
15
|
+
const daysToAppend = (DAYS_IN_WEEK - 1 - lastWeekdayOfMonth + firstDayOfWeek) % DAYS_IN_WEEK;
|
|
16
|
+
const month = [];
|
|
17
|
+
let week = [];
|
|
18
|
+
|
|
19
|
+
for (let i = 1 - daysToPrepend; i <= daysInMonth + daysToAppend + 1; i++) {
|
|
20
|
+
if (i <= 0 || i > daysInMonth) {
|
|
21
|
+
week.push(null);
|
|
22
|
+
} else {
|
|
23
|
+
const result = new Date(date);
|
|
24
|
+
result.setDate(i);
|
|
25
|
+
week.push(result);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
if (week.length === 7) {
|
|
29
|
+
month.push(week);
|
|
30
|
+
week = [];
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
return month;
|
|
35
|
+
};
|
|
36
|
+
export const dateToIso = date => {
|
|
37
|
+
return date.toISOString().substring(0, 10);
|
|
38
|
+
};
|
|
39
|
+
export const isoToDate = value => {
|
|
40
|
+
return new Date(`${value.substring(0, 10)}T00:00:00Z`);
|
|
41
|
+
};
|
|
42
|
+
export const getDayNames = locale => {
|
|
43
|
+
const formatter = new Intl.DateTimeFormat(locale, {
|
|
44
|
+
weekday: 'narrow',
|
|
45
|
+
timeZone: 'UTC'
|
|
46
|
+
});
|
|
47
|
+
return [1, 2, 3, 4, 5, 6, 7].map(dd => {
|
|
48
|
+
const date = new Date(Date.UTC(2018, 0, dd));
|
|
49
|
+
return formatter.format(date);
|
|
50
|
+
});
|
|
51
|
+
};
|
|
52
|
+
export const getMonthNames = locale => {
|
|
53
|
+
const formatter = new Intl.DateTimeFormat(locale, {
|
|
54
|
+
month: 'short',
|
|
55
|
+
timeZone: 'UTC'
|
|
56
|
+
});
|
|
57
|
+
return [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11].map(mm => {
|
|
58
|
+
const date = new Date(Date.UTC(2018, mm, 1));
|
|
59
|
+
return formatter.format(date);
|
|
60
|
+
});
|
|
61
|
+
};
|
|
62
|
+
export const assertMinMax = (value, attrName) => {
|
|
63
|
+
if (value == null || value === '') {
|
|
64
|
+
throw new Error(`sinch-date-picker: missing or empty "${attrName}" attribute`);
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
export const assertValue = value => {
|
|
68
|
+
if (value == null) {
|
|
69
|
+
throw new Error(`sinch-date-picker: missing "value" attribute`);
|
|
70
|
+
}
|
|
71
|
+
};
|
|
72
|
+
export const assertLocale = value => {
|
|
73
|
+
if (value === null || value.length === 0) {
|
|
74
|
+
throw new Error(`sinch-date-picker: invalid locale attribute: ${value}`);
|
|
75
|
+
}
|
|
76
|
+
};
|
|
77
|
+
export const isValidDate = value => {
|
|
78
|
+
return value instanceof Date && !isNaN(value);
|
|
79
|
+
};
|
|
80
|
+
export const assertDate = (value, attrName, attrValue) => {
|
|
81
|
+
if (!isValidDate(value)) {
|
|
82
|
+
throw new Error(`sinch-date-picker: invalid "${attrName}" attribute: ${attrValue}`);
|
|
83
|
+
}
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
const compareDates = (a, b) => {
|
|
87
|
+
return a.getTime() - b.getTime();
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
export const cloneDate = date => {
|
|
91
|
+
const result = new Date(date);
|
|
92
|
+
result.setHours(0, 0, 0, 0);
|
|
93
|
+
return result;
|
|
94
|
+
};
|
|
95
|
+
export const clampMinDate = (date, min) => {
|
|
96
|
+
if (compareDates(min, date) > 0) {
|
|
97
|
+
date.setTime(min.getTime());
|
|
98
|
+
}
|
|
99
|
+
};
|
|
100
|
+
export const clampMaxDate = (date, max) => {
|
|
101
|
+
if (compareDates(date, max) > 0) {
|
|
102
|
+
date.setTime(max.getTime());
|
|
103
|
+
}
|
|
104
|
+
};
|
|
105
|
+
export const incMonth = (date, max) => {
|
|
106
|
+
date.setMonth(date.getMonth() + 1);
|
|
107
|
+
clampMaxDate(date, max);
|
|
108
|
+
};
|
|
109
|
+
export const decMonth = (date, min) => {
|
|
110
|
+
date.setMonth(date.getMonth() - 1);
|
|
111
|
+
clampMinDate(date, min);
|
|
112
|
+
};
|
|
113
|
+
export const incYear = (date, max) => {
|
|
114
|
+
date.setFullYear(date.getFullYear() + 1);
|
|
115
|
+
clampMaxDate(date, max);
|
|
116
|
+
};
|
|
117
|
+
export const decYear = (date, min) => {
|
|
118
|
+
date.setFullYear(date.getFullYear() - 1);
|
|
119
|
+
clampMinDate(date, min);
|
|
120
|
+
};
|
|
121
|
+
export const canGoPrevMonth = (date, min) => {
|
|
122
|
+
const prevMonth = new Date(Date.UTC(date.getFullYear(), date.getMonth(), 0));
|
|
123
|
+
return compareDates(prevMonth, min) >= 0;
|
|
124
|
+
};
|
|
125
|
+
export const canGoNextMonth = (date, max) => {
|
|
126
|
+
const nextMonth = new Date(Date.UTC(date.getFullYear(), date.getMonth() + 1, 1));
|
|
127
|
+
return compareDates(max, nextMonth) >= 0;
|
|
128
|
+
};
|
|
129
|
+
export const canGoNextYear = (date, max) => {
|
|
130
|
+
const nextYear = new Date(Date.UTC(date.getFullYear() + 1, 0, 1));
|
|
131
|
+
return compareDates(max, nextYear) >= 0;
|
|
132
|
+
};
|
|
133
|
+
export const canGoPrevYear = (date, min) => {
|
|
134
|
+
const prevYear = new Date(Date.UTC(date.getFullYear(), 0, 0));
|
|
135
|
+
return compareDates(prevYear, min) >= 0;
|
|
136
|
+
};
|
|
137
|
+
export const isDateBetween = (date, min, max) => {
|
|
138
|
+
return compareDates(date, min) >= 0 && compareDates(max, date) >= 0;
|
|
139
|
+
};
|
|
140
|
+
export const areDatesEqual = (a, b) => {
|
|
141
|
+
return compareDates(a, b) === 0;
|
|
142
|
+
};
|