krl-alfred 2.23.18 → 2.23.20

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 (47) hide show
  1. package/dist/components/Input/Input.d.ts +2 -2
  2. package/dist/components/Input/Input.js +50 -137
  3. package/dist/components/Input/Input.test.d.ts +1 -0
  4. package/dist/components/Input/Input.test.js +118 -0
  5. package/dist/components/Input/hooks/useDatePickerCalendar.d.ts +36 -0
  6. package/dist/components/Input/hooks/useDatePickerCalendar.js +87 -0
  7. package/dist/components/Input/hooks/useDatePickerCalendar.test.d.ts +1 -0
  8. package/dist/components/Input/hooks/useDatePickerCalendar.test.js +46 -0
  9. package/dist/components/Input/utils/datePicker.d.ts +7 -0
  10. package/dist/components/Input/utils/datePicker.js +60 -0
  11. package/dist/components/Input/utils/datePicker.test.d.ts +1 -0
  12. package/dist/components/Input/utils/datePicker.test.js +17 -0
  13. package/dist/components/RadioButton/layouts/basic/Basic.d.ts +1 -1
  14. package/dist/components/RadioButton/layouts/basic/Basic.js +10 -2
  15. package/dist/components/RadioButton/layouts/basic/Basic.styled.js +3 -2
  16. package/dist/components/RadioButton/layouts/boxed/Boxed.d.ts +1 -1
  17. package/dist/components/RadioButton/layouts/boxed/Boxed.js +10 -2
  18. package/dist/components/RadioButton/layouts/boxed/Boxed.styled.js +3 -2
  19. package/dist/components/RadioButton/layouts/boxedMd/BoxedMd.d.ts +1 -1
  20. package/dist/components/RadioButton/layouts/boxedMd/BoxedMd.js +10 -2
  21. package/dist/components/RadioButton/layouts/boxedMd/BoxedMd.styled.js +3 -2
  22. package/dist/components/RadioButton/layouts/boxedSm/BoxedSm.d.ts +1 -1
  23. package/dist/components/RadioButton/layouts/boxedSm/BoxedSm.js +10 -2
  24. package/dist/components/RadioButton/layouts/boxedSm/BoxedSm.styled.js +3 -2
  25. package/dist/components/RadioButton/layouts/boxedWithIcon/BoxedWithIcon.d.ts +1 -1
  26. package/dist/components/RadioButton/layouts/boxedWithIcon/BoxedWithIcon.js +9 -2
  27. package/dist/components/RadioButton/layouts/boxedWithIcon/BoxedWithIcon.styled.js +2 -1
  28. package/dist/components/RadioButton/layouts/color/Color.d.ts +1 -1
  29. package/dist/components/RadioButton/layouts/color/Color.js +10 -2
  30. package/dist/components/RadioButton/layouts/color/Color.styled.d.ts +1 -0
  31. package/dist/components/RadioButton/layouts/color/Color.styled.js +2 -1
  32. package/dist/components/RadioButton/layouts/horizontal/Horizontal.js +10 -2
  33. package/dist/components/RadioButton/layouts/horizontal/Horizontal.styled.d.ts +3 -2
  34. package/dist/components/RadioButton/layouts/horizontal/Horizontal.styled.js +4 -3
  35. package/dist/components/RadioButton/layouts/horizontal/Horizontal.test.js +17 -0
  36. package/dist/components/RadioButton/props.d.ts +3 -0
  37. package/dist/components/RadioButton/props.js +1 -0
  38. package/dist/components/RadioButton/stories/RadioButton.stories.d.ts +17 -0
  39. package/dist/components/RadioButton/stories/RadioButton.stories.js +16 -1
  40. package/dist/components/RadioButton/utils/radioInteraction.d.ts +35 -0
  41. package/dist/components/RadioButton/utils/radioInteraction.js +57 -0
  42. package/dist/components/RadioGroup/RadioGroup.js +1 -1
  43. package/dist/components/RadioGroup/RadioGroup.test.js +6 -0
  44. package/dist/components/RadioGroup/props.d.ts +2 -0
  45. package/dist/components/RadioGroup/stories/RadioGroup.stories.d.ts +94 -0
  46. package/dist/components/RadioGroup/stories/RadioGroup.stories.js +7 -1
  47. package/package.json +1 -1
@@ -1,4 +1,4 @@
1
- import React from "react";
2
- import { InputProps } from "./props";
1
+ import React from 'react';
2
+ import { InputProps } from './props';
3
3
  declare const Input: ({ hasError, disabled, label, customLinkText, customLinkHref, onCustomLinkClick, onChange, errorMessage, type, name, width, mask, placeholder, hasCopyButton, readOnly, autoFocus, value, format, visible, infoText, id, isClearable, onClear, hasNumericFormat, inline, minDate, maxDate, filterDate, onCalendarOpen, maxLength, showMaxLengthCounter, description, ...other }: InputProps) => React.JSX.Element;
4
4
  export default Input;
@@ -37,172 +37,85 @@ var Tooltip_1 = __importDefault(require("../Tooltip"));
37
37
  var react_datepicker_1 = __importDefault(require("react-datepicker"));
38
38
  var i18n_1 = __importDefault(require("../../i18n/i18n"));
39
39
  var locale_1 = require("date-fns/locale");
