intelicoreact 1.8.8 → 1.8.10
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/Atomic/FormElements/Dropdown/components/DropdownLoader.jsx +18 -1
- package/dist/Atomic/FormElements/FormattedRawSSN/FormattedRawSSN_old.jsx +121 -1
- package/dist/Atomic/FormElements/MobileCalendar/MobileCalendar.jsx +507 -1
- package/dist/Atomic/FormElements/MultiSelect/MultiSelect.jsx +46 -1
- package/dist/Atomic/FormElements/NumericInput/NumericInput.jsx +337 -1
- package/dist/Atomic/FormElements/RadioGroup/RadioGroup.jsx +66 -1
- package/dist/Atomic/FormElements/RadioGroupWithInput/RadioGroupWithInput.jsx +78 -1
- package/dist/Atomic/FormElements/RadioRowSwitcher/RadioRowSwitcher.jsx +54 -1
- package/dist/Atomic/FormElements/RangeCalendar/RangeCalendar.jsx +183 -1
- package/dist/Atomic/FormElements/RangeList/RangeList.jsx +181 -1
- package/dist/Atomic/FormElements/RangeList/partial/RangeListRow.jsx +41 -1
- package/dist/Atomic/FormElements/RangeSlider/RangeSlider.jsx +449 -1
- package/dist/Atomic/FormElements/RangeSlider2/RangeSlider2.jsx +865 -1
- package/dist/Atomic/FormElements/SwitchableRow/SwitchableRow.jsx +37 -1
- package/dist/Atomic/FormElements/SwitcherCheckbox/SwitcherCheckbox.jsx +48 -1
- package/dist/Atomic/FormElements/SwitcherRangeList/SwitcherRangeList.jsx +62 -1
- package/dist/Atomic/FormElements/SwitcherTagsDropdown/SwitcherTagsDropdown.jsx +175 -1
- package/dist/Atomic/FormElements/SwitcherTextarea/SwitcherTextarea.jsx +65 -1
- package/dist/Atomic/FormElements/TagListToDropdown/TagListToDropdown.jsx +118 -1
- package/dist/Atomic/FormElements/Text/Text.jsx +126 -1
- package/dist/Atomic/FormElements/Textarea/Textarea.jsx +61 -1
- package/dist/Atomic/FormElements/TieredCheckboxes/TieredCheckboxes.jsx +181 -1
- package/dist/Atomic/FormElements/TieredCheckboxes/partial/AccordionWithCheckbox.jsx +60 -1
- package/dist/Atomic/FormElements/VariantsListRadio/VariantsListRadio.jsx +83 -1
- package/dist/Atomic/FormElements/VariantsListRadio/partials/VariantsListRadioItem.jsx +80 -1
- package/dist/Atomic/FormElements/WidgetPseudoTable/WidgetPseudoTable.jsx +103 -1
- package/dist/Atomic/FormElements/WidgetWithSwitchableRows/WidgetWithSwitchableRows.jsx +115 -1
- package/dist/Atomic/Layout/Header/Header.jsx +86 -1
- package/dist/Atomic/Layout/MainMenu/MainMenu.jsx +164 -1
- package/dist/Atomic/UI/AccordionTable/AccordionTable.jsx +250 -1
- package/dist/Atomic/UI/AccordionText/AccordionText.jsx +68 -1
- package/dist/Atomic/UI/Arrow/Arrow.jsx +134 -1
- package/dist/Atomic/UI/Box/Box.jsx +53 -1
- package/dist/Atomic/UI/Chart/Chart.jsx +178 -1
- package/dist/Atomic/UI/Chart/partial/ChartTypeSwitcherIcon/ChartTypeSwitcherIcon.jsx +78 -1
- package/dist/Atomic/UI/Chart/partial/optionsConstructor.jsx +334 -1
- package/dist/Atomic/UI/CircleProgressBar/CircleProgressBar.jsx +111 -1
- package/dist/Atomic/UI/DateTime/DateTime.jsx +57 -1
- package/dist/Atomic/UI/DebugContainer/DebugContainer.jsx +44 -1
- package/dist/Atomic/UI/DebugContainer/useDebugContainer.jsx +15 -1
- package/dist/Atomic/UI/ExampleChartIntegration/ExampleChartIntegration.jsx +223 -1
- package/dist/Atomic/UI/MonoAccordion/MonoAccordion._test.jsx +75 -1
- package/dist/Atomic/UI/MonoAccordion/MonoAccordion.jsx +86 -1
- package/dist/Atomic/UI/PieChart/PieChart.jsx +41 -1
- package/dist/Atomic/UI/Table/Partials/TdCell.jsx +87 -1
- package/dist/Atomic/UI/Table/Partials/TdHeader.jsx +36 -1
- package/dist/Atomic/UI/Table/Partials/TdRow.jsx +103 -1
- package/dist/Atomic/UI/Table/Partials/TdTitle.jsx +55 -1
- package/dist/Atomic/UI/Table/Table.jsx +63 -1
- package/dist/Atomic/UI/Table/TdTypes/TdActions.jsx +80 -1
- package/dist/Atomic/UI/Table/TdTypes/TdPriority.jsx +26 -1
- package/dist/Atomic/UI/Table/TdTypes/TdRange.jsx +13 -1
- package/dist/Atomic/UI/Table/TdTypes/TdWeight.jsx +56 -1
- package/dist/Atomic/UI/TagList/TagList.jsx +256 -1
- package/dist/Atomic/UI/WizardStepper/constructor.jsx +86 -1
- package/dist/Classes/RESTAPI/partials/CredentialsProcessing.jsx +254 -1
- package/dist/Functions/customEventListener.jsx +96 -1
- package/dist/Functions/operations.jsx +138 -1
- package/dist/Functions/useFormTools/functions/RenderFields.jsx +108 -1
- package/dist/Functions/useFormTools/index.jsx +777 -1
- package/dist/Functions/usePasswordChecker.jsx +128 -1
- package/dist/Functions/utils.jsx +492 -1
- package/dist/Molecular/CustomIcons/components/AffiliateNetworks.jsx +22 -1
- package/dist/Molecular/CustomIcons/components/AlertCircle.jsx +24 -1
- package/dist/Molecular/CustomIcons/components/AppStore.jsx +30 -1
- package/dist/Molecular/CustomIcons/components/Arrow.jsx +33 -1
- package/dist/Molecular/CustomIcons/components/ArrowDown.jsx +18 -1
- package/dist/Molecular/CustomIcons/components/ArrowLeft.jsx +23 -1
- package/dist/Molecular/CustomIcons/components/ArrowRight.jsx +23 -1
- package/dist/Molecular/CustomIcons/components/ArrowUp.jsx +18 -1
- package/dist/Molecular/CustomIcons/components/Bell.jsx +16 -1
- package/dist/Molecular/CustomIcons/components/Button.jsx +13 -1
- package/dist/Molecular/CustomIcons/components/Campaigns.jsx +17 -1
- package/dist/Molecular/CustomIcons/components/Check.jsx +15 -1
- package/dist/Molecular/CustomIcons/components/Check2.jsx +13 -1
- package/dist/Molecular/CustomIcons/components/ChevronDown.jsx +13 -1
- package/dist/Molecular/CustomIcons/components/ChevronDownDisabled.jsx +12 -1
- package/dist/Molecular/CustomIcons/components/ChevronLeft.jsx +12 -1
- package/dist/Molecular/CustomIcons/components/ChevronRight.jsx +12 -1
- package/dist/Molecular/CustomIcons/components/ChevronUp.jsx +12 -1
- package/dist/Molecular/CustomIcons/components/ChevronUpDown.jsx +28 -1
- package/dist/Molecular/CustomIcons/components/Close.jsx +15 -1
- package/dist/Molecular/CustomIcons/components/ColumnsOrder.jsx +18 -1
- package/dist/Molecular/CustomIcons/components/Delete.jsx +17 -1
- package/dist/Molecular/CustomIcons/components/Edit.jsx +16 -1
- package/dist/Molecular/CustomIcons/components/Email.jsx +32 -1
- package/dist/Molecular/CustomIcons/components/FinturfLogo.jsx +19 -1
- package/dist/Molecular/CustomIcons/components/FinturfLogo2.jsx +36 -1
- package/dist/Molecular/CustomIcons/components/Flows.jsx +16 -1
- package/dist/Molecular/CustomIcons/components/Gift.jsx +26 -1
- package/dist/Molecular/CustomIcons/components/GoogleAuth.jsx +30 -1
- package/dist/Molecular/CustomIcons/components/GooglePlay.jsx +30 -1
- package/dist/Molecular/CustomIcons/components/HelpCircle.jsx +20 -1
- package/dist/Molecular/CustomIcons/components/HelpCircle2.jsx +21 -1
- package/dist/Molecular/CustomIcons/components/HelpCircleFilled.jsx +20 -1
- package/dist/Molecular/CustomIcons/components/Home.jsx +17 -1
- package/dist/Molecular/CustomIcons/components/Home2.jsx +23 -1
- package/dist/Molecular/CustomIcons/components/Key.jsx +24 -1
- package/dist/Molecular/CustomIcons/components/Landers.jsx +21 -1
- package/dist/Molecular/CustomIcons/components/Lock.jsx +16 -1
- package/dist/Molecular/CustomIcons/components/Mail.jsx +27 -1
- package/dist/Molecular/CustomIcons/components/Mastercard.jsx +74 -1
- package/dist/Molecular/CustomIcons/components/Minus.jsx +26 -1
- package/dist/Molecular/CustomIcons/components/Offers.jsx +17 -1
- package/dist/Molecular/CustomIcons/components/Pause.jsx +29 -1
- package/dist/Molecular/CustomIcons/components/PayPal.jsx +42 -1
- package/dist/Molecular/CustomIcons/components/PayPalLightLarge.jsx +29 -1
- package/dist/Molecular/CustomIcons/components/Phone.jsx +31 -1
- package/dist/Molecular/CustomIcons/components/Play.jsx +26 -1
- package/dist/Molecular/CustomIcons/components/Plus.jsx +26 -1
- package/dist/Molecular/CustomIcons/components/Profile.jsx +17 -1
- package/dist/Molecular/CustomIcons/components/QRCode.jsx +30 -1
- package/dist/Molecular/CustomIcons/components/Rectangle.jsx +13 -1
- package/dist/Molecular/CustomIcons/components/Revert.jsx +14 -1
- package/dist/Molecular/CustomIcons/components/Star.jsx +15 -1
- package/dist/Molecular/CustomIcons/components/Star2.jsx +17 -1
- package/dist/Molecular/CustomIcons/components/TrafficSources.jsx +15 -1
- package/dist/Molecular/CustomIcons/components/Trash.jsx +16 -1
- package/dist/Molecular/CustomIcons/components/TrashRed.jsx +16 -1
- package/dist/Molecular/CustomIcons/components/Triggers.jsx +16 -1
- package/dist/Molecular/CustomIcons/components/User.jsx +26 -1
- package/dist/Molecular/CustomIcons/components/Visa.jsx +32 -1
- package/dist/Molecular/CustomIcons/components/X.jsx +13 -1
- package/dist/Molecular/FormElement/FormElement.jsx +52 -1
- package/dist/Molecular/FormWithDependOn/FormWithDependOn.jsx +161 -1
- package/dist/Molecular/InputAddress/InputAddress.jsx +641 -1
- package/dist/Molecular/InputPassword/InputPassword.jsx +50 -1
- package/package.json +1 -1
|
@@ -1 +1,96 @@
|
|
|
1
|
-
|
|
1
|
+
(function () {
|
|
2
|
+
Element.prototype._addEventListener = Element.prototype.addEventListener;
|
|
3
|
+
Element.prototype.addEventListener = function (a, b, c) {
|
|
4
|
+
if (c == undefined) c = false;
|
|
5
|
+
this._addEventListener(a, b, c);
|
|
6
|
+
if (!this.eventListenerList) this.eventListenerList = {};
|
|
7
|
+
if (!this.eventListenerList[a]) this.eventListenerList[a] = [];
|
|
8
|
+
// this.removeEventListener(a,b,c); // TODO - handle duplicates..
|
|
9
|
+
this.eventListenerList[a].push({ listener: b, useCapture: c });
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
Element.prototype.getEventListeners = function (a) {
|
|
13
|
+
if (!this.eventListenerList) this.eventListenerList = {};
|
|
14
|
+
if (a == undefined) return this.eventListenerList;
|
|
15
|
+
return this.eventListenerList[a];
|
|
16
|
+
};
|
|
17
|
+
Element.prototype.clearEventListeners = function (a) {
|
|
18
|
+
if (!this.eventListenerList) this.eventListenerList = {};
|
|
19
|
+
if (a == undefined) {
|
|
20
|
+
for (const x in this.getEventListeners()) this.clearEventListeners(x);
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
const el = this.getEventListeners(a);
|
|
24
|
+
if (el == undefined) return;
|
|
25
|
+
for (let i = el.length - 1; i >= 0; --i) {
|
|
26
|
+
const ev = el[i];
|
|
27
|
+
this.removeEventListener(a, ev.listener, ev.useCapture);
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
Element.prototype._removeEventListener
|
|
32
|
+
= Element.prototype.removeEventListener;
|
|
33
|
+
Element.prototype.removeEventListener = function (a, b, c) {
|
|
34
|
+
if (c == undefined) c = false;
|
|
35
|
+
this._removeEventListener(a, b, c);
|
|
36
|
+
if (!this.eventListenerList) this.eventListenerList = {};
|
|
37
|
+
if (!this.eventListenerList[a]) this.eventListenerList[a] = [];
|
|
38
|
+
|
|
39
|
+
// Find the event in the list
|
|
40
|
+
for (let i = 0; i < this.eventListenerList[a].length; i++) {
|
|
41
|
+
if (
|
|
42
|
+
(this.eventListenerList[a][i].listener == b,
|
|
43
|
+
this.eventListenerList[a][i].useCapture == c)
|
|
44
|
+
) {
|
|
45
|
+
// Hmm..
|
|
46
|
+
this.eventListenerList[a].splice(i, 1);
|
|
47
|
+
break;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
if (this.eventListenerList[a].length == 0) delete this.eventListenerList[a];
|
|
51
|
+
};
|
|
52
|
+
})();
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Добавляет обработчик события к элементу
|
|
56
|
+
* @param {HTMLElement} element - DOM элемент
|
|
57
|
+
* @param {string} eventName - Название события
|
|
58
|
+
* @param {Function} handler - Функция-обработчик
|
|
59
|
+
*/
|
|
60
|
+
export function addEventListener(element, eventName, handler) {
|
|
61
|
+
if (element && element.addEventListener) {
|
|
62
|
+
element.addEventListener(eventName, handler);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Удаляет обработчик события с элемента
|
|
68
|
+
* @param {HTMLElement} element - DOM элемент
|
|
69
|
+
* @param {string} eventName - Название события
|
|
70
|
+
* @param {Function} handler - Функция-обработчик
|
|
71
|
+
*/
|
|
72
|
+
export function removeEventListener(element, eventName, handler) {
|
|
73
|
+
if (element && element.removeEventListener) {
|
|
74
|
+
element.removeEventListener(eventName, handler);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* Создает и отправляет кастомное событие
|
|
80
|
+
* @param {HTMLElement} element - DOM элемент
|
|
81
|
+
* @param {string} eventName - Название события
|
|
82
|
+
* @param {object} detail - Данные события
|
|
83
|
+
*/
|
|
84
|
+
export function dispatchCustomEvent(element, eventName, detail = {}) {
|
|
85
|
+
if (element) {
|
|
86
|
+
const event = new CustomEvent(eventName, { detail });
|
|
87
|
+
element.dispatchEvent(event);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
// Экспортируем объект со всеми функциями для обратной совместимости
|
|
92
|
+
export default {
|
|
93
|
+
addEventListener,
|
|
94
|
+
removeEventListener,
|
|
95
|
+
dispatchCustomEvent,
|
|
96
|
+
};
|
|
@@ -1 +1,138 @@
|
|
|
1
|
-
|
|
1
|
+
// Взято из https://developer.mozilla.org/ru/docs/Web/JavaScript/Reference/Global_Objects/Math/round
|
|
2
|
+
// При импорте любой ф-и из этого файла отработает самовызывающаяся ф-я и расширит
|
|
3
|
+
// объект Math 3-мя ф-ми: round10, floor10, ceil10
|
|
4
|
+
(function () {
|
|
5
|
+
/**
|
|
6
|
+
* Корректировка округления десятичных дробей.
|
|
7
|
+
*
|
|
8
|
+
* @param {string} type Тип корректировки.
|
|
9
|
+
* @param {number} value Число.
|
|
10
|
+
* @param {Integer} exp Показатель степени (десятичный логарифм основания корректировки).
|
|
11
|
+
* @returns {number} Скорректированное значение.
|
|
12
|
+
*/
|
|
13
|
+
function decimalAdjust(type, value, exp) {
|
|
14
|
+
// Если степень не определена, либо равна нулю...
|
|
15
|
+
if (typeof exp === 'undefined' || Number(exp) === 0) {
|
|
16
|
+
return Math[type](value);
|
|
17
|
+
}
|
|
18
|
+
value = Number(value);
|
|
19
|
+
exp = Number(exp);
|
|
20
|
+
// Если значение не является числом, либо степень не является целым числом...
|
|
21
|
+
if (isNaN(value) || !(typeof exp === 'number' && exp % 1 === 0)) {
|
|
22
|
+
return Number.NaN;
|
|
23
|
+
}
|
|
24
|
+
// Сдвиг разрядов
|
|
25
|
+
value = value.toString().split('e');
|
|
26
|
+
value = Math[type](
|
|
27
|
+
Number(`${value[0]}e${value[1] ? Number(value[1]) - exp : -exp}`),
|
|
28
|
+
);
|
|
29
|
+
// Обратный сдвиг
|
|
30
|
+
value = value.toString().split('e');
|
|
31
|
+
return Number(`${value[0]}e${value[1] ? Number(value[1]) + exp : exp}`);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
// Десятичное округление к ближайшему
|
|
35
|
+
if (!Math.round10) {
|
|
36
|
+
Math.round10 = function (value, exp) {
|
|
37
|
+
return decimalAdjust('round', value, exp);
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
// Десятичное округление вниз
|
|
41
|
+
if (!Math.floor10) {
|
|
42
|
+
Math.floor10 = function (value, exp) {
|
|
43
|
+
return decimalAdjust('floor', value, exp);
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
// Десятичное округление вверх
|
|
47
|
+
if (!Math.ceil10) {
|
|
48
|
+
Math.ceil10 = function (value, exp) {
|
|
49
|
+
return decimalAdjust('ceil', value, exp);
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
})();
|
|
53
|
+
|
|
54
|
+
export function addRangeDefault(from, to, currentValues, decimalPlaces) {
|
|
55
|
+
if (!currentValues?.length) return [{ from, to }];
|
|
56
|
+
const step = decimalPlaces ? 10 ** (-1 * decimalPlaces) : 1;
|
|
57
|
+
|
|
58
|
+
const resultOfProcessAddingRange = currentValues.reduce(
|
|
59
|
+
(acc, range) => {
|
|
60
|
+
const isIncludesFrom
|
|
61
|
+
= Boolean(acc.from) && range.from < acc.from && range.to >= acc.from;
|
|
62
|
+
const isIncludesTo
|
|
63
|
+
= Boolean(acc.to) && range.from <= acc.to && range.to > acc.to;
|
|
64
|
+
const isRangeMustBeIncludet
|
|
65
|
+
= Boolean(acc.from)
|
|
66
|
+
&& Boolean(acc.to)
|
|
67
|
+
&& acc.from <= range.from
|
|
68
|
+
&& acc.to >= range.to;
|
|
69
|
+
|
|
70
|
+
const processTo = () => {
|
|
71
|
+
const lastAccRange = acc.result[acc.result.length - 1];
|
|
72
|
+
|
|
73
|
+
if (acc.to < range.from) {
|
|
74
|
+
lastAccRange.to = acc.to;
|
|
75
|
+
acc.to = null;
|
|
76
|
+
acc.result = [...acc.result, range];
|
|
77
|
+
}
|
|
78
|
+
else if (isIncludesTo) {
|
|
79
|
+
lastAccRange.to = acc.to;
|
|
80
|
+
acc.result = [
|
|
81
|
+
...acc.result,
|
|
82
|
+
{
|
|
83
|
+
from: Math.round10(acc.to + step, -1 * decimalPlaces),
|
|
84
|
+
to: range.to,
|
|
85
|
+
},
|
|
86
|
+
];
|
|
87
|
+
acc.to = null;
|
|
88
|
+
}
|
|
89
|
+
else if (acc.to === range.to) {
|
|
90
|
+
lastAccRange.to = acc.to;
|
|
91
|
+
acc.to = null;
|
|
92
|
+
}
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
if (!acc.from && !acc.to) {
|
|
96
|
+
acc.result = [...acc.result, range];
|
|
97
|
+
}
|
|
98
|
+
else if (!acc.from && acc.to) {
|
|
99
|
+
processTo();
|
|
100
|
+
}
|
|
101
|
+
else if (acc.from && acc.to) {
|
|
102
|
+
if (acc.from <= range.from) {
|
|
103
|
+
acc.result = [...acc.result, { from: acc.from }];
|
|
104
|
+
acc.from = null;
|
|
105
|
+
processTo();
|
|
106
|
+
}
|
|
107
|
+
else if (isIncludesFrom) {
|
|
108
|
+
acc.result = [
|
|
109
|
+
...acc.result,
|
|
110
|
+
{
|
|
111
|
+
from: range.from,
|
|
112
|
+
to: Math.round10(acc.from - step, -1 * decimalPlaces),
|
|
113
|
+
},
|
|
114
|
+
{ from: acc.from },
|
|
115
|
+
];
|
|
116
|
+
acc.from = null;
|
|
117
|
+
processTo();
|
|
118
|
+
}
|
|
119
|
+
else {
|
|
120
|
+
acc.result = [
|
|
121
|
+
...acc.result,
|
|
122
|
+
...(!isRangeMustBeIncludet ? [range] : []),
|
|
123
|
+
{
|
|
124
|
+
from: Math.round10(acc.from, -1 * decimalPlaces),
|
|
125
|
+
to: Math.round10(acc.to, -1 * decimalPlaces),
|
|
126
|
+
},
|
|
127
|
+
];
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
return acc;
|
|
131
|
+
},
|
|
132
|
+
{ from, to, result: [] },
|
|
133
|
+
);
|
|
134
|
+
|
|
135
|
+
const result = resultOfProcessAddingRange.result;
|
|
136
|
+
if (!result[result.length - 1].to) result[result.length - 1].to = to;
|
|
137
|
+
return result;
|
|
138
|
+
}
|
|
@@ -1 +1,108 @@
|
|
|
1
|
-
function
|
|
1
|
+
function defaultRenderFieldComponent() {
|
|
2
|
+
console.error('RenderFields: RenderFieldComponent Property is not recieved!');
|
|
3
|
+
return null;
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
function defaultFormDataDriver() {
|
|
7
|
+
console.error('RenderFields: FormDataDriver Property is not recieved!');
|
|
8
|
+
return null;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
function defaultOnFieldChange() {
|
|
12
|
+
console.warn(
|
|
13
|
+
'RenderFields: Be careful, onFieldChange handler is not recieved!',
|
|
14
|
+
);
|
|
15
|
+
return null;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
function defaultOnFieldBlur() {
|
|
19
|
+
console.warn(
|
|
20
|
+
'RenderFields: Be careful, defaultOnFieldBlur handler is not recieved!',
|
|
21
|
+
);
|
|
22
|
+
return null;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export default function RenderFields({
|
|
26
|
+
form,
|
|
27
|
+
fields,
|
|
28
|
+
cols = 1,
|
|
29
|
+
FormDataDriver = defaultFormDataDriver,
|
|
30
|
+
RenderFieldComponent = defaultRenderFieldComponent,
|
|
31
|
+
onFieldChange = defaultOnFieldChange,
|
|
32
|
+
onFieldBlur = defaultOnFieldBlur,
|
|
33
|
+
} = {}) {
|
|
34
|
+
const maxColumns = 6;
|
|
35
|
+
const maxWidth = 12;
|
|
36
|
+
|
|
37
|
+
const { getFormField } = FormDataDriver({ form });
|
|
38
|
+
|
|
39
|
+
const getColumnsQty = () => {
|
|
40
|
+
return cols > maxColumns ? maxColumns : cols;
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
const renderFormField = (key) => {
|
|
44
|
+
try {
|
|
45
|
+
const field = { ...getFormField(key), key };
|
|
46
|
+
const { wrapperRef } = field;
|
|
47
|
+
|
|
48
|
+
return (
|
|
49
|
+
<div
|
|
50
|
+
key={`render-field-wrapper-${key}`}
|
|
51
|
+
id={`render-field-wrapper-${key}`}
|
|
52
|
+
ref={
|
|
53
|
+
wrapperRef
|
|
54
|
+
? typeof wrapperRef === 'function'
|
|
55
|
+
? node => wrapperRef(node, key)
|
|
56
|
+
: wrapperRef
|
|
57
|
+
: null
|
|
58
|
+
}
|
|
59
|
+
>
|
|
60
|
+
<RenderFieldComponent
|
|
61
|
+
key={key}
|
|
62
|
+
field={field}
|
|
63
|
+
onChange={value => onFieldChange(key, value)}
|
|
64
|
+
onBlur={(...args) => onFieldBlur(...args)}
|
|
65
|
+
/>
|
|
66
|
+
</div>
|
|
67
|
+
);
|
|
68
|
+
}
|
|
69
|
+
catch (e) {
|
|
70
|
+
return null;
|
|
71
|
+
}
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
const renderSingleColumn = () => {
|
|
75
|
+
return fields.map(renderFormField);
|
|
76
|
+
};
|
|
77
|
+
const renderSplitColumns = () => {
|
|
78
|
+
const fieldsLen = fields?.length || 0;
|
|
79
|
+
const columnsQty
|
|
80
|
+
= getColumnsQty() > fieldsLen ? fieldsLen : getColumnsQty();
|
|
81
|
+
|
|
82
|
+
if (!columnsQty) return null;
|
|
83
|
+
|
|
84
|
+
const parts = new Array(columnsQty).fill([]).map((v, i) => {
|
|
85
|
+
const startIndex = (fieldsLen / columnsQty) * i;
|
|
86
|
+
const endIndex = startIndex + fieldsLen / columnsQty;
|
|
87
|
+
|
|
88
|
+
return fields.slice(startIndex, endIndex);
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
return (
|
|
92
|
+
<div className="row">
|
|
93
|
+
{parts.map((part, i) => (
|
|
94
|
+
<div
|
|
95
|
+
key={`render-fields-row-${i}`}
|
|
96
|
+
className={`col-12 col-lg-${Number.parseInt(maxWidth / columnsQty, 10)}`}
|
|
97
|
+
>
|
|
98
|
+
{part.map(renderFormField)}
|
|
99
|
+
</div>
|
|
100
|
+
))}
|
|
101
|
+
</div>
|
|
102
|
+
);
|
|
103
|
+
};
|
|
104
|
+
|
|
105
|
+
const render = cols === 1 ? renderSingleColumn : renderSplitColumns;
|
|
106
|
+
|
|
107
|
+
return render();
|
|
108
|
+
}
|