ublo-lib 1.12.29 → 1.13.1

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.
@@ -13,31 +13,8 @@ import datePickerStyles from "./date-picker.module.css";
13
13
  import styles from "./calendar.module.css";
14
14
  import { jsx as _jsx } from "react/jsx-runtime";
15
15
  import { jsxs as _jsxs } from "react/jsx-runtime";
16
- const ConfirmDateChangeForm = ({
17
- lang,
18
- cancel,
19
- confirm
20
- }) => {
21
- return _jsxs("div", {
22
- className: styles.confirmDateChange,
23
- children: [_jsx("div", {
24
- className: styles.confirmDateChangeMessage,
25
- children: Messages.get(lang, "warning-date-change-text")
26
- }), _jsxs("div", {
27
- className: styles.confirmDateChangeButtons,
28
- children: [_jsx("button", {
29
- className: classNames(styles.confirmDateChangeButton, styles.confirmDateChangeButtonCancel),
30
- onClick: cancel,
31
- children: Messages.get(lang, "warning-date-change-cancel")
32
- }), _jsx("button", {
33
- className: classNames(styles.confirmDateChangeButton, styles.confirmDateChangeButtonConfirm),
34
- onClick: confirm,
35
- children: Messages.get(lang, "warning-date-change-confirm")
36
- })]
37
- })]
38
- });
39
- };
40
- const Calendar = ({
16
+ export default React.memo(Calendar);
17
+ function Calendar({
41
18
  date,
42
19
  mode,
43
20
  setMode,
@@ -49,8 +26,9 @@ const Calendar = ({
49
26
  rules,
50
27
  hideModes,
51
28
  singleDate,
52
- submitOnSelectionEnd
53
- }) => {
29
+ submitOnSelectionEnd,
30
+ availabilities
31
+ }) {
54
32
  const isDateObject = Utils.isDate(date);
55
33
  const _date = isDateObject ? date : new Date();
56
34
  const {
@@ -68,6 +46,7 @@ const Calendar = ({
68
46
  const [firstSelectedDate, setFirstSelectedDate] = React.useState();
69
47
  const [lastSelectedDate, setLastSelectedDate] = React.useState();
70
48
  const [showPopup, setShowPopup] = React.useState(false);
49
+ const [stays, setStays] = React.useState();
71
50
  const mustKeepSelected = firstRangeDate && !selecting && (Utils.isSaturday(firstRangeDate) && Utils.isSaturday(selectedDates[selectedDates.length - 1]) || Utils.isSunday(firstRangeDate) && Utils.isSunday(selectedDates[selectedDates.length - 1]));
72
51
  const gotoPreviousMonth = () => {
73
52
  const {
@@ -154,6 +133,37 @@ const Calendar = ({
154
133
  const isPast = month <= currentMonth && year <= currentYear;
155
134
  const showSubmit = !submitOnSelectionEnd && selectedDates.length > 0 && !selecting;
156
135
  const hide2ndMonth = display !== Data.DISPLAYS.DESKTOP;
136
+ React.useEffect(() => {
137
+ if (availabilities) {
138
+ const fetchAvailabilities = async () => {
139
+ setStays(undefined);
140
+ const bareStart = `${year}-${Utils.zeroPad(month, 2)}-01`;
141
+ const start = Utils.addDays(bareStart, -7);
142
+ const numberDays = hide2ndMonth ? 38 : 76;
143
+ const {
144
+ fetcher,
145
+ ...rest
146
+ } = availabilities;
147
+ const {
148
+ stays
149
+ } = await fetcher({
150
+ ...rest,
151
+ start,
152
+ numberDays
153
+ });
154
+ if (stays?.length) {
155
+ const formatedStays = stays.map(stay => {
156
+ return {
157
+ start: new Date(stay.start),
158
+ end: new Date(stay.end)
159
+ };
160
+ });
161
+ setStays(formatedStays);
162
+ }
163
+ };
164
+ fetchAvailabilities();
165
+ }
166
+ }, [availabilities, hide2ndMonth, month, year]);
157
167
  const classes = classNames(styles.calendar, {
158
168
  [styles.calendarTouch]: hide2ndMonth,
159
169
  [styles.hiddenModes]: hideModes
@@ -190,7 +200,7 @@ const Calendar = ({
190
200
  singleDate: singleDate,
191
201
  submitOnSelectionEnd: submitOnSelectionEnd,
192
202
  onSubmit: submit,
193
- setShowPopup: setShowPopup
203
+ stays: stays
194
204
  }), !hide2ndMonth && _jsx(Month, {
195
205
  mode: mode,
196
206
  setMode: setMode,
@@ -207,7 +217,8 @@ const Calendar = ({
207
217
  setLastSelectedDate: setLastSelectedDate,
208
218
  singleDate: singleDate,
209
219
  submitOnSelectionEnd: submitOnSelectionEnd,
210
- onSubmit: submit
220
+ onSubmit: submit,
221
+ stays: stays
211
222
  }), showSubmit && _jsxs(Button, {
212
223
  className: styles.submit,
213
224
  onClick: () => submit(selectedDates),
@@ -228,5 +239,28 @@ const Calendar = ({
228
239
  })
229
240
  })]
230
241
  });
231
- };
232
- export default React.memo(Calendar);
242
+ }
243
+ function ConfirmDateChangeForm({
244
+ lang,
245
+ cancel,
246
+ confirm
247
+ }) {
248
+ return _jsxs("div", {
249
+ className: styles.confirmDateChange,
250
+ children: [_jsx("div", {
251
+ className: styles.confirmDateChangeMessage,
252
+ children: Messages.get(lang, "warning-date-change-text")
253
+ }), _jsxs("div", {
254
+ className: styles.confirmDateChangeButtons,
255
+ children: [_jsx("button", {
256
+ className: classNames(styles.confirmDateChangeButton, styles.confirmDateChangeButtonCancel),
257
+ onClick: cancel,
258
+ children: Messages.get(lang, "warning-date-change-cancel")
259
+ }), _jsx("button", {
260
+ className: classNames(styles.confirmDateChangeButton, styles.confirmDateChangeButtonConfirm),
261
+ onClick: confirm,
262
+ children: Messages.get(lang, "warning-date-change-confirm")
263
+ })]
264
+ })]
265
+ });
266
+ }
@@ -20,13 +20,18 @@ const DateItem = ({
20
20
  setSelecting,
21
21
  singleDate,
22
22
  submitOnSelectionEnd,
23
- onSubmit
23
+ onSubmit,
24
+ stays
24
25
  }) => {
25
26
  const today = new Date();
26
27
  const _date = new Date(date.join("-"));
27
28
  _date.setHours(0, 0, 0, 0);
28
29
  const isToday = Utils.isSameDay(_date, today);
29
30
  const inMonth = month && year && Utils.isSameMonth(_date, new Date([Utils.zeroPad(year, 2), Utils.zeroPad(month, 2), "01"].join("-")));
31
+ const enableAvailability = Boolean(stays);
32
+ const isAvailable = stays?.some(stay => {
33
+ return stay.start < _date && stay.end > _date;
34
+ }) || false;
30
35
  const firstDate = selectedDates[0];
31
36
  const isFirstSelected = selectedDates.map(Number).indexOf(Number(_date)) === 0;
32
37
  const isLastSelected = selectedDates.map(Number).indexOf(Number(_date)) === selectedDates.length - 1;
@@ -95,7 +100,9 @@ const DateItem = ({
95
100
  [styles.dateNotInMonth]: !inMonth,
96
101
  [styles.dateIsPast]: isPastDate,
97
102
  [styles.dateSaturday]: mode === Data.MODES.SATURDAY && Utils.isSaturday(date),
98
- [styles.dateSunday]: mode === Data.MODES.SUNDAY && Utils.isSunday(date)
103
+ [styles.dateSunday]: mode === Data.MODES.SUNDAY && Utils.isSunday(date),
104
+ [styles.available]: enableAvailability && isAvailable,
105
+ [styles.notAvailable]: enableAvailability && !isAvailable
99
106
  });
100
107
  return _jsx("button", {
101
108
  className: classes,
@@ -1,6 +1,10 @@
1
1
  .date {
2
2
  width: 100%;
3
3
  padding: 8px 6px;
4
+ display: flex;
5
+ align-items: center;
6
+ justify-content: center;
7
+ gap: 4px;
4
8
  font-size: 14px;
5
9
  text-align: center;
6
10
  cursor: pointer;
@@ -76,3 +80,20 @@
76
80
  .date:not(.dateIsPast):not(.dateSelected):hover {
77
81
  background-color: var(--ds-grey-200, #efefef);
78
82
  }
83
+
84
+ .available::after,
85
+ .notAvailable::after {
86
+ content: "";
87
+ flex: 0 0 6px;
88
+ width: 6px;
89
+ height: 6px;
90
+ border-radius: 50%;
91
+ }
92
+
93
+ .available::after {
94
+ background-color: hsl(var(--green));
95
+ }
96
+
97
+ .notAvailable::after {
98
+ background-color: hsl(var(--red));
99
+ }
@@ -20,7 +20,8 @@ const DatePicker = ({
20
20
  defaultMode = Data.MODES[DEFAULT_MODE],
21
21
  rules,
22
22
  singleDate,
23
- submitOnSelectionEnd
23
+ submitOnSelectionEnd,
24
+ availabilities
24
25
  }) => {
25
26
  const [display, setDisplay] = React.useState(Data.DISPLAYS.DESKTOP);
26
27
  const [specialRule, setSpecialRule] = React.useState();
@@ -89,7 +90,8 @@ const DatePicker = ({
89
90
  setSpecialRule: setSpecialRule,
90
91
  hideModes: hideModes,
91
92
  singleDate: singleDate,
92
- submitOnSelectionEnd: submitOnSelectionEnd
93
+ submitOnSelectionEnd: submitOnSelectionEnd,
94
+ availabilities: availabilities
93
95
  }), specialRule && _jsxs("div", {
94
96
  className: styles.specialRule,
95
97
  children: [_jsx(Icons.Info, {}), _jsxs("div", {
@@ -20,7 +20,8 @@ const Month = ({
20
20
  setLastSelectedDate,
21
21
  singleDate,
22
22
  submitOnSelectionEnd,
23
- onSubmit
23
+ onSubmit,
24
+ stays
24
25
  }) => {
25
26
  const {
26
27
  lang
@@ -67,7 +68,8 @@ const Month = ({
67
68
  setSelecting: setSelecting,
68
69
  singleDate: singleDate,
69
70
  submitOnSelectionEnd: submitOnSelectionEnd,
70
- onSubmit: onSubmit
71
+ onSubmit: onSubmit,
72
+ stays: stays
71
73
  }, i);
72
74
  })
73
75
  })]
@@ -65,17 +65,17 @@ export const isBefore = (date, ref) => {
65
65
  const _ref = new Date(r);
66
66
  return _date < _ref;
67
67
  };
68
+ export function addDays(_date, days) {
69
+ const date = new Date(_date);
70
+ date.setDate(date.getDate() + days);
71
+ return date;
72
+ }
68
73
  export const getDateInterval = (startDate, endDate) => {
69
74
  const dates = [];
70
75
  let currentDate = startDate;
71
- const addDays = function (days) {
72
- const date = new Date(this.valueOf());
73
- date.setDate(date.getDate() + days);
74
- return date;
75
- };
76
76
  while (currentDate <= endDate) {
77
77
  dates.push(currentDate);
78
- currentDate = addDays.call(currentDate, 1);
78
+ currentDate = addDays(currentDate, 1);
79
79
  }
80
80
  return dates;
81
81
  };
@@ -1,4 +1,5 @@
1
1
  import * as React from "react";
2
+ import * as L from "leaflet";
2
3
  import classNames from "classnames";
3
4
  import css from "./marker-list.module.css";
4
5
  import Button from "dt-design-system/es/button";
@@ -48,12 +49,23 @@ export default function MarkerList({
48
49
  important
49
50
  }) => {
50
51
  const focusMarker = e => {
51
- e.preventDefault();
52
52
  e.stopPropagation();
53
+ e.preventDefault();
54
+ mapRef.current.setView(position, 20);
55
+ setTimeout(() => {
56
+ mapRef.current.eachLayer(layer => {
57
+ if (layer instanceof L.Marker) {
58
+ const markerElement = layer.getElement();
59
+ const markerId = markerElement.querySelector(`[data-id="${id}"]`)?.getAttribute("data-id");
60
+ if (markerId) {
61
+ layer.openPopup();
62
+ }
63
+ }
64
+ });
65
+ }, 300);
53
66
  if (width <= 992) {
54
67
  setOpened(false);
55
68
  }
56
- mapRef.current.setView(position, 23);
57
69
  };
58
70
  const Icon = Icons[iconSet][icon] || Icons[iconSet].Location;
59
71
  const classes = classNames(css.button, {
@@ -52,6 +52,19 @@
52
52
  overflow: auto;
53
53
  animation: marker-list-inner-appearance 160ms
54
54
  var(--ds-transition-easing, cubic-bezier(0.4, 0.1, 0.2, 0.9));
55
+ background: linear-gradient(
56
+ var(--ds-grey-100, #f8f8f8) 30%,
57
+ hsla(0, 0%, 100%, 0)
58
+ ),
59
+ linear-gradient(hsla(0, 0%, 100%, 0), var(--ds-grey-100, #f8f8f8) 70%) 0
60
+ 100%,
61
+ radial-gradient(farthest-side at 50% 0, rgba(0, 0, 0, 0.25), transparent),
62
+ radial-gradient(farthest-side at 50% 100%, rgba(0, 0, 0, 0.25), transparent)
63
+ 0 100%;
64
+ background-repeat: no-repeat;
65
+ background-size: 100% 30px, 100% 30px, 100% 10px, 100% 10px;
66
+ background-attachment: local, local, scroll, scroll;
67
+ border-radius: inherit;
55
68
  }
56
69
 
57
70
  @keyframes marker-list-inner-appearance {
@@ -70,6 +83,7 @@
70
83
  text-align: left;
71
84
  border-radius: var(--ds-radius-100, 6px);
72
85
  cursor: pointer;
86
+ user-select: none;
73
87
  }
74
88
 
75
89
  .listIsInDialog .button:first-of-type {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ublo-lib",
3
- "version": "1.12.29",
3
+ "version": "1.13.1",
4
4
  "peerDependencies": {
5
5
  "dt-design-system": "^2.1.0",
6
6
  "leaflet": "^1.9.1",