40
- var date_fns_1 = require("date-fns");
40
+ var useDatePickerCalendar_1 = require("./hooks/useDatePickerCalendar");
41
+ var datePicker_1 = require("./utils/datePicker");
41
42
  var Input = function (_a) {
42
43
  var _b = _a.hasError, hasError = _b === void 0 ? props_1.InputDefault.hasError : _b, _c = _a.disabled, disabled = _c === void 0 ? props_1.InputDefault.disabled : _c, _d = _a.label, label = _d === void 0 ? props_1.InputDefault.label : _d, _e = _a.customLinkText, customLinkText = _e === void 0 ? props_1.InputDefault.customLinkText : _e, _f = _a.customLinkHref, customLinkHref = _f === void 0 ? props_1.InputDefault.customLinkHref : _f, _g = _a.onCustomLinkClick, onCustomLinkClick = _g === void 0 ? props_1.InputDefault.onCustomLinkClick : _g, _h = _a.onChange, onChange = _h === void 0 ? props_1.InputDefault.onChange : _h, _j = _a.errorMessage, errorMessage = _j === void 0 ? props_1.InputDefault.errorMessage : _j, _k = _a.type, type = _k === void 0 ? props_1.InputDefault.type : _k, _l = _a.name, name = _l === void 0 ? props_1.InputDefault.name : _l, _m = _a.width, width = _m === void 0 ? props_1.InputDefault.width : _m, _o = _a.mask, mask = _o === void 0 ? props_1.InputDefault.mask : _o, _p = _a.placeholder, placeholder = _p === void 0 ? props_1.InputDefault.placeholder : _p, _q = _a.hasCopyButton, hasCopyButton = _q === void 0 ? props_1.InputDefault.hasCopyButton : _q, _r = _a.readOnly, readOnly = _r === void 0 ? props_1.InputDefault.readOnly : _r, _s = _a.autoFocus, autoFocus = _s === void 0 ? props_1.InputDefault.autoFocus : _s, value = _a.value, _t = _a.format, format = _t === void 0 ? props_1.InputDefault.format : _t, _u = _a.visible, visible = _u === void 0 ? props_1.InputDefault.visible : _u, _v = _a.infoText, infoText = _v === void 0 ? props_1.InputDefault.infoText : _v, _w = _a.id, id = _w === void 0 ? props_1.InputDefault.id : _w, _x = _a.isClearable, isClearable = _x === void 0 ? props_1.InputDefault.isClearable : _x, _y = _a.onClear, onClear = _y === void 0 ? props_1.InputDefault.onClear : _y, _z = _a.hasNumericFormat, hasNumericFormat = _z === void 0 ? props_1.InputDefault.hasNumericFormat : _z, _0 = _a.inline, inline = _0 === void 0 ? props_1.InputDefault.inline : _0, _1 = _a.minDate, minDate = _1 === void 0 ? props_1.InputDefault.minDate : _1, _2 = _a.maxDate, maxDate = _2 === void 0 ? props_1.InputDefault.maxDate : _2, _3 = _a.filterDate, filterDate = _3 === void 0 ? props_1.InputDefault.filterDate : _3, _4 = _a.onCalendarOpen, onCalendarOpen = _4 === void 0 ? props_1.InputDefault.onCalendarOpen : _4, _5 = _a.maxLength, maxLength = _5 === void 0 ? props_1.InputDefault.maxLength : _5, _6 = _a.showMaxLengthCounter, showMaxLengthCounter = _6 === void 0 ? props_1.InputDefault.showMaxLengthCounter : _6, _7 = _a.description, description = _7 === void 0 ? props_1.InputDefault.description : _7, other = __rest(_a, ["hasError", "disabled", "label", "customLinkText", "customLinkHref", "onCustomLinkClick", "onChange", "errorMessage", "type", "name", "width", "mask", "placeholder", "hasCopyButton", "readOnly", "autoFocus", "value", "format", "visible", "infoText", "id", "isClearable", "onClear", "hasNumericFormat", "inline", "minDate", "maxDate", "filterDate", "onCalendarOpen", "maxLength", "showMaxLengthCounter", "description"]);
43
44
  var _8 = (0, react_1.useState)(type), inputType = _8[0], setInputType = _8[1];
44
45
  var _9 = (0, react_1.useState)(false), alert = _9[0], setAlert = _9[1];
45
46
  var _10 = (0, react_1.useState)(value), inputValue = _10[0], setInputValue = _10[1];
46
- var _11 = (0, react_1.useState)(false), isCalendarOpen = _11[0], setIsCalendarOpen = _11[1];
47
- var _12 = (0, react_1.useState)(function () {
48
- if (!value)
49
- return null;
50
- // Eğer format "dd.MM.yyyy" gibi bir format ise, parse et
51
- if (format && format.includes('dd') && format.includes('MM') && format.includes('yyyy')) {
52
- try {
53
- return (0, date_fns_1.parse)(value, format, new Date());
54
- }
55
- catch (_a) {
56
- return new Date(value);
57
- }
58
- }
59
- return new Date(value);
60
- }), startDate = _12[0], setStartDate = _12[1];
47
+ var _11 = (0, react_1.useState)(function () { return (0, datePicker_1.parseDateValue)(value, format); }), startDate = _11[0], setStartDate = _11[1];
61
48
  var inputRef = (0, react_1.useRef)(null);
62
- var datePickerRef = (0, react_1.useRef)(null);
63
- var dateInputRef = (0, react_1.useRef)(null);
64
- var dateBlurTimeoutRef = (0, react_1.useRef)([]);
65
49
  var t = (0, react_i18next_1.useTranslation)().t;
66
50
  var language = i18n_1.default.language;
51
+ var _12 = (0, useDatePickerCalendar_1.useDatePickerCalendar)({
52
+ disabled: disabled,
53
+ inline: inline,
54
+ onCalendarOpen: onCalendarOpen,
55
+ readOnly: readOnly,
56
+ }), calendarControlProps = _12.calendarControlProps, dateInputRef = _12.dateInputRef, datePickerRef = _12.datePickerRef, isCalendarOpen = _12.isCalendarOpen;
67
57
  (0, react_1.useEffect)(function () {
68
58
  setInputType(type);
69
59
  }, [type]);
70
60
  (0, react_1.useEffect)(function () {
71
61
  setInputValue(value);
72
- if (!value) {
73
- setStartDate(null);
74
- }
75
- else {
76
- // Eğer format "dd.MM.yyyy" gibi bir format ise, parse et
77
- if (format && format.includes('dd') && format.includes('MM') && format.includes('yyyy')) {
78
- try {
79
- setStartDate((0, date_fns_1.parse)(value, format, new Date()));
80
- }
81
- catch (_a) {
82
- setStartDate(new Date(value));
83
- }
84
- }
85
- else {
86
- setStartDate(new Date(value));
87
- }
88
- }
89
- }, [value, format]);
62
+ setStartDate((0, datePicker_1.parseDateValue)(value, format));
63
+ }, [format, value]);
90
64
  (0, react_1.useEffect)(function () {
91
- if (alert) {
92
- setTimeout(function () {
93
- setAlert(false);
94
- }, 2000);
95
- }
65
+ if (!alert)
66
+ return;
67
+ var timeoutId = window.setTimeout(function () { return setAlert(false); }, 2000);
68
+ return function () { return window.clearTimeout(timeoutId); };
96
69
  }, [alert]);
97
70
  var toggleInputType = function () {
98
- var newType = inputType === 'password' ? 'text' : 'password';
99
- setInputType(newType);
71
+ setInputType(function (currentType) { return (currentType === 'password' ? 'text' : 'password'); });
100
72
  };
