@rolster/react-components 1.5.7 → 18.9.0
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/cjs/assets/{lib.cjs-c052832f.css → index-Fy0sGm5F.css} +159 -106
- package/dist/cjs/index.js +2036 -0
- package/dist/cjs/index.js.map +1 -0
- package/dist/es/assets/{lib-c052832f.css → index-Fy0sGm5F.css} +159 -106
- package/dist/es/index.js +1970 -0
- package/dist/es/index.js.map +1 -0
- package/dist/esm/components/atoms/Amount/Amount.css +3 -2
- package/dist/esm/components/atoms/Amount/Amount.d.ts +3 -1
- package/dist/esm/components/atoms/Amount/Amount.js +2 -2
- package/dist/esm/components/atoms/Amount/Amount.js.map +1 -1
- package/dist/esm/components/atoms/Button/Button.css +1 -1
- package/dist/esm/components/atoms/CheckBox/CheckBox.d.ts +8 -1
- package/dist/esm/components/atoms/CheckBox/CheckBox.js +7 -2
- package/dist/esm/components/atoms/CheckBox/CheckBox.js.map +1 -1
- package/dist/esm/components/atoms/Icon/Icon.css +1 -1
- package/dist/esm/components/atoms/Input/Input.css +1 -1
- package/dist/esm/components/atoms/Input/Input.d.ts +3 -3
- package/dist/esm/components/atoms/Input/Input.js +12 -10
- package/dist/esm/components/atoms/Input/Input.js.map +1 -1
- package/dist/esm/components/atoms/InputMoney/InputMoney.d.ts +3 -3
- package/dist/esm/components/atoms/InputMoney/InputMoney.js +5 -10
- package/dist/esm/components/atoms/InputMoney/InputMoney.js.map +1 -1
- package/dist/esm/components/atoms/InputNumber/InputNumber.d.ts +3 -3
- package/dist/esm/components/atoms/InputNumber/InputNumber.js +5 -10
- package/dist/esm/components/atoms/InputNumber/InputNumber.js.map +1 -1
- package/dist/esm/components/atoms/InputPassword/InputPassword.d.ts +1 -1
- package/dist/esm/components/atoms/InputPassword/InputPassword.js +9 -7
- package/dist/esm/components/atoms/InputPassword/InputPassword.js.map +1 -1
- package/dist/esm/components/atoms/InputText/InputText.d.ts +3 -3
- package/dist/esm/components/atoms/InputText/InputText.js +5 -10
- package/dist/esm/components/atoms/InputText/InputText.js.map +1 -1
- package/dist/esm/components/atoms/Label/Label.css +3 -0
- package/dist/esm/components/atoms/Label/Label.d.ts +2 -0
- package/dist/esm/components/atoms/Label/Label.js +5 -0
- package/dist/esm/components/atoms/Label/Label.js.map +1 -0
- package/dist/esm/components/atoms/MessageIcon/MessageIcon.css +12 -0
- package/dist/esm/components/atoms/MessageIcon/MessageIcon.d.ts +7 -0
- package/dist/esm/components/atoms/MessageIcon/MessageIcon.js +7 -0
- package/dist/esm/components/atoms/MessageIcon/MessageIcon.js.map +1 -0
- package/dist/esm/components/atoms/RadioButton/RadioButton.d.ts +2 -1
- package/dist/esm/components/atoms/RadioButton/RadioButton.js +2 -2
- package/dist/esm/components/atoms/RadioButton/RadioButton.js.map +1 -1
- package/dist/esm/components/atoms/SearchInput/SearchInput.d.ts +2 -2
- package/dist/esm/components/atoms/Switch/Switch.css +40 -21
- package/dist/esm/components/atoms/Switch/Switch.d.ts +7 -1
- package/dist/esm/components/atoms/Switch/Switch.js +8 -3
- package/dist/esm/components/atoms/Switch/Switch.js.map +1 -1
- package/dist/esm/components/atoms/index.d.ts +2 -0
- package/dist/esm/components/atoms/index.js +2 -0
- package/dist/esm/components/atoms/index.js.map +1 -1
- package/dist/esm/components/molecules/ButtonToggle/ButtonToggle.js.map +1 -1
- package/dist/esm/components/molecules/CheckBoxLabel/CheckBoxLabel.css +1 -5
- package/dist/esm/components/molecules/CheckBoxLabel/CheckBoxLabel.d.ts +1 -1
- package/dist/esm/components/molecules/CheckBoxLabel/CheckBoxLabel.js.map +1 -1
- package/dist/esm/components/molecules/DayPicker/DayPicker.d.ts +1 -1
- package/dist/esm/components/molecules/DayPicker/DayPicker.js +1 -1
- package/dist/esm/components/molecules/DayPicker/DayPicker.js.map +1 -1
- package/dist/esm/components/molecules/DayRangePicker/DayRangePicker.d.ts +1 -1
- package/dist/esm/components/molecules/DayRangePicker/DayRangePicker.js +1 -1
- package/dist/esm/components/molecules/DayRangePicker/DayRangePicker.js.map +1 -1
- package/dist/esm/components/molecules/MoneyField/MoneyField.d.ts +4 -2
- package/dist/esm/components/molecules/MoneyField/MoneyField.js +7 -8
- package/dist/esm/components/molecules/MoneyField/MoneyField.js.map +1 -1
- package/dist/esm/components/molecules/MonthPicker/MonthPicker.d.ts +1 -1
- package/dist/esm/components/molecules/MonthPicker/MonthPicker.js.map +1 -1
- package/dist/esm/components/molecules/MonthTitlePicker/MonthTitlePicker.d.ts +1 -1
- package/dist/esm/components/molecules/MonthTitlePicker/MonthTitlePicker.js +1 -1
- package/dist/esm/components/molecules/MonthTitlePicker/MonthTitlePicker.js.map +1 -1
- package/dist/esm/components/molecules/NumberField/NumberField.d.ts +4 -2
- package/dist/esm/components/molecules/NumberField/NumberField.js +7 -8
- package/dist/esm/components/molecules/NumberField/NumberField.js.map +1 -1
- package/dist/esm/components/molecules/Pagination/Pagination.js.map +1 -1
- package/dist/esm/components/molecules/PasswordField/PasswordField.d.ts +1 -1
- package/dist/esm/components/molecules/PasswordField/PasswordField.js +6 -7
- package/dist/esm/components/molecules/PasswordField/PasswordField.js.map +1 -1
- package/dist/esm/components/molecules/RadioButtonLabel/RadioButtonLabel.d.ts +1 -1
- package/dist/esm/components/molecules/RadioButtonLabel/RadioButtonLabel.js.map +1 -1
- package/dist/esm/components/molecules/SwitchLabel/SwitchLabel.css +2 -5
- package/dist/esm/components/molecules/SwitchLabel/SwitchLabel.d.ts +1 -1
- package/dist/esm/components/molecules/SwitchLabel/SwitchLabel.js.map +1 -1
- package/dist/esm/components/molecules/TextField/TextField.d.ts +4 -2
- package/dist/esm/components/molecules/TextField/TextField.js +7 -8
- package/dist/esm/components/molecules/TextField/TextField.js.map +1 -1
- package/dist/esm/components/molecules/YearPicker/YearPicker.d.ts +2 -2
- package/dist/esm/components/molecules/YearPicker/YearPicker.js +2 -2
- package/dist/esm/components/molecules/YearPicker/YearPicker.js.map +1 -1
- package/dist/esm/components/organisms/AutocompleteField/AutocompleteField.css +21 -19
- package/dist/esm/components/organisms/AutocompleteField/AutocompleteField.d.ts +5 -3
- package/dist/esm/components/organisms/AutocompleteField/AutocompleteField.js +32 -29
- package/dist/esm/components/organisms/AutocompleteField/AutocompleteField.js.map +1 -1
- package/dist/esm/components/organisms/Card/Card.css +1 -1
- package/dist/esm/components/organisms/Confirmation/Confirmation.css +58 -34
- package/dist/esm/components/organisms/Confirmation/Confirmation.js.map +1 -1
- package/dist/esm/components/organisms/Datatable/Datatable.d.ts +2 -1
- package/dist/esm/components/organisms/Datatable/Datatable.js +3 -2
- package/dist/esm/components/organisms/Datatable/Datatable.js.map +1 -1
- package/dist/esm/components/organisms/DateField/DateField.css +3 -0
- package/dist/esm/components/organisms/DateField/DateField.d.ts +1 -1
- package/dist/esm/components/organisms/DateField/DateField.js +10 -3
- package/dist/esm/components/organisms/DateField/DateField.js.map +1 -1
- package/dist/esm/components/organisms/DatePicker/DatePicker.d.ts +1 -1
- package/dist/esm/components/organisms/DatePicker/DatePicker.js +2 -2
- package/dist/esm/components/organisms/DatePicker/DatePicker.js.map +1 -1
- package/dist/esm/components/organisms/DateRangeField/DateRangeField.d.ts +1 -1
- package/dist/esm/components/organisms/DateRangeField/DateRangeField.js.map +1 -1
- package/dist/esm/components/organisms/DateRangePicker/DateRangePicker.d.ts +1 -1
- package/dist/esm/components/organisms/DateRangePicker/DateRangePicker.js +1 -1
- package/dist/esm/components/organisms/DateRangePicker/DateRangePicker.js.map +1 -1
- package/dist/esm/components/organisms/SelectField/SelectField.d.ts +4 -3
- package/dist/esm/components/organisms/SelectField/SelectField.js +16 -9
- package/dist/esm/components/organisms/SelectField/SelectField.js.map +1 -1
- package/dist/esm/components/organisms/Snackbar/Snackbar.css +14 -16
- package/dist/esm/components/organisms/Snackbar/Snackbar.d.ts +1 -1
- package/dist/esm/components/organisms/Snackbar/Snackbar.js +1 -1
- package/dist/esm/components/organisms/Snackbar/Snackbar.js.map +1 -1
- package/dist/esm/hooks/index.d.ts +0 -2
- package/dist/esm/hooks/index.js +0 -2
- package/dist/esm/hooks/index.js.map +1 -1
- package/dist/esm/hooks/list-control.hook.d.ts +13 -7
- package/dist/esm/hooks/list-control.hook.js +16 -9
- package/dist/esm/hooks/list-control.hook.js.map +1 -1
- package/dist/esm/models.d.ts +4 -4
- package/dist/esm/models.js +6 -7
- package/dist/esm/models.js.map +1 -1
- package/dist/esm/utils/css.d.ts +1 -1
- package/dist/esm/utils/css.js +4 -1
- package/dist/esm/utils/css.js.map +1 -1
- package/dist/esm/utils/date-range-picker.js.map +1 -1
- package/dist/esm/utils/day-picker.js.map +1 -1
- package/dist/esm/utils/month-picker.js +1 -1
- package/dist/esm/utils/month-picker.js.map +1 -1
- package/dist/esm/utils/year-picker.js.map +1 -1
- package/package.json +25 -11
- package/dist/cjs/lib.cjs.js +0 -3366
- package/dist/cjs/lib.cjs.js.map +0 -1
- package/dist/es/lib.js +0 -3300
- package/dist/es/lib.js.map +0 -1
- package/dist/esm/hooks/form-control.hook.d.ts +0 -15
- package/dist/esm/hooks/form-control.hook.js +0 -77
- package/dist/esm/hooks/form-control.hook.js.map +0 -1
- package/dist/esm/hooks/form-group.hook.d.ts +0 -2
- package/dist/esm/hooks/form-group.hook.js +0 -22
- package/dist/esm/hooks/form-group.hook.js.map +0 -1
package/dist/es/index.js
ADDED
|
@@ -0,0 +1,1970 @@
|
|
|
1
|
+
import { jsx, jsxs } from 'react/jsx-runtime';
|
|
2
|
+
import { useState, useRef, useEffect, createContext } from 'react';
|
|
3
|
+
import { currencyFormat, PartialSealed } from '@rolster/helpers-advanced';
|
|
4
|
+
import { daysFromMonth, weight, refactorDay, DAY_LABELS, normalizeMinTime, isBefore, formatDate, isAfter, timeDifference, isBetween, Month, MONTH_NAMES, refactorYear, refactorMonth } from '@rolster/helpers-date';
|
|
5
|
+
import { hasPattern } from '@rolster/helpers-string';
|
|
6
|
+
import ReactDOM from 'react-dom';
|
|
7
|
+
import 'uuid';
|
|
8
|
+
import { BehaviorSubject } from 'rxjs';
|
|
9
|
+
|
|
10
|
+
const baseCls = 'rls-tabular-text';
|
|
11
|
+
const pointers = ['.', ','];
|
|
12
|
+
function charClass(char) {
|
|
13
|
+
return pointers.includes(char) ? `${baseCls}__pointer` : `${baseCls}__char`;
|
|
14
|
+
}
|
|
15
|
+
function RlsTabularText({ value }) {
|
|
16
|
+
return (jsx("div", { className: "rls-tabular-text", children: value?.split('').map((char, index) => (jsx("span", { className: charClass(char), children: char }, index))) }));
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
function RlsAmount({ value, decimals, rlsTheme, symbol }) {
|
|
20
|
+
return (jsxs("div", { className: "rls-amount", "rls-theme": rlsTheme, children: [symbol && jsx("span", { children: symbol }), jsx(RlsTabularText, { value: currencyFormat({ value, decimals }) })] }));
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
function renderClassStatus(base, status = {}, aditionals) {
|
|
24
|
+
const resultClass = [base];
|
|
25
|
+
Object.entries(status).forEach(([name, value]) => {
|
|
26
|
+
if (value) {
|
|
27
|
+
typeof value === 'string'
|
|
28
|
+
? resultClass.push(`${base}--${value}`)
|
|
29
|
+
: resultClass.push(`${base}--${name}`);
|
|
30
|
+
}
|
|
31
|
+
});
|
|
32
|
+
if (aditionals) {
|
|
33
|
+
resultClass.push(aditionals);
|
|
34
|
+
}
|
|
35
|
+
return resultClass.join(' ');
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
function RlsAvatar({ children, rounded, skeleton, rlsTheme }) {
|
|
39
|
+
return (jsx("div", { className: renderClassStatus('rls-avatar', { rounded, skeleton }), "rls-theme": rlsTheme, children: children }));
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
function RlsBreadcrumb({ labels }) {
|
|
43
|
+
return (jsx("div", { className: "rls-breadcrumb", children: labels.map(({ label, onClick }, index) => (jsx("label", { className: "rls-breadcrumb__label", onClick: onClick, children: jsx("a", { className: "rls-breadcrumb__label__a", children: label }) }, index))) }));
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
function RlsIcon({ value, skeleton }) {
|
|
47
|
+
return (jsx("div", { className: renderClassStatus('rls-icon', { skeleton }), children: jsx("i", { className: `rls-icon-${value}` }) }));
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
function RlsButton({ type, children, disabled, prefixIcon, suffixIcon, rlsTheme, onClick }) {
|
|
51
|
+
return (jsx("button", { className: "rls-button", onClick: onClick, "rls-theme": rlsTheme, disabled: disabled, children: jsxs("div", { className: renderClassStatus('rls-button__content', { type }), children: [prefixIcon && jsx(RlsIcon, { value: prefixIcon }), children && (jsx("div", { className: "rls-button__label", children: children })), suffixIcon && jsx(RlsIcon, { value: suffixIcon })] }) }));
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
function RlsButtonAction({ icon, disabled, tooltip, onClick }) {
|
|
55
|
+
return (jsxs("button", { className: "rls-button-action", onClick: onClick, disabled: disabled, children: [jsx("div", { className: "rls-button-action__content", children: jsx(RlsIcon, { value: icon }) }), tooltip && (jsx("div", { className: "rls-button-action__tooltip caption-semibold", children: jsx("span", { children: tooltip }) }))] }));
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
function RlsCheckBox({ checked, disabled, onClick, rlsTheme }) {
|
|
59
|
+
return (jsx("div", { className: renderClassStatus('rls-checkbox', { checked, disabled }), onClick: onClick, "rls-theme": rlsTheme, children: jsx("div", { className: "rls-checkbox__component" }) }));
|
|
60
|
+
}
|
|
61
|
+
function RlsCheckBoxControl({ formControl, disabled, rlsTheme }) {
|
|
62
|
+
return (jsx(RlsCheckBox, { checked: formControl.state || false, disabled: disabled, onClick: () => {
|
|
63
|
+
formControl.setState(!formControl.state);
|
|
64
|
+
}, rlsTheme: rlsTheme }));
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
function RlsInput({ children, disabled, formControl, onValue, placeholder, type, value }) {
|
|
68
|
+
const [focused, setFocused] = useState(false);
|
|
69
|
+
function onChange(event) {
|
|
70
|
+
switch (type) {
|
|
71
|
+
case 'number':
|
|
72
|
+
setState(+event.target.value);
|
|
73
|
+
break;
|
|
74
|
+
default:
|
|
75
|
+
setState(event.target.value);
|
|
76
|
+
break;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
function setState(value) {
|
|
80
|
+
formControl?.setState(value);
|
|
81
|
+
if (onValue) {
|
|
82
|
+
onValue(value);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
function onFocus() {
|
|
86
|
+
formControl?.focus();
|
|
87
|
+
setFocused(true);
|
|
88
|
+
}
|
|
89
|
+
function onBlur() {
|
|
90
|
+
if (formControl && !formControl.touched) {
|
|
91
|
+
formControl.touch();
|
|
92
|
+
}
|
|
93
|
+
formControl?.blur();
|
|
94
|
+
setFocused(false);
|
|
95
|
+
}
|
|
96
|
+
return (jsxs("div", { className: renderClassStatus('rls-input', {
|
|
97
|
+
focused: formControl?.focused || focused,
|
|
98
|
+
disabled: formControl?.disabled || disabled
|
|
99
|
+
}), children: [jsx("input", { ref: formControl?.elementRef, className: "rls-input__component", autoComplete: "off", type: type || 'text', placeholder: placeholder, disabled: formControl?.disabled || disabled, onFocus: onFocus, onBlur: onBlur, onChange: onChange, value: formControl?.state || value || '' }), jsx("span", { className: "rls-input__value", children: children })] }));
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
function RlsInputMoney({ decimals, disabled, formControl, onValue, placeholder, symbol, value }) {
|
|
103
|
+
const [valueInput, setValueInput] = useState(value || 0);
|
|
104
|
+
function onMoney(value) {
|
|
105
|
+
if (!formControl) {
|
|
106
|
+
setValueInput(value);
|
|
107
|
+
}
|
|
108
|
+
if (onValue) {
|
|
109
|
+
onValue(value);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
return (jsx("div", { className: "rls-input-money", children: jsx(RlsInput, { formControl: formControl, type: "number", value: value, disabled: disabled, placeholder: placeholder, onValue: onMoney, children: jsx(RlsAmount, { value: formControl?.state || value || valueInput, symbol: symbol, decimals: decimals }) }) }));
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
function RlsInputNumber({ disabled, formControl, onValue, placeholder, value }) {
|
|
116
|
+
const [valueInput, setValueInput] = useState(value || 0);
|
|
117
|
+
function onNumber(value) {
|
|
118
|
+
if (!formControl) {
|
|
119
|
+
setValueInput(value);
|
|
120
|
+
}
|
|
121
|
+
if (onValue) {
|
|
122
|
+
onValue(value);
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
return (jsx("div", { className: "rls-input-number", children: jsx(RlsInput, { formControl: formControl, type: "number", value: value, disabled: disabled, placeholder: placeholder, onValue: onNumber, children: formControl?.state || value || valueInput }) }));
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
function RlsInputPassword({ disabled, formControl, onValue, placeholder, type }) {
|
|
129
|
+
const [focused, setFocused] = useState(false);
|
|
130
|
+
function onChange(event) {
|
|
131
|
+
formControl?.setState(event.target.value);
|
|
132
|
+
if (onValue) {
|
|
133
|
+
onValue(event.target.value);
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
function onFocus() {
|
|
137
|
+
formControl?.focus();
|
|
138
|
+
setFocused(true);
|
|
139
|
+
}
|
|
140
|
+
function onBlur() {
|
|
141
|
+
if (formControl && !formControl.touched) {
|
|
142
|
+
formControl.touch();
|
|
143
|
+
}
|
|
144
|
+
formControl?.blur();
|
|
145
|
+
setFocused(false);
|
|
146
|
+
}
|
|
147
|
+
return (jsx("div", { className: renderClassStatus('rls-input-password', {
|
|
148
|
+
focused: formControl?.focused || focused,
|
|
149
|
+
disabled
|
|
150
|
+
}), children: jsx("input", { className: "rls-input-password__component", autoComplete: "off", type: type || 'password', placeholder: placeholder, disabled: disabled, onFocus: onFocus, onBlur: onBlur, onChange: onChange }) }));
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
function RlsInputText({ disabled, formControl, onValue, placeholder, value }) {
|
|
154
|
+
const [valueInput, setValueInput] = useState(value || '');
|
|
155
|
+
function onText(value) {
|
|
156
|
+
if (!formControl) {
|
|
157
|
+
setValueInput(value);
|
|
158
|
+
}
|
|
159
|
+
if (onValue) {
|
|
160
|
+
onValue(value);
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
return (jsx("div", { className: "rls-input-text", children: jsx(RlsInput, { formControl: formControl, type: "text", value: value, disabled: disabled, placeholder: placeholder, onValue: onText, children: formControl?.state || value || valueInput }) }));
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
function RlsLabel({ children, rlsTheme }) {
|
|
167
|
+
return (jsx("label", { className: "rls-label", "rls-theme": rlsTheme, children: children }));
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
function RlsMessageIcon({ icon, children, rlsTheme }) {
|
|
171
|
+
return (jsxs("div", { className: "rls-message-icon", "rls-theme": rlsTheme, children: [icon && jsx(RlsIcon, { value: icon }), jsx("span", { className: "caption-regular truncate", children: children })] }));
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
function RlsPoster({ children, rlsTheme }) {
|
|
175
|
+
return (jsx("div", { className: "rls-poster", "rls-theme": rlsTheme, children: children }));
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
function RlsProgressBar({ indeterminate, percentage, rlsTheme }) {
|
|
179
|
+
return (jsx("div", { className: renderClassStatus('rls-progress-bar', { indeterminate }), "rls-theme": rlsTheme, children: jsx("div", { className: "rls-progress-bar__component", style: { width: `${percentage || 0}%` } }) }));
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
function RlsRadioButton({ checked, disabled, onClick, rlsTheme }) {
|
|
183
|
+
return (jsx("div", { className: renderClassStatus('rls-radiobutton', { checked, disabled }), onClick: onClick, "rls-theme": rlsTheme, children: jsx("div", { className: "rls-radiobutton__component" }) }));
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
function RlsSearchInput({ formControl, placeholder, onSearch }) {
|
|
187
|
+
return (jsxs("div", { className: "rls-search-input", children: [jsx(RlsInput, { formControl: formControl, placeholder: placeholder }), onSearch && jsx(RlsButtonAction, { icon: "search", onClick: onSearch })] }));
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
function RlsSkeleton({ rlsTheme }) {
|
|
191
|
+
return jsx("div", { className: "rls-skeleton", "rls-theme": rlsTheme });
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
function RlsSkeletonText({ active, children, rlsTheme }) {
|
|
195
|
+
return (jsx("div", { className: renderClassStatus('rls-skeleton-text', { active }), "rls-theme": rlsTheme, children: jsx("span", { className: "rls-skeleton-text__value", children: children }) }));
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
function RlsSwitch({ checked, disabled, onClick, rlsTheme }) {
|
|
199
|
+
return (jsx("div", { className: renderClassStatus('rls-switch', { checked, disabled }), onClick: onClick, "rls-theme": rlsTheme, children: jsxs("div", { className: "rls-switch__component", children: [jsx("div", { className: "rls-switch__component__element" }), jsx("div", { className: "rls-switch__component__bar" })] }) }));
|
|
200
|
+
}
|
|
201
|
+
function RlsSwitchControl({ formControl, disabled, rlsTheme }) {
|
|
202
|
+
return (jsx(RlsSwitch, { checked: formControl.state || false, disabled: disabled, onClick: () => {
|
|
203
|
+
formControl.setState(!formControl.state);
|
|
204
|
+
}, rlsTheme: rlsTheme }));
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
function RlsBallot({ bordered, children, img, initials, skeleton, subtitle, rlsTheme }) {
|
|
208
|
+
return (jsxs("div", { className: renderClassStatus('rls-ballot', { bordered, skeleton }), "rls-theme": rlsTheme, children: [(img || initials) && (jsxs(RlsAvatar, { skeleton: skeleton, children: [img && jsx("img", { src: img }), initials && jsx("span", { children: initials })] })), jsxs("div", { className: "rls-ballot__component", children: [jsx("label", { className: "rls-ballot__title", children: jsx(RlsSkeletonText, { active: skeleton, children: children }) }), subtitle && (jsx("label", { className: "rls-ballot__subtitle", children: jsx(RlsSkeletonText, { active: skeleton, children: subtitle }) }))] })] }));
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
function RlsButtonToggle({ options, type, disabled, rlsTheme, onAction }) {
|
|
212
|
+
const contentRef = useRef(null);
|
|
213
|
+
const [firstAction] = options;
|
|
214
|
+
const [action, setAction] = useState(firstAction);
|
|
215
|
+
const [visible, setVisible] = useState(false);
|
|
216
|
+
useEffect(() => {
|
|
217
|
+
function onCloseMenu({ target }) {
|
|
218
|
+
if (!contentRef?.current?.contains(target)) {
|
|
219
|
+
setVisible(false);
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
document.addEventListener('click', onCloseMenu);
|
|
223
|
+
return () => {
|
|
224
|
+
document.removeEventListener('click', onCloseMenu);
|
|
225
|
+
};
|
|
226
|
+
}, []);
|
|
227
|
+
function onClickMenu() {
|
|
228
|
+
setVisible((prevValue) => !prevValue);
|
|
229
|
+
}
|
|
230
|
+
function onSelectAction(action) {
|
|
231
|
+
setAction(action);
|
|
232
|
+
setVisible(false);
|
|
233
|
+
}
|
|
234
|
+
return (jsxs("div", { className: "rls-button-toggle", ref: contentRef, "rls-theme": rlsTheme, children: [jsxs("div", { className: "rls-button-toggle__content", children: [action && (jsx("div", { className: "rls-button-toggle__action", children: jsx(RlsButton, { disabled: disabled, type: type, onClick: () => {
|
|
235
|
+
if (onAction) {
|
|
236
|
+
onAction(action.value);
|
|
237
|
+
}
|
|
238
|
+
}, children: action.label }) })), jsx("div", { className: "rls-button-toggle__icon", children: jsx(RlsButton, { type: type, prefixIcon: "arrow-ios-down", disabled: disabled, onClick: onClickMenu }) })] }), jsx("div", { className: renderClassStatus('rls-button-toggle__list', {
|
|
239
|
+
visible,
|
|
240
|
+
hide: !visible
|
|
241
|
+
}), children: jsx("ul", { children: options.map((action, index) => (jsx("li", { className: "truncate", onClick: () => {
|
|
242
|
+
onSelectAction(action);
|
|
243
|
+
}, children: action.label }, index))) }) })] }));
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
function RlsCheckBoxLabel({ children, disabled, extended, formControl, rlsTheme }) {
|
|
247
|
+
const [checked, setChecked] = useState(formControl?.value || false);
|
|
248
|
+
useEffect(() => {
|
|
249
|
+
setChecked(formControl?.state || false);
|
|
250
|
+
}, [formControl?.state]);
|
|
251
|
+
function onToggle() {
|
|
252
|
+
if (formControl) {
|
|
253
|
+
formControl?.setState(!formControl.state);
|
|
254
|
+
}
|
|
255
|
+
else {
|
|
256
|
+
setChecked(!checked);
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
return (jsxs("div", { className: renderClassStatus('rls-checkbox-label', {
|
|
260
|
+
disabled,
|
|
261
|
+
extended
|
|
262
|
+
}), "rls-theme": rlsTheme, children: [jsx("div", { className: "rls-checkbox-label__component", onClick: onToggle, children: jsx(RlsCheckBox, { checked: checked, disabled: disabled }) }), jsx("label", { className: "rls-checkbox-label__text", children: children })] }));
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
let Factory$2 = class Factory {
|
|
266
|
+
constructor(props) {
|
|
267
|
+
const { date, value, maxDate, minDate } = props;
|
|
268
|
+
this.value = value;
|
|
269
|
+
this.date = new Date(date.getTime());
|
|
270
|
+
this.maxDate = maxDate;
|
|
271
|
+
this.minDate = minDate;
|
|
272
|
+
this.date.setDate(1);
|
|
273
|
+
}
|
|
274
|
+
static execute(props) {
|
|
275
|
+
const factory = new Factory(props);
|
|
276
|
+
const firstWeek = factory.createFirstWeek();
|
|
277
|
+
const rightWeeks = factory.createRightWeeks();
|
|
278
|
+
return [firstWeek, ...rightWeeks];
|
|
279
|
+
}
|
|
280
|
+
createFirstWeek() {
|
|
281
|
+
const dayStart = this.date.getDay();
|
|
282
|
+
const days = [];
|
|
283
|
+
let day = 1;
|
|
284
|
+
for (let start = 0; start < dayStart; start++) {
|
|
285
|
+
days.push(this.createDayState());
|
|
286
|
+
}
|
|
287
|
+
for (let end = dayStart; end < 7; end++) {
|
|
288
|
+
days.push(this.createDayState(day));
|
|
289
|
+
day++;
|
|
290
|
+
}
|
|
291
|
+
return { days };
|
|
292
|
+
}
|
|
293
|
+
createRightWeeks() {
|
|
294
|
+
const dayStart = this.date.getDay();
|
|
295
|
+
const rightWeeks = [];
|
|
296
|
+
const dayCount = daysFromMonth(this.date.getFullYear(), this.date.getMonth());
|
|
297
|
+
let days = [];
|
|
298
|
+
let countDaysWeek = 1;
|
|
299
|
+
let day = 8 - dayStart;
|
|
300
|
+
do {
|
|
301
|
+
days.push(this.createDayState(day));
|
|
302
|
+
day++;
|
|
303
|
+
countDaysWeek++;
|
|
304
|
+
if (countDaysWeek > 7) {
|
|
305
|
+
rightWeeks.push({ days });
|
|
306
|
+
days = [];
|
|
307
|
+
countDaysWeek = 1;
|
|
308
|
+
}
|
|
309
|
+
} while (day <= dayCount);
|
|
310
|
+
const daysPending = this.createDaysPending(days.length);
|
|
311
|
+
rightWeeks.push({ days: [...days, ...daysPending] });
|
|
312
|
+
return rightWeeks;
|
|
313
|
+
}
|
|
314
|
+
createDaysPending(daysWeek) {
|
|
315
|
+
const daysPending = [];
|
|
316
|
+
const length = 7 - daysWeek;
|
|
317
|
+
for (let index = 0; index < length; index++) {
|
|
318
|
+
daysPending.push(this.createDayState());
|
|
319
|
+
}
|
|
320
|
+
return daysPending;
|
|
321
|
+
}
|
|
322
|
+
createDayState(value) {
|
|
323
|
+
return {
|
|
324
|
+
disabled: this.overflowDay(value || 0),
|
|
325
|
+
forbidden: !value,
|
|
326
|
+
selected: value === this.value,
|
|
327
|
+
value
|
|
328
|
+
};
|
|
329
|
+
}
|
|
330
|
+
overflowDay(day) {
|
|
331
|
+
return this.minOverflowDay(day) || this.maxOverflowDay(day);
|
|
332
|
+
}
|
|
333
|
+
minOverflowDay(day) {
|
|
334
|
+
return this.minDate
|
|
335
|
+
? weight(refactorDay(this.date, day)) < weight(this.minDate)
|
|
336
|
+
: false;
|
|
337
|
+
}
|
|
338
|
+
maxOverflowDay(day) {
|
|
339
|
+
return this.maxDate
|
|
340
|
+
? weight(refactorDay(this.date, day)) > weight(this.maxDate)
|
|
341
|
+
: false;
|
|
342
|
+
}
|
|
343
|
+
};
|
|
344
|
+
function createDayPicker(props) {
|
|
345
|
+
return Factory$2.execute(props);
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
function RlsDayPicker({ date, disabled: disabledPicker, formControl, maxDate, minDate, rlsTheme }) {
|
|
349
|
+
const initialDate = date || new Date();
|
|
350
|
+
const initialDay = formControl?.state || initialDate.getDate();
|
|
351
|
+
const [weeks, setWeeks] = useState([]);
|
|
352
|
+
const [value, setValue] = useState(initialDay);
|
|
353
|
+
useEffect(() => {
|
|
354
|
+
setWeeks(createDayPicker({
|
|
355
|
+
date: initialDate,
|
|
356
|
+
value: formControl?.state || value,
|
|
357
|
+
minDate,
|
|
358
|
+
maxDate
|
|
359
|
+
}));
|
|
360
|
+
}, [value, date, minDate, maxDate]);
|
|
361
|
+
useEffect(() => {
|
|
362
|
+
if (date && date.getDate() !== value) {
|
|
363
|
+
onChange(date.getDate());
|
|
364
|
+
}
|
|
365
|
+
}, [date]);
|
|
366
|
+
function onChange(value) {
|
|
367
|
+
setValue(value);
|
|
368
|
+
formControl?.setState(value);
|
|
369
|
+
}
|
|
370
|
+
return (jsxs("div", { className: "rls-day-picker", "rls-theme": rlsTheme, children: [jsx("div", { className: "rls-day-picker__header", children: DAY_LABELS().map((title, index) => (jsx("label", { className: "rls-day-picker__label", children: title }, index))) }), jsx("div", { className: "rls-day-picker__component", children: weeks.map(({ days }, index) => (jsx("div", { className: "rls-day-picker__week", children: days.map(({ value, disabled, forbidden, selected }, index) => (jsx("div", { className: renderClassStatus('rls-day-picker__day', {
|
|
371
|
+
disabled: disabled || disabledPicker,
|
|
372
|
+
forbidden,
|
|
373
|
+
selected
|
|
374
|
+
}), onClick: () => {
|
|
375
|
+
if (value && !disabled) {
|
|
376
|
+
onChange(value);
|
|
377
|
+
}
|
|
378
|
+
}, children: jsx("span", { className: "rls-day-picker__day__span", children: value || '??' }) }, index))) }, index))) })] }));
|
|
379
|
+
}
|
|
380
|
+
|
|
381
|
+
const FORMAT_DESCRIPTION$1 = '{dd}/{mm}/{aa}';
|
|
382
|
+
class ListFieldCollection {
|
|
383
|
+
constructor(value) {
|
|
384
|
+
this.value = value;
|
|
385
|
+
}
|
|
386
|
+
findElement(value) {
|
|
387
|
+
return this.value.find((element) => element.compareTo(value));
|
|
388
|
+
}
|
|
389
|
+
}
|
|
390
|
+
class DateRange {
|
|
391
|
+
constructor(minDate, maxDate) {
|
|
392
|
+
this.minDate = normalizeMinTime(minDate);
|
|
393
|
+
if (maxDate && isBefore(maxDate, minDate)) {
|
|
394
|
+
this.maxDate = normalizeMinTime(maxDate);
|
|
395
|
+
}
|
|
396
|
+
else {
|
|
397
|
+
this.maxDate = normalizeMinTime(minDate);
|
|
398
|
+
}
|
|
399
|
+
const minFormat = formatDate(this.minDate, FORMAT_DESCRIPTION$1);
|
|
400
|
+
const maxFormat = formatDate(this.maxDate, FORMAT_DESCRIPTION$1);
|
|
401
|
+
this.description = `${minFormat} - ${maxFormat}`;
|
|
402
|
+
}
|
|
403
|
+
recalculate(date) {
|
|
404
|
+
if (isBefore(this.minDate, date)) {
|
|
405
|
+
return new DateRange(date, this.maxDate);
|
|
406
|
+
}
|
|
407
|
+
if (isAfter(this.maxDate, date)) {
|
|
408
|
+
return new DateRange(this.minDate, date);
|
|
409
|
+
}
|
|
410
|
+
const minDifference = timeDifference(date, this.minDate);
|
|
411
|
+
const maxDifference = timeDifference(this.maxDate, date);
|
|
412
|
+
return minDifference > maxDifference
|
|
413
|
+
? new DateRange(this.minDate, date)
|
|
414
|
+
: new DateRange(date, this.maxDate);
|
|
415
|
+
}
|
|
416
|
+
static now() {
|
|
417
|
+
return new DateRange(new Date());
|
|
418
|
+
}
|
|
419
|
+
}
|
|
420
|
+
|
|
421
|
+
let Factory$1 = class Factory {
|
|
422
|
+
constructor(props) {
|
|
423
|
+
const { date, range, maxDate, minDate } = props;
|
|
424
|
+
this.date = new Date(date.getTime());
|
|
425
|
+
this.range = range;
|
|
426
|
+
this.maxDate = maxDate;
|
|
427
|
+
this.minDate = minDate;
|
|
428
|
+
this.date.setDate(1);
|
|
429
|
+
}
|
|
430
|
+
static execute(props) {
|
|
431
|
+
const factory = new Factory(props);
|
|
432
|
+
const firstWeek = factory.createFirstWeek();
|
|
433
|
+
const rightWeeks = factory.createRightWeeks();
|
|
434
|
+
return [firstWeek, ...rightWeeks];
|
|
435
|
+
}
|
|
436
|
+
createFirstWeek() {
|
|
437
|
+
const dayStart = this.date.getDay();
|
|
438
|
+
const days = [];
|
|
439
|
+
let day = 1;
|
|
440
|
+
for (let start = 0; start < dayStart; start++) {
|
|
441
|
+
days.push(this.createDayRangeState());
|
|
442
|
+
}
|
|
443
|
+
for (let end = dayStart; end < 7; end++) {
|
|
444
|
+
days.push(this.createDayRangeState(day));
|
|
445
|
+
day++;
|
|
446
|
+
}
|
|
447
|
+
return { days };
|
|
448
|
+
}
|
|
449
|
+
createRightWeeks() {
|
|
450
|
+
const rightWeeks = [];
|
|
451
|
+
const dayStart = this.date.getDay();
|
|
452
|
+
const dayCount = daysFromMonth(this.date.getFullYear(), this.date.getMonth());
|
|
453
|
+
let days = [];
|
|
454
|
+
let countDaysWeek = 1;
|
|
455
|
+
let day = 8 - dayStart;
|
|
456
|
+
do {
|
|
457
|
+
days.push(this.createDayRangeState(day));
|
|
458
|
+
day++;
|
|
459
|
+
countDaysWeek++;
|
|
460
|
+
if (countDaysWeek > 7) {
|
|
461
|
+
rightWeeks.push({ days });
|
|
462
|
+
days = [];
|
|
463
|
+
countDaysWeek = 1;
|
|
464
|
+
}
|
|
465
|
+
} while (day <= dayCount);
|
|
466
|
+
const daysPending = this.createDaysPending(days.length);
|
|
467
|
+
rightWeeks.push({ days: [...days, ...daysPending] });
|
|
468
|
+
return rightWeeks;
|
|
469
|
+
}
|
|
470
|
+
createDaysPending(daysWeek) {
|
|
471
|
+
const daysPending = [];
|
|
472
|
+
const length = 7 - daysWeek;
|
|
473
|
+
for (let index = 0; index < length; index++) {
|
|
474
|
+
daysPending.push(this.createDayRangeState());
|
|
475
|
+
}
|
|
476
|
+
return daysPending;
|
|
477
|
+
}
|
|
478
|
+
createDayRangeState(day) {
|
|
479
|
+
return {
|
|
480
|
+
value: day,
|
|
481
|
+
disabled: this.overflowDay(day || 0),
|
|
482
|
+
forbidden: !day,
|
|
483
|
+
ranged: day ? this.isRangedFromDate(day) : false,
|
|
484
|
+
selected: day ? this.isSelected(day) : false
|
|
485
|
+
};
|
|
486
|
+
}
|
|
487
|
+
isSelected(day) {
|
|
488
|
+
return (this.isSelectedForDate(this.range.minDate, day) ||
|
|
489
|
+
this.isSelectedForDate(this.range.maxDate, day));
|
|
490
|
+
}
|
|
491
|
+
isSelectedForDate(date, day) {
|
|
492
|
+
return (date.getFullYear() === this.date.getFullYear() &&
|
|
493
|
+
date.getMonth() === this.date.getMonth() &&
|
|
494
|
+
day === date.getDate());
|
|
495
|
+
}
|
|
496
|
+
isRangedFromDate(day) {
|
|
497
|
+
return isBetween(this.range.minDate, this.range.maxDate, refactorDay(this.date, day));
|
|
498
|
+
}
|
|
499
|
+
overflowDay(day) {
|
|
500
|
+
return this.minOverflowDay(day) || this.maxOverflowDay(day);
|
|
501
|
+
}
|
|
502
|
+
minOverflowDay(day) {
|
|
503
|
+
return this.minDate
|
|
504
|
+
? weight(refactorDay(this.date, day)) < weight(this.minDate)
|
|
505
|
+
: false;
|
|
506
|
+
}
|
|
507
|
+
maxOverflowDay(day) {
|
|
508
|
+
return this.maxDate
|
|
509
|
+
? weight(refactorDay(this.date, day)) > weight(this.maxDate)
|
|
510
|
+
: false;
|
|
511
|
+
}
|
|
512
|
+
};
|
|
513
|
+
function createRangePicker(props) {
|
|
514
|
+
return Factory$1.execute(props);
|
|
515
|
+
}
|
|
516
|
+
|
|
517
|
+
function RlsDayRangePicker({ date, disabled: disabledPicker, formControl, maxDate, minDate, rlsTheme }) {
|
|
518
|
+
const initialRange = formControl?.state || DateRange.now();
|
|
519
|
+
const initialDate = normalizeMinTime(date || initialRange.minDate);
|
|
520
|
+
const [weeks, setWeeks] = useState([]);
|
|
521
|
+
const [range, setRange] = useState(initialRange);
|
|
522
|
+
useEffect(() => {
|
|
523
|
+
setWeeks(createRangePicker({
|
|
524
|
+
date: initialDate,
|
|
525
|
+
range,
|
|
526
|
+
minDate,
|
|
527
|
+
maxDate
|
|
528
|
+
}));
|
|
529
|
+
}, [range, date, minDate, maxDate]);
|
|
530
|
+
function onChange(value) {
|
|
531
|
+
const newRange = range.recalculate(refactorDay(initialDate, value));
|
|
532
|
+
setRange(newRange);
|
|
533
|
+
formControl?.setState(newRange);
|
|
534
|
+
}
|
|
535
|
+
return (jsxs("div", { className: "rls-day-range-picker", "rls-theme": rlsTheme, children: [jsx("div", { className: "rls-day-range-picker__header", children: DAY_LABELS().map((title, index) => (jsx("label", { className: "rls-day-range-picker__label", children: title }, index))) }), jsx("div", { className: "rls-day-range-picker__component", children: weeks.map(({ days }, index) => (jsx("div", { className: "rls-day-range-picker__week", children: days.map(({ value, disabled, forbidden, ranged, selected }, index) => (jsx("div", { className: renderClassStatus('rls-day-range-picker__day', {
|
|
536
|
+
disabled: disabled || disabledPicker,
|
|
537
|
+
forbidden,
|
|
538
|
+
selected,
|
|
539
|
+
ranged
|
|
540
|
+
}), onClick: () => {
|
|
541
|
+
if (value && !disabled) {
|
|
542
|
+
onChange(value);
|
|
543
|
+
}
|
|
544
|
+
}, children: jsx("span", { className: "rls-day-range-picker__day__span", children: value || '??' }) }, index))) }, index))) })] }));
|
|
545
|
+
}
|
|
546
|
+
|
|
547
|
+
function RlsMoneyField({ children, decimals, disabled, formControl, onValue, placeholder, symbol, rlsTheme, value }) {
|
|
548
|
+
return (jsxs("div", { className: renderClassStatus('rls-box-field', {
|
|
549
|
+
focused: formControl?.focused,
|
|
550
|
+
error: formControl?.touched && !formControl?.valid,
|
|
551
|
+
disabled: formControl?.disabled || disabled
|
|
552
|
+
}, 'rls-money-field'), "rls-theme": rlsTheme, children: [children && jsx("label", { className: "rls-box-field__label", children: children }), jsx("div", { className: "rls-box-field__component", children: jsx("div", { className: "rls-box-field__body", children: jsx(RlsInputMoney, { formControl: formControl, value: value, disabled: disabled, placeholder: placeholder, symbol: symbol, decimals: decimals, onValue: onValue }) }) }), formControl?.touched && formControl?.error && (jsx("div", { className: "rls-box-field__error", children: jsx(RlsMessageIcon, { icon: "alert-triangle", rlsTheme: "danger", children: formControl.error.message }) }))] }));
|
|
553
|
+
}
|
|
554
|
+
|
|
555
|
+
const MONTH_MAX_VALUE = Month.January;
|
|
556
|
+
const MONTH_MIN_VALUE = Month.December;
|
|
557
|
+
class Factory {
|
|
558
|
+
constructor(props) {
|
|
559
|
+
const { date, value, maxDate, minDate } = props;
|
|
560
|
+
this.value = value;
|
|
561
|
+
this.date = new Date(date.getTime());
|
|
562
|
+
this.maxDate = maxDate;
|
|
563
|
+
this.minDate = minDate;
|
|
564
|
+
}
|
|
565
|
+
static execute(props) {
|
|
566
|
+
const factory = new Factory(props);
|
|
567
|
+
return [
|
|
568
|
+
factory.createMonth(0),
|
|
569
|
+
factory.createMonth(1),
|
|
570
|
+
factory.createMonth(2),
|
|
571
|
+
factory.createMonth(3),
|
|
572
|
+
factory.createMonth(4),
|
|
573
|
+
factory.createMonth(5),
|
|
574
|
+
factory.createMonth(6),
|
|
575
|
+
factory.createMonth(7),
|
|
576
|
+
factory.createMonth(8),
|
|
577
|
+
factory.createMonth(9),
|
|
578
|
+
factory.createMonth(10),
|
|
579
|
+
factory.createMonth(11)
|
|
580
|
+
];
|
|
581
|
+
}
|
|
582
|
+
createMonth(value) {
|
|
583
|
+
return {
|
|
584
|
+
value,
|
|
585
|
+
label: MONTH_NAMES()[value],
|
|
586
|
+
disabled: this.overflowMonth(value),
|
|
587
|
+
selected: value === this.value
|
|
588
|
+
};
|
|
589
|
+
}
|
|
590
|
+
get minYear() {
|
|
591
|
+
return this.minDate?.getFullYear() || 0;
|
|
592
|
+
}
|
|
593
|
+
get maxYear() {
|
|
594
|
+
return this.maxDate?.getFullYear() || 10000;
|
|
595
|
+
}
|
|
596
|
+
get minMonth() {
|
|
597
|
+
return this.minDate?.getMonth() || MONTH_MIN_VALUE;
|
|
598
|
+
}
|
|
599
|
+
get maxMonth() {
|
|
600
|
+
return this.maxDate?.getMonth() || MONTH_MAX_VALUE;
|
|
601
|
+
}
|
|
602
|
+
overflowMonth(month) {
|
|
603
|
+
return this.minOverflowMonth(month) || this.maxOverflowMonth(month);
|
|
604
|
+
}
|
|
605
|
+
minOverflowMonth(month) {
|
|
606
|
+
return this.date.getFullYear() === this.minYear && month < this.minMonth;
|
|
607
|
+
}
|
|
608
|
+
maxOverflowMonth(month) {
|
|
609
|
+
return this.date.getFullYear() === this.maxYear && month > this.maxMonth;
|
|
610
|
+
}
|
|
611
|
+
}
|
|
612
|
+
function isMinLimitMonth(month, date, maxDate) {
|
|
613
|
+
const minYear = maxDate?.getFullYear() || 0;
|
|
614
|
+
const minMonth = maxDate?.getMonth() || 0;
|
|
615
|
+
return date.getFullYear() === minYear && month <= minMonth;
|
|
616
|
+
}
|
|
617
|
+
function isMaxLimitMonth(month, date, maxDate) {
|
|
618
|
+
const maxYear = maxDate?.getFullYear() || 10000;
|
|
619
|
+
const maxMonth = maxDate?.getMonth() || 11;
|
|
620
|
+
return date.getFullYear() === maxYear && month >= maxMonth;
|
|
621
|
+
}
|
|
622
|
+
function createMonthPicker(props) {
|
|
623
|
+
return Factory.execute(props);
|
|
624
|
+
}
|
|
625
|
+
|
|
626
|
+
function RlsMonthPicker({ formControl, date, disabled: disabledPicker, maxDate, minDate, rlsTheme }) {
|
|
627
|
+
const initialDate = date || new Date();
|
|
628
|
+
const initialMonth = formControl?.state || initialDate.getMonth();
|
|
629
|
+
const [months, setMonths] = useState([]);
|
|
630
|
+
const [value, setValue] = useState(initialMonth);
|
|
631
|
+
useEffect(() => {
|
|
632
|
+
setMonths(createMonthPicker({
|
|
633
|
+
date: initialDate,
|
|
634
|
+
value: formControl?.state || value,
|
|
635
|
+
minDate,
|
|
636
|
+
maxDate
|
|
637
|
+
}));
|
|
638
|
+
}, [value, date, minDate, maxDate]);
|
|
639
|
+
return (jsx("div", { className: "rls-month-picker", "rls-theme": rlsTheme, children: months.map(({ label, value, disabled, selected }, index) => (jsx("div", { className: renderClassStatus('rls-month-picker__component', {
|
|
640
|
+
disabled: disabled || disabledPicker || false,
|
|
641
|
+
selected
|
|
642
|
+
}), onClick: () => {
|
|
643
|
+
formControl?.setState(value);
|
|
644
|
+
setValue(value);
|
|
645
|
+
}, children: jsx("span", { className: "rls-month-picker__span", children: label }) }, index))) }));
|
|
646
|
+
}
|
|
647
|
+
|
|
648
|
+
function RlsMonthTitlePicker({ monthControl, yearControl, date, maxDate, minDate, onClick }) {
|
|
649
|
+
const { state: month } = monthControl;
|
|
650
|
+
const { state: year } = yearControl;
|
|
651
|
+
const [limitMinMonth, setLimitMinMonth] = useState(false);
|
|
652
|
+
const [limitMaxMonth, setLimitMaxMonth] = useState(false);
|
|
653
|
+
const monthName = MONTH_NAMES()[month || 0];
|
|
654
|
+
useEffect(() => {
|
|
655
|
+
if (typeof month === 'number' && date) {
|
|
656
|
+
setLimitMinMonth(isMinLimitMonth(month, date, minDate));
|
|
657
|
+
setLimitMaxMonth(isMaxLimitMonth(month, date, maxDate));
|
|
658
|
+
}
|
|
659
|
+
}, [date]);
|
|
660
|
+
function onPreviousMonth() {
|
|
661
|
+
if (typeof month === 'number' && typeof year === 'number') {
|
|
662
|
+
if (month > MONTH_MIN_VALUE) {
|
|
663
|
+
monthControl.setState(month - 1);
|
|
664
|
+
}
|
|
665
|
+
else {
|
|
666
|
+
monthControl.setState(MONTH_MAX_VALUE);
|
|
667
|
+
yearControl.setState(year - 1);
|
|
668
|
+
}
|
|
669
|
+
}
|
|
670
|
+
}
|
|
671
|
+
function onNextMonth() {
|
|
672
|
+
if (typeof month === 'number' && typeof year === 'number') {
|
|
673
|
+
if (month < MONTH_MAX_VALUE) {
|
|
674
|
+
monthControl.setState(month + 1);
|
|
675
|
+
}
|
|
676
|
+
else {
|
|
677
|
+
monthControl.setState(MONTH_MIN_VALUE);
|
|
678
|
+
yearControl.setState(year + 1);
|
|
679
|
+
}
|
|
680
|
+
}
|
|
681
|
+
}
|
|
682
|
+
return (jsxs("div", { className: "rls-month-title-picker", children: [jsx(RlsButtonAction, { icon: "arrow-ios-left", onClick: onPreviousMonth, disabled: limitMinMonth }), jsx("span", { onClick: onClick, children: monthName }), jsx(RlsButtonAction, { icon: "arrow-ios-right", onClick: onNextMonth, disabled: limitMaxMonth })] }));
|
|
683
|
+
}
|
|
684
|
+
|
|
685
|
+
function RlsNumberField({ children, disabled, formControl, onValue, placeholder, rlsTheme, value }) {
|
|
686
|
+
return (jsxs("div", { className: renderClassStatus('rls-box-field', {
|
|
687
|
+
focused: formControl?.focused,
|
|
688
|
+
error: formControl?.touched && !formControl?.valid,
|
|
689
|
+
disabled: formControl?.disabled || disabled
|
|
690
|
+
}, 'rls-number-field'), "rls-theme": rlsTheme, children: [children && jsx("label", { className: "rls-box-field__label", children: children }), jsx("div", { className: "rls-box-field__component", children: jsx("div", { className: "rls-box-field__body", children: jsx(RlsInputNumber, { formControl: formControl, value: value, disabled: disabled, placeholder: placeholder, onValue: onValue }) }) }), formControl?.touched && formControl?.error && (jsx("div", { className: "rls-box-field__error", children: jsx(RlsMessageIcon, { icon: "alert-triangle", rlsTheme: "danger", children: formControl.error.message }) }))] }));
|
|
691
|
+
}
|
|
692
|
+
|
|
693
|
+
const DEFAULT_COUNT_ELEMENT = 20;
|
|
694
|
+
const MIN_NUMBER_PAGE = 1;
|
|
695
|
+
const FIRST_PAGE = 0;
|
|
696
|
+
const DEFAULT_MAX_VISIBLE = 4;
|
|
697
|
+
function RlsPagination({ elements, count: defaultCount, filter, onElements, onPagination }) {
|
|
698
|
+
const count = defaultCount || DEFAULT_COUNT_ELEMENT;
|
|
699
|
+
const [collection, setCollection] = useState([]);
|
|
700
|
+
const [index, setIndex] = useState(0);
|
|
701
|
+
const [maxPage, setMaxPage] = useState(calculateMaxPage(elements, count));
|
|
702
|
+
const [paginations, setPaginations] = useState([]);
|
|
703
|
+
const [currentPagination, setCurrentPagination] = useState();
|
|
704
|
+
const [description, setDescription] = useState('');
|
|
705
|
+
const [firstPage, setFirstPage] = useState(true);
|
|
706
|
+
const [lastPage, setLastPage] = useState(false);
|
|
707
|
+
useEffect(() => {
|
|
708
|
+
refreshFromElements(elements);
|
|
709
|
+
}, [elements]);
|
|
710
|
+
useEffect(() => {
|
|
711
|
+
const isFirstPage = currentPagination?.value === FIRST_PAGE;
|
|
712
|
+
const isLastPage = currentPagination?.value === maxPage - 1;
|
|
713
|
+
setFirstPage(isFirstPage);
|
|
714
|
+
setLastPage(isLastPage);
|
|
715
|
+
if (onPagination) {
|
|
716
|
+
onPagination({ firstPage: isFirstPage, lastPage: isLastPage });
|
|
717
|
+
}
|
|
718
|
+
}, [currentPagination]);
|
|
719
|
+
useEffect(() => {
|
|
720
|
+
refreshFromFilter(filter);
|
|
721
|
+
}, [filter]);
|
|
722
|
+
function onChangeElements(elements) {
|
|
723
|
+
if (onElements) {
|
|
724
|
+
onElements(elements);
|
|
725
|
+
}
|
|
726
|
+
}
|
|
727
|
+
function calculateMaxPage(collection, count) {
|
|
728
|
+
return collection.length ? Math.ceil(collection.length / count) : 0;
|
|
729
|
+
}
|
|
730
|
+
function onSelectPagination(pagination) {
|
|
731
|
+
const { value } = pagination;
|
|
732
|
+
pagination.active = true;
|
|
733
|
+
setIndex(value);
|
|
734
|
+
setCurrentPagination(pagination);
|
|
735
|
+
refreshFromChanged(createPageProps({ index: value }));
|
|
736
|
+
}
|
|
737
|
+
function goPagination(pagination) {
|
|
738
|
+
if (currentPagination) {
|
|
739
|
+
currentPagination.active = false;
|
|
740
|
+
}
|
|
741
|
+
onSelectPagination(pagination);
|
|
742
|
+
}
|
|
743
|
+
function goPreviousPagination() {
|
|
744
|
+
if (currentPagination) {
|
|
745
|
+
const { prev, value } = currentPagination;
|
|
746
|
+
if (prev) {
|
|
747
|
+
onSelectPagination(prev);
|
|
748
|
+
currentPagination.active = false;
|
|
749
|
+
}
|
|
750
|
+
else {
|
|
751
|
+
const prevIndex = value - MIN_NUMBER_PAGE;
|
|
752
|
+
if (prevIndex >= FIRST_PAGE) {
|
|
753
|
+
refreshFromChanged(createPagePropsFromIndex(prevIndex));
|
|
754
|
+
}
|
|
755
|
+
}
|
|
756
|
+
}
|
|
757
|
+
}
|
|
758
|
+
function goFirstPagination() {
|
|
759
|
+
if (collection.length) {
|
|
760
|
+
refreshFromChanged(createPagePropsFromIndex(FIRST_PAGE));
|
|
761
|
+
}
|
|
762
|
+
}
|
|
763
|
+
function goNextPagination() {
|
|
764
|
+
if (currentPagination) {
|
|
765
|
+
const { next, value } = currentPagination;
|
|
766
|
+
if (next) {
|
|
767
|
+
onSelectPagination(next);
|
|
768
|
+
currentPagination.active = false;
|
|
769
|
+
}
|
|
770
|
+
else {
|
|
771
|
+
const nextIndex = value + 1;
|
|
772
|
+
if (nextIndex <= maxPage) {
|
|
773
|
+
refreshFromChanged(createPagePropsFromIndex(nextIndex));
|
|
774
|
+
}
|
|
775
|
+
}
|
|
776
|
+
}
|
|
777
|
+
}
|
|
778
|
+
function goLastPagination() {
|
|
779
|
+
if (collection.length) {
|
|
780
|
+
refreshFromChanged(createPagePropsFromIndex(maxPage - MIN_NUMBER_PAGE));
|
|
781
|
+
}
|
|
782
|
+
}
|
|
783
|
+
function createPageCollection(props) {
|
|
784
|
+
const { collection, count, index } = props;
|
|
785
|
+
if (collection.length) {
|
|
786
|
+
const finish = (index + MIN_NUMBER_PAGE) * count;
|
|
787
|
+
const start = index * count;
|
|
788
|
+
return collection.slice(start, finish);
|
|
789
|
+
}
|
|
790
|
+
return [];
|
|
791
|
+
}
|
|
792
|
+
function refreshFromElements(elements) {
|
|
793
|
+
elements.length
|
|
794
|
+
? refreshFromChanged(createRefreshProps(elements, filter))
|
|
795
|
+
: rebootPagination();
|
|
796
|
+
}
|
|
797
|
+
function refreshFromFilter(filter) {
|
|
798
|
+
refreshFromChanged(createRefreshProps(elements, filter));
|
|
799
|
+
}
|
|
800
|
+
function createRefreshProps(elements, filter) {
|
|
801
|
+
const collection = refreshCollection(elements, filter);
|
|
802
|
+
const maxPage = refreshMaxPage(collection, count);
|
|
803
|
+
const index = refreshIndex(collection, maxPage);
|
|
804
|
+
return createPageProps({ collection, index, maxPage });
|
|
805
|
+
}
|
|
806
|
+
function refreshFromChanged(page) {
|
|
807
|
+
refreshPaginations(page);
|
|
808
|
+
refreshDescription(page);
|
|
809
|
+
onChangeElements(createPageCollection(page));
|
|
810
|
+
}
|
|
811
|
+
function refreshCollection(elements, filter) {
|
|
812
|
+
const collection = filter
|
|
813
|
+
? elements.filter((element) => hasPattern(JSON.stringify(element), filter))
|
|
814
|
+
: elements;
|
|
815
|
+
setCollection(collection);
|
|
816
|
+
return collection;
|
|
817
|
+
}
|
|
818
|
+
function refreshMaxPage(collection, count) {
|
|
819
|
+
const maxPage = calculateMaxPage(collection, count);
|
|
820
|
+
setMaxPage(maxPage);
|
|
821
|
+
return maxPage;
|
|
822
|
+
}
|
|
823
|
+
function refreshIndex(collection, currentMaxPage) {
|
|
824
|
+
const maxPage = currentMaxPage || refreshMaxPage(collection, count);
|
|
825
|
+
if (index < maxPage || index === FIRST_PAGE) {
|
|
826
|
+
return index;
|
|
827
|
+
}
|
|
828
|
+
const newIndex = maxPage - 1;
|
|
829
|
+
setIndex(newIndex);
|
|
830
|
+
return newIndex;
|
|
831
|
+
}
|
|
832
|
+
function rebootPagination() {
|
|
833
|
+
setCollection([]);
|
|
834
|
+
setMaxPage(0);
|
|
835
|
+
setIndex(0);
|
|
836
|
+
setPaginations([]);
|
|
837
|
+
onChangeElements([]);
|
|
838
|
+
}
|
|
839
|
+
function refreshDescription(page) {
|
|
840
|
+
const { collection, count, index } = page;
|
|
841
|
+
const totalCount = elements.length;
|
|
842
|
+
const start = index * count + MIN_NUMBER_PAGE;
|
|
843
|
+
let end = (index + MIN_NUMBER_PAGE) * count;
|
|
844
|
+
if (end > collection.length) {
|
|
845
|
+
end = collection.length;
|
|
846
|
+
}
|
|
847
|
+
setDescription(`${start} - ${end} de ${totalCount}`);
|
|
848
|
+
}
|
|
849
|
+
function refreshPaginations({ index, maxPage }) {
|
|
850
|
+
let maxPageVisible = index + DEFAULT_MAX_VISIBLE;
|
|
851
|
+
if (maxPageVisible > maxPage) {
|
|
852
|
+
maxPageVisible = maxPage;
|
|
853
|
+
}
|
|
854
|
+
let minIndexPage = maxPageVisible - DEFAULT_MAX_VISIBLE;
|
|
855
|
+
if (minIndexPage < 0) {
|
|
856
|
+
minIndexPage = 0;
|
|
857
|
+
}
|
|
858
|
+
if (minIndexPage > index) {
|
|
859
|
+
minIndexPage = index;
|
|
860
|
+
}
|
|
861
|
+
let prevPagination = undefined;
|
|
862
|
+
const paginations = [];
|
|
863
|
+
for (let i = minIndexPage; i < maxPageVisible; i++) {
|
|
864
|
+
const pagination = createPagination(i, index);
|
|
865
|
+
paginations.push(pagination);
|
|
866
|
+
pagination.prev = prevPagination;
|
|
867
|
+
if (prevPagination) {
|
|
868
|
+
prevPagination.next = pagination;
|
|
869
|
+
}
|
|
870
|
+
prevPagination = pagination;
|
|
871
|
+
}
|
|
872
|
+
setPaginations(paginations);
|
|
873
|
+
}
|
|
874
|
+
function createPagination(value, index) {
|
|
875
|
+
const active = value === index;
|
|
876
|
+
const pagination = {
|
|
877
|
+
label: (value + 1).toString(),
|
|
878
|
+
value,
|
|
879
|
+
active
|
|
880
|
+
};
|
|
881
|
+
if (active) {
|
|
882
|
+
setCurrentPagination(pagination);
|
|
883
|
+
}
|
|
884
|
+
return pagination;
|
|
885
|
+
}
|
|
886
|
+
function createPagePropsFromIndex(index) {
|
|
887
|
+
return createPageProps({ index });
|
|
888
|
+
}
|
|
889
|
+
function createPageProps(props) {
|
|
890
|
+
return {
|
|
891
|
+
collection: props.collection || collection,
|
|
892
|
+
index: typeof props.index === 'number' ? props.index : index,
|
|
893
|
+
count: props.count || count,
|
|
894
|
+
maxPage: typeof props.maxPage === 'number' ? props.maxPage : maxPage
|
|
895
|
+
};
|
|
896
|
+
}
|
|
897
|
+
return (jsxs("div", { className: "rls-pagination", children: [jsxs("div", { className: "rls-pagination__actions", children: [jsx("button", { className: "rls-pagination__action", onClick: goFirstPagination, disabled: firstPage, children: jsx(RlsIcon, { value: "arrowhead-left" }) }), jsx("button", { className: "rls-pagination__action", onClick: goPreviousPagination, disabled: firstPage, children: jsx(RlsIcon, { value: "arrow-ios-left" }) })] }), jsx("div", { className: "rls-pagination__pages", children: paginations.map((page, index) => {
|
|
898
|
+
return (jsx("div", { className: renderClassStatus('rls-pagination__page', {
|
|
899
|
+
active: page.active
|
|
900
|
+
}), onClick: () => {
|
|
901
|
+
goPagination(page);
|
|
902
|
+
}, children: page.label }, index));
|
|
903
|
+
}) }), jsx("div", { className: "rls-pagination__description", children: description }), jsxs("div", { className: "rls-pagination__actions", children: [jsx("button", { className: "rls-pagination__action", onClick: goNextPagination, disabled: lastPage, children: jsx(RlsIcon, { value: "arrow-ios-right" }) }), jsx("button", { className: "rls-pagination__action", onClick: goLastPagination, disabled: lastPage, children: jsx(RlsIcon, { value: "arrowhead-right" }) })] })] }));
|
|
904
|
+
}
|
|
905
|
+
|
|
906
|
+
function RlsPasswordField({ children, disabled, formControl, placeholder, rlsTheme }) {
|
|
907
|
+
const [password, setPassword] = useState(true);
|
|
908
|
+
function onToggleInput() {
|
|
909
|
+
setPassword(!password);
|
|
910
|
+
}
|
|
911
|
+
return (jsxs("div", { className: renderClassStatus(' rls-box-field', {
|
|
912
|
+
focused: formControl?.focused,
|
|
913
|
+
error: formControl?.touched && !formControl?.valid,
|
|
914
|
+
disabled: formControl?.disabled || disabled
|
|
915
|
+
}, 'rls-password-field'), "rls-theme": rlsTheme, children: [children && jsx("label", { className: "rls-box-field__label", children: children }), jsx("div", { className: "rls-box-field__component", children: jsxs("div", { className: "rls-box-field__body", children: [jsx(RlsInputPassword, { formControl: formControl, disabled: disabled, placeholder: placeholder, type: password ? 'password' : 'text' }), jsx(RlsButtonAction, { icon: password ? 'eye' : 'eye-off', onClick: onToggleInput })] }) }), formControl?.touched && formControl?.error && (jsx("div", { className: "rls-box-field__error", children: jsx(RlsMessageIcon, { icon: "alert-triangle", rlsTheme: "danger", children: formControl.error.message }) }))] }));
|
|
916
|
+
}
|
|
917
|
+
|
|
918
|
+
function RlsRadioButtonLabel({ children, disabled, extended, formControl, rlsTheme, value }) {
|
|
919
|
+
const [checked, setChecked] = useState(formControl?.state || false);
|
|
920
|
+
useEffect(() => {
|
|
921
|
+
setChecked(formControl?.state === value);
|
|
922
|
+
}, [formControl?.state]);
|
|
923
|
+
function onSelect() {
|
|
924
|
+
if (formControl) {
|
|
925
|
+
formControl?.setState(value);
|
|
926
|
+
}
|
|
927
|
+
}
|
|
928
|
+
return (jsxs("div", { className: renderClassStatus('rls-radiobutton-label', {
|
|
929
|
+
disabled,
|
|
930
|
+
extended
|
|
931
|
+
}), "rls-theme": rlsTheme, children: [jsx("div", { className: "rls-radiobutton-label__component", onClick: onSelect, children: jsx(RlsRadioButton, { checked: checked, disabled: disabled }) }), jsx("label", { className: "rls-radiobutton-label__text", children: children })] }));
|
|
932
|
+
}
|
|
933
|
+
|
|
934
|
+
function RlsSwitchLabel({ children, disabled, extended, formControl, rlsTheme }) {
|
|
935
|
+
const [checked, setChecked] = useState(formControl?.value || false);
|
|
936
|
+
useEffect(() => {
|
|
937
|
+
setChecked(formControl?.state || false);
|
|
938
|
+
}, [formControl?.state]);
|
|
939
|
+
function onToggle() {
|
|
940
|
+
if (formControl) {
|
|
941
|
+
formControl?.setState(!formControl.state);
|
|
942
|
+
}
|
|
943
|
+
else {
|
|
944
|
+
setChecked(!checked);
|
|
945
|
+
}
|
|
946
|
+
}
|
|
947
|
+
return (jsxs("div", { className: renderClassStatus('rls-switch-label', { disabled, extended }), "rls-theme": rlsTheme, children: [jsx("div", { className: "rls-switch-label__component", onClick: onToggle, children: jsx(RlsSwitch, { checked: checked, disabled: disabled }) }), jsx("label", { className: "rls-switch-label__text", children: children })] }));
|
|
948
|
+
}
|
|
949
|
+
|
|
950
|
+
function RlsTextField({ children, disabled, formControl, onValue, placeholder, rlsTheme, value }) {
|
|
951
|
+
return (jsxs("div", { className: renderClassStatus('rls-box-field', {
|
|
952
|
+
focused: formControl?.focused,
|
|
953
|
+
error: formControl?.touched && !formControl?.valid,
|
|
954
|
+
disabled: formControl?.disabled || disabled
|
|
955
|
+
}, 'rls-text-field'), "rls-theme": rlsTheme, children: [children && jsx("label", { className: "rls-box-field__label", children: children }), jsx("div", { className: "rls-box-field__component", children: jsx("div", { className: "rls-box-field__body", children: jsx(RlsInputText, { formControl: formControl, value: value, disabled: disabled, placeholder: placeholder, onValue: onValue }) }) }), formControl?.touched && formControl?.error && (jsx("div", { className: "rls-box-field__error", children: jsx(RlsMessageIcon, { icon: "alert-triangle", rlsTheme: "danger", children: formControl.error.message }) }))] }));
|
|
956
|
+
}
|
|
957
|
+
|
|
958
|
+
function RlsToolbar({ actions, children, subtitle }) {
|
|
959
|
+
return (jsxs("div", { className: "rls-toolbar", children: [jsxs("div", { className: "rls-toolbar__description", children: [children && jsx("label", { className: "rls-toolbar__title", children: children }), subtitle && (jsx("label", { className: "rls-toolbar__subtitle caption-semibold", children: subtitle }))] }), actions && (jsx("div", { className: "rls-toolbar__actions", children: actions.map((action, index) => (jsx("div", { children: action }, index))) }))] }));
|
|
960
|
+
}
|
|
961
|
+
|
|
962
|
+
const COUNT_YEAR_RANGE = 4;
|
|
963
|
+
class FactoryYearPicker {
|
|
964
|
+
constructor(props) {
|
|
965
|
+
const { value, maxDate, minDate } = props;
|
|
966
|
+
this.value = value;
|
|
967
|
+
this.maxDate = maxDate;
|
|
968
|
+
this.minDate = minDate;
|
|
969
|
+
}
|
|
970
|
+
static execute(props) {
|
|
971
|
+
const factory = new FactoryYearPicker(props);
|
|
972
|
+
let year = props.year;
|
|
973
|
+
if (factory.minOverflowYear(year)) {
|
|
974
|
+
year = factory.minYear;
|
|
975
|
+
}
|
|
976
|
+
else if (factory.maxOverflowYear(year)) {
|
|
977
|
+
year = factory.maxYear;
|
|
978
|
+
}
|
|
979
|
+
const years = factory.createYears(year);
|
|
980
|
+
return {
|
|
981
|
+
hasNext: factory.hasNext,
|
|
982
|
+
hasPrevious: factory.hasPrevious,
|
|
983
|
+
maxRange: factory.maxYearRange,
|
|
984
|
+
minRange: factory.minYearRange,
|
|
985
|
+
years
|
|
986
|
+
};
|
|
987
|
+
}
|
|
988
|
+
createYears(year) {
|
|
989
|
+
const prevYears = [];
|
|
990
|
+
const nextYears = [];
|
|
991
|
+
this.minYearRange = year;
|
|
992
|
+
this.maxYearRange = year;
|
|
993
|
+
for (let index = 0; index < COUNT_YEAR_RANGE; index++) {
|
|
994
|
+
const yearPrev = year - COUNT_YEAR_RANGE + index;
|
|
995
|
+
const yearNext = year + index + 1;
|
|
996
|
+
const valuePrev = yearPrev >= this.minYear ? yearPrev : undefined;
|
|
997
|
+
const valueNext = yearNext <= this.maxYear ? yearNext : undefined;
|
|
998
|
+
const prevState = this.createYear(valuePrev);
|
|
999
|
+
const nextState = this.createYear(valueNext);
|
|
1000
|
+
prevYears.push(prevState);
|
|
1001
|
+
nextYears.push(nextState);
|
|
1002
|
+
this.recalculateRange(prevState, nextState);
|
|
1003
|
+
}
|
|
1004
|
+
const yearCenter = this.createYear(year);
|
|
1005
|
+
return [...prevYears, yearCenter, ...nextYears];
|
|
1006
|
+
}
|
|
1007
|
+
minOverflowYear(year) {
|
|
1008
|
+
return year < this.minYear;
|
|
1009
|
+
}
|
|
1010
|
+
maxOverflowYear(year) {
|
|
1011
|
+
return year > this.maxYear;
|
|
1012
|
+
}
|
|
1013
|
+
get minYear() {
|
|
1014
|
+
return this.minDate?.getFullYear() || 0;
|
|
1015
|
+
}
|
|
1016
|
+
get maxYear() {
|
|
1017
|
+
return this.maxDate?.getFullYear() || 10000;
|
|
1018
|
+
}
|
|
1019
|
+
get hasPrevious() {
|
|
1020
|
+
return this.minYear < this.minYearRange;
|
|
1021
|
+
}
|
|
1022
|
+
get hasNext() {
|
|
1023
|
+
return this.maxYear > this.maxYearRange;
|
|
1024
|
+
}
|
|
1025
|
+
createYear(value) {
|
|
1026
|
+
return {
|
|
1027
|
+
value,
|
|
1028
|
+
disabled: !value,
|
|
1029
|
+
selected: value === this.value
|
|
1030
|
+
};
|
|
1031
|
+
}
|
|
1032
|
+
recalculateRange(prev, next) {
|
|
1033
|
+
if (!!prev.value && this.minYearRange > prev.value) {
|
|
1034
|
+
this.minYearRange = prev.value;
|
|
1035
|
+
}
|
|
1036
|
+
if (!!next.value && this.maxYearRange < next.value) {
|
|
1037
|
+
this.maxYearRange = next.value;
|
|
1038
|
+
}
|
|
1039
|
+
}
|
|
1040
|
+
}
|
|
1041
|
+
function createYearPicker(props) {
|
|
1042
|
+
return FactoryYearPicker.execute(props);
|
|
1043
|
+
}
|
|
1044
|
+
|
|
1045
|
+
function RlsYearPicker({ formControl, date: date, disabled: disabledPicker, maxDate, minDate, rlsTheme }) {
|
|
1046
|
+
const initialDate = date || new Date();
|
|
1047
|
+
const initialYear = formControl?.state || initialDate.getFullYear();
|
|
1048
|
+
const [value, setValue] = useState(initialYear);
|
|
1049
|
+
const [year, setYear] = useState(initialYear);
|
|
1050
|
+
const [template, setTemplate] = useState(createYearPicker({
|
|
1051
|
+
value: formControl?.state || value,
|
|
1052
|
+
year: initialYear,
|
|
1053
|
+
minDate,
|
|
1054
|
+
maxDate
|
|
1055
|
+
}));
|
|
1056
|
+
useEffect(() => {
|
|
1057
|
+
setTemplate(createYearPicker({
|
|
1058
|
+
value: formControl?.state || value,
|
|
1059
|
+
year,
|
|
1060
|
+
minDate,
|
|
1061
|
+
maxDate
|
|
1062
|
+
}));
|
|
1063
|
+
}, [value, year, date, minDate, maxDate]);
|
|
1064
|
+
function onClickPrev() {
|
|
1065
|
+
setYear(year - 8);
|
|
1066
|
+
}
|
|
1067
|
+
function onClickNext() {
|
|
1068
|
+
setYear(year + 8);
|
|
1069
|
+
}
|
|
1070
|
+
function onChange(value) {
|
|
1071
|
+
formControl?.setState(value);
|
|
1072
|
+
setYear(value);
|
|
1073
|
+
setValue(value);
|
|
1074
|
+
}
|
|
1075
|
+
return (jsxs("div", { className: "rls-year-picker", "rls-theme": rlsTheme, children: [jsxs("div", { className: "rls-year-picker__header", children: [jsx("div", { className: "rls-year-picker__action rls-year-picker__action--prev", children: jsx("button", { disabled: !template.hasPrevious || disabledPicker, onClick: onClickPrev, children: jsx(RlsIcon, { value: "arrow-ios-left" }) }) }), jsx("div", { className: "rls-year-picker__title", children: jsxs("label", { className: "title1-bold", children: [template.minRange, " - ", template.maxRange] }) }), jsx("div", { className: "rls-year-picker__action rls-year-picker__action--next", children: jsx("button", { disabled: !template.hasNext || disabledPicker, onClick: onClickNext, children: jsx(RlsIcon, { value: "arrow-ios-right" }) }) })] }), jsx("div", { className: "rls-year-picker__component", children: template.years.map(({ value, disabled, selected }, index) => (jsx("div", { className: renderClassStatus('rls-year-picker__year', {
|
|
1076
|
+
disabled: disabled || disabledPicker,
|
|
1077
|
+
selected
|
|
1078
|
+
}), onClick: () => {
|
|
1079
|
+
if (value) {
|
|
1080
|
+
onChange(value);
|
|
1081
|
+
}
|
|
1082
|
+
}, children: jsx("span", { className: "rls-year-picker__year__span body1-medium", children: value || '????' }) }, index))) })] }));
|
|
1083
|
+
}
|
|
1084
|
+
|
|
1085
|
+
const classElement = '.rls-list-field__element';
|
|
1086
|
+
const MAX_POSITION_VISIBLE = 4;
|
|
1087
|
+
const LIST_SIZE_REM = 16;
|
|
1088
|
+
const ELEMENT_SIZE_REM = 4;
|
|
1089
|
+
const BASE_SIZE_PX = 16;
|
|
1090
|
+
const ELEMENT_SIZE_PX = BASE_SIZE_PX * ELEMENT_SIZE_REM;
|
|
1091
|
+
const MAZ_LIST_SIZE_PX = BASE_SIZE_PX * LIST_SIZE_REM;
|
|
1092
|
+
function useListControl({ suggestions, formControl, ignoreHigher = false }) {
|
|
1093
|
+
const boxContentRef = useRef(null);
|
|
1094
|
+
const listRef = useRef(null);
|
|
1095
|
+
const inputRef = useRef(null);
|
|
1096
|
+
const [collection, setCollection] = useState(new ListFieldCollection([]));
|
|
1097
|
+
const [active, setActive] = useState(false);
|
|
1098
|
+
const [visible, setVisible] = useState(false);
|
|
1099
|
+
const [opened, setOpened] = useState(false);
|
|
1100
|
+
const [value, setValue] = useState('');
|
|
1101
|
+
const [higher, setHigher] = useState(false);
|
|
1102
|
+
const [positionElement, setPositionElement] = useState(0);
|
|
1103
|
+
const [listElements, setListElements] = useState(undefined);
|
|
1104
|
+
useEffect(() => {
|
|
1105
|
+
function onCloseSuggestions(event) {
|
|
1106
|
+
if (!boxContentRef?.current?.contains(event.target)) {
|
|
1107
|
+
setVisible(false);
|
|
1108
|
+
}
|
|
1109
|
+
}
|
|
1110
|
+
document.addEventListener('click', onCloseSuggestions);
|
|
1111
|
+
return () => {
|
|
1112
|
+
document.removeEventListener('click', onCloseSuggestions);
|
|
1113
|
+
};
|
|
1114
|
+
}, []);
|
|
1115
|
+
useEffect(() => {
|
|
1116
|
+
if (visible && !opened) {
|
|
1117
|
+
setOpened(true);
|
|
1118
|
+
}
|
|
1119
|
+
if (!visible && opened && formControl && !formControl.touched) {
|
|
1120
|
+
formControl.touch();
|
|
1121
|
+
}
|
|
1122
|
+
setLocationList();
|
|
1123
|
+
}, [visible]);
|
|
1124
|
+
useEffect(() => {
|
|
1125
|
+
setCollection(new ListFieldCollection(suggestions));
|
|
1126
|
+
}, [suggestions]);
|
|
1127
|
+
function setLocationList() {
|
|
1128
|
+
if (boxContentRef?.current) {
|
|
1129
|
+
const { top, height } = boxContentRef.current.getBoundingClientRect();
|
|
1130
|
+
const overflow = BASE_SIZE_PX / 2;
|
|
1131
|
+
const positionEnd = top + height + MAZ_LIST_SIZE_PX + overflow;
|
|
1132
|
+
setHigher(positionEnd > window.innerHeight);
|
|
1133
|
+
}
|
|
1134
|
+
}
|
|
1135
|
+
function navigationInput(event) {
|
|
1136
|
+
switch (event.code) {
|
|
1137
|
+
case 'ArrowUp':
|
|
1138
|
+
if (visible && higher) {
|
|
1139
|
+
navigationInputUp();
|
|
1140
|
+
}
|
|
1141
|
+
break;
|
|
1142
|
+
case 'ArrowDown':
|
|
1143
|
+
if (visible && (ignoreHigher || !higher)) {
|
|
1144
|
+
navigationInputDown();
|
|
1145
|
+
}
|
|
1146
|
+
break;
|
|
1147
|
+
}
|
|
1148
|
+
}
|
|
1149
|
+
function navigationElement(event) {
|
|
1150
|
+
switch (event.code) {
|
|
1151
|
+
case 'ArrowUp':
|
|
1152
|
+
navigationElementUp();
|
|
1153
|
+
break;
|
|
1154
|
+
case 'ArrowDown':
|
|
1155
|
+
navigationElementDown();
|
|
1156
|
+
break;
|
|
1157
|
+
}
|
|
1158
|
+
}
|
|
1159
|
+
function navigationInputUp() {
|
|
1160
|
+
const elements = listRef?.current?.querySelectorAll(classElement);
|
|
1161
|
+
if (elements?.length) {
|
|
1162
|
+
const newPosition = elements.length - 1;
|
|
1163
|
+
setListElements(elements);
|
|
1164
|
+
setPositionElement(newPosition);
|
|
1165
|
+
elements.item(newPosition).focus();
|
|
1166
|
+
if (positionElement > MAX_POSITION_VISIBLE) {
|
|
1167
|
+
const elementPosition = elements.length - MAX_POSITION_VISIBLE;
|
|
1168
|
+
setTimeout(() => {
|
|
1169
|
+
listRef?.current?.scroll({
|
|
1170
|
+
top: ELEMENT_SIZE_PX * elementPosition,
|
|
1171
|
+
behavior: 'smooth'
|
|
1172
|
+
});
|
|
1173
|
+
}, 100);
|
|
1174
|
+
}
|
|
1175
|
+
}
|
|
1176
|
+
}
|
|
1177
|
+
function navigationInputDown() {
|
|
1178
|
+
const elements = listRef?.current?.querySelectorAll(classElement);
|
|
1179
|
+
if (elements?.length) {
|
|
1180
|
+
setListElements(elements);
|
|
1181
|
+
setPositionElement(0);
|
|
1182
|
+
elements.item(0).focus();
|
|
1183
|
+
setTimeout(() => {
|
|
1184
|
+
listRef?.current?.scroll({
|
|
1185
|
+
top: 0,
|
|
1186
|
+
behavior: 'smooth'
|
|
1187
|
+
});
|
|
1188
|
+
}, 100);
|
|
1189
|
+
}
|
|
1190
|
+
}
|
|
1191
|
+
function navigationElementUp() {
|
|
1192
|
+
if (positionElement > 0) {
|
|
1193
|
+
const newPosition = positionElement - 1;
|
|
1194
|
+
setPositionElement(newPosition);
|
|
1195
|
+
listElements?.item(newPosition).focus();
|
|
1196
|
+
}
|
|
1197
|
+
else if (ignoreHigher || !higher) {
|
|
1198
|
+
inputRef?.current?.focus();
|
|
1199
|
+
}
|
|
1200
|
+
}
|
|
1201
|
+
function navigationElementDown() {
|
|
1202
|
+
const newPosition = positionElement + 1;
|
|
1203
|
+
const length = listElements?.length || 0;
|
|
1204
|
+
if (newPosition < length) {
|
|
1205
|
+
setPositionElement(newPosition);
|
|
1206
|
+
listElements?.item(newPosition).focus();
|
|
1207
|
+
}
|
|
1208
|
+
else if (higher && !ignoreHigher) {
|
|
1209
|
+
inputRef?.current?.focus();
|
|
1210
|
+
}
|
|
1211
|
+
}
|
|
1212
|
+
return {
|
|
1213
|
+
active,
|
|
1214
|
+
boxContentRef,
|
|
1215
|
+
collection,
|
|
1216
|
+
higher,
|
|
1217
|
+
inputRef,
|
|
1218
|
+
listRef,
|
|
1219
|
+
navigationElement,
|
|
1220
|
+
navigationInput,
|
|
1221
|
+
setActive,
|
|
1222
|
+
setValue,
|
|
1223
|
+
setVisible,
|
|
1224
|
+
value,
|
|
1225
|
+
visible
|
|
1226
|
+
};
|
|
1227
|
+
}
|
|
1228
|
+
|
|
1229
|
+
const DURATION_ANIMATION$1 = 240;
|
|
1230
|
+
const MAX_ELEMENTS = 6;
|
|
1231
|
+
function RlsAutocompleteField({ suggestions, children, disabled, formControl, hiddenIcon, onSearch, onSelect, onValue, placeholder, searching, rlsTheme }) {
|
|
1232
|
+
const [pattern, setPattern] = useState('');
|
|
1233
|
+
const [coincidences, setCoincidences] = useState([]);
|
|
1234
|
+
const [store, setStore] = useState({
|
|
1235
|
+
pattern: '',
|
|
1236
|
+
coincidences: [],
|
|
1237
|
+
previous: null
|
|
1238
|
+
});
|
|
1239
|
+
const { active, boxContentRef, higher, inputRef, listRef, collection, value, visible, setActive, setValue, setVisible, navigationElement, navigationInput } = useListControl({ suggestions, formControl, ignoreHigher: true });
|
|
1240
|
+
const [changeInternal, setChangeInternal] = useState(false);
|
|
1241
|
+
useEffect(() => {
|
|
1242
|
+
filterSuggestions(pattern, true);
|
|
1243
|
+
}, [suggestions]);
|
|
1244
|
+
useEffect(() => {
|
|
1245
|
+
filterSuggestions(pattern);
|
|
1246
|
+
}, [pattern]);
|
|
1247
|
+
useEffect(() => {
|
|
1248
|
+
if (!changeInternal) {
|
|
1249
|
+
redefineDescription();
|
|
1250
|
+
}
|
|
1251
|
+
setChangeInternal(false);
|
|
1252
|
+
}, [formControl?.state]);
|
|
1253
|
+
useEffect(() => {
|
|
1254
|
+
redefineDescription();
|
|
1255
|
+
}, [collection]);
|
|
1256
|
+
function redefineDescription() {
|
|
1257
|
+
const element = formControl?.state && collection.findElement(formControl?.state);
|
|
1258
|
+
setValue(element?.description || '');
|
|
1259
|
+
}
|
|
1260
|
+
function onClickControl() {
|
|
1261
|
+
if (!disabled) {
|
|
1262
|
+
setVisible(true);
|
|
1263
|
+
setTimeout(() => inputRef?.current?.focus(), DURATION_ANIMATION$1);
|
|
1264
|
+
}
|
|
1265
|
+
}
|
|
1266
|
+
function onFocusInput() {
|
|
1267
|
+
setActive(true);
|
|
1268
|
+
}
|
|
1269
|
+
function onBlurInput() {
|
|
1270
|
+
setActive(false);
|
|
1271
|
+
}
|
|
1272
|
+
function onKeydownInput(event) {
|
|
1273
|
+
switch (event.code) {
|
|
1274
|
+
case 'Escape':
|
|
1275
|
+
setVisible(false);
|
|
1276
|
+
break;
|
|
1277
|
+
case 'Tab':
|
|
1278
|
+
setVisible(false);
|
|
1279
|
+
break;
|
|
1280
|
+
default:
|
|
1281
|
+
navigationInput(event);
|
|
1282
|
+
break;
|
|
1283
|
+
}
|
|
1284
|
+
}
|
|
1285
|
+
function onClickAction() {
|
|
1286
|
+
setVisible(false);
|
|
1287
|
+
setValue('');
|
|
1288
|
+
if (formControl) {
|
|
1289
|
+
setChangeInternal(true);
|
|
1290
|
+
formControl.setState(undefined);
|
|
1291
|
+
}
|
|
1292
|
+
if (onValue) {
|
|
1293
|
+
onValue(undefined);
|
|
1294
|
+
}
|
|
1295
|
+
}
|
|
1296
|
+
function onClickBackdrop() {
|
|
1297
|
+
setVisible(false);
|
|
1298
|
+
}
|
|
1299
|
+
function onClickItem(element) {
|
|
1300
|
+
return () => {
|
|
1301
|
+
onChange(element);
|
|
1302
|
+
};
|
|
1303
|
+
}
|
|
1304
|
+
function onKeydownItem(element) {
|
|
1305
|
+
return (event) => {
|
|
1306
|
+
switch (event.code) {
|
|
1307
|
+
case 'Enter':
|
|
1308
|
+
onChange(element);
|
|
1309
|
+
break;
|
|
1310
|
+
default:
|
|
1311
|
+
navigationElement(event);
|
|
1312
|
+
break;
|
|
1313
|
+
}
|
|
1314
|
+
};
|
|
1315
|
+
}
|
|
1316
|
+
function onChange({ description, value }) {
|
|
1317
|
+
setVisible(false);
|
|
1318
|
+
if (onSelect) {
|
|
1319
|
+
onSelect(value);
|
|
1320
|
+
}
|
|
1321
|
+
else {
|
|
1322
|
+
if (formControl) {
|
|
1323
|
+
setChangeInternal(true);
|
|
1324
|
+
formControl.setState(value);
|
|
1325
|
+
}
|
|
1326
|
+
setValue(description);
|
|
1327
|
+
}
|
|
1328
|
+
if (onValue) {
|
|
1329
|
+
onValue(value);
|
|
1330
|
+
}
|
|
1331
|
+
}
|
|
1332
|
+
function filterSuggestions(pattern, reboot = false) {
|
|
1333
|
+
if (pattern) {
|
|
1334
|
+
const store = reboot ? createStoreEmpty() : searchForPattern(pattern);
|
|
1335
|
+
const filters = store?.coincidences || suggestions;
|
|
1336
|
+
const coincidences = filters.filter((element) => element.hasCoincidence(pattern));
|
|
1337
|
+
setCoincidences(coincidences.slice(0, MAX_ELEMENTS));
|
|
1338
|
+
setStore({
|
|
1339
|
+
coincidences,
|
|
1340
|
+
pattern,
|
|
1341
|
+
previous: store
|
|
1342
|
+
});
|
|
1343
|
+
}
|
|
1344
|
+
else {
|
|
1345
|
+
setCoincidences(suggestions.slice(0, MAX_ELEMENTS));
|
|
1346
|
+
rebootStore();
|
|
1347
|
+
}
|
|
1348
|
+
}
|
|
1349
|
+
function searchForPattern(value) {
|
|
1350
|
+
if (!store.pattern) {
|
|
1351
|
+
return null;
|
|
1352
|
+
}
|
|
1353
|
+
let newStore = store;
|
|
1354
|
+
let search = false;
|
|
1355
|
+
while (!search && newStore) {
|
|
1356
|
+
search = hasPattern(value, newStore.pattern, true);
|
|
1357
|
+
if (!search) {
|
|
1358
|
+
newStore = newStore.previous;
|
|
1359
|
+
}
|
|
1360
|
+
}
|
|
1361
|
+
return newStore || rebootStore();
|
|
1362
|
+
}
|
|
1363
|
+
function rebootStore() {
|
|
1364
|
+
const newStore = createStoreEmpty();
|
|
1365
|
+
setStore(newStore);
|
|
1366
|
+
return newStore;
|
|
1367
|
+
}
|
|
1368
|
+
function createStoreEmpty() {
|
|
1369
|
+
return {
|
|
1370
|
+
coincidences: undefined,
|
|
1371
|
+
pattern: '',
|
|
1372
|
+
previous: null
|
|
1373
|
+
};
|
|
1374
|
+
}
|
|
1375
|
+
return (jsxs("div", { ref: boxContentRef, className: renderClassStatus('rls-box-field', {
|
|
1376
|
+
disabled,
|
|
1377
|
+
active,
|
|
1378
|
+
selected: !!value
|
|
1379
|
+
}, 'rls-autocomplete-field rls-list-field'), "rls-theme": rlsTheme, children: [children && jsx("label", { className: "rls-box-field__label", children: children }), jsx("div", { className: "rls-box-field__component", children: jsxs("div", { className: "rls-box-field__body", children: [jsx("label", { className: "rls-list-field__control", onClick: onClickControl, children: value ? (jsx("span", { className: "rls-list-field__control__description", children: value })) : (jsx("span", { className: "rls-list-field__control__placeholder", children: placeholder })) }), !hiddenIcon && value && (jsx("button", { className: "rls-list-field__action", disabled: disabled, onClick: onClickAction, children: jsx(RlsIcon, { value: "trash-2" }) }))] }) }), formControl?.touched && formControl?.error && (jsx("div", { className: "rls-box-field__error", children: jsx(RlsMessageIcon, { icon: "alert-triangle", rlsTheme: "danger", children: formControl.error.message }) })), jsxs("div", { className: renderClassStatus('rls-list-field__suggestions', {
|
|
1380
|
+
visible,
|
|
1381
|
+
hide: !visible,
|
|
1382
|
+
higher
|
|
1383
|
+
}), children: [jsx("div", { className: "rls-list-field__suggestions__body", children: jsxs("ul", { ref: listRef, className: "rls-list-field__ul", children: [jsxs("div", { className: "rls-list-field__ul__search", children: [jsx("input", { ref: inputRef, className: "rls-list-field__ul__control", type: "text", value: pattern, onChange: ({ target: { value } }) => {
|
|
1384
|
+
setPattern(value);
|
|
1385
|
+
}, disabled: disabled || searching, onFocus: onFocusInput, onBlur: onBlurInput, onKeyDown: onKeydownInput }), onSearch && (jsx("button", { disabled: disabled || searching, onClick: () => {
|
|
1386
|
+
onSearch(pattern);
|
|
1387
|
+
}, children: jsx(RlsIcon, { value: "search" }) }))] }), searching && jsx(RlsProgressBar, { indeterminate: true }), coincidences.map((element, index) => (jsx("li", { className: "rls-list-field__element", tabIndex: -1, onClick: onClickItem(element), onKeyDown: onKeydownItem(element), children: jsx(RlsBallot, { subtitle: element.subtitle, img: element.img, initials: element.initials, children: element.title }) }, index))), !coincidences.length && (jsx("li", { className: "rls-list-field__empty", children: jsxs("div", { className: "rls-list-field__empty__description", children: [jsx("label", { className: "label-bold truncate", children: "Selecci\u00F3n no disponible" }), jsx("p", { className: "caption-regular", children: "Lo sentimos, en el momento no hay elementos en el listado" })] }) }))] }) }), jsx("div", { className: "rls-list-field__backdrop", onClick: onClickBackdrop })] })] }));
|
|
1388
|
+
}
|
|
1389
|
+
|
|
1390
|
+
function RlsCard({ children, outline, rlsTheme }) {
|
|
1391
|
+
return (jsx("div", { className: renderClassStatus('rls-card', { outline }), "rls-theme": rlsTheme, children: jsx("div", { className: "rls-card__content", children: children }) }));
|
|
1392
|
+
}
|
|
1393
|
+
|
|
1394
|
+
class ConfirmationResult extends PartialSealed {
|
|
1395
|
+
static approved() {
|
|
1396
|
+
return new ConfirmationResult('approved');
|
|
1397
|
+
}
|
|
1398
|
+
static reject() {
|
|
1399
|
+
return new ConfirmationResult('reject');
|
|
1400
|
+
}
|
|
1401
|
+
}
|
|
1402
|
+
function RlsConfirmation({ approved, content, reject, rlsTheme, subtitle, title, visible }) {
|
|
1403
|
+
return (jsxs("div", { className: renderClassStatus('rls-confirmation', { visible }), "rls-theme": rlsTheme, children: [jsxs("div", { className: "rls-confirmation__component", children: [jsxs("div", { className: "rls-confirmation__header", children: [title && (jsx("div", { className: "rls-confirmation__header__title", children: title })), subtitle && (jsx("div", { className: "rls-confirmation__header__subtitle", children: subtitle }))] }), jsx("div", { className: "rls-confirmation__body", children: content && (jsx("div", { className: "rls-confirmation__body__content", children: content })) }), (approved || reject) && (jsx("div", { className: "rls-confirmation__footer", children: jsxs("div", { className: "rls-confirmation__footer__actions", children: [approved && (jsx(RlsButton, { type: "raised", onClick: () => {
|
|
1404
|
+
if (approved.onClick) {
|
|
1405
|
+
approved.onClick();
|
|
1406
|
+
}
|
|
1407
|
+
}, children: approved.label })), reject && (jsx(RlsButton, { type: "outline", onClick: () => {
|
|
1408
|
+
if (reject.onClick) {
|
|
1409
|
+
reject.onClick();
|
|
1410
|
+
}
|
|
1411
|
+
}, children: reject.label }))] }) }))] }), jsx("div", { className: "rls-confirmation__backdrop" })] }));
|
|
1412
|
+
}
|
|
1413
|
+
function useConfirmationService() {
|
|
1414
|
+
const [config, setConfig] = useState({});
|
|
1415
|
+
const [visible, setVisible] = useState(false);
|
|
1416
|
+
const rlsConfirmation = ReactDOM.createPortal(jsx(RlsConfirmation, { ...config, visible: visible }), document.body);
|
|
1417
|
+
function confirmation(config) {
|
|
1418
|
+
return new Promise((resolve) => {
|
|
1419
|
+
const { content, rlsTheme, subtitle, title, approved, reject } = config;
|
|
1420
|
+
setConfig({
|
|
1421
|
+
content,
|
|
1422
|
+
rlsTheme,
|
|
1423
|
+
subtitle,
|
|
1424
|
+
title,
|
|
1425
|
+
approved: {
|
|
1426
|
+
label: approved || 'Aceptar',
|
|
1427
|
+
onClick: () => {
|
|
1428
|
+
setVisible(false);
|
|
1429
|
+
resolve(ConfirmationResult.approved());
|
|
1430
|
+
}
|
|
1431
|
+
},
|
|
1432
|
+
reject: reject
|
|
1433
|
+
? {
|
|
1434
|
+
label: reject,
|
|
1435
|
+
onClick: () => {
|
|
1436
|
+
setVisible(false);
|
|
1437
|
+
resolve(ConfirmationResult.reject());
|
|
1438
|
+
}
|
|
1439
|
+
}
|
|
1440
|
+
: undefined
|
|
1441
|
+
});
|
|
1442
|
+
setVisible(true);
|
|
1443
|
+
});
|
|
1444
|
+
}
|
|
1445
|
+
return {
|
|
1446
|
+
RlsConfirmation: rlsConfirmation,
|
|
1447
|
+
confirmation
|
|
1448
|
+
};
|
|
1449
|
+
}
|
|
1450
|
+
|
|
1451
|
+
function RlsDatatableHeader({ children }) {
|
|
1452
|
+
return jsx("tr", { className: "rls-datatable__header", children: children });
|
|
1453
|
+
}
|
|
1454
|
+
function RlsDatatableTitle({ children, className, control }) {
|
|
1455
|
+
return (jsx("th", { className: `${className} ` + renderClassStatus('rls-datatable__title', { control }), children: children }));
|
|
1456
|
+
}
|
|
1457
|
+
function RlsDatatableData({ children, className }) {
|
|
1458
|
+
return jsx("tr", { className: `rls-datatable__data ${className}`, children: children });
|
|
1459
|
+
}
|
|
1460
|
+
function RlsDatatableCell({ children, className, control, overflow }) {
|
|
1461
|
+
return (jsx("th", { className: `${className} ` +
|
|
1462
|
+
renderClassStatus('rls-datatable__cell', { control, overflow }), children: children }));
|
|
1463
|
+
}
|
|
1464
|
+
function RlsDatatable({ children, footer, header, rlsTheme }) {
|
|
1465
|
+
return (jsxs("div", { className: "rls-datatable", "rls-theme": rlsTheme, children: [jsxs("table", { children: [header && jsx("thead", { className: "rls-datatable__thead", children: header }), jsx("tbody", { className: "rls-datatable__tbody", children: children })] }), footer && jsx("div", { className: "rls-datatable__tfooter", children: footer })] }));
|
|
1466
|
+
}
|
|
1467
|
+
|
|
1468
|
+
const controlIsValid = (props) => {
|
|
1469
|
+
const { state, validators } = props;
|
|
1470
|
+
return validators.reduce((errors, validator) => {
|
|
1471
|
+
const error = validator(state);
|
|
1472
|
+
if (error) {
|
|
1473
|
+
errors.push(error);
|
|
1474
|
+
}
|
|
1475
|
+
return errors;
|
|
1476
|
+
}, []);
|
|
1477
|
+
};
|
|
1478
|
+
|
|
1479
|
+
function useReactControl(props = {}) {
|
|
1480
|
+
const [state, setCurrentState] = useState(props.state);
|
|
1481
|
+
const [value, setValue] = useState(props.state);
|
|
1482
|
+
const [touched, setTouched] = useState(false);
|
|
1483
|
+
const [dirty, setDirty] = useState(false);
|
|
1484
|
+
const [focused, setFocused] = useState(false);
|
|
1485
|
+
const [disabled, setDisabled] = useState(false);
|
|
1486
|
+
const [initialValue] = useState(props.state);
|
|
1487
|
+
const [validators, setValidators] = useState(props.validators);
|
|
1488
|
+
const [subscribers] = useState(new BehaviorSubject(props.state));
|
|
1489
|
+
const elementRef = useRef(null);
|
|
1490
|
+
const errors = (() => validators ? controlIsValid({ state, validators }) : [])();
|
|
1491
|
+
const error = (() => errors[0])();
|
|
1492
|
+
const valid = (() => errors.length === 0)();
|
|
1493
|
+
useEffect(() => {
|
|
1494
|
+
if (state !== null && state !== undefined) {
|
|
1495
|
+
setValue(state);
|
|
1496
|
+
}
|
|
1497
|
+
subscribers.next(state);
|
|
1498
|
+
}, [state]);
|
|
1499
|
+
function focus() {
|
|
1500
|
+
setFocused(true);
|
|
1501
|
+
}
|
|
1502
|
+
function blur() {
|
|
1503
|
+
setFocused(false);
|
|
1504
|
+
}
|
|
1505
|
+
function disable() {
|
|
1506
|
+
setDisabled(true);
|
|
1507
|
+
}
|
|
1508
|
+
function enable() {
|
|
1509
|
+
setDisabled(false);
|
|
1510
|
+
}
|
|
1511
|
+
function touch() {
|
|
1512
|
+
setTouched(true);
|
|
1513
|
+
}
|
|
1514
|
+
function untouch() {
|
|
1515
|
+
setTouched(false);
|
|
1516
|
+
}
|
|
1517
|
+
function setState(state) {
|
|
1518
|
+
setDirty(true);
|
|
1519
|
+
setCurrentState(state);
|
|
1520
|
+
}
|
|
1521
|
+
function reset() {
|
|
1522
|
+
setTouched(false);
|
|
1523
|
+
setDirty(false);
|
|
1524
|
+
setCurrentState(initialValue);
|
|
1525
|
+
}
|
|
1526
|
+
function subscribe(subscriber) {
|
|
1527
|
+
return subscribers.subscribe(subscriber);
|
|
1528
|
+
}
|
|
1529
|
+
return {
|
|
1530
|
+
elementRef,
|
|
1531
|
+
error,
|
|
1532
|
+
errors,
|
|
1533
|
+
focused,
|
|
1534
|
+
unfocused: !focused,
|
|
1535
|
+
dirty,
|
|
1536
|
+
pristine: !dirty,
|
|
1537
|
+
disabled,
|
|
1538
|
+
enabled: !disabled,
|
|
1539
|
+
valid,
|
|
1540
|
+
invalid: !valid,
|
|
1541
|
+
touched,
|
|
1542
|
+
untouched: !touched,
|
|
1543
|
+
reset,
|
|
1544
|
+
focus,
|
|
1545
|
+
blur,
|
|
1546
|
+
disable,
|
|
1547
|
+
enable,
|
|
1548
|
+
touch,
|
|
1549
|
+
untouch,
|
|
1550
|
+
setState,
|
|
1551
|
+
setValidators,
|
|
1552
|
+
state,
|
|
1553
|
+
subscribe,
|
|
1554
|
+
value
|
|
1555
|
+
};
|
|
1556
|
+
}
|
|
1557
|
+
|
|
1558
|
+
var PickerListenerType;
|
|
1559
|
+
(function (PickerListenerType) {
|
|
1560
|
+
PickerListenerType["Select"] = "PickerSelect";
|
|
1561
|
+
PickerListenerType["Now"] = "PickerNow";
|
|
1562
|
+
PickerListenerType["Cancel"] = "PickerCancel";
|
|
1563
|
+
})(PickerListenerType || (PickerListenerType = {}));
|
|
1564
|
+
|
|
1565
|
+
function verifyDateRange(date, min, max) {
|
|
1566
|
+
return min && isBefore(min, date)
|
|
1567
|
+
? min
|
|
1568
|
+
: max && isAfter(max, date)
|
|
1569
|
+
? max
|
|
1570
|
+
: date;
|
|
1571
|
+
}
|
|
1572
|
+
|
|
1573
|
+
const FORMAT_DESCRIPTION = '{dw}, {mx} {dd} de {aa}';
|
|
1574
|
+
const VISIBILITY_STATE$1 = {
|
|
1575
|
+
month: false,
|
|
1576
|
+
day: false,
|
|
1577
|
+
year: false
|
|
1578
|
+
};
|
|
1579
|
+
const VISIBILITY$1 = {
|
|
1580
|
+
DAY: {
|
|
1581
|
+
...VISIBILITY_STATE$1,
|
|
1582
|
+
day: true
|
|
1583
|
+
},
|
|
1584
|
+
MONTH: {
|
|
1585
|
+
...VISIBILITY_STATE$1,
|
|
1586
|
+
month: true
|
|
1587
|
+
},
|
|
1588
|
+
YEAR: {
|
|
1589
|
+
...VISIBILITY_STATE$1,
|
|
1590
|
+
year: true
|
|
1591
|
+
}
|
|
1592
|
+
};
|
|
1593
|
+
function RlsDatePicker({ automatic, date, formControl, disabled, maxDate, minDate, onListener, rlsTheme }) {
|
|
1594
|
+
const dateInitial = formControl?.state || date || new Date();
|
|
1595
|
+
const yearControl = useReactControl({ state: dateInitial.getFullYear() });
|
|
1596
|
+
const dayControl = useReactControl({ state: dateInitial.getDate() });
|
|
1597
|
+
const monthControl = useReactControl({ state: dateInitial.getMonth() });
|
|
1598
|
+
const [value, setValue] = useState(dateInitial);
|
|
1599
|
+
const [{ day, month, year }, setVisibility] = useState(VISIBILITY$1.DAY);
|
|
1600
|
+
const title = formatDate(value, FORMAT_DESCRIPTION);
|
|
1601
|
+
useEffect(() => {
|
|
1602
|
+
setValue((prevValue) => {
|
|
1603
|
+
return typeof yearControl.state === 'number'
|
|
1604
|
+
? verifyDateRange(refactorYear(prevValue, yearControl.state), minDate, maxDate)
|
|
1605
|
+
: prevValue;
|
|
1606
|
+
});
|
|
1607
|
+
setVisibility(VISIBILITY$1.DAY);
|
|
1608
|
+
}, [yearControl.state]);
|
|
1609
|
+
useEffect(() => {
|
|
1610
|
+
setValue((prevValue) => {
|
|
1611
|
+
return typeof monthControl.state === 'number'
|
|
1612
|
+
? verifyDateRange(refactorMonth(prevValue, monthControl.state), minDate, maxDate)
|
|
1613
|
+
: prevValue;
|
|
1614
|
+
});
|
|
1615
|
+
setVisibility(VISIBILITY$1.DAY);
|
|
1616
|
+
}, [monthControl.state]);
|
|
1617
|
+
useEffect(() => {
|
|
1618
|
+
setValue((prevValue) => {
|
|
1619
|
+
return typeof dayControl.state === 'number'
|
|
1620
|
+
? verifyDateRange(refactorDay(prevValue, dayControl.state), minDate, maxDate)
|
|
1621
|
+
: prevValue;
|
|
1622
|
+
});
|
|
1623
|
+
}, [dayControl.state]);
|
|
1624
|
+
function onVisibilityDay() {
|
|
1625
|
+
setVisibility(VISIBILITY$1.DAY);
|
|
1626
|
+
}
|
|
1627
|
+
function onVisibilityMonth() {
|
|
1628
|
+
setVisibility(VISIBILITY$1.MONTH);
|
|
1629
|
+
}
|
|
1630
|
+
function onVisibilityYear() {
|
|
1631
|
+
setVisibility(VISIBILITY$1.YEAR);
|
|
1632
|
+
}
|
|
1633
|
+
function onCancel() {
|
|
1634
|
+
if (onListener) {
|
|
1635
|
+
onListener({ type: PickerListenerType.Cancel });
|
|
1636
|
+
}
|
|
1637
|
+
}
|
|
1638
|
+
function onToday() {
|
|
1639
|
+
const value = new Date(); // Today date
|
|
1640
|
+
formControl?.setState(value);
|
|
1641
|
+
setValue(value);
|
|
1642
|
+
yearControl.setState(value.getFullYear());
|
|
1643
|
+
dayControl.setState(value.getDate());
|
|
1644
|
+
monthControl.setState(value.getMonth());
|
|
1645
|
+
if (onListener) {
|
|
1646
|
+
onListener({ type: PickerListenerType.Now, value });
|
|
1647
|
+
}
|
|
1648
|
+
}
|
|
1649
|
+
function onSelect() {
|
|
1650
|
+
formControl?.setState(value);
|
|
1651
|
+
if (onListener) {
|
|
1652
|
+
onListener({ type: PickerListenerType.Select, value });
|
|
1653
|
+
}
|
|
1654
|
+
}
|
|
1655
|
+
return (jsxs("div", { className: "rls-date-picker", "rls-theme": rlsTheme, children: [jsxs("div", { className: "rls-date-picker__header", children: [jsx("div", { className: "rls-date-picker__title rls-date-picker__title--description", children: jsx("span", { onClick: onVisibilityDay, children: title }) }), jsx("div", { className: "rls-date-picker__title rls-date-picker__title--year", children: jsx("span", { onClick: onVisibilityYear, children: yearControl.value }) }), jsx(RlsMonthTitlePicker, { monthControl: monthControl, yearControl: yearControl, date: value, maxDate: maxDate, minDate: minDate, onClick: onVisibilityMonth })] }), jsxs("div", { className: renderClassStatus('rls-date-picker__component', {
|
|
1656
|
+
year,
|
|
1657
|
+
day,
|
|
1658
|
+
month
|
|
1659
|
+
}), children: [jsx(RlsDayPicker, { formControl: dayControl, date: value, maxDate: maxDate, minDate: minDate, disabled: disabled }), jsx(RlsMonthPicker, { formControl: monthControl, date: value, maxDate: maxDate, minDate: minDate, disabled: disabled }), jsx(RlsYearPicker, { formControl: yearControl, date: value, maxDate: maxDate, minDate: minDate, disabled: disabled })] }), jsx("div", { className: renderClassStatus('rls-date-picker__footer', { automatic }), children: jsxs("div", { className: "rls-date-picker__actions", children: [jsx("div", { className: "rls-date-picker__actions--cancel", children: jsx(RlsButton, { type: "ghost", onClick: onCancel, children: "Cancelar" }) }), jsx("div", { className: "rls-date-picker__actions--today", children: jsx(RlsButton, { type: "ghost", onClick: onToday, children: "Hoy" }) }), jsx("div", { className: "rls-date-picker__actions--ok", children: jsx(RlsButton, { type: "raised", onClick: onSelect, children: "Establecer" }) })] }) })] }));
|
|
1660
|
+
}
|
|
1661
|
+
|
|
1662
|
+
function RlsModal({ children, visible, rlsTheme }) {
|
|
1663
|
+
return ReactDOM.createPortal(jsxs("div", { className: renderClassStatus('rls-modal', { visible }), "rls-theme": rlsTheme, children: [jsx("div", { className: "rls-modal__component", children: children }), jsx("div", { className: "rls-modal__backdrop" })] }), document.body);
|
|
1664
|
+
}
|
|
1665
|
+
|
|
1666
|
+
function RlsDateField({ children, date, disabled, formControl, maxDate, minDate, placeholder, rlsTheme }) {
|
|
1667
|
+
const dateInitial = formControl?.state || date || new Date();
|
|
1668
|
+
const [value, setValue] = useState(dateInitial);
|
|
1669
|
+
const [show, setShow] = useState(false);
|
|
1670
|
+
const [description, setDescription] = useState('');
|
|
1671
|
+
useEffect(() => {
|
|
1672
|
+
setDescription(value ? formatDate(value, '{dd}/{mx}/{aa}') : '');
|
|
1673
|
+
}, [value]);
|
|
1674
|
+
function onClickInput() {
|
|
1675
|
+
setShow(true);
|
|
1676
|
+
}
|
|
1677
|
+
function onClean() {
|
|
1678
|
+
if (value) {
|
|
1679
|
+
formControl?.setState(undefined);
|
|
1680
|
+
setValue(undefined);
|
|
1681
|
+
if (formControl && !formControl.touched) {
|
|
1682
|
+
formControl.touch();
|
|
1683
|
+
}
|
|
1684
|
+
}
|
|
1685
|
+
else {
|
|
1686
|
+
setShow(true);
|
|
1687
|
+
}
|
|
1688
|
+
}
|
|
1689
|
+
return (jsxs("div", { className: "rls-date-field", "rls-theme": rlsTheme, children: [jsxs("div", { className: renderClassStatus('rls-box-field', { disabled }), children: [children && jsx("label", { className: "rls-box-field__label", children: children }), jsx("div", { className: "rls-box-field__component", children: jsxs("div", { className: "rls-box-field__body", children: [jsx("input", { className: "rls-date-field__control", type: "text", value: description, readOnly: true, placeholder: placeholder, onClick: onClickInput, disabled: disabled }), jsx("button", { className: "rls-date-field__action", onClick: onClean, disabled: disabled, children: jsx(RlsIcon, { value: value ? 'trash-2' : 'calendar' }) })] }) }), formControl?.touched && formControl?.error && (jsx("div", { className: "rls-box-field__error", children: jsx(RlsMessageIcon, { icon: "alert-triangle", rlsTheme: "danger", children: formControl.error.message }) }))] }), jsx(RlsModal, { visible: show, children: jsx(RlsDatePicker, { formControl: formControl, date: date, disabled: disabled, maxDate: maxDate, minDate: minDate, onListener: ({ value }) => {
|
|
1690
|
+
if (value) {
|
|
1691
|
+
setValue(value);
|
|
1692
|
+
}
|
|
1693
|
+
setShow(false);
|
|
1694
|
+
if (formControl && !formControl.touched) {
|
|
1695
|
+
formControl.touch();
|
|
1696
|
+
}
|
|
1697
|
+
} }) })] }));
|
|
1698
|
+
}
|
|
1699
|
+
|
|
1700
|
+
const VISIBILITY_STATE = {
|
|
1701
|
+
month: false,
|
|
1702
|
+
day: false,
|
|
1703
|
+
year: false
|
|
1704
|
+
};
|
|
1705
|
+
const VISIBILITY = {
|
|
1706
|
+
DAY: {
|
|
1707
|
+
...VISIBILITY_STATE,
|
|
1708
|
+
day: true
|
|
1709
|
+
},
|
|
1710
|
+
MONTH: {
|
|
1711
|
+
...VISIBILITY_STATE,
|
|
1712
|
+
month: true
|
|
1713
|
+
},
|
|
1714
|
+
YEAR: {
|
|
1715
|
+
...VISIBILITY_STATE,
|
|
1716
|
+
year: true
|
|
1717
|
+
}
|
|
1718
|
+
};
|
|
1719
|
+
function RlsDateRangePicker({ automatic, date: datePicker, disabled, formControl, maxDate, minDate, rlsTheme, onListener }) {
|
|
1720
|
+
const dateInitial = normalizeMinTime(datePicker || new Date());
|
|
1721
|
+
const rangeInitial = formControl?.state || DateRange.now();
|
|
1722
|
+
const yearControl = useReactControl({ state: dateInitial.getFullYear() });
|
|
1723
|
+
const monthControl = useReactControl({ state: dateInitial.getMonth() });
|
|
1724
|
+
const dayControl = useReactControl({ state: rangeInitial });
|
|
1725
|
+
const [value, setValue] = useState(rangeInitial);
|
|
1726
|
+
const [date, setDate] = useState(dateInitial);
|
|
1727
|
+
const [{ day, month, year }, setVisibility] = useState(VISIBILITY.DAY);
|
|
1728
|
+
useEffect(() => {
|
|
1729
|
+
setDate((prevValue) => {
|
|
1730
|
+
return typeof yearControl.state === 'number'
|
|
1731
|
+
? refactorYear(prevValue, yearControl.state)
|
|
1732
|
+
: prevValue;
|
|
1733
|
+
});
|
|
1734
|
+
setVisibility(VISIBILITY.DAY);
|
|
1735
|
+
}, [yearControl.state]);
|
|
1736
|
+
useEffect(() => {
|
|
1737
|
+
setDate((prevValue) => {
|
|
1738
|
+
return typeof monthControl.state === 'number'
|
|
1739
|
+
? refactorMonth(prevValue, monthControl.state)
|
|
1740
|
+
: prevValue;
|
|
1741
|
+
});
|
|
1742
|
+
setVisibility(VISIBILITY.DAY);
|
|
1743
|
+
}, [monthControl.state]);
|
|
1744
|
+
useEffect(() => {
|
|
1745
|
+
if (dayControl.state) {
|
|
1746
|
+
setValue(dayControl.state);
|
|
1747
|
+
}
|
|
1748
|
+
setVisibility(VISIBILITY.DAY);
|
|
1749
|
+
}, [dayControl.state]);
|
|
1750
|
+
function onVisibilityDay() {
|
|
1751
|
+
setVisibility(VISIBILITY.DAY);
|
|
1752
|
+
}
|
|
1753
|
+
function onVisibilityMonth() {
|
|
1754
|
+
setVisibility(VISIBILITY.MONTH);
|
|
1755
|
+
}
|
|
1756
|
+
function onVisibilityYear() {
|
|
1757
|
+
setVisibility(VISIBILITY.YEAR);
|
|
1758
|
+
}
|
|
1759
|
+
function onCancel() {
|
|
1760
|
+
if (onListener) {
|
|
1761
|
+
onListener({ type: PickerListenerType.Cancel });
|
|
1762
|
+
}
|
|
1763
|
+
}
|
|
1764
|
+
function onSelect() {
|
|
1765
|
+
formControl?.setState(value);
|
|
1766
|
+
if (onListener) {
|
|
1767
|
+
onListener({ type: PickerListenerType.Select, value });
|
|
1768
|
+
}
|
|
1769
|
+
}
|
|
1770
|
+
return (jsxs("div", { className: "rls-date-range-picker", "rls-theme": rlsTheme, children: [jsxs("div", { className: "rls-date-range-picker__header", children: [jsx("div", { className: "rls-date-range-picker__title rls-date-range-picker__title--description", children: jsx("span", { onClick: onVisibilityDay, children: value.description }) }), jsx("div", { className: "rls-date-range-picker__title rls-date-range-picker__title--year", children: jsx("span", { onClick: onVisibilityYear, children: yearControl.state }) }), jsx(RlsMonthTitlePicker, { monthControl: monthControl, yearControl: yearControl, date: date, maxDate: maxDate, minDate: minDate, onClick: onVisibilityMonth })] }), jsxs("div", { className: renderClassStatus('rls-date-range-picker__component', {
|
|
1771
|
+
year,
|
|
1772
|
+
day,
|
|
1773
|
+
month
|
|
1774
|
+
}), children: [jsx(RlsDayRangePicker, { formControl: dayControl, date: date, maxDate: maxDate, minDate: minDate, disabled: disabled }), jsx(RlsMonthPicker, { formControl: monthControl, date: date, maxDate: maxDate, minDate: minDate, disabled: disabled }), jsx(RlsYearPicker, { formControl: yearControl, date: date, maxDate: maxDate, minDate: minDate, disabled: disabled })] }), jsx("div", { className: renderClassStatus('rls-date-range-picker__footer', {
|
|
1775
|
+
automatic
|
|
1776
|
+
}), children: jsxs("div", { className: "rls-date-range-picker__actions", children: [jsx("div", { className: "rls-date-range-picker__actions--cancel", children: jsx(RlsButton, { type: "ghost", onClick: onCancel, children: "Cancelar" }) }), jsx("div", { className: "rls-date-range-picker__actions--ok", children: jsx(RlsButton, { type: "raised", onClick: onSelect, children: "Establecer" }) })] }) })] }));
|
|
1777
|
+
}
|
|
1778
|
+
|
|
1779
|
+
function RlsDateRangeField({ children, date: datePicker, disabled, formControl, maxDate, minDate, placeholder, rlsTheme }) {
|
|
1780
|
+
const rangeInitial = formControl?.state || DateRange.now();
|
|
1781
|
+
const dateInitial = datePicker || new Date();
|
|
1782
|
+
const [value, setValue] = useState(rangeInitial);
|
|
1783
|
+
const [date] = useState(dateInitial);
|
|
1784
|
+
const [show, setShow] = useState(false);
|
|
1785
|
+
const [description, setDescription] = useState('');
|
|
1786
|
+
useEffect(() => {
|
|
1787
|
+
setDescription(value?.description || '');
|
|
1788
|
+
}, [value]);
|
|
1789
|
+
function onClickInput() {
|
|
1790
|
+
setShow(true);
|
|
1791
|
+
}
|
|
1792
|
+
function onClickAction() {
|
|
1793
|
+
if (value) {
|
|
1794
|
+
formControl?.setState(undefined);
|
|
1795
|
+
setValue(undefined);
|
|
1796
|
+
}
|
|
1797
|
+
else {
|
|
1798
|
+
setShow(true);
|
|
1799
|
+
}
|
|
1800
|
+
}
|
|
1801
|
+
return (jsxs("div", { className: "rls-date-field", "rls-theme": rlsTheme, children: [jsxs("div", { className: "rls-box-field", children: [children && jsx("label", { className: "rls-box-field__label", children: children }), jsx("div", { className: "rls-box-field__component", children: jsxs("div", { className: "rls-box-field__body", children: [jsx("input", { className: "rls-date-field__control", type: "text", value: description, readOnly: true, placeholder: placeholder, onClick: onClickInput }), jsx("button", { className: "rls-date-field__action", onClick: onClickAction, children: jsx(RlsIcon, { value: value ? 'trash-2' : 'calendar' }) })] }) })] }), jsx(RlsModal, { visible: show, children: jsx(RlsDateRangePicker, { formControl: formControl, date: date, disabled: disabled, maxDate: maxDate, minDate: minDate, onListener: ({ value }) => {
|
|
1802
|
+
if (value) {
|
|
1803
|
+
setValue(value);
|
|
1804
|
+
}
|
|
1805
|
+
setShow(false);
|
|
1806
|
+
} }) })] }));
|
|
1807
|
+
}
|
|
1808
|
+
|
|
1809
|
+
function RlsFormNavigation({ children, visible, rlsTheme }) {
|
|
1810
|
+
return (jsx("div", { className: renderClassStatus('rls-form-navigation', { visible }), "rls-theme": rlsTheme, children: jsx("div", { className: "rls-form-navigation__body", children: children }) }));
|
|
1811
|
+
}
|
|
1812
|
+
|
|
1813
|
+
function RlsSelectField({ suggestions, children, disabled, formControl, onSelect, onValue, placeholder, rlsTheme }) {
|
|
1814
|
+
const { active, boxContentRef, higher, inputRef, listRef, collection, value, visible, setActive, setValue, setVisible, navigationElement, navigationInput } = useListControl({ suggestions, formControl });
|
|
1815
|
+
const [changeInternal, setChangeInternal] = useState(false);
|
|
1816
|
+
useEffect(() => {
|
|
1817
|
+
if (!changeInternal) {
|
|
1818
|
+
redefineDescription();
|
|
1819
|
+
}
|
|
1820
|
+
setChangeInternal(false);
|
|
1821
|
+
}, [formControl?.state]);
|
|
1822
|
+
useEffect(() => {
|
|
1823
|
+
redefineDescription();
|
|
1824
|
+
}, [collection]);
|
|
1825
|
+
function redefineDescription() {
|
|
1826
|
+
const element = formControl?.state && collection.findElement(formControl?.state);
|
|
1827
|
+
setValue(element?.description || '');
|
|
1828
|
+
}
|
|
1829
|
+
function onFocusInput() {
|
|
1830
|
+
setActive(true);
|
|
1831
|
+
}
|
|
1832
|
+
function onBlurInput() {
|
|
1833
|
+
setActive(false);
|
|
1834
|
+
}
|
|
1835
|
+
function onClickInput() {
|
|
1836
|
+
setVisible(true);
|
|
1837
|
+
}
|
|
1838
|
+
function onKeydownInput(event) {
|
|
1839
|
+
switch (event.code) {
|
|
1840
|
+
case 'Space':
|
|
1841
|
+
setVisible(true);
|
|
1842
|
+
break;
|
|
1843
|
+
case 'Enter':
|
|
1844
|
+
setVisible(true);
|
|
1845
|
+
break;
|
|
1846
|
+
case 'Escape':
|
|
1847
|
+
setVisible(false);
|
|
1848
|
+
break;
|
|
1849
|
+
case 'Tab':
|
|
1850
|
+
setVisible(false);
|
|
1851
|
+
break;
|
|
1852
|
+
default:
|
|
1853
|
+
navigationInput(event);
|
|
1854
|
+
break;
|
|
1855
|
+
}
|
|
1856
|
+
}
|
|
1857
|
+
function onClickAction() {
|
|
1858
|
+
const newVisible = !visible;
|
|
1859
|
+
setVisible(newVisible);
|
|
1860
|
+
if (newVisible) {
|
|
1861
|
+
inputRef?.current?.focus();
|
|
1862
|
+
}
|
|
1863
|
+
}
|
|
1864
|
+
function onClickBackdrop() {
|
|
1865
|
+
setVisible(false);
|
|
1866
|
+
}
|
|
1867
|
+
function onClickItem(element) {
|
|
1868
|
+
return () => {
|
|
1869
|
+
onChange(element);
|
|
1870
|
+
};
|
|
1871
|
+
}
|
|
1872
|
+
function onKeydownItem(element) {
|
|
1873
|
+
return (event) => {
|
|
1874
|
+
switch (event.code) {
|
|
1875
|
+
case 'Enter':
|
|
1876
|
+
onChange(element);
|
|
1877
|
+
break;
|
|
1878
|
+
default:
|
|
1879
|
+
navigationElement(event);
|
|
1880
|
+
break;
|
|
1881
|
+
}
|
|
1882
|
+
};
|
|
1883
|
+
}
|
|
1884
|
+
function onChange({ description, value }) {
|
|
1885
|
+
inputRef?.current?.focus();
|
|
1886
|
+
setVisible(false);
|
|
1887
|
+
if (onSelect) {
|
|
1888
|
+
onSelect(value);
|
|
1889
|
+
}
|
|
1890
|
+
else {
|
|
1891
|
+
if (formControl) {
|
|
1892
|
+
setChangeInternal(true);
|
|
1893
|
+
formControl.setState(value);
|
|
1894
|
+
}
|
|
1895
|
+
setValue(description);
|
|
1896
|
+
}
|
|
1897
|
+
if (onValue) {
|
|
1898
|
+
onValue(value);
|
|
1899
|
+
}
|
|
1900
|
+
}
|
|
1901
|
+
return (jsxs("div", { ref: boxContentRef, className: renderClassStatus('rls-box-field', { active, disabled }, 'rls-select-field rls-list-field'), "rls-theme": rlsTheme, children: [children && jsx("label", { className: "rls-box-field__label", children: children }), jsx("div", { className: "rls-box-field__component", children: jsxs("div", { className: "rls-box-field__body", children: [jsx("input", { ref: inputRef, className: "rls-list-field__control", readOnly: true, disabled: disabled, placeholder: placeholder, value: value, onFocus: onFocusInput, onBlur: onBlurInput, onClick: onClickInput, onKeyDown: onKeydownInput }), jsx("button", { className: renderClassStatus('rls-list-field__action', { visible }), disabled: disabled, onClick: onClickAction, children: jsx(RlsIcon, { value: "arrow-ios-down" }) })] }) }), formControl?.touched && formControl?.error && (jsx("div", { className: "rls-box-field__error", children: jsx(RlsMessageIcon, { icon: "alert-triangle", rlsTheme: "danger", children: formControl.error.message }) })), jsxs("div", { className: renderClassStatus('rls-list-field__suggestions', {
|
|
1902
|
+
visible,
|
|
1903
|
+
hide: !visible,
|
|
1904
|
+
higher
|
|
1905
|
+
}), children: [jsx("div", { className: "rls-list-field__suggestions__body", children: jsxs("ul", { ref: listRef, className: "rls-list-field__ul", children: [suggestions.map((element, index) => (jsx("li", { className: "rls-list-field__element", tabIndex: -1, onClick: onClickItem(element), onKeyDown: onKeydownItem(element), children: jsx(RlsBallot, { subtitle: element.subtitle, img: element.img, initials: element.initials, children: element.title }) }, index))), !suggestions.length && (jsx("li", { className: "rls-list-field__empty", children: jsxs("div", { className: "rls-list-field__empty__description", children: [jsx("label", { className: "label-bold truncate", children: "Selecci\u00F3n no disponible" }), jsx("p", { className: "caption-regular", children: "Lo sentimos, en el momento no hay elementos en el listado" })] }) }))] }) }), jsx("div", { className: "rls-list-field__backdrop", onClick: onClickBackdrop })] })] }));
|
|
1906
|
+
}
|
|
1907
|
+
|
|
1908
|
+
const DURATION_ANIMATION = 240;
|
|
1909
|
+
const DURATION_CHAR = 75;
|
|
1910
|
+
const DURATION_MAX = 9000;
|
|
1911
|
+
const DURATION_MIN = 3000;
|
|
1912
|
+
const DURATION_RESET = 480;
|
|
1913
|
+
function calculateDuration({ length }) {
|
|
1914
|
+
let duration = length * DURATION_CHAR;
|
|
1915
|
+
if (duration < DURATION_MIN) {
|
|
1916
|
+
duration = DURATION_MIN;
|
|
1917
|
+
}
|
|
1918
|
+
else if (duration > DURATION_MAX) {
|
|
1919
|
+
duration = DURATION_MAX;
|
|
1920
|
+
}
|
|
1921
|
+
return duration + DURATION_RESET;
|
|
1922
|
+
}
|
|
1923
|
+
function RlsSnackbar({ content, icon, title, visible, rlsTheme }) {
|
|
1924
|
+
return (jsxs("div", { className: renderClassStatus('rls-snackbar', { visible }), "rls-theme": rlsTheme, children: [icon && (jsx("div", { className: "rls-snackbar__avatar", children: jsx(RlsIcon, { value: icon }) })), jsxs("div", { className: "rls-snackbar__component", children: [title && jsx("div", { className: "rls-snackbar__title", children: title }), jsx("div", { className: "rls-snackbar__content", children: content })] })] }));
|
|
1925
|
+
}
|
|
1926
|
+
function useSnackbarService() {
|
|
1927
|
+
const [config, setConfig] = useState({});
|
|
1928
|
+
const [duration, setDuration] = useState(4000);
|
|
1929
|
+
const [timeoutId, setTimeoutId] = useState();
|
|
1930
|
+
const [visible, setVisible] = useState(false);
|
|
1931
|
+
const rlsSnackbar = jsx(RlsSnackbar, { ...config, visible: visible });
|
|
1932
|
+
useEffect(() => {
|
|
1933
|
+
if (visible) {
|
|
1934
|
+
const timeoutId = setTimeout(() => {
|
|
1935
|
+
setVisible(false);
|
|
1936
|
+
setTimeoutId(undefined);
|
|
1937
|
+
}, duration);
|
|
1938
|
+
setTimeoutId(timeoutId);
|
|
1939
|
+
}
|
|
1940
|
+
else if (timeoutId) {
|
|
1941
|
+
clearTimeout(timeoutId);
|
|
1942
|
+
setTimeout(() => snackbar(config), DURATION_ANIMATION);
|
|
1943
|
+
}
|
|
1944
|
+
}, [visible]);
|
|
1945
|
+
function snackbar(config) {
|
|
1946
|
+
const { content } = config;
|
|
1947
|
+
setConfig(config);
|
|
1948
|
+
setDuration(calculateDuration(String(content)));
|
|
1949
|
+
setVisible(!visible);
|
|
1950
|
+
}
|
|
1951
|
+
return {
|
|
1952
|
+
RlsSnackbar: rlsSnackbar,
|
|
1953
|
+
snackbar
|
|
1954
|
+
};
|
|
1955
|
+
}
|
|
1956
|
+
|
|
1957
|
+
const RlsContext = createContext({
|
|
1958
|
+
confirmation: () => {
|
|
1959
|
+
return Promise.resolve(ConfirmationResult.approved());
|
|
1960
|
+
},
|
|
1961
|
+
snackbar: () => { }
|
|
1962
|
+
});
|
|
1963
|
+
function RlsApplication({ children }) {
|
|
1964
|
+
const { RlsConfirmation, confirmation } = useConfirmationService();
|
|
1965
|
+
const { RlsSnackbar, snackbar } = useSnackbarService();
|
|
1966
|
+
return (jsxs(RlsContext.Provider, { value: { confirmation, snackbar }, children: [jsx("div", { className: "rls-app__body", children: children }), RlsSnackbar, RlsConfirmation] }));
|
|
1967
|
+
}
|
|
1968
|
+
|
|
1969
|
+
export { ConfirmationResult, DateRange, ListFieldCollection, RlsAmount, RlsApplication, RlsAutocompleteField, RlsAvatar, RlsBallot, RlsBreadcrumb, RlsButton, RlsButtonAction, RlsButtonToggle, RlsCard, RlsCheckBox, RlsCheckBoxControl, RlsCheckBoxLabel, RlsConfirmation, RlsContext, RlsDatatable, RlsDatatableCell, RlsDatatableData, RlsDatatableHeader, RlsDatatableTitle, RlsDateField, RlsDatePicker, RlsDateRangeField, RlsDateRangePicker, RlsDayPicker, RlsDayRangePicker, RlsFormNavigation, RlsIcon, RlsInput, RlsInputMoney, RlsInputNumber, RlsInputPassword, RlsInputText, RlsLabel, RlsMessageIcon, RlsModal, RlsMoneyField, RlsMonthPicker, RlsMonthTitlePicker, RlsNumberField, RlsPagination, RlsPasswordField, RlsPoster, RlsProgressBar, RlsRadioButton, RlsRadioButtonLabel, RlsSearchInput, RlsSelectField, RlsSkeleton, RlsSkeletonText, RlsSnackbar, RlsSwitch, RlsSwitchControl, RlsSwitchLabel, RlsTabularText, RlsTextField, RlsToolbar, RlsYearPicker, renderClassStatus, useConfirmationService, useListControl, useSnackbarService };
|
|
1970
|
+
//# sourceMappingURL=index.js.map
|