@cleartrip/ct-design-calendar 4.0.0 → 5.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (119) hide show
  1. package/dist/Arrow/LeftArrow.d.ts +3 -0
  2. package/dist/Arrow/LeftArrow.d.ts.map +1 -0
  3. package/dist/Arrow/RightArrow.d.ts +3 -0
  4. package/dist/Arrow/RightArrow.d.ts.map +1 -0
  5. package/dist/BaseCalendar.d.ts +4 -0
  6. package/dist/BaseCalendar.d.ts.map +1 -0
  7. package/dist/Calendar.d.ts +4 -0
  8. package/dist/Calendar.d.ts.map +1 -0
  9. package/dist/Calendar.native.d.ts +4 -0
  10. package/dist/Calendar.native.d.ts.map +1 -0
  11. package/dist/CalendarBody/LazyMonthList.d.ts +4 -0
  12. package/dist/CalendarBody/LazyMonthList.d.ts.map +1 -0
  13. package/dist/CalendarBody/PlaceholderMonth.d.ts +5 -0
  14. package/dist/CalendarBody/PlaceholderMonth.d.ts.map +1 -0
  15. package/dist/CalendarBody/index.d.ts +4 -0
  16. package/dist/CalendarBody/index.d.ts.map +1 -0
  17. package/dist/CalendarDayElements/CalendarDate.d.ts +4 -0
  18. package/dist/CalendarDayElements/CalendarDate.d.ts.map +1 -0
  19. package/dist/CalendarDayElements/CalendarDot.d.ts +4 -0
  20. package/dist/CalendarDayElements/CalendarDot.d.ts.map +1 -0
  21. package/dist/CalendarDayElements/CalendarDotWrapper.d.ts +5 -0
  22. package/dist/CalendarDayElements/CalendarDotWrapper.d.ts.map +1 -0
  23. package/dist/CalendarDayElements/CalendarRange.d.ts +4 -0
  24. package/dist/CalendarDayElements/CalendarRange.d.ts.map +1 -0
  25. package/dist/CalendarDayElements/index.d.ts +4 -0
  26. package/dist/CalendarDayElements/index.d.ts.map +1 -0
  27. package/dist/CalendarDayElements/useForceRerender.d.ts +5 -0
  28. package/dist/CalendarDayElements/useForceRerender.d.ts.map +1 -0
  29. package/dist/CalendarMonth/CalendarMonthBody.d.ts +4 -0
  30. package/dist/CalendarMonth/CalendarMonthBody.d.ts.map +1 -0
  31. package/dist/CalendarMonth/CalendarMonthFooter.d.ts +5 -0
  32. package/dist/CalendarMonth/CalendarMonthFooter.d.ts.map +1 -0
  33. package/dist/CalendarMonth/CalendarMonthHeader.d.ts +4 -0
  34. package/dist/CalendarMonth/CalendarMonthHeader.d.ts.map +1 -0
  35. package/dist/CalendarMonth/index.d.ts +12 -0
  36. package/dist/CalendarMonth/index.d.ts.map +1 -0
  37. package/dist/Caption/index.d.ts +4 -0
  38. package/dist/Caption/index.d.ts.map +1 -0
  39. package/dist/DayPicker.d.ts +62 -0
  40. package/dist/DayPicker.d.ts.map +1 -0
  41. package/dist/Footer/CheckinCheckout.d.ts +11 -0
  42. package/dist/Footer/CheckinCheckout.d.ts.map +1 -0
  43. package/dist/Footer/LongWeekend.d.ts +5 -0
  44. package/dist/Footer/LongWeekend.d.ts.map +1 -0
  45. package/dist/Footer/constants.d.ts +7 -0
  46. package/dist/Footer/constants.d.ts.map +1 -0
  47. package/dist/Footer/index.d.ts +14 -0
  48. package/dist/Footer/index.d.ts.map +1 -0
  49. package/dist/WeekDays.d.ts +3 -0
  50. package/dist/WeekDays.d.ts.map +1 -0
  51. package/dist/constants.d.ts +13 -0
  52. package/dist/constants.d.ts.map +1 -0
  53. package/dist/ct-design-calendar.browser.cjs.js +2 -0
  54. package/dist/ct-design-calendar.browser.cjs.js.map +1 -0
  55. package/dist/ct-design-calendar.browser.esm.js +2 -0
  56. package/dist/ct-design-calendar.browser.esm.js.map +1 -0
  57. package/dist/ct-design-calendar.cjs.js +67 -0
  58. package/dist/ct-design-calendar.cjs.js.map +1 -0
  59. package/dist/ct-design-calendar.esm.js +61 -0
  60. package/dist/ct-design-calendar.esm.js.map +1 -0
  61. package/dist/ct-design-calendar.umd.js +70 -0
  62. package/dist/ct-design-calendar.umd.js.map +1 -0
  63. package/dist/event/EventEmitter/index.d.ts +10 -0
  64. package/dist/event/EventEmitter/index.d.ts.map +1 -0
  65. package/dist/event/EventEmitter/type.d.ts +10 -0
  66. package/dist/event/EventEmitter/type.d.ts.map +1 -0
  67. package/dist/event/constants.d.ts +6 -0
  68. package/dist/event/constants.d.ts.map +1 -0
  69. package/dist/event/index.d.ts +8 -0
  70. package/dist/event/index.d.ts.map +1 -0
  71. package/dist/globalStyle.d.ts +2 -0
  72. package/dist/globalStyle.d.ts.map +1 -0
  73. package/dist/index.d.ts +4 -0
  74. package/dist/index.d.ts.map +1 -0
  75. package/dist/style.d.ts +2 -0
  76. package/dist/style.d.ts.map +1 -0
  77. package/dist/styles.d.ts +570 -0
  78. package/dist/styles.d.ts.map +1 -0
  79. package/dist/type.d.ts +58 -0
  80. package/dist/type.d.ts.map +1 -0
  81. package/dist/util.d.ts +22 -0
  82. package/dist/util.d.ts.map +1 -0
  83. package/package.json +32 -5
  84. package/src/Arrow/LeftArrow.tsx +13 -0
  85. package/src/Arrow/RightArrow.tsx +13 -0
  86. package/src/BaseCalendar.tsx +189 -0
  87. package/src/Calendar.native.tsx +99 -0
  88. package/src/Calendar.tsx +13 -0
  89. package/src/CalendarBody/LazyMonthList.tsx +45 -0
  90. package/src/CalendarBody/PlaceholderMonth.tsx +20 -0
  91. package/src/CalendarBody/index.tsx +159 -0
  92. package/src/CalendarDayElements/CalendarDate.tsx +34 -0
  93. package/src/CalendarDayElements/CalendarDot.tsx +11 -0
  94. package/src/CalendarDayElements/CalendarDotWrapper.tsx +17 -0
  95. package/src/CalendarDayElements/CalendarRange.tsx +54 -0
  96. package/src/CalendarDayElements/index.tsx +77 -0
  97. package/src/CalendarDayElements/useForceRerender.ts +14 -0
  98. package/src/CalendarMonth/CalendarMonthBody.tsx +39 -0
  99. package/src/CalendarMonth/CalendarMonthFooter.tsx +70 -0
  100. package/src/CalendarMonth/CalendarMonthHeader.tsx +15 -0
  101. package/src/CalendarMonth/index.tsx +43 -0
  102. package/src/Caption/index.tsx +39 -0
  103. package/src/DayPicker.tsx +324 -0
  104. package/src/Footer/CheckinCheckout.tsx +196 -0
  105. package/src/Footer/LongWeekend.tsx +98 -0
  106. package/src/Footer/constants.ts +7 -0
  107. package/src/Footer/index.tsx +84 -0
  108. package/src/WeekDays.tsx +20 -0
  109. package/src/constants.ts +54 -0
  110. package/src/event/EventEmitter/index.ts +34 -0
  111. package/src/event/EventEmitter/type.ts +10 -0
  112. package/src/event/constants.ts +5 -0
  113. package/src/event/index.tsx +21 -0
  114. package/src/globalStyle.ts +351 -0
  115. package/src/index.ts +3 -0
  116. package/src/style.ts +333 -0
  117. package/src/styles.ts +167 -0
  118. package/src/type.ts +66 -0
  119. package/src/util.ts +114 -0
