@chayns-components/date 5.0.0-beta.1000
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/LICENSE +21 -0
- package/README.md +34 -0
- package/lib/cjs/components/calendar/Calendar.js +314 -0
- package/lib/cjs/components/calendar/Calendar.js.map +1 -0
- package/lib/cjs/components/calendar/Calendar.styles.js +34 -0
- package/lib/cjs/components/calendar/Calendar.styles.js.map +1 -0
- package/lib/cjs/components/calendar/month-wrapper/MonthWrapper.js +158 -0
- package/lib/cjs/components/calendar/month-wrapper/MonthWrapper.js.map +1 -0
- package/lib/cjs/components/calendar/month-wrapper/MonthWrapper.styles.js +23 -0
- package/lib/cjs/components/calendar/month-wrapper/MonthWrapper.styles.js.map +1 -0
- package/lib/cjs/components/calendar/month-wrapper/month/Month.js +65 -0
- package/lib/cjs/components/calendar/month-wrapper/month/Month.js.map +1 -0
- package/lib/cjs/components/calendar/month-wrapper/month/Month.styles.js +26 -0
- package/lib/cjs/components/calendar/month-wrapper/month/Month.styles.js.map +1 -0
- package/lib/cjs/components/calendar/month-wrapper/month/day-wrapper/DayWrapper.js +129 -0
- package/lib/cjs/components/calendar/month-wrapper/month/day-wrapper/DayWrapper.js.map +1 -0
- package/lib/cjs/components/calendar/month-wrapper/month/day-wrapper/DayWrapper.styles.js +16 -0
- package/lib/cjs/components/calendar/month-wrapper/month/day-wrapper/DayWrapper.styles.js.map +1 -0
- package/lib/cjs/components/calendar/month-wrapper/month/day-wrapper/day/Day.js +63 -0
- package/lib/cjs/components/calendar/month-wrapper/month/day-wrapper/day/Day.js.map +1 -0
- package/lib/cjs/components/calendar/month-wrapper/month/day-wrapper/day/Day.styles.js +114 -0
- package/lib/cjs/components/calendar/month-wrapper/month/day-wrapper/day/Day.styles.js.map +1 -0
- package/lib/cjs/components/calendar/month-wrapper/month/day-wrapper/day/category/Category.js +17 -0
- package/lib/cjs/components/calendar/month-wrapper/month/day-wrapper/day/category/Category.js.map +1 -0
- package/lib/cjs/components/calendar/month-wrapper/month/day-wrapper/day/category/Category.styles.js +18 -0
- package/lib/cjs/components/calendar/month-wrapper/month/day-wrapper/day/category/Category.styles.js.map +1 -0
- package/lib/cjs/components/calendar/month-wrapper/month/weekday-wrapper/WeekdayWrapper.js +42 -0
- package/lib/cjs/components/calendar/month-wrapper/month/weekday-wrapper/WeekdayWrapper.js.map +1 -0
- package/lib/cjs/components/calendar/month-wrapper/month/weekday-wrapper/WeekdayWrapper.styles.js +16 -0
- package/lib/cjs/components/calendar/month-wrapper/month/weekday-wrapper/WeekdayWrapper.styles.js.map +1 -0
- package/lib/cjs/components/calendar/month-wrapper/month/weekday-wrapper/weekday/Weekday.js +15 -0
- package/lib/cjs/components/calendar/month-wrapper/month/weekday-wrapper/weekday/Weekday.js.map +1 -0
- package/lib/cjs/components/calendar/month-wrapper/month/weekday-wrapper/weekday/Weekday.styles.js +17 -0
- package/lib/cjs/components/calendar/month-wrapper/month/weekday-wrapper/weekday/Weekday.styles.js.map +1 -0
- package/lib/cjs/components/calendar/month-year-pickers/MonthYearPickers.js +86 -0
- package/lib/cjs/components/calendar/month-year-pickers/MonthYearPickers.js.map +1 -0
- package/lib/cjs/components/date-info/DateInfo.js +35 -0
- package/lib/cjs/components/date-info/DateInfo.js.map +1 -0
- package/lib/cjs/components/opening-times/OpeningTimes.js +246 -0
- package/lib/cjs/components/opening-times/OpeningTimes.js.map +1 -0
- package/lib/cjs/components/opening-times/OpeningTimes.styles.js +28 -0
- package/lib/cjs/components/opening-times/OpeningTimes.styles.js.map +1 -0
- package/lib/cjs/components/opening-times/hint-text/HintText.js +19 -0
- package/lib/cjs/components/opening-times/hint-text/HintText.js.map +1 -0
- package/lib/cjs/components/opening-times/hint-text/HintText.styles.js +24 -0
- package/lib/cjs/components/opening-times/hint-text/HintText.styles.js.map +1 -0
- package/lib/cjs/components/opening-times/opening-inputs/OpeningInputs.js +153 -0
- package/lib/cjs/components/opening-times/opening-inputs/OpeningInputs.js.map +1 -0
- package/lib/cjs/components/opening-times/opening-inputs/OpeningInputs.styles.js +24 -0
- package/lib/cjs/components/opening-times/opening-inputs/OpeningInputs.styles.js.map +1 -0
- package/lib/cjs/components/opening-times/opening-inputs/opening-input/OpeningInput.js +106 -0
- package/lib/cjs/components/opening-times/opening-inputs/opening-input/OpeningInput.js.map +1 -0
- package/lib/cjs/components/opening-times/opening-inputs/opening-input/OpeningInput.styles.js +41 -0
- package/lib/cjs/components/opening-times/opening-inputs/opening-input/OpeningInput.styles.js.map +1 -0
- package/lib/cjs/hooks/useDateInfo.js +63 -0
- package/lib/cjs/hooks/useDateInfo.js.map +1 -0
- package/lib/cjs/index.js +177 -0
- package/lib/cjs/index.js.map +1 -0
- package/lib/cjs/types/calendar.js +28 -0
- package/lib/cjs/types/calendar.js.map +1 -0
- package/lib/cjs/types/dateinfo.js +2 -0
- package/lib/cjs/types/dateinfo.js.map +1 -0
- package/lib/cjs/types/openingTimes.js +18 -0
- package/lib/cjs/types/openingTimes.js.map +1 -0
- package/lib/cjs/utils/calendar.js +73 -0
- package/lib/cjs/utils/calendar.js.map +1 -0
- package/lib/cjs/utils/date.js +114 -0
- package/lib/cjs/utils/date.js.map +1 -0
- package/lib/cjs/utils/dateInfo.js +126 -0
- package/lib/cjs/utils/dateInfo.js.map +1 -0
- package/lib/esm/components/calendar/Calendar.js +306 -0
- package/lib/esm/components/calendar/Calendar.js.map +1 -0
- package/lib/esm/components/calendar/Calendar.styles.js +33 -0
- package/lib/esm/components/calendar/Calendar.styles.js.map +1 -0
- package/lib/esm/components/calendar/month-wrapper/MonthWrapper.js +150 -0
- package/lib/esm/components/calendar/month-wrapper/MonthWrapper.js.map +1 -0
- package/lib/esm/components/calendar/month-wrapper/MonthWrapper.styles.js +22 -0
- package/lib/esm/components/calendar/month-wrapper/MonthWrapper.styles.js.map +1 -0
- package/lib/esm/components/calendar/month-wrapper/month/Month.js +61 -0
- package/lib/esm/components/calendar/month-wrapper/month/Month.js.map +1 -0
- package/lib/esm/components/calendar/month-wrapper/month/Month.styles.js +22 -0
- package/lib/esm/components/calendar/month-wrapper/month/Month.styles.js.map +1 -0
- package/lib/esm/components/calendar/month-wrapper/month/day-wrapper/DayWrapper.js +121 -0
- package/lib/esm/components/calendar/month-wrapper/month/day-wrapper/DayWrapper.js.map +1 -0
- package/lib/esm/components/calendar/month-wrapper/month/day-wrapper/DayWrapper.styles.js +9 -0
- package/lib/esm/components/calendar/month-wrapper/month/day-wrapper/DayWrapper.styles.js.map +1 -0
- package/lib/esm/components/calendar/month-wrapper/month/day-wrapper/day/Day.js +54 -0
- package/lib/esm/components/calendar/month-wrapper/month/day-wrapper/day/Day.js.map +1 -0
- package/lib/esm/components/calendar/month-wrapper/month/day-wrapper/day/Day.styles.js +123 -0
- package/lib/esm/components/calendar/month-wrapper/month/day-wrapper/day/Day.styles.js.map +1 -0
- package/lib/esm/components/calendar/month-wrapper/month/day-wrapper/day/category/Category.js +13 -0
- package/lib/esm/components/calendar/month-wrapper/month/day-wrapper/day/category/Category.js.map +1 -0
- package/lib/esm/components/calendar/month-wrapper/month/day-wrapper/day/category/Category.styles.js +14 -0
- package/lib/esm/components/calendar/month-wrapper/month/day-wrapper/day/category/Category.styles.js.map +1 -0
- package/lib/esm/components/calendar/month-wrapper/month/weekday-wrapper/WeekdayWrapper.js +34 -0
- package/lib/esm/components/calendar/month-wrapper/month/weekday-wrapper/WeekdayWrapper.js.map +1 -0
- package/lib/esm/components/calendar/month-wrapper/month/weekday-wrapper/WeekdayWrapper.styles.js +9 -0
- package/lib/esm/components/calendar/month-wrapper/month/weekday-wrapper/WeekdayWrapper.styles.js.map +1 -0
- package/lib/esm/components/calendar/month-wrapper/month/weekday-wrapper/weekday/Weekday.js +11 -0
- package/lib/esm/components/calendar/month-wrapper/month/weekday-wrapper/weekday/Weekday.js.map +1 -0
- package/lib/esm/components/calendar/month-wrapper/month/weekday-wrapper/weekday/Weekday.styles.js +13 -0
- package/lib/esm/components/calendar/month-wrapper/month/weekday-wrapper/weekday/Weekday.styles.js.map +1 -0
- package/lib/esm/components/calendar/month-year-pickers/MonthYearPickers.js +79 -0
- package/lib/esm/components/calendar/month-year-pickers/MonthYearPickers.js.map +1 -0
- package/lib/esm/components/date-info/DateInfo.js +28 -0
- package/lib/esm/components/date-info/DateInfo.js.map +1 -0
- package/lib/esm/components/opening-times/OpeningTimes.js +240 -0
- package/lib/esm/components/opening-times/OpeningTimes.js.map +1 -0
- package/lib/esm/components/opening-times/OpeningTimes.styles.js +24 -0
- package/lib/esm/components/opening-times/OpeningTimes.styles.js.map +1 -0
- package/lib/esm/components/opening-times/hint-text/HintText.js +12 -0
- package/lib/esm/components/opening-times/hint-text/HintText.js.map +1 -0
- package/lib/esm/components/opening-times/hint-text/HintText.styles.js +23 -0
- package/lib/esm/components/opening-times/hint-text/HintText.styles.js.map +1 -0
- package/lib/esm/components/opening-times/opening-inputs/OpeningInputs.js +149 -0
- package/lib/esm/components/opening-times/opening-inputs/OpeningInputs.js.map +1 -0
- package/lib/esm/components/opening-times/opening-inputs/OpeningInputs.styles.js +22 -0
- package/lib/esm/components/opening-times/opening-inputs/OpeningInputs.styles.js.map +1 -0
- package/lib/esm/components/opening-times/opening-inputs/opening-input/OpeningInput.js +99 -0
- package/lib/esm/components/opening-times/opening-inputs/opening-input/OpeningInput.js.map +1 -0
- package/lib/esm/components/opening-times/opening-inputs/opening-input/OpeningInput.styles.js +40 -0
- package/lib/esm/components/opening-times/opening-inputs/opening-input/OpeningInput.styles.js.map +1 -0
- package/lib/esm/hooks/useDateInfo.js +57 -0
- package/lib/esm/hooks/useDateInfo.js.map +1 -0
- package/lib/esm/index.js +15 -0
- package/lib/esm/index.js.map +1 -0
- package/lib/esm/types/calendar.js +22 -0
- package/lib/esm/types/calendar.js.map +1 -0
- package/lib/esm/types/dateinfo.js +2 -0
- package/lib/esm/types/dateinfo.js.map +1 -0
- package/lib/esm/types/openingTimes.js +12 -0
- package/lib/esm/types/openingTimes.js.map +1 -0
- package/lib/esm/utils/calendar.js +63 -0
- package/lib/esm/utils/calendar.js.map +1 -0
- package/lib/esm/utils/date.js +89 -0
- package/lib/esm/utils/date.js.map +1 -0
- package/lib/esm/utils/dateInfo.js +120 -0
- package/lib/esm/utils/dateInfo.js.map +1 -0
- package/lib/types/components/calendar/Calendar.d.ts +97 -0
- package/lib/types/components/calendar/Calendar.styles.d.ts +8 -0
- package/lib/types/components/calendar/month-wrapper/MonthWrapper.d.ts +26 -0
- package/lib/types/components/calendar/month-wrapper/MonthWrapper.styles.d.ts +274 -0
- package/lib/types/components/calendar/month-wrapper/month/Month.d.ts +26 -0
- package/lib/types/components/calendar/month-wrapper/month/Month.styles.d.ts +8 -0
- package/lib/types/components/calendar/month-wrapper/month/day-wrapper/DayWrapper.d.ts +20 -0
- package/lib/types/components/calendar/month-wrapper/month/day-wrapper/DayWrapper.styles.d.ts +1 -0
- package/lib/types/components/calendar/month-wrapper/month/day-wrapper/day/Day.d.ts +19 -0
- package/lib/types/components/calendar/month-wrapper/month/day-wrapper/day/Day.styles.d.ts +20 -0
- package/lib/types/components/calendar/month-wrapper/month/day-wrapper/day/category/Category.d.ts +6 -0
- package/lib/types/components/calendar/month-wrapper/month/day-wrapper/day/category/Category.styles.d.ts +7 -0
- package/lib/types/components/calendar/month-wrapper/month/weekday-wrapper/WeekdayWrapper.d.ts +7 -0
- package/lib/types/components/calendar/month-wrapper/month/weekday-wrapper/WeekdayWrapper.styles.d.ts +1 -0
- package/lib/types/components/calendar/month-wrapper/month/weekday-wrapper/weekday/Weekday.d.ts +6 -0
- package/lib/types/components/calendar/month-wrapper/month/weekday-wrapper/weekday/Weekday.styles.d.ts +3 -0
- package/lib/types/components/calendar/month-year-pickers/MonthYearPickers.d.ts +19 -0
- package/lib/types/components/date-info/DateInfo.d.ts +5 -0
- package/lib/types/components/opening-times/OpeningTimes.d.ts +51 -0
- package/lib/types/components/opening-times/OpeningTimes.styles.d.ts +11 -0
- package/lib/types/components/opening-times/hint-text/HintText.d.ts +6 -0
- package/lib/types/components/opening-times/hint-text/HintText.styles.d.ts +3 -0
- package/lib/types/components/opening-times/opening-inputs/OpeningInputs.d.ts +46 -0
- package/lib/types/components/opening-times/opening-inputs/OpeningInputs.styles.d.ts +272 -0
- package/lib/types/components/opening-times/opening-inputs/opening-input/OpeningInput.d.ts +15 -0
- package/lib/types/components/opening-times/opening-inputs/opening-input/OpeningInput.styles.d.ts +273 -0
- package/lib/types/hooks/useDateInfo.d.ts +2 -0
- package/lib/types/index.d.ts +10 -0
- package/lib/types/types/calendar.d.ts +55 -0
- package/lib/types/types/dateinfo.d.ts +34 -0
- package/lib/types/types/openingTimes.d.ts +33 -0
- package/lib/types/utils/calendar.d.ts +18 -0
- package/lib/types/utils/date.d.ts +27 -0
- package/lib/types/utils/dateInfo.d.ts +14 -0
- package/package.json +86 -0
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { ComboBox } from '@chayns-components/core';
|
|
2
|
+
import React, { useMemo, useState } from 'react';
|
|
3
|
+
import { formatMonth, getYearsBetween, isDateInRange } from '../../../utils/calendar';
|
|
4
|
+
import { StyledMonthName } from '../month-wrapper/month/Month.styles';
|
|
5
|
+
import { differenceInCalendarMonths } from "../../../utils/date";
|
|
6
|
+
export let MonthYearPickerType = /*#__PURE__*/function (MonthYearPickerType) {
|
|
7
|
+
MonthYearPickerType["Month"] = "month";
|
|
8
|
+
MonthYearPickerType["Year"] = "year";
|
|
9
|
+
return MonthYearPickerType;
|
|
10
|
+
}({});
|
|
11
|
+
const MonthYearPickers = _ref => {
|
|
12
|
+
let {
|
|
13
|
+
month,
|
|
14
|
+
year,
|
|
15
|
+
locale,
|
|
16
|
+
minDate,
|
|
17
|
+
maxDate,
|
|
18
|
+
setCurrentDate,
|
|
19
|
+
displayIndex = 0,
|
|
20
|
+
showMonthYearPickers
|
|
21
|
+
} = _ref;
|
|
22
|
+
const [currentYear] = useState(new Date().getFullYear());
|
|
23
|
+
const months = useMemo(() => [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12].map(tempMonth => ({
|
|
24
|
+
text: formatMonth({
|
|
25
|
+
month: tempMonth,
|
|
26
|
+
locale
|
|
27
|
+
}),
|
|
28
|
+
value: tempMonth
|
|
29
|
+
})), [locale]);
|
|
30
|
+
const hasMultipleMonths = useMemo(() => differenceInCalendarMonths(maxDate, minDate) > 0, [minDate, maxDate]);
|
|
31
|
+
const years = useMemo(() => getYearsBetween(minDate, maxDate).map(tempYear => ({
|
|
32
|
+
text: tempYear.toString(),
|
|
33
|
+
value: tempYear
|
|
34
|
+
})), [minDate, maxDate]);
|
|
35
|
+
const hasMultipleYears = useMemo(() => years.length > 1, [years]);
|
|
36
|
+
return /*#__PURE__*/React.createElement(React.Fragment, null, showMonthYearPickers && hasMultipleMonths ? /*#__PURE__*/React.createElement(ComboBox, {
|
|
37
|
+
onSelect: selectedItem => {
|
|
38
|
+
const tempSelectedDate = isDateInRange({
|
|
39
|
+
minDate,
|
|
40
|
+
maxDate,
|
|
41
|
+
currentDate: new Date(year, selectedItem.value - 1 - displayIndex, 1)
|
|
42
|
+
});
|
|
43
|
+
setCurrentDate(tempSelectedDate);
|
|
44
|
+
},
|
|
45
|
+
lists: [{
|
|
46
|
+
list: months
|
|
47
|
+
}],
|
|
48
|
+
selectedItem: {
|
|
49
|
+
text: formatMonth({
|
|
50
|
+
month,
|
|
51
|
+
locale
|
|
52
|
+
}),
|
|
53
|
+
value: month
|
|
54
|
+
},
|
|
55
|
+
placeholder: ""
|
|
56
|
+
}) : /*#__PURE__*/React.createElement(StyledMonthName, null, formatMonth({
|
|
57
|
+
locale,
|
|
58
|
+
month
|
|
59
|
+
})), showMonthYearPickers && hasMultipleYears ? /*#__PURE__*/React.createElement(ComboBox, {
|
|
60
|
+
onSelect: selectedItem => {
|
|
61
|
+
const tempSelectedDate = isDateInRange({
|
|
62
|
+
minDate,
|
|
63
|
+
maxDate,
|
|
64
|
+
currentDate: new Date(selectedItem.value, month - 1 - displayIndex, 1)
|
|
65
|
+
});
|
|
66
|
+
setCurrentDate(tempSelectedDate);
|
|
67
|
+
},
|
|
68
|
+
lists: [{
|
|
69
|
+
list: years
|
|
70
|
+
}],
|
|
71
|
+
selectedItem: {
|
|
72
|
+
text: year.toString(),
|
|
73
|
+
value: year
|
|
74
|
+
},
|
|
75
|
+
placeholder: ""
|
|
76
|
+
}) : /*#__PURE__*/React.createElement(StyledMonthName, null, currentYear !== year ? year : ''));
|
|
77
|
+
};
|
|
78
|
+
export default MonthYearPickers;
|
|
79
|
+
//# sourceMappingURL=MonthYearPickers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MonthYearPickers.js","names":["ComboBox","React","useMemo","useState","formatMonth","getYearsBetween","isDateInRange","StyledMonthName","differenceInCalendarMonths","MonthYearPickerType","MonthYearPickers","_ref","month","year","locale","minDate","maxDate","setCurrentDate","displayIndex","showMonthYearPickers","currentYear","Date","getFullYear","months","map","tempMonth","text","value","hasMultipleMonths","years","tempYear","toString","hasMultipleYears","length","createElement","Fragment","onSelect","selectedItem","tempSelectedDate","currentDate","lists","list","placeholder"],"sources":["../../../../../src/components/calendar/month-year-pickers/MonthYearPickers.tsx"],"sourcesContent":["import { ComboBox } from '@chayns-components/core';\nimport React, { FC, useMemo, useState } from 'react';\nimport { EMonth } from '../../../types/calendar';\nimport { formatMonth, getYearsBetween, isDateInRange } from '../../../utils/calendar';\nimport { StyledMonthName } from '../month-wrapper/month/Month.styles';\nimport {Language} from \"chayns-api\";\nimport {differenceInCalendarMonths} from \"../../../utils/date\";\n\nexport enum MonthYearPickerType {\n Month = 'month',\n Year = 'year',\n}\n\ntype MonthYearPickerProps = {\n month: EMonth;\n year: number;\n locale: Language;\n minDate: Date;\n maxDate: Date;\n setCurrentDate: (date: Date) => void;\n displayIndex?: number;\n showMonthYearPickers: boolean;\n};\n\nconst MonthYearPickers: FC<MonthYearPickerProps> = ({\n month,\n year,\n locale,\n minDate,\n maxDate,\n setCurrentDate,\n displayIndex = 0,\n showMonthYearPickers,\n}) => {\n const [currentYear] = useState(new Date().getFullYear());\n\n const months = useMemo(\n () =>\n [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12].map((tempMonth) => ({\n text: formatMonth({ month: tempMonth, locale }),\n value: tempMonth,\n })),\n [locale],\n );\n\n const hasMultipleMonths = useMemo(\n () => differenceInCalendarMonths(maxDate, minDate) > 0,\n [minDate, maxDate],\n );\n\n const years = useMemo(\n () =>\n getYearsBetween(minDate, maxDate).map((tempYear) => ({\n text: tempYear.toString(),\n value: tempYear,\n })),\n [minDate, maxDate],\n );\n\n const hasMultipleYears = useMemo(() => years.length > 1, [years]);\n\n return (\n <>\n {showMonthYearPickers && hasMultipleMonths ? (\n <ComboBox\n onSelect={(selectedItem) => {\n const tempSelectedDate = isDateInRange({\n minDate,\n maxDate,\n currentDate: new Date(\n year,\n (selectedItem.value as number) - 1 - displayIndex,\n 1,\n ),\n });\n\n setCurrentDate(tempSelectedDate);\n }}\n lists={[\n {\n list: months,\n },\n ]}\n selectedItem={{\n text: formatMonth({ month, locale }),\n value: month,\n }}\n placeholder=\"\"\n />\n ) : (\n <StyledMonthName>{formatMonth({ locale, month })}</StyledMonthName>\n )}\n {showMonthYearPickers && hasMultipleYears ? (\n <ComboBox\n onSelect={(selectedItem) => {\n const tempSelectedDate = isDateInRange({\n minDate,\n maxDate,\n currentDate: new Date(\n selectedItem.value as number,\n month - 1 - displayIndex,\n 1,\n ),\n });\n\n setCurrentDate(tempSelectedDate);\n }}\n lists={[\n {\n list: years,\n },\n ]}\n selectedItem={{\n text: year.toString(),\n value: year,\n }}\n placeholder=\"\"\n />\n ) : (\n <StyledMonthName>{currentYear !== year ? year : ''}</StyledMonthName>\n )}\n </>\n );\n};\n\nexport default MonthYearPickers;\n"],"mappings":"AAAA,SAASA,QAAQ,QAAQ,yBAAyB;AAClD,OAAOC,KAAK,IAAQC,OAAO,EAAEC,QAAQ,QAAQ,OAAO;AAEpD,SAASC,WAAW,EAAEC,eAAe,EAAEC,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,CAAC;IACpC,CAAE;IACFE,KAAK,EAAE,CACH;MACIC,IAAI,EAAEZ;IACV,CAAC,CACH;IACFQ,YAAY,EAAE;MACVX,IAAI,EAAEb,IAAI,CAACkB,QAAQ,CAAC,CAAC;MACrBJ,KAAK,EAAEd;IACX,CAAE;IACF6B,WAAW,EAAC;EAAE,CACjB,CAAC,gBAEFzC,KAAA,CAAAiC,aAAA,CAAC3B,eAAe,QAAEa,WAAW,KAAKP,IAAI,GAAGA,IAAI,GAAG,EAAoB,CAE1E,CAAC;AAEX,CAAC;AAED,eAAeH,gBAAgB","ignoreList":[]}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import React, { useMemo } from 'react';
|
|
2
|
+
import { useDateInfo } from '../../hooks/useDateInfo';
|
|
3
|
+
const DateInfo = _ref => {
|
|
4
|
+
let {
|
|
5
|
+
date,
|
|
6
|
+
preText = '',
|
|
7
|
+
shouldShowYear,
|
|
8
|
+
shouldShowTime,
|
|
9
|
+
shouldShowRelativeDayOfWeek,
|
|
10
|
+
shouldUseShortText,
|
|
11
|
+
shouldShowDayOfWeek,
|
|
12
|
+
shouldShowDateToNowDifference
|
|
13
|
+
} = _ref;
|
|
14
|
+
const formattedDate = useDateInfo({
|
|
15
|
+
date,
|
|
16
|
+
preText,
|
|
17
|
+
shouldShowYear,
|
|
18
|
+
shouldShowTime,
|
|
19
|
+
shouldUseShortText,
|
|
20
|
+
shouldShowDayOfWeek,
|
|
21
|
+
shouldShowRelativeDayOfWeek,
|
|
22
|
+
shouldShowDateToNowDifference
|
|
23
|
+
});
|
|
24
|
+
return useMemo(() => /*#__PURE__*/React.createElement("span", null, formattedDate), [formattedDate]);
|
|
25
|
+
};
|
|
26
|
+
DateInfo.displayName = 'DateInfo';
|
|
27
|
+
export default DateInfo;
|
|
28
|
+
//# sourceMappingURL=DateInfo.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"DateInfo.js","names":["React","useMemo","useDateInfo","DateInfo","_ref","date","preText","shouldShowYear","shouldShowTime","shouldShowRelativeDayOfWeek","shouldUseShortText","shouldShowDayOfWeek","shouldShowDateToNowDifference","formattedDate","createElement","displayName"],"sources":["../../../../src/components/date-info/DateInfo.tsx"],"sourcesContent":["import React, { FC, useMemo } from 'react';\nimport { useDateInfo } from '../../hooks/useDateInfo';\nimport { UseDateInfoOptions } from '../../types/dateinfo';\n\nexport type DateInfoProps = UseDateInfoOptions;\n\nconst DateInfo: FC<DateInfoProps> = ({\n date,\n preText = '',\n shouldShowYear,\n shouldShowTime,\n shouldShowRelativeDayOfWeek,\n shouldUseShortText,\n shouldShowDayOfWeek,\n shouldShowDateToNowDifference,\n}) => {\n const formattedDate = useDateInfo({\n date,\n preText,\n shouldShowYear,\n shouldShowTime,\n shouldUseShortText,\n shouldShowDayOfWeek,\n shouldShowRelativeDayOfWeek,\n shouldShowDateToNowDifference,\n });\n\n return useMemo(() => <span>{formattedDate}</span>, [formattedDate]);\n};\n\nDateInfo.displayName = 'DateInfo';\n\nexport default DateInfo;\n"],"mappings":"AAAA,OAAOA,KAAK,IAAQC,OAAO,QAAQ,OAAO;AAC1C,SAASC,WAAW,QAAQ,yBAAyB;AAKrD,MAAMC,QAA2B,GAAGC,IAAA,IAS9B;EAAA,IAT+B;IACjCC,IAAI;IACJC,OAAO,GAAG,EAAE;IACZC,cAAc;IACdC,cAAc;IACdC,2BAA2B;IAC3BC,kBAAkB;IAClBC,mBAAmB;IACnBC;EACJ,CAAC,GAAAR,IAAA;EACG,MAAMS,aAAa,GAAGX,WAAW,CAAC;IAC9BG,IAAI;IACJC,OAAO;IACPC,cAAc;IACdC,cAAc;IACdE,kBAAkB;IAClBC,mBAAmB;IACnBF,2BAA2B;IAC3BG;EACJ,CAAC,CAAC;EAEF,OAAOX,OAAO,CAAC,mBAAMD,KAAA,CAAAc,aAAA,eAAOD,aAAoB,CAAC,EAAE,CAACA,aAAa,CAAC,CAAC;AACvE,CAAC;AAEDV,QAAQ,CAACY,WAAW,GAAG,UAAU;AAEjC,eAAeZ,QAAQ","ignoreList":[]}
|
|
@@ -0,0 +1,240 @@
|
|
|
1
|
+
import { Checkbox, Popup, useElementSize } from '@chayns-components/core';
|
|
2
|
+
import React, { useCallback, useEffect, useMemo, useRef, useState } from 'react';
|
|
3
|
+
import { HintTextPosition } from '../../types/openingTimes';
|
|
4
|
+
import HintText from './hint-text/HintText';
|
|
5
|
+
import OpeningInputs from './opening-inputs/OpeningInputs';
|
|
6
|
+
import { StyledOpeningTimes, StyledOpeningTimesTooltipContent, StyledOpeningTimesWeekDay, StyledOpeningTimesWrapper } from './OpeningTimes.styles';
|
|
7
|
+
const OpeningTimes = _ref => {
|
|
8
|
+
let {
|
|
9
|
+
closedText = 'closed',
|
|
10
|
+
currentDayId,
|
|
11
|
+
editMode = false,
|
|
12
|
+
hintText,
|
|
13
|
+
hintTextPosition = HintTextPosition.Bottom,
|
|
14
|
+
openingTimes,
|
|
15
|
+
weekdays,
|
|
16
|
+
onChange,
|
|
17
|
+
onTimeAdd,
|
|
18
|
+
onTimeRemove,
|
|
19
|
+
shouldNotValidate = false
|
|
20
|
+
} = _ref;
|
|
21
|
+
const [newOpeningTimes, setNewOpeningTimes] = useState();
|
|
22
|
+
const [invalidOpeningTimes, setInvalidOpeningTimes] = useState([]);
|
|
23
|
+
const [isPopupOpen, setIsPopupOpen] = useState(false);
|
|
24
|
+
const ref = useRef(null);
|
|
25
|
+
const popupRef = useRef(null);
|
|
26
|
+
useEffect(() => {
|
|
27
|
+
setNewOpeningTimes(openingTimes);
|
|
28
|
+
}, [openingTimes]);
|
|
29
|
+
const validateTime = useCallback((newTime, dayId) => {
|
|
30
|
+
if (newTime.start === newTime.end) {
|
|
31
|
+
return false;
|
|
32
|
+
}
|
|
33
|
+
const dayTimes = newOpeningTimes?.find(day => day.id === dayId)?.times || [];
|
|
34
|
+
return dayTimes.every(time => time.id === newTime.id || newTime.end <= time.start || newTime.start >= time.end);
|
|
35
|
+
}, [newOpeningTimes]);
|
|
36
|
+
const handleCheckBoxChange = useCallback(id => {
|
|
37
|
+
setNewOpeningTimes(prevOpeningTimes => {
|
|
38
|
+
const updatedOpeningTimes = (prevOpeningTimes ?? []).map(openingTime => {
|
|
39
|
+
if (openingTime.id === id) {
|
|
40
|
+
return {
|
|
41
|
+
...openingTime,
|
|
42
|
+
isDisabled: !openingTime.isDisabled
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
return openingTime;
|
|
46
|
+
});
|
|
47
|
+
if (typeof onChange === 'function') {
|
|
48
|
+
onChange({
|
|
49
|
+
enabledDays: updatedOpeningTimes.filter(item => !item.isDisabled).map(item => item.id)
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
return updatedOpeningTimes;
|
|
53
|
+
});
|
|
54
|
+
}, [onChange]);
|
|
55
|
+
const handleChange = useCallback((newTime, id) => {
|
|
56
|
+
const isValid = shouldNotValidate || validateTime(newTime, id);
|
|
57
|
+
if (!isValid) {
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
setNewOpeningTimes(prevOpeningTimes => {
|
|
61
|
+
const updatedOpeningTimes = (prevOpeningTimes ?? []).map(openingTime => {
|
|
62
|
+
if (openingTime.id === id) {
|
|
63
|
+
const newTimes = openingTime.times.map(time => {
|
|
64
|
+
if (time.id === newTime.id) {
|
|
65
|
+
return newTime;
|
|
66
|
+
}
|
|
67
|
+
return time;
|
|
68
|
+
});
|
|
69
|
+
return {
|
|
70
|
+
...openingTime,
|
|
71
|
+
times: newTimes
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
return openingTime;
|
|
75
|
+
});
|
|
76
|
+
const changedOpeningTime = updatedOpeningTimes.find(updatedOpeningTime => updatedOpeningTime.id === id);
|
|
77
|
+
if (isValid && typeof onChange === 'function') {
|
|
78
|
+
onChange({
|
|
79
|
+
dayId: changedOpeningTime?.id,
|
|
80
|
+
time: newTime
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
return updatedOpeningTimes;
|
|
84
|
+
});
|
|
85
|
+
}, [onChange, shouldNotValidate, validateTime]);
|
|
86
|
+
const handleAdd = useCallback((time, id) => {
|
|
87
|
+
const isValid = shouldNotValidate || validateTime(time, id);
|
|
88
|
+
if (isValid && typeof onTimeAdd === 'function') {
|
|
89
|
+
onTimeAdd({
|
|
90
|
+
time,
|
|
91
|
+
dayId: id
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
setNewOpeningTimes(prevOpeningTimes => (prevOpeningTimes ?? []).map(openingTime => {
|
|
95
|
+
if (openingTime.id === id) {
|
|
96
|
+
return {
|
|
97
|
+
...openingTime,
|
|
98
|
+
times: [...openingTime.times, time]
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
return openingTime;
|
|
102
|
+
}));
|
|
103
|
+
}, [onTimeAdd, shouldNotValidate, validateTime]);
|
|
104
|
+
const handleUpdateInvalidIds = useCallback((openingTimeId, invalidTimeIds) => {
|
|
105
|
+
setInvalidOpeningTimes(prevState => {
|
|
106
|
+
const updatedInvalidOpeningTimes = prevState.map(invalidOpeningTime => {
|
|
107
|
+
if (invalidOpeningTime.openingTimeId === openingTimeId) {
|
|
108
|
+
return {
|
|
109
|
+
openingTimeId,
|
|
110
|
+
invalidTimeIds
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
return invalidOpeningTime;
|
|
114
|
+
});
|
|
115
|
+
if (!updatedInvalidOpeningTimes.some(_ref2 => {
|
|
116
|
+
let {
|
|
117
|
+
openingTimeId: updatedInvalidOpeningId
|
|
118
|
+
} = _ref2;
|
|
119
|
+
return updatedInvalidOpeningId === openingTimeId;
|
|
120
|
+
}) && invalidTimeIds.length > 0) {
|
|
121
|
+
updatedInvalidOpeningTimes.push({
|
|
122
|
+
openingTimeId,
|
|
123
|
+
invalidTimeIds
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
return updatedInvalidOpeningTimes.filter(updatedInvalidOpeningTime => updatedInvalidOpeningTime.invalidTimeIds.length !== 0);
|
|
127
|
+
});
|
|
128
|
+
}, []);
|
|
129
|
+
const handleRemove = useCallback(id => {
|
|
130
|
+
setNewOpeningTimes(prevOpeningTimes => (prevOpeningTimes ?? []).map(openingTime => {
|
|
131
|
+
const newTimes = openingTime.times.filter(time => time.id !== id);
|
|
132
|
+
return {
|
|
133
|
+
...openingTime,
|
|
134
|
+
times: newTimes
|
|
135
|
+
};
|
|
136
|
+
}));
|
|
137
|
+
if (typeof onTimeRemove === 'function') {
|
|
138
|
+
onTimeRemove(id);
|
|
139
|
+
}
|
|
140
|
+
}, [onTimeRemove]);
|
|
141
|
+
const content = useMemo(() => {
|
|
142
|
+
const items = [];
|
|
143
|
+
if (!newOpeningTimes) {
|
|
144
|
+
return items;
|
|
145
|
+
}
|
|
146
|
+
newOpeningTimes.forEach(_ref3 => {
|
|
147
|
+
let {
|
|
148
|
+
times,
|
|
149
|
+
id,
|
|
150
|
+
weekdayId,
|
|
151
|
+
isDisabled
|
|
152
|
+
} = _ref3;
|
|
153
|
+
const weekday = weekdays.find(weekDay => weekDay.id === weekdayId)?.name;
|
|
154
|
+
if (!weekday) {
|
|
155
|
+
return;
|
|
156
|
+
}
|
|
157
|
+
items.push(/*#__PURE__*/React.createElement(StyledOpeningTimesWrapper, {
|
|
158
|
+
key: `openingTimes__${id}`
|
|
159
|
+
}, editMode ? /*#__PURE__*/React.createElement(Checkbox, {
|
|
160
|
+
isChecked: !isDisabled,
|
|
161
|
+
onChange: () => handleCheckBoxChange(id)
|
|
162
|
+
}, weekday) : /*#__PURE__*/React.createElement(StyledOpeningTimesWeekDay, null, weekday), /*#__PURE__*/React.createElement(OpeningInputs, {
|
|
163
|
+
closedText: closedText,
|
|
164
|
+
currentDayId: currentDayId,
|
|
165
|
+
id: id,
|
|
166
|
+
times: times,
|
|
167
|
+
isDisabled: isDisabled,
|
|
168
|
+
onInvalid: handleUpdateInvalidIds,
|
|
169
|
+
onChange: newTime => handleChange(newTime, id),
|
|
170
|
+
onRemove: handleRemove,
|
|
171
|
+
onAdd: handleAdd,
|
|
172
|
+
editMode: editMode
|
|
173
|
+
})));
|
|
174
|
+
});
|
|
175
|
+
return items;
|
|
176
|
+
}, [closedText, currentDayId, editMode, handleAdd, handleChange, handleCheckBoxChange, handleRemove, handleUpdateInvalidIds, newOpeningTimes, weekdays]);
|
|
177
|
+
const size = useElementSize(ref);
|
|
178
|
+
const hidePopup = useCallback(() => {
|
|
179
|
+
setIsPopupOpen(false);
|
|
180
|
+
popupRef.current?.hide();
|
|
181
|
+
}, []);
|
|
182
|
+
const showPopup = useCallback(() => {
|
|
183
|
+
setIsPopupOpen(true);
|
|
184
|
+
popupRef.current?.show();
|
|
185
|
+
}, []);
|
|
186
|
+
const displayedContent = useMemo(() => {
|
|
187
|
+
if (!currentDayId || editMode) {
|
|
188
|
+
return content;
|
|
189
|
+
}
|
|
190
|
+
const singleDay = newOpeningTimes?.find(_ref4 => {
|
|
191
|
+
let {
|
|
192
|
+
id
|
|
193
|
+
} = _ref4;
|
|
194
|
+
return id === currentDayId;
|
|
195
|
+
});
|
|
196
|
+
if (!singleDay) {
|
|
197
|
+
return content;
|
|
198
|
+
}
|
|
199
|
+
const {
|
|
200
|
+
id,
|
|
201
|
+
times,
|
|
202
|
+
weekdayId
|
|
203
|
+
} = singleDay;
|
|
204
|
+
const weekday = weekdays.find(weekDay => weekDay.id === weekdayId)?.name;
|
|
205
|
+
return /*#__PURE__*/React.createElement(StyledOpeningTimesWrapper, {
|
|
206
|
+
key: `currentDay__${currentDayId}`,
|
|
207
|
+
style: size && {
|
|
208
|
+
width: size.width
|
|
209
|
+
},
|
|
210
|
+
onMouseEnter: showPopup,
|
|
211
|
+
onMouseLeave: hidePopup,
|
|
212
|
+
onClick: () => isPopupOpen ? hidePopup() : showPopup()
|
|
213
|
+
}, /*#__PURE__*/React.createElement(Popup, {
|
|
214
|
+
onShow: () => setIsPopupOpen(true),
|
|
215
|
+
onHide: () => setIsPopupOpen(false),
|
|
216
|
+
ref: popupRef,
|
|
217
|
+
content: /*#__PURE__*/React.createElement(StyledOpeningTimesTooltipContent, {
|
|
218
|
+
key: "opening-time-tooltip"
|
|
219
|
+
}, content)
|
|
220
|
+
}, /*#__PURE__*/React.createElement(StyledOpeningTimesWeekDay, null, weekday)), /*#__PURE__*/React.createElement(OpeningInputs, {
|
|
221
|
+
closedText: closedText,
|
|
222
|
+
currentDayId: currentDayId,
|
|
223
|
+
onInvalid: handleUpdateInvalidIds,
|
|
224
|
+
id: id,
|
|
225
|
+
times: times,
|
|
226
|
+
editMode: editMode
|
|
227
|
+
}));
|
|
228
|
+
}, [currentDayId, editMode, newOpeningTimes, weekdays, size, showPopup, hidePopup, content, closedText, handleUpdateInvalidIds, isPopupOpen]);
|
|
229
|
+
const shouldShowHint = useMemo(() => invalidOpeningTimes.length > 0, [invalidOpeningTimes.length]);
|
|
230
|
+
return useMemo(() => /*#__PURE__*/React.createElement(StyledOpeningTimes, {
|
|
231
|
+
ref: ref
|
|
232
|
+
}, shouldShowHint && hintText && hintTextPosition === HintTextPosition.Top && /*#__PURE__*/React.createElement(HintText, {
|
|
233
|
+
text: hintText
|
|
234
|
+
}), displayedContent, shouldShowHint && hintText && hintTextPosition === HintTextPosition.Bottom && /*#__PURE__*/React.createElement(HintText, {
|
|
235
|
+
text: hintText
|
|
236
|
+
})), [displayedContent, hintText, hintTextPosition, shouldShowHint]);
|
|
237
|
+
};
|
|
238
|
+
OpeningTimes.displayName = 'OpeningTimes';
|
|
239
|
+
export default OpeningTimes;
|
|
240
|
+
//# sourceMappingURL=OpeningTimes.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"OpeningTimes.js","names":["Checkbox","Popup","useElementSize","React","useCallback","useEffect","useMemo","useRef","useState","HintTextPosition","HintText","OpeningInputs","StyledOpeningTimes","StyledOpeningTimesTooltipContent","StyledOpeningTimesWeekDay","StyledOpeningTimesWrapper","OpeningTimes","_ref","closedText","currentDayId","editMode","hintText","hintTextPosition","Bottom","openingTimes","weekdays","onChange","onTimeAdd","onTimeRemove","shouldNotValidate","newOpeningTimes","setNewOpeningTimes","invalidOpeningTimes","setInvalidOpeningTimes","isPopupOpen","setIsPopupOpen","ref","popupRef","validateTime","newTime","dayId","start","end","dayTimes","find","day","id","times","every","time","handleCheckBoxChange","prevOpeningTimes","updatedOpeningTimes","map","openingTime","isDisabled","enabledDays","filter","item","handleChange","isValid","newTimes","changedOpeningTime","updatedOpeningTime","handleAdd","handleUpdateInvalidIds","openingTimeId","invalidTimeIds","prevState","updatedInvalidOpeningTimes","invalidOpeningTime","some","_ref2","updatedInvalidOpeningId","length","push","updatedInvalidOpeningTime","handleRemove","content","items","forEach","_ref3","weekdayId","weekday","weekDay","name","createElement","key","isChecked","onInvalid","onRemove","onAdd","size","hidePopup","current","hide","showPopup","show","displayedContent","singleDay","_ref4","style","width","onMouseEnter","onMouseLeave","onClick","onShow","onHide","shouldShowHint","Top","text","displayName"],"sources":["../../../../src/components/opening-times/OpeningTimes.tsx"],"sourcesContent":["import { Checkbox, Popup, useElementSize, type PopupRef } from '@chayns-components/core';\nimport React, {\n FC,\n useCallback,\n useEffect,\n useMemo,\n useRef,\n useState,\n type ReactElement,\n} from 'react';\nimport {\n HintTextPosition,\n type OnChange,\n type OnTimeAdd,\n type OpeningTime,\n type Time,\n type Weekday,\n} from '../../types/openingTimes';\nimport HintText from './hint-text/HintText';\nimport OpeningInputs from './opening-inputs/OpeningInputs';\nimport {\n StyledOpeningTimes,\n StyledOpeningTimesTooltipContent,\n StyledOpeningTimesWeekDay,\n StyledOpeningTimesWrapper,\n} from './OpeningTimes.styles';\n\nexport type OpeningTimesProps = {\n /**\n * The text that should be displayed when a day is closed.\n */\n closedText?: string;\n /**\n * If set just the current day is displayed and the whole week in a tooltip.\n */\n currentDayId?: OpeningTime['id'];\n /**\n * Whether the opening times can be edited.\n */\n editMode?: boolean;\n /**\n * The text that should be displayed if times are colliding.\n */\n hintText?: string;\n /**\n * The position of the hint text.\n */\n hintTextPosition?: HintTextPosition;\n /**\n * Function to be executed when a time is changed or a day is enabled/disabled.\n * @param openingTimes\n */\n onChange?: ({ time, enabledDays, dayId }: OnChange) => void;\n /**\n * Function to be executed when a time is added.\n */\n onTimeAdd?: ({ time, dayId }: OnTimeAdd) => void;\n /**\n * Function to be executed when a time is removed.\n */\n onTimeRemove?: (id: string) => void;\n /**\n * The opening times corresponding to its weekday.\n */\n openingTimes: OpeningTime[];\n /**\n * The weekdays that should be displayed.\n */\n weekdays: Weekday[];\n /**\n * When set to true, events are triggered without validation.\n */\n shouldNotValidate?: boolean;\n};\n\nconst OpeningTimes: FC<OpeningTimesProps> = ({\n closedText = 'closed',\n currentDayId,\n editMode = false,\n hintText,\n hintTextPosition = HintTextPosition.Bottom,\n openingTimes,\n weekdays,\n onChange,\n onTimeAdd,\n onTimeRemove,\n shouldNotValidate = false,\n}) => {\n const [newOpeningTimes, setNewOpeningTimes] = useState<OpeningTime[]>();\n const [invalidOpeningTimes, setInvalidOpeningTimes] = useState<\n { openingTimeId: string; invalidTimeIds: string[] }[]\n >([]);\n const [isPopupOpen, setIsPopupOpen] = useState(false);\n\n const ref = useRef<HTMLDivElement>(null);\n const popupRef = useRef<PopupRef>(null);\n\n useEffect(() => {\n setNewOpeningTimes(openingTimes);\n }, [openingTimes]);\n\n const validateTime = useCallback(\n (newTime: Time, dayId: string): boolean => {\n if (newTime.start === newTime.end) {\n return false;\n }\n const dayTimes = newOpeningTimes?.find((day) => day.id === dayId)?.times || [];\n\n return dayTimes.every(\n (time) =>\n time.id === newTime.id ||\n newTime.end <= time.start ||\n newTime.start >= time.end,\n );\n },\n [newOpeningTimes],\n );\n\n const handleCheckBoxChange = useCallback(\n (id: string) => {\n setNewOpeningTimes((prevOpeningTimes) => {\n const updatedOpeningTimes = (prevOpeningTimes ?? []).map((openingTime) => {\n if (openingTime.id === id) {\n return { ...openingTime, isDisabled: !openingTime.isDisabled };\n }\n return openingTime;\n });\n\n if (typeof onChange === 'function') {\n onChange({\n enabledDays: updatedOpeningTimes\n .filter((item) => !item.isDisabled)\n .map((item) => item.id),\n });\n }\n\n return updatedOpeningTimes;\n });\n },\n [onChange],\n );\n\n const handleChange = useCallback(\n (newTime: Time, id: string) => {\n const isValid = shouldNotValidate || validateTime(newTime, id);\n if (!isValid) {\n return;\n }\n\n setNewOpeningTimes((prevOpeningTimes) => {\n const updatedOpeningTimes = (prevOpeningTimes ?? []).map((openingTime) => {\n if (openingTime.id === id) {\n const newTimes = openingTime.times.map((time) => {\n if (time.id === newTime.id) {\n return newTime;\n }\n return time;\n });\n return { ...openingTime, times: newTimes };\n }\n return openingTime;\n });\n\n const changedOpeningTime = updatedOpeningTimes.find(\n (updatedOpeningTime) => updatedOpeningTime.id === id,\n );\n\n if (isValid && typeof onChange === 'function') {\n onChange({\n dayId: changedOpeningTime?.id,\n time: newTime,\n });\n }\n\n return updatedOpeningTimes;\n });\n },\n [onChange, shouldNotValidate, validateTime],\n );\n\n const handleAdd = useCallback(\n (time: Time, id: string) => {\n const isValid = shouldNotValidate || validateTime(time, id);\n\n if (isValid && typeof onTimeAdd === 'function') {\n onTimeAdd({ time, dayId: id });\n }\n\n setNewOpeningTimes((prevOpeningTimes) =>\n (prevOpeningTimes ?? []).map((openingTime) => {\n if (openingTime.id === id) {\n return { ...openingTime, times: [...openingTime.times, time] };\n }\n return openingTime;\n }),\n );\n },\n [onTimeAdd, shouldNotValidate, validateTime],\n );\n\n const handleUpdateInvalidIds = useCallback(\n (openingTimeId: string, invalidTimeIds: string[]) => {\n setInvalidOpeningTimes((prevState) => {\n const updatedInvalidOpeningTimes = prevState.map((invalidOpeningTime) => {\n if (invalidOpeningTime.openingTimeId === openingTimeId) {\n return {\n openingTimeId,\n invalidTimeIds,\n };\n }\n return invalidOpeningTime;\n });\n\n if (\n !updatedInvalidOpeningTimes.some(\n ({ openingTimeId: updatedInvalidOpeningId }) =>\n updatedInvalidOpeningId === openingTimeId,\n ) &&\n invalidTimeIds.length > 0\n ) {\n updatedInvalidOpeningTimes.push({ openingTimeId, invalidTimeIds });\n }\n\n return updatedInvalidOpeningTimes.filter(\n (updatedInvalidOpeningTime) =>\n updatedInvalidOpeningTime.invalidTimeIds.length !== 0,\n );\n });\n },\n [],\n );\n\n const handleRemove = useCallback(\n (id: string) => {\n setNewOpeningTimes((prevOpeningTimes) =>\n (prevOpeningTimes ?? []).map((openingTime) => {\n const newTimes = openingTime.times.filter((time) => time.id !== id);\n\n return { ...openingTime, times: newTimes };\n }),\n );\n\n if (typeof onTimeRemove === 'function') {\n onTimeRemove(id);\n }\n },\n [onTimeRemove],\n );\n\n const content = useMemo(() => {\n const items: ReactElement[] = [];\n\n if (!newOpeningTimes) {\n return items;\n }\n\n newOpeningTimes.forEach(({ times, id, weekdayId, isDisabled }) => {\n const weekday = weekdays.find((weekDay) => weekDay.id === weekdayId)?.name;\n\n if (!weekday) {\n return;\n }\n\n items.push(\n <StyledOpeningTimesWrapper key={`openingTimes__${id}`}>\n {editMode ? (\n <Checkbox isChecked={!isDisabled} onChange={() => handleCheckBoxChange(id)}>\n {weekday}\n </Checkbox>\n ) : (\n <StyledOpeningTimesWeekDay>{weekday}</StyledOpeningTimesWeekDay>\n )}\n <OpeningInputs\n closedText={closedText}\n currentDayId={currentDayId}\n id={id}\n times={times}\n isDisabled={isDisabled}\n onInvalid={handleUpdateInvalidIds}\n onChange={(newTime) => handleChange(newTime, id)}\n onRemove={handleRemove}\n onAdd={handleAdd}\n editMode={editMode}\n />\n </StyledOpeningTimesWrapper>,\n );\n });\n\n return items;\n }, [\n closedText,\n currentDayId,\n editMode,\n handleAdd,\n handleChange,\n handleCheckBoxChange,\n handleRemove,\n handleUpdateInvalidIds,\n newOpeningTimes,\n weekdays,\n ]);\n\n const size = useElementSize(ref);\n\n const hidePopup = useCallback(() => {\n setIsPopupOpen(false);\n popupRef.current?.hide();\n }, []);\n\n const showPopup = useCallback(() => {\n setIsPopupOpen(true);\n popupRef.current?.show();\n }, []);\n\n const displayedContent = useMemo(() => {\n if (!currentDayId || editMode) {\n return content;\n }\n\n const singleDay = newOpeningTimes?.find(({ id }) => id === currentDayId);\n\n if (!singleDay) {\n return content;\n }\n\n const { id, times, weekdayId } = singleDay;\n\n const weekday = weekdays.find((weekDay) => weekDay.id === weekdayId)?.name;\n\n return (\n <StyledOpeningTimesWrapper\n key={`currentDay__${currentDayId}`}\n style={size && { width: size.width }}\n onMouseEnter={showPopup}\n onMouseLeave={hidePopup}\n onClick={() => (isPopupOpen ? hidePopup() : showPopup())}\n >\n <Popup\n onShow={() => setIsPopupOpen(true)}\n onHide={() => setIsPopupOpen(false)}\n ref={popupRef}\n content={\n <StyledOpeningTimesTooltipContent key=\"opening-time-tooltip\">\n {content}\n </StyledOpeningTimesTooltipContent>\n }\n >\n <StyledOpeningTimesWeekDay>{weekday}</StyledOpeningTimesWeekDay>\n </Popup>\n <OpeningInputs\n closedText={closedText}\n currentDayId={currentDayId}\n onInvalid={handleUpdateInvalidIds}\n id={id}\n times={times}\n editMode={editMode}\n />\n </StyledOpeningTimesWrapper>\n );\n }, [\n currentDayId,\n editMode,\n newOpeningTimes,\n weekdays,\n size,\n showPopup,\n hidePopup,\n content,\n closedText,\n handleUpdateInvalidIds,\n isPopupOpen,\n ]);\n\n const shouldShowHint = useMemo(\n () => invalidOpeningTimes.length > 0,\n [invalidOpeningTimes.length],\n );\n\n return useMemo(\n () => (\n <StyledOpeningTimes ref={ref}>\n {shouldShowHint && hintText && hintTextPosition === HintTextPosition.Top && (\n <HintText text={hintText} />\n )}\n {displayedContent}\n {shouldShowHint && hintText && hintTextPosition === HintTextPosition.Bottom && (\n <HintText text={hintText} />\n )}\n </StyledOpeningTimes>\n ),\n [displayedContent, hintText, hintTextPosition, shouldShowHint],\n );\n};\n\nOpeningTimes.displayName = 'OpeningTimes';\n\nexport default OpeningTimes;\n"],"mappings":"AAAA,SAASA,QAAQ,EAAEC,KAAK,EAAEC,cAAc,QAAuB,yBAAyB;AACxF,OAAOC,KAAK,IAERC,WAAW,EACXC,SAAS,EAC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M,GAAG,CAAC,EACpC,CAAC1C,mBAAmB,CAAC0C,MAAM,CAC/B,CAAC;EAED,OAAOpE,OAAO,CACV,mBACIH,KAAA,CAAAmF,aAAA,CAAC1E,kBAAkB;IAACwB,GAAG,EAAEA;EAAI,GACxBwE,cAAc,IAAIvF,QAAQ,IAAIC,gBAAgB,KAAKb,gBAAgB,CAACoG,GAAG,iBACpE1G,KAAA,CAAAmF,aAAA,CAAC5E,QAAQ;IAACoG,IAAI,EAAEzF;EAAS,CAAE,CAC9B,EACA6E,gBAAgB,EAChBU,cAAc,IAAIvF,QAAQ,IAAIC,gBAAgB,KAAKb,gBAAgB,CAACc,MAAM,iBACvEpB,KAAA,CAAAmF,aAAA,CAAC5E,QAAQ;IAACoG,IAAI,EAAEzF;EAAS,CAAE,CAEf,CACvB,EACD,CAAC6E,gBAAgB,EAAE7E,QAAQ,EAAEC,gBAAgB,EAAEsF,cAAc,CACjE,CAAC;AACL,CAAC;AAED5F,YAAY,CAAC+F,WAAW,GAAG,cAAc;AAEzC,eAAe/F,YAAY","ignoreList":[]}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import styled from 'styled-components';
|
|
2
|
+
export const StyledOpeningTimes = styled.div`
|
|
3
|
+
display: flex;
|
|
4
|
+
flex-direction: column;
|
|
5
|
+
gap: 8px;
|
|
6
|
+
`;
|
|
7
|
+
export const StyledOpeningTimesWrapper = styled.div`
|
|
8
|
+
display: flex;
|
|
9
|
+
align-items: baseline;
|
|
10
|
+
justify-content: space-between;
|
|
11
|
+
min-width: 300px;
|
|
12
|
+
`;
|
|
13
|
+
export const StyledOpeningTimesTooltipContent = styled.div`
|
|
14
|
+
padding: 8px;
|
|
15
|
+
`;
|
|
16
|
+
export const StyledOpeningTimesWeekDay = styled.div`
|
|
17
|
+
color: ${_ref => {
|
|
18
|
+
let {
|
|
19
|
+
theme
|
|
20
|
+
} = _ref;
|
|
21
|
+
return theme.text;
|
|
22
|
+
}};
|
|
23
|
+
`;
|
|
24
|
+
//# sourceMappingURL=OpeningTimes.styles.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"OpeningTimes.styles.js","names":["styled","StyledOpeningTimes","div","StyledOpeningTimesWrapper","StyledOpeningTimesTooltipContent","StyledOpeningTimesWeekDay","_ref","theme","text"],"sources":["../../../../src/components/opening-times/OpeningTimes.styles.ts"],"sourcesContent":["import type { WithTheme } from '@chayns-components/core';\nimport styled from 'styled-components';\n\ntype StyledSliderButtonProps = WithTheme<{ $isDisabled?: boolean }>;\n\nexport const StyledOpeningTimes = styled.div<StyledSliderButtonProps>`\n display: flex;\n flex-direction: column;\n gap: 8px;\n`;\n\nexport const StyledOpeningTimesWrapper = styled.div`\n display: flex;\n align-items: baseline;\n justify-content: space-between;\n min-width: 300px;\n`;\n\nexport const StyledOpeningTimesTooltipContent = styled.div`\n padding: 8px;\n`;\n\ntype StyledOpeningTimesWeekDayProps = WithTheme<unknown>;\n\nexport const StyledOpeningTimesWeekDay = styled.div<StyledOpeningTimesWeekDayProps>`\n color: ${({ theme }: StyledOpeningTimesWeekDayProps) => theme.text};\n`;\n"],"mappings":"AACA,OAAOA,MAAM,MAAM,mBAAmB;AAItC,OAAO,MAAMC,kBAAkB,GAAGD,MAAM,CAACE,GAA4B;AACrE;AACA;AACA;AACA,CAAC;AAED,OAAO,MAAMC,yBAAyB,GAAGH,MAAM,CAACE,GAAG;AACnD;AACA;AACA;AACA;AACA,CAAC;AAED,OAAO,MAAME,gCAAgC,GAAGJ,MAAM,CAACE,GAAG;AAC1D;AACA,CAAC;AAID,OAAO,MAAMG,yBAAyB,GAAGL,MAAM,CAACE,GAAmC;AACnF,aAAaI,IAAA;EAAA,IAAC;IAAEC;EAAsC,CAAC,GAAAD,IAAA;EAAA,OAAKC,KAAK,CAACC,IAAI;AAAA;AACtE,CAAC","ignoreList":[]}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import React, { useMemo, useState } from 'react';
|
|
2
|
+
import { StyledHintText } from './HintText.styles';
|
|
3
|
+
const HintText = _ref => {
|
|
4
|
+
let {
|
|
5
|
+
text
|
|
6
|
+
} = _ref;
|
|
7
|
+
const [newHintText, setNewHintText] = useState();
|
|
8
|
+
return useMemo(() => /*#__PURE__*/React.createElement(StyledHintText, null, text), [text]);
|
|
9
|
+
};
|
|
10
|
+
HintText.displayName = 'HintText';
|
|
11
|
+
export default HintText;
|
|
12
|
+
//# sourceMappingURL=HintText.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"HintText.js","names":["React","useMemo","useState","StyledHintText","HintText","_ref","text","newHintText","setNewHintText","createElement","displayName"],"sources":["../../../../../src/components/opening-times/hint-text/HintText.tsx"],"sourcesContent":["import React, { FC, useMemo, useState } from 'react';\nimport { StyledHintText } from './HintText.styles';\n\nexport type HintTextProps = {\n text: string;\n};\n\nconst HintText: FC<HintTextProps> = ({ text }) => {\n const [newHintText, setNewHintText] = useState<string>();\n\n return useMemo(() => <StyledHintText>{text}</StyledHintText>, [text]);\n};\n\nHintText.displayName = 'HintText';\n\nexport default HintText;\n"],"mappings":"AAAA,OAAOA,KAAK,IAAQC,OAAO,EAAEC,QAAQ,QAAQ,OAAO;AACpD,SAASC,cAAc,QAAQ,mBAAmB;AAMlD,MAAMC,QAA2B,GAAGC,IAAA,IAAc;EAAA,IAAb;IAAEC;EAAK,CAAC,GAAAD,IAAA;EACzC,MAAM,CAACE,WAAW,EAAEC,cAAc,CAAC,GAAGN,QAAQ,CAAS,CAAC;EAExD,OAAOD,OAAO,CAAC,mBAAMD,KAAA,CAAAS,aAAA,CAACN,cAAc,QAAEG,IAAqB,CAAC,EAAE,CAACA,IAAI,CAAC,CAAC;AACzE,CAAC;AAEDF,QAAQ,CAACM,WAAW,GAAG,UAAU;AAEjC,eAAeN,QAAQ","ignoreList":[]}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import styled from 'styled-components';
|
|
2
|
+
export const StyledHintText = styled.div`
|
|
3
|
+
border-width: 1px;
|
|
4
|
+
border-style: solid;
|
|
5
|
+
border-color: #9f5f00;
|
|
6
|
+
background-color: #fff3e0;
|
|
7
|
+
color: #222;
|
|
8
|
+
padding: 8px 12px;
|
|
9
|
+
|
|
10
|
+
border-radius: ${_ref => {
|
|
11
|
+
let {
|
|
12
|
+
theme
|
|
13
|
+
} = _ref;
|
|
14
|
+
return theme.cardBorderRadius;
|
|
15
|
+
}}px;
|
|
16
|
+
box-shadow: 0 2px 6px 0 rgba(0, 0, 0, ${_ref2 => {
|
|
17
|
+
let {
|
|
18
|
+
theme
|
|
19
|
+
} = _ref2;
|
|
20
|
+
return theme.cardShadow;
|
|
21
|
+
}});
|
|
22
|
+
`;
|
|
23
|
+
//# sourceMappingURL=HintText.styles.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"HintText.styles.js","names":["styled","StyledHintText","div","_ref","theme","cardBorderRadius","_ref2","cardShadow"],"sources":["../../../../../src/components/opening-times/hint-text/HintText.styles.ts"],"sourcesContent":["import type { WithTheme } from '@chayns-components/core';\nimport styled from 'styled-components';\n\ntype StyledHintTextProp = WithTheme<unknown>;\n\nexport const StyledHintText = styled.div<StyledHintTextProp>`\n border-width: 1px;\n border-style: solid;\n border-color: #9f5f00;\n background-color: #fff3e0;\n color: #222;\n padding: 8px 12px;\n\n border-radius: ${({ theme }: StyledHintTextProp) => theme.cardBorderRadius}px;\n box-shadow: 0 2px 6px 0 rgba(0, 0, 0, ${({ theme }: StyledHintTextProp) => theme.cardShadow});\n`;\n"],"mappings":"AACA,OAAOA,MAAM,MAAM,mBAAmB;AAItC,OAAO,MAAMC,cAAc,GAAGD,MAAM,CAACE,GAAuB;AAC5D;AACA;AACA;AACA;AACA;AACA;AACA;AACA,qBAAqBC,IAAA;EAAA,IAAC;IAAEC;EAA0B,CAAC,GAAAD,IAAA;EAAA,OAAKC,KAAK,CAACC,gBAAgB;AAAA;AAC9E,4CAA4CC,KAAA;EAAA,IAAC;IAAEF;EAA0B,CAAC,GAAAE,KAAA;EAAA,OAAKF,KAAK,CAACG,UAAU;AAAA;AAC/F,CAAC","ignoreList":[]}
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
import { AnimatePresence } from 'framer-motion';
|
|
2
|
+
import React, { useCallback, useEffect, useMemo, useState } from 'react';
|
|
3
|
+
import { v4 as uuidV4 } from 'uuid';
|
|
4
|
+
import { OpeningTimesButtonType } from '../../../types/openingTimes';
|
|
5
|
+
import OpeningInput from './opening-input/OpeningInput';
|
|
6
|
+
import { StyledOpeningInputPreview, StyledOpeningInputs } from './OpeningInputs.styles';
|
|
7
|
+
const OpeningInputs = _ref => {
|
|
8
|
+
let {
|
|
9
|
+
times,
|
|
10
|
+
isDisabled,
|
|
11
|
+
onRemove,
|
|
12
|
+
onAdd,
|
|
13
|
+
onInvalid,
|
|
14
|
+
id,
|
|
15
|
+
onChange,
|
|
16
|
+
currentDayId,
|
|
17
|
+
editMode = false,
|
|
18
|
+
closedText = ''
|
|
19
|
+
} = _ref;
|
|
20
|
+
const [newTimes, setNewTimes] = useState();
|
|
21
|
+
const [invalidTimes, setInvalidTimes] = useState([]);
|
|
22
|
+
useEffect(() => {
|
|
23
|
+
setNewTimes(times);
|
|
24
|
+
}, [times]);
|
|
25
|
+
const handleAdd = useCallback(() => {
|
|
26
|
+
const defaultTime = {
|
|
27
|
+
start: '08:00',
|
|
28
|
+
end: '18:00',
|
|
29
|
+
id: uuidV4()
|
|
30
|
+
};
|
|
31
|
+
setNewTimes(prevState => prevState ? [...prevState, defaultTime] : [defaultTime]);
|
|
32
|
+
if (typeof onAdd === 'function') {
|
|
33
|
+
onAdd(defaultTime, id);
|
|
34
|
+
}
|
|
35
|
+
}, [id, onAdd]);
|
|
36
|
+
const handleRemove = useCallback(timeId => {
|
|
37
|
+
setNewTimes(prevState => (prevState ?? []).filter(time => time.id !== timeId));
|
|
38
|
+
if (typeof onRemove === 'function') {
|
|
39
|
+
onRemove(timeId);
|
|
40
|
+
}
|
|
41
|
+
}, [onRemove]);
|
|
42
|
+
useEffect(() => {
|
|
43
|
+
const result = [];
|
|
44
|
+
for (let i = 0; i < times.length; i++) {
|
|
45
|
+
const currentTime = times[i];
|
|
46
|
+
const prevTime = times[i - 1];
|
|
47
|
+
if (currentTime) {
|
|
48
|
+
const currStart = new Date(`2000-01-01T${currentTime.start}`);
|
|
49
|
+
const currEnd = new Date(`2000-01-01T${currentTime.end}`);
|
|
50
|
+
if (currStart >= currEnd) {
|
|
51
|
+
result.push(currentTime);
|
|
52
|
+
}
|
|
53
|
+
if (prevTime) {
|
|
54
|
+
const prevEnd = new Date(`2000-01-01T${prevTime.end}`);
|
|
55
|
+
if (prevEnd > currStart) {
|
|
56
|
+
result.push(prevTime, currentTime);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
const invalidTimeIds = result.map(_ref2 => {
|
|
62
|
+
let {
|
|
63
|
+
id: invalidId
|
|
64
|
+
} = _ref2;
|
|
65
|
+
return invalidId;
|
|
66
|
+
});
|
|
67
|
+
setInvalidTimes(invalidTimeIds);
|
|
68
|
+
if (typeof onInvalid === 'function') {
|
|
69
|
+
onInvalid(id, invalidTimeIds);
|
|
70
|
+
}
|
|
71
|
+
}, [id, onInvalid, times]);
|
|
72
|
+
const handleChange = useCallback(newTime => {
|
|
73
|
+
setNewTimes(prevState => {
|
|
74
|
+
const updatedTimes = (prevState ?? []).map(time => {
|
|
75
|
+
if (time.id === newTime.id) {
|
|
76
|
+
return newTime;
|
|
77
|
+
}
|
|
78
|
+
return time;
|
|
79
|
+
});
|
|
80
|
+
if (typeof onChange === 'function') {
|
|
81
|
+
onChange(newTime);
|
|
82
|
+
}
|
|
83
|
+
return updatedTimes;
|
|
84
|
+
});
|
|
85
|
+
}, [onChange]);
|
|
86
|
+
const content = useMemo(() => {
|
|
87
|
+
const items = [];
|
|
88
|
+
if (!newTimes) {
|
|
89
|
+
return items;
|
|
90
|
+
}
|
|
91
|
+
newTimes.forEach((_ref3, index) => {
|
|
92
|
+
let {
|
|
93
|
+
end,
|
|
94
|
+
start,
|
|
95
|
+
id: timeId
|
|
96
|
+
} = _ref3;
|
|
97
|
+
if (!editMode) {
|
|
98
|
+
const text = isDisabled ? closedText : `${start} - ${end}`;
|
|
99
|
+
items.push(/*#__PURE__*/React.createElement(StyledOpeningInputPreview, {
|
|
100
|
+
key: `opening-times-preview__${id}.${timeId}`
|
|
101
|
+
}, `${text}${currentDayId && newTimes.length > 1 && index === 0 ? ', ' : ''}`));
|
|
102
|
+
return;
|
|
103
|
+
}
|
|
104
|
+
if (index > 1) {
|
|
105
|
+
return;
|
|
106
|
+
}
|
|
107
|
+
let buttonType = OpeningTimesButtonType.NONE;
|
|
108
|
+
if (index === 0 && times.length === 1 && !isDisabled) {
|
|
109
|
+
buttonType = OpeningTimesButtonType.ADD;
|
|
110
|
+
} else if (index === 1 && !isDisabled) {
|
|
111
|
+
buttonType = OpeningTimesButtonType.REMOVE;
|
|
112
|
+
}
|
|
113
|
+
items.push(/*#__PURE__*/React.createElement(OpeningInput, {
|
|
114
|
+
key: `opening-times-input__${id}.${timeId}`,
|
|
115
|
+
start: start,
|
|
116
|
+
id: timeId,
|
|
117
|
+
end: end,
|
|
118
|
+
isDisabled: isDisabled,
|
|
119
|
+
isInvalid: invalidTimes.includes(timeId),
|
|
120
|
+
buttonType: buttonType,
|
|
121
|
+
onAdd: handleAdd,
|
|
122
|
+
onChange: time => handleChange(time),
|
|
123
|
+
onRemove: () => handleRemove(timeId)
|
|
124
|
+
}));
|
|
125
|
+
});
|
|
126
|
+
return items;
|
|
127
|
+
}, [closedText, currentDayId, editMode, handleAdd, handleChange, handleRemove, id, invalidTimes, isDisabled, newTimes, times.length]);
|
|
128
|
+
const gap = useMemo(() => {
|
|
129
|
+
if (newTimes && newTimes.length > 1 && editMode || !editMode && currentDayId) {
|
|
130
|
+
return '8px';
|
|
131
|
+
}
|
|
132
|
+
return 0;
|
|
133
|
+
}, [currentDayId, editMode, newTimes]);
|
|
134
|
+
return useMemo(() => /*#__PURE__*/React.createElement(StyledOpeningInputs, {
|
|
135
|
+
$editMode: !currentDayId,
|
|
136
|
+
key: `opening-inputs__${id}`,
|
|
137
|
+
animate: {
|
|
138
|
+
gap
|
|
139
|
+
},
|
|
140
|
+
initial: {
|
|
141
|
+
gap: 0
|
|
142
|
+
}
|
|
143
|
+
}, /*#__PURE__*/React.createElement(AnimatePresence, {
|
|
144
|
+
initial: false
|
|
145
|
+
}, content)), [content, currentDayId, gap, id]);
|
|
146
|
+
};
|
|
147
|
+
OpeningInputs.displayName = 'OpeningInputs';
|
|
148
|
+
export default OpeningInputs;
|
|
149
|
+
//# sourceMappingURL=OpeningInputs.js.map
|