pixel-react 1.0.5 → 1.0.7

Sign up to get free protection for your applications and to get access to all the features.
Files changed (95) hide show
  1. package/.yarn/install-state.gz +0 -0
  2. package/lib/StyleGuide/ColorPalette/types.d.ts +2 -0
  3. package/lib/assets/utils/functionUtils.d.ts +3 -0
  4. package/lib/components/DatePicker/DatePicker.d.ts +5 -0
  5. package/lib/components/DatePicker/DatePicker.stories.d.ts +9 -0
  6. package/lib/components/DatePicker/Timepicker.d.ts +4 -0
  7. package/lib/components/DatePicker/index.d.ts +1 -0
  8. package/lib/components/DatePicker/types.d.ts +81 -0
  9. package/lib/components/DragAndDrop/DragAndDrop.d.ts +9 -0
  10. package/lib/components/DragAndDrop/DragAndDrop.stories.d.ts +6 -0
  11. package/lib/components/DragAndDrop/DragAndDropList.d.ts +20 -0
  12. package/lib/components/DragAndDrop/index.d.ts +1 -0
  13. package/lib/components/Drawer/Drawer.d.ts +2 -1
  14. package/lib/components/IconButton/IconButton.d.ts +5 -0
  15. package/lib/components/IconButton/IconButton.stories.d.ts +6 -0
  16. package/lib/components/IconButton/index.d.ts +1 -0
  17. package/lib/components/{AddButton → IconButton}/types.d.ts +3 -2
  18. package/lib/components/InputWithDropdown/InputWithDropdown.d.ts +1 -1
  19. package/lib/components/InputWithDropdown/types.d.ts +3 -7
  20. package/lib/components/Modal/Modal.d.ts +5 -0
  21. package/lib/components/Modal/Modal.stories.d.ts +7 -0
  22. package/lib/components/Modal/index.d.ts +1 -0
  23. package/lib/components/Modal/types.d.ts +26 -0
  24. package/lib/components/TableTree/TableTree.d.ts +2 -2
  25. package/lib/components/ThemeProvider/CustomThemeProvider.d.ts +8 -0
  26. package/lib/hooks/useCustomThemeProvider.d.ts +11 -0
  27. package/lib/index.d.ts +76 -16
  28. package/lib/index.esm.js +13365 -414
  29. package/lib/index.esm.js.map +1 -1
  30. package/lib/index.js +13368 -415
  31. package/lib/index.js.map +1 -1
  32. package/lib/tsconfig.tsbuildinfo +1 -1
  33. package/package.json +28 -23
  34. package/src/StyleGuide/ColorPalette/ColorPalette.scss +5 -0
  35. package/src/StyleGuide/ColorPalette/ColorPalette.tsx +10 -1
  36. package/src/StyleGuide/ColorPalette/colorPaletteList.ts +2 -2
  37. package/src/StyleGuide/ColorPalette/types.ts +2 -0
  38. package/src/assets/Themes/BaseTheme.scss +9 -1
  39. package/src/assets/Themes/DarkTheme.scss +8 -1
  40. package/src/assets/icons/add_variable_icon.svg +5 -0
  41. package/src/assets/icons/calendar_icon.svg +9 -0
  42. package/src/assets/icons/clock_icon.svg +11 -0
  43. package/src/assets/icons/collapse-icon.svg +6 -0
  44. package/src/assets/icons/copy-icon.svg +3 -0
  45. package/src/assets/icons/download-icon.svg +3 -0
  46. package/src/assets/icons/expand-icon.svg +6 -0
  47. package/src/assets/icons/info_icon.svg +4 -0
  48. package/src/assets/icons/left_arrow_icon.svg +3 -0
  49. package/src/assets/icons/license_info.svg +28 -0
  50. package/src/assets/icons/license_warning.svg +10 -0
  51. package/src/assets/icons/refresh-icon.svg +4 -0
  52. package/src/assets/icons/right_arrow_icon.svg +4 -0
  53. package/src/assets/styles/_mixins.scss +1 -0
  54. package/src/assets/utils/functionUtils.ts +37 -0
  55. package/src/components/DatePicker/DatePicker.scss +387 -0
  56. package/src/components/DatePicker/DatePicker.stories.tsx +161 -0
  57. package/src/components/DatePicker/DatePicker.tsx +438 -0
  58. package/src/components/DatePicker/Timepicker.tsx +372 -0
  59. package/src/components/DatePicker/index.ts +1 -0
  60. package/src/components/DatePicker/types.ts +100 -0
  61. package/src/components/DragAndDrop/DragAndDrop.d.ts +5 -0
  62. package/src/components/DragAndDrop/DragAndDrop.stories.tsx +25 -0
  63. package/src/components/DragAndDrop/DragAndDrop.ts +7 -0
  64. package/src/components/DragAndDrop/DragAndDropList.scss +69 -0
  65. package/src/components/DragAndDrop/DragAndDropList.tsx +150 -0
  66. package/src/components/DragAndDrop/index.ts +1 -0
  67. package/src/components/Drawer/Drawer.scss +0 -1
  68. package/src/components/Drawer/Drawer.tsx +7 -15
  69. package/src/components/Icon/iconList.ts +31 -9
  70. package/src/components/{AddButton/AddButton.scss → IconButton/IconButton.scss} +6 -2
  71. package/src/components/IconButton/IconButton.stories.tsx +25 -0
  72. package/src/components/{AddButton/AddButton.tsx → IconButton/IconButton.tsx} +10 -7
  73. package/src/components/IconButton/index.ts +1 -0
  74. package/src/components/{AddButton → IconButton}/types.ts +3 -2
  75. package/src/components/InputWithDropdown/InputWithDropdown.scss +1 -1
  76. package/src/components/InputWithDropdown/InputWithDropdown.stories.tsx +10 -13
  77. package/src/components/InputWithDropdown/InputWithDropdown.tsx +10 -8
  78. package/src/components/InputWithDropdown/types.ts +4 -7
  79. package/src/components/Modal/Modal.stories.tsx +63 -0
  80. package/src/components/Modal/Modal.tsx +71 -0
  81. package/src/components/Modal/index.tsx +1 -0
  82. package/src/components/Modal/modal.scss +37 -0
  83. package/src/components/Modal/types.ts +37 -0
  84. package/src/components/RadioButton/RadioButton.scss +3 -3
  85. package/src/components/Select/Select.scss +1 -1
  86. package/src/components/TableTree/TableTree.tsx +5 -1
  87. package/src/components/ThemeProvider/ThemeProvider.tsx +11 -8
  88. package/src/index.ts +6 -6
  89. package/lib/components/AddButton/AddButton.d.ts +0 -5
  90. package/lib/components/AddButton/AddButton.stories.d.ts +0 -6
  91. package/lib/components/AddButton/index.d.ts +0 -1
  92. package/src/assets/icons/expired_license_icon.svg +0 -3
  93. package/src/assets/icons/expiringSoon_license_icon.svg +0 -3
  94. package/src/components/AddButton/AddButton.stories.tsx +0 -24
  95. package/src/components/AddButton/index.ts +0 -1