package/src/style.ts ADDED
@@ -0,0 +1,333 @@
1
+ import { css } from '@emotion/react';
2
+
3
+ export const rdpStyles = css`
4
+ .rdp {
5
+ --rdp-cell-height: 30px;
6
+ --rdp-cell-width: 54px;
7
+ --rdp-day-size: 30px;
8
+ --rdp-day-height-custom: 30px;
9
+ --rdp-day-width-custom: 30px;
10
+ --rdp-caption-font-size: 16px;
11
+ --rdp-accent-color: #1a1a1a;
12
+ --rdp-selected-range-color: #d7d7d7;
13
+ --rdp-background-color: #e7edff;
14
+ --rdp-outline: 1.5px solid var(--rdp-accent-color);
15
+ --rdp-outline-selected: 3px solid var(--rdp-accent-color);
16
+ }
17
+
18
+ /* Hide elements for devices that are not screen readers */
19
+ .rdp-vhidden {
20
+ box-sizing: border-box;
21
+ padding: 0;
22
+ margin: 0;
23
+ background: transparent;
24
+ border: 0;
25
+ -moz-appearance: none;
26
+ -webkit-appearance: none;
27
+ appearance: none;
28
+ position: absolute !important;
29
+ top: 0;
30
+ width: 1px !important;
31
+ height: 1px !important;
32
+ padding: 0 !important;
33
+ overflow: hidden !important;
34
+ clip: rect(1px, 1px, 1px, 1px) !important;
35
+ border: 0 !important;
36
+ }
37
+
38
+ /* Buttons */
39
+ .rdp-button_reset {
40
+ appearance: none;
41
+ position: relative;
42
+ margin: 0;
43
+ padding: 0;
44
+ cursor: default;
45
+ color: inherit;
46
+ background: none;
47
+ font: inherit;
48
+ -moz-appearance: none;
49
+ -webkit-appearance: none;
50
+ }
51
+
52
+ .rdp-button_reset:focus-visible {
53
+ outline: none;
54
+ }
55
+
56
+ .rdp-button {
57
+ border: 1.5px solid transparent;
58
+ }
59
+
60
+ .rdp-button[disabled]:not(.rdp-day_selected) {
61
+ opacity: 0.25;
62
+ }
63
+
64
+ .rdp-button:not([disabled]) {
65
+ cursor: pointer;
66
+ }
67
+
68
+ .rdp-button:focus-visible:not([disabled]) {
69
+ color: inherit;
70
+ background-color: var(--rdp-background-color);
71
+ }
72
+
73
+ .rdp-months {
74
+ display: flex;
75
+ flex-wrap: wrap;
76
+ }
77
+
78
+ .rdp-month {
79
+ margin: unset !important;
80
+ }
81
+
82
+ .rdp-month:first-child {
83
+ margin-left: 12px;
84
+ }
85
+
86
+ .rdp-month:last-child {
87
+ margin-right: 12px;
88
+ }
89
+
90
+ .rdp-table {
91
+ margin: 0;
92
+ max-width: calc(var(--rdp-cell-width) * 7);
93
+ border-spacing: 0 10px;
94
+ }
95
+
96
+ .rdp-with_weeknumber .rdp-table {
97
+ max-width: calc(var(--rdp-cell-width) * 8);
98
+ border-collapse: collapse;
99
+ }
100
+
101
+ .rdp-caption {
102
+ display: flex;
103
+ align-items: center;
104
+ justify-content: space-between;
105
+ padding: 0;
106
+ text-align: left;
107
+ }
108
+
109
+ .rdp-multiple_months .rdp-caption {
110
+ position: relative;
111
+ display: block;
112
+ text-align: center;
113
+ }
114
+
115
+ .rdp-caption_dropdowns {
116
+ position: relative;
117
+ display: inline-flex;
118
+ }
119
+
120
+ .rdp-caption_label {
121
+ position: relative;
122
+ z-index: 1;
123
+ display: inline-flex;
124
+ align-items: center;
125
+ margin: 0;
126
+ padding: 0 0.25em;
127
+ white-space: nowrap;
128
+ color: currentColor;
129
+ border: 0;
130
+ border: 1.5px solid transparent;
131
+ font-family: inherit;
132
+ font-size: var(--rdp-caption-font-size);
133
+ font-weight: bold;
134
+ }
135
+
136
+ .rdp-nav {
137
+ white-space: nowrap;
138
+ }
139
+
140
+ .rdp-multiple_months .rdp-caption_start .rdp-nav {
141
+ position: absolute;
142
+ top: 50%;
143
+ left: 0;
144
+ transform: translateY(-50%);
145
+ }
146
+
147
+ .rdp-multiple_months .rdp-caption_end .rdp-nav {
148
+ position: absolute;
149
+ top: 50%;
150
+ right: 0;
151
+ transform: translateY(-50%);
152
+ }
153
+
154
+ .rdp-nav_button {
155
+ display: inline-flex;
156
+ align-items: center;
157
+ justify-content: center;
158
+ width: var(--rdp-cell-width);
159
+ height: var(--rdp-cell-height);
160
+ padding: 0.25em;
161
+ border-radius: 100%;
162
+ }
163
+
164
+ /* Dropdowns */
165
+ .rdp-dropdown_year,
166
+ .rdp-dropdown_month {
167
+ position: relative;
168
+ display: inline-flex;
169
+ align-items: center;
170
+ }
171
+
172
+ .rdp-dropdown {
173
+ appearance: none;
174
+ position: absolute;
175
+ z-index: 2;
176
+ top: 0;
177
+ bottom: 0;
178
+ left: 0;
179
+ width: 100%;
180
+ margin: 0;
181
+ padding: 0;
182
+ cursor: inherit;
183
+ opacity: 0;
184
+ border: none;
185
+ background-color: transparent;
186
+ font-family: inherit;
187
+ font-size: inherit;
188
+ line-height: inherit;
189
+ }
190
+
191
+ .rdp-dropdown[disabled] {
192
+ opacity: unset;
193
+ color: unset;
194
+ }
195
+
196
+ .rdp-dropdown:focus-visible:not([disabled]) + .rdp-caption_label {
197
+ background-color: var(--rdp-background-color);
198
+ border-radius: 6px;
199
+ }
200
+
201
+ .rdp-dropdown_icon {
202
+ margin: 0 0 0 5px;
203
+ }
204
+
205
+ .rdp-head {
206
+ border: 0;
207
+ }
208
+
209
+ .rdp-head_row,
210
+ .rdp-row {
211
+ height: 100%;
212
+ }
213
+
214
+ .rdp-head_cell {
215
+ vertical-align: middle;
216
+ font-size: 0.75em;
217
+ font-weight: 700;
218
+ text-align: center;
219
+ height: 100%;
220
+ height: var(--rdp-cell-height);
221
+ padding: 0;
222
+ text-transform: uppercase;
223
+ }
224
+
225
+ .rdp-tbody {
226
+ border: 0;
227
+ }
228
+
229
+ .rdp-tfoot {
230
+ margin: 0.5em;
231
+ }
232
+
233
+ .rdp-cell {
234
+ width: var(--rdp-cell-width);
235
+ height: var(--rdp-day-height-custom);
236
+ padding: 10;
237
+ text-align: center;
238
+ }
239
+
240
+ .rdp-weeknumber {
241
+ font-size: 0.75em;
242
+ }
243
+
244
+ .rdp-weeknumber,
245
+ .rdp-day {
246
+ display: flex;
247
+ overflow: hidden;
248
+ align-items: center;
249
+ justify-content: center;
250
+ box-sizing: border-box;
251
+ width: var(--rdp-day-width-custom);
252
+ height: var(--rdp-day-height-custom);
253
+ max-width: var(--rdp-day-size);
254
+ line-height: 20px;
255
+ color: #212121;
256
+ margin: auto;
257
+ border: 1.5px solid transparent;
258
+ border-radius: var(--rdp-day-borderRadius-custom);
259
+ font-size: 16px;
260
+ z-index: 100;
261
+ }
262
+
263
+ .rdp-day_selected,
264
+ .rdp-day_selected:focus-visible {
265
+ color: white;
266
+ opacity: 1;
267
+ background-color: var(--rdp-accent-color);
268
+ }
269
+
270
+ .rdp-day_outside {
271
+ opacity: 0.5;
272
+ }
273
+
274
+ .rdp-day_selected:focus-visible {
275
+ outline-offset: 1.5px;
276
+ z-index: 1;
277
+ }
278
+
279
+ .rdp-cell:has(.rdp-day_range_start) {
280
+ background-color: var(--rdp-selected-range-color);
281
+ border-top-left-radius: 50%;
282
+ border-bottom-left-radius: 50%;
283
+ position: relative;
284
+ }
285
+
286
+ .rdp-cell:has(.rdp-day_range_end)::after {
287
+ background-color: white;
288
+ content: '';
289
+ position: absolute;
290
+ width: 50%;
291
+ height: 100%;
292
+ top: 0;
293
+ left: 0;
294
+ transform: translate(100%, 0px);
295
+ }
296
+
297
+ .rdp-cell:has(.rdp-day_range_start)::before {
298
+ background-color: white;
299
+ content: '';
300
+ position: absolute;
301
+ width: 50%;
302
+ height: 100%;
303
+ top: 0;
304
+ left: 0;
305
+ }
306
+
307
+ .rdp-cell:has(.rdp-day_range_end) {
308
+ background-color: var(--rdp-selected-range-color);
309
+ border-top-right-radius: 50%;
310
+ border-bottom-right-radius: 50%;
311
+ position: relative;
312
+ }
313
+
314
+ .rdp-day_range_end.rdp-day_range_start {
315
+ border-radius: var(--rdp-day-borderRadius-custom);
316
+ padding: 4px;
317
+ }
318
+
319
+ .rdp-cell:has(.rdp-day_range_middle) {
320
+ background-color: var(--rdp-selected-range-color);
321
+ }
322
+
323
+ .rdp-day_range_middle {
324
+ border-radius: 0;
325
+ color: var(--rdp-accent-color);
326
+ background-color: var(--rdp-selected-range-color);
327
+ padding: 4px;
328
+ }
329
+
330
+ .weekendColor {
331
+ color: #ff0000;
332
+ }
333
+ `;
package/src/styles.ts ADDED
@@ -0,0 +1,167 @@
1
+ import { makeStyles } from '@cleartrip/ct-design-style-manager';
2
+ import { Theme } from '@cleartrip/ct-design-theme';
3
+ import { getTypographyVariant, TypographyVariant } from '@cleartrip/ct-design-typography';
4
+
5
+ export const staticDayNameStyles = makeStyles((theme) => {
6
+ return {
7
+ root: {
8
+ flexDirection: 'row',
9
+ justifyContent: 'space-between',
10
+ paddingVertical: theme.spacing[3],
11
+ paddingHorizontal: theme.spacing[4],
12
+ borderBottomWidth: theme.border.width.sm,
13
+ borderBottomColor: theme.color.border.disabledDark,
14
+ },
15
+ weekDay: {
16
+ color: theme?.color?.text?.subHeading,
17
+ ...getTypographyVariant(theme, TypographyVariant.P3),
18
+ },
19
+ weekEnd: {
20
+ color: theme?.color?.text?.warning,
21
+ ...getTypographyVariant(theme, TypographyVariant.P3),
22
+ },
23
+ };
24
+ });
25
+
26
+ export const staticCalendarMonthHeaderStyles = makeStyles((theme) => {
27
+ return {
28
+ root: {
29
+ textAlign: 'center',
30
+ paddingTop: theme.spacing[6],
31
+ paddingBottom: theme.spacing[4],
32
+ color: theme?.color?.text?.heading,
33
+ ...getTypographyVariant(theme, TypographyVariant.B1),
34
+ },
35
+ };
36
+ });
37
+
38
+ export const staticCalendarMonthFooterStyles = makeStyles((theme) => {
39
+ return {
40
+ root: {
41
+ paddingHorizontal: theme.spacing[5],
42
+ paddingVertical: theme.spacing[2],
43
+ },
44
+ headingContainer: {
45
+ flexDirection: 'row',
46
+ gap: theme.spacing[2],
47
+ alignItems: 'center',
48
+ },
49
+ heading: {
50
+ color: theme?.color?.text?.heading,
51
+ // ...getTypographyVariant(theme, TypographyVariant.B3),
52
+ },
53
+ listContainer: {
54
+ marginTop: theme.spacing[2],
55
+ },
56
+ listItem: {
57
+ color: theme?.color?.text?.heading,
58
+ //...getTypographyVariant(theme, TypographyVariant.P3),
59
+ },
60
+ };
61
+ });
62
+
63
+ export const staticCalendarDotStyle = makeStyles((theme) => {
64
+ return {
65
+ root: {
66
+ width: theme.spacing[1.5],
67
+ height: theme.spacing[1.5],
68
+ borderRadius: theme.border.radius['50P'],
69
+ backgroundColor: theme.color.background.warning,
70
+ },
71
+ wrapper: {
72
+ position: 'absolute',
73
+ right: theme.spacing[1],
74
+ top: theme.spacing[1],
75
+ },
76
+ };
77
+ });
78
+
79
+ export const staticCalendarDateStyle = makeStyles((theme) => {
80
+ return {
81
+ root: {
82
+ position: 'relative',
83
+ alignItems: 'center',
84
+ justifyContent: 'center',
85
+ width: theme.spacing[10],
86
+ height: theme.spacing[10],
87
+ borderRadius: 50,
88
+ },
89
+ };
90
+ });
91
+
92
+ export const getSelectedDateRootStyles = (theme: Theme, isSelected: boolean) => {
93
+ if (isSelected)
94
+ return {
95
+ backgroundColor: theme.color.background.defaultDarkest,
96
+ };
97
+ return {
98
+ backgroundColor: theme.color.background.transparent,
99
+ };
100
+ };
101
+
102
+ export const staticCalendarRangeStyles = makeStyles((theme) => {
103
+ return {
104
+ root: {
105
+ flexDirection: 'row',
106
+ position: 'absolute',
107
+ height: theme?.size['100P'],
108
+ },
109
+ fullGrayed: {
110
+ backgroundColor: theme.color.background.disabled,
111
+ width: theme?.size['100P'],
112
+ height: theme?.size['100P'],
113
+ },
114
+ halfNeutral: {
115
+ backgroundColor: theme.color.background.neutral,
116
+ width: theme?.size['50P'],
117
+ height: theme?.size['100P'],
118
+ },
119
+ halfGrayed: {
120
+ backgroundColor: theme.color.background.disabled,
121
+ width: theme?.size['50P'],
122
+ height: theme?.size['100P'],
123
+ },
124
+ };
125
+ });
126
+
127
+ export const staticCalendarDateWrapperStyles = makeStyles((theme) => {
128
+ return {
129
+ root: {
130
+ width: `${100 / 7}%`,
131
+ alignItems: 'center',
132
+ justifyContent: 'center',
133
+ paddingVertical: theme.spacing['1.5'],
134
+ },
135
+ };
136
+ });
137
+
138
+ export const getSelectedDateStyles = (theme: Theme, isSelected: boolean) => {
139
+ if (isSelected)
140
+ return {
141
+ opacity: 0.2,
142
+ pointerEvents: 'none',
143
+ };
144
+ return {
145
+ opacity: 1,
146
+ };
147
+ };
148
+
149
+ export const staticCalendarMonthBodyStyles = makeStyles(() => {
150
+ return {
151
+ root: {
152
+ flexDirection: 'row',
153
+ },
154
+ };
155
+ });
156
+
157
+ export const staticCalendarBodyStyle = makeStyles((theme) => {
158
+ return {
159
+ placeholderMonthContainer: {
160
+ width: theme?.size['100P'],
161
+ backgroundColor: theme.color.background.neutral,
162
+ },
163
+ spacer: {
164
+ height: 100,
165
+ },
166
+ };
167
+ });
package/src/type.ts ADDED
@@ -0,0 +1,66 @@
1
+ import { MutableRefObject } from 'react';
2
+
3
+ export interface IMonthListObj {
4
+ month: string;
5
+ year: string;
6
+ }
7
+
8
+ export interface HandleCalendarDateClickedParams {
9
+ checkInDate?: Date;
10
+ checkOutDate?: Date;
11
+ stateDateType?: 'checkIn' | 'checkOut';
12
+ }
13
+
14
+ export interface ICalendarProps {
15
+ selectedDates: string[];
16
+ handleCalendarDateClicked: (params: HandleCalendarDateClickedParams) => void;
17
+ calendarDotsList: string[];
18
+ holidayList: Record<string, Record<string, string[]>>;
19
+ }
20
+
21
+ export interface ICalendarMonthBodyProps {
22
+ month: string;
23
+ year: string;
24
+ calendarDotsList: string[];
25
+ getSelectedDates: () => string[];
26
+ handleDateClicked: (date: string) => void;
27
+ }
28
+
29
+ export interface ICalendarDateProp {
30
+ day: string;
31
+ date: string;
32
+ isSelected: boolean;
33
+ calendarDotsList: string[];
34
+ }
35
+
36
+ export interface ICalendarRangeProps {
37
+ getSelectedDates: () => string[];
38
+ date: string;
39
+ }
40
+
41
+ export interface ICalendarDateWrapperProps {
42
+ year: string;
43
+ month: string;
44
+ day: string;
45
+ idxx: number;
46
+ getSelectedDates: () => string[];
47
+ handleDateClicked: (date: string) => void;
48
+ calendarDotsList: string[];
49
+ }
50
+
51
+ export interface ILazyMonthListProps {
52
+ show: boolean;
53
+ monthList: IMonthListObj[];
54
+ getSelectedDates: () => string[];
55
+ handleDateClicked: (date: string) => void;
56
+ calendarDotsList: string[];
57
+ holidayList: Record<string, Record<string, string[]>>;
58
+ monthHeightRef: MutableRefObject<Record<string, number>>;
59
+ }
60
+
61
+ export interface ICalendarBodyProps {
62
+ getSelectedDates: () => string[];
63
+ handleDateClicked: (date: string) => void;
64
+ calendarDotsList: string[];
65
+ holidayList: Record<string, Record<string, string[]>>;
66
+ }
package/src/util.ts ADDED
@@ -0,0 +1,114 @@
1
+ export const PAST_DATE = '2000-01-01';
2
+
3
+ export const DAY_MILLISECONDS = 1000 * 60 * 60 * 24;
4
+
5
+ export const TODAY_DATE = new Date().toLocaleDateString('en-CA').replace(/-/g, '/');
6
+
7
+ export const MONTHS = [
8
+ 'January',
9
+ 'February',
10
+ 'March',
11
+ 'April',
12
+ 'May',
13
+ 'June',
14
+ 'July',
15
+ 'August',
16
+ 'September',
17
+ 'October',
18
+ 'November',
19
+ 'December',
20
+ ];
21
+
22
+ export const ELEMENTS_HEIGHT = {
23
+ HEADING: 64,
24
+ DATE: 52,
25
+ FOOTER: 40,
26
+ HOLIDAY: 20,
27
+ };
28
+
29
+ export const DAY_LIST = [
30
+ {
31
+ day: 'Mon',
32
+ isWeekend: false,
33
+ },
34
+ {
35
+ day: 'Tue',
36
+ isWeekend: false,
37
+ },
38
+ {
39
+ day: 'Wed',
40
+ isWeekend: false,
41
+ },
42
+ {
43
+ day: 'Thu',
44
+ isWeekend: false,
45
+ },
46
+ {
47
+ day: 'Fri',
48
+ isWeekend: false,
49
+ },
50
+ {
51
+ day: 'Sat',
52
+ isWeekend: true,
53
+ },
54
+ {
55
+ day: 'Sun',
56
+ isWeekend: true,
57
+ },
58
+ ];
59
+
60
+ export const formattedDate = (year: string, month: string, day: string) => {
61
+ if (!day) return '';
62
+ const formattedMonth = month.toString().padStart(2, '0');
63
+ const formattedDay = day.toString().padStart(2, '0');
64
+ return `${year}/${formattedMonth}/${formattedDay}`;
65
+ };
66
+
67
+ export const getWeekRow = (year: number, month: number) => {
68
+ let startDayOfWeek = (new Date(year + '-' + month + '-01').getDay() - 1 + 7) % 7;
69
+ const daysInMonth = new Date(year, month, 0).getDate();
70
+
71
+ if (startDayOfWeek === -1) startDayOfWeek = 6;
72
+
73
+ const rows: number[][] = [];
74
+ let currentDay = 1;
75
+ let currRow: number[] = [];
76
+
77
+ currRow = [...(Array(startDayOfWeek).fill(null) as number[])];
78
+
79
+ while (currentDay <= daysInMonth) {
80
+ while (currentDay <= daysInMonth && currRow.length < 7) {
81
+ currRow.push(currentDay);
82
+ currentDay++;
83
+ }
84
+ if (currRow.length !== 7) {
85
+ currRow = [...currRow, ...(Array(7 - currRow.length).fill(null) as number[])];
86
+ }
87
+ rows.push(currRow);
88
+ currRow = [];
89
+ }
90
+ return rows;
91
+ };
92
+
93
+ export const getMonthArray = (startMonth: number, startYear: number) => {
94
+ const months: { month: string; year: string }[] = [];
95
+ let month = startMonth;
96
+ let year = startYear;
97
+
98
+ for (let i = 0; i < 12; i++) {
99
+ months.push({ month: month.toString().padStart(2, '0'), year: year.toString() });
100
+ month += 1;
101
+ if (month > 12) {
102
+ month = 1;
103
+ year += 1;
104
+ }
105
+ }
106
+
107
+ return months;
108
+ };
109
+ export const getDateDifference = (date1: string, date2: string) => {
110
+ const diffInMillis: number =
111
+ new Date(date1.replace(/\//g, '-')).getTime() - new Date(date2.replace(/\//g, '-')).getTime();
112
+ const diffInDays = diffInMillis / DAY_MILLISECONDS;
113
+ return diffInDays;
114
+ };