@chayns-components/date 5.0.0-beta.433

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.
Files changed (90) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +34 -0
  3. package/lib/components/calendar/Calendar.d.ts +36 -0
  4. package/lib/components/calendar/Calendar.js +141 -0
  5. package/lib/components/calendar/Calendar.js.map +1 -0
  6. package/lib/components/calendar/Calendar.styles.d.ts +4 -0
  7. package/lib/components/calendar/Calendar.styles.js +20 -0
  8. package/lib/components/calendar/Calendar.styles.js.map +1 -0
  9. package/lib/components/calendar/month-wrapper/MonthWrapper.d.ts +17 -0
  10. package/lib/components/calendar/month-wrapper/MonthWrapper.js +137 -0
  11. package/lib/components/calendar/month-wrapper/MonthWrapper.js.map +1 -0
  12. package/lib/components/calendar/month-wrapper/MonthWrapper.styles.d.ts +271 -0
  13. package/lib/components/calendar/month-wrapper/MonthWrapper.styles.js +24 -0
  14. package/lib/components/calendar/month-wrapper/MonthWrapper.styles.js.map +1 -0
  15. package/lib/components/calendar/month-wrapper/month/Month.d.ts +14 -0
  16. package/lib/components/calendar/month-wrapper/month/Month.js +43 -0
  17. package/lib/components/calendar/month-wrapper/month/Month.js.map +1 -0
  18. package/lib/components/calendar/month-wrapper/month/Month.styles.d.ts +4 -0
  19. package/lib/components/calendar/month-wrapper/month/Month.styles.js +23 -0
  20. package/lib/components/calendar/month-wrapper/month/Month.styles.js.map +1 -0
  21. package/lib/components/calendar/month-wrapper/month/day-wrapper/DayWrapper.d.ts +12 -0
  22. package/lib/components/calendar/month-wrapper/month/day-wrapper/DayWrapper.js +60 -0
  23. package/lib/components/calendar/month-wrapper/month/day-wrapper/DayWrapper.js.map +1 -0
  24. package/lib/components/calendar/month-wrapper/month/day-wrapper/DayWrapper.styles.d.ts +2 -0
  25. package/lib/components/calendar/month-wrapper/month/day-wrapper/DayWrapper.styles.js +17 -0
  26. package/lib/components/calendar/month-wrapper/month/day-wrapper/DayWrapper.styles.js.map +1 -0
  27. package/lib/components/calendar/month-wrapper/month/day-wrapper/day/Day.d.ts +12 -0
  28. package/lib/components/calendar/month-wrapper/month/day-wrapper/day/Day.js +66 -0
  29. package/lib/components/calendar/month-wrapper/month/day-wrapper/day/Day.js.map +1 -0
  30. package/lib/components/calendar/month-wrapper/month/day-wrapper/day/Day.styles.d.ts +15 -0
  31. package/lib/components/calendar/month-wrapper/month/day-wrapper/day/Day.styles.js +75 -0
  32. package/lib/components/calendar/month-wrapper/month/day-wrapper/day/Day.styles.js.map +1 -0
  33. package/lib/components/calendar/month-wrapper/month/day-wrapper/day/category/Category.d.ts +6 -0
  34. package/lib/components/calendar/month-wrapper/month/day-wrapper/day/category/Category.js +20 -0
  35. package/lib/components/calendar/month-wrapper/month/day-wrapper/day/category/Category.js.map +1 -0
  36. package/lib/components/calendar/month-wrapper/month/day-wrapper/day/category/Category.styles.d.ts +7 -0
  37. package/lib/components/calendar/month-wrapper/month/day-wrapper/day/category/Category.styles.js +21 -0
  38. package/lib/components/calendar/month-wrapper/month/day-wrapper/day/category/Category.styles.js.map +1 -0
  39. package/lib/components/calendar/month-wrapper/month/weekday-wrapper/WeekdayWrapper.d.ts +7 -0
  40. package/lib/components/calendar/month-wrapper/month/weekday-wrapper/WeekdayWrapper.js +45 -0
  41. package/lib/components/calendar/month-wrapper/month/weekday-wrapper/WeekdayWrapper.js.map +1 -0
  42. package/lib/components/calendar/month-wrapper/month/weekday-wrapper/WeekdayWrapper.styles.d.ts +2 -0
  43. package/lib/components/calendar/month-wrapper/month/weekday-wrapper/WeekdayWrapper.styles.js +16 -0
  44. package/lib/components/calendar/month-wrapper/month/weekday-wrapper/WeekdayWrapper.styles.js.map +1 -0
  45. package/lib/components/calendar/month-wrapper/month/weekday-wrapper/weekday/Weekday.d.ts +6 -0
  46. package/lib/components/calendar/month-wrapper/month/weekday-wrapper/weekday/Weekday.js +18 -0
  47. package/lib/components/calendar/month-wrapper/month/weekday-wrapper/weekday/Weekday.js.map +1 -0
  48. package/lib/components/calendar/month-wrapper/month/weekday-wrapper/weekday/Weekday.styles.d.ts +4 -0
  49. package/lib/components/calendar/month-wrapper/month/weekday-wrapper/weekday/Weekday.styles.js +19 -0
  50. package/lib/components/calendar/month-wrapper/month/weekday-wrapper/weekday/Weekday.styles.js.map +1 -0
  51. package/lib/components/date-info/DateInfo.d.ts +37 -0
  52. package/lib/components/date-info/DateInfo.js +110 -0
  53. package/lib/components/date-info/DateInfo.js.map +1 -0
  54. package/lib/components/opening-times/OpeningTimes.d.ts +27 -0
  55. package/lib/components/opening-times/OpeningTimes.js +135 -0
  56. package/lib/components/opening-times/OpeningTimes.js.map +1 -0
  57. package/lib/components/opening-times/OpeningTimes.styles.d.ts +8 -0
  58. package/lib/components/opening-times/OpeningTimes.styles.js +19 -0
  59. package/lib/components/opening-times/OpeningTimes.styles.js.map +1 -0
  60. package/lib/components/opening-times/opening-inputs/OpeningInputs.d.ts +12 -0
  61. package/lib/components/opening-times/opening-inputs/OpeningInputs.js +94 -0
  62. package/lib/components/opening-times/opening-inputs/OpeningInputs.js.map +1 -0
  63. package/lib/components/opening-times/opening-inputs/OpeningInputs.styles.d.ts +2 -0
  64. package/lib/components/opening-times/opening-inputs/OpeningInputs.styles.js +13 -0
  65. package/lib/components/opening-times/opening-inputs/OpeningInputs.styles.js.map +1 -0
  66. package/lib/components/opening-times/opening-inputs/opening-input/OpeningInput.d.ts +14 -0
  67. package/lib/components/opening-times/opening-inputs/opening-input/OpeningInput.js +100 -0
  68. package/lib/components/opening-times/opening-inputs/opening-input/OpeningInput.js.map +1 -0
  69. package/lib/components/opening-times/opening-inputs/opening-input/OpeningInput.styles.d.ts +274 -0
  70. package/lib/components/opening-times/opening-inputs/opening-input/OpeningInput.styles.js +46 -0
  71. package/lib/components/opening-times/opening-inputs/opening-input/OpeningInput.styles.js.map +1 -0
  72. package/lib/constants/dateInfo.d.ts +22 -0
  73. package/lib/constants/dateInfo.js +629 -0
  74. package/lib/constants/dateInfo.js.map +1 -0
  75. package/lib/index.d.ts +5 -0
  76. package/lib/index.js +28 -0
  77. package/lib/index.js.map +1 -0
  78. package/lib/types/calendar.d.ts +32 -0
  79. package/lib/types/calendar.js +22 -0
  80. package/lib/types/calendar.js.map +1 -0
  81. package/lib/types/openingTimes.d.ts +28 -0
  82. package/lib/types/openingTimes.js +13 -0
  83. package/lib/types/openingTimes.js.map +1 -0
  84. package/lib/utils/calendar.d.ts +15 -0
  85. package/lib/utils/calendar.js +58 -0
  86. package/lib/utils/calendar.js.map +1 -0
  87. package/lib/utils/dateInfo.d.ts +55 -0
  88. package/lib/utils/dateInfo.js +364 -0
  89. package/lib/utils/dateInfo.js.map +1 -0
  90. package/package.json +69 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2021 Tobit Laboratories AG
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,34 @@
1
+ <div align="center">
2
+ <h1>
3
+ <img src="https://raw.githubusercontent.com/TobitSoftware/chayns-components/master/assets/logo.png" width="600px" alt="chayns-components" />
4
+ </h1>
5
+ <p>A set of beautiful React components for developing your own applications with chayns.</p>
6
+ <div>
7
+ <img src="https://img.shields.io/npm/dm/@chayns-components/typewriter.svg?style=for-the-badge" alt="" />
8
+ <img src="https://img.shields.io/npm/v/@chayns-components/typewriter?style=for-the-badge" alt="" />
9
+ <img src="https://img.shields.io/github/license/TobitSoftware/chayns-components?style=for-the-badge" alt="" />
10
+ <img src="https://img.shields.io/github/contributors/TobitSoftware/chayns-components?style=for-the-badge" alt="" />
11
+ </div>
12
+ </div>
13
+
14
+ ---
15
+
16
+ ## Installation
17
+
18
+ First you need to install the color picker part of the chayns-components.
19
+
20
+ ```bash
21
+ # NPM
22
+ npm install @chayns-components/date
23
+
24
+ # Yarn
25
+ yarn add @chayns-components/date
26
+ ```
27
+
28
+ > **Information:** Since the components have now been implemented with the styled-components
29
+ > library, the styles are delivered directly with the components. There is no need to load an extra
30
+ > stylesheet anymore.
31
+
32
+ ## Usage
33
+
34
+ For detailed usage visit the [storybook](https://components.chayns.site/storybook).
@@ -0,0 +1,36 @@
1
+ import { FC } from 'react';
2
+ import { type Locale } from 'date-fns';
3
+ import type { Categories, HighlightedDates } from '../../types/calendar';
4
+ export type CalendarProps = {
5
+ /**
6
+ * An array to group dates into a category.
7
+ */
8
+ categories?: Categories[];
9
+ /**
10
+ * The last Month that can be displayed.
11
+ */
12
+ endDate?: Date;
13
+ /**
14
+ * An array with dates and corresponding styles to highlight.
15
+ */
16
+ highlightedDates?: HighlightedDates[];
17
+ /**
18
+ * The locale language to format the dates.
19
+ */
20
+ locale?: Locale;
21
+ /**
22
+ * Function to be executed when a date is selected.
23
+ * @param date
24
+ */
25
+ onSelect?: (date: Date) => void;
26
+ /**
27
+ * A date that should be preselected.
28
+ */
29
+ selectedDate?: Date;
30
+ /**
31
+ * The first Month that can be displayed.
32
+ */
33
+ startDate: Date;
34
+ };
35
+ declare const Calendar: FC<CalendarProps>;
36
+ export default Calendar;
@@ -0,0 +1,141 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+ var _react = _interopRequireWildcard(require("react"));
8
+ var _dateFns = require("date-fns");
9
+ var _locale = require("date-fns/locale");
10
+ var _Calendar = require("./Calendar.styles");
11
+ var _calendar = require("../../utils/calendar");
12
+ var _core = require("@chayns-components/core");
13
+ var _MonthWrapper = _interopRequireDefault(require("./month-wrapper/MonthWrapper"));
14
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
15
+ function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
16
+ function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
17
+ const END_DATE = new Date(new Date().setFullYear(new Date().getFullYear() + 100));
18
+ const Calendar = _ref => {
19
+ let {
20
+ locale = _locale.de,
21
+ endDate = END_DATE,
22
+ startDate,
23
+ highlightedDates,
24
+ onSelect,
25
+ selectedDate,
26
+ categories
27
+ } = _ref;
28
+ const [currentDate, setCurrentDate] = (0, _react.useState)();
29
+ const [shouldRenderTwoMonths, setShouldRenderTwoMonths] = (0, _react.useState)(true);
30
+ const [internalSelectedDate, setInternalSelectedDate] = (0, _react.useState)();
31
+ const [direction, setDirection] = (0, _react.useState)();
32
+ const [width, setWidth] = (0, _react.useState)(0);
33
+ const calendarRef = (0, _react.useRef)(null);
34
+ (0, _react.useEffect)(() => {
35
+ if (selectedDate) {
36
+ setInternalSelectedDate(selectedDate);
37
+ }
38
+ }, [selectedDate]);
39
+ (0, _react.useEffect)(() => {
40
+ if (calendarRef.current) {
41
+ const resizeObserver = new ResizeObserver(entries => {
42
+ if (entries && entries[0]) {
43
+ const observedWidth = entries[0].contentRect.width;
44
+ setWidth(observedWidth - 30);
45
+ if (observedWidth < 430) {
46
+ setShouldRenderTwoMonths(false);
47
+ } else {
48
+ setShouldRenderTwoMonths(true);
49
+ }
50
+ }
51
+ });
52
+ resizeObserver.observe(calendarRef.current);
53
+ return () => {
54
+ resizeObserver.disconnect();
55
+ };
56
+ }
57
+ return () => {};
58
+ }, []);
59
+ (0, _react.useEffect)(() => {
60
+ const date = new Date();
61
+ setCurrentDate((0, _calendar.isDateInRange)({
62
+ startDate,
63
+ endDate,
64
+ currentDate: date
65
+ }));
66
+ }, [endDate, startDate]);
67
+ const handleLeftArrowClick = (0, _react.useCallback)(() => {
68
+ setDirection('left');
69
+ setCurrentDate(prevDate => {
70
+ if (!prevDate) {
71
+ return prevDate;
72
+ }
73
+ const newDate = (0, _calendar.getNewDate)(-1, prevDate);
74
+ return (0, _calendar.isDateInRange)({
75
+ startDate,
76
+ endDate,
77
+ currentDate: newDate
78
+ });
79
+ });
80
+ }, [endDate, startDate]);
81
+ const handleRightArrowClick = (0, _react.useCallback)(() => {
82
+ setDirection('right');
83
+ setCurrentDate(prevDate => {
84
+ if (!prevDate) {
85
+ return prevDate;
86
+ }
87
+ const newDate = (0, _calendar.getNewDate)(1, prevDate);
88
+ return (0, _calendar.isDateInRange)({
89
+ startDate,
90
+ endDate,
91
+ currentDate: newDate
92
+ });
93
+ });
94
+ }, [endDate, startDate]);
95
+ const handleSelect = (0, _react.useCallback)(date => {
96
+ setInternalSelectedDate(date);
97
+ if (typeof onSelect === 'function') {
98
+ onSelect(date);
99
+ }
100
+ }, [onSelect]);
101
+ const handleAnimationFinished = () => {
102
+ setDirection(undefined);
103
+ };
104
+ const ShouldShowLeftArrow = (0, _react.useMemo)(() => {
105
+ if (!currentDate) {
106
+ return false;
107
+ }
108
+ return !(0, _dateFns.isSameMonth)(currentDate, startDate);
109
+ }, [currentDate, startDate]);
110
+ const ShouldShowRightArrow = (0, _react.useMemo)(() => {
111
+ if (!currentDate) {
112
+ return false;
113
+ }
114
+ return !(0, _dateFns.isSameMonth)(currentDate, endDate);
115
+ }, [currentDate, endDate]);
116
+ return /*#__PURE__*/_react.default.createElement(_Calendar.StyledCalendar, {
117
+ ref: calendarRef
118
+ }, ShouldShowLeftArrow ? /*#__PURE__*/_react.default.createElement(_Calendar.StyledCalendarIconWrapper, {
119
+ onClick: handleLeftArrowClick
120
+ }, /*#__PURE__*/_react.default.createElement(_core.Icon, {
121
+ icons: ['fa fa-angle-left']
122
+ })) : /*#__PURE__*/_react.default.createElement(_Calendar.StyledCalendarIconWrapperPseudo, null), currentDate && /*#__PURE__*/_react.default.createElement(_MonthWrapper.default, {
123
+ shouldRenderTwo: shouldRenderTwoMonths,
124
+ currentDate: currentDate,
125
+ width: width,
126
+ locale: locale,
127
+ direction: direction,
128
+ onSelect: handleSelect,
129
+ selectedDate: internalSelectedDate,
130
+ highlightedDates: highlightedDates,
131
+ categories: categories,
132
+ onAnimationFinished: handleAnimationFinished
133
+ }), ShouldShowRightArrow ? /*#__PURE__*/_react.default.createElement(_Calendar.StyledCalendarIconWrapper, {
134
+ onClick: handleRightArrowClick
135
+ }, /*#__PURE__*/_react.default.createElement(_core.Icon, {
136
+ icons: ['fa fa-angle-right']
137
+ })) : /*#__PURE__*/_react.default.createElement(_Calendar.StyledCalendarIconWrapperPseudo, null));
138
+ };
139
+ Calendar.displayName = 'Calendar';
140
+ var _default = exports.default = Calendar;
141
+ //# sourceMappingURL=Calendar.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Calendar.js","names":["_react","_interopRequireWildcard","require","_dateFns","_locale","_Calendar","_calendar","_core","_MonthWrapper","_interopRequireDefault","obj","__esModule","default","_getRequireWildcardCache","e","WeakMap","r","t","has","get","n","__proto__","a","Object","defineProperty","getOwnPropertyDescriptor","u","prototype","hasOwnProperty","call","i","set","END_DATE","Date","setFullYear","getFullYear","Calendar","_ref","locale","de","endDate","startDate","highlightedDates","onSelect","selectedDate","categories","currentDate","setCurrentDate","useState","shouldRenderTwoMonths","setShouldRenderTwoMonths","internalSelectedDate","setInternalSelectedDate","direction","setDirection","width","setWidth","calendarRef","useRef","useEffect","current","resizeObserver","ResizeObserver","entries","observedWidth","contentRect","observe","disconnect","date","isDateInRange","handleLeftArrowClick","useCallback","prevDate","newDate","getNewDate","handleRightArrowClick","handleSelect","handleAnimationFinished","undefined","ShouldShowLeftArrow","useMemo","isSameMonth","ShouldShowRightArrow","createElement","StyledCalendar","ref","StyledCalendarIconWrapper","onClick","Icon","icons","StyledCalendarIconWrapperPseudo","shouldRenderTwo","onAnimationFinished","displayName","_default","exports"],"sources":["../../../src/components/calendar/Calendar.tsx"],"sourcesContent":["import React, { FC, useCallback, useEffect, useMemo, useRef, useState } from 'react';\nimport { isSameMonth, type Locale } from 'date-fns';\nimport { de } from 'date-fns/locale';\nimport {\n StyledCalendar,\n StyledCalendarIconWrapper,\n StyledCalendarIconWrapperPseudo,\n} from './Calendar.styles';\nimport { getNewDate, isDateInRange } from '../../utils/calendar';\nimport type { Categories, HighlightedDates } from '../../types/calendar';\nimport { Icon } from '@chayns-components/core';\nimport MonthWrapper from './month-wrapper/MonthWrapper';\n\nconst END_DATE = new Date(new Date().setFullYear(new Date().getFullYear() + 100));\n\nexport type CalendarProps = {\n /**\n * An array to group dates into a category.\n */\n categories?: Categories[];\n /**\n * The last Month that can be displayed.\n */\n endDate?: Date;\n /**\n * An array with dates and corresponding styles to highlight.\n */\n highlightedDates?: HighlightedDates[];\n /**\n * The locale language to format the dates.\n */\n locale?: Locale;\n /**\n * Function to be executed when a date is selected.\n * @param date\n */\n onSelect?: (date: Date) => void;\n /**\n * A date that should be preselected.\n */\n selectedDate?: Date;\n /**\n * The first Month that can be displayed.\n */\n startDate: Date;\n};\n\nconst Calendar: FC<CalendarProps> = ({\n locale = de,\n endDate = END_DATE,\n startDate,\n highlightedDates,\n onSelect,\n selectedDate,\n categories,\n}) => {\n const [currentDate, setCurrentDate] = useState<Date>();\n const [shouldRenderTwoMonths, setShouldRenderTwoMonths] = useState(true);\n const [internalSelectedDate, setInternalSelectedDate] = useState<Date>();\n const [direction, setDirection] = useState<'left' | 'right'>();\n const [width, setWidth] = useState(0);\n\n const calendarRef = useRef<HTMLDivElement>(null);\n\n useEffect(() => {\n if (selectedDate) {\n setInternalSelectedDate(selectedDate);\n }\n }, [selectedDate]);\n\n useEffect(() => {\n if (calendarRef.current) {\n const resizeObserver = new ResizeObserver((entries) => {\n if (entries && entries[0]) {\n const observedWidth = entries[0].contentRect.width;\n\n setWidth(observedWidth - 30);\n\n if (observedWidth < 430) {\n setShouldRenderTwoMonths(false);\n } else {\n setShouldRenderTwoMonths(true);\n }\n }\n });\n\n resizeObserver.observe(calendarRef.current);\n\n return () => {\n resizeObserver.disconnect();\n };\n }\n\n return () => {};\n }, []);\n\n useEffect(() => {\n const date = new Date();\n\n setCurrentDate(isDateInRange({ startDate, endDate, currentDate: date }));\n }, [endDate, startDate]);\n\n const handleLeftArrowClick = useCallback(() => {\n setDirection('left');\n\n setCurrentDate((prevDate) => {\n if (!prevDate) {\n return prevDate;\n }\n\n const newDate = getNewDate(-1, prevDate);\n\n return isDateInRange({ startDate, endDate, currentDate: newDate });\n });\n }, [endDate, startDate]);\n\n const handleRightArrowClick = useCallback(() => {\n setDirection('right');\n\n setCurrentDate((prevDate) => {\n if (!prevDate) {\n return prevDate;\n }\n\n const newDate = getNewDate(1, prevDate);\n\n return isDateInRange({ startDate, endDate, currentDate: newDate });\n });\n }, [endDate, startDate]);\n\n const handleSelect = useCallback(\n (date: Date) => {\n setInternalSelectedDate(date);\n\n if (typeof onSelect === 'function') {\n onSelect(date);\n }\n },\n [onSelect],\n );\n\n const handleAnimationFinished = () => {\n setDirection(undefined);\n };\n\n const ShouldShowLeftArrow = useMemo(() => {\n if (!currentDate) {\n return false;\n }\n\n return !isSameMonth(currentDate, startDate);\n }, [currentDate, startDate]);\n\n const ShouldShowRightArrow = useMemo(() => {\n if (!currentDate) {\n return false;\n }\n\n return !isSameMonth(currentDate, endDate);\n }, [currentDate, endDate]);\n\n return (\n <StyledCalendar ref={calendarRef}>\n {ShouldShowLeftArrow ? (\n <StyledCalendarIconWrapper onClick={handleLeftArrowClick}>\n <Icon icons={['fa fa-angle-left']} />\n </StyledCalendarIconWrapper>\n ) : (\n <StyledCalendarIconWrapperPseudo />\n )}\n {currentDate && (\n <MonthWrapper\n shouldRenderTwo={shouldRenderTwoMonths}\n currentDate={currentDate}\n width={width}\n locale={locale}\n direction={direction}\n onSelect={handleSelect}\n selectedDate={internalSelectedDate}\n highlightedDates={highlightedDates}\n categories={categories}\n onAnimationFinished={handleAnimationFinished}\n />\n )}\n {ShouldShowRightArrow ? (\n <StyledCalendarIconWrapper onClick={handleRightArrowClick}>\n <Icon icons={['fa fa-angle-right']} />\n </StyledCalendarIconWrapper>\n ) : (\n <StyledCalendarIconWrapperPseudo />\n )}\n </StyledCalendar>\n );\n};\n\nCalendar.displayName = 'Calendar';\n\nexport default Calendar;\n"],"mappings":";;;;;;AAAA,IAAAA,MAAA,GAAAC,uBAAA,CAAAC,OAAA;AACA,IAAAC,QAAA,GAAAD,OAAA;AACA,IAAAE,OAAA,GAAAF,OAAA;AACA,IAAAG,SAAA,GAAAH,OAAA;AAKA,IAAAI,SAAA,GAAAJ,OAAA;AAEA,IAAAK,KAAA,GAAAL,OAAA;AACA,IAAAM,aAAA,GAAAC,sBAAA,CAAAP,OAAA;AAAwD,SAAAO,uBAAAC,GAAA,WAAAA,GAAA,IAAAA,GAAA,CAAAC,UAAA,GAAAD,GAAA,KAAAE,OAAA,EAAAF,GAAA;AAA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,CAAE,CACb,CAAC,gBAE5BzF,MAAA,CAAAY,OAAA,CAAAuE,aAAA,CAAC9E,SAAA,CAAAqF,+BAA+B,MAAE,CACrC,EACA5C,WAAW,iBACR9C,MAAA,CAAAY,OAAA,CAAAuE,aAAA,CAAC3E,aAAA,CAAAI,OAAY;IACT+E,eAAe,EAAE1C,qBAAsB;IACvCH,WAAW,EAAEA,WAAY;IACzBS,KAAK,EAAEA,KAAM;IACbjB,MAAM,EAAEA,MAAO;IACfe,SAAS,EAAEA,SAAU;IACrBV,QAAQ,EAAEiC,YAAa;IACvBhC,YAAY,EAAEO,oBAAqB;IACnCT,gBAAgB,EAAEA,gBAAiB;IACnCG,UAAU,EAAEA,UAAW;IACvB+C,mBAAmB,EAAEf;EAAwB,CAChD,CACJ,EACAK,oBAAoB,gBACjBlF,MAAA,CAAAY,OAAA,CAAAuE,aAAA,CAAC9E,SAAA,CAAAiF,yBAAyB;IAACC,OAAO,EAAEZ;EAAsB,gBACtD3E,MAAA,CAAAY,OAAA,CAAAuE,aAAA,CAAC5E,KAAA,CAAAiF,IAAI;IAACC,KAAK,EAAE,CAAC,mBAAmB;EAAE,CAAE,CACd,CAAC,gBAE5BzF,MAAA,CAAAY,OAAA,CAAAuE,aAAA,CAAC9E,SAAA,CAAAqF,+BAA+B,MAAE,CAE1B,CAAC;AAEzB,CAAC;AAEDtD,QAAQ,CAACyD,WAAW,GAAG,UAAU;AAAC,IAAAC,QAAA,GAAAC,OAAA,CAAAnF,OAAA,GAEnBwB,QAAQ"}
@@ -0,0 +1,4 @@
1
+ /// <reference types="react" />
2
+ export declare const StyledCalendar: import("styled-components").IStyledComponent<"web", import("styled-components/dist/types").FastOmit<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLDivElement>, HTMLDivElement>, never>>;
3
+ export declare const StyledCalendarIconWrapper: import("styled-components").IStyledComponent<"web", import("styled-components/dist/types").FastOmit<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLDivElement>, HTMLDivElement>, never>>;
4
+ export declare const StyledCalendarIconWrapperPseudo: import("styled-components").IStyledComponent<"web", import("styled-components/dist/types").FastOmit<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLDivElement>, HTMLDivElement>, never>>;
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.StyledCalendarIconWrapperPseudo = exports.StyledCalendarIconWrapper = exports.StyledCalendar = void 0;
7
+ var _styledComponents = _interopRequireDefault(require("styled-components"));
8
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
9
+ const StyledCalendar = exports.StyledCalendar = _styledComponents.default.div`
10
+ display: flex;
11
+ width: 100%;
12
+ `;
13
+ const StyledCalendarIconWrapper = exports.StyledCalendarIconWrapper = _styledComponents.default.div`
14
+ cursor: pointer;
15
+ z-index: 2;
16
+ `;
17
+ const StyledCalendarIconWrapperPseudo = exports.StyledCalendarIconWrapperPseudo = _styledComponents.default.div`
18
+ width: 15px;
19
+ `;
20
+ //# sourceMappingURL=Calendar.styles.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Calendar.styles.js","names":["_styledComponents","_interopRequireDefault","require","obj","__esModule","default","StyledCalendar","exports","styled","div","StyledCalendarIconWrapper","StyledCalendarIconWrapperPseudo"],"sources":["../../../src/components/calendar/Calendar.styles.ts"],"sourcesContent":["import styled from 'styled-components';\n\nexport const StyledCalendar = styled.div`\n display: flex;\n width: 100%;\n`;\n\nexport const StyledCalendarIconWrapper = styled.div`\n cursor: pointer;\n z-index: 2;\n`;\n\nexport const StyledCalendarIconWrapperPseudo = styled.div`\n width: 15px;\n`;\n"],"mappings":";;;;;;AAAA,IAAAA,iBAAA,GAAAC,sBAAA,CAAAC,OAAA;AAAuC,SAAAD,uBAAAE,GAAA,WAAAA,GAAA,IAAAA,GAAA,CAAAC,UAAA,GAAAD,GAAA,KAAAE,OAAA,EAAAF,GAAA;AAEhC,MAAMG,cAAc,GAAAC,OAAA,CAAAD,cAAA,GAAGE,yBAAM,CAACC,GAAI;AACzC;AACA;AACA,CAAC;AAEM,MAAMC,yBAAyB,GAAAH,OAAA,CAAAG,yBAAA,GAAGF,yBAAM,CAACC,GAAI;AACpD;AACA;AACA,CAAC;AAEM,MAAME,+BAA+B,GAAAJ,OAAA,CAAAI,+BAAA,GAAGH,yBAAM,CAACC,GAAI;AAC1D;AACA,CAAC"}
@@ -0,0 +1,17 @@
1
+ import { FC } from 'react';
2
+ import type { Locale } from 'date-fns';
3
+ import type { Categories, HighlightedDates } from '../../../types/calendar';
4
+ export type MonthWrapperProps = {
5
+ locale: Locale;
6
+ highlightedDates?: HighlightedDates[];
7
+ onSelect: (date: Date) => void;
8
+ selectedDate?: Date;
9
+ categories?: Categories[];
10
+ currentDate: Date;
11
+ direction?: 'left' | 'right';
12
+ onAnimationFinished: () => void;
13
+ shouldRenderTwo: boolean;
14
+ width: number;
15
+ };
16
+ declare const MonthWrapper: FC<MonthWrapperProps>;
17
+ export default MonthWrapper;
@@ -0,0 +1,137 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+ var _react = _interopRequireWildcard(require("react"));
8
+ var _MonthWrapper = require("./MonthWrapper.styles");
9
+ var _Month = _interopRequireDefault(require("./month/Month"));
10
+ var _calendar = require("../../../utils/calendar");
11
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
12
+ function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
13
+ function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
14
+ const MonthWrapper = _ref => {
15
+ let {
16
+ locale,
17
+ currentDate,
18
+ highlightedDates,
19
+ selectedDate,
20
+ onSelect,
21
+ categories,
22
+ direction,
23
+ onAnimationFinished,
24
+ shouldRenderTwo,
25
+ width
26
+ } = _ref;
27
+ const [content, setContent] = (0, _react.useState)();
28
+ (0, _react.useEffect)(() => {
29
+ setContent(prevState => {
30
+ // Initial render of months
31
+ if (!prevState) {
32
+ const items = [];
33
+ for (let i = -1; i < 3; i++) {
34
+ const date = (0, _calendar.getNewDate)(i, currentDate);
35
+ const {
36
+ month,
37
+ year
38
+ } = (0, _calendar.getMonthAndYear)(date);
39
+ items.push( /*#__PURE__*/_react.default.createElement(_Month.default, {
40
+ key: `${month}-${year}`,
41
+ month: month,
42
+ year: year,
43
+ locale: locale,
44
+ onSelect: onSelect,
45
+ highlightedDates: highlightedDates,
46
+ categories: categories,
47
+ selectedDate: selectedDate
48
+ }));
49
+ }
50
+ return items;
51
+ }
52
+ if (direction === 'left') {
53
+ const date = (0, _calendar.getNewDate)(-1, currentDate);
54
+ const {
55
+ month,
56
+ year
57
+ } = (0, _calendar.getMonthAndYear)(date);
58
+ prevState.unshift( /*#__PURE__*/_react.default.createElement(_Month.default, {
59
+ key: `${month}-${year}`,
60
+ month: month,
61
+ year: year,
62
+ locale: locale,
63
+ onSelect: onSelect,
64
+ highlightedDates: highlightedDates,
65
+ categories: categories,
66
+ selectedDate: selectedDate
67
+ }));
68
+ prevState.pop();
69
+ }
70
+ if (direction === 'right') {
71
+ const date = (0, _calendar.getNewDate)(2, currentDate);
72
+ const {
73
+ month,
74
+ year
75
+ } = (0, _calendar.getMonthAndYear)(date);
76
+ prevState.push( /*#__PURE__*/_react.default.createElement(_Month.default, {
77
+ key: `${month}-${year}`,
78
+ month: month,
79
+ year: year,
80
+ locale: locale,
81
+ onSelect: onSelect,
82
+ highlightedDates: highlightedDates,
83
+ categories: categories,
84
+ selectedDate: selectedDate
85
+ }));
86
+ prevState.shift();
87
+ }
88
+ return prevState;
89
+ });
90
+ }, [categories, currentDate, direction, highlightedDates, locale, onSelect, selectedDate]);
91
+ const animate = (0, _react.useMemo)(() => {
92
+ if (shouldRenderTwo) {
93
+ switch (true) {
94
+ case direction === 'left':
95
+ return {
96
+ x: '0%'
97
+ };
98
+ case direction === 'right':
99
+ return {
100
+ x: '-100%'
101
+ };
102
+ default:
103
+ return {
104
+ x: '-50%'
105
+ };
106
+ }
107
+ } else {
108
+ switch (true) {
109
+ case direction === 'left':
110
+ return {
111
+ x: '0%'
112
+ };
113
+ case direction === 'right':
114
+ return {
115
+ x: '-200%'
116
+ };
117
+ default:
118
+ return {
119
+ x: '-100%'
120
+ };
121
+ }
122
+ }
123
+ }, [direction, shouldRenderTwo]);
124
+ return /*#__PURE__*/_react.default.createElement(_MonthWrapper.StyledMonthWrapper, {
125
+ height: shouldRenderTwo ? width / 2 : width
126
+ }, /*#__PURE__*/_react.default.createElement(_MonthWrapper.StyledMotionWrapper, {
127
+ animate: animate,
128
+ transition: {
129
+ type: 'tween',
130
+ duration: !direction ? 0 : 0.2
131
+ },
132
+ onAnimationComplete: onAnimationFinished
133
+ }, content));
134
+ };
135
+ MonthWrapper.displayName = 'MonthWrapper';
136
+ var _default = exports.default = MonthWrapper;
137
+ //# sourceMappingURL=MonthWrapper.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"MonthWrapper.js","names":["_react","_interopRequireWildcard","require","_MonthWrapper","_Month","_interopRequireDefault","_calendar","obj","__esModule","default","_getRequireWildcardCache","e","WeakMap","r","t","has","get","n","__proto__","a","Object","defineProperty","getOwnPropertyDescriptor","u","prototype","hasOwnProperty","call","i","set","MonthWrapper","_ref","locale","currentDate","highlightedDates","selectedDate","onSelect","categories","direction","onAnimationFinished","shouldRenderTwo","width","content","setContent","useState","useEffect","prevState","items","date","getNewDate","month","year","getMonthAndYear","push","createElement","key","unshift","pop","shift","animate","useMemo","x","StyledMonthWrapper","height","StyledMotionWrapper","transition","type","duration","onAnimationComplete","displayName","_default","exports"],"sources":["../../../../src/components/calendar/month-wrapper/MonthWrapper.tsx"],"sourcesContent":["import React, { FC, type ReactElement, useEffect, useMemo, useState } from 'react';\nimport type { Locale } from 'date-fns';\nimport { StyledMonthWrapper, StyledMotionWrapper } from './MonthWrapper.styles';\nimport type { MotionProps } from 'framer-motion';\nimport type { Categories, HighlightedDates } from '../../../types/calendar';\nimport Month from './month/Month';\nimport { getMonthAndYear, getNewDate } from '../../../utils/calendar';\n\nexport type MonthWrapperProps = {\n locale: Locale;\n highlightedDates?: HighlightedDates[];\n onSelect: (date: Date) => void;\n selectedDate?: Date;\n categories?: Categories[];\n currentDate: Date;\n direction?: 'left' | 'right';\n onAnimationFinished: () => void;\n shouldRenderTwo: boolean;\n width: number;\n};\n\nconst MonthWrapper: FC<MonthWrapperProps> = ({\n locale,\n currentDate,\n highlightedDates,\n selectedDate,\n onSelect,\n categories,\n direction,\n onAnimationFinished,\n shouldRenderTwo,\n width,\n}) => {\n const [content, setContent] = useState<ReactElement[]>();\n\n useEffect(() => {\n setContent((prevState) => {\n // Initial render of months\n if (!prevState) {\n const items: ReactElement[] = [];\n\n for (let i = -1; i < 3; i++) {\n const date = getNewDate(i, currentDate);\n\n const { month, year } = getMonthAndYear(date);\n\n items.push(\n <Month\n key={`${month}-${year}`}\n month={month}\n year={year}\n locale={locale}\n onSelect={onSelect}\n highlightedDates={highlightedDates}\n categories={categories}\n selectedDate={selectedDate}\n />,\n );\n }\n\n return items;\n }\n\n if (direction === 'left') {\n const date = getNewDate(-1, currentDate);\n\n const { month, year } = getMonthAndYear(date);\n\n prevState.unshift(\n <Month\n key={`${month}-${year}`}\n month={month}\n year={year}\n locale={locale}\n onSelect={onSelect}\n highlightedDates={highlightedDates}\n categories={categories}\n selectedDate={selectedDate}\n />,\n );\n prevState.pop();\n }\n\n if (direction === 'right') {\n const date = getNewDate(2, currentDate);\n\n const { month, year } = getMonthAndYear(date);\n\n prevState.push(\n <Month\n key={`${month}-${year}`}\n month={month}\n year={year}\n locale={locale}\n onSelect={onSelect}\n highlightedDates={highlightedDates}\n categories={categories}\n selectedDate={selectedDate}\n />,\n );\n prevState.shift();\n }\n\n return prevState;\n });\n }, [categories, currentDate, direction, highlightedDates, locale, onSelect, selectedDate]);\n\n const animate: MotionProps['animate'] = useMemo(() => {\n if (shouldRenderTwo) {\n switch (true) {\n case direction === 'left':\n return { x: '0%' };\n case direction === 'right':\n return { x: '-100%' };\n default:\n return { x: '-50%' };\n }\n } else {\n switch (true) {\n case direction === 'left':\n return { x: '0%' };\n case direction === 'right':\n return { x: '-200%' };\n default:\n return { x: '-100%' };\n }\n }\n }, [direction, shouldRenderTwo]);\n\n return (\n <StyledMonthWrapper height={shouldRenderTwo ? width / 2 : width}>\n <StyledMotionWrapper\n animate={animate}\n transition={{\n type: 'tween',\n duration: !direction ? 0 : 0.2,\n }}\n onAnimationComplete={onAnimationFinished}\n >\n {content}\n </StyledMotionWrapper>\n </StyledMonthWrapper>\n );\n};\n\nMonthWrapper.displayName = 'MonthWrapper';\n\nexport default MonthWrapper;\n"],"mappings":";;;;;;AAAA,IAAAA,MAAA,GAAAC,uBAAA,CAAAC,OAAA;AAEA,IAAAC,aAAA,GAAAD,OAAA;AAGA,IAAAE,MAAA,GAAAC,sBAAA,CAAAH,OAAA;AACA,IAAAI,SAAA,GAAAJ,OAAA;AAAsE,SAAAG,uBAAAE,GAAA,WAAAA,GAAA,IAAAA,GAAA,CAAAC,UAAA,GAAAD,GAAA,KAAAE,OAAA,EAAAF,GAAA;AAAA,SAAAG,yBAAAC,CAAA,6BAAAC,OAAA,mBAAAC,CAAA,OAAAD,OAAA,IAAAE,CAAA,OAAAF,OAAA,YAAAF,wBAAA,YAAAA,CAAAC,CAAA,WAAAA,CAAA,GAAAG,CAAA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