digitinary-ui 1.0.4 → 1.0.6

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 (81) hide show
  1. package/dist/components/Accordion/Accordion.js +28 -0
  2. package/dist/components/Accordion/index.js +1 -0
  3. package/dist/components/Alert/Alert.js +58 -0
  4. package/dist/components/Alert/index.js +1 -0
  5. package/dist/components/Button/Button.js +17 -0
  6. package/dist/components/Button/index.js +1 -0
  7. package/dist/components/Card/Card.js +6 -0
  8. package/dist/components/Card/index.js +1 -0
  9. package/dist/components/Checkbox/Checkbox.js +8 -0
  10. package/dist/components/Checkbox/index.js +1 -0
  11. package/dist/components/Chip/Chip.js +18 -0
  12. package/dist/components/Chip/index.js +1 -0
  13. package/dist/components/Date/Date.js +460 -0
  14. package/dist/components/Date/index.js +1 -0
  15. package/dist/components/DateRange/DateRange.js +206 -0
  16. package/dist/components/DateRange/index.js +1 -0
  17. package/dist/components/Dialog/Dialog.js +36 -0
  18. package/dist/components/Dialog/index.js +1 -0
  19. package/dist/components/HelperText/HelperText.js +6 -0
  20. package/dist/components/HelperText/index.js +1 -0
  21. package/dist/components/Input/Input.js +38 -0
  22. package/dist/components/Input/index.js +1 -0
  23. package/dist/components/Label/Label.js +6 -0
  24. package/dist/components/Label/index.js +1 -0
  25. package/dist/components/Overlay/Overlay.js +8 -0
  26. package/dist/components/Overlay/index.js +1 -0
  27. package/dist/components/Pagination/Pagination.js +26 -0
  28. package/dist/components/Pagination/index.js +1 -0
  29. package/dist/components/Radio/Radio.js +8 -0
  30. package/dist/components/Radio/index.js +1 -0
  31. package/dist/components/RadioGroup/RadioGroup.js +14 -0
  32. package/dist/components/RadioGroup/index.js +1 -0
  33. package/dist/components/SelectGroup/SelectGroup.js +251 -0
  34. package/dist/components/SelectGroup/index.js +1 -0
  35. package/dist/components/SideDrawer/SideDrawer.js +54 -0
  36. package/dist/components/SideDrawer/index.js +1 -0
  37. package/dist/components/Switch/Switch.js +6 -0
  38. package/dist/components/Switch/index.js +1 -0
  39. package/dist/components/Table/Table.d.ts +1 -1
  40. package/dist/components/Table/Table.js +60 -0
  41. package/dist/components/Table/index.js +1 -0
  42. package/dist/components/TextArea/TextArea.d.ts +1 -1
  43. package/dist/components/TextArea/TextArea.js +30 -0
  44. package/dist/components/TextArea/index.js +1 -0
  45. package/dist/components/Tooltip/Tooltip.js +8 -0
  46. package/dist/components/index.js +19 -0
  47. package/dist/constants/index.js +5 -0
  48. package/dist/icons/AlertErrorIcon.js +3 -0
  49. package/dist/icons/AlertInfoIcon.js +3 -0
  50. package/dist/icons/AlertSuccessIcon.js +3 -0
  51. package/dist/icons/AlertWarningIcon.js +3 -0
  52. package/dist/icons/ArrowBottom.js +3 -0
  53. package/dist/icons/ArrowLeft.js +3 -0
  54. package/dist/icons/ArrowRight.js +3 -0
  55. package/dist/icons/ArrowUpIcon.js +3 -0
  56. package/dist/icons/Calendar.js +3 -0
  57. package/dist/icons/CheckMark.js +3 -0
  58. package/dist/icons/ClearField.js +3 -0
  59. package/dist/icons/CloseIcon.js +3 -0
  60. package/dist/icons/DoubleLeftArrow.js +3 -0
  61. package/dist/icons/DoubleRightArrow.js +3 -0
  62. package/dist/icons/ExcelIcon.js +3 -0
  63. package/dist/icons/HidePasswordIcon.js +3 -0
  64. package/dist/icons/InfoIcon.js +3 -0
  65. package/dist/icons/LeftArrowIcon.js +3 -0
  66. package/dist/icons/LoaderIcon.js +3 -0
  67. package/dist/icons/PdfIcon.js +3 -0
  68. package/dist/icons/RightArrowIcon.js +3 -0
  69. package/dist/icons/SearchIcon.js +3 -0
  70. package/dist/icons/SelectFieldDownArrow.js +3 -0
  71. package/dist/icons/SelectFieldUpArrow.js +3 -0
  72. package/dist/icons/ShowPasswordIcon.js +3 -0
  73. package/dist/icons/SortIcon.js +3 -0
  74. package/dist/index.js +3 -2
  75. package/dist/types/enums.js +25 -0
  76. package/dist/types/index.js +3 -0
  77. package/dist/types/interfaces.d.ts +4 -10
  78. package/dist/types/interfaces.js +1 -0
  79. package/dist/types/types.js +1 -0
  80. package/dist/utils/index.js +8 -0
  81. package/package.json +1 -1
@@ -0,0 +1,28 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { useState } from 'react';
3
+ import style from './accordion.module.scss';
4
+ import SelectFieldDownArrow from '../../icons/SelectFieldDownArrow';
5
+ const Accordion = ({ defaultExpanded = false, expanded, disabled = false, onChange, summary, children, className, }) => {
6
+ const [isExpanded, setIsExpanded] = useState(defaultExpanded);
7
+ const isControlled = expanded !== undefined;
8
+ const toggleAccordion = () => {
9
+ if (disabled)
10
+ return;
11
+ if (isControlled && onChange) {
12
+ onChange();
13
+ }
14
+ else {
15
+ setIsExpanded(!isExpanded);
16
+ }
17
+ };
18
+ const handleKeyDown = (event) => {
19
+ if (disabled)
20
+ return;
21
+ if (event.key === 'Enter' || event.key === ' ') {
22
+ toggleAccordion();
23
+ }
24
+ };
25
+ const shouldExpand = isControlled ? expanded && !disabled : isExpanded && !disabled;
26
+ return (_jsxs("div", { className: `${style.accordion} ${shouldExpand ? style.expanded : ''} ${disabled ? style.disabled : ''} ${className}`, children: [_jsxs("div", { className: style.summary, onClick: toggleAccordion, onKeyDown: handleKeyDown, "aria-expanded": shouldExpand, role: "button", tabIndex: 0, children: [summary, _jsx("div", { className: style.iconContainer, children: _jsx(SelectFieldDownArrow, { "data-id": "ACCORDION_DROPDOWN_ARROW_ICON", className: `${style.dropdownIcon} ${shouldExpand ? style.rotateFlip : ''} ${disabled ? style.disabled : ''}`, width: "1.5rem", height: "1.5rem" }) })] }), _jsx("div", { className: `${style.details} ${shouldExpand ? style.show : ''}`, children: children })] }));
27
+ };
28
+ export default Accordion;
@@ -0,0 +1 @@
1
+ export { default } from './Accordion';
@@ -0,0 +1,58 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { useState, useEffect, useRef } from 'react';
3
+ import style from './alert.module.scss';
4
+ import ErrorAlert from '../../icons/AlertErrorIcon';
5
+ import WarningAlert from '../../icons/AlertWarningIcon';
6
+ import InfoAlert from '../../icons/AlertInfoIcon';
7
+ import NaturalAlert from '../../icons/InfoIcon';
8
+ import SuccessAlert from '../../icons/AlertSuccessIcon';
9
+ import CloseIcon from '../../icons/CloseIcon';
10
+ const severityMap = {
11
+ info: InfoAlert,
12
+ success: SuccessAlert,
13
+ error: ErrorAlert,
14
+ warning: WarningAlert,
15
+ natural: NaturalAlert,
16
+ };
17
+ const Alert = ({ severity = 'info', color = severity, variant = 'default', onClose, action, className, icon = true, // Default to true, showing the icon based on severity
18
+ customStyle, children, }) => {
19
+ const IconComponent = severityMap[severity];
20
+ const [visible, setVisible] = useState(true);
21
+ const [exitTransition, setExitTransition] = useState(false);
22
+ const actionBtnRef = useRef(null);
23
+ const alertContentRef = useRef(null);
24
+ const handleClose = () => {
25
+ setExitTransition(true);
26
+ if (typeof onClose === 'function')
27
+ onClose();
28
+ setTimeout(() => {
29
+ setVisible(false);
30
+ }, 500);
31
+ };
32
+ useEffect(() => {
33
+ let offsetWidth = 0;
34
+ if (actionBtnRef.current) {
35
+ const actionBtnWidth = actionBtnRef.current.offsetWidth / 16;
36
+ offsetWidth += actionBtnWidth;
37
+ }
38
+ if (onClose) {
39
+ offsetWidth += 1.5;
40
+ }
41
+ if (actionBtnRef.current || onClose) {
42
+ offsetWidth += 1;
43
+ }
44
+ if (alertContentRef.current) {
45
+ alertContentRef.current.style.marginRight = `${offsetWidth}rem`;
46
+ }
47
+ }, []);
48
+ if (!visible)
49
+ return null;
50
+ return (_jsxs("div", { className: `${className} ${style.alertContainer} ${style[color]} ${style[variant]} ${exitTransition ? style.exit : ''}`, style: customStyle, role: "alert", "data-id": `ALERT${severity ? `_${severity?.toUpperCase()}_ID` : ''}`, children: [icon === true ? (
51
+ // Default icon based on severity
52
+ _jsx(IconComponent, { className: `${style.alertIcon} ${style[color]} ${style[variant]}`, width: "1.25rem", height: "1.25rem", "data-id": "ALERT-ICON" })) : icon ? ( // Render custom icon if icon is JSX.Element
53
+ icon) : null, _jsx("div", { className: style.alertContent, ref: alertContentRef, children: children }), _jsxs("div", { className: style.actionContainer, children: [action && (_jsx("div", { className: style.actionButton, ref: actionBtnRef, children: action })), onClose && (_jsx(CloseIcon, { className: style.closeIcon, width: "1.25rem", height: "1.25rem", "data-id": "CLOSE-ICON", tabIndex: 0, onKeyDown: (e) => {
54
+ if (e.key === 'Enter' || e.key === ' ')
55
+ handleClose();
56
+ }, onClick: handleClose, "aria-label": "Close alert" }))] })] }));
57
+ };
58
+ export default Alert;
@@ -0,0 +1 @@
1
+ export { default } from './Alert';
@@ -0,0 +1,17 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import styles from './button.module.scss';
3
+ import LoaderIcon from '../../icons/LoaderIcon';
4
+ import { Size } from '../../types';
5
+ const Button = ({ children, className = '', variant = 'contained', color = 'primary', size = Size.Medium, type = 'button', disabled, loading, startIcon, endIcon, fullWidth, onKeyDown, onClick, active, ...props }) => {
6
+ return (_jsxs("button", { className: `${styles.customBtn}
7
+ ${styles[variant]}
8
+ ${styles[size]}
9
+ ${styles[color]}
10
+ ${disabled ? styles.disabled : ''}
11
+ ${loading ? styles.loading : ''}
12
+ ${active ? styles.active : ''}
13
+ ${fullWidth ? styles.fullWidth : ''}
14
+ ${className || ''}`, disabled: disabled || loading, type: type, onKeyDown: onKeyDown, onClick: onClick, "data-id": `${String(children).toUpperCase().replaceAll(' ', '_')}_BUTTON_ID`, ...props, children: [_jsxs("div", { className: styles.btnContentWrapper, children: [startIcon && _jsx("div", { className: styles.startBtnIcon, children: startIcon }), _jsx("div", { className: styles.btnContent, children: children }), endIcon && _jsx("div", { className: styles.endBtnIcon, children: endIcon })] }), loading && (_jsx("div", { className: styles.btnLoaderContainer, children: _jsx("div", { className: styles.btnLoaderIconContainer, children: _jsx(LoaderIcon, { className: styles.btnLoaderIcon, width: '1.5rem', height: '1.5rem' }) }) }))] }));
15
+ };
16
+ Button.displayName = 'Button';
17
+ export default Button;
@@ -0,0 +1 @@
1
+ export { default } from './Button';
@@ -0,0 +1,6 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import styles from './card.module.scss';
3
+ const Card = ({ header, children, footer, className = '', rounded = true }) => {
4
+ return (_jsxs("div", { className: `${styles.cardContainer} ${className} ${rounded ? styles.roundedCorners : ''}`, children: [header && _jsx("section", { className: styles.cardHeader, children: header }), children && _jsx("section", { className: styles.cardBody, children: children }), _jsx("section", { className: styles.cardFooter, children: footer })] }));
5
+ };
6
+ export default Card;
@@ -0,0 +1 @@
1
+ export { default } from './Card';
@@ -0,0 +1,8 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import CheckMark from '../../icons/CheckMark';
3
+ import styles from './checkbox.module.scss';
4
+ import { Position, Size } from '../../types';
5
+ const Checkbox = ({ label, labelPlacement = Position.Start, handleCheckboxChange, className = '', checked = false, size = Size.Medium, disabled = false, }) => {
6
+ return (_jsx("div", { className: `${styles.checkBox} ${className}`, children: _jsx("div", { className: styles.checkBoxItemsContainer, children: _jsxs("div", { className: `${styles.checkBoxItemContainer} ${styles[labelPlacement]}`, onClick: !disabled ? handleCheckboxChange : undefined, tabIndex: 0, children: [_jsx("div", { className: `${styles.itemCheckbox} ${disabled ? styles.disabledCheckbox : checked ? styles.checked : ''}`, children: checked && (_jsx(CheckMark, { width: size === 'small' ? '1.5rem' : size === 'large' ? '1rem' : '0.875rem', height: size === 'small' ? '1.5rem' : size === 'large' ? '1rem' : '0.875rem' })) }), _jsx("label", { className: `${styles.checkBoxItemLabel} ${styles[size] || styles.medium} ${disabled ? styles.disabledLabel : ''}`, children: label })] }) }) }));
7
+ };
8
+ export default Checkbox;
@@ -0,0 +1 @@
1
+ export { default } from './Checkbox';
@@ -0,0 +1,18 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import styles from './chip.module.scss';
3
+ import CloseIcon from '../../icons/CloseIcon';
4
+ import { Size } from '../../types';
5
+ const Chip = ({ className = '', color = 'primary', children, variant = 'filled', clickable, onClick, onDelete, size = Size.Small, id, }) => {
6
+ return (_jsxs("span", { className: `${styles.singleChip} ${styles[size]} ${variant === 'filled' ? styles[`chip-${color}`] : ''} ${className} ${clickable ? styles.clickable : ''}
7
+ ${variant === 'outlined'
8
+ ? styles[`outlinedChip-${color}`]
9
+ : clickable
10
+ ? styles[`clickable-${color}`]
11
+ : ''} `, onClick: onClick, children: [children, onDelete && (_jsx("div", { className: styles.deleteContainer, children: _jsx(CloseIcon, { onClick: (e) => {
12
+ e.stopPropagation();
13
+ if (id)
14
+ onDelete(id);
15
+ }, className: styles.chipCloseIcon, width: '0.875rem', height: '0.875rem', "data-id": "CHIPS_CLOSE_ICON" }) }))] }));
16
+ };
17
+ Chip.displayName = 'Chip';
18
+ export default Chip;
@@ -0,0 +1 @@
1
+ export { default } from './Chip';
@@ -0,0 +1,460 @@
1
+ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
2
+ import { useState, useEffect, useRef } from 'react';
3
+ import moment from 'moment';
4
+ import Button from '../Button';
5
+ import styles from './date.module.scss';
6
+ import ClearField from '../../icons/ClearField';
7
+ import CalendarIcon from '../../icons/Calendar';
8
+ import ArrowUpIcon from '../../icons/ArrowUpIcon';
9
+ import RightArrowIcon from '../../icons/RightArrowIcon';
10
+ import ArrowBottomIcon from '../../icons/ArrowBottom';
11
+ import LeftArrowIcon from '../../icons/LeftArrowIcon';
12
+ const Date = ({ id, label, placeholder, helperText, errorMsg, value, onChange, disabledDay, selectedEndDate, success, disabled, size = 'medium', clearable = true, disablePastDays, timePicker, isEndDay, defaultFormat = !timePicker ? 'DD MMM YYYY' : 'DD MMM YYYY HH:mm:ss', required, acceptSameDay, setCheckDateOpened, maxDate, minDate, className = '', dataId, }) => {
13
+ const presentDate = moment().startOf('day');
14
+ const years = getYears();
15
+ const datepickerRef = useRef(null);
16
+ const [currentMonth, setCurrentMonth] = useState(moment());
17
+ const [showDatePicker, setShowDatePicker] = useState(false);
18
+ const [calendarView, setCalendarView] = useState('daily');
19
+ const currentDate = moment();
20
+ const [yearsObj, setYearsObj] = useState({
21
+ currentView: Math.floor(years.length / 12 - 1),
22
+ itemsPerView: 12,
23
+ allYears: years,
24
+ });
25
+ const [time, setTime] = useState({
26
+ h: isEndDay && !value ? 23 : value ? Number(moment(value).format('H')) : 0,
27
+ mm: isEndDay && !value ? 59 : value ? Number(moment(value).format('m')) : 0,
28
+ ss: isEndDay && !value ? 59 : value ? Number(moment(value).format('s')) : 0,
29
+ });
30
+ const [selectedDate, setSelectedDate] = useState(moment());
31
+ const weekdaysShort = moment.weekdaysShort();
32
+ const weeks = getWeeksArray(currentMonth);
33
+ const monthsShort = moment.monthsShort();
34
+ const startYears = (yearsObj.currentView - 1) * yearsObj.itemsPerView;
35
+ const endYears = startYears + yearsObj.itemsPerView;
36
+ const displayedYears = yearsObj.allYears.slice(startYears, endYears);
37
+ const totalYears = Math.ceil(yearsObj.allYears.length / yearsObj.itemsPerView);
38
+ const nextMonthRefs = useRef(null);
39
+ const prevMonthRefs = useRef(null);
40
+ const [isEndDateCorrect, setIsEndDateCorrect] = useState(true);
41
+ const [isStartDateCorrect, setIsStartDateCorrect] = useState(true);
42
+ function timeKeyDown(e, increaseNum, decreaseNum) {
43
+ if (e.key === 'Enter' || e.key === ' ') {
44
+ submitDate();
45
+ e.stopPropagation();
46
+ e.preventDefault();
47
+ }
48
+ else if (e.key === 'ArrowUp') {
49
+ e.stopPropagation();
50
+ increaseNum();
51
+ e.preventDefault();
52
+ }
53
+ else if (e.key === 'ArrowDown') {
54
+ e.stopPropagation();
55
+ decreaseNum();
56
+ e.preventDefault();
57
+ }
58
+ }
59
+ function getYears() {
60
+ const years = [];
61
+ const pastYear = moment().subtract(100, 'years').year();
62
+ const futureYear = moment().add(30, 'years').year();
63
+ for (let year = pastYear; year <= futureYear; year++)
64
+ years.push(year);
65
+ return years;
66
+ }
67
+ function getWeeksArray(month) {
68
+ const firstDayOfMonth = moment(month).startOf('month');
69
+ const firstDayOfCalendar = moment(firstDayOfMonth).startOf('week');
70
+ const lastDayOfMonth = moment(month).endOf('month');
71
+ const numWeeks = lastDayOfMonth.diff(firstDayOfMonth, 'weeks') + 1;
72
+ const weeks = [];
73
+ for (let i = 0; i < numWeeks; i++) {
74
+ weeks.push(moment(firstDayOfCalendar).add(i, 'weeks'));
75
+ }
76
+ return weeks;
77
+ }
78
+ const increaseHours = () => {
79
+ if (time.h < 23)
80
+ setTime((prev) => ({ ...prev, h: prev.h + 1 }));
81
+ if (time.h === 23)
82
+ setTime((prev) => ({ ...prev, h: 0 }));
83
+ };
84
+ const decreaseHours = () => {
85
+ if (time.h > 0)
86
+ setTime((prev) => ({ ...prev, h: prev.h - 1 }));
87
+ if (time.h === 0)
88
+ setTime((prev) => ({ ...prev, h: 23 }));
89
+ };
90
+ const increaseMinuts = () => {
91
+ if (time.mm < 59)
92
+ setTime((prev) => ({ ...prev, mm: prev.mm + 1 }));
93
+ if (time.mm === 59)
94
+ setTime((prev) => ({ ...prev, mm: 0 }));
95
+ };
96
+ const decreaseMinuts = () => {
97
+ if (time.mm > 0)
98
+ setTime((prev) => ({ ...prev, mm: prev.mm - 1 }));
99
+ if (time.mm === 0)
100
+ setTime((prev) => ({ ...prev, mm: 59 }));
101
+ };
102
+ const increaseSeconds = () => {
103
+ if (time.ss < 59)
104
+ setTime((prev) => ({ ...prev, ss: prev.ss + 1 }));
105
+ if (time.ss === 59)
106
+ setTime((prev) => ({ ...prev, ss: 0 }));
107
+ };
108
+ const decreaseSeconds = () => {
109
+ if (time.ss > 0)
110
+ setTime((prev) => ({ ...prev, ss: prev.ss - 1 }));
111
+ if (time.ss === 0)
112
+ setTime((prev) => ({ ...prev, ss: 59 }));
113
+ };
114
+ const setTimeoutDisable = () => {
115
+ if (isEndDay) {
116
+ document.querySelectorAll(`.${styles.row} .${styles.dayUnit}`).forEach((cell) => {
117
+ const cellElement = cell;
118
+ if (disabledDay && moment(cellElement.dataset.val).isBefore(moment(disabledDay))) {
119
+ cellElement?.classList.add(styles.dayOff);
120
+ cellElement.disabled = true;
121
+ }
122
+ const endOfDay = moment(disabledDay).clone().endOf('day');
123
+ if (acceptSameDay) {
124
+ if (disabledDay && moment(cellElement.dataset.val).isBefore(moment(disabledDay))) {
125
+ cellElement?.classList.add(styles.dayOff);
126
+ cellElement.disabled = true;
127
+ }
128
+ }
129
+ else {
130
+ if (moment(disabledDay).format(defaultFormat) === moment(endOfDay).format(defaultFormat)) {
131
+ if (moment(cellElement.dataset.val).format('D') === moment(disabledDay).format('D')) {
132
+ cellElement?.classList.add(styles.dayOff);
133
+ cellElement.disabled = true;
134
+ }
135
+ }
136
+ }
137
+ });
138
+ }
139
+ else if (selectedEndDate) {
140
+ document.querySelectorAll(`.${styles.row} .${styles.dayUnit}`).forEach((cell) => {
141
+ const cellElement = cell;
142
+ if (moment(cellElement.dataset.val).isAfter(selectedEndDate)) {
143
+ cellElement?.classList.add(styles.dayOff);
144
+ cellElement.disabled = true;
145
+ }
146
+ });
147
+ }
148
+ };
149
+ useEffect(() => {
150
+ setSelectedDate(value === null ? '' : value);
151
+ }, [value]);
152
+ useEffect(() => {
153
+ setCheckDateOpened && setCheckDateOpened(showDatePicker);
154
+ }, [showDatePicker]);
155
+ const checkDate = (endDate) => {
156
+ if (disabledDay &&
157
+ (endDate ?? value) &&
158
+ id === 'end' &&
159
+ !acceptSameDay &&
160
+ moment(disabledDay).isSameOrAfter(moment(endDate ?? value))) {
161
+ setIsEndDateCorrect(false);
162
+ return false;
163
+ }
164
+ else {
165
+ setIsEndDateCorrect(true);
166
+ return true;
167
+ }
168
+ };
169
+ const excludePastDate = (startDate) => {
170
+ const currentDate = moment().format('DD MMM YYYY HH:mm');
171
+ if ((startDate ?? disabledDay) &&
172
+ id === 'start' &&
173
+ moment(currentDate).isAfter(moment(startDate ?? disabledDay).format('DD MMM YYYY HH:mm'))) {
174
+ setIsStartDateCorrect(false);
175
+ return false;
176
+ }
177
+ else {
178
+ setIsStartDateCorrect(true);
179
+ return true;
180
+ }
181
+ };
182
+ useEffect(() => {
183
+ const presentDateElement = document.querySelector(`.${styles.row} .${styles.dayUnit} .${styles.present}`);
184
+ const presentDateHtml = presentDateElement;
185
+ const presentDate = presentDateHtml ? presentDateHtml.dataset.val : null;
186
+ document.querySelectorAll(`.${styles.row} .${styles.dayUnit}`).forEach((cell) => {
187
+ const cellElement = cell;
188
+ if (presentDate &&
189
+ moment(cellElement.dataset.val, 'D MMM YYYY').isSame(moment(presentDate), 'day')) {
190
+ cellElement.classList.add(`${styles.present}`);
191
+ }
192
+ });
193
+ setTimeout(() => {
194
+ document.querySelectorAll(`.${styles.row} .${styles.dayUnit}`).forEach((selected) => {
195
+ const dataVal = selected.getAttribute('data-val');
196
+ if (dataVal) {
197
+ if (moment(dataVal).isSame(selectedDate, 'day')) {
198
+ selected.classList.add(`${styles.active}`);
199
+ }
200
+ else {
201
+ selected.classList.remove(`${styles.active}`);
202
+ }
203
+ }
204
+ });
205
+ document
206
+ .querySelectorAll(`.${styles.present}.${styles.active}`)
207
+ .forEach((cell) => cell.classList.remove(styles.present));
208
+ }, 0);
209
+ }, [showDatePicker, currentMonth, selectedDate]);
210
+ const excludePastDay = () => {
211
+ document.querySelectorAll(`.${styles.row} .${styles.dayUnit}`).forEach((cell) => {
212
+ const cellElement = cell;
213
+ if (moment(cellElement.dataset.val) < presentDate) {
214
+ cellElement?.classList.add(styles.dayOff);
215
+ cellElement.disabled = true;
216
+ }
217
+ });
218
+ };
219
+ const handleMinDate = () => {
220
+ const datepickerFrom = document.getElementById('datepicker-from');
221
+ if (datepickerFrom) {
222
+ const dayUnits = datepickerFrom.querySelectorAll('[data-val]');
223
+ dayUnits.forEach((cell) => {
224
+ const dataVal = cell.getAttribute('data-val');
225
+ if (moment(dataVal).format('YYYY-MM-DD') < moment(minDate).format('YYYY-MM-DD')) {
226
+ cell.classList.add(styles.dayOff);
227
+ cell.disabled = true;
228
+ }
229
+ });
230
+ }
231
+ };
232
+ const handleMaxDate = () => {
233
+ const datepickerFrom = document.getElementById('datepicker-from');
234
+ if (datepickerFrom) {
235
+ const dayUnits = datepickerFrom.querySelectorAll('[data-val]');
236
+ dayUnits.forEach((cell) => {
237
+ const dataVal = cell.getAttribute('data-val');
238
+ if (moment(dataVal).format('YYYY-MM-DD') > moment(maxDate).format('YYYY-MM-DD')) {
239
+ cell.classList.add(styles.dayOff);
240
+ cell.disabled = true;
241
+ }
242
+ });
243
+ }
244
+ };
245
+ useEffect(() => {
246
+ setTimeoutDisable();
247
+ if (disablePastDays) {
248
+ excludePastDay();
249
+ }
250
+ else if (maxDate) {
251
+ handleMaxDate();
252
+ }
253
+ }, [currentMonth, calendarView, showDatePicker, yearsObj]);
254
+ useEffect(() => {
255
+ if (minDate) {
256
+ handleMinDate();
257
+ }
258
+ }, [currentMonth, calendarView, showDatePicker, yearsObj]);
259
+ const handlePrev = () => {
260
+ switch (calendarView) {
261
+ case 'daily':
262
+ return setCurrentMonth(moment(currentMonth).subtract(1, 'month'));
263
+ case 'monthly':
264
+ return setCurrentMonth(moment(currentMonth).subtract(1, 'year'));
265
+ case 'yearly':
266
+ if (yearsObj.currentView) {
267
+ return setYearsObj((prev) => ({
268
+ ...prev,
269
+ currentView: yearsObj.currentView - 1,
270
+ }));
271
+ }
272
+ else {
273
+ return null;
274
+ }
275
+ default:
276
+ }
277
+ };
278
+ const handleNext = () => {
279
+ switch (calendarView) {
280
+ case 'daily':
281
+ return setCurrentMonth(moment(currentMonth).add(1, 'month'));
282
+ case 'monthly':
283
+ return setCurrentMonth(moment(currentMonth).add(1, 'year'));
284
+ case 'yearly':
285
+ if (yearsObj.currentView < totalYears) {
286
+ setYearsObj((prev) => ({
287
+ ...prev,
288
+ currentView: yearsObj.currentView + 1,
289
+ }));
290
+ }
291
+ else {
292
+ return null;
293
+ }
294
+ default:
295
+ }
296
+ };
297
+ const hidePicker = () => {
298
+ if (id === 'end' && moment(disabledDay).isSameOrAfter(moment(value))) {
299
+ setShowDatePicker(true);
300
+ }
301
+ else if (id === 'end' && moment(disabledDay).isBefore(moment(value))) {
302
+ setShowDatePicker(false);
303
+ }
304
+ setShowDatePicker(false);
305
+ };
306
+ const showCalendarView = (view) => setCalendarView(view);
307
+ const handleFocus = () => {
308
+ setShowDatePicker(!showDatePicker);
309
+ setDate(value === null ? '' : value);
310
+ };
311
+ const selectView = (month, year) => {
312
+ if (calendarView === 'monthly') {
313
+ setCalendarView('daily');
314
+ setCurrentMonth(moment().month(month).year(Number(year)));
315
+ }
316
+ if (calendarView === 'yearly') {
317
+ setCalendarView('monthly');
318
+ setCurrentMonth(moment().month(month).year(Number(month)));
319
+ }
320
+ };
321
+ const setDate = (day) => {
322
+ setSelectedDate(moment(day).format(defaultFormat));
323
+ };
324
+ const submitDate = (submittedDate) => {
325
+ const isCorrect = checkDate(moment(submittedDate)
326
+ .set({ hour: time.h, minute: time.mm, second: time.ss })
327
+ .format(defaultFormat));
328
+ const isEndDateTimeCorrect = excludePastDate(moment(submittedDate)
329
+ .set({ hour: time.h, minute: time.mm, second: time.ss })
330
+ .format(defaultFormat));
331
+ if (id === 'end' && !isCorrect)
332
+ return;
333
+ if (id === 'start' && !isEndDateTimeCorrect && disablePastDays)
334
+ return;
335
+ hidePicker();
336
+ onChange(moment(submittedDate)
337
+ .set({ hour: time.h, minute: time.mm, second: time.ss })
338
+ .format(defaultFormat));
339
+ };
340
+ useEffect(() => {
341
+ function handleClickOutside(event) {
342
+ if (datepickerRef.current &&
343
+ !datepickerRef.current.contains(event.target) &&
344
+ event.target &&
345
+ !(event.target.matches &&
346
+ event.target.matches(`#${id ?? 'date-picker-id'}`))) {
347
+ hidePicker();
348
+ }
349
+ }
350
+ document.addEventListener('mousedown', handleClickOutside);
351
+ return () => document.removeEventListener('mousedown', handleClickOutside);
352
+ }, [datepickerRef]);
353
+ const clearTime = (id) => {
354
+ if (id === 'start') {
355
+ setTime({ h: 0, mm: 0, ss: 0 });
356
+ }
357
+ else if (id === 'end') {
358
+ setTime({ h: 23, mm: 59, ss: 59 });
359
+ }
360
+ else
361
+ return;
362
+ };
363
+ const [flipDropdown, setFlipDropdown] = useState(false);
364
+ const isInViewport = (element, timePicker) => {
365
+ if (element) {
366
+ const rect = element.getBoundingClientRect();
367
+ const coordinationElement = document.elementFromPoint(rect.left + 50, rect.bottom - 30);
368
+ const foundLastItemInList = Array.from(element.children).find((child) => child === coordinationElement);
369
+ const isOverlapped = !foundLastItemInList ? 0 : 150;
370
+ return timePicker
371
+ ? rect.bottom + 373 - (window.innerHeight - isOverlapped) >= 0
372
+ : rect.bottom + 287 - window.innerHeight >= 0;
373
+ }
374
+ // Return false if the element is falsy
375
+ return false;
376
+ };
377
+ useEffect(() => {
378
+ if (showDatePicker && datepickerRef.current) {
379
+ setFlipDropdown(isInViewport(datepickerRef.current));
380
+ }
381
+ else
382
+ setFlipDropdown(false);
383
+ }, [datepickerRef, showDatePicker]);
384
+ return (_jsxs("div", { className: `${styles.dateContainer} ${className}`, children: [label && (_jsxs("label", { htmlFor: id, className: styles.dateLabel, "data-id": `${String(dataId ?? label)
385
+ .toUpperCase()
386
+ .replaceAll(' ', '_')}_FIELD_LABEL_ID`, children: [label, required && _jsx("span", { className: styles.star, children: "*" })] })), _jsxs("div", { className: styles.dateInputContainer, ref: datepickerRef, children: [_jsxs("div", { className: `${styles.inputIconsContainer} ${disabled ? styles.disabled : ''} ${styles[size]} ${errorMsg ? styles.error : ''} ${success ? styles.success : ''} ${!value ? styles.placeholder : ''}`, children: [_jsx("input", { id: id, className: `${styles.dateInput} ${disabled ? styles.disabled : ''}`, onChange: (e) => onChange(e.target.value), disabled: disabled, value: value ?? '', placeholder: placeholder, readOnly: true, "data-id": `${String(dataId ?? label)
387
+ ?.toUpperCase()
388
+ .replaceAll(' ', '_')}_FIELD_ID`, onClick: () => handleFocus(), onKeyDown: (e) => {
389
+ if (e.key === 'Enter' || e.key === ' ') {
390
+ e.stopPropagation();
391
+ e.preventDefault();
392
+ setShowDatePicker(!showDatePicker);
393
+ }
394
+ }, autoComplete: "off" }), helperText && _jsx("span", { className: styles.dateHelper, children: helperText }), errorMsg && _jsx("span", { className: styles.dateError, children: errorMsg }), _jsxs("div", { className: `${styles.iconsContainer} ${disabled ? styles.disabled : ''}`, onClick: () => !disabled && handleFocus(), children: [clearable && value && !disabled && (_jsx(ClearField, { className: styles.clearIcon, width: '1rem', height: '1rem', onClick: (e) => {
395
+ e.stopPropagation();
396
+ onChange(null);
397
+ clearTime(id);
398
+ setShowDatePicker(false);
399
+ }, "data-id": 'CLEAR_ICON_ID' })), _jsx(CalendarIcon, { className: `${styles.calendarIcon} ${disabled ? styles.disabled : ''} ${value ? styles.activeContent : ''}`, width: 24, height: 24, onClick: (e) => {
400
+ !disabled && handleFocus();
401
+ e.stopPropagation();
402
+ }, "data-id": "CALENDER_ICON" })] })] }), showDatePicker && (_jsxs("div", { id: "datepicker-from", className: `${styles.datepicker} ${flipDropdown ? styles[`flip-${size}`] : ''}`, children: [_jsxs("div", { className: styles.datepickerCalendar, children: [_jsxs("div", { className: styles.header, children: [_jsxs("div", { className: styles.headerDates, children: [_jsx("button", { type: "button", className: `${styles.monthChange} ${styles.goToPreviousMonth}`, ref: (ref) => (prevMonthRefs.current = ref), onKeyDown: (e) => {
403
+ if (e.key === 'Enter' || e.key === ' ') {
404
+ handlePrev();
405
+ e.preventDefault();
406
+ e.stopPropagation();
407
+ }
408
+ }, onClick: (e) => {
409
+ e.preventDefault();
410
+ handlePrev();
411
+ }, "data-id": "PREVIOUS_DAY", children: _jsx(LeftArrowIcon, { width: '0.875rem', height: '0.875rem' }) }), _jsxs("span", { className: `${styles.headerDates} ${styles.YearAndMonth}`, children: [calendarView === 'daily' && (_jsx("span", {
412
+ // className={styles.pickMonth}
413
+ className: `${styles.pickMonth} ${moment(currentMonth).format('MMMM') === moment(currentDate).format('MMMM')
414
+ ? styles.active
415
+ : ''}`, "data-id": "PICK_MONTH", onClick: () => showCalendarView('monthly'), children: currentMonth.format('MMMM') })), (calendarView === 'monthly' || calendarView === 'daily') && (_jsx("span", { className: styles.pickYear, "data-id": "PICK_YEAR", onClick: () => showCalendarView('yearly'), children: currentMonth.format('YYYY') })), calendarView === 'yearly' && (_jsx("span", { className: styles.selectYear, children: "Select a Year" }))] }), _jsx("button", { type: "button", "data-id": "NEXT_DAY", className: `${styles.monthChange} ${styles.goToNextMonth}`, ref: (ref) => (nextMonthRefs.current = ref), onKeyDown: (e) => {
416
+ if (e.key === 'Enter' || e.key === ' ') {
417
+ e.preventDefault();
418
+ handleNext();
419
+ }
420
+ }, onClick: (e) => {
421
+ handleNext();
422
+ e.preventDefault();
423
+ e.stopPropagation();
424
+ }, children: _jsx(RightArrowIcon, { width: '0.875rem', height: '0.875rem' }) })] }), _jsx("div", { className: styles.headerDaysRow, children: calendarView === 'daily' &&
425
+ weekdaysShort?.map((day, idx) => (_jsx("span", { className: styles.dayName, children: day }, idx))) })] }), _jsxs("div", { className: styles.bodyDaysRow, children: [calendarView === 'daily' &&
426
+ weeks?.map((week) => {
427
+ return (_jsx("div", { className: styles.row, children: Array.from({ length: 7 })?.map((_, i) => {
428
+ const day = moment(week).add(i, 'days');
429
+ const isCurrentMonth = day.isSame(currentMonth, 'month');
430
+ const isToday = day.isSame(moment(), 'day');
431
+ const className = isCurrentMonth
432
+ ? `${styles.currentMonth} ${isToday ? styles.active : ''}`
433
+ : styles.otherMonth;
434
+ return (_jsx("button", { type: "button", "data-val": moment(day)
435
+ .set({ hour: time.h, minute: time.mm, second: time.ss })
436
+ .format(defaultFormat), "data-disabledday": moment(disabledDay, defaultFormat).format('D/M'), className: `${styles.dayUnit} ${className}
437
+ ${day.isSame(moment(currentDate), 'day') ? styles.present : ''}`, onClick: (e) => {
438
+ e.preventDefault();
439
+ timePicker
440
+ ? setDate(day)
441
+ : submitDate(moment(day).format(defaultFormat));
442
+ }, children: day.format('D') }, day.format(defaultFormat)));
443
+ }) }, week.format(defaultFormat)));
444
+ }), calendarView === 'monthly' && (_jsx("div", { className: styles.bodyMonthsView, children: monthsShort?.map((month, index) => {
445
+ return (_jsx("button", { type: "button", onClick: () => selectView(index, currentMonth.format('YYYY')), className: `${styles.month} ${index === moment(selectedDate).month() ? styles.active : ''}`, children: _jsx("span", { children: month }) }, month));
446
+ }) })), calendarView === 'yearly' && (_jsx("div", { className: styles.bodyYearsView, children: displayedYears?.map((year) => (_jsx("button", { type: "button", onClick: () => selectView(year), className: `${styles.year} ${year === moment(selectedDate).year() ? styles.active : ''}`, children: _jsx("span", { children: year }) }, year))) }))] })] }), timePicker && (_jsxs(_Fragment, { children: [_jsx("hr", { className: styles.separator }), _jsxs("div", { className: styles.timePicker, children: [_jsxs("div", { className: styles.inputContainer, children: [_jsx("input", { className: `${styles.hours} ${!isEndDateCorrect || (!isStartDateCorrect && disablePastDays)
447
+ ? styles.errorInput
448
+ : ''}`, "data-id": "HOURS_TIME_PICKER", type: "number", value: time.h < 10 ? `0${time.h}` : time.h, readOnly: true, onKeyDown: (e) => timeKeyDown(e, increaseHours, decreaseHours) }), _jsxs("div", { className: styles.buttons, children: [_jsx("span", { className: styles.button, onClick: increaseHours, children: _jsx(ArrowBottomIcon, { width: '1.5rem', height: '1.5rem', "data-id": "DOWN_ARROW_HOURS_TIME_PICKER" }) }), _jsx("span", { className: styles.button, onClick: decreaseHours, children: _jsx(ArrowUpIcon, { width: '1.5rem', height: '1.5rem', "data-id": "UP_ARROW_HOURS_TIME_PICKER" }) })] })] }), _jsxs("div", { className: styles.inputContainer, children: [_jsx("input", { className: `${styles.minutes} ${!isEndDateCorrect || (!isStartDateCorrect && disablePastDays)
449
+ ? styles.errorInput
450
+ : ''}`, type: "number", "data-id": "MINUTED_TIME_PICKER", value: time.mm < 10 ? `0${time.mm}` : time.mm, readOnly: true, onKeyDown: (e) => timeKeyDown(e, increaseMinuts, decreaseMinuts) }), _jsxs("div", { className: styles.buttons, children: [_jsx("span", { className: styles.button, onClick: increaseMinuts, children: _jsx(ArrowBottomIcon, { width: '1.5rem', height: '1.5rem', "data-id": "DOWN_ARROW_MINUTED_TIME_PICKER" }) }), _jsx("span", { className: styles.button, onClick: decreaseMinuts, children: _jsx(ArrowUpIcon, { width: '1.5rem', height: '1.5rem', "data-id": "UP_ARROW_MINUTED_TIME_PICKER" }) })] })] }), _jsxs("div", { className: styles.inputContainer, children: [_jsx("input", { className: `${styles.seconds} ${!isEndDateCorrect || (!isStartDateCorrect && disablePastDays)
451
+ ? styles.errorInput
452
+ : ''}`, type: "number", "data-id": "SECONDS_TIME_PICKER", value: time.ss < 10 ? `0${time.ss}` : time.ss, readOnly: true, onKeyDown: (e) => timeKeyDown(e, increaseSeconds, decreaseSeconds) }), _jsxs("div", { className: styles.buttons, children: [_jsx("span", { className: styles.button, onClick: increaseSeconds, children: _jsx(ArrowBottomIcon, { width: '1.5rem', height: '1.5rem', "data-id": "DOWN_ARROW_SECONDS_TIME_PICKER" }) }), _jsx("span", { className: styles.button, onClick: decreaseSeconds, children: _jsx(ArrowUpIcon, { width: '1.5rem', height: '1.5rem', "data-id": "UP_ARROW_SECONDS_TIME_PICKER" }) })] })] }), !isEndDateCorrect || (!isStartDateCorrect && disablePastDays) ? (_jsx("span", { className: styles.errorTimeMessage, children: "Invalid Date" })) : null] }), _jsx(Button, { className: styles.submit, variant: "outlined", fullWidth: true, onClick: () => {
453
+ submitDate(selectedDate);
454
+ }, disabled: !selectedDate || selectedDate === 'Invalid date', onKeyDown: () => (e) => {
455
+ if (e.key === 'Enter' || e.key === ' ') {
456
+ submitDate(selectedDate);
457
+ }
458
+ }, children: "Submit" })] }))] }))] })] }));
459
+ };
460
+ export default Date;
@@ -0,0 +1 @@
1
+ export { default } from './Date';