master-components-react-ts 2.1.2 → 2.1.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/_virtual/_commonjsHelpers.js +8 -0
- package/dist/_virtual/customParseFormat.js +4 -0
- package/dist/assets/Icons/IconArrowUp.js +13 -0
- package/dist/assets/Icons/IconCalendar.js +32 -0
- package/dist/assets/Icons/IconCheck.js +15 -0
- package/dist/assets/Icons/IconCheckCircle.js +16 -0
- package/dist/assets/Icons/IconCheckmark.js +15 -0
- package/dist/assets/Icons/IconCircularLoading.js +36 -0
- package/dist/assets/Icons/IconClose.js +31 -0
- package/dist/assets/Icons/IconCloseBackground.js +15 -0
- package/dist/assets/Icons/IconCloseCircle.js +15 -0
- package/dist/assets/Icons/IconErrorDash.js +15 -0
- package/dist/assets/Icons/IconExclamation.js +15 -0
- package/dist/assets/Icons/IconLeft.js +13 -0
- package/dist/assets/Icons/IconLoading.js +22 -0
- package/dist/assets/Icons/IconMinus.js +7 -0
- package/dist/assets/Icons/IconRadioChecked.js +19 -0
- package/dist/assets/Icons/IconRadioCheckedDisabled.js +19 -0
- package/dist/assets/Icons/IconRadioUnchecked.js +16 -0
- package/dist/assets/Icons/IconRadioUncheckedDisabled.js +16 -0
- package/dist/assets/Icons/IconRight.js +13 -0
- package/dist/assets/Icons/IconSave.js +16 -0
- package/dist/assets/Icons/IconSearch.js +26 -0
- package/dist/assets/Icons/IconSuccess.js +15 -0
- package/dist/assets/Icons/IconTrash.js +16 -0
- package/dist/assets/style-CXs6Ghy1.css +2249 -0
- package/dist/components/ActionDropdown/ActionDropdown.js +74 -0
- package/dist/components/ActionDropdown/ActionDropdown.module.scss.js +29 -0
- package/dist/components/Checkbox/Checkbox.js +54 -0
- package/dist/components/Checkbox/Checkbox.module.scss.js +26 -0
- package/dist/components/DatePicker/Calendar.js +437 -0
- package/dist/components/DatePicker/Calendar.module.scss.js +83 -0
- package/dist/components/DatePicker/DatePicker.js +211 -0
- package/dist/components/DatePicker/Datepicker.module.scss.js +17 -0
- package/dist/components/Dropdown/Dropdown.js +337 -0
- package/dist/components/Dropdown/Dropdown.module.scss.js +74 -0
- package/dist/components/FormInput/FormInput.js +151 -0
- package/dist/components/FormInput/FormInput.module.scss.js +62 -0
- package/dist/components/InlineLoading/InlineLoading.js +24 -0
- package/dist/components/InlineLoading/InlineLoading.module.scss.js +11 -0
- package/dist/components/MainButton/MainButton.js +72 -0
- package/dist/components/MainButton/MainButton.module.scss.js +56 -0
- package/dist/components/NotificationToast/NotificationContext.js +57 -0
- package/dist/components/NotificationToast/NotificationToast.js +66 -0
- package/dist/components/NotificationToast/NotificationToast.module.scss.js +59 -0
- package/dist/components/NotificationToast/createNotificationToast.js +10 -0
- package/dist/components/Popup/Popup.js +116 -0
- package/dist/components/Popup/Popup.module.scss.js +41 -0
- package/dist/components/Radio/Radio.js +46 -0
- package/dist/components/Radio/Radio.module.scss.js +8 -0
- package/dist/components/Skeleton/Skeleton.js +8 -0
- package/dist/components/Skeleton/Skeleton.module.scss.js +20 -0
- package/dist/components/Textarea/Textarea.js +149 -0
- package/dist/components/Textarea/Textarea.module.scss.js +41 -0
- package/dist/components/TimePicker/TimePicker.js +172 -0
- package/dist/components/TimePicker/TimePicker.module.scss.js +50 -0
- package/dist/components/Toggle/Toggle.js +20 -0
- package/dist/components/Toggle/Toggle.module.scss.js +29 -0
- package/dist/components/Tooltip/Tooltip.js +153 -0
- package/dist/components/Tooltip/Tooltip.module.scss.js +35 -0
- package/dist/context/NamespaceContext.js +7 -0
- package/dist/index.js +32 -5154
- package/dist/node_modules/dayjs/plugin/customParseFormat.js +129 -0
- package/dist/utils/Helpers.js +15 -0
- package/package.json +10 -14
- package/dist/types/css-modules.d.ts +0 -9
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
const datePicker = "Calendar-module__datePicker";
|
|
2
|
+
const dualCalendar = "Calendar-module__dualCalendar";
|
|
3
|
+
const dualCalendarWithQuick = "Calendar-module__dualCalendarWithQuick";
|
|
4
|
+
const border = "Calendar-module__border";
|
|
5
|
+
const calendarWrapper = "Calendar-module__calendarWrapper";
|
|
6
|
+
const quickPick = "Calendar-module__quickPick";
|
|
7
|
+
const datePickerHeader = "Calendar-module__datePickerHeader";
|
|
8
|
+
const div = "Calendar-module__div";
|
|
9
|
+
const currentDateHeader = "Calendar-module__currentDateHeader";
|
|
10
|
+
const left = "Calendar-module__left";
|
|
11
|
+
const right = "Calendar-module__right";
|
|
12
|
+
const singleIcon = "Calendar-module__singleIcon";
|
|
13
|
+
const doubleIcon = "Calendar-module__doubleIcon";
|
|
14
|
+
const spacerRow = "Calendar-module__spacerRow";
|
|
15
|
+
const day = "Calendar-module__day";
|
|
16
|
+
const today = "Calendar-module__today";
|
|
17
|
+
const inRange = "Calendar-module__inRange";
|
|
18
|
+
const selected = "Calendar-module__selected";
|
|
19
|
+
const startDate = "Calendar-module__startDate";
|
|
20
|
+
const endDate = "Calendar-module__endDate";
|
|
21
|
+
const disabled = "Calendar-module__disabled";
|
|
22
|
+
const otherMonth = "Calendar-module__otherMonth";
|
|
23
|
+
const monthsWrapper = "Calendar-module__monthsWrapper";
|
|
24
|
+
const month = "Calendar-module__month";
|
|
25
|
+
const pickedMonth = "Calendar-module__pickedMonth";
|
|
26
|
+
const buttonWrapper = "Calendar-module__buttonWrapper";
|
|
27
|
+
const style = {
|
|
28
|
+
datePicker,
|
|
29
|
+
dualCalendar,
|
|
30
|
+
dualCalendarWithQuick,
|
|
31
|
+
border,
|
|
32
|
+
calendarWrapper,
|
|
33
|
+
quickPick,
|
|
34
|
+
datePickerHeader,
|
|
35
|
+
div,
|
|
36
|
+
currentDateHeader,
|
|
37
|
+
left,
|
|
38
|
+
right,
|
|
39
|
+
singleIcon,
|
|
40
|
+
doubleIcon,
|
|
41
|
+
spacerRow,
|
|
42
|
+
day,
|
|
43
|
+
today,
|
|
44
|
+
inRange,
|
|
45
|
+
selected,
|
|
46
|
+
startDate,
|
|
47
|
+
endDate,
|
|
48
|
+
disabled,
|
|
49
|
+
otherMonth,
|
|
50
|
+
monthsWrapper,
|
|
51
|
+
month,
|
|
52
|
+
pickedMonth,
|
|
53
|
+
buttonWrapper
|
|
54
|
+
};
|
|
55
|
+
export {
|
|
56
|
+
border,
|
|
57
|
+
buttonWrapper,
|
|
58
|
+
calendarWrapper,
|
|
59
|
+
currentDateHeader,
|
|
60
|
+
datePicker,
|
|
61
|
+
datePickerHeader,
|
|
62
|
+
day,
|
|
63
|
+
style as default,
|
|
64
|
+
disabled,
|
|
65
|
+
div,
|
|
66
|
+
doubleIcon,
|
|
67
|
+
dualCalendar,
|
|
68
|
+
dualCalendarWithQuick,
|
|
69
|
+
endDate,
|
|
70
|
+
inRange,
|
|
71
|
+
left,
|
|
72
|
+
month,
|
|
73
|
+
monthsWrapper,
|
|
74
|
+
otherMonth,
|
|
75
|
+
pickedMonth,
|
|
76
|
+
quickPick,
|
|
77
|
+
right,
|
|
78
|
+
selected,
|
|
79
|
+
singleIcon,
|
|
80
|
+
spacerRow,
|
|
81
|
+
startDate,
|
|
82
|
+
today
|
|
83
|
+
};
|
|
@@ -0,0 +1,211 @@
|
|
|
1
|
+
import { jsxs, jsx } from "react/jsx-runtime";
|
|
2
|
+
import { useState, useRef, useEffect } from "react";
|
|
3
|
+
import dayjs from "dayjs";
|
|
4
|
+
import style from "./Datepicker.module.scss.js";
|
|
5
|
+
import Calendar from "./Calendar.js";
|
|
6
|
+
import { IconCalendar } from "../../assets/Icons/IconCalendar.js";
|
|
7
|
+
import customParseFormat from "../../node_modules/dayjs/plugin/customParseFormat.js";
|
|
8
|
+
import { useNamespace } from "../../context/NamespaceContext.js";
|
|
9
|
+
import FormInput from "../FormInput/FormInput.js";
|
|
10
|
+
import { IconCloseCircle } from "../../assets/Icons/IconCloseCircle.js";
|
|
11
|
+
dayjs.extend(customParseFormat);
|
|
12
|
+
const DatePicker = ({
|
|
13
|
+
defaultValue,
|
|
14
|
+
valueFormat = "DD-MM-YYYY",
|
|
15
|
+
onChange,
|
|
16
|
+
onBlur,
|
|
17
|
+
onFocus,
|
|
18
|
+
customYears,
|
|
19
|
+
fixedDropdown = true,
|
|
20
|
+
disabledDatesFrom,
|
|
21
|
+
disabledDatesTill,
|
|
22
|
+
disabledDatesRange,
|
|
23
|
+
datepickerStyle,
|
|
24
|
+
datepickerLabelStyle,
|
|
25
|
+
requiredStyle,
|
|
26
|
+
datepickerHelperTextStyle,
|
|
27
|
+
selectedStyle,
|
|
28
|
+
endDateStyle,
|
|
29
|
+
startDateStyle,
|
|
30
|
+
inRangeStyle,
|
|
31
|
+
otherMonthStyle,
|
|
32
|
+
todayStyle,
|
|
33
|
+
weekDayStyle,
|
|
34
|
+
quickPickStyle,
|
|
35
|
+
monthStyle,
|
|
36
|
+
quickPick,
|
|
37
|
+
mode = "single",
|
|
38
|
+
pickerType = "single",
|
|
39
|
+
disabled = false,
|
|
40
|
+
...rest
|
|
41
|
+
}) => {
|
|
42
|
+
const namespace = useNamespace();
|
|
43
|
+
const [IsFocused, setIsFocused] = useState(false);
|
|
44
|
+
const [Value, setValue] = useState("");
|
|
45
|
+
const DefaultValue = useRef({ state: false, value: "" });
|
|
46
|
+
const CalendarRef = useRef(null);
|
|
47
|
+
const [CurrentMonth, setCurrentMonth] = useState(() => {
|
|
48
|
+
const thisYear = dayjs().year().toString();
|
|
49
|
+
if (customYears?.length) {
|
|
50
|
+
return customYears.includes(thisYear) ? dayjs() : dayjs(`${Math.min(...customYears.map(Number))}-01-01`);
|
|
51
|
+
}
|
|
52
|
+
return dayjs();
|
|
53
|
+
});
|
|
54
|
+
useEffect(() => {
|
|
55
|
+
const thisYear = dayjs().year().toString();
|
|
56
|
+
if (customYears?.length) {
|
|
57
|
+
setCurrentMonth(customYears.includes(thisYear) ? dayjs() : dayjs(`${Math.min(...customYears.map(Number))}-01-01`));
|
|
58
|
+
}
|
|
59
|
+
}, [customYears]);
|
|
60
|
+
const [SelectedDate, setSelectedDate] = useState("");
|
|
61
|
+
const [RangeSelection, setRangeSelection] = useState({
|
|
62
|
+
start: null,
|
|
63
|
+
end: null
|
|
64
|
+
});
|
|
65
|
+
const ComponentRef = useRef(null);
|
|
66
|
+
const Change = (value, singleQuickPick, withDefault) => {
|
|
67
|
+
let dateValue = "";
|
|
68
|
+
let objValue = { start: "", end: "" };
|
|
69
|
+
if (mode === "single" || typeof value === "string") {
|
|
70
|
+
dateValue = value;
|
|
71
|
+
setValue(dateValue);
|
|
72
|
+
}
|
|
73
|
+
if (mode !== "single" || typeof value !== "string") {
|
|
74
|
+
dateValue = `${dayjs(value?.start ?? "").format(valueFormat)} / ${value?.end ? dayjs(value?.end).format(valueFormat) : ""}`;
|
|
75
|
+
objValue.start = dayjs(value?.start ?? "").format(valueFormat);
|
|
76
|
+
objValue.end = value?.end ? dayjs(value?.end).format(valueFormat) : "";
|
|
77
|
+
setValue(dateValue);
|
|
78
|
+
}
|
|
79
|
+
if (value?.end) {
|
|
80
|
+
setIsFocused(false);
|
|
81
|
+
}
|
|
82
|
+
if (onChange && typeof onChange === "function" && !withDefault) {
|
|
83
|
+
onChange(objValue.start !== "" ? objValue : dateValue);
|
|
84
|
+
DefaultValue.current.value = objValue.start !== "" ? objValue : dateValue;
|
|
85
|
+
}
|
|
86
|
+
};
|
|
87
|
+
const Clear = (e) => {
|
|
88
|
+
e.stopPropagation();
|
|
89
|
+
setSelectedDate("");
|
|
90
|
+
DefaultValue.current.value = "";
|
|
91
|
+
setValue("");
|
|
92
|
+
setRangeSelection({
|
|
93
|
+
start: null,
|
|
94
|
+
end: null
|
|
95
|
+
});
|
|
96
|
+
if (onChange && typeof onChange === "function") {
|
|
97
|
+
onChange("");
|
|
98
|
+
}
|
|
99
|
+
};
|
|
100
|
+
const ClickHandler = (event) => {
|
|
101
|
+
if (!ComponentRef.current) return;
|
|
102
|
+
if (event.composedPath().includes(ComponentRef.current)) return;
|
|
103
|
+
setIsFocused(false);
|
|
104
|
+
};
|
|
105
|
+
const ScrollHandler = (event) => {
|
|
106
|
+
if (!ComponentRef.current || !CalendarRef.current) return;
|
|
107
|
+
if (event.composedPath().includes(ComponentRef.current) || event.composedPath().includes(CalendarRef.current)) return;
|
|
108
|
+
setIsFocused(false);
|
|
109
|
+
};
|
|
110
|
+
const CalculatePos = () => {
|
|
111
|
+
if (!ComponentRef.current || !CalendarRef.current) return;
|
|
112
|
+
const componentEl = ComponentRef.current;
|
|
113
|
+
const calendarEl = CalendarRef.current;
|
|
114
|
+
if (!calendarEl || !componentEl) return;
|
|
115
|
+
const componentRect = componentEl.getBoundingClientRect();
|
|
116
|
+
const windowHeight = window.innerHeight;
|
|
117
|
+
const windowWidth = window.innerWidth;
|
|
118
|
+
calendarEl.style.position = "fixed";
|
|
119
|
+
if (componentRect.bottom + calendarEl.offsetHeight > windowHeight) {
|
|
120
|
+
calendarEl.style.top = `${window.scrollY + componentRect.top - calendarEl.offsetHeight - 8}px`;
|
|
121
|
+
calendarEl.style.bottom = "unset";
|
|
122
|
+
} else {
|
|
123
|
+
calendarEl.style.top = `${window.scrollY + componentRect.bottom + 8}px`;
|
|
124
|
+
calendarEl.style.bottom = "unset";
|
|
125
|
+
}
|
|
126
|
+
if (componentRect.right + componentRect.width > windowWidth - 120) {
|
|
127
|
+
calendarEl.style.left = `${window.scrollX + componentRect.left + componentRect.width - calendarEl.offsetWidth}px`;
|
|
128
|
+
} else {
|
|
129
|
+
calendarEl.style.left = `${window.scrollX + componentRect.left}px`;
|
|
130
|
+
}
|
|
131
|
+
};
|
|
132
|
+
useEffect(() => {
|
|
133
|
+
if (defaultValue && DefaultValue.current.value === "") {
|
|
134
|
+
let value = Array.isArray(defaultValue) ? {
|
|
135
|
+
start: dayjs(defaultValue[0], valueFormat),
|
|
136
|
+
end: defaultValue.length > 1 ? dayjs(defaultValue[1], valueFormat) : ""
|
|
137
|
+
} : dayjs(defaultValue, valueFormat).format(valueFormat);
|
|
138
|
+
DefaultValue.current.value = defaultValue;
|
|
139
|
+
DefaultValue.current.state = true;
|
|
140
|
+
if (value) {
|
|
141
|
+
Change(value, false, true);
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
}, []);
|
|
145
|
+
useEffect(() => {
|
|
146
|
+
if (IsFocused) {
|
|
147
|
+
CalculatePos();
|
|
148
|
+
}
|
|
149
|
+
}, [CalendarRef, IsFocused]);
|
|
150
|
+
useEffect(() => {
|
|
151
|
+
document.addEventListener("click", ClickHandler);
|
|
152
|
+
document.addEventListener("wheel", ScrollHandler);
|
|
153
|
+
return () => {
|
|
154
|
+
document.removeEventListener("click", ClickHandler);
|
|
155
|
+
document.removeEventListener("wheel", ScrollHandler);
|
|
156
|
+
};
|
|
157
|
+
}, []);
|
|
158
|
+
return /* @__PURE__ */ jsxs("div", { className: `${namespace === "namespaceHr" ? style.namespaceHr : ""} ${style.datepickerContainer}`, children: [
|
|
159
|
+
/* @__PURE__ */ jsx("div", { ref: ComponentRef, className: style.datepickerInputWrapper, onClick: () => (setIsFocused((state) => !state), CalculatePos()), children: /* @__PURE__ */ jsx(
|
|
160
|
+
FormInput,
|
|
161
|
+
{
|
|
162
|
+
...rest,
|
|
163
|
+
customFocus: IsFocused,
|
|
164
|
+
withActive: false,
|
|
165
|
+
value: Value,
|
|
166
|
+
toggleFocus: true,
|
|
167
|
+
formInputStyle: { cursor: "pointer" },
|
|
168
|
+
leftSlot: /* @__PURE__ */ jsx("div", { className: style.datepickerLeftIcon, children: /* @__PURE__ */ jsx(IconCalendar, {}) }),
|
|
169
|
+
rightSlot: /* @__PURE__ */ jsx("div", { className: `${style.datepickerRightIcon}`, onClick: Clear, children: Value && /* @__PURE__ */ jsx(IconCloseCircle, {}) }),
|
|
170
|
+
readOnly: true
|
|
171
|
+
}
|
|
172
|
+
) }),
|
|
173
|
+
IsFocused && /* @__PURE__ */ jsx(
|
|
174
|
+
Calendar,
|
|
175
|
+
{
|
|
176
|
+
namespace,
|
|
177
|
+
defaultValue: DefaultValue.current,
|
|
178
|
+
CalendarRef,
|
|
179
|
+
disabledDatesFrom,
|
|
180
|
+
disabledDatesTill,
|
|
181
|
+
disabledDatesRange,
|
|
182
|
+
valueFormat,
|
|
183
|
+
onChange: (value) => Change(value, false, false),
|
|
184
|
+
customYears,
|
|
185
|
+
CurrentMonth,
|
|
186
|
+
setCurrentMonth,
|
|
187
|
+
SelectedDate,
|
|
188
|
+
setSelectedDate,
|
|
189
|
+
IsFocused,
|
|
190
|
+
setIsFocused,
|
|
191
|
+
quickPick,
|
|
192
|
+
mode,
|
|
193
|
+
RangeSelection,
|
|
194
|
+
setRangeSelection,
|
|
195
|
+
pickerType,
|
|
196
|
+
selectedStyle,
|
|
197
|
+
endDateStyle,
|
|
198
|
+
startDateStyle,
|
|
199
|
+
inRangeStyle,
|
|
200
|
+
otherMonthStyle,
|
|
201
|
+
todayStyle,
|
|
202
|
+
weekDayStyle,
|
|
203
|
+
quickPickStyle,
|
|
204
|
+
monthStyle
|
|
205
|
+
}
|
|
206
|
+
)
|
|
207
|
+
] });
|
|
208
|
+
};
|
|
209
|
+
export {
|
|
210
|
+
DatePicker as default
|
|
211
|
+
};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
const datepickerContainer = "Datepicker-module__datepickerContainer";
|
|
2
|
+
const datepickerInputWrapper = "Datepicker-module__datepickerInputWrapper";
|
|
3
|
+
const datepickerLeftIcon = "Datepicker-module__datepickerLeftIcon";
|
|
4
|
+
const datepickerRightIcon = "Datepicker-module__datepickerRightIcon";
|
|
5
|
+
const style = {
|
|
6
|
+
datepickerContainer,
|
|
7
|
+
datepickerInputWrapper,
|
|
8
|
+
datepickerLeftIcon,
|
|
9
|
+
datepickerRightIcon
|
|
10
|
+
};
|
|
11
|
+
export {
|
|
12
|
+
datepickerContainer,
|
|
13
|
+
datepickerInputWrapper,
|
|
14
|
+
datepickerLeftIcon,
|
|
15
|
+
datepickerRightIcon,
|
|
16
|
+
style as default
|
|
17
|
+
};
|
|
@@ -0,0 +1,337 @@
|
|
|
1
|
+
import { jsxs, jsx } from "react/jsx-runtime";
|
|
2
|
+
import { useState, useRef, useEffect } from "react";
|
|
3
|
+
import style from "./Dropdown.module.scss.js";
|
|
4
|
+
import FormInput from "../FormInput/FormInput.js";
|
|
5
|
+
import Checkbox from "../Checkbox/Checkbox.js";
|
|
6
|
+
import { _filterUnique } from "../../utils/Helpers.js";
|
|
7
|
+
import { IconClose } from "../../assets/Icons/IconClose.js";
|
|
8
|
+
import { IconArrowUp } from "../../assets/Icons/IconArrowUp.js";
|
|
9
|
+
import { IconCloseCircle } from "../../assets/Icons/IconCloseCircle.js";
|
|
10
|
+
const Dropdown = ({
|
|
11
|
+
data,
|
|
12
|
+
withFilter = true,
|
|
13
|
+
withClose = true,
|
|
14
|
+
disableAll = false,
|
|
15
|
+
withMultiselect = false,
|
|
16
|
+
selectedOptionID,
|
|
17
|
+
withInput = false,
|
|
18
|
+
dropdownType = "country",
|
|
19
|
+
onSelect,
|
|
20
|
+
onFocus,
|
|
21
|
+
onBlur,
|
|
22
|
+
onValueChange,
|
|
23
|
+
customInputSlot,
|
|
24
|
+
dropdownWrapperStyle,
|
|
25
|
+
dropdownInputWrapperStyle,
|
|
26
|
+
dropdownInputSlotStyle,
|
|
27
|
+
dropdownInputSlotItemStyle,
|
|
28
|
+
dropdownInputSlotItemLabelStyle,
|
|
29
|
+
dropdownInputSlotItemCloseStyle,
|
|
30
|
+
dropdownInputSlotItemMoreStyle,
|
|
31
|
+
dropdownItemStyle,
|
|
32
|
+
dropdownItemLabelStyle,
|
|
33
|
+
itemCheckboxStyle,
|
|
34
|
+
dropdownItemLabelTextStyle,
|
|
35
|
+
dropdownListStyle,
|
|
36
|
+
...rest
|
|
37
|
+
}) => {
|
|
38
|
+
const [Flag, setFlag] = useState(false);
|
|
39
|
+
const [InputValue, setInputValue] = useState("");
|
|
40
|
+
const [SelectAllKey, setSelectAllKey] = useState(false);
|
|
41
|
+
const [ClickedSelectAll, setClickedSelectAll] = useState(false);
|
|
42
|
+
const [IsFocused, setIsFocused] = useState(false);
|
|
43
|
+
const DropdownRef = useRef(null);
|
|
44
|
+
const ComponentRef = useRef(null);
|
|
45
|
+
const ListRef = useRef(null);
|
|
46
|
+
const ListItemRef = useRef(null);
|
|
47
|
+
const [Data, setData] = useState([]);
|
|
48
|
+
const SelectedData = useRef([]);
|
|
49
|
+
const SelectedDataLength = useRef(0);
|
|
50
|
+
const [SearchValue, setSearchValue] = useState("");
|
|
51
|
+
const [SingleSelectValue, setSingleSelectValue] = useState(null);
|
|
52
|
+
const getFlagIconUrl = (code) => {
|
|
53
|
+
return `https://flagsapi.com/${code}/flat/64.png`;
|
|
54
|
+
};
|
|
55
|
+
const SelectItem = (object) => {
|
|
56
|
+
object.selected = !object.selected;
|
|
57
|
+
if (!withMultiselect) {
|
|
58
|
+
onSelect?.(object);
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
SelectedData.current = [...SelectedData.current, ...Data.filter((el) => el.selected == true), ...Data.filter((el) => el.id === object.id)];
|
|
62
|
+
SelectedData.current = _filterUnique(SelectedData.current, "id").filter((el) => el.selected).filter((el) => el.id !== "SELECT_ALL");
|
|
63
|
+
if (object.id === "SELECT_ALL") {
|
|
64
|
+
setSelectAllKey(object.selected);
|
|
65
|
+
setClickedSelectAll(true);
|
|
66
|
+
} else {
|
|
67
|
+
setSelectAllKey(false);
|
|
68
|
+
onSelect?.(SelectedData.current);
|
|
69
|
+
setClickedSelectAll(false);
|
|
70
|
+
}
|
|
71
|
+
setFlag((state) => !state);
|
|
72
|
+
};
|
|
73
|
+
const SingleSelect = (object) => {
|
|
74
|
+
setSingleSelectValue(object);
|
|
75
|
+
onSelect?.(object);
|
|
76
|
+
setIsFocused(false);
|
|
77
|
+
};
|
|
78
|
+
const Focus = () => {
|
|
79
|
+
onFocus?.();
|
|
80
|
+
};
|
|
81
|
+
const CalculatePos = () => {
|
|
82
|
+
const componentEl = ComponentRef.current;
|
|
83
|
+
const dropdownEl = DropdownRef.current;
|
|
84
|
+
if (!dropdownEl || !componentEl) return;
|
|
85
|
+
const componentRect = componentEl.getBoundingClientRect();
|
|
86
|
+
const windowHeight = window.innerHeight;
|
|
87
|
+
dropdownEl.style.zIndex = "100";
|
|
88
|
+
dropdownEl.style.position = "fixed";
|
|
89
|
+
dropdownEl.style.width = componentRect.width + "px";
|
|
90
|
+
dropdownEl.style.left = `${componentRect.left + window.pageXOffset}px`;
|
|
91
|
+
if (componentRect.bottom + dropdownEl.offsetHeight > windowHeight) {
|
|
92
|
+
dropdownEl.style.top = `${window.scrollY + componentRect.top - dropdownEl.offsetHeight + 18}px`;
|
|
93
|
+
dropdownEl.style.bottom = "unset";
|
|
94
|
+
} else {
|
|
95
|
+
dropdownEl.style.top = `${window.scrollY + componentRect.bottom + 8}px`;
|
|
96
|
+
dropdownEl.style.bottom = "unset";
|
|
97
|
+
}
|
|
98
|
+
};
|
|
99
|
+
useEffect(() => {
|
|
100
|
+
CalculatePos();
|
|
101
|
+
}, [DropdownRef, IsFocused]);
|
|
102
|
+
useEffect(() => {
|
|
103
|
+
SelectedData.current = data.filter((el) => el.selected);
|
|
104
|
+
if (!withMultiselect) {
|
|
105
|
+
setData(data);
|
|
106
|
+
return;
|
|
107
|
+
}
|
|
108
|
+
const hasSelected = data.some((el) => "selected" in el);
|
|
109
|
+
const firstItem = { id: "SELECT_ALL", label: "Select All", selected: SelectAllKey };
|
|
110
|
+
if (hasSelected) {
|
|
111
|
+
setData([firstItem, ...data]);
|
|
112
|
+
} else {
|
|
113
|
+
data.forEach((el) => {
|
|
114
|
+
el.selected = false;
|
|
115
|
+
});
|
|
116
|
+
setData([firstItem, ...data]);
|
|
117
|
+
}
|
|
118
|
+
}, [JSON.stringify(data)]);
|
|
119
|
+
useEffect(() => {
|
|
120
|
+
if (!withMultiselect) return;
|
|
121
|
+
if (!data.every((el) => el.selected)) {
|
|
122
|
+
setSelectAllKey(false);
|
|
123
|
+
}
|
|
124
|
+
}, [SelectedData.current.length]);
|
|
125
|
+
useEffect(() => {
|
|
126
|
+
if (!withMultiselect && selectedOptionID) {
|
|
127
|
+
setSingleSelectValue(data.find((el) => el.id === selectedOptionID));
|
|
128
|
+
}
|
|
129
|
+
}, [selectedOptionID]);
|
|
130
|
+
useEffect(() => {
|
|
131
|
+
if (!withMultiselect) return;
|
|
132
|
+
if (Data.length > 0 && ClickedSelectAll) {
|
|
133
|
+
const updated = Data.map((el) => {
|
|
134
|
+
if (el.id === "SELECT_ALL") return { ...el, selected: SelectAllKey };
|
|
135
|
+
if (el.disabled) return el;
|
|
136
|
+
return { ...el, selected: SelectAllKey };
|
|
137
|
+
});
|
|
138
|
+
setData(updated);
|
|
139
|
+
data.forEach((el) => {
|
|
140
|
+
if (el.id === "SELECT_ALL") {
|
|
141
|
+
el.selected = SelectAllKey;
|
|
142
|
+
} else if (!el.disabled) {
|
|
143
|
+
el.selected = SelectAllKey;
|
|
144
|
+
}
|
|
145
|
+
});
|
|
146
|
+
SelectedData.current = updated.filter((el) => el.selected && el.id !== "SELECT_ALL");
|
|
147
|
+
onSelect?.(SelectedData.current);
|
|
148
|
+
}
|
|
149
|
+
}, [Flag]);
|
|
150
|
+
useEffect(() => {
|
|
151
|
+
const ClickHandler = (event) => {
|
|
152
|
+
if (!ComponentRef.current) return;
|
|
153
|
+
if (event.composedPath().includes(ComponentRef.current)) return;
|
|
154
|
+
setIsFocused(false);
|
|
155
|
+
};
|
|
156
|
+
const ScrollHandler = (event) => {
|
|
157
|
+
if (!ComponentRef.current || !ListRef.current) return;
|
|
158
|
+
if (ListRef.current.contains(event.target)) return;
|
|
159
|
+
setIsFocused(false);
|
|
160
|
+
};
|
|
161
|
+
document.addEventListener("click", ClickHandler);
|
|
162
|
+
document.addEventListener("wheel", ScrollHandler);
|
|
163
|
+
return () => {
|
|
164
|
+
document.removeEventListener("click", ClickHandler);
|
|
165
|
+
document.removeEventListener("wheel", ScrollHandler);
|
|
166
|
+
};
|
|
167
|
+
}, []);
|
|
168
|
+
useEffect(() => {
|
|
169
|
+
if (!withMultiselect) return;
|
|
170
|
+
const calculateSelectedLength = () => {
|
|
171
|
+
const rect = ComponentRef.current?.getBoundingClientRect();
|
|
172
|
+
if (!rect) return;
|
|
173
|
+
const width = rect.width;
|
|
174
|
+
if (width <= 150) SelectedDataLength.current = 0;
|
|
175
|
+
else if (width <= 250) SelectedDataLength.current = 1;
|
|
176
|
+
else if (width <= 350) SelectedDataLength.current = 2;
|
|
177
|
+
else if (width <= 450) SelectedDataLength.current = 3;
|
|
178
|
+
else SelectedDataLength.current = 4;
|
|
179
|
+
};
|
|
180
|
+
calculateSelectedLength();
|
|
181
|
+
window.addEventListener("resize", calculateSelectedLength);
|
|
182
|
+
return () => window.removeEventListener("resize", calculateSelectedLength);
|
|
183
|
+
}, []);
|
|
184
|
+
const isInitialRender = useRef(true);
|
|
185
|
+
useEffect(() => {
|
|
186
|
+
if (isInitialRender.current) {
|
|
187
|
+
isInitialRender.current = false;
|
|
188
|
+
return;
|
|
189
|
+
}
|
|
190
|
+
if (!IsFocused) {
|
|
191
|
+
onBlur?.();
|
|
192
|
+
}
|
|
193
|
+
}, [IsFocused]);
|
|
194
|
+
return /* @__PURE__ */ jsxs("div", { className: `${style.dropdownWrapper}`, style: dropdownWrapperStyle ?? {}, children: [
|
|
195
|
+
/* @__PURE__ */ jsx(
|
|
196
|
+
"div",
|
|
197
|
+
{
|
|
198
|
+
ref: ComponentRef,
|
|
199
|
+
className: style.dropdownInputWrapper,
|
|
200
|
+
style: dropdownInputWrapperStyle ?? {},
|
|
201
|
+
onClick: () => (setIsFocused((state) => !state), CalculatePos()),
|
|
202
|
+
onFocus: Focus,
|
|
203
|
+
children: /* @__PURE__ */ jsx(
|
|
204
|
+
FormInput,
|
|
205
|
+
{
|
|
206
|
+
...rest,
|
|
207
|
+
onFocusChange: (value) => setIsFocused(value),
|
|
208
|
+
customFocus: IsFocused,
|
|
209
|
+
withActive: false,
|
|
210
|
+
value: withInput ? InputValue : SingleSelectValue?.label ?? "",
|
|
211
|
+
onChange: (value) => {
|
|
212
|
+
setInputValue(value);
|
|
213
|
+
onValueChange?.(value);
|
|
214
|
+
},
|
|
215
|
+
toggleFocus: true,
|
|
216
|
+
formInputStyle: { cursor: withInput ? "text" : "pointer" },
|
|
217
|
+
leftSlot: withInput && /* @__PURE__ */ jsxs("div", { className: style.dropdownInputSlot, children: [
|
|
218
|
+
dropdownType === "currency" ? /* @__PURE__ */ jsx("p", { children: SingleSelectValue?.label }) : /* @__PURE__ */ jsx("img", { src: getFlagIconUrl(SingleSelectValue?.code), alt: "flag" }),
|
|
219
|
+
/* @__PURE__ */ jsx("div", { className: `${style.dropdownRightIconArrow} ${IsFocused ? style.focused : ""}`, children: /* @__PURE__ */ jsx(IconArrowUp, {}) })
|
|
220
|
+
] }),
|
|
221
|
+
rightSlot: /* @__PURE__ */ jsxs("div", { className: `${style.dropdownRightIcon} ${IsFocused ? style.focused : ""}`, children: [
|
|
222
|
+
(withInput ? InputValue : !withMultiselect && SingleSelectValue) && /* @__PURE__ */ jsx(
|
|
223
|
+
"div",
|
|
224
|
+
{
|
|
225
|
+
onClick: (e) => {
|
|
226
|
+
e.stopPropagation();
|
|
227
|
+
if (withInput) {
|
|
228
|
+
setInputValue("");
|
|
229
|
+
setIsFocused(false);
|
|
230
|
+
} else {
|
|
231
|
+
setSingleSelectValue(null);
|
|
232
|
+
}
|
|
233
|
+
},
|
|
234
|
+
className: style.dropdownRightIconClose,
|
|
235
|
+
children: /* @__PURE__ */ jsx(IconCloseCircle, {})
|
|
236
|
+
}
|
|
237
|
+
),
|
|
238
|
+
!withInput && /* @__PURE__ */ jsx("div", { className: style.dropdownRightIconArrow, children: /* @__PURE__ */ jsx(IconArrowUp, {}) })
|
|
239
|
+
] }),
|
|
240
|
+
readOnly: !withInput,
|
|
241
|
+
forDropdown: true,
|
|
242
|
+
inputSlotStyle: { width: "100%" },
|
|
243
|
+
inputSlot: withMultiselect && SelectedData.current.length > 0 ? customInputSlot || /* @__PURE__ */ jsxs("ul", { className: style.dropdownInputSlot, style: dropdownInputSlotStyle ?? {}, children: [
|
|
244
|
+
SelectedData.current.slice(0, SelectedDataLength.current).map((el, index) => {
|
|
245
|
+
return /* @__PURE__ */ jsxs(
|
|
246
|
+
"li",
|
|
247
|
+
{
|
|
248
|
+
ref: ListItemRef,
|
|
249
|
+
className: style.dropdownInputSlotItem,
|
|
250
|
+
style: dropdownInputSlotItemStyle ?? {},
|
|
251
|
+
onClick: (e) => e.stopPropagation(),
|
|
252
|
+
children: [
|
|
253
|
+
/* @__PURE__ */ jsx("p", { title: el.label, className: style.dropdownInputSlotItemLabel, style: dropdownInputSlotItemLabelStyle ?? {}, children: typeof el.customLabel === "function" ? el.customLabel(el) : el.label }),
|
|
254
|
+
/* @__PURE__ */ jsx(
|
|
255
|
+
"div",
|
|
256
|
+
{
|
|
257
|
+
style: dropdownInputSlotItemCloseStyle ?? {},
|
|
258
|
+
className: style.dropdownInputSlotItemClose,
|
|
259
|
+
onClick: (e) => {
|
|
260
|
+
e.stopPropagation();
|
|
261
|
+
SelectItem(el);
|
|
262
|
+
},
|
|
263
|
+
children: /* @__PURE__ */ jsx(IconClose, { width: "16", height: "16", viewBox: "0 0 16 16", stroke: "#95969C" })
|
|
264
|
+
}
|
|
265
|
+
)
|
|
266
|
+
]
|
|
267
|
+
},
|
|
268
|
+
index
|
|
269
|
+
);
|
|
270
|
+
}),
|
|
271
|
+
SelectedData.current.length > SelectedDataLength.current && /* @__PURE__ */ jsx("li", { className: `${style.dropdownInputSlotItem} ${style.dropdownInputSlotItemMore}`, style: dropdownInputSlotItemMoreStyle ?? {}, children: /* @__PURE__ */ jsx("p", { className: style.dropdownInputSlotItemLabel, style: dropdownInputSlotItemLabelStyle ?? {}, children: `+${SelectedData.current.length - SelectedDataLength.current}` }) })
|
|
272
|
+
] }) : null
|
|
273
|
+
}
|
|
274
|
+
)
|
|
275
|
+
}
|
|
276
|
+
),
|
|
277
|
+
data && data.length > 0 && IsFocused && /* @__PURE__ */ jsxs("div", { ref: DropdownRef, onClick: (e) => e.stopPropagation(), className: style.dropdownListContainer, children: [
|
|
278
|
+
withFilter && /* @__PURE__ */ jsx(
|
|
279
|
+
FormInput,
|
|
280
|
+
{
|
|
281
|
+
placeholder: "Search",
|
|
282
|
+
searchComponent: true,
|
|
283
|
+
withFocus: false,
|
|
284
|
+
withActive: false,
|
|
285
|
+
value: SearchValue,
|
|
286
|
+
onChange: (value) => setSearchValue(value)
|
|
287
|
+
}
|
|
288
|
+
),
|
|
289
|
+
/* @__PURE__ */ jsx("ul", { onClick: (e) => e.stopPropagation(), className: style.dropdownList, ref: ListRef, style: dropdownListStyle ?? {}, children: Data.filter((item) => item?.label?.toLowerCase().includes(SearchValue.toLowerCase())).map((item, index) => {
|
|
290
|
+
return /* @__PURE__ */ jsxs(
|
|
291
|
+
"li",
|
|
292
|
+
{
|
|
293
|
+
style: { ...dropdownItemStyle, cursor: !withMultiselect && item?.disabled ? "not-allowed" : "pointer" },
|
|
294
|
+
className: `${style.dropdownItem} ${!withMultiselect && SingleSelectValue?.id === item.id ? style.selected : ""} ${!item?.label || item.label === void 0 || disableAll || item?.disabled ? style.disabled : ""} ${!withMultiselect && !item?.disabled ? style.hovered : ""}`,
|
|
295
|
+
onClick: (e) => {
|
|
296
|
+
e.stopPropagation();
|
|
297
|
+
if (!withMultiselect && !item?.disabled) {
|
|
298
|
+
SingleSelect(item);
|
|
299
|
+
}
|
|
300
|
+
},
|
|
301
|
+
children: [
|
|
302
|
+
withMultiselect && /* @__PURE__ */ jsx("div", { className: style.itemCheckbox, style: itemCheckboxStyle ?? {}, children: /* @__PURE__ */ jsx(
|
|
303
|
+
Checkbox,
|
|
304
|
+
{
|
|
305
|
+
multipleChecked: item.id === "SELECT_ALL",
|
|
306
|
+
disabled: disableAll || item?.disabled,
|
|
307
|
+
checked: item?.selected,
|
|
308
|
+
change: () => SelectItem(item)
|
|
309
|
+
}
|
|
310
|
+
) }),
|
|
311
|
+
/* @__PURE__ */ jsxs("div", { className: style.dropdownItemLabel, style: dropdownItemLabelStyle ?? {}, children: [
|
|
312
|
+
withInput ? /* @__PURE__ */ jsxs("div", { className: style.dropdownItemLabelInput, children: [
|
|
313
|
+
/* @__PURE__ */ jsx("img", { src: getFlagIconUrl(item.code), style: { width: "1.375rem", height: "1.375rem", objectFit: "contain" }, alt: item.name }),
|
|
314
|
+
/* @__PURE__ */ jsx("span", { title: item.name, className: style.countryName, children: item.name || item.label }),
|
|
315
|
+
/* @__PURE__ */ jsx("span", { className: style.countryDialCode, children: dropdownType === "country" ? item.dialCode : item?.label })
|
|
316
|
+
] }) : /* @__PURE__ */ jsx(
|
|
317
|
+
"p",
|
|
318
|
+
{
|
|
319
|
+
title: typeof item.label === "string" ? item.label : "",
|
|
320
|
+
className: `${item.id === "SELECT_ALL" ? style.selectAll : ""}`,
|
|
321
|
+
style: dropdownItemLabelTextStyle ?? {},
|
|
322
|
+
children: typeof item.customLabel === "function" ? item.customLabel(item) : item.label
|
|
323
|
+
}
|
|
324
|
+
),
|
|
325
|
+
withMultiselect && /* @__PURE__ */ jsx("p", { children: item.id === "SELECT_ALL" ? `${Data.filter((el) => el.id !== "SELECT_ALL" && el.selected).length}/${data.length}` : "" })
|
|
326
|
+
] })
|
|
327
|
+
]
|
|
328
|
+
},
|
|
329
|
+
index
|
|
330
|
+
);
|
|
331
|
+
}) }, Data.length)
|
|
332
|
+
] })
|
|
333
|
+
] });
|
|
334
|
+
};
|
|
335
|
+
export {
|
|
336
|
+
Dropdown as default
|
|
337
|
+
};
|