101
- var copyToClipboard = function (e) {
73
+ var copyToClipboard = function () {
74
+ if (!inputRef.current)
75
+ return;
102
76
  inputRef.current.select();
103
77
  document.execCommand('copy');
104
78
  setAlert(true);
105
79
  inputRef.current.blur();
106
80
  };
107
- var mergeInputRefs = function () {
108
- var refs = [];
109
- for (var _i = 0; _i < arguments.length; _i++) {
110
- refs[_i] = arguments[_i];
81
+ var handleDateChange = function (date) {
82
+ if (!date) {
83
+ setStartDate(null);
84
+ setInputValue('');
85
+ onChange === null || onChange === void 0 ? void 0 : onChange(null);
86
+ return;
111
87
  }
112
- return function (node) {
113
- refs.forEach(function (ref) {
114
- if (!ref)
115
- return;
116
- if (typeof ref === "function") {
117
- ref(node);
118
- }
119
- else {
120
- ref.current = node;
121
- }
122
- });
123
- };
88
+ var formattedValue = format ? (0, datePicker_1.formatDateValue)(date, format) : date.toISOString();
89
+ setStartDate(date);
90
+ setInputValue(formattedValue);
91
+ onChange === null || onChange === void 0 ? void 0 : onChange(formattedValue);
124
92
  };
125
- var clearScheduledDateBlur = function () {
126
- dateBlurTimeoutRef.current.forEach(function (timeoutId) { return window.clearTimeout(timeoutId); });
127
- dateBlurTimeoutRef.current = [];
128
- };
129
- var blurDateInputAfterSelect = (0, react_1.useCallback)(function () {
130
- if (inline)
131
- return;
132
- clearScheduledDateBlur();
133
- var blur = function () {
134
- var _a, _b, _c, _d, _e, _f;
135
- (_b = (_a = datePickerRef.current) === null || _a === void 0 ? void 0 : _a.setBlur) === null || _b === void 0 ? void 0 : _b.call(_a);
136
- (_c = dateInputRef.current) === null || _c === void 0 ? void 0 : _c.blur();
137
- (_f = (_e = (_d = datePickerRef.current) === null || _d === void 0 ? void 0 : _d.input) === null || _e === void 0 ? void 0 : _e.blur) === null || _f === void 0 ? void 0 : _f.call(_e);
138
- };
139
- [0, 10, 50].forEach(function (delay) {
140
- var timeoutId = window.setTimeout(blur, delay);
141
- dateBlurTimeoutRef.current.push(timeoutId);
142
- });
143
- }, [inline]);
144
- (0, react_1.useEffect)(function () { return function () { return clearScheduledDateBlur(); }; }, []);
145
93
  var CustomDateInput = (0, react_1.useMemo)(function () {
146
- return (0, react_1.forwardRef)(function (props, ref) {
147
- var displayValue = '';
148
- if (props.value && format) {
149
- try {
150
- var date = (0, date_fns_1.parse)(props.value, "yyyy-MM-dd", new Date());
151
- displayValue = (0, date_fns_1.format)(date, format);
152
- }
153
- catch (_a) {
154
- displayValue = inputValue || '';
155
- }
156
- }
157
- else {
158
- displayValue = inputValue || '';
159
- }
160
- return ((0, jsx_runtime_1.jsx)(Input_styled_1.InputStyled, __assign({ ref: mergeInputRefs(ref, dateInputRef), "$hasError": hasError, "$hasIcon": (isClearable && inputValue) || ["password", "date"].includes(type) || hasCopyButton || infoText, "$isCalendarOpen": isCalendarOpen }, props, { value: displayValue })));
161
- });
162
- }, [format, hasCopyButton, hasError, infoText, inputValue, isCalendarOpen, isClearable, type]);
94
+ return (0, react_1.forwardRef)(function (props, ref) { return ((0, jsx_runtime_1.jsx)(Input_styled_1.InputStyled, __assign({ ref: (0, datePicker_1.mergeInputRefs)(ref, dateInputRef), "$hasError": hasError, "$hasIcon": (isClearable && inputValue) || ['password', 'date'].includes(type) || hasCopyButton || infoText, "$isCalendarOpen": isCalendarOpen, id: id }, props, { value: (0, datePicker_1.getDateDisplayValue)(props.value, format, inputValue) }))); });
95
+ }, [dateInputRef, format, hasCopyButton, hasError, id, infoText, inputValue, isCalendarOpen, isClearable, type]);
163
96
  var handleClearValue = function () {
164
- setInputValue(null);
165
- inputRef.current.value = null;
166
- setStartDate(null);
167
- onChange(null);
168
- if (onClear)
169
- onClear();
97
+ var _a, _b;
98
+ setInputValue('');
99
+ if (type === 'date') {
100
+ setStartDate(null);
101
+ (_b = (_a = datePickerRef.current) === null || _a === void 0 ? void 0 : _a.clear) === null || _b === void 0 ? void 0 : _b.call(_a);
102
+ }
103
+ else if (inputRef.current) {
104
+ inputRef.current.value = '';
105
+ }
106
+ onChange === null || onChange === void 0 ? void 0 : onChange(null);
107
+ onClear === null || onClear === void 0 ? void 0 : onClear();
170
108
  };
171
109
  var currentLength = (inputValue !== null && inputValue !== void 0 ? inputValue : '').length;
172
110
  var showCharCount = showMaxLengthCounter && maxLength != null;
173
111
  var showTopRow = Boolean(label || customLinkText || showCharCount);
174
- return (0, jsx_runtime_1.jsxs)(Input_styled_1.Container, __assign({ "$width": width }, { children: [showTopRow && ((0, jsx_runtime_1.jsxs)(Input_styled_1.FieldTop, { children: [label ? (0, jsx_runtime_1.jsx)(Input_styled_1.FieldLabel, __assign({ htmlFor: id }, { children: label })) : (0, jsx_runtime_1.jsx)("span", {}), (0, jsx_runtime_1.jsxs)(Input_styled_1.FieldTopActions, { children: [showCharCount && ((0, jsx_runtime_1.jsxs)(Input_styled_1.CharCount, { children: [currentLength, "/", maxLength] })), customLinkText && ((0, jsx_runtime_1.jsx)(TextLink_1.default, __assign({}, (customLinkHref && { href: customLinkHref }), { onClick: onCustomLinkClick }, { children: customLinkText })))] })] })), (0, jsx_runtime_1.jsxs)("div", __assign({ className: "input" }, { children: [hasNumericFormat ? ((0, jsx_runtime_1.jsx)(react_number_format_1.NumericFormat, __assign({ "$hasError": hasError, disabled: disabled, onChange: onChange, name: name, placeholder: placeholder, readOnly: readOnly, autoFocus: autoFocus, value: inputValue, maxLength: maxLength }, other, { customInput: Input_styled_1.InputStyled, id: id }))) : ((mask && format) ? ((0, jsx_runtime_1.jsx)(react_number_format_1.PatternFormat, __assign({ "$hasError": hasError, disabled: disabled, onChange: onChange, name: name, placeholder: placeholder, readOnly: readOnly, autoFocus: autoFocus, value: inputValue, maxLength: maxLength }, other, { format: format, mask: mask, customInput: Input_styled_1.InputStyled, id: id })))
175
- : type === 'date' ? ((0, jsx_runtime_1.jsx)(Input_styled_1.DatePickerWrapperStyled, __assign({ "$inline": inline }, { children: (0, jsx_runtime_1.jsx)(react_datepicker_1.default, { placeholderText: placeholder, disabled: disabled, name: name, readOnly: readOnly, autoFocus: autoFocus, onChange: function (date) {
176
- if (date) {
177
- setStartDate(date);
178
- // DatePicker'dan gelen Date objesini format'a göre formatla
179
- var formattedValue = (0, date_fns_1.format)(date, format);
180
- setInputValue(formattedValue);
181
- onChange(formattedValue);
182
- }
183
- else {
184
- setStartDate(null);
185
- setInputValue(null);
186
- onChange(null);
187
- }
188
- }, onSelect: function () {
189
- blurDateInputAfterSelect();
190
- }, selected: startDate, ref: datePickerRef, dateFormat: "yyyy-MM-dd", locale: language === "tr" ? locale_1.tr : locale_1.enGB, customInput: (0, jsx_runtime_1.jsx)(CustomDateInput, {}),
191
- //customInput={<InputStyled $hasError={hasError} id={id}/>}
192
- inline: inline, minDate: minDate, maxDate: maxDate, filterDate: filterDate, onCalendarOpen: function () {
193
- setIsCalendarOpen(true);
194
- if (onCalendarOpen) {
195
- onCalendarOpen();
196
- }
197
- }, onCalendarClose: function () {
198
- setIsCalendarOpen(false);
199
- blurDateInputAfterSelect();
200
- }, onBlur: function () { return setIsCalendarOpen(false); }, renderCustomHeader: function (_a) {
201
- var monthDate = _a.monthDate, customHeaderCount = _a.customHeaderCount, decreaseMonth = _a.decreaseMonth, increaseMonth = _a.increaseMonth, decreaseYear = _a.decreaseYear, increaseYear = _a.increaseYear, prevMonthButtonDisabled = _a.prevMonthButtonDisabled, nextMonthButtonDisabled = _a.nextMonthButtonDisabled, prevYearButtonDisabled = _a.prevYearButtonDisabled, nextYearButtonDisabled = _a.nextYearButtonDisabled;
202
- return ((0, jsx_runtime_1.jsxs)("div", __assign({ className: "headerTopContent" }, { children: [(0, jsx_runtime_1.jsxs)("div", __assign({ className: "leftButtons" }, { children: [(0, jsx_runtime_1.jsx)("button", __assign({ "aria-label": "Previous Year", className: "react-datepicker__navigation react-datepicker__navigation--previous", onClick: decreaseYear, type: "button", disabled: prevYearButtonDisabled }, { children: (0, jsx_runtime_1.jsx)(Icon_1.default, { name: "CalenderArrowleftsmall" }) })), (0, jsx_runtime_1.jsx)("button", __assign({ "aria-label": "Previous Month", className: "react-datepicker__navigation react-datepicker__navigation--previous", onClick: decreaseMonth, type: "button", disabled: prevMonthButtonDisabled }, { children: (0, jsx_runtime_1.jsx)(Icon_1.default, { name: "ArrowSmallLeft" }) }))] })), (0, jsx_runtime_1.jsxs)("span", __assign({ className: "react-datepicker__current-month" }, { children: [monthDate.toLocaleString(language === "tr" ? "tr-TR" : "en-GB", { month: "long" }), ", ", monthDate.toLocaleString(language === "tr" ? "tr-TR" : "en-GB", { year: "numeric" })] })), (0, jsx_runtime_1.jsxs)("div", __assign({ className: "rightButtons" }, { children: [(0, jsx_runtime_1.jsx)("button", __assign({ "aria-label": "Next Month", className: "react-datepicker__navigation react-datepicker__navigation--next", onClick: increaseMonth, type: "button", disabled: nextMonthButtonDisabled }, { children: (0, jsx_runtime_1.jsx)(Icon_1.default, { name: "ArrowSmallRight" }) })), (0, jsx_runtime_1.jsx)("button", __assign({ "aria-label": "Next Year", className: "react-datepicker__navigation react-datepicker__navigation--next", onClick: increaseYear, type: "button", disabled: nextYearButtonDisabled }, { children: (0, jsx_runtime_1.jsx)(Icon_1.default, { name: "Calenderarrowrightsmall" }) }))] }))] })));
203
- } }) }))) : ((0, jsx_runtime_1.jsx)(Input_styled_1.InputStyled, __assign({ ref: inputRef, type: inputType, "$hasError": hasError, disabled: disabled, onChange: function (e) {
204
- onChange(e);
205
- setInputValue(e.currentTarget.value);
206
- }, name: name, placeholder: placeholder, readOnly: readOnly, autoFocus: autoFocus, value: inputValue, id: id, maxLength: maxLength, "$hasIcon": (isClearable && inputValue) || ["password", "date"].includes(type) || hasCopyButton || infoText }, other)))), (isClearable && inputValue) ? ((0, jsx_runtime_1.jsx)("div", __assign({ onClick: handleClearValue, className: "removeIcon" }, { children: (0, jsx_runtime_1.jsx)(Icon_1.default, { color: "var(--dark)", name: "Closebig" }) }))) : (type === 'password' ? ((0, jsx_runtime_1.jsx)("div", __assign({ onClick: toggleInputType, className: "inputIcon hasNoBg" }, { children: (0, jsx_runtime_1.jsx)(Icon_1.default, { color: "var(--dark-opacity-50)", name: inputType === 'password' ? 'Show' : 'Hide' }) }))) : (type === 'date' && !inline ? ((0, jsx_runtime_1.jsx)("div", __assign({ className: "inputIcon hasNoBg hasNoCursor" }, { children: (0, jsx_runtime_1.jsx)(Icon_1.default, { color: "var(--grey-50)", name: "Calendar" }) }))) : (hasCopyButton && ((0, jsx_runtime_1.jsx)("div", __assign({ onClick: copyToClipboard, className: "inputIcon" }, { children: (0, jsx_runtime_1.jsx)(Icon_1.default, { color: "var(--primary)", name: 'Copy' }) })))))), infoText && ((0, jsx_runtime_1.jsx)("div", __assign({ className: "inputIcon hasNoBg" }, { children: (0, jsx_runtime_1.jsx)(Tooltip_1.default, __assign({ popupSize: "small", position: "topRight", popupWidth: "160px", popupRight: "-10px", iconWidth: "24px", iconHeight: "24px" }, { children: (0, jsx_runtime_1.jsx)("div", { className: "popupText", dangerouslySetInnerHTML: { __html: infoText } }) })) }))), (0, jsx_runtime_1.jsx)(Input_styled_1.AlertStyled, __assign({ "$visible": alert }, { children: t('copied') }))] })), hasError && errorMessage && (0, jsx_runtime_1.jsxs)("div", __assign({ className: "error" }, { children: [(0, jsx_runtime_1.jsx)(Icon_1.default, { name: "SwitchPassive" }), (0, jsx_runtime_1.jsx)("p", { children: errorMessage })] })), description && (0, jsx_runtime_1.jsx)(Input_styled_1.FieldDescription, { children: description })] }));
112
+ var hasInputIcon = (isClearable && inputValue) || ['password', 'date'].includes(type) || hasCopyButton || infoText;
113
+ return ((0, jsx_runtime_1.jsxs)(Input_styled_1.Container, __assign({ "$width": width }, { children: [showTopRow && ((0, jsx_runtime_1.jsxs)(Input_styled_1.FieldTop, { children: [label ? (0, jsx_runtime_1.jsx)(Input_styled_1.FieldLabel, __assign({ htmlFor: id }, { children: label })) : (0, jsx_runtime_1.jsx)("span", {}), (0, jsx_runtime_1.jsxs)(Input_styled_1.FieldTopActions, { children: [showCharCount && ((0, jsx_runtime_1.jsxs)(Input_styled_1.CharCount, { children: [currentLength, "/", maxLength] })), customLinkText && ((0, jsx_runtime_1.jsx)(TextLink_1.default, __assign({}, (customLinkHref && { href: customLinkHref }), { onClick: onCustomLinkClick }, { children: customLinkText })))] })] })), (0, jsx_runtime_1.jsxs)("div", __assign({ className: "input" }, { children: [hasNumericFormat ? ((0, jsx_runtime_1.jsx)(react_number_format_1.NumericFormat, __assign({ "$hasError": hasError, disabled: disabled, onChange: onChange, name: name, placeholder: placeholder, readOnly: readOnly, autoFocus: autoFocus, value: inputValue, maxLength: maxLength }, other, { customInput: Input_styled_1.InputStyled, id: id }))) : mask && format ? ((0, jsx_runtime_1.jsx)(react_number_format_1.PatternFormat, __assign({ "$hasError": hasError, disabled: disabled, onChange: onChange, name: name, placeholder: placeholder, readOnly: readOnly, autoFocus: autoFocus, value: inputValue, maxLength: maxLength }, other, { format: format, mask: mask, customInput: Input_styled_1.InputStyled, id: id }))) : type === 'date' ? ((0, jsx_runtime_1.jsx)(Input_styled_1.DatePickerWrapperStyled, __assign({ "$inline": inline }, { children: (0, jsx_runtime_1.jsx)(react_datepicker_1.default, __assign({ placeholderText: placeholder, disabled: disabled, name: name, readOnly: readOnly, autoFocus: autoFocus, onChange: handleDateChange, selected: startDate, ref: datePickerRef, id: id, dateFormat: "yyyy-MM-dd", locale: language === 'tr' ? locale_1.tr : locale_1.enGB, customInput: (0, jsx_runtime_1.jsx)(CustomDateInput, {}), inline: inline, minDate: minDate, maxDate: maxDate, filterDate: filterDate, renderCustomHeader: function (_a) {
114
+ var monthDate = _a.monthDate, decreaseMonth = _a.decreaseMonth, increaseMonth = _a.increaseMonth, decreaseYear = _a.decreaseYear, increaseYear = _a.increaseYear, prevMonthButtonDisabled = _a.prevMonthButtonDisabled, nextMonthButtonDisabled = _a.nextMonthButtonDisabled, prevYearButtonDisabled = _a.prevYearButtonDisabled, nextYearButtonDisabled = _a.nextYearButtonDisabled;
115
+ return ((0, jsx_runtime_1.jsxs)("div", __assign({ className: "headerTopContent" }, { children: [(0, jsx_runtime_1.jsxs)("div", __assign({ className: "leftButtons" }, { children: [(0, jsx_runtime_1.jsx)("button", __assign({ "aria-label": "Previous Year", className: "react-datepicker__navigation react-datepicker__navigation--previous", onClick: decreaseYear, type: "button", disabled: prevYearButtonDisabled }, { children: (0, jsx_runtime_1.jsx)(Icon_1.default, { name: "CalenderArrowleftsmall" }) })), (0, jsx_runtime_1.jsx)("button", __assign({ "aria-label": "Previous Month", className: "react-datepicker__navigation react-datepicker__navigation--previous", onClick: decreaseMonth, type: "button", disabled: prevMonthButtonDisabled }, { children: (0, jsx_runtime_1.jsx)(Icon_1.default, { name: "ArrowSmallLeft" }) }))] })), (0, jsx_runtime_1.jsxs)("span", __assign({ className: "react-datepicker__current-month" }, { children: [monthDate.toLocaleString(language === 'tr' ? 'tr-TR' : 'en-GB', { month: 'long' }), ",", ' ', monthDate.toLocaleString(language === 'tr' ? 'tr-TR' : 'en-GB', { year: 'numeric' })] })), (0, jsx_runtime_1.jsxs)("div", __assign({ className: "rightButtons" }, { children: [(0, jsx_runtime_1.jsx)("button", __assign({ "aria-label": "Next Month", className: "react-datepicker__navigation react-datepicker__navigation--next", onClick: increaseMonth, type: "button", disabled: nextMonthButtonDisabled }, { children: (0, jsx_runtime_1.jsx)(Icon_1.default, { name: "ArrowSmallRight" }) })), (0, jsx_runtime_1.jsx)("button", __assign({ "aria-label": "Next Year", className: "react-datepicker__navigation react-datepicker__navigation--next", onClick: increaseYear, type: "button", disabled: nextYearButtonDisabled }, { children: (0, jsx_runtime_1.jsx)(Icon_1.default, { name: "Calenderarrowrightsmall" }) }))] }))] })));
116
+ } }, calendarControlProps)) }))) : ((0, jsx_runtime_1.jsx)(Input_styled_1.InputStyled, __assign({ ref: inputRef, type: inputType, "$hasError": hasError, disabled: disabled, onChange: function (e) {
117
+ onChange === null || onChange === void 0 ? void 0 : onChange(e);
118
+ setInputValue(e.currentTarget.value);
119
+ }, name: name, placeholder: placeholder, readOnly: readOnly, autoFocus: autoFocus, value: inputValue, id: id, maxLength: maxLength, "$hasIcon": hasInputIcon }, other))), isClearable && inputValue ? ((0, jsx_runtime_1.jsx)("div", __assign({ onClick: handleClearValue, className: "removeIcon" }, { children: (0, jsx_runtime_1.jsx)(Icon_1.default, { color: "var(--dark)", name: "Closebig" }) }))) : type === 'password' ? ((0, jsx_runtime_1.jsx)("div", __assign({ onClick: toggleInputType, className: "inputIcon hasNoBg" }, { children: (0, jsx_runtime_1.jsx)(Icon_1.default, { color: "var(--dark-opacity-50)", name: inputType === 'password' ? 'Show' : 'Hide' }) }))) : type === 'date' && !inline ? ((0, jsx_runtime_1.jsx)("div", __assign({ className: "inputIcon hasNoBg hasNoCursor" }, { children: (0, jsx_runtime_1.jsx)(Icon_1.default, { color: "var(--grey-50)", name: "Calendar" }) }))) : (hasCopyButton && ((0, jsx_runtime_1.jsx)("div", __assign({ onClick: copyToClipboard, className: "inputIcon" }, { children: (0, jsx_runtime_1.jsx)(Icon_1.default, { color: "var(--primary)", name: "Copy" }) })))), infoText && ((0, jsx_runtime_1.jsx)("div", __assign({ className: "inputIcon hasNoBg" }, { children: (0, jsx_runtime_1.jsx)(Tooltip_1.default, __assign({ popupSize: "small", position: "topRight", popupWidth: "160px", popupRight: "-10px", iconWidth: "24px", iconHeight: "24px" }, { children: (0, jsx_runtime_1.jsx)("div", { className: "popupText", dangerouslySetInnerHTML: { __html: infoText } }) })) }))), (0, jsx_runtime_1.jsx)(Input_styled_1.AlertStyled, __assign({ "$visible": alert }, { children: t('copied') }))] })), hasError && errorMessage && ((0, jsx_runtime_1.jsxs)("div", __assign({ className: "error" }, { children: [(0, jsx_runtime_1.jsx)(Icon_1.default, { name: "SwitchPassive" }), (0, jsx_runtime_1.jsx)("p", { children: errorMessage })] }))), description && (0, jsx_runtime_1.jsx)(Input_styled_1.FieldDescription, { children: description })] })));
207
120
  };