@@ -0,0 +1,438 @@
1
+ import React, { useEffect, useState, useRef } from 'react';
2
+ import { DayPicker } from 'react-day-picker';
3
+ import { formatInTimeZone } from 'date-fns-tz';
4
+ import TimePicker from './Timepicker';
5
+ import Icon from '../Icon';
6
+ import './DatePicker.scss';
7
+ import {
8
+ DatePickerProps,
9
+ CustomCaptionProps,
10
+ CustomCalenderButtonProps,
11
+ } from './types';
12
+ import Button from '../Button';
13
+ import Typography from '../Typography';
14
+ import classNames from 'classnames';
15
+
16
+ const CustomDatePicker: React.FC<DatePickerProps> = ({
17
+ minDate,
18
+ maxDate,
19
+ value,
20
+ onChange,
21
+ placeholder = 'Select a date',
22
+ disabled = false,
23
+ dateFormat = 'EEEE, dd MMM yyyy',
24
+ calendarWidth,
25
+ timezone = 'Asia/Kolkata',
26
+ timeFormat = 'hh:mm a',
27
+ error,
28
+ helperText = '',
29
+ }) => {
30
+ const [timeValue, setTimeValue] = useState<string>('');
31
+ const [selectedDate, setSelectedDate] = useState<Date | undefined>();
32
+ const [isPickerOpen, setIsPickerOpen] = useState<boolean>(false);
33
+ const [timeError, setTimeError] = useState<boolean>(false);
34
+ const [selectedMonth, setSelectedMonth] = useState<Date | undefined>(
35
+ new Date()
36
+ );
37
+ const [view, setView] = useState<string>('days');
38
+ const [startYear, setStartYear] = useState(() => {
39
+ const currentYear =
40
+ selectedMonth?.getFullYear() ?? new Date().getFullYear();
41
+ return currentYear - (currentYear % 12); // Set to the first year in the 12-year range
42
+ });
43
+ const [datePickerPosition, setDatePickerPosition] = useState<
44
+ 'top' | 'bottom'
45
+ >('bottom');
46
+ const pickerRef = useRef<HTMLDivElement>(null); // Ref to track the picker
47
+ const containerRef = useRef<HTMLDivElement>(null);
48
+
49
+ useEffect(() => {
50
+ if (value) {
51
+ setTimeValue(formatTimeStr(value));
52
+ setSelectedDate(value);
53
+ }
54
+ }, [value, isPickerOpen]);
55
+
56
+ const formatTimeStr = (date: Date): string => {
57
+ const hours = date.getHours().toString().padStart(2, '0');
58
+ const minutes = date.getMinutes().toString().padStart(2, '0');
59
+ return `${hours}:${minutes}`;
60
+ };
61
+
62
+ // Convert minDate and maxDate to "hh:mm" for the TimePicker if the dates match
63
+ const minTime =
64
+ selectedDate &&
65
+ minDate &&
66
+ selectedDate.toDateString() === minDate.toDateString()
67
+ ? formatTimeStr(minDate)
68
+ : undefined;
69
+
70
+ const maxTime =
71
+ selectedDate &&
72
+ maxDate &&
73
+ selectedDate.toDateString() === maxDate.toDateString()
74
+ ? formatTimeStr(maxDate)
75
+ : undefined;
76
+
77
+ useEffect(() => {
78
+ const adjustPosition = () => {
79
+ if (containerRef.current && pickerRef.current) {
80
+ const relativeRect = containerRef.current.getBoundingClientRect();
81
+ const absoluteRect = pickerRef.current.getBoundingClientRect();
82
+
83
+ const spaceBelow = window.innerHeight - relativeRect.bottom;
84
+ const spaceAbove = relativeRect.top;
85
+
86
+ // Check if there is more space above than below
87
+ if (
88
+ spaceBelow < absoluteRect.height &&
89
+ spaceAbove >= absoluteRect.height
90
+ ) {
91
+ setDatePickerPosition('top');
92
+ } else {
93
+ setDatePickerPosition('bottom');
94
+ }
95
+ }
96
+ };
97
+
98
+ // Initial check
99
+ adjustPosition();
100
+
101
+ // Adjust position on window resize
102
+ window.addEventListener('resize', adjustPosition);
103
+ return () => window.removeEventListener('resize', adjustPosition);
104
+ }, []);
105
+
106
+ const calendarStyle = {
107
+ '--rdp-day-width': calendarWidth ? `${calendarWidth / 7 - 4}px` : undefined,
108
+ } as React.CSSProperties;
109
+
110
+ const handleTimeChange = (time: string) => {
111
+ setTimeValue(time);
112
+ if (selectedDate) {
113
+ const [hoursStr, minutesStr] = time.split(':');
114
+ const newSelectedDate = new Date(selectedDate);
115
+ newSelectedDate.setHours(parseInt(hoursStr ? hoursStr : '0', 10));
116
+ newSelectedDate.setMinutes(
117
+ parseInt(minutesStr ? minutesStr : '0', 10) || 0
118
+ );
119
+ setSelectedDate(newSelectedDate);
120
+ }
121
+ };
122
+
123
+ const handleDaySelect = (date: Date | undefined) => {
124
+ if (!timeValue || !date) {
125
+ // if need to set time to current time in case no time selected
126
+ const now = new Date();
127
+ date?.setHours(now.getHours(), now.getMinutes(), now.getSeconds());
128
+
129
+ setSelectedDate(date);
130
+ } else {
131
+ const [hoursStr, minutesStr] = timeValue.split(':');
132
+ date.setHours(parseInt(hoursStr ? hoursStr : '0', 10) || 0);
133
+ date.setMinutes(parseInt(minutesStr ? minutesStr : '0', 10) || 0);
134
+ setSelectedDate(date);
135
+ }
136
+ };
137
+
138
+ const handleSave = () => {
139
+ onChange(selectedDate);
140
+ resetAndCloseDatePicker();
141
+ };
142
+
143
+ const handleDateInputClick = () => {
144
+ setIsPickerOpen((prev) => !prev);
145
+ setView('days');
146
+ setSelectedMonth(value ?? new Date());
147
+ };
148
+
149
+ const handleClickOutside = (event: MouseEvent) => {
150
+ if (
151
+ pickerRef.current &&
152
+ !pickerRef.current.contains(event.target as Node)
153
+ ) {
154
+ resetAndCloseDatePicker();
155
+ }
156
+ };
157
+
158
+ const handleCancel = () => {
159
+ resetAndCloseDatePicker();
160
+ };
161
+
162
+ const resetAndCloseDatePicker = () => {
163
+ setIsPickerOpen(false); // Close the picker if the click was outside
164
+ setView('days'); // Return to default day view on close of day picker
165
+ setSelectedMonth(value ?? new Date());
166
+ };
167
+
168
+ useEffect(() => {
169
+ if (isPickerOpen) {
170
+ document.addEventListener('mousedown', handleClickOutside);
171
+ } else {
172
+ document.removeEventListener('mousedown', handleClickOutside);
173
+ }
174
+ return () => {
175
+ document.removeEventListener('mousedown', handleClickOutside); // Clean up the event listener
176
+ };
177
+ }, [isPickerOpen]);
178
+
179
+ const months = Array.from({ length: 12 }, (_, i) =>
180
+ new Date(0, i).toLocaleString('default', { month: 'long' })
181
+ );
182
+ const years = Array.from({ length: 12 }, (_, i) => startYear + i);
183
+
184
+ const handleMonthClick = () => setView('months');
185
+ const handleYearClick = () => setView('years');
186
+
187
+ const handleMonthSelect = (monthIndex: number) => {
188
+ const newDate = new Date(selectedMonth || '');
189
+ newDate.setMonth(monthIndex);
190
+ setSelectedMonth(newDate);
191
+ setView('days');
192
+ };
193
+
194
+ const handleYearSelect = (year: number) => {
195
+ const newDate = new Date(selectedMonth || '');
196
+ newDate.setFullYear(year);
197
+ setSelectedMonth(newDate);
198
+ setView('days');
199
+ };
200
+
201
+ const handleNextClick = () => {
202
+ if (view === 'years') {
203
+ setStartYear((prev) => prev + 12);
204
+ }
205
+ };
206
+
207
+ const handlePrevClick = () => {
208
+ if (view === 'years') {
209
+ setStartYear((prev) => prev - 12);
210
+ }
211
+ };
212
+
213
+ useEffect(() => {
214
+ if (isPickerOpen && view === 'years') {
215
+ const currentYear =
216
+ selectedMonth?.getFullYear() ?? new Date().getFullYear();
217
+ setStartYear(currentYear - (currentYear % 12)); // Reset to the first year in the range that contains the selected year
218
+ }
219
+ }, [isPickerOpen, selectedMonth, view]);
220
+
221
+ // Custom Caption Component
222
+ const CustomCaption: React.FC<CustomCaptionProps> = ({ children }) => {
223
+ // If children is a React node (like an element), render it directly
224
+ if (React.isValidElement(children)) {
225
+ return <div>{children}</div>;
226
+ }
227
+
228
+ const [month = '', year = ''] = String(children).split(' ');
229
+
230
+ return (
231
+ <Typography
232
+ as="div"
233
+ fontWeight="medium"
234
+ lineHeight="16.8px"
235
+ className="ff-calendar-haeder"
236
+ >
237
+ <span onClick={handleMonthClick} className="ff-cursor-pointer">
238
+ {month}
239
+ </span>
240
+ <span onClick={handleYearClick} className="ff-cursor-pointer">
241
+ {year}
242
+ </span>
243
+ </Typography>
244
+ );
245
+ };
246
+
247
+ // Custom MonthGrid Component
248
+ const CustomMonthGrid: React.FC = () => {
249
+ return (
250
+ <div className="ff-custom-month_grid">
251
+ {months.map((month: string, index: number) => (
252
+ <div
253
+ key={index}
254
+ onClick={() => handleMonthSelect(index)}
255
+ className={classNames('ff-custom-month', {
256
+ 'ff-custom-month--selected': index === selectedMonth?.getMonth(),
257
+ })}
258
+ >
259
+ <Typography>{month}</Typography>
260
+ </div>
261
+ ))}
262
+ </div>
263
+ );
264
+ };
265
+
266
+ const CustomPrevButton: React.FC<CustomCalenderButtonProps> = ({
267
+ disabled,
268
+ onClick,
269
+ }) => {
270
+ return (
271
+ <button
272
+ className="ff-calendar-nav-button"
273
+ onClick={onClick}
274
+ disabled={disabled}
275
+ >
276
+ <Icon name="left_arrow_icon" height={12} width={12} />
277
+ </button>
278
+ );
279
+ };
280
+ const CustomNextButton: React.FC<CustomCalenderButtonProps> = ({
281
+ disabled,
282
+ onClick,
283
+ }) => {
284
+ return (
285
+ <button
286
+ className="ff-calendar-nav-button"
287
+ onClick={onClick}
288
+ disabled={disabled}
289
+ >
290
+ <Icon name="right_arrow_icon" height={12} width={12} />
291
+ </button>
292
+ );
293
+ };
294
+
295
+ // Custom YearGrid Component
296
+ const CustomYearGrid: React.FC = () => {
297
+ return (
298
+ <div className="ff-custom-year_grid">
299
+ {years.map((year: number) => (
300
+ <div
301
+ key={year}
302
+ onClick={() => handleYearSelect(year)}
303
+ className={classNames('ff-custom-year', {
304
+ 'ff-custom-year--selected': year === selectedMonth?.getFullYear(),
305
+ })}
306
+ >
307
+ <Typography>{year}</Typography>
308
+ </div>
309
+ ))}
310
+ </div>
311
+ );
312
+ };
313
+
314
+ return (
315
+ <div className="ff-date-picker" ref={containerRef}>
316
+ <div className="ff-datepicker-input-container">
317
+ <div className="ff-input-with-icon ff-date-input-field">
318
+ <Icon
319
+ name={'calendar_icon'}
320
+ hoverEffect={false}
321
+ className="ff-calendar-icon"
322
+ />
323
+ <input
324
+ type="text"
325
+ value={value ? formatInTimeZone(value, timezone, dateFormat) : ''}
326
+ readOnly
327
+ placeholder={placeholder}
328
+ className="ff-date-input"
329
+ disabled={disabled}
330
+ onClick={handleDateInputClick}
331
+ />
332
+ {helperText && error && (
333
+ <span
334
+ className={classNames('ff-date-input-message', {
335
+ 'ff-date-input-message--danger': !!error,
336
+ })}
337
+ >
338
+ {helperText}
339
+ </span>
340
+ )}
341
+ </div>
342
+
343
+ <div className="ff-input-with-icon ff-time-input-field">
344
+ <Icon
345
+ name={'clock_icon'}
346
+ hoverEffect={false}
347
+ className="ff-clock-icon"
348
+ />
349
+ <input
350
+ type="text"
351
+ placeholder="Select time"
352
+ className="ff-time-input"
353
+ value={value ? formatInTimeZone(value, timezone, timeFormat) : ''}
354
+ disabled={disabled}
355
+ onClick={handleDateInputClick}
356
+ readOnly
357
+ />
358
+ </div>
359
+ </div>
360
+
361
+ {isPickerOpen && (
362
+ <div
363
+ className="ff-date-picker-container"
364
+ ref={pickerRef}
365
+ style={{
366
+ top: datePickerPosition === 'top' ? 'auto' : '110%',
367
+ bottom: datePickerPosition === 'top' ? '110%' : 'auto',
368
+ }}
369
+ >
370
+ <div className="ff-calendar-container">
371
+ <DayPicker
372
+ style={calendarStyle}
373
+ className="ff-calendar"
374
+ mode="single"
375
+ selected={selectedDate}
376
+ onSelect={handleDaySelect}
377
+ month={selectedMonth}
378
+ onMonthChange={(month) => {
379
+ if (view === 'days') {
380
+ setSelectedMonth(month);
381
+ }
382
+ }}
383
+ onNextClick={handleNextClick}
384
+ onPrevClick={handlePrevClick}
385
+ disableNavigation={view === 'months'}
386
+ disabled={[
387
+ {
388
+ before: new Date(minDate ? minDate : ''),
389
+ after: new Date(maxDate ? maxDate : ''),
390
+ },
391
+ ]}
392
+ timeZone={timezone}
393
+ components={{
394
+ CaptionLabel: (props) => <CustomCaption {...props} />,
395
+ PreviousMonthButton: (props) => <CustomPrevButton {...props} />,
396
+ NextMonthButton: (props) => <CustomNextButton {...props} />,
397
+ ...(view === 'months'
398
+ ? {
399
+ MonthGrid: () => <CustomMonthGrid />,
400
+ }
401
+ : {}),
402
+ ...(view === 'years'
403
+ ? {
404
+ MonthGrid: () => <CustomYearGrid />,
405
+ }
406
+ : {}),
407
+ }}
408
+ />
409
+ <TimePicker
410
+ value={timeValue}
411
+ onChange={handleTimeChange}
412
+ minTime={minTime}
413
+ maxTime={maxTime}
414
+ onErrorChange={setTimeError}
415
+ />
416
+ </div>
417
+ <div className="ff-date-picker-controls">
418
+ <Button
419
+ className="ff-date-picker-button"
420
+ variant="secondary"
421
+ onClick={handleCancel}
422
+ label="Cancel"
423
+ />
424
+ <Button
425
+ className="ff-date-picker-button"
426
+ variant="primary"
427
+ onClick={handleSave}
428
+ label="Save"
429
+ disabled={timeError}
430
+ />
431
+ </div>
432
+ </div>
433
+ )}
434
+ </div>
435
+ );
436
+ };
437
+
438
+ export default CustomDatePicker;