@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
@@ -0,0 +1,20 @@
1
+ import { memo } from 'react';
2
+
3
+ import { Text, View } from 'react-native';
4
+
5
+ import { staticDayNameStyles } from './styles';
6
+ import { DAY_LIST } from './util';
7
+
8
+ const WeekDays = () => {
9
+ return (
10
+ <View style={staticDayNameStyles?.root}>
11
+ {DAY_LIST?.map(({ day, isWeekend }, index) => (
12
+ <Text key={index} style={isWeekend ? staticDayNameStyles?.weekEnd : staticDayNameStyles?.weekDay}>
13
+ {day}
14
+ </Text>
15
+ ))}
16
+ </View>
17
+ );
18
+ };
19
+
20
+ export default memo(WeekDays);
@@ -0,0 +1,54 @@
1
+ export const PAST_DATE = '2000-01-01';
2
+
3
+ export const MONTHS = [
4
+ 'January',
5
+ 'February',
6
+ 'March',
7
+ 'April',
8
+ 'May',
9
+ 'June',
10
+ 'July',
11
+ 'August',
12
+ 'September',
13
+ 'October',
14
+ 'November',
15
+ 'December',
16
+ ];
17
+
18
+ export const ELEMENTS_HEIGHT = {
19
+ HEADING: 64,
20
+ DATE: 52,
21
+ FOOTER: 40,
22
+ HOLIDAY: 20,
23
+ };
24
+
25
+ export const DAY_LIST = [
26
+ {
27
+ day: 'Mon',
28
+ isWeekend: false,
29
+ },
30
+ {
31
+ day: 'Tue',
32
+ isWeekend: false,
33
+ },
34
+ {
35
+ day: 'Wed',
36
+ isWeekend: false,
37
+ },
38
+ {
39
+ day: 'Thu',
40
+ isWeekend: false,
41
+ },
42
+ {
43
+ day: 'Fri',
44
+ isWeekend: false,
45
+ },
46
+ {
47
+ day: 'Sat',
48
+ isWeekend: true,
49
+ },
50
+ {
51
+ day: 'Sun',
52
+ isWeekend: true,
53
+ },
54
+ ];
@@ -0,0 +1,34 @@
1
+ import { ICustomEventEmitter, ICustomEventListener } from './type';
2
+ class CustomEventEmitter implements ICustomEventEmitter {
3
+ private events: Record<string, ICustomEventListener<unknown>[]> = {};
4
+
5
+ on<T>(eventName: string, callback: ICustomEventListener<T>) {
6
+ this.events[eventName] = this.events[eventName] || [];
7
+ this.events[eventName].push(callback as ICustomEventListener<unknown>);
8
+
9
+ return () => this.off(eventName, callback);
10
+ }
11
+
12
+ emit<T>(eventName: string, data: T): void {
13
+ if (this.events[eventName]) {
14
+ this.events[eventName].slice().forEach((callback) => callback(data)); // Avoid modifying original array during iteration
15
+ }
16
+ }
17
+
18
+ off<T>(eventName: string, callback: ICustomEventListener<T>): void {
19
+ if (!this.events[eventName]) {
20
+ return;
21
+ }
22
+ this.events[eventName] = this.events[eventName].filter((cb) => cb !== callback);
23
+ }
24
+
25
+ once<T>(eventName: string, callback: ICustomEventListener<T>): void {
26
+ const wrappedCallback = (data: T) => {
27
+ callback(data);
28
+ this.off(eventName, wrappedCallback);
29
+ };
30
+ this.on(eventName, wrappedCallback);
31
+ }
32
+ }
33
+
34
+ export default CustomEventEmitter;
@@ -0,0 +1,10 @@
1
+ export interface ICustomEventListener<T> {
2
+ (data: T): void;
3
+ }
4
+
5
+ export interface ICustomEventEmitter {
6
+ on<T>(eventName: string, callback: ICustomEventListener<T>): void;
7
+ emit<T>(eventName: string, data: T): void;
8
+ off<T>(eventName: string, callback: ICustomEventListener<T>): void;
9
+ once<T>(eventName: string, callback: ICustomEventListener<T>): void;
10
+ }
@@ -0,0 +1,5 @@
1
+ export const PUB_SUB_IDS = {
2
+ FLAT_LIST_VIEWABLE_ITEM_CHANGED: 'FLAT_LIST/VIEWABLE_ITEM_CHANGED',
3
+ FLASH_LIST_VISIBLE_ITEMS: 'FLASH_LIST_VISIBLE_ITEMS',
4
+ MARKER_CLICKED: 'MARKER_CLICKED',
5
+ };
@@ -0,0 +1,21 @@
1
+ import { useCallback, useEffect } from 'react';
2
+
3
+ import CustomEventEmitter from './EventEmitter';
4
+ import { ICustomEventListener } from './EventEmitter/type';
5
+
6
+ export const eventEmitter = new CustomEventEmitter(); // Create a single instance
7
+
8
+ export function usePubEvent<T>(eventName: string): (data?: T) => void {
9
+ const publishEvent = useCallback((data?: T) => eventEmitter.emit(eventName, data), [eventName]);
10
+
11
+ return publishEvent;
12
+ }
13
+
14
+ export function useSubEvent<T>(eventName: string, callback: ICustomEventListener<T>, options: { once?: boolean } = {}) {
15
+ const { once = false } = options; // Allow specifying "once" behavior in options
16
+
17
+ useEffect(() => {
18
+ const listener = once ? eventEmitter.once(eventName, callback) : eventEmitter.on(eventName, callback);
19
+ return listener; // Cleanup on unmount
20
+ }, [eventName, callback, once]);
21
+ }
@@ -0,0 +1,351 @@
1
+ import { injectGlobal } from '@emotion/css';
2
+
3
+ // eslint-disable-next-line @typescript-eslint/no-unused-expressions
4
+ injectGlobal`
5
+ .rdp {
6
+ --rdp-cell-height: 30px;
7
+ --rdp-cell-width: 54px;
8
+ --rdp-day-size: 30px;
9
+ --rdp-day-height-custom: 30px;
10
+ --rdp-day-width-custom: 30px;
11
+ --rdp-caption-font-size: 16px;
12
+ --rdp-accent-color: #1a1a1a;
13
+ --rdp-selected-range-color: #d7d7d7;
14
+ --rdp-background-color: #e7edff;
15
+ --rdp-outline: 1.5px solid var(--rdp-accent-color); /* Outline border for focused elements */
16
+ --rdp-outline-selected: 3px solid var(--rdp-accent-color); /* Outline border for focused _and_ selected elements */
17
+ }
18
+
19
+ /* Hide elements for devices that are not screen readers */
20
+ .rdp-vhidden {
21
+ box-sizing: border-box;
22
+ padding: 0;
23
+ margin: 0;
24
+ background: transparent;
25
+ border: 0;
26
+ -moz-appearance: none;
27
+ -webkit-appearance: none;
28
+ appearance: none;
29
+ position: absolute !important;
30
+ top: 0;
31
+ width: 1px !important;
32
+ height: 1px !important;
33
+ padding: 0 !important;
34
+ overflow: hidden !important;
35
+ clip: rect(1px, 1px, 1px, 1px) !important;
36
+ border: 0 !important;
37
+ }
38
+
39
+ /* Buttons */
40
+ .rdp-button_reset {
41
+ appearance: none;
42
+ position: relative;
43
+ margin: 0;
44
+ padding: 0;
45
+ cursor: default;
46
+ color: inherit;
47
+ background: none;
48
+ font: inherit;
49
+
50
+ -moz-appearance: none;
51
+ -webkit-appearance: none;
52
+ }
53
+
54
+ .rdp-button_reset:focus-visible {
55
+ /* Make sure to reset outline only when :focus-visible is supported */
56
+ outline: none;
57
+ }
58
+
59
+ .rdp-button {
60
+ border: 1.5px solid transparent;
61
+ }
62
+
63
+ .rdp-button[disabled]:not(.rdp-day_selected) {
64
+ opacity: 0.25;
65
+ }
66
+
67
+ .rdp-button:not([disabled]) {
68
+ cursor: pointer;
69
+ }
70
+
71
+ .rdp-button:focus-visible:not([disabled]) {
72
+ color: inherit;
73
+ background-color: var(--rdp-background-color);
74
+ // border: var(--rdp-outline);
75
+ }
76
+
77
+ .rdp-button:hover:not([disabled]):not(.rdp-day_selected) {
78
+ // border: var(--rdp-outline);
79
+ }
80
+
81
+ .rdp-months {
82
+ display: flex;
83
+ flex-wrap: wrap;
84
+ }
85
+
86
+ .rdp-month {
87
+ margin: unset !important;
88
+ // margin: 0 1em;
89
+ }
90
+
91
+ .rdp-month:first-child {
92
+ margin-left: 12px;
93
+ }
94
+
95
+ .rdp-month:last-child {
96
+ margin-right: 12px;
97
+ }
98
+
99
+ .rdp-table {
100
+ margin: 0;
101
+ max-width: calc(var(--rdp-cell-width) * 7);
102
+ border-spacing: 0 10px;
103
+ }
104
+
105
+ .rdp-with_weeknumber .rdp-table {
106
+ max-width: calc(var(--rdp-cell-width) * 8);
107
+ border-collapse: collapse;
108
+ }
109
+
110
+ .rdp-caption {
111
+ display: flex;
112
+ align-items: center;
113
+ justify-content: space-between;
114
+ padding: 0;
115
+ text-align: left;
116
+ }
117
+
118
+ .rdp-multiple_months .rdp-caption {
119
+ position: relative;
120
+ display: block;
121
+ text-align: center;
122
+ }
123
+
124
+ .rdp-caption_dropdowns {
125
+ position: relative;
126
+ display: inline-flex;
127
+ }
128
+
129
+ .rdp-caption_label {
130
+ position: relative;
131
+ z-index: 1;
132
+ display: inline-flex;
133
+ align-items: center;
134
+ margin: 0;
135
+ padding: 0 0.25em;
136
+ white-space: nowrap;
137
+ color: currentColor;
138
+ border: 0;
139
+ border: 1.5px solid transparent;
140
+ font-family: inherit;
141
+ font-size: var(--rdp-caption-font-size);
142
+ font-weight: bold;
143
+ }
144
+
145
+ .rdp-nav {
146
+ white-space: nowrap;
147
+ }
148
+
149
+ .rdp-multiple_months .rdp-caption_start .rdp-nav {
150
+ position: absolute;
151
+ top: 50%;
152
+ left: 0;
153
+ transform: translateY(-50%);
154
+ }
155
+
156
+ .rdp-multiple_months .rdp-caption_end .rdp-nav {
157
+ position: absolute;
158
+ top: 50%;
159
+ right: 0;
160
+ transform: translateY(-50%);
161
+ }
162
+
163
+ .rdp-nav_button {
164
+ display: inline-flex;
165
+ align-items: center;
166
+ justify-content: center;
167
+ width: var(--rdp-cell-width);
168
+ height: var(--rdp-cell-height);
169
+ padding: 0.25em;
170
+ border-radius: 100%;
171
+ }
172
+
173
+ /* ---------- */
174
+ /* Dropdowns */
175
+ /* ---------- */
176
+
177
+ .rdp-dropdown_year,
178
+ .rdp-dropdown_month {
179
+ position: relative;
180
+ display: inline-flex;
181
+ align-items: center;
182
+ }
183
+
184
+ .rdp-dropdown {
185
+ appearance: none;
186
+ position: absolute;
187
+ z-index: 2;
188
+ top: 0;
189
+ bottom: 0;
190
+ left: 0;
191
+ width: 100%;
192
+ margin: 0;
193
+ padding: 0;
194
+ cursor: inherit;
195
+ opacity: 0;
196
+ border: none;
197
+ background-color: transparent;
198
+ font-family: inherit;
199
+ font-size: inherit;
200
+ line-height: inherit;
201
+ }
202
+
203
+ .rdp-dropdown[disabled] {
204
+ opacity: unset;
205
+ color: unset;
206
+ }
207
+
208
+ .rdp-dropdown:focus-visible:not([disabled]) + .rdp-caption_label {
209
+ background-color: var(--rdp-background-color);
210
+ // border: var(--rdp-outline);
211
+ border-radius: 6px;
212
+ }
213
+
214
+ .rdp-dropdown_icon {
215
+ margin: 0 0 0 5px;
216
+ }
217
+
218
+ .rdp-head {
219
+ border: 0;
220
+ }
221
+
222
+ .rdp-head_row,
223
+ .rdp-row {
224
+ height: 100%;
225
+ }
226
+
227
+ .rdp-head_cell {
228
+ vertical-align: middle;
229
+ font-size: 0.75em;
230
+ font-weight: 700;
231
+ text-align: center;
232
+ height: 100%;
233
+ height: var(--rdp-cell-height);
234
+ padding: 0;
235
+ text-transform: uppercase;
236
+ }
237
+
238
+ .rdp-tbody {
239
+ border: 0;
240
+ }
241
+
242
+ .rdp-tfoot {
243
+ margin: 0.5em;
244
+ }
245
+
246
+ .rdp-cell {
247
+ width: var(--rdp-cell-width);
248
+ // height: 100%;
249
+ // height: var(--rdp-cell-height);
250
+ height: var(--rdp-day-height-custom);
251
+ padding: 10;
252
+ text-align: center;
253
+ }
254
+
255
+ .rdp-weeknumber {
256
+ font-size: 0.75em;
257
+ }
258
+
259
+ .rdp-weeknumber,
260
+ .rdp-day {
261
+ display: flex;
262
+ overflow: hidden;
263
+ align-items: center;
264
+ justify-content: center;
265
+ box-sizing: border-box;
266
+ width: var(--rdp-day-width-custom);
267
+ height: var(--rdp-day-height-custom);
268
+ max-width: var(--rdp-day-size);
269
+ line-height: 20px;
270
+ color: #212121;
271
+ margin: auto;
272
+ border: 1.5px solid transparent;
273
+ border-radius: var(--rdp-day-borderRadius-custom);
274
+ font-size: 16px;
275
+ z-index: 100; // just needs to be > than ::after's z-index
276
+ }
277
+
278
+ .rdp-day_selected,
279
+ .rdp-day_selected:focus-visible {
280
+ color: white;
281
+ opacity: 1;
282
+ background-color: var(--rdp-accent-color);
283
+ }
284
+
285
+ .rdp-day_outside {
286
+ opacity: 0.5;
287
+ }
288
+
289
+ .rdp-day_selected:focus-visible {
290
+ /* Since the background is the same use again the outline */
291
+ // outline: var(--rdp-outline);
292
+ outline-offset: 1.5px;
293
+ z-index: 1;
294
+ }
295
+
296
+ .rdp-cell:has(.rdp-day_range_start) {
297
+ background-color: var(--rdp-selected-range-color);
298
+ border-top-left-radius: 50%;
299
+ border-bottom-left-radius: 50%;
300
+ position: relative;
301
+ }
302
+
303
+ .rdp-cell:has(.rdp-day_range_end)::after {
304
+ background-color: white;
305
+ content: '';
306
+ position: absolute;
307
+ width: 50%;
308
+ height: 100%;
309
+ top: 0;
310
+ left: 0;
311
+ transform: translate(100%, 0px);
312
+ }
313
+
314
+ .rdp-cell:has(.rdp-day_range_start)::before {
315
+ background-color: white;
316
+ content: '';
317
+ position: absolute;
318
+ width: 50%;
319
+ height: 100%;
320
+ top: 0;
321
+ left: 0;
322
+ }
323
+
324
+ .rdp-cell:has(.rdp-day_range_end) {
325
+ background-color: var(--rdp-selected-range-color);
326
+ border-top-right-radius: 50%;
327
+ border-bottom-right-radius: 50%;
328
+ position: relative;
329
+ }
330
+
331
+ .rdp-day_range_end.rdp-day_range_start {
332
+ border-radius: var(--rdp-day-borderRadius-custom);
333
+ padding: 4px;
334
+ }
335
+
336
+ .rdp-cell:has(.rdp-day_range_middle) {
337
+ background-color: var(--rdp-selected-range-color);
338
+ }
339
+
340
+ .rdp-day_range_middle {
341
+ border-radius: 0;
342
+ color: var(--rdp-accent-color);
343
+ background-color: var(--rdp-selected-range-color);
344
+ padding: 4px;
345
+ }
346
+
347
+ .weekendColor {
348
+ color: #ff0000;
349
+ }
350
+
351
+ `;
package/src/index.ts ADDED
@@ -0,0 +1,3 @@
1
+ export { default as Calendar } from './Calendar';
2
+ export type * from './type';
3
+ export * from './constants';