@quillsql/react 1.7.5 → 1.7.7
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/lib/Chart.d.ts +1 -1
- package/lib/Chart.js +107 -50
- package/lib/Chart.js.map +1 -1
- package/lib/Dashboard.d.ts +36 -1
- package/lib/Dashboard.js +107 -37
- package/lib/Dashboard.js.map +1 -1
- package/lib/ReportBuilder.js +117 -41
- package/lib/ReportBuilder.js.map +1 -1
- package/lib/SQLEditor.js +80 -29
- package/lib/SQLEditor.js.map +1 -1
- package/lib/Table.js +31 -16
- package/lib/Table.js.map +1 -1
- package/lib/components/BigModal/BigModal.js +1 -0
- package/lib/components/BigModal/BigModal.js.map +1 -1
- package/lib/components/Modal/Modal.js +1 -0
- package/lib/components/Modal/Modal.js.map +1 -1
- package/lib/hooks/useQuill.js +16 -1
- package/lib/hooks/useQuill.js.map +1 -1
- package/package.json +11 -5
- package/.eslintrc.json +0 -19
- package/.prettierrc +0 -11
- package/.vscode/settings.json +0 -10
- package/src/AddToDashboardModal.tsx +0 -1220
- package/src/BarList.tsx +0 -580
- package/src/Chart.tsx +0 -1337
- package/src/Context.tsx +0 -252
- package/src/Dashboard.tsx +0 -820
- package/src/DateRangePicker/Calendar.tsx +0 -442
- package/src/DateRangePicker/DateRangePicker.tsx +0 -261
- package/src/DateRangePicker/DateRangePickerButton.tsx +0 -250
- package/src/DateRangePicker/dateRangePickerUtils.tsx +0 -480
- package/src/DateRangePicker/index.ts +0 -4
- package/src/PieChart.tsx +0 -845
- package/src/QuillProvider.tsx +0 -81
- package/src/ReportBuilder.tsx +0 -2208
- package/src/SQLEditor.tsx +0 -1093
- package/src/Table.tsx +0 -1074
- package/src/TableChart.tsx +0 -428
- package/src/assets/ArrowDownHeadIcon.tsx +0 -11
- package/src/assets/ArrowDownIcon.tsx +0 -14
- package/src/assets/ArrowDownRightIcon.tsx +0 -14
- package/src/assets/ArrowLeftHeadIcon.tsx +0 -11
- package/src/assets/ArrowRightHeadIcon.tsx +0 -11
- package/src/assets/ArrowRightIcon.tsx +0 -14
- package/src/assets/ArrowUpHeadIcon.tsx +0 -11
- package/src/assets/ArrowUpIcon.tsx +0 -14
- package/src/assets/ArrowUpRightIcon.tsx +0 -14
- package/src/assets/CalendarIcon.tsx +0 -14
- package/src/assets/DoubleArrowLeftHeadIcon.tsx +0 -18
- package/src/assets/DoubleArrowRightHeadIcon.tsx +0 -20
- package/src/assets/ExclamationFilledIcon.tsx +0 -14
- package/src/assets/LoadingSpinner.tsx +0 -11
- package/src/assets/SearchIcon.tsx +0 -14
- package/src/assets/XCircleIcon.tsx +0 -14
- package/src/assets/index.ts +0 -16
- package/src/components/BigModal/BigModal.tsx +0 -108
- package/src/components/Dropdown/Dropdown.tsx +0 -169
- package/src/components/Dropdown/DropdownItem.tsx +0 -68
- package/src/components/Dropdown/index.ts +0 -2
- package/src/components/Modal/Modal.tsx +0 -132
- package/src/components/Modal/index.ts +0 -1
- package/src/components/selectUtils.ts +0 -60
- package/src/contexts/BaseColorContext.tsx +0 -5
- package/src/contexts/HoveredValueContext.tsx +0 -12
- package/src/contexts/RootStylesContext.tsx +0 -5
- package/src/contexts/SelectedValueContext.tsx +0 -13
- package/src/contexts/index.ts +0 -4
- package/src/hooks/index.ts +0 -4
- package/src/hooks/useInternalState.tsx +0 -18
- package/src/hooks/useOnClickOutside.tsx +0 -23
- package/src/hooks/useOnWindowResize.tsx +0 -17
- package/src/hooks/useQuill.ts +0 -138
- package/src/hooks/useSelectOnKeyDown.tsx +0 -80
- package/src/index.ts +0 -9
- package/src/lib/font.ts +0 -14
- package/src/lib/index.ts +0 -3
- package/src/lib/inputTypes.ts +0 -81
- package/src/lib/utils.tsx +0 -46
- package/tsconfig.json +0 -22
|
@@ -1,442 +0,0 @@
|
|
|
1
|
-
import React, { Dispatch, SetStateAction, useContext, useState } from 'react';
|
|
2
|
-
// import { twMerge } from 'tailwind-merge';
|
|
3
|
-
import {
|
|
4
|
-
add,
|
|
5
|
-
eachDayOfInterval,
|
|
6
|
-
endOfMonth,
|
|
7
|
-
format,
|
|
8
|
-
getDay,
|
|
9
|
-
isSaturday,
|
|
10
|
-
isSunday,
|
|
11
|
-
nextSaturday,
|
|
12
|
-
previousSunday,
|
|
13
|
-
startOfMonth,
|
|
14
|
-
} from 'date-fns';
|
|
15
|
-
import { BaseColorContext } from '../contexts';
|
|
16
|
-
|
|
17
|
-
import {
|
|
18
|
-
ArrowLeftHeadIcon,
|
|
19
|
-
ArrowRightHeadIcon,
|
|
20
|
-
DoubleArrowLeftHeadIcon,
|
|
21
|
-
DoubleArrowRightHeadIcon,
|
|
22
|
-
} from '../assets';
|
|
23
|
-
|
|
24
|
-
import { capitalize, getDateStyles, getWeekdays } from './dateRangePickerUtils';
|
|
25
|
-
|
|
26
|
-
export const colStartClasses = [
|
|
27
|
-
'',
|
|
28
|
-
'col-start-2',
|
|
29
|
-
'col-start-3',
|
|
30
|
-
'col-start-4',
|
|
31
|
-
'col-start-5',
|
|
32
|
-
'col-start-6',
|
|
33
|
-
'col-start-7',
|
|
34
|
-
];
|
|
35
|
-
|
|
36
|
-
interface CalendarHeaderProps {
|
|
37
|
-
enableYearPagination: boolean;
|
|
38
|
-
anchorDate: Date;
|
|
39
|
-
setStartOfCurrMonth: Dispatch<SetStateAction<Date | null>>;
|
|
40
|
-
locale: Locale;
|
|
41
|
-
theme: any;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
const CalendarHeader = ({
|
|
45
|
-
enableYearPagination,
|
|
46
|
-
anchorDate,
|
|
47
|
-
setStartOfCurrMonth,
|
|
48
|
-
locale,
|
|
49
|
-
theme,
|
|
50
|
-
}: CalendarHeaderProps) => {
|
|
51
|
-
const firstDayOfMonth = startOfMonth(anchorDate);
|
|
52
|
-
const handlePaginationClick = (
|
|
53
|
-
type: 'nextMonth' | 'prevMonth' | 'nextYear' | 'prevYear'
|
|
54
|
-
) => {
|
|
55
|
-
switch (type) {
|
|
56
|
-
case 'nextMonth':
|
|
57
|
-
setStartOfCurrMonth(add(firstDayOfMonth, { months: 1 }));
|
|
58
|
-
break;
|
|
59
|
-
case 'prevMonth':
|
|
60
|
-
setStartOfCurrMonth(add(firstDayOfMonth, { months: -1 }));
|
|
61
|
-
break;
|
|
62
|
-
case 'nextYear':
|
|
63
|
-
setStartOfCurrMonth(add(firstDayOfMonth, { years: 1 }));
|
|
64
|
-
break;
|
|
65
|
-
case 'prevYear':
|
|
66
|
-
setStartOfCurrMonth(add(firstDayOfMonth, { years: -1 }));
|
|
67
|
-
break;
|
|
68
|
-
}
|
|
69
|
-
};
|
|
70
|
-
|
|
71
|
-
const displayedTitle = capitalize(
|
|
72
|
-
format(firstDayOfMonth, 'MMMM yyyy', { locale }),
|
|
73
|
-
locale
|
|
74
|
-
);
|
|
75
|
-
|
|
76
|
-
return (
|
|
77
|
-
<div
|
|
78
|
-
style={{
|
|
79
|
-
display: 'flex',
|
|
80
|
-
justifyContent: 'space-between',
|
|
81
|
-
alignItems: 'center',
|
|
82
|
-
padding: '0.125rem',
|
|
83
|
-
paddingTop: '0.25rem',
|
|
84
|
-
paddingBottom: '0.25rem',
|
|
85
|
-
}}
|
|
86
|
-
>
|
|
87
|
-
<div
|
|
88
|
-
style={{
|
|
89
|
-
display: 'flex',
|
|
90
|
-
alignItems: 'center',
|
|
91
|
-
gap: '0.25rem',
|
|
92
|
-
}}
|
|
93
|
-
>
|
|
94
|
-
<button
|
|
95
|
-
type="button"
|
|
96
|
-
style={{
|
|
97
|
-
borderStyle: 'solid',
|
|
98
|
-
borderWidth: 1,
|
|
99
|
-
fontFamily: theme?.fontFamily,
|
|
100
|
-
borderColor: theme?.borderColor || '#E5E7EB',
|
|
101
|
-
background: theme?.backgroundColor || 'white',
|
|
102
|
-
display: 'inline-flex',
|
|
103
|
-
padding: '0.25rem',
|
|
104
|
-
marginRight: '0.0625rem',
|
|
105
|
-
fontSize: '0.875rem',
|
|
106
|
-
fontWeight: 500,
|
|
107
|
-
borderRadius: '0.25rem',
|
|
108
|
-
boxShadow: '0 1px 2px 0 rgba(0, 0, 0, 0.05)',
|
|
109
|
-
outline: enableYearPagination ? 'none' : '2px solid transparent',
|
|
110
|
-
outlineOffset: '2px',
|
|
111
|
-
cursor: 'pointer',
|
|
112
|
-
}}
|
|
113
|
-
onClick={() => handlePaginationClick('prevYear')}
|
|
114
|
-
>
|
|
115
|
-
<DoubleArrowLeftHeadIcon
|
|
116
|
-
style={{
|
|
117
|
-
height: '1.25rem',
|
|
118
|
-
width: '1.25rem',
|
|
119
|
-
color: theme?.primaryTextColor || '#364153',
|
|
120
|
-
}}
|
|
121
|
-
aria-hidden="true"
|
|
122
|
-
/>
|
|
123
|
-
</button>
|
|
124
|
-
<button
|
|
125
|
-
style={{
|
|
126
|
-
borderStyle: 'solid',
|
|
127
|
-
borderBottomWidth: 1,
|
|
128
|
-
borderBottomColor: theme?.borderColor || '#E5E7EB',
|
|
129
|
-
background: theme?.backgroundColor || 'white',
|
|
130
|
-
borderWidth: 1,
|
|
131
|
-
fontFamily: theme?.fontFamily,
|
|
132
|
-
borderColor: theme?.borderColor || '#E5E7EB',
|
|
133
|
-
display: 'inline-flex',
|
|
134
|
-
padding: '0.25rem',
|
|
135
|
-
marginRight: '0.0625rem',
|
|
136
|
-
fontSize: '0.875rem',
|
|
137
|
-
fontWeight: 500,
|
|
138
|
-
borderRadius: '0.25rem',
|
|
139
|
-
boxShadow: '0 1px 2px 0 rgba(0, 0, 0, 0.05)',
|
|
140
|
-
outline: enableYearPagination ? 'none' : '2px solid transparent',
|
|
141
|
-
outlineOffset: '2px',
|
|
142
|
-
cursor: 'pointer',
|
|
143
|
-
}}
|
|
144
|
-
type="button"
|
|
145
|
-
name="prevMonth"
|
|
146
|
-
onClick={() => handlePaginationClick('prevMonth')}
|
|
147
|
-
>
|
|
148
|
-
<ArrowLeftHeadIcon
|
|
149
|
-
style={{
|
|
150
|
-
height: '1.25rem',
|
|
151
|
-
width: '1.25rem',
|
|
152
|
-
color: theme?.primaryTextColor || '#364153',
|
|
153
|
-
}}
|
|
154
|
-
aria-hidden="true"
|
|
155
|
-
/>
|
|
156
|
-
</button>
|
|
157
|
-
</div>
|
|
158
|
-
<h2
|
|
159
|
-
style={{
|
|
160
|
-
color: theme?.textColor || '#364153',
|
|
161
|
-
fontSize: '0.875rem',
|
|
162
|
-
fontFamily: theme?.fontFamily,
|
|
163
|
-
fontWeight: '700',
|
|
164
|
-
}}
|
|
165
|
-
>
|
|
166
|
-
{displayedTitle}
|
|
167
|
-
</h2>
|
|
168
|
-
<div
|
|
169
|
-
style={{
|
|
170
|
-
display: 'flex',
|
|
171
|
-
alignItems: 'center',
|
|
172
|
-
marginRight: '0.25rem',
|
|
173
|
-
marginLeft: '0.25rem',
|
|
174
|
-
}}
|
|
175
|
-
>
|
|
176
|
-
<button
|
|
177
|
-
style={{
|
|
178
|
-
borderStyle: 'solid',
|
|
179
|
-
borderBottomWidth: 1,
|
|
180
|
-
borderBottomColor: theme?.borderColor || '#E5E7EB',
|
|
181
|
-
background: theme?.backgroundColor || 'white',
|
|
182
|
-
borderWidth: 1,
|
|
183
|
-
borderColor: theme?.borderColor || '#E5E7EB',
|
|
184
|
-
fontFamily: theme?.fontFamily,
|
|
185
|
-
display: 'inline-flex',
|
|
186
|
-
padding: '0.25rem',
|
|
187
|
-
marginRight: '0.0625rem',
|
|
188
|
-
fontSize: '0.875rem',
|
|
189
|
-
fontWeight: 500,
|
|
190
|
-
borderRadius: '0.25rem',
|
|
191
|
-
boxShadow: '0 1px 2px 0 rgba(0, 0, 0, 0.05)',
|
|
192
|
-
outline: enableYearPagination ? 'none' : '2px solid transparent',
|
|
193
|
-
outlineOffset: '2px',
|
|
194
|
-
cursor: 'pointer',
|
|
195
|
-
}}
|
|
196
|
-
type="button"
|
|
197
|
-
name="nextMonth"
|
|
198
|
-
onClick={() => handlePaginationClick('nextMonth')}
|
|
199
|
-
>
|
|
200
|
-
<ArrowRightHeadIcon
|
|
201
|
-
style={{
|
|
202
|
-
height: '1.25rem',
|
|
203
|
-
width: '1.25rem',
|
|
204
|
-
color: theme?.primaryTextColor || '#364153',
|
|
205
|
-
}}
|
|
206
|
-
aria-hidden="true"
|
|
207
|
-
/>
|
|
208
|
-
</button>
|
|
209
|
-
<button
|
|
210
|
-
style={{
|
|
211
|
-
background: theme?.backgroundColor || 'white',
|
|
212
|
-
borderStyle: 'solid',
|
|
213
|
-
borderWidth: 1,
|
|
214
|
-
borderColor: theme?.borderColor || '#E5E7EB',
|
|
215
|
-
display: 'inline-flex',
|
|
216
|
-
padding: '0.25rem',
|
|
217
|
-
marginRight: '0.0625rem',
|
|
218
|
-
fontFamily: theme?.fontFamily,
|
|
219
|
-
fontSize: '0.875rem',
|
|
220
|
-
fontWeight: 500,
|
|
221
|
-
borderRadius: '0.25rem',
|
|
222
|
-
boxShadow: '0 1px 2px 0 rgba(0, 0, 0, 0.05)',
|
|
223
|
-
outline: enableYearPagination ? 'none' : '2px solid transparent',
|
|
224
|
-
outlineOffset: '2px',
|
|
225
|
-
cursor: 'pointer',
|
|
226
|
-
}}
|
|
227
|
-
type="button"
|
|
228
|
-
onClick={() => handlePaginationClick('nextYear')}
|
|
229
|
-
>
|
|
230
|
-
<DoubleArrowRightHeadIcon
|
|
231
|
-
style={{
|
|
232
|
-
height: '1.25rem',
|
|
233
|
-
width: '1.25rem',
|
|
234
|
-
color: theme?.primaryTextColor || '#364153',
|
|
235
|
-
}}
|
|
236
|
-
aria-hidden="true"
|
|
237
|
-
/>
|
|
238
|
-
</button>
|
|
239
|
-
</div>
|
|
240
|
-
</div>
|
|
241
|
-
);
|
|
242
|
-
};
|
|
243
|
-
|
|
244
|
-
interface CalendarBodyProps {
|
|
245
|
-
anchorDate: Date;
|
|
246
|
-
selectedStartDate: Date | null;
|
|
247
|
-
selectedEndDate: Date | null;
|
|
248
|
-
onDateClick: (date: Date) => void;
|
|
249
|
-
minDate: Date | null;
|
|
250
|
-
maxDate: Date | null;
|
|
251
|
-
locale: Locale;
|
|
252
|
-
theme: any;
|
|
253
|
-
}
|
|
254
|
-
|
|
255
|
-
const CalendarBody = ({
|
|
256
|
-
anchorDate,
|
|
257
|
-
selectedStartDate,
|
|
258
|
-
selectedEndDate,
|
|
259
|
-
onDateClick,
|
|
260
|
-
minDate,
|
|
261
|
-
maxDate,
|
|
262
|
-
locale,
|
|
263
|
-
theme,
|
|
264
|
-
}: CalendarBodyProps) => {
|
|
265
|
-
const [hoveredDate, setHoveredDate] = useState<Date | undefined>();
|
|
266
|
-
const color = useContext(BaseColorContext);
|
|
267
|
-
|
|
268
|
-
const firstDayOfDisplayedMonth = startOfMonth(anchorDate);
|
|
269
|
-
const lastDayOfDisplayedMonth = endOfMonth(anchorDate);
|
|
270
|
-
|
|
271
|
-
const weekdays = getWeekdays(locale).map(dayName =>
|
|
272
|
-
capitalize(dayName, locale)
|
|
273
|
-
);
|
|
274
|
-
|
|
275
|
-
const displayedDates = eachDayOfInterval({
|
|
276
|
-
start: isSunday(firstDayOfDisplayedMonth)
|
|
277
|
-
? firstDayOfDisplayedMonth
|
|
278
|
-
: previousSunday(firstDayOfDisplayedMonth),
|
|
279
|
-
end: isSaturday(lastDayOfDisplayedMonth)
|
|
280
|
-
? lastDayOfDisplayedMonth
|
|
281
|
-
: nextSaturday(lastDayOfDisplayedMonth),
|
|
282
|
-
});
|
|
283
|
-
|
|
284
|
-
const isDateDisabled = (
|
|
285
|
-
date: Date,
|
|
286
|
-
minDate: Date | null,
|
|
287
|
-
maxDate: Date | null,
|
|
288
|
-
firstDayDisplayedMonth: Date,
|
|
289
|
-
lastDayDisplayedMonth: Date
|
|
290
|
-
) => {
|
|
291
|
-
const isDateInDisplayedMonth =
|
|
292
|
-
date >= firstDayDisplayedMonth && date <= lastDayDisplayedMonth;
|
|
293
|
-
return (
|
|
294
|
-
(minDate !== null && date < minDate) ||
|
|
295
|
-
(maxDate !== null && date > maxDate) ||
|
|
296
|
-
!isDateInDisplayedMonth
|
|
297
|
-
);
|
|
298
|
-
};
|
|
299
|
-
|
|
300
|
-
return (
|
|
301
|
-
<>
|
|
302
|
-
<div
|
|
303
|
-
style={{
|
|
304
|
-
color: theme?.primaryTextColor || '#364153',
|
|
305
|
-
textAlign: 'center',
|
|
306
|
-
fontSize: '0.75rem',
|
|
307
|
-
fontWeight: '500',
|
|
308
|
-
display: 'grid',
|
|
309
|
-
gridTemplateColumns: 'repeat(7, minmax(0, 1fr))',
|
|
310
|
-
}}
|
|
311
|
-
>
|
|
312
|
-
{weekdays.map(dayName => (
|
|
313
|
-
<div
|
|
314
|
-
key={dayName}
|
|
315
|
-
style={{ width: '100%', display: 'flex', justifyContent: 'center' }}
|
|
316
|
-
>
|
|
317
|
-
<div
|
|
318
|
-
style={{
|
|
319
|
-
display: 'flex',
|
|
320
|
-
alignItems: 'center',
|
|
321
|
-
justifyContent: 'center',
|
|
322
|
-
width: '100%',
|
|
323
|
-
height: '2.25rem',
|
|
324
|
-
fontFamily: theme?.fontFamily,
|
|
325
|
-
}}
|
|
326
|
-
>
|
|
327
|
-
{dayName}
|
|
328
|
-
</div>
|
|
329
|
-
</div>
|
|
330
|
-
))}
|
|
331
|
-
</div>
|
|
332
|
-
<div
|
|
333
|
-
style={{
|
|
334
|
-
display: 'grid',
|
|
335
|
-
gridTemplateColumns: 'repeat(7, minmax(0, 1fr))',
|
|
336
|
-
paddingBottom: 8,
|
|
337
|
-
}}
|
|
338
|
-
>
|
|
339
|
-
{displayedDates.map(date => {
|
|
340
|
-
const isCurrentDateDisabled = isDateDisabled(
|
|
341
|
-
date,
|
|
342
|
-
minDate,
|
|
343
|
-
maxDate,
|
|
344
|
-
firstDayOfDisplayedMonth,
|
|
345
|
-
lastDayOfDisplayedMonth
|
|
346
|
-
);
|
|
347
|
-
|
|
348
|
-
return (
|
|
349
|
-
<div key={date.toString()} style={{ width: '100%' }}>
|
|
350
|
-
<button
|
|
351
|
-
style={{
|
|
352
|
-
border: 'none',
|
|
353
|
-
height: '1.5rem',
|
|
354
|
-
display: 'flex',
|
|
355
|
-
width: '100%',
|
|
356
|
-
alignItems: 'center',
|
|
357
|
-
justifyContent: 'center',
|
|
358
|
-
fontFamily: theme?.fontFamily,
|
|
359
|
-
...getDateStyles(
|
|
360
|
-
theme,
|
|
361
|
-
date,
|
|
362
|
-
selectedStartDate,
|
|
363
|
-
selectedEndDate,
|
|
364
|
-
hoveredDate,
|
|
365
|
-
isCurrentDateDisabled
|
|
366
|
-
),
|
|
367
|
-
}}
|
|
368
|
-
type="button"
|
|
369
|
-
onClick={() => onDateClick(date)}
|
|
370
|
-
onPointerEnter={() => setHoveredDate?.(date)}
|
|
371
|
-
onPointerLeave={() => setHoveredDate?.(undefined)}
|
|
372
|
-
// className={twMerge(fontSize.sm)}
|
|
373
|
-
disabled={isCurrentDateDisabled}
|
|
374
|
-
>
|
|
375
|
-
<time dateTime={format(date, 'yyyy-MM-dd', { locale })}>
|
|
376
|
-
{format(date, 'd', { locale })}
|
|
377
|
-
</time>
|
|
378
|
-
</button>
|
|
379
|
-
</div>
|
|
380
|
-
);
|
|
381
|
-
})}
|
|
382
|
-
</div>
|
|
383
|
-
</>
|
|
384
|
-
);
|
|
385
|
-
};
|
|
386
|
-
|
|
387
|
-
export interface CalendarProps {
|
|
388
|
-
enableYearPagination: boolean;
|
|
389
|
-
anchorDate: Date;
|
|
390
|
-
setStartOfCurrMonth: Dispatch<SetStateAction<Date | null>>;
|
|
391
|
-
startDate: Date | null;
|
|
392
|
-
endDate: Date | null;
|
|
393
|
-
minDate: Date | null;
|
|
394
|
-
maxDate: Date | null;
|
|
395
|
-
onDateClick: (date: Date) => void;
|
|
396
|
-
locale: Locale;
|
|
397
|
-
theme: any;
|
|
398
|
-
}
|
|
399
|
-
|
|
400
|
-
const Calendar = ({
|
|
401
|
-
enableYearPagination,
|
|
402
|
-
anchorDate,
|
|
403
|
-
setStartOfCurrMonth,
|
|
404
|
-
startDate,
|
|
405
|
-
endDate,
|
|
406
|
-
minDate,
|
|
407
|
-
maxDate,
|
|
408
|
-
onDateClick,
|
|
409
|
-
locale,
|
|
410
|
-
theme,
|
|
411
|
-
}: CalendarProps) => {
|
|
412
|
-
return (
|
|
413
|
-
<div
|
|
414
|
-
style={{
|
|
415
|
-
paddingLeft: '0.75rem',
|
|
416
|
-
paddingRight: '0.75rem',
|
|
417
|
-
paddingTop: '0.25rem',
|
|
418
|
-
paddingBottom: '0.25rem',
|
|
419
|
-
}}
|
|
420
|
-
>
|
|
421
|
-
<CalendarHeader
|
|
422
|
-
enableYearPagination={enableYearPagination}
|
|
423
|
-
anchorDate={anchorDate}
|
|
424
|
-
setStartOfCurrMonth={setStartOfCurrMonth}
|
|
425
|
-
locale={locale}
|
|
426
|
-
theme={theme}
|
|
427
|
-
/>
|
|
428
|
-
<CalendarBody
|
|
429
|
-
anchorDate={anchorDate}
|
|
430
|
-
selectedStartDate={startDate}
|
|
431
|
-
selectedEndDate={endDate}
|
|
432
|
-
onDateClick={onDateClick}
|
|
433
|
-
minDate={minDate}
|
|
434
|
-
maxDate={maxDate}
|
|
435
|
-
locale={locale}
|
|
436
|
-
theme={theme}
|
|
437
|
-
/>
|
|
438
|
-
</div>
|
|
439
|
-
);
|
|
440
|
-
};
|
|
441
|
-
|
|
442
|
-
export default Calendar;
|
|
@@ -1,261 +0,0 @@
|
|
|
1
|
-
/* eslint-disable react/display-name */
|
|
2
|
-
// @ts-nocheck
|
|
3
|
-
import React, { useRef, useState } from 'react';
|
|
4
|
-
|
|
5
|
-
import { startOfMonth, startOfToday, sub } from 'date-fns';
|
|
6
|
-
import { enUS } from 'date-fns/locale';
|
|
7
|
-
|
|
8
|
-
import {
|
|
9
|
-
BaseColorContext,
|
|
10
|
-
HoveredValueContext,
|
|
11
|
-
SelectedValueContext,
|
|
12
|
-
} from '../contexts';
|
|
13
|
-
|
|
14
|
-
import { useInternalState, useSelectOnKeyDown } from '../hooks';
|
|
15
|
-
|
|
16
|
-
import {
|
|
17
|
-
defaultOptions,
|
|
18
|
-
getEndDateByDropdownValue,
|
|
19
|
-
getStartDateByDropdownValue,
|
|
20
|
-
parseEndDate,
|
|
21
|
-
parseStartDate,
|
|
22
|
-
} from './dateRangePickerUtils';
|
|
23
|
-
|
|
24
|
-
import Calendar from './Calendar';
|
|
25
|
-
import DateRangePickerButton from './DateRangePickerButton';
|
|
26
|
-
import { DropdownItem } from '../components/Dropdown';
|
|
27
|
-
import Modal from '../components/Modal';
|
|
28
|
-
|
|
29
|
-
export type Locale = typeof enUS;
|
|
30
|
-
|
|
31
|
-
export type DateRangePickerValue = [
|
|
32
|
-
(Date | null)?,
|
|
33
|
-
(Date | null)?,
|
|
34
|
-
(string | null)?
|
|
35
|
-
];
|
|
36
|
-
export type DateRangePickerOption = {
|
|
37
|
-
value: string;
|
|
38
|
-
text: string;
|
|
39
|
-
startDate: Date;
|
|
40
|
-
endDate?: Date;
|
|
41
|
-
};
|
|
42
|
-
|
|
43
|
-
export interface DateRangePickerProps
|
|
44
|
-
extends Omit<React.HTMLAttributes<HTMLDivElement>, 'value' | 'defaultValue'> {
|
|
45
|
-
value?: DateRangePickerValue;
|
|
46
|
-
defaultValue?: DateRangePickerValue;
|
|
47
|
-
onValueChange?: (value: DateRangePickerValue) => void;
|
|
48
|
-
enableDropdown?: boolean;
|
|
49
|
-
options?: DateRangePickerOption[];
|
|
50
|
-
minDate?: Date | null;
|
|
51
|
-
maxDate?: Date | null;
|
|
52
|
-
placeholder?: string;
|
|
53
|
-
dropdownPlaceholder?: string;
|
|
54
|
-
enableYearPagination?: boolean;
|
|
55
|
-
disabled?: boolean;
|
|
56
|
-
color?: string;
|
|
57
|
-
locale?: Locale;
|
|
58
|
-
theme: any;
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
const DateRangePicker = React.forwardRef<HTMLDivElement, DateRangePickerProps>(
|
|
62
|
-
(props, ref) => {
|
|
63
|
-
const {
|
|
64
|
-
value,
|
|
65
|
-
defaultValue,
|
|
66
|
-
onValueChange,
|
|
67
|
-
enableDropdown = true,
|
|
68
|
-
options,
|
|
69
|
-
minDate = null,
|
|
70
|
-
maxDate = null,
|
|
71
|
-
placeholder = 'Select',
|
|
72
|
-
dropdownPlaceholder = 'Select',
|
|
73
|
-
disabled = false,
|
|
74
|
-
color = 'blue',
|
|
75
|
-
enableYearPagination = false,
|
|
76
|
-
locale = enUS,
|
|
77
|
-
className,
|
|
78
|
-
theme,
|
|
79
|
-
...other
|
|
80
|
-
} = props;
|
|
81
|
-
|
|
82
|
-
const TODAY = startOfToday();
|
|
83
|
-
const calendarRef = useRef(null);
|
|
84
|
-
const dropdownRef = useRef(null);
|
|
85
|
-
|
|
86
|
-
const [selectedValue, setSelectedValue] = useInternalState(
|
|
87
|
-
defaultValue,
|
|
88
|
-
value
|
|
89
|
-
);
|
|
90
|
-
|
|
91
|
-
const [startOfCurrMonth, setStartOfCurrMonth] = useState<Date | null>(null);
|
|
92
|
-
const [showCalendar, setShowCalendar] = useState(false);
|
|
93
|
-
const [showDropdown, setShowDropdown] = useState(false);
|
|
94
|
-
|
|
95
|
-
const dropdownOptions = options ?? defaultOptions;
|
|
96
|
-
const selectedDropdownValue = selectedValue
|
|
97
|
-
? selectedValue[2] ?? null
|
|
98
|
-
: null;
|
|
99
|
-
const selectedStartDate = selectedValue
|
|
100
|
-
? parseStartDate(
|
|
101
|
-
selectedValue[0],
|
|
102
|
-
minDate,
|
|
103
|
-
selectedDropdownValue,
|
|
104
|
-
dropdownOptions
|
|
105
|
-
)
|
|
106
|
-
: null;
|
|
107
|
-
const selectedEndDate = selectedValue
|
|
108
|
-
? parseEndDate(
|
|
109
|
-
selectedValue[1],
|
|
110
|
-
maxDate,
|
|
111
|
-
selectedDropdownValue,
|
|
112
|
-
dropdownOptions
|
|
113
|
-
)
|
|
114
|
-
: null;
|
|
115
|
-
|
|
116
|
-
const anchorDate =
|
|
117
|
-
startOfCurrMonth ?? selectedEndDate ?? selectedStartDate ?? TODAY;
|
|
118
|
-
|
|
119
|
-
const handleDateClick = (date: Date) => {
|
|
120
|
-
if (!selectedStartDate) {
|
|
121
|
-
onValueChange?.([date, selectedEndDate, null]);
|
|
122
|
-
setSelectedValue([date, selectedEndDate, null]);
|
|
123
|
-
} else if (selectedStartDate && !selectedEndDate) {
|
|
124
|
-
if (date < selectedStartDate) {
|
|
125
|
-
onValueChange?.([date, selectedEndDate, null]);
|
|
126
|
-
setSelectedValue([date, selectedEndDate, null]);
|
|
127
|
-
// Selection complete
|
|
128
|
-
} else {
|
|
129
|
-
onValueChange?.([selectedStartDate, date, null]);
|
|
130
|
-
setSelectedValue([selectedStartDate, date, null]);
|
|
131
|
-
setShowCalendar(false);
|
|
132
|
-
}
|
|
133
|
-
} else if (selectedStartDate && selectedEndDate) {
|
|
134
|
-
onValueChange?.([date, null, null]);
|
|
135
|
-
setSelectedValue([date, null, null]);
|
|
136
|
-
}
|
|
137
|
-
};
|
|
138
|
-
|
|
139
|
-
const handleCalendarKeyDown = (
|
|
140
|
-
e: React.KeyboardEvent<HTMLButtonElement>
|
|
141
|
-
) => {
|
|
142
|
-
if (e.key === 'Escape') {
|
|
143
|
-
e.preventDefault();
|
|
144
|
-
setShowCalendar(false);
|
|
145
|
-
}
|
|
146
|
-
};
|
|
147
|
-
|
|
148
|
-
const handleDropdownOptionClick = (dropdownValue: string) => {
|
|
149
|
-
const selectedStartDate = getStartDateByDropdownValue(
|
|
150
|
-
dropdownValue,
|
|
151
|
-
dropdownOptions
|
|
152
|
-
);
|
|
153
|
-
const selectedEndDate = getEndDateByDropdownValue(
|
|
154
|
-
dropdownValue,
|
|
155
|
-
dropdownOptions
|
|
156
|
-
);
|
|
157
|
-
|
|
158
|
-
setSelectedValue([selectedStartDate, selectedEndDate, dropdownValue]);
|
|
159
|
-
onValueChange?.([selectedStartDate, selectedEndDate, dropdownValue]);
|
|
160
|
-
setStartOfCurrMonth(startOfMonth(selectedEndDate));
|
|
161
|
-
setShowDropdown(false);
|
|
162
|
-
};
|
|
163
|
-
|
|
164
|
-
const [hoveredDropdownValue, handleDropdownKeyDown] = useSelectOnKeyDown(
|
|
165
|
-
handleDropdownOptionClick,
|
|
166
|
-
dropdownOptions.map((option: DateRangePickerOption) => option.value),
|
|
167
|
-
showDropdown,
|
|
168
|
-
setShowDropdown,
|
|
169
|
-
selectedDropdownValue as string
|
|
170
|
-
);
|
|
171
|
-
|
|
172
|
-
return (
|
|
173
|
-
<BaseColorContext.Provider value={color}>
|
|
174
|
-
<div
|
|
175
|
-
ref={ref}
|
|
176
|
-
style={{ position: 'relative', width: '100%' }}
|
|
177
|
-
// className={twMerge(
|
|
178
|
-
// makeDateRangePickerClassName('root'),
|
|
179
|
-
// 'qq-relative qq-w-full',
|
|
180
|
-
// className
|
|
181
|
-
// )}
|
|
182
|
-
{...other}
|
|
183
|
-
>
|
|
184
|
-
<DateRangePickerButton
|
|
185
|
-
value={[selectedStartDate, selectedEndDate, selectedDropdownValue]}
|
|
186
|
-
options={dropdownOptions}
|
|
187
|
-
placeholder={placeholder}
|
|
188
|
-
disabled={disabled}
|
|
189
|
-
calendarRef={calendarRef}
|
|
190
|
-
showCalendar={showCalendar}
|
|
191
|
-
setShowCalendar={setShowCalendar}
|
|
192
|
-
onCalendarKeyDown={handleCalendarKeyDown}
|
|
193
|
-
enableDropdown={enableDropdown}
|
|
194
|
-
dropdownRef={dropdownRef}
|
|
195
|
-
showDropdown={showDropdown}
|
|
196
|
-
setShowDropdown={setShowDropdown}
|
|
197
|
-
onDropdownKeyDown={handleDropdownKeyDown}
|
|
198
|
-
locale={locale}
|
|
199
|
-
dropdownPlaceholder={dropdownPlaceholder}
|
|
200
|
-
theme={theme}
|
|
201
|
-
/>
|
|
202
|
-
{/* Calendar Modal */}
|
|
203
|
-
<Modal
|
|
204
|
-
theme={theme}
|
|
205
|
-
showModal={showCalendar}
|
|
206
|
-
setShowModal={setShowCalendar}
|
|
207
|
-
parentRef={calendarRef}
|
|
208
|
-
width={288}
|
|
209
|
-
maxHeight="fit-content"
|
|
210
|
-
>
|
|
211
|
-
<Calendar
|
|
212
|
-
enableYearPagination={enableYearPagination}
|
|
213
|
-
anchorDate={anchorDate}
|
|
214
|
-
// setAnchorDate={setAnchorDate}
|
|
215
|
-
startDate={selectedStartDate}
|
|
216
|
-
endDate={selectedEndDate}
|
|
217
|
-
minDate={minDate}
|
|
218
|
-
maxDate={maxDate}
|
|
219
|
-
onDateClick={handleDateClick}
|
|
220
|
-
locale={locale}
|
|
221
|
-
setStartOfCurrMonth={setStartOfCurrMonth}
|
|
222
|
-
theme={theme}
|
|
223
|
-
/>
|
|
224
|
-
</Modal>
|
|
225
|
-
{/* Dropdpown Modal */}
|
|
226
|
-
<Modal
|
|
227
|
-
showModal={showDropdown}
|
|
228
|
-
setShowModal={setShowDropdown}
|
|
229
|
-
parentRef={dropdownRef}
|
|
230
|
-
theme={theme}
|
|
231
|
-
>
|
|
232
|
-
<SelectedValueContext.Provider
|
|
233
|
-
value={{
|
|
234
|
-
selectedValue: selectedDropdownValue,
|
|
235
|
-
handleValueChange: handleDropdownOptionClick,
|
|
236
|
-
}}
|
|
237
|
-
>
|
|
238
|
-
<HoveredValueContext.Provider
|
|
239
|
-
value={{ hoveredValue: hoveredDropdownValue }}
|
|
240
|
-
>
|
|
241
|
-
{dropdownOptions.map(
|
|
242
|
-
({ value, text }: DateRangePickerOption, index: number) => (
|
|
243
|
-
<DropdownItem
|
|
244
|
-
key={value}
|
|
245
|
-
value={value}
|
|
246
|
-
text={text}
|
|
247
|
-
theme={theme}
|
|
248
|
-
lastItem={dropdownOptions.length - 1 === index}
|
|
249
|
-
/>
|
|
250
|
-
)
|
|
251
|
-
)}
|
|
252
|
-
</HoveredValueContext.Provider>
|
|
253
|
-
</SelectedValueContext.Provider>
|
|
254
|
-
</Modal>
|
|
255
|
-
</div>
|
|
256
|
-
</BaseColorContext.Provider>
|
|
257
|
-
);
|
|
258
|
-
}
|
|
259
|
-
);
|
|
260
|
-
|
|
261
|
-
export default DateRangePicker;
|