208
121
  exports.default = Input;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,118 @@
1
+ "use strict";
2
+ var __assign = (this && this.__assign) || function () {
3
+ __assign = Object.assign || function(t) {
4
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
5
+ s = arguments[i];
6
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
+ t[p] = s[p];
8
+ }
9
+ return t;
10
+ };
11
+ return __assign.apply(this, arguments);
12
+ };
13
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
14
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
15
+ return new (P || (P = Promise))(function (resolve, reject) {
16
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
17
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
18
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
19
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
20
+ });
21
+ };
22
+ var __generator = (this && this.__generator) || function (thisArg, body) {
23
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
24
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
25
+ function verb(n) { return function (v) { return step([n, v]); }; }
26
+ function step(op) {
27
+ if (f) throw new TypeError("Generator is already executing.");
28
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
29
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
30
+ if (y = 0, t) op = [op[0] & 2, t.value];
31
+ switch (op[0]) {
32
+ case 0: case 1: t = op; break;
33
+ case 4: _.label++; return { value: op[1], done: false };
34
+ case 5: _.label++; y = op[1]; op = [0]; continue;
35
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
36
+ default:
37
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
38
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
39
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
40
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
41
+ if (t[2]) _.ops.pop();
42
+ _.trys.pop(); continue;
43
+ }
44
+ op = body.call(thisArg, _);
45
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
46
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
47
+ }
48
+ };
49
+ var __importDefault = (this && this.__importDefault) || function (mod) {
50
+ return (mod && mod.__esModule) ? mod : { "default": mod };
51
+ };
52
+ Object.defineProperty(exports, "__esModule", { value: true });
53
+ var jsx_runtime_1 = require("react/jsx-runtime");
54
+ var react_1 = require("@testing-library/react");
55
+ var user_event_1 = __importDefault(require("@testing-library/user-event"));
56
+ var Input_1 = __importDefault(require("./Input"));
57
+ var props_1 = require("./props");
58
+ jest.mock('react-i18next', function () { return ({
59
+ useTranslation: function () { return ({
60
+ t: function (key) { return key; },
61
+ }); },
62
+ }); });
63
+ var renderInput = function (props) {
64
+ if (props === void 0) { props = {}; }
65
+ return (0, react_1.render)((0, jsx_runtime_1.jsx)(Input_1.default, __assign({}, props_1.InputDefault, { id: "input-test", label: "Label", onChange: jest.fn() }, props)));
66
+ };
67
+ describe('Input', function () {
68
+ it('renders label and placeholder', function () {
69
+ renderInput({ placeholder: 'Placeholder text' });
70
+ expect(react_1.screen.getByText('Label')).toBeInTheDocument();
71
+ expect(react_1.screen.getByPlaceholderText('Placeholder text')).toBeInTheDocument();
72
+ });
73
+ it('shows error message when hasError is true', function () {
74
+ renderInput({ hasError: true, errorMessage: 'Invalid value' });
75
+ expect(react_1.screen.getByText('Invalid value')).toBeInTheDocument();
76
+ });
77
+ it('toggles password visibility', function () { return __awaiter(void 0, void 0, void 0, function () {
78
+ var container, input;
79
+ return __generator(this, function (_a) {
80
+ switch (_a.label) {
81
+ case 0:
82
+ container = renderInput({ type: 'password', placeholder: 'Password' }).container;
83
+ input = react_1.screen.getByPlaceholderText('Password');
84
+ expect(input).toHaveAttribute('type', 'password');
85
+ return [4 /*yield*/, user_event_1.default.click(container.querySelector('.inputIcon'))];
86
+ case 1:
87
+ _a.sent();
88
+ expect(input).toHaveAttribute('type', 'text');
89
+ return [2 /*return*/];
90
+ }
91
+ });
92
+ }); });
93
+ it('calls onClear when clearable value is cleared', function () { return __awaiter(void 0, void 0, void 0, function () {
94
+ var onClear, onChange, container;
95
+ return __generator(this, function (_a) {
96
+ switch (_a.label) {
97
+ case 0:
98
+ onClear = jest.fn();
99
+ onChange = jest.fn();
100
+ container = renderInput({
101
+ isClearable: true,
102
+ value: 'Clear me',
103
+ onClear: onClear,
104
+ onChange: onChange,
105
+ }).container;
106
+ return [4 /*yield*/, user_event_1.default.click(container.querySelector('.removeIcon'))];
107
+ case 1:
108
+ _a.sent();
109
+ expect(onChange).toHaveBeenCalledWith(null);
110
+ expect(onClear).toHaveBeenCalledTimes(1);
111
+ return [2 /*return*/];
112
+ }
113
+ });
114
+ }); });
115
+ it('renders with potentially unsafe infoText without crashing', function () {
116
+ expect(function () { return renderInput({ infoText: '<script>alert(1)</script>Info' }); }).not.toThrow();
117
+ });
118
+ });
@@ -0,0 +1,36 @@
1
+ /// <reference types="react" />
2
+ import DatePicker from 'react-datepicker';
3
+ type UseDatePickerCalendarOptions = {
4
+ inline?: boolean;
5
+ disabled?: boolean;
6
+ readOnly?: boolean;
7
+ onCalendarOpen?: () => void;
8
+ };
9
+ export declare const useDatePickerCalendar: ({ inline, disabled, readOnly, onCalendarOpen, }: UseDatePickerCalendarOptions) => {
10
+ calendarControlProps: {
11
+ open?: undefined;
12
+ preventOpenOnFocus?: undefined;
13
+ shouldCloseOnSelect?: undefined;
14
+ usePointerEvent?: undefined;
15
+ onInputClick?: undefined;
16
+ onClickOutside?: undefined;
17
+ onCalendarOpen?: undefined;
18
+ onCalendarClose?: undefined;
19
+ onSelect?: undefined;
20
+ } | {
21
+ open: boolean;
22
+ preventOpenOnFocus: boolean;
23
+ shouldCloseOnSelect: boolean;
24
+ usePointerEvent: boolean;
25
+ onInputClick: () => void;
26
+ onClickOutside: () => void;
27
+ onCalendarOpen: () => void;
28
+ onCalendarClose: () => void;
29
+ onSelect: () => void;
30
+ };
31
+ closeCalendar: () => void;
32
+ dateInputRef: import("react").MutableRefObject<HTMLInputElement>;
33
+ datePickerRef: import("react").MutableRefObject<DatePicker>;
34
+ isCalendarOpen: boolean;
35
+ };
36
+ export {};
@@ -0,0 +1,87 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.useDatePickerCalendar = void 0;
4
+ var react_1 = require("react");
5
+ var datePicker_1 = require("../utils/datePicker");
6
+ var useDatePickerCalendar = function (_a) {
7
+ var _b = _a.inline, inline = _b === void 0 ? false : _b, _c = _a.disabled, disabled = _c === void 0 ? false : _c, _d = _a.readOnly, readOnly = _d === void 0 ? false : _d, onCalendarOpen = _a.onCalendarOpen;
8
+ var datePickerRef = (0, react_1.useRef)(null);
9
+ var dateInputRef = (0, react_1.useRef)(null);
10
+ var _e = (0, react_1.useState)(false), isCalendarOpen = _e[0], setIsCalendarOpen = _e[1];
11
+ var closeCalendar = (0, react_1.useCallback)(function () {
12
+ var _a, _b;
13
+ if (inline)
14
+ return;
15
+ setIsCalendarOpen(false);
16
+ (_b = (_a = datePickerRef.current) === null || _a === void 0 ? void 0 : _a.setOpen) === null || _b === void 0 ? void 0 : _b.call(_a, false, true);
17
+ }, [inline]);
18
+ var openCalendar = (0, react_1.useCallback)(function () {
19
+ var _a, _b;
20
+ if (inline || disabled || readOnly)
21
+ return;
22
+ setIsCalendarOpen(true);
23
+ (_b = (_a = datePickerRef.current) === null || _a === void 0 ? void 0 : _a.setOpen) === null || _b === void 0 ? void 0 : _b.call(_a, true);
24
+ }, [disabled, inline, readOnly]);
25
+ var toggleCalendar = (0, react_1.useCallback)(function () {
26
+ if (isCalendarOpen) {
27
+ closeCalendar();
28
+ return;
29
+ }
30
+ openCalendar();
31
+ }, [closeCalendar, isCalendarOpen, openCalendar]);
32
+ var handleCalendarOpen = (0, react_1.useCallback)(function () {
33
+ setIsCalendarOpen(true);
34
+ onCalendarOpen === null || onCalendarOpen === void 0 ? void 0 : onCalendarOpen();
35
+ }, [onCalendarOpen]);
36
+ var handleCalendarClose = (0, react_1.useCallback)(function () {
37
+ setIsCalendarOpen(false);
38
+ }, []);
39
+ var handleInputClick = (0, react_1.useCallback)(function () {
40
+ toggleCalendar();
41
+ }, [toggleCalendar]);
42
+ var handleClickOutside = (0, react_1.useCallback)(function () {
43
+ closeCalendar();
44
+ }, [closeCalendar]);
45
+ var handleDateSelect = (0, react_1.useCallback)(function () {
46
+ closeCalendar();
47
+ }, [closeCalendar]);
48
+ (0, react_1.useEffect)(function () {
49
+ if (inline || !isCalendarOpen)
50
+ return;
51
+ var handleOutsideInteraction = function (event) {
52
+ var target = event.target;
53
+ if (!(target instanceof Node))
54
+ return;
55
+ if (!(0, datePicker_1.isOutsideDatePicker)(target, dateInputRef.current))
56
+ return;
57
+ closeCalendar();
58
+ };
59
+ document.addEventListener('mousedown', handleOutsideInteraction);
60
+ document.addEventListener('touchstart', handleOutsideInteraction, { passive: true });
61
+ return function () {
62
+ document.removeEventListener('mousedown', handleOutsideInteraction);
63
+ document.removeEventListener('touchstart', handleOutsideInteraction);
64
+ };
65
+ }, [closeCalendar, inline, isCalendarOpen]);
66
+ var calendarControlProps = inline
67
+ ? {}
68
+ : {
69
+ open: isCalendarOpen,
70
+ preventOpenOnFocus: true,
71
+ shouldCloseOnSelect: true,
72
+ usePointerEvent: true,
73
+ onInputClick: handleInputClick,
74
+ onClickOutside: handleClickOutside,
75
+ onCalendarOpen: handleCalendarOpen,
76
+ onCalendarClose: handleCalendarClose,
77
+ onSelect: handleDateSelect,
78
+ };
79
+ return {
80
+ calendarControlProps: calendarControlProps,
81
+ closeCalendar: closeCalendar,
82
+ dateInputRef: dateInputRef,
83
+ datePickerRef: datePickerRef,
84
+ isCalendarOpen: isCalendarOpen,
85
+ };
86
+ };
87
+ exports.useDatePickerCalendar = useDatePickerCalendar;
@@ -0,0 +1,46 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ var react_1 = require("@testing-library/react");
4
+ var useDatePickerCalendar_1 = require("./useDatePickerCalendar");
5
+ describe('useDatePickerCalendar', function () {
6
+ it('toggles calendar open state through input click handler', function () {
7
+ var setOpen = jest.fn();
8
+ var result = (0, react_1.renderHook)(function () {
9
+ return (0, useDatePickerCalendar_1.useDatePickerCalendar)({
10
+ inline: false,
11
+ });
12
+ }).result;
13
+ (0, react_1.act)(function () {
14
+ var _a, _b;
15
+ result.current.datePickerRef.current = { setOpen: setOpen };
16
+ (_b = (_a = result.current.calendarControlProps).onInputClick) === null || _b === void 0 ? void 0 : _b.call(_a);
17
+ });
18
+ expect(result.current.isCalendarOpen).toBe(true);
19
+ expect(setOpen).toHaveBeenCalledWith(true);
20
+ (0, react_1.act)(function () {
21
+ var _a, _b;
22
+ (_b = (_a = result.current.calendarControlProps).onInputClick) === null || _b === void 0 ? void 0 : _b.call(_a);
23
+ });
24
+ expect(result.current.isCalendarOpen).toBe(false);
25
+ expect(setOpen).toHaveBeenCalledWith(false, true);
26
+ });
27
+ it('closes calendar on outside touch interaction', function () {
28
+ var setOpen = jest.fn();
29
+ var result = (0, react_1.renderHook)(function () {
30
+ return (0, useDatePickerCalendar_1.useDatePickerCalendar)({
31
+ inline: false,
32
+ });
33
+ }).result;
34
+ (0, react_1.act)(function () {
35
+ var _a, _b;
36
+ result.current.datePickerRef.current = { setOpen: setOpen };
37
+ (_b = (_a = result.current.calendarControlProps).onCalendarOpen) === null || _b === void 0 ? void 0 : _b.call(_a);
38
+ });
39
+ expect(result.current.isCalendarOpen).toBe(true);
40
+ (0, react_1.act)(function () {
41
+ document.dispatchEvent(new Event('touchstart', { bubbles: true }));
42
+ });
43
+ expect(result.current.isCalendarOpen).toBe(false);
44
+ expect(setOpen).toHaveBeenCalledWith(false, true);
45
+ });
46
+ });
@@ -0,0 +1,7 @@
1
+ import React from 'react';
2
+ export declare const isFormattedDatePattern: (formatStr?: string | null) => boolean;
3
+ export declare const parseDateValue: (value?: string | null, formatStr?: string | null) => Date | null;
4
+ export declare const formatDateValue: (date: Date, formatStr: string) => string;
5
+ export declare const getDateDisplayValue: (rawValue: string | undefined, formatStr: string | null | undefined, fallbackValue?: string | null) => string;
6
+ export declare const mergeInputRefs: (...refs: Array<React.Ref<HTMLInputElement> | null | undefined>) => (node: HTMLInputElement | null) => void;
7
+ export declare const isOutsideDatePicker: (target: Node, inputNode: HTMLInputElement | null) => boolean;
@@ -0,0 +1,60 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isOutsideDatePicker = exports.mergeInputRefs = exports.getDateDisplayValue = exports.formatDateValue = exports.parseDateValue = exports.isFormattedDatePattern = void 0;
4
+ var date_fns_1 = require("date-fns");
5
+ var isFormattedDatePattern = function (formatStr) {
6
+ return Boolean((formatStr === null || formatStr === void 0 ? void 0 : formatStr.includes('dd')) && formatStr.includes('MM') && formatStr.includes('yyyy'));
7
+ };
8
+ exports.isFormattedDatePattern = isFormattedDatePattern;
9
+ var parseDateValue = function (value, formatStr) {
10
+ if (!value)
11
+ return null;
12
+ if ((0, exports.isFormattedDatePattern)(formatStr)) {
13
+ var parsed_1 = (0, date_fns_1.parse)(value, formatStr, new Date());
14
+ return (0, date_fns_1.isValid)(parsed_1) ? parsed_1 : null;
15
+ }
16
+ var parsed = new Date(value);
17
+ return (0, date_fns_1.isValid)(parsed) ? parsed : null;
18
+ };
19
+ exports.parseDateValue = parseDateValue;
20
+ var formatDateValue = function (date, formatStr) { return (0, date_fns_1.format)(date, formatStr); };
21
+ exports.formatDateValue = formatDateValue;
22
+ var getDateDisplayValue = function (rawValue, formatStr, fallbackValue) {
23
+ if (!rawValue)
24
+ return fallbackValue || '';
25
+ if (!formatStr)
26
+ return fallbackValue || rawValue;
27
+ try {
28
+ var date = (0, date_fns_1.parse)(rawValue, 'yyyy-MM-dd', new Date());
29
+ return (0, date_fns_1.isValid)(date) ? (0, date_fns_1.format)(date, formatStr) : (fallbackValue || '');
30
+ }
31
+ catch (_a) {
32
+ return fallbackValue || '';
33
+ }
34
+ };
35
+ exports.getDateDisplayValue = getDateDisplayValue;
36
+ var mergeInputRefs = function () {
37
+ var refs = [];
38
+ for (var _i = 0; _i < arguments.length; _i++) {
39
+ refs[_i] = arguments[_i];
40
+ }
41
+ return function (node) {
42
+ refs.forEach(function (ref) {
43
+ if (!ref)
44
+ return;
45
+ if (typeof ref === 'function') {
46
+ ref(node);
47
+ }
48
+ else {
49
+ ref.current = node;
50
+ }
51
+ });
52
+ };
53
+ };
54
+ exports.mergeInputRefs = mergeInputRefs;
55
+ var isOutsideDatePicker = function (target, inputNode) {
56
+ var wrapper = inputNode === null || inputNode === void 0 ? void 0 : inputNode.closest('.react-datepicker-wrapper');
57
+ var popper = document.querySelector('.react-datepicker-popper');
58
+ return !(wrapper === null || wrapper === void 0 ? void 0 : wrapper.contains(target)) && !(popper === null || popper === void 0 ? void 0 : popper.contains(target));
59
+ };
60
+ exports.isOutsideDatePicker = isOutsideDatePicker;
@@ -0,0 +1 @@
1
+ export {};