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