@rolster/react-components 18.12.9 → 18.13.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/assets/{index-7UzJ6VgT.css → index-fykwrWLx.css} +747 -648
- package/dist/cjs/index.js +760 -776
- package/dist/cjs/index.js.map +1 -1
- package/dist/es/assets/{index-7UzJ6VgT.css → index-fykwrWLx.css} +747 -648
- package/dist/es/index.js +760 -778
- package/dist/es/index.js.map +1 -1
- package/dist/esm/components/atoms/Amount/Amount.css +3 -3
- package/dist/esm/components/atoms/Avatar/Avatar.css +7 -7
- package/dist/esm/components/atoms/Badge/Badge.css +7 -7
- package/dist/esm/components/atoms/Breadcrumb/Breadcrumb.css +12 -12
- package/dist/esm/components/atoms/Button/Button.css +74 -53
- package/dist/esm/components/atoms/Button/Button.d.ts +1 -1
- package/dist/esm/components/atoms/Button/Button.js +1 -1
- package/dist/esm/components/atoms/Button/Button.js.map +1 -1
- package/dist/esm/components/atoms/ButtonAction/ButtonAction.css +22 -22
- package/dist/esm/components/atoms/ButtonAction/ButtonAction.d.ts +1 -1
- package/dist/esm/components/atoms/CheckBox/CheckBox.css +8 -8
- package/dist/esm/components/atoms/Icon/Icon.css +7 -8
- package/dist/esm/components/atoms/Input/Input.css +13 -15
- package/dist/esm/components/atoms/InputMoney/InputMoney.css +1 -1
- package/dist/esm/components/atoms/InputNumber/InputNumber.css +1 -1
- package/dist/esm/components/atoms/InputPassword/InputPassword.css +8 -8
- package/dist/esm/components/atoms/InputText/InputText.css +1 -1
- package/dist/esm/components/atoms/Label/Label.css +1 -1
- package/dist/esm/components/atoms/MessageIcon/MessageIcon.css +6 -6
- package/dist/esm/components/atoms/Poster/Poster.css +6 -6
- package/dist/esm/components/atoms/ProgressBar/ProgressBar.css +7 -7
- package/dist/esm/components/atoms/ProgressCircular/ProgressCircular.css +44 -0
- package/dist/esm/components/atoms/ProgressCircular/ProgressCircular.d.ts +7 -0
- package/dist/esm/components/atoms/ProgressCircular/ProgressCircular.js +6 -0
- package/dist/esm/components/atoms/ProgressCircular/ProgressCircular.js.map +1 -0
- package/dist/esm/components/atoms/RadioButton/RadioButton.css +6 -6
- package/dist/esm/components/atoms/SearchInput/SearchInput.css +4 -4
- package/dist/esm/components/atoms/Skeleton/Skeleton.css +6 -6
- package/dist/esm/components/atoms/SkeletonText/SkeletonText.css +6 -8
- package/dist/esm/components/atoms/Switch/Switch.css +16 -16
- package/dist/esm/components/atoms/TabularText/TabularText.css +2 -2
- package/dist/esm/components/atoms/index.d.ts +1 -0
- package/dist/esm/components/atoms/index.js +1 -0
- package/dist/esm/components/atoms/index.js.map +1 -1
- package/dist/esm/components/definitions.d.ts +1 -1
- package/dist/esm/components/molecules/Ballot/Ballot.css +27 -34
- package/dist/esm/components/molecules/ButtonProgress/ButtonProgress.css +7 -0
- package/dist/esm/components/molecules/ButtonProgress/ButtonProgress.d.ts +12 -0
- package/dist/esm/components/molecules/ButtonProgress/ButtonProgress.js +8 -0
- package/dist/esm/components/molecules/ButtonProgress/ButtonProgress.js.map +1 -0
- package/dist/esm/components/molecules/ButtonToggle/ButtonToggle.css +32 -30
- package/dist/esm/components/molecules/CheckBoxLabel/CheckBoxLabel.css +8 -8
- package/dist/esm/components/molecules/DayPicker/DayPicker.css +39 -27
- package/dist/esm/components/molecules/DayPicker/DayPicker.d.ts +3 -1
- package/dist/esm/components/molecules/DayPicker/DayPicker.js +32 -24
- package/dist/esm/components/molecules/DayPicker/DayPicker.js.map +1 -1
- package/dist/esm/components/molecules/DayRangePicker/DayRangePicker.css +28 -28
- package/dist/esm/components/molecules/DayRangePicker/DayRangePicker.js +18 -21
- package/dist/esm/components/molecules/DayRangePicker/DayRangePicker.js.map +1 -1
- package/dist/esm/components/molecules/MoneyField/MoneyField.css +1 -2
- package/dist/esm/components/molecules/MonthPicker/MonthPicker.css +34 -19
- package/dist/esm/components/molecules/MonthPicker/MonthPicker.d.ts +2 -1
- package/dist/esm/components/molecules/MonthPicker/MonthPicker.js +30 -19
- package/dist/esm/components/molecules/MonthPicker/MonthPicker.js.map +1 -1
- package/dist/esm/components/molecules/MonthTitlePicker/MonthTitlePicker.css +6 -6
- package/dist/esm/components/molecules/MonthTitlePicker/MonthTitlePicker.d.ts +1 -1
- package/dist/esm/components/molecules/MonthTitlePicker/MonthTitlePicker.js +26 -21
- package/dist/esm/components/molecules/MonthTitlePicker/MonthTitlePicker.js.map +1 -1
- package/dist/esm/components/molecules/NumberField/NumberField.css +1 -2
- package/dist/esm/components/molecules/Pagination/Pagination.css +29 -30
- package/dist/esm/components/molecules/PasswordField/PasswordField.css +4 -5
- package/dist/esm/components/molecules/RadioButtonLabel/RadioButtonLabel.css +8 -10
- package/dist/esm/components/molecules/SwitchLabel/SwitchLabel.css +8 -9
- package/dist/esm/components/molecules/TextField/TextField.css +1 -2
- package/dist/esm/components/molecules/Toolbar/Toolbar.css +10 -10
- package/dist/esm/components/molecules/YearPicker/YearPicker.css +42 -28
- package/dist/esm/components/molecules/YearPicker/YearPicker.d.ts +1 -1
- package/dist/esm/components/molecules/YearPicker/YearPicker.js +33 -26
- package/dist/esm/components/molecules/YearPicker/YearPicker.js.map +1 -1
- package/dist/esm/components/molecules/index.d.ts +1 -0
- package/dist/esm/components/molecules/index.js +1 -0
- package/dist/esm/components/molecules/index.js.map +1 -1
- package/dist/esm/components/organisms/AutocompleteField/AutocompleteField.css +22 -22
- package/dist/esm/components/organisms/AutocompleteField/AutocompleteField.d.ts +1 -1
- package/dist/esm/components/organisms/AutocompleteField/AutocompleteField.js +1 -1
- package/dist/esm/components/organisms/AutocompleteField/AutocompleteField.js.map +1 -1
- package/dist/esm/components/organisms/AutocompleteField/AutocompleteFieldHook.d.ts +1 -1
- package/dist/esm/components/organisms/AutocompleteField/AutocompleteFieldHook.js +27 -81
- package/dist/esm/components/organisms/AutocompleteField/AutocompleteFieldHook.js.map +1 -1
- package/dist/esm/components/organisms/Card/Card.css +5 -5
- package/dist/esm/components/organisms/Confirmation/Confirmation.css +38 -38
- package/dist/esm/components/organisms/DateField/DateField.css +15 -15
- package/dist/esm/components/organisms/DateField/DateField.d.ts +2 -2
- package/dist/esm/components/organisms/DateField/DateField.js +28 -16
- package/dist/esm/components/organisms/DateField/DateField.js.map +1 -1
- package/dist/esm/components/organisms/DatePicker/DatePicker.css +27 -24
- package/dist/esm/components/organisms/DatePicker/DatePicker.d.ts +2 -2
- package/dist/esm/components/organisms/DatePicker/DatePicker.js +38 -56
- package/dist/esm/components/organisms/DatePicker/DatePicker.js.map +1 -1
- package/dist/esm/components/organisms/DateRangeField/DateRangeField.css +13 -15
- package/dist/esm/components/organisms/DateRangeField/DateRangeField.js +5 -5
- package/dist/esm/components/organisms/DateRangeField/DateRangeField.js.map +1 -1
- package/dist/esm/components/organisms/DateRangePicker/DateRangePicker.css +20 -20
- package/dist/esm/components/organisms/DateRangePicker/DateRangePicker.d.ts +2 -2
- package/dist/esm/components/organisms/DateRangePicker/DateRangePicker.js +16 -36
- package/dist/esm/components/organisms/DateRangePicker/DateRangePicker.js.map +1 -1
- package/dist/esm/components/organisms/FormNavigation/FormNavigation.css +15 -14
- package/dist/esm/components/organisms/Modal/Modal.css +11 -11
- package/dist/esm/components/organisms/SelectField/SelectField.css +1 -1
- package/dist/esm/components/organisms/SelectField/SelectField.d.ts +1 -1
- package/dist/esm/components/organisms/SelectField/SelectField.js +1 -1
- package/dist/esm/components/organisms/SelectField/SelectField.js.map +1 -1
- package/dist/esm/components/organisms/SelectField/SelectFieldHook.d.ts +1 -1
- package/dist/esm/components/organisms/SelectField/SelectFieldHook.js +18 -35
- package/dist/esm/components/organisms/SelectField/SelectFieldHook.js.map +1 -1
- package/dist/esm/components/organisms/Snackbar/Snackbar.css +26 -26
- package/dist/esm/constants/index.d.ts +1 -0
- package/dist/esm/constants/index.js +2 -0
- package/dist/esm/constants/index.js.map +1 -0
- package/dist/esm/constants/picker.constant.d.ts +1 -0
- package/dist/esm/constants/picker.constant.js +2 -0
- package/dist/esm/constants/picker.constant.js.map +1 -0
- package/dist/esm/helpers/date-range-picker.d.ts +1 -12
- package/dist/esm/helpers/date-range-picker.js +5 -105
- package/dist/esm/helpers/date-range-picker.js.map +1 -1
- package/dist/esm/helpers/index.d.ts +2 -0
- package/dist/esm/helpers/index.js +3 -0
- package/dist/esm/helpers/index.js.map +1 -0
- package/dist/esm/hooks/ListControlHook.d.ts +2 -3
- package/dist/esm/hooks/ListControlHook.js +22 -92
- package/dist/esm/hooks/ListControlHook.js.map +1 -1
- package/dist/esm/index.d.ts +1 -2
- package/dist/esm/index.js +1 -2
- package/dist/esm/index.js.map +1 -1
- package/package.json +7 -6
- package/dist/esm/helpers/date-picker.d.ts +0 -1
- package/dist/esm/helpers/date-picker.js +0 -5
- package/dist/esm/helpers/date-picker.js.map +0 -1
- package/dist/esm/helpers/day-picker.d.ts +0 -9
- package/dist/esm/helpers/day-picker.js +0 -84
- package/dist/esm/helpers/day-picker.js.map +0 -1
- package/dist/esm/helpers/month-picker.d.ts +0 -14
- package/dist/esm/helpers/month-picker.js +0 -78
- package/dist/esm/helpers/month-picker.js.map +0 -1
- package/dist/esm/helpers/year-picker.d.ts +0 -17
- package/dist/esm/helpers/year-picker.js +0 -83
- package/dist/esm/helpers/year-picker.js.map +0 -1
- package/dist/esm/models.d.ts +0 -58
- package/dist/esm/models.js +0 -9
- package/dist/esm/models.js.map +0 -1
- package/dist/esm/types.d.ts +0 -12
- package/dist/esm/types.js +0 -7
- package/dist/esm/types.js.map +0 -1
package/dist/es/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { jsx, jsxs } from 'react/jsx-runtime';
|
|
2
2
|
import { useState, useRef, useEffect, createContext } from 'react';
|
|
3
|
-
import { currencyFormat, PartialSealed } from '@rolster/helpers-advanced';
|
|
4
|
-
import {
|
|
3
|
+
import { currencyFormat, itIsDefined, PartialSealed } from '@rolster/helpers-advanced';
|
|
4
|
+
import { dateIsBefore, normalizeMinTime, dateIsAfter, normalizeMaxTime, getDaysOfMonth, getDateWeight, dateIsEqualsWeight, dateIsBetween, assignDayInDate, Month, MONTH_NAMES, DAY_LABELS, DateRange, dateFormatTemplate, assignYearInDate, assignMonthInDate } from '@rolster/helpers-date';
|
|
5
5
|
import { hasPattern } from '@rolster/helpers-string';
|
|
6
6
|
import { i18n } from '@rolster/i18n';
|
|
7
7
|
import ReactDOM from 'react-dom';
|
|
@@ -54,7 +54,7 @@ function RlsIcon({ value, skeleton }) {
|
|
|
54
54
|
}
|
|
55
55
|
|
|
56
56
|
function RlsButton({ type, children, disabled, prefixIcon, suffixIcon, rlsTheme, onClick }) {
|
|
57
|
-
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 &&
|
|
57
|
+
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 })] }) }));
|
|
58
58
|
}
|
|
59
59
|
|
|
60
60
|
function RlsButtonAction({ icon, disabled, tooltip, onClick }) {
|
|
@@ -185,6 +185,10 @@ function RlsProgressBar({ indeterminate, percentage, rlsTheme }) {
|
|
|
185
185
|
return (jsx("div", { className: renderClassStatus('rls-progress-bar', { indeterminate }), "rls-theme": rlsTheme, children: jsx("div", { className: "rls-progress-bar__component", style: { width: `${percentage || 0}%` } }) }));
|
|
186
186
|
}
|
|
187
187
|
|
|
188
|
+
function RlsProgressCircular({ rlsTheme }) {
|
|
189
|
+
return (jsx("div", { className: "rls-progress-circular", "rls-theme": rlsTheme, children: jsx("svg", { className: "rls-progress-circular__svg", viewBox: "0 0 36 36", children: jsx("circle", { className: "rls-progress-circular__circle", cx: "18", cy: "18", r: "12" }) }) }));
|
|
190
|
+
}
|
|
191
|
+
|
|
188
192
|
function RlsRadioButton({ checked, disabled, rlsTheme, onClick }) {
|
|
189
193
|
return (jsx("div", { className: renderClassStatus('rls-radiobutton', { checked, disabled }), onClick: onClick, "rls-theme": rlsTheme, children: jsx("div", { className: "rls-radiobutton__component" }) }));
|
|
190
194
|
}
|
|
@@ -214,6 +218,10 @@ function RlsBallot({ bordered, children, img, initials, skeleton, subtitle, rlsT
|
|
|
214
218
|
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 }) }))] })] }));
|
|
215
219
|
}
|
|
216
220
|
|
|
221
|
+
function RlsButtonProgress({ icon, disabled, onClick, progressing, rlsTheme }) {
|
|
222
|
+
return (jsxs("div", { className: renderClassStatus('rls-button-progress', { progressing }), "rls-theme": rlsTheme, children: [!progressing && (jsx(RlsButtonAction, { icon: icon, onClick: onClick, disabled: disabled })), progressing && jsx(RlsProgressCircular, {})] }));
|
|
223
|
+
}
|
|
224
|
+
|
|
217
225
|
function RlsButtonToggle({ onAction, options, type, automatic, disabled, rlsTheme }) {
|
|
218
226
|
const componentRef = useRef(null);
|
|
219
227
|
const [firstAction] = options;
|
|
@@ -265,241 +273,541 @@ function RlsCheckBoxLabel({ children, disabled, extended, formControl, rlsTheme
|
|
|
265
273
|
}), "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 })] }));
|
|
266
274
|
}
|
|
267
275
|
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
276
|
+
function dateIsOutRangeMin(props) {
|
|
277
|
+
const { date, minDate } = props;
|
|
278
|
+
return !!minDate && dateIsBefore(normalizeMinTime(minDate), date);
|
|
279
|
+
}
|
|
280
|
+
function dateIsOutRangeMax(props) {
|
|
281
|
+
const { date, maxDate } = props;
|
|
282
|
+
return !!maxDate && dateIsAfter(normalizeMaxTime(maxDate), date);
|
|
283
|
+
}
|
|
284
|
+
function dateOutRange(props) {
|
|
285
|
+
return dateIsOutRangeMin(props) || dateIsOutRangeMax(props);
|
|
286
|
+
}
|
|
287
|
+
function checkDateRange(props) {
|
|
288
|
+
const { date, maxDate, minDate } = props;
|
|
289
|
+
return minDate && dateIsOutRangeMax(props)
|
|
290
|
+
? minDate
|
|
291
|
+
: maxDate && dateIsOutRangeMax(props)
|
|
292
|
+
? maxDate
|
|
293
|
+
: date;
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
const DAYS_WEEK = 7;
|
|
297
|
+
const COUNT_YEAR_RANGE = 4;
|
|
298
|
+
|
|
299
|
+
function createDayState(props, today, value) {
|
|
300
|
+
const { date, day, month, year } = props;
|
|
301
|
+
const dateValue = value && new Date(year, month, value);
|
|
302
|
+
return {
|
|
303
|
+
disabled: dayIsOutside(props, value || 0),
|
|
304
|
+
focused: !!value && day === value,
|
|
305
|
+
forbidden: !value,
|
|
306
|
+
selected: !!dateValue && dateIsEqualsWeight(date, dateValue),
|
|
307
|
+
today: !!dateValue && dateIsEqualsWeight(today, dateValue),
|
|
308
|
+
value
|
|
309
|
+
};
|
|
310
|
+
}
|
|
311
|
+
function createFirstWeek$1(props, date, today) {
|
|
312
|
+
const days = [];
|
|
313
|
+
let day = 1;
|
|
314
|
+
for (let start = 0; start < date.getDay(); start++) {
|
|
315
|
+
days.push(createDayState(props, today));
|
|
316
|
+
}
|
|
317
|
+
for (let end = date.getDay(); end < 7; end++) {
|
|
318
|
+
days.push(createDayState(props, today, day));
|
|
319
|
+
day++;
|
|
320
|
+
}
|
|
321
|
+
return { days };
|
|
322
|
+
}
|
|
323
|
+
function createDaysPending$1(props, today, days) {
|
|
324
|
+
const daysPending = [];
|
|
325
|
+
const length = 7 - days;
|
|
326
|
+
for (let index = 0; index < length; index++) {
|
|
327
|
+
daysPending.push(createDayState(props, today));
|
|
328
|
+
}
|
|
329
|
+
return daysPending;
|
|
330
|
+
}
|
|
331
|
+
function createNextWeeks$1(props, date, today) {
|
|
332
|
+
const daysMonth = getDaysOfMonth(date.getFullYear(), date.getMonth());
|
|
333
|
+
const weeks = [];
|
|
334
|
+
let days = [];
|
|
335
|
+
let countDays = 1;
|
|
336
|
+
let day = DAYS_WEEK - date.getDay() + 1;
|
|
337
|
+
do {
|
|
338
|
+
days.push(createDayState(props, today, day));
|
|
339
|
+
day++;
|
|
340
|
+
countDays++;
|
|
341
|
+
if (countDays > DAYS_WEEK) {
|
|
342
|
+
weeks.push({ days });
|
|
343
|
+
days = [];
|
|
344
|
+
countDays = 1;
|
|
345
|
+
}
|
|
346
|
+
} while (day <= daysMonth);
|
|
347
|
+
if (days.length && days.length < DAYS_WEEK) {
|
|
348
|
+
weeks.push({
|
|
349
|
+
days: [...days, ...createDaysPending$1(props, today, days.length)]
|
|
350
|
+
});
|
|
351
|
+
}
|
|
352
|
+
return weeks;
|
|
353
|
+
}
|
|
354
|
+
function dayIsOutsideMin(props, day) {
|
|
355
|
+
const { month, year, minDate } = props;
|
|
356
|
+
return minDate
|
|
357
|
+
? getDateWeight(new Date(year, month, day)) < getDateWeight(minDate)
|
|
358
|
+
: false;
|
|
359
|
+
}
|
|
360
|
+
function dayIsOutsideMax(props, day) {
|
|
361
|
+
const { month, year, maxDate } = props;
|
|
362
|
+
return maxDate
|
|
363
|
+
? getDateWeight(new Date(year, month, day)) > getDateWeight(maxDate)
|
|
364
|
+
: false;
|
|
365
|
+
}
|
|
366
|
+
function dayIsOutside(props, day) {
|
|
367
|
+
return dayIsOutsideMin(props, day) || dayIsOutsideMax(props, day);
|
|
368
|
+
}
|
|
369
|
+
function checkDayPicker(props) {
|
|
370
|
+
const { day, maxDate, minDate } = props;
|
|
371
|
+
return minDate && dayIsOutsideMin(props, day)
|
|
372
|
+
? minDate.getDate()
|
|
373
|
+
: maxDate && dayIsOutsideMax(props, day)
|
|
374
|
+
? maxDate.getDate()
|
|
375
|
+
: undefined;
|
|
376
|
+
}
|
|
377
|
+
function createDayPicker(props) {
|
|
378
|
+
const date = new Date(props.year, props.month, 1);
|
|
379
|
+
const today = new Date();
|
|
380
|
+
const firstWeek = createFirstWeek$1(props, date, today);
|
|
381
|
+
const nextWeeks = createNextWeeks$1(props, date, today);
|
|
382
|
+
return [firstWeek, ...nextWeeks];
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
function dateIsSelected(base, date, day) {
|
|
386
|
+
return (date.getFullYear() === base.getFullYear() &&
|
|
387
|
+
date.getMonth() === base.getMonth() &&
|
|
388
|
+
day === date.getDate());
|
|
389
|
+
}
|
|
390
|
+
function sourceIsSelected({ sourceDate }, base, day) {
|
|
391
|
+
return dateIsSelected(base, sourceDate, day);
|
|
392
|
+
}
|
|
393
|
+
function rangeIsSelected({ range }, base, day) {
|
|
394
|
+
return (dateIsSelected(base, range.minDate, day) ||
|
|
395
|
+
dateIsSelected(base, range.maxDate, day));
|
|
396
|
+
}
|
|
397
|
+
function dayIsRange({ range }, base, day) {
|
|
398
|
+
return dateIsBetween(range.minDate, range.maxDate, assignDayInDate(base, day));
|
|
399
|
+
}
|
|
400
|
+
function createDayRangeState(props, base, day) {
|
|
401
|
+
return {
|
|
402
|
+
disabled: dayRangeIsOutside(props, day || 0),
|
|
403
|
+
end: day ? rangeIsSelected(props, base, day) : false,
|
|
404
|
+
forbidden: !day,
|
|
405
|
+
ranged: day ? dayIsRange(props, base, day) : false,
|
|
406
|
+
source: day ? sourceIsSelected(props, base, day) : false,
|
|
407
|
+
value: day
|
|
408
|
+
};
|
|
409
|
+
}
|
|
410
|
+
function createFirstWeek(props, base) {
|
|
411
|
+
const days = [];
|
|
412
|
+
let day = 1;
|
|
413
|
+
for (let start = 0; start < base.getDay(); start++) {
|
|
414
|
+
days.push(createDayRangeState(props, base));
|
|
415
|
+
}
|
|
416
|
+
for (let end = base.getDay(); end < 7; end++) {
|
|
417
|
+
days.push(createDayRangeState(props, base, day));
|
|
418
|
+
day++;
|
|
419
|
+
}
|
|
420
|
+
return { days };
|
|
421
|
+
}
|
|
422
|
+
function createDaysPending(props, base, days) {
|
|
423
|
+
const daysPending = [];
|
|
424
|
+
const length = 7 - days;
|
|
425
|
+
for (let index = 0; index < length; index++) {
|
|
426
|
+
daysPending.push(createDayRangeState(props, base));
|
|
427
|
+
}
|
|
428
|
+
return daysPending;
|
|
429
|
+
}
|
|
430
|
+
function createNextWeeks(props, base) {
|
|
431
|
+
const weeks = [];
|
|
432
|
+
const { date } = props;
|
|
433
|
+
const dayCount = getDaysOfMonth(date.getFullYear(), date.getMonth());
|
|
434
|
+
let days = [];
|
|
435
|
+
let countDays = 1;
|
|
436
|
+
let day = DAYS_WEEK - base.getDay() + 1;
|
|
437
|
+
do {
|
|
438
|
+
days.push(createDayRangeState(props, date, day));
|
|
439
|
+
day++;
|
|
440
|
+
countDays++;
|
|
441
|
+
if (countDays > 7) {
|
|
442
|
+
weeks.push({ days });
|
|
443
|
+
days = [];
|
|
444
|
+
countDays = 1;
|
|
445
|
+
}
|
|
446
|
+
} while (day <= dayCount);
|
|
447
|
+
if (days.length && days.length < DAYS_WEEK) {
|
|
448
|
+
weeks.push({
|
|
449
|
+
days: [...days, ...createDaysPending(props, base, days.length)]
|
|
450
|
+
});
|
|
451
|
+
}
|
|
452
|
+
return weeks;
|
|
453
|
+
}
|
|
454
|
+
function dayRangeIsOutsideMin(props, day) {
|
|
455
|
+
const { date, minDate } = props;
|
|
456
|
+
return minDate
|
|
457
|
+
? getDateWeight(assignDayInDate(date, day)) < getDateWeight(minDate)
|
|
458
|
+
: false;
|
|
459
|
+
}
|
|
460
|
+
function dayRangeIsOutsideMax(props, day) {
|
|
461
|
+
const { date, maxDate } = props;
|
|
462
|
+
return maxDate
|
|
463
|
+
? getDateWeight(assignDayInDate(date, day)) > getDateWeight(maxDate)
|
|
464
|
+
: false;
|
|
465
|
+
}
|
|
466
|
+
function dayRangeIsOutside(props, day) {
|
|
467
|
+
return dayRangeIsOutsideMin(props, day) || dayRangeIsOutsideMax(props, day);
|
|
468
|
+
}
|
|
469
|
+
function createDayRangePicker(props) {
|
|
470
|
+
const date = new Date(props.date.getFullYear(), props.date.getMonth(), 1);
|
|
471
|
+
const firstWeek = createFirstWeek(props, date);
|
|
472
|
+
const nextWeeks = createNextWeeks(props, date);
|
|
473
|
+
return [firstWeek, ...nextWeeks];
|
|
474
|
+
}
|
|
475
|
+
|
|
476
|
+
function createMonthState(props, value) {
|
|
477
|
+
const { date, month, year } = props;
|
|
478
|
+
return {
|
|
479
|
+
disabled: monthIsOutside(props, value),
|
|
480
|
+
focused: value === month,
|
|
481
|
+
label: MONTH_NAMES()[value],
|
|
482
|
+
selected: date.getFullYear() === year && value === date.getMonth(),
|
|
483
|
+
value
|
|
484
|
+
};
|
|
485
|
+
}
|
|
486
|
+
function monthIsOutsideMin(props, month) {
|
|
487
|
+
const { year, minDate } = props;
|
|
488
|
+
return minDate
|
|
489
|
+
? minDate.getFullYear() === year && month < minDate.getMonth()
|
|
490
|
+
: false;
|
|
491
|
+
}
|
|
492
|
+
function monthIsOutsideMax(props, month) {
|
|
493
|
+
const { year, maxDate } = props;
|
|
494
|
+
return maxDate
|
|
495
|
+
? maxDate.getFullYear() === year && month > maxDate.getMonth()
|
|
496
|
+
: false;
|
|
497
|
+
}
|
|
498
|
+
function monthIsOutside(props, month) {
|
|
499
|
+
return monthIsOutsideMin(props, month) || monthIsOutsideMax(props, month);
|
|
500
|
+
}
|
|
501
|
+
function checkMonthPicker(props) {
|
|
502
|
+
const { maxDate, minDate, month } = props;
|
|
503
|
+
return minDate && monthIsOutsideMin(props, month)
|
|
504
|
+
? minDate.getMonth()
|
|
505
|
+
: maxDate && monthIsOutsideMax(props, month)
|
|
506
|
+
? maxDate.getMonth()
|
|
507
|
+
: undefined;
|
|
508
|
+
}
|
|
509
|
+
function createMonthPicker(props) {
|
|
510
|
+
return [
|
|
511
|
+
createMonthState(props, Month.January),
|
|
512
|
+
createMonthState(props, Month.February),
|
|
513
|
+
createMonthState(props, Month.March),
|
|
514
|
+
createMonthState(props, Month.April),
|
|
515
|
+
createMonthState(props, Month.May),
|
|
516
|
+
createMonthState(props, Month.June),
|
|
517
|
+
createMonthState(props, Month.July),
|
|
518
|
+
createMonthState(props, Month.August),
|
|
519
|
+
createMonthState(props, Month.September),
|
|
520
|
+
createMonthState(props, Month.October),
|
|
521
|
+
createMonthState(props, Month.November),
|
|
522
|
+
createMonthState(props, Month.December)
|
|
523
|
+
];
|
|
524
|
+
}
|
|
525
|
+
function monthIsLimitMin(props) {
|
|
526
|
+
const { month, date, minDate } = props;
|
|
527
|
+
if (itIsDefined(month) && date) {
|
|
528
|
+
const minYear = minDate ? minDate.getFullYear() : 0;
|
|
529
|
+
const minMonth = minDate ? minDate.getMonth() : 0;
|
|
530
|
+
return date.getFullYear() === minYear && month <= minMonth;
|
|
531
|
+
}
|
|
532
|
+
return false;
|
|
533
|
+
}
|
|
534
|
+
function monthIsLimitMax(props) {
|
|
535
|
+
const { month, date, maxDate } = props;
|
|
536
|
+
if (itIsDefined(month) && date) {
|
|
537
|
+
const maxYear = maxDate ? maxDate.getFullYear() : 10000;
|
|
538
|
+
const maxMonth = maxDate ? maxDate.getMonth() : 11;
|
|
539
|
+
return date.getFullYear() === maxYear && month >= maxMonth;
|
|
540
|
+
}
|
|
541
|
+
return false;
|
|
542
|
+
}
|
|
543
|
+
function monthLimitTemplate(props) {
|
|
544
|
+
return {
|
|
545
|
+
limitNext: monthIsLimitMax(props),
|
|
546
|
+
limitPrevious: monthIsLimitMin(props)
|
|
547
|
+
};
|
|
548
|
+
}
|
|
549
|
+
|
|
550
|
+
var PickerListenerType;
|
|
551
|
+
(function (PickerListenerType) {
|
|
552
|
+
PickerListenerType["Select"] = "PickerSelect";
|
|
553
|
+
PickerListenerType["Now"] = "PickerNow";
|
|
554
|
+
PickerListenerType["Cancel"] = "PickerCancel";
|
|
555
|
+
})(PickerListenerType || (PickerListenerType = {}));
|
|
556
|
+
|
|
557
|
+
function createYear(props, value) {
|
|
558
|
+
const { date, year } = props;
|
|
559
|
+
return {
|
|
560
|
+
disabled: !value,
|
|
561
|
+
focused: value === year,
|
|
562
|
+
selected: value === date.getFullYear(),
|
|
563
|
+
value
|
|
564
|
+
};
|
|
565
|
+
}
|
|
566
|
+
function yearIsOutlineMin(props) {
|
|
567
|
+
const { year, minDate } = props;
|
|
568
|
+
return minDate ? year < minDate.getFullYear() : false;
|
|
569
|
+
}
|
|
570
|
+
function yearIsOutlineMax(props) {
|
|
571
|
+
const { year, maxDate } = props;
|
|
572
|
+
return maxDate ? year > maxDate.getFullYear() : false;
|
|
573
|
+
}
|
|
574
|
+
function checkYearPicker(props) {
|
|
575
|
+
const { maxDate, minDate } = props;
|
|
576
|
+
return minDate && yearIsOutlineMin(props)
|
|
577
|
+
? minDate.getFullYear()
|
|
578
|
+
: maxDate && yearIsOutlineMax(props)
|
|
579
|
+
? maxDate.getFullYear()
|
|
580
|
+
: undefined;
|
|
581
|
+
}
|
|
582
|
+
function createYearPicker(props) {
|
|
583
|
+
const { year, maxDate, minDate } = props;
|
|
584
|
+
const prevYears = [];
|
|
585
|
+
const nextYears = [];
|
|
586
|
+
let minRange = year;
|
|
587
|
+
let maxRange = year;
|
|
588
|
+
const minYear = minDate?.getFullYear() || 0;
|
|
589
|
+
const maxYear = maxDate?.getFullYear() || 10000;
|
|
590
|
+
for (let index = 0; index < COUNT_YEAR_RANGE; index++) {
|
|
591
|
+
const prevValue = year - COUNT_YEAR_RANGE + index;
|
|
592
|
+
const nextValue = year + index + 1;
|
|
593
|
+
const prevYear = prevValue >= minYear ? prevValue : undefined;
|
|
594
|
+
const nextYear = nextValue <= maxYear ? nextValue : undefined;
|
|
595
|
+
const prevState = createYear(props, prevYear);
|
|
596
|
+
const nextState = createYear(props, nextYear);
|
|
597
|
+
prevYears.push(prevState);
|
|
598
|
+
nextYears.push(nextState);
|
|
599
|
+
if (!!prevState.value && minRange > prevState.value) {
|
|
600
|
+
minRange = prevState.value;
|
|
601
|
+
}
|
|
602
|
+
if (!!nextState.value && maxRange < nextState.value) {
|
|
603
|
+
maxRange = nextState.value;
|
|
604
|
+
}
|
|
605
|
+
}
|
|
606
|
+
const yearCenter = createYear(props, year);
|
|
607
|
+
return {
|
|
608
|
+
canPrevious: minYear < minRange,
|
|
609
|
+
canNext: maxYear > maxRange,
|
|
610
|
+
maxRange,
|
|
611
|
+
minRange,
|
|
612
|
+
years: [...prevYears, yearCenter, ...nextYears]
|
|
613
|
+
};
|
|
614
|
+
}
|
|
615
|
+
|
|
616
|
+
function createEmptyStore() {
|
|
617
|
+
return {
|
|
618
|
+
coincidences: undefined,
|
|
619
|
+
pattern: '',
|
|
620
|
+
previous: null
|
|
621
|
+
};
|
|
622
|
+
}
|
|
623
|
+
function searchForPattern(props) {
|
|
624
|
+
const { pattern, store } = props;
|
|
625
|
+
if (!store?.pattern) {
|
|
626
|
+
return null;
|
|
627
|
+
}
|
|
628
|
+
let newStore = store;
|
|
629
|
+
let search = false;
|
|
630
|
+
while (!search && newStore) {
|
|
631
|
+
search = hasPattern(pattern || '', newStore.pattern, true);
|
|
632
|
+
if (!search) {
|
|
633
|
+
newStore = newStore.previous;
|
|
634
|
+
}
|
|
635
|
+
}
|
|
636
|
+
return newStore || createEmptyStore();
|
|
637
|
+
}
|
|
638
|
+
function createStoreAutocomplete(props) {
|
|
639
|
+
const { pattern, suggestions, reboot } = props;
|
|
640
|
+
if (!pattern) {
|
|
641
|
+
return { collection: suggestions, store: createEmptyStore() };
|
|
642
|
+
}
|
|
643
|
+
const store = reboot ? createEmptyStore() : searchForPattern(props);
|
|
644
|
+
const elements = store?.coincidences || suggestions;
|
|
645
|
+
const coincidences = elements.filter((element) => element.hasCoincidence(pattern));
|
|
646
|
+
return {
|
|
647
|
+
collection: coincidences,
|
|
648
|
+
store: {
|
|
649
|
+
coincidences,
|
|
650
|
+
pattern,
|
|
651
|
+
previous: store
|
|
652
|
+
}
|
|
653
|
+
};
|
|
654
|
+
}
|
|
655
|
+
|
|
656
|
+
const classElement = '.rls-list-field__element';
|
|
657
|
+
const POSITION_INITIAL = 0;
|
|
658
|
+
function locationListIsBottom(contentElement, listElement) {
|
|
659
|
+
if (contentElement && listElement) {
|
|
660
|
+
const { top, height } = contentElement.getBoundingClientRect();
|
|
661
|
+
const { clientHeight } = listElement;
|
|
662
|
+
return top + height + clientHeight < window.innerHeight;
|
|
663
|
+
}
|
|
664
|
+
return true;
|
|
665
|
+
}
|
|
666
|
+
function navigationInputDown(props) {
|
|
667
|
+
const { contentElement, listElement } = props;
|
|
668
|
+
if (!locationListIsBottom(contentElement, listElement)) {
|
|
669
|
+
return undefined;
|
|
670
|
+
}
|
|
671
|
+
const elements = listElement?.querySelectorAll(classElement);
|
|
672
|
+
if (elements?.length) {
|
|
673
|
+
elements.item(0).focus();
|
|
674
|
+
setTimeout(() => {
|
|
675
|
+
listElement?.scroll({ top: 0, behavior: 'smooth' });
|
|
676
|
+
}, 100);
|
|
677
|
+
}
|
|
678
|
+
return POSITION_INITIAL;
|
|
679
|
+
}
|
|
680
|
+
function navigationInputUp(props) {
|
|
681
|
+
const { contentElement, listElement } = props;
|
|
682
|
+
if (locationListIsBottom(contentElement, listElement)) {
|
|
683
|
+
return undefined;
|
|
684
|
+
}
|
|
685
|
+
const elements = listElement?.querySelectorAll(classElement);
|
|
686
|
+
if (!elements?.length) {
|
|
687
|
+
return POSITION_INITIAL;
|
|
688
|
+
}
|
|
689
|
+
const position = elements.length - 1;
|
|
690
|
+
const element = elements.item(position);
|
|
691
|
+
element?.focus();
|
|
692
|
+
setTimeout(() => {
|
|
693
|
+
listElement?.scroll({
|
|
694
|
+
top: element?.offsetTop + element?.offsetLeft,
|
|
695
|
+
behavior: 'smooth'
|
|
696
|
+
});
|
|
697
|
+
}, 100);
|
|
698
|
+
return position;
|
|
699
|
+
}
|
|
700
|
+
function navigationElementDown(props) {
|
|
701
|
+
const { contentElement, inputElement, listElement, position } = props;
|
|
702
|
+
const elements = listElement?.querySelectorAll(classElement);
|
|
703
|
+
const newPosition = position + 1;
|
|
704
|
+
if (newPosition < (elements?.length || 0)) {
|
|
705
|
+
elements?.item(newPosition)?.focus();
|
|
706
|
+
return newPosition;
|
|
707
|
+
}
|
|
708
|
+
if (!locationListIsBottom(contentElement, listElement)) {
|
|
709
|
+
inputElement?.focus();
|
|
710
|
+
}
|
|
711
|
+
return position;
|
|
712
|
+
}
|
|
713
|
+
function navigationElementUp(props) {
|
|
714
|
+
const { contentElement, inputElement, listElement, position } = props;
|
|
715
|
+
if (position > 0) {
|
|
716
|
+
const elements = listElement?.querySelectorAll(classElement);
|
|
717
|
+
const newPosition = position - 1;
|
|
718
|
+
elements?.item(newPosition)?.focus();
|
|
719
|
+
return newPosition;
|
|
720
|
+
}
|
|
721
|
+
if (locationListIsBottom(contentElement, listElement)) {
|
|
722
|
+
inputElement?.focus();
|
|
723
|
+
}
|
|
724
|
+
return POSITION_INITIAL;
|
|
725
|
+
}
|
|
726
|
+
function listNavigationInput(props) {
|
|
727
|
+
switch (props.event.code) {
|
|
728
|
+
case 'ArrowDown':
|
|
729
|
+
return navigationInputDown(props);
|
|
730
|
+
case 'ArrowUp':
|
|
731
|
+
return navigationInputUp(props);
|
|
732
|
+
default:
|
|
733
|
+
return undefined;
|
|
734
|
+
}
|
|
735
|
+
}
|
|
736
|
+
function listNavigationElement(props) {
|
|
737
|
+
const { event } = props;
|
|
738
|
+
switch (event.code) {
|
|
739
|
+
case 'ArrowDown':
|
|
740
|
+
return navigationElementDown(props);
|
|
741
|
+
case 'ArrowUp':
|
|
742
|
+
return navigationElementUp(props);
|
|
743
|
+
default:
|
|
744
|
+
return POSITION_INITIAL;
|
|
745
|
+
}
|
|
346
746
|
}
|
|
347
|
-
|
|
348
|
-
|
|
747
|
+
|
|
748
|
+
class ListCollection {
|
|
749
|
+
constructor(value) {
|
|
750
|
+
this.value = value;
|
|
751
|
+
}
|
|
752
|
+
find(element) {
|
|
753
|
+
return this.value.find((current) => current.compareTo(element));
|
|
754
|
+
}
|
|
349
755
|
}
|
|
350
756
|
|
|
351
|
-
function RlsDayPicker({ date, disabled: disabledPicker, formControl, maxDate, minDate, rlsTheme,
|
|
352
|
-
const
|
|
353
|
-
const initialDay = formControl?.state || initialDate.getDate();
|
|
757
|
+
function RlsDayPicker({ date, disabled: disabledPicker, formControl, maxDate, month, minDate, onValue, rlsTheme, year }) {
|
|
758
|
+
const currentDate = date || new Date(); // Initial date
|
|
354
759
|
const [weeks, setWeeks] = useState([]);
|
|
355
|
-
const [value, setValue] = useState(
|
|
760
|
+
const [value, setValue] = useState(formControl?.state || currentDate.getDate());
|
|
356
761
|
useEffect(() => {
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
762
|
+
const props = createPickerProps();
|
|
763
|
+
const day = checkDayPicker(props);
|
|
764
|
+
day ? setDayValue(day) : setWeeks(createDayPicker(props));
|
|
765
|
+
}, [date, month, year, value, minDate, maxDate]);
|
|
766
|
+
useEffect(() => {
|
|
767
|
+
const day = checkDayPicker(createPickerProps());
|
|
768
|
+
day
|
|
769
|
+
? formControl?.setState(day)
|
|
770
|
+
: setValue(formControl?.state || currentDate.getDate());
|
|
771
|
+
}, [formControl?.state]);
|
|
772
|
+
function createPickerProps() {
|
|
773
|
+
return {
|
|
774
|
+
date: currentDate,
|
|
775
|
+
day: formControl?.state || value,
|
|
776
|
+
month: itIsDefined(month) ? month : currentDate.getMonth(),
|
|
777
|
+
year: year || currentDate.getFullYear(),
|
|
360
778
|
minDate,
|
|
361
779
|
maxDate
|
|
362
|
-
}
|
|
363
|
-
}
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
}
|
|
368
|
-
}, [date]);
|
|
780
|
+
};
|
|
781
|
+
}
|
|
782
|
+
function setDayValue(value) {
|
|
783
|
+
formControl ? formControl.setState(value) : setValue(value);
|
|
784
|
+
}
|
|
369
785
|
function onChange(value) {
|
|
370
|
-
|
|
371
|
-
formControl?.setState(value);
|
|
786
|
+
setDayValue(value);
|
|
372
787
|
if (onValue) {
|
|
373
788
|
onValue(value);
|
|
374
789
|
}
|
|
375
790
|
}
|
|
376
|
-
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', {
|
|
791
|
+
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, focused, forbidden, selected, today }, index) => (jsx("div", { className: renderClassStatus('rls-day-picker__day', {
|
|
377
792
|
disabled: disabled || disabledPicker,
|
|
793
|
+
focused,
|
|
378
794
|
forbidden,
|
|
379
|
-
selected
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
onChange(value);
|
|
383
|
-
}
|
|
384
|
-
}, children: jsx("span", { className: "rls-day-picker__day__span", children: value || '??' }) }, index))) }, index))) })] }));
|
|
795
|
+
selected,
|
|
796
|
+
today
|
|
797
|
+
}), onClick: value && !disabledPicker ? () => onChange(value) : undefined, children: jsx("span", { className: "rls-day-picker__day__span", children: value || '??' }) }, index))) }, index))) })] }));
|
|
385
798
|
}
|
|
386
799
|
|
|
387
800
|
const DATE_RANGE_FORMAT = '{dd}/{mx}/{aa}';
|
|
388
|
-
class DateRangePickerFactory {
|
|
389
|
-
constructor(props) {
|
|
390
|
-
const { date, range, sourceDate, maxDate, minDate } = props;
|
|
391
|
-
this.date = new Date(date.getTime());
|
|
392
|
-
this.range = range;
|
|
393
|
-
this.sourceDate = sourceDate;
|
|
394
|
-
this.maxDate = maxDate;
|
|
395
|
-
this.minDate = minDate;
|
|
396
|
-
this.date.setDate(1);
|
|
397
|
-
}
|
|
398
|
-
static execute(props) {
|
|
399
|
-
const factory = new DateRangePickerFactory(props);
|
|
400
|
-
const firstWeek = factory.createFirstWeek();
|
|
401
|
-
const rightWeeks = factory.createRightWeeks();
|
|
402
|
-
return [firstWeek, ...rightWeeks];
|
|
403
|
-
}
|
|
404
|
-
createFirstWeek() {
|
|
405
|
-
const dayStart = this.date.getDay();
|
|
406
|
-
const days = [];
|
|
407
|
-
let day = 1;
|
|
408
|
-
for (let start = 0; start < dayStart; start++) {
|
|
409
|
-
days.push(this.createDayRangeState());
|
|
410
|
-
}
|
|
411
|
-
for (let end = dayStart; end < 7; end++) {
|
|
412
|
-
days.push(this.createDayRangeState(day));
|
|
413
|
-
day++;
|
|
414
|
-
}
|
|
415
|
-
return { days };
|
|
416
|
-
}
|
|
417
|
-
createRightWeeks() {
|
|
418
|
-
const rightWeeks = [];
|
|
419
|
-
const dayStart = this.date.getDay();
|
|
420
|
-
const dayCount = daysFromMonth(this.date.getFullYear(), this.date.getMonth());
|
|
421
|
-
let days = [];
|
|
422
|
-
let countDaysWeek = 1;
|
|
423
|
-
let day = 8 - dayStart;
|
|
424
|
-
do {
|
|
425
|
-
days.push(this.createDayRangeState(day));
|
|
426
|
-
day++;
|
|
427
|
-
countDaysWeek++;
|
|
428
|
-
if (countDaysWeek > 7) {
|
|
429
|
-
rightWeeks.push({ days });
|
|
430
|
-
days = [];
|
|
431
|
-
countDaysWeek = 1;
|
|
432
|
-
}
|
|
433
|
-
} while (day <= dayCount);
|
|
434
|
-
const daysPending = this.createDaysPending(days.length);
|
|
435
|
-
rightWeeks.push({ days: [...days, ...daysPending] });
|
|
436
|
-
return rightWeeks;
|
|
437
|
-
}
|
|
438
|
-
createDaysPending(daysWeek) {
|
|
439
|
-
const daysPending = [];
|
|
440
|
-
const length = 7 - daysWeek;
|
|
441
|
-
for (let index = 0; index < length; index++) {
|
|
442
|
-
daysPending.push(this.createDayRangeState());
|
|
443
|
-
}
|
|
444
|
-
return daysPending;
|
|
445
|
-
}
|
|
446
|
-
isSelectedSource(day) {
|
|
447
|
-
return this.isSelectedForDate(this.sourceDate, day);
|
|
448
|
-
}
|
|
449
|
-
isSelectedEnd(day) {
|
|
450
|
-
return (this.isSelectedForDate(this.range.minDate, day) ||
|
|
451
|
-
this.isSelectedForDate(this.range.maxDate, day));
|
|
452
|
-
}
|
|
453
|
-
isSelectedForDate(date, day) {
|
|
454
|
-
return (date.getFullYear() === this.date.getFullYear() &&
|
|
455
|
-
date.getMonth() === this.date.getMonth() &&
|
|
456
|
-
day === date.getDate());
|
|
457
|
-
}
|
|
458
|
-
isRangedFromDate(day) {
|
|
459
|
-
return between(this.range.minDate, this.range.maxDate, assignDay(this.date, day));
|
|
460
|
-
}
|
|
461
|
-
overflowDay(day) {
|
|
462
|
-
return this.minOverflowDay(day) || this.maxOverflowDay(day);
|
|
463
|
-
}
|
|
464
|
-
minOverflowDay(day) {
|
|
465
|
-
return this.minDate
|
|
466
|
-
? weight(assignDay(this.date, day)) < weight(this.minDate)
|
|
467
|
-
: false;
|
|
468
|
-
}
|
|
469
|
-
maxOverflowDay(day) {
|
|
470
|
-
return this.maxDate
|
|
471
|
-
? weight(assignDay(this.date, day)) > weight(this.maxDate)
|
|
472
|
-
: false;
|
|
473
|
-
}
|
|
474
|
-
createDayRangeState(day) {
|
|
475
|
-
return {
|
|
476
|
-
value: day,
|
|
477
|
-
disabled: this.overflowDay(day || 0),
|
|
478
|
-
forbidden: !day,
|
|
479
|
-
ranged: day ? this.isRangedFromDate(day) : false,
|
|
480
|
-
end: day ? this.isSelectedEnd(day) : false,
|
|
481
|
-
source: day ? this.isSelectedSource(day) : false
|
|
482
|
-
};
|
|
483
|
-
}
|
|
484
|
-
}
|
|
485
|
-
function formatRange(range) {
|
|
486
|
-
const minFormat = formatDate(range.minDate, DATE_RANGE_FORMAT);
|
|
487
|
-
const maxFormat = formatDate(range.maxDate, DATE_RANGE_FORMAT);
|
|
488
|
-
return `${minFormat} - ${maxFormat}`;
|
|
489
|
-
}
|
|
490
|
-
function createRangePicker(props) {
|
|
491
|
-
return DateRangePickerFactory.execute(props);
|
|
492
|
-
}
|
|
493
801
|
|
|
494
802
|
function RlsDayRangePicker({ date, disabled: disabledPicker, formControl, maxDate, minDate, rlsTheme }) {
|
|
495
|
-
const
|
|
496
|
-
const
|
|
497
|
-
const sourceDate = useRef(
|
|
803
|
+
const currentRange = formControl?.state || DateRange.now();
|
|
804
|
+
const currentDate = normalizeMinTime(date || currentRange.minDate);
|
|
805
|
+
const sourceDate = useRef(currentRange.minDate);
|
|
498
806
|
const [weeks, setWeeks] = useState([]);
|
|
499
|
-
const [range, setRange] = useState(
|
|
807
|
+
const [range, setRange] = useState(currentRange);
|
|
500
808
|
useEffect(() => {
|
|
501
|
-
setWeeks(
|
|
502
|
-
date:
|
|
809
|
+
setWeeks(createDayRangePicker({
|
|
810
|
+
date: currentDate,
|
|
503
811
|
range,
|
|
504
812
|
sourceDate: sourceDate.current,
|
|
505
813
|
minDate,
|
|
@@ -507,25 +815,21 @@ function RlsDayRangePicker({ date, disabled: disabledPicker, formControl, maxDat
|
|
|
507
815
|
}));
|
|
508
816
|
}, [range, date, minDate, maxDate]);
|
|
509
817
|
function onChange(value) {
|
|
510
|
-
const
|
|
511
|
-
const
|
|
512
|
-
? new DateRange(sourceDate.current,
|
|
513
|
-
: new DateRange(
|
|
514
|
-
sourceDate.current =
|
|
515
|
-
setRange(
|
|
516
|
-
formControl?.setState(
|
|
517
|
-
}
|
|
518
|
-
return (jsxs("div", { className: "rls-day-range-picker", "rls-theme": rlsTheme, children: [jsx("div", { className: "rls-day-range-picker__title", children:
|
|
818
|
+
const date = assignDayInDate(currentDate, value);
|
|
819
|
+
const range = dateIsBefore(date, sourceDate.current)
|
|
820
|
+
? new DateRange(sourceDate.current, date)
|
|
821
|
+
: new DateRange(date, sourceDate.current);
|
|
822
|
+
sourceDate.current = date;
|
|
823
|
+
setRange(range);
|
|
824
|
+
formControl?.setState(range);
|
|
825
|
+
}
|
|
826
|
+
return (jsxs("div", { className: "rls-day-range-picker", "rls-theme": rlsTheme, children: [jsx("div", { className: "rls-day-range-picker__title", children: dateFormatTemplate(sourceDate.current, DATE_RANGE_FORMAT) }), 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(({ disabled, end, forbidden, source, ranged, value }, index) => (jsx("div", { className: renderClassStatus('rls-day-range-picker__day', {
|
|
519
827
|
disabled: disabled || disabledPicker,
|
|
520
828
|
end,
|
|
521
829
|
forbidden,
|
|
522
830
|
ranged,
|
|
523
831
|
source
|
|
524
|
-
}), onClick: () => {
|
|
525
|
-
if (value && !disabled) {
|
|
526
|
-
onChange(value);
|
|
527
|
-
}
|
|
528
|
-
}, children: jsx("span", { className: "rls-day-range-picker__day__span", children: value || '??' }) }, index))) }, index))) })] }));
|
|
832
|
+
}), onClick: value && !disabledPicker ? () => onChange(value) : undefined, children: jsx("span", { className: "rls-day-range-picker__day__span", children: value || '??' }) }, index))) }, index))) })] }));
|
|
529
833
|
}
|
|
530
834
|
|
|
531
835
|
function RlsMoneyField({ children, decimals, disabled, formControl, placeholder, symbol, rlsTheme, value, onValue }) {
|
|
@@ -536,156 +840,93 @@ function RlsMoneyField({ children, decimals, disabled, formControl, placeholder,
|
|
|
536
840
|
}, '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 }) }))] }));
|
|
537
841
|
}
|
|
538
842
|
|
|
539
|
-
|
|
540
|
-
const
|
|
541
|
-
class MonthPickerFactory {
|
|
542
|
-
constructor(props) {
|
|
543
|
-
const { date, value, maxDate, minDate } = props;
|
|
544
|
-
this.value = value;
|
|
545
|
-
this.date = new Date(date.getTime());
|
|
546
|
-
this.maxDate = maxDate;
|
|
547
|
-
this.minDate = minDate;
|
|
548
|
-
}
|
|
549
|
-
static execute(props) {
|
|
550
|
-
const factory = new MonthPickerFactory(props);
|
|
551
|
-
return [
|
|
552
|
-
factory.createMonth(Month.January),
|
|
553
|
-
factory.createMonth(Month.February),
|
|
554
|
-
factory.createMonth(Month.March),
|
|
555
|
-
factory.createMonth(Month.April),
|
|
556
|
-
factory.createMonth(Month.May),
|
|
557
|
-
factory.createMonth(Month.June),
|
|
558
|
-
factory.createMonth(Month.July),
|
|
559
|
-
factory.createMonth(Month.August),
|
|
560
|
-
factory.createMonth(Month.September),
|
|
561
|
-
factory.createMonth(Month.October),
|
|
562
|
-
factory.createMonth(Month.November),
|
|
563
|
-
factory.createMonth(Month.December)
|
|
564
|
-
];
|
|
565
|
-
}
|
|
566
|
-
createMonth(value) {
|
|
567
|
-
return {
|
|
568
|
-
value,
|
|
569
|
-
label: MONTH_NAMES()[value],
|
|
570
|
-
disabled: this.overflowMonth(value),
|
|
571
|
-
selected: value === this.value
|
|
572
|
-
};
|
|
573
|
-
}
|
|
574
|
-
get minYear() {
|
|
575
|
-
return this.minDate?.getFullYear() || 0;
|
|
576
|
-
}
|
|
577
|
-
get maxYear() {
|
|
578
|
-
return this.maxDate?.getFullYear() || 10000;
|
|
579
|
-
}
|
|
580
|
-
get minMonth() {
|
|
581
|
-
return this.minDate ? this.minDate.getMonth() : MONTH_MIN_VALUE;
|
|
582
|
-
}
|
|
583
|
-
get maxMonth() {
|
|
584
|
-
return this.maxDate ? this.maxDate.getMonth() : MONTH_MAX_VALUE;
|
|
585
|
-
}
|
|
586
|
-
overflowMonth(month) {
|
|
587
|
-
return this.minOverflowMonth(month) || this.maxOverflowMonth(month);
|
|
588
|
-
}
|
|
589
|
-
minOverflowMonth(month) {
|
|
590
|
-
return this.date.getFullYear() === this.minYear && month < this.minMonth;
|
|
591
|
-
}
|
|
592
|
-
maxOverflowMonth(month) {
|
|
593
|
-
return this.date.getFullYear() === this.maxYear && month > this.maxMonth;
|
|
594
|
-
}
|
|
595
|
-
}
|
|
596
|
-
function isMinLimitMonth(month, date, minDate) {
|
|
597
|
-
if (typeof month === 'number' && date) {
|
|
598
|
-
const minMonth = minDate ? minDate.getMonth() : MONTH_MIN_VALUE;
|
|
599
|
-
const minYear = minDate ? minDate.getFullYear() : 0;
|
|
600
|
-
return date.getFullYear() === minYear && month <= minMonth;
|
|
601
|
-
}
|
|
602
|
-
return false;
|
|
603
|
-
}
|
|
604
|
-
function isMaxLimitMonth(month, date, maxDate) {
|
|
605
|
-
if (typeof month === 'number' && date) {
|
|
606
|
-
const maxMonth = maxDate ? maxDate.getMonth() : MONTH_MAX_VALUE;
|
|
607
|
-
const maxYear = maxDate ? maxDate.getFullYear() : 10000;
|
|
608
|
-
return date.getFullYear() === maxYear && month >= maxMonth;
|
|
609
|
-
}
|
|
610
|
-
return false;
|
|
611
|
-
}
|
|
612
|
-
function createMonthPicker(props) {
|
|
613
|
-
return MonthPickerFactory.execute(props);
|
|
614
|
-
}
|
|
615
|
-
|
|
616
|
-
function RlsMonthPicker({ formControl, date, disabled: disabledPicker, maxDate, minDate, rlsTheme, onValue }) {
|
|
617
|
-
const initialDate = date || new Date();
|
|
618
|
-
const initialMonth = formControl?.state || initialDate.getMonth();
|
|
843
|
+
function RlsMonthPicker({ date, disabled: disabledPicker, formControl, maxDate, minDate, onValue, rlsTheme, year }) {
|
|
844
|
+
const currentDate = date || new Date();
|
|
619
845
|
const [months, setMonths] = useState([]);
|
|
620
|
-
const [value, setValue] = useState(
|
|
846
|
+
const [value, setValue] = useState(formControl?.state || currentDate.getMonth());
|
|
621
847
|
useEffect(() => {
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
848
|
+
const props = createPickerProps(); // MonthPickerProps
|
|
849
|
+
const month = checkMonthPicker(props);
|
|
850
|
+
month ? setMonthValue(month) : setMonths(createMonthPicker(props));
|
|
851
|
+
}, [date, year, value, minDate, maxDate]);
|
|
852
|
+
useEffect(() => {
|
|
853
|
+
const month = checkMonthPicker(createPickerProps());
|
|
854
|
+
itIsDefined(month)
|
|
855
|
+
? formControl?.setState(month)
|
|
856
|
+
: setValue(formControl?.state || currentDate.getMonth());
|
|
857
|
+
}, [formControl?.state]);
|
|
858
|
+
function createPickerProps() {
|
|
859
|
+
return {
|
|
860
|
+
date: currentDate,
|
|
861
|
+
month: itIsDefined(formControl?.state) ? formControl?.state : value,
|
|
862
|
+
year: year || currentDate.getFullYear(),
|
|
625
863
|
minDate,
|
|
626
864
|
maxDate
|
|
627
|
-
}
|
|
628
|
-
}
|
|
865
|
+
};
|
|
866
|
+
}
|
|
867
|
+
function setMonthValue(value) {
|
|
868
|
+
formControl ? formControl.setState(value) : setValue(value);
|
|
869
|
+
}
|
|
629
870
|
function onChange(value) {
|
|
630
|
-
|
|
631
|
-
setValue(value);
|
|
871
|
+
setMonthValue(value);
|
|
632
872
|
if (onValue) {
|
|
633
873
|
onValue(value);
|
|
634
874
|
}
|
|
635
875
|
}
|
|
636
|
-
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', {
|
|
637
|
-
disabled: disabled || disabledPicker
|
|
876
|
+
return (jsx("div", { className: "rls-month-picker", "rls-theme": rlsTheme, children: months.map(({ label, value, disabled, focused, selected }, index) => (jsx("div", { className: renderClassStatus('rls-month-picker__component', {
|
|
877
|
+
disabled: disabled || disabledPicker,
|
|
878
|
+
focused,
|
|
638
879
|
selected
|
|
639
|
-
}), onClick: () => {
|
|
640
|
-
if (!disabled) {
|
|
641
|
-
onChange(value);
|
|
642
|
-
}
|
|
643
|
-
}, children: jsx("span", { className: "rls-month-picker__span", children: label }) }, index))) }));
|
|
880
|
+
}), onClick: !(disabled || disabledPicker) ? () => onChange(value) : undefined, children: jsx("span", { className: "rls-month-picker__span", children: label }) }, index))) }));
|
|
644
881
|
}
|
|
645
882
|
|
|
646
|
-
function RlsMonthTitlePicker({
|
|
647
|
-
const {
|
|
648
|
-
|
|
649
|
-
|
|
883
|
+
function RlsMonthTitlePicker({ monthControl, type, yearControl, date, disabled, maxDate, minDate, onClick }) {
|
|
884
|
+
const { limitNext, limitPrevious } = monthLimitTemplate({
|
|
885
|
+
date,
|
|
886
|
+
maxDate,
|
|
887
|
+
minDate,
|
|
888
|
+
month: monthControl.state
|
|
889
|
+
});
|
|
890
|
+
const monthName = MONTH_NAMES()[monthControl.state || 0];
|
|
650
891
|
function onPreviousMonth() {
|
|
651
|
-
if (
|
|
652
|
-
if (
|
|
653
|
-
monthControl.setState(
|
|
892
|
+
if (itIsDefined(monthControl.state) && itIsDefined(yearControl.state)) {
|
|
893
|
+
if (monthControl.state > Month.January) {
|
|
894
|
+
monthControl.setState(monthControl.state - 1);
|
|
654
895
|
}
|
|
655
896
|
else {
|
|
656
|
-
monthControl.setState(
|
|
657
|
-
yearControl.setState(
|
|
897
|
+
monthControl.setState(Month.December);
|
|
898
|
+
yearControl.setState(yearControl.state - 1);
|
|
658
899
|
}
|
|
659
900
|
}
|
|
660
901
|
}
|
|
661
902
|
function onPreviousYear() {
|
|
662
|
-
if (
|
|
663
|
-
yearControl.setState(
|
|
903
|
+
if (itIsDefined(yearControl.state)) {
|
|
904
|
+
yearControl.setState(yearControl.state - 1);
|
|
664
905
|
}
|
|
665
906
|
}
|
|
666
907
|
function onPrevious() {
|
|
667
908
|
type === 'month' ? onPreviousMonth() : onPreviousYear();
|
|
668
909
|
}
|
|
669
910
|
function onNextMonth() {
|
|
670
|
-
if (
|
|
671
|
-
if (
|
|
672
|
-
monthControl.setState(
|
|
911
|
+
if (itIsDefined(monthControl.state) && itIsDefined(yearControl.state)) {
|
|
912
|
+
if (monthControl.state < Month.December) {
|
|
913
|
+
monthControl.setState(monthControl.state + 1);
|
|
673
914
|
}
|
|
674
915
|
else {
|
|
675
|
-
monthControl.setState(
|
|
676
|
-
yearControl.setState(
|
|
916
|
+
monthControl.setState(Month.January);
|
|
917
|
+
yearControl.setState(yearControl.state + 1);
|
|
677
918
|
}
|
|
678
919
|
}
|
|
679
920
|
}
|
|
680
921
|
function onNextYear() {
|
|
681
|
-
if (
|
|
682
|
-
yearControl.setState(
|
|
922
|
+
if (itIsDefined(yearControl.state)) {
|
|
923
|
+
yearControl.setState(yearControl.state + 1);
|
|
683
924
|
}
|
|
684
925
|
}
|
|
685
926
|
function onNext() {
|
|
686
927
|
type === 'month' ? onNextMonth() : onNextYear();
|
|
687
928
|
}
|
|
688
|
-
return (jsxs("div", { className: "rls-month-title-picker", children: [jsx(RlsButtonAction, { icon: "arrow-ios-left", onClick: onPrevious, disabled:
|
|
929
|
+
return (jsxs("div", { className: "rls-month-title-picker", children: [jsx(RlsButtonAction, { icon: "arrow-ios-left", onClick: onPrevious, disabled: limitPrevious || disabled }), jsx("span", { onClick: onClick, children: monthName }), jsx(RlsButtonAction, { icon: "arrow-ios-right", onClick: onNext, disabled: limitNext || disabled })] }));
|
|
689
930
|
}
|
|
690
931
|
|
|
691
932
|
function RlsNumberField({ children, disabled, formControl, placeholder, rlsTheme, value, onValue }) {
|
|
@@ -965,108 +1206,36 @@ function RlsToolbar({ actions, children, subtitle }) {
|
|
|
965
1206
|
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 smalltext-semibold", children: subtitle }))] }), actions && (jsx("div", { className: "rls-toolbar__actions", children: actions.map((action, index) => (jsx("div", { children: action }, index))) }))] }));
|
|
966
1207
|
}
|
|
967
1208
|
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
year = factory.minYear;
|
|
981
|
-
}
|
|
982
|
-
else if (factory.maxOverflowYear(year)) {
|
|
983
|
-
year = factory.maxYear;
|
|
984
|
-
}
|
|
985
|
-
const years = factory.createYears(year);
|
|
986
|
-
return {
|
|
987
|
-
hasNext: factory.hasNext,
|
|
988
|
-
hasPrevious: factory.hasPrevious,
|
|
989
|
-
maxRange: factory.maxYearRange,
|
|
990
|
-
minRange: factory.minYearRange,
|
|
991
|
-
years
|
|
992
|
-
};
|
|
993
|
-
}
|
|
994
|
-
createYears(year) {
|
|
995
|
-
const prevYears = [];
|
|
996
|
-
const nextYears = [];
|
|
997
|
-
this.minYearRange = year;
|
|
998
|
-
this.maxYearRange = year;
|
|
999
|
-
for (let index = 0; index < COUNT_YEAR_RANGE; index++) {
|
|
1000
|
-
const yearPrev = year - COUNT_YEAR_RANGE + index;
|
|
1001
|
-
const yearNext = year + index + 1;
|
|
1002
|
-
const valuePrev = yearPrev >= this.minYear ? yearPrev : undefined;
|
|
1003
|
-
const valueNext = yearNext <= this.maxYear ? yearNext : undefined;
|
|
1004
|
-
const prevState = this.createYear(valuePrev);
|
|
1005
|
-
const nextState = this.createYear(valueNext);
|
|
1006
|
-
prevYears.push(prevState);
|
|
1007
|
-
nextYears.push(nextState);
|
|
1008
|
-
this.recalculateRange(prevState, nextState);
|
|
1009
|
-
}
|
|
1010
|
-
const yearCenter = this.createYear(year);
|
|
1011
|
-
return [...prevYears, yearCenter, ...nextYears];
|
|
1012
|
-
}
|
|
1013
|
-
minOverflowYear(year) {
|
|
1014
|
-
return year < this.minYear;
|
|
1015
|
-
}
|
|
1016
|
-
maxOverflowYear(year) {
|
|
1017
|
-
return year > this.maxYear;
|
|
1018
|
-
}
|
|
1019
|
-
get minYear() {
|
|
1020
|
-
return this.minDate?.getFullYear() || 0;
|
|
1021
|
-
}
|
|
1022
|
-
get maxYear() {
|
|
1023
|
-
return this.maxDate?.getFullYear() || 10000;
|
|
1024
|
-
}
|
|
1025
|
-
get hasPrevious() {
|
|
1026
|
-
return this.minYear < this.minYearRange;
|
|
1027
|
-
}
|
|
1028
|
-
get hasNext() {
|
|
1029
|
-
return this.maxYear > this.maxYearRange;
|
|
1030
|
-
}
|
|
1031
|
-
createYear(value) {
|
|
1032
|
-
return {
|
|
1033
|
-
value,
|
|
1034
|
-
disabled: !value,
|
|
1035
|
-
selected: value === this.value
|
|
1036
|
-
};
|
|
1037
|
-
}
|
|
1038
|
-
recalculateRange(prev, next) {
|
|
1039
|
-
if (!!prev.value && this.minYearRange > prev.value) {
|
|
1040
|
-
this.minYearRange = prev.value;
|
|
1041
|
-
}
|
|
1042
|
-
if (!!next.value && this.maxYearRange < next.value) {
|
|
1043
|
-
this.maxYearRange = next.value;
|
|
1044
|
-
}
|
|
1045
|
-
}
|
|
1046
|
-
}
|
|
1047
|
-
function createYearPicker(props) {
|
|
1048
|
-
return YearPickerFactory.execute(props);
|
|
1049
|
-
}
|
|
1050
|
-
|
|
1051
|
-
function RlsYearPicker({ formControl, date, disabled: disabledPicker, maxDate, minDate, rlsTheme, onValue }) {
|
|
1052
|
-
const initialDate = date || new Date();
|
|
1053
|
-
const initialYear = formControl?.state || initialDate.getFullYear();
|
|
1054
|
-
const [value, setValue] = useState(initialYear);
|
|
1055
|
-
const [year, setYear] = useState(initialYear);
|
|
1056
|
-
const [template, setTemplate] = useState(createYearPicker({
|
|
1057
|
-
value: formControl?.state || value,
|
|
1058
|
-
year: initialYear,
|
|
1059
|
-
minDate,
|
|
1060
|
-
maxDate
|
|
1061
|
-
}));
|
|
1209
|
+
function RlsYearPicker({ date, disabled: disabledPicker, formControl, maxDate, minDate, onValue, rlsTheme }) {
|
|
1210
|
+
const currentDate = date || new Date();
|
|
1211
|
+
const [value, setValue] = useState(formControl?.state || currentDate.getFullYear());
|
|
1212
|
+
const [year, setYear] = useState(formControl?.state || currentDate.getFullYear());
|
|
1213
|
+
const [template, setTemplate] = useState(createYearPicker(createPickerProps()));
|
|
1214
|
+
useEffect(() => {
|
|
1215
|
+
const props = createPickerProps(); // YearPickerProps
|
|
1216
|
+
const year = checkYearPicker(props);
|
|
1217
|
+
year
|
|
1218
|
+
? setYearValue(year)
|
|
1219
|
+
: setTemplate(createYearPicker(createPickerProps()));
|
|
1220
|
+
}, [date, year, value, minDate, maxDate]);
|
|
1062
1221
|
useEffect(() => {
|
|
1063
|
-
|
|
1064
|
-
|
|
1222
|
+
const year = checkYearPicker(createPickerProps());
|
|
1223
|
+
itIsDefined(year)
|
|
1224
|
+
? formControl?.setState(year)
|
|
1225
|
+
: setValue(formControl?.state || currentDate.getFullYear());
|
|
1226
|
+
}, [formControl?.state]);
|
|
1227
|
+
function createPickerProps() {
|
|
1228
|
+
return {
|
|
1229
|
+
date: currentDate,
|
|
1065
1230
|
year,
|
|
1066
1231
|
minDate,
|
|
1067
1232
|
maxDate
|
|
1068
|
-
}
|
|
1069
|
-
}
|
|
1233
|
+
};
|
|
1234
|
+
}
|
|
1235
|
+
function setYearValue(value) {
|
|
1236
|
+
formControl ? formControl.setState(value) : setValue(value);
|
|
1237
|
+
setYear(value);
|
|
1238
|
+
}
|
|
1070
1239
|
function onClickPrev() {
|
|
1071
1240
|
setYear(year - 8);
|
|
1072
1241
|
}
|
|
@@ -1074,21 +1243,16 @@ function RlsYearPicker({ formControl, date, disabled: disabledPicker, maxDate, m
|
|
|
1074
1243
|
setYear(year + 8);
|
|
1075
1244
|
}
|
|
1076
1245
|
function onChange(value) {
|
|
1077
|
-
|
|
1078
|
-
setYear(value);
|
|
1079
|
-
setValue(value);
|
|
1246
|
+
setYearValue(value);
|
|
1080
1247
|
if (onValue) {
|
|
1081
1248
|
onValue(value);
|
|
1082
1249
|
}
|
|
1083
1250
|
}
|
|
1084
|
-
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(
|
|
1251
|
+
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(RlsButtonAction, { icon: "arrow-ios-left", onClick: onClickPrev, disabled: !template.canPrevious || disabledPicker }) }), jsxs("label", { className: "rls-title-bold", children: [template.minRange, " - ", template.maxRange] }), jsx("div", { className: "rls-year-picker__action rls-year-picker__action--next", children: jsx(RlsButtonAction, { icon: "arrow-ios-right", onClick: onClickNext, disabled: !template.canNext || disabledPicker }) })] }), jsx("div", { className: "rls-year-picker__component", children: template.years.map(({ value, disabled, focused, selected }, index) => (jsx("div", { className: renderClassStatus('rls-year-picker__year', {
|
|
1085
1252
|
disabled: disabled || disabledPicker,
|
|
1253
|
+
focused,
|
|
1086
1254
|
selected
|
|
1087
|
-
}), onClick: () => {
|
|
1088
|
-
if (value && !disabled) {
|
|
1089
|
-
onChange(value);
|
|
1090
|
-
}
|
|
1091
|
-
}, children: jsx("span", { className: "rls-year-picker__year__span body1-medium", children: value || '????' }) }, index))) })] }));
|
|
1255
|
+
}), onClick: value && !disabledPicker ? () => onChange(value) : undefined, children: jsx("span", { className: "rls-year-picker__year__span rls-body1-medium", children: value || '????' }) }, index))) })] }));
|
|
1092
1256
|
}
|
|
1093
1257
|
|
|
1094
1258
|
const reactI18n = i18n({
|
|
@@ -1130,23 +1294,7 @@ function useDatatable() {
|
|
|
1130
1294
|
return { bodyRef, scrolleable };
|
|
1131
1295
|
}
|
|
1132
1296
|
|
|
1133
|
-
|
|
1134
|
-
constructor(value) {
|
|
1135
|
-
this.value = value;
|
|
1136
|
-
}
|
|
1137
|
-
find(element) {
|
|
1138
|
-
return this.value.find((current) => current.compareTo(element));
|
|
1139
|
-
}
|
|
1140
|
-
}
|
|
1141
|
-
|
|
1142
|
-
const classElement = '.rls-list-field__element';
|
|
1143
|
-
const MAX_POSITION_VISIBLE = 4;
|
|
1144
|
-
const LIST_SIZE_REM = 16;
|
|
1145
|
-
const ELEMENT_SIZE_REM = 4;
|
|
1146
|
-
const BASE_SIZE_PX = 16;
|
|
1147
|
-
const ELEMENT_SIZE_PX = BASE_SIZE_PX * ELEMENT_SIZE_REM;
|
|
1148
|
-
const MAZ_LIST_SIZE_PX = BASE_SIZE_PX * LIST_SIZE_REM;
|
|
1149
|
-
function useListControl({ suggestions, formControl, higher: withHigher = false }) {
|
|
1297
|
+
function useListControl({ suggestions, formControl }) {
|
|
1150
1298
|
const boxContentRef = useRef(null);
|
|
1151
1299
|
const listRef = useRef(null);
|
|
1152
1300
|
const inputRef = useRef(null);
|
|
@@ -1156,11 +1304,10 @@ function useListControl({ suggestions, formControl, higher: withHigher = false }
|
|
|
1156
1304
|
const [visible, setVisible] = useState(false);
|
|
1157
1305
|
const [higher, setHigher] = useState(false);
|
|
1158
1306
|
const [focused, setFocused] = useState(false);
|
|
1159
|
-
const
|
|
1160
|
-
const [listElements, setListElements] = useState(undefined);
|
|
1307
|
+
const position = useRef(0);
|
|
1161
1308
|
useEffect(() => {
|
|
1162
|
-
function onCloseSuggestions(
|
|
1163
|
-
if (!boxContentRef?.current?.contains(
|
|
1309
|
+
function onCloseSuggestions({ target }) {
|
|
1310
|
+
if (!boxContentRef?.current?.contains(target)) {
|
|
1164
1311
|
setVisible(false);
|
|
1165
1312
|
}
|
|
1166
1313
|
}
|
|
@@ -1173,95 +1320,32 @@ function useListControl({ suggestions, formControl, higher: withHigher = false }
|
|
|
1173
1320
|
if (visible && !opened) {
|
|
1174
1321
|
setOpened(true);
|
|
1175
1322
|
}
|
|
1176
|
-
if (!visible && opened && formControl
|
|
1323
|
+
if (!visible && opened && !!formControl?.touched) {
|
|
1177
1324
|
formControl.touch();
|
|
1178
1325
|
}
|
|
1179
|
-
|
|
1326
|
+
setHigher(!locationListIsBottom(boxContentRef.current, listRef.current));
|
|
1180
1327
|
}, [visible]);
|
|
1181
1328
|
useEffect(() => {
|
|
1182
1329
|
setCollection(new ListCollection(suggestions));
|
|
1183
1330
|
}, [suggestions]);
|
|
1184
|
-
function setLocationList() {
|
|
1185
|
-
if (boxContentRef?.current) {
|
|
1186
|
-
const { top, height } = boxContentRef.current.getBoundingClientRect();
|
|
1187
|
-
const overflow = BASE_SIZE_PX / 2;
|
|
1188
|
-
const positionEnd = top + height + MAZ_LIST_SIZE_PX + overflow;
|
|
1189
|
-
setHigher(positionEnd > window.innerHeight);
|
|
1190
|
-
}
|
|
1191
|
-
}
|
|
1192
1331
|
function navigationInput(event) {
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
|
|
1198
|
-
|
|
1199
|
-
|
|
1200
|
-
if (visible && (withHigher || !higher)) {
|
|
1201
|
-
navigationInputDown();
|
|
1202
|
-
}
|
|
1203
|
-
break;
|
|
1332
|
+
if (visible) {
|
|
1333
|
+
const newPosition = listNavigationInput({
|
|
1334
|
+
contentElement: boxContentRef.current,
|
|
1335
|
+
event: event,
|
|
1336
|
+
listElement: listRef.current
|
|
1337
|
+
});
|
|
1338
|
+
position.current = itIsDefined(newPosition) ? newPosition : 0;
|
|
1204
1339
|
}
|
|
1205
1340
|
}
|
|
1206
1341
|
function navigationElement(event) {
|
|
1207
|
-
|
|
1208
|
-
|
|
1209
|
-
|
|
1210
|
-
|
|
1211
|
-
|
|
1212
|
-
|
|
1213
|
-
|
|
1214
|
-
}
|
|
1215
|
-
}
|
|
1216
|
-
function navigationInputUp() {
|
|
1217
|
-
const elements = listRef?.current?.querySelectorAll(classElement);
|
|
1218
|
-
if (elements?.length) {
|
|
1219
|
-
const newPosition = elements.length - 1;
|
|
1220
|
-
setListElements(elements);
|
|
1221
|
-
setPositionElement(newPosition);
|
|
1222
|
-
elements.item(newPosition).focus();
|
|
1223
|
-
if (positionElement > MAX_POSITION_VISIBLE) {
|
|
1224
|
-
const elementPosition = elements.length - MAX_POSITION_VISIBLE;
|
|
1225
|
-
setTimeout(() => {
|
|
1226
|
-
listRef?.current?.scroll({
|
|
1227
|
-
top: ELEMENT_SIZE_PX * elementPosition,
|
|
1228
|
-
behavior: 'smooth'
|
|
1229
|
-
});
|
|
1230
|
-
}, 100);
|
|
1231
|
-
}
|
|
1232
|
-
}
|
|
1233
|
-
}
|
|
1234
|
-
function navigationInputDown() {
|
|
1235
|
-
const elements = listRef?.current?.querySelectorAll(classElement);
|
|
1236
|
-
if (elements?.length) {
|
|
1237
|
-
setListElements(elements);
|
|
1238
|
-
setPositionElement(0);
|
|
1239
|
-
elements.item(0).focus();
|
|
1240
|
-
setTimeout(() => {
|
|
1241
|
-
listRef?.current?.scroll({ top: 0, behavior: 'smooth' });
|
|
1242
|
-
}, 100);
|
|
1243
|
-
}
|
|
1244
|
-
}
|
|
1245
|
-
function navigationElementUp() {
|
|
1246
|
-
if (positionElement > 0) {
|
|
1247
|
-
const newPosition = positionElement - 1;
|
|
1248
|
-
setPositionElement(newPosition);
|
|
1249
|
-
listElements?.item(newPosition).focus();
|
|
1250
|
-
}
|
|
1251
|
-
else if (withHigher || !higher) {
|
|
1252
|
-
inputRef?.current?.focus();
|
|
1253
|
-
}
|
|
1254
|
-
}
|
|
1255
|
-
function navigationElementDown() {
|
|
1256
|
-
const newPosition = positionElement + 1;
|
|
1257
|
-
const length = listElements?.length || 0;
|
|
1258
|
-
if (newPosition < length) {
|
|
1259
|
-
setPositionElement(newPosition);
|
|
1260
|
-
listElements?.item(newPosition).focus();
|
|
1261
|
-
}
|
|
1262
|
-
else if (higher && !withHigher) {
|
|
1263
|
-
inputRef?.current?.focus();
|
|
1264
|
-
}
|
|
1342
|
+
position.current = listNavigationElement({
|
|
1343
|
+
contentElement: boxContentRef.current,
|
|
1344
|
+
event: event,
|
|
1345
|
+
inputElement: inputRef.current,
|
|
1346
|
+
listElement: listRef.current,
|
|
1347
|
+
position: position.current
|
|
1348
|
+
});
|
|
1265
1349
|
}
|
|
1266
1350
|
return {
|
|
1267
1351
|
boxContentRef,
|
|
@@ -1290,39 +1374,31 @@ function useAutocompleteField({ disabled, formControl, onSelect, onValue, sugges
|
|
|
1290
1374
|
coincidences: [],
|
|
1291
1375
|
previous: null
|
|
1292
1376
|
});
|
|
1293
|
-
const listControl = useListControl({
|
|
1294
|
-
suggestions,
|
|
1295
|
-
formControl,
|
|
1296
|
-
higher: true
|
|
1297
|
-
});
|
|
1377
|
+
const listControl = useListControl({ suggestions, formControl });
|
|
1298
1378
|
const { collection, inputRef, navigationElement, navigationInput, setFocused, setValue, setVisible } = listControl;
|
|
1299
|
-
const
|
|
1379
|
+
const changeInternal = useRef(false);
|
|
1300
1380
|
useEffect(() => filterSuggestions(pattern, true), [suggestions]);
|
|
1301
1381
|
useEffect(() => filterSuggestions(pattern), [pattern]);
|
|
1302
1382
|
useEffect(() => {
|
|
1303
|
-
|
|
1383
|
+
if (changeInternal.current) {
|
|
1384
|
+
changeInternal.current = false;
|
|
1385
|
+
}
|
|
1386
|
+
else {
|
|
1387
|
+
resetState(formControl?.state);
|
|
1388
|
+
}
|
|
1304
1389
|
}, [formControl?.state]);
|
|
1305
1390
|
useEffect(() => resetCollection(collection, formControl?.state), [collection]);
|
|
1306
1391
|
function setFormState(value) {
|
|
1307
|
-
|
|
1308
|
-
|
|
1392
|
+
if (formControl) {
|
|
1393
|
+
changeInternal.current = true;
|
|
1394
|
+
formControl.setState(value);
|
|
1395
|
+
}
|
|
1309
1396
|
}
|
|
1310
1397
|
function resetCollection(collection, state) {
|
|
1311
|
-
|
|
1312
|
-
const element = collection.find(state);
|
|
1313
|
-
if (element) {
|
|
1314
|
-
setValue(element.description);
|
|
1315
|
-
}
|
|
1316
|
-
else {
|
|
1317
|
-
setValue('');
|
|
1318
|
-
}
|
|
1319
|
-
}
|
|
1320
|
-
else {
|
|
1321
|
-
setValue('');
|
|
1322
|
-
}
|
|
1398
|
+
setValue(state ? collection.find(state)?.description || '' : '');
|
|
1323
1399
|
}
|
|
1324
1400
|
function resetState(state) {
|
|
1325
|
-
|
|
1401
|
+
resetCollection(collection, state);
|
|
1326
1402
|
}
|
|
1327
1403
|
function onClickControl() {
|
|
1328
1404
|
if (!disabled) {
|
|
@@ -1339,8 +1415,6 @@ function useAutocompleteField({ disabled, formControl, onSelect, onValue, sugges
|
|
|
1339
1415
|
function onKeydownInput(event) {
|
|
1340
1416
|
switch (event.code) {
|
|
1341
1417
|
case 'Escape':
|
|
1342
|
-
setVisible(false);
|
|
1343
|
-
break;
|
|
1344
1418
|
case 'Tab':
|
|
1345
1419
|
setVisible(false);
|
|
1346
1420
|
break;
|
|
@@ -1352,9 +1426,7 @@ function useAutocompleteField({ disabled, formControl, onSelect, onValue, sugges
|
|
|
1352
1426
|
function onClickAction() {
|
|
1353
1427
|
setVisible(false);
|
|
1354
1428
|
setValue('');
|
|
1355
|
-
|
|
1356
|
-
setFormState(undefined);
|
|
1357
|
-
}
|
|
1429
|
+
setFormState(undefined);
|
|
1358
1430
|
if (onValue) {
|
|
1359
1431
|
onValue(undefined);
|
|
1360
1432
|
}
|
|
@@ -1369,14 +1441,7 @@ function useAutocompleteField({ disabled, formControl, onSelect, onValue, sugges
|
|
|
1369
1441
|
}
|
|
1370
1442
|
function onKeydownElement(element) {
|
|
1371
1443
|
return (event) => {
|
|
1372
|
-
|
|
1373
|
-
case 'Enter':
|
|
1374
|
-
onChange(element);
|
|
1375
|
-
break;
|
|
1376
|
-
default:
|
|
1377
|
-
navigationElement(event);
|
|
1378
|
-
break;
|
|
1379
|
-
}
|
|
1444
|
+
event.code === 'Enter' ? onChange(element) : navigationElement(event);
|
|
1380
1445
|
};
|
|
1381
1446
|
}
|
|
1382
1447
|
function onChange({ description, value }) {
|
|
@@ -1385,9 +1450,7 @@ function useAutocompleteField({ disabled, formControl, onSelect, onValue, sugges
|
|
|
1385
1450
|
onSelect(value);
|
|
1386
1451
|
}
|
|
1387
1452
|
else {
|
|
1388
|
-
|
|
1389
|
-
setFormState(value);
|
|
1390
|
-
}
|
|
1453
|
+
setFormState(value);
|
|
1391
1454
|
setValue(description);
|
|
1392
1455
|
}
|
|
1393
1456
|
if (onValue) {
|
|
@@ -1395,47 +1458,14 @@ function useAutocompleteField({ disabled, formControl, onSelect, onValue, sugges
|
|
|
1395
1458
|
}
|
|
1396
1459
|
}
|
|
1397
1460
|
function filterSuggestions(pattern, reboot = false) {
|
|
1398
|
-
|
|
1399
|
-
|
|
1400
|
-
|
|
1401
|
-
|
|
1402
|
-
|
|
1403
|
-
|
|
1404
|
-
|
|
1405
|
-
|
|
1406
|
-
previous: store
|
|
1407
|
-
});
|
|
1408
|
-
}
|
|
1409
|
-
else {
|
|
1410
|
-
setCoincidences(suggestions.slice(0, MAX_ELEMENTS));
|
|
1411
|
-
rebootStore();
|
|
1412
|
-
}
|
|
1413
|
-
}
|
|
1414
|
-
function searchForPattern(value) {
|
|
1415
|
-
if (!store.pattern) {
|
|
1416
|
-
return null;
|
|
1417
|
-
}
|
|
1418
|
-
let newStore = store;
|
|
1419
|
-
let search = false;
|
|
1420
|
-
while (!search && newStore) {
|
|
1421
|
-
search = hasPattern(value, newStore.pattern, true);
|
|
1422
|
-
if (!search) {
|
|
1423
|
-
newStore = newStore.previous;
|
|
1424
|
-
}
|
|
1425
|
-
}
|
|
1426
|
-
return newStore || rebootStore();
|
|
1427
|
-
}
|
|
1428
|
-
function rebootStore() {
|
|
1429
|
-
const store = createStoreEmpty();
|
|
1430
|
-
setStore(store);
|
|
1431
|
-
return store;
|
|
1432
|
-
}
|
|
1433
|
-
function createStoreEmpty() {
|
|
1434
|
-
return {
|
|
1435
|
-
coincidences: undefined,
|
|
1436
|
-
pattern: '',
|
|
1437
|
-
previous: null
|
|
1438
|
-
};
|
|
1461
|
+
const result = createStoreAutocomplete({
|
|
1462
|
+
pattern,
|
|
1463
|
+
suggestions,
|
|
1464
|
+
reboot,
|
|
1465
|
+
store
|
|
1466
|
+
});
|
|
1467
|
+
setCoincidences(result.collection.slice(0, MAX_ELEMENTS));
|
|
1468
|
+
setStore(result.store);
|
|
1439
1469
|
}
|
|
1440
1470
|
return {
|
|
1441
1471
|
coincidences,
|
|
@@ -1473,7 +1503,7 @@ function RlsAutocompleteFieldTemplate({ suggestions, children, disabled, formCon
|
|
|
1473
1503
|
setPattern(value);
|
|
1474
1504
|
}, disabled: disabled || searching, onFocus: onFocusInput, onBlur: onBlurInput, onKeyDown: onKeydownInput }), onSearch && (jsx("button", { disabled: disabled || searching, onClick: () => {
|
|
1475
1505
|
onSearch(pattern);
|
|
1476
|
-
}, 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 })] })] }));
|
|
1506
|
+
}, 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: "rls-label-bold truncate", children: reactI18n('listEmptyTitle') }), jsx("p", { className: "rls-caption-regular", children: reactI18n('listEmptyDescription') })] }) }))] }) }), jsx("div", { className: "rls-list-field__backdrop", onClick: onClickBackdrop })] })] }));
|
|
1477
1507
|
}
|
|
1478
1508
|
function RlsAutocompleteField(props) {
|
|
1479
1509
|
return (jsx(RlsAutocompleteFieldTemplate, { ...props, render: (element) => (jsx(RlsBallot, { subtitle: element.subtitle, img: element.img, initials: element.initials, children: element.title })) }));
|
|
@@ -1564,6 +1594,12 @@ function RlsDatatable({ children, datatable, footer, header, rlsTheme, summary }
|
|
|
1564
1594
|
}), "rls-theme": rlsTheme, children: [jsxs("table", { children: [header && jsx("thead", { className: "rls-datatable__thead", children: header }), jsx("tbody", { ref: datatable?.bodyRef, className: "rls-datatable__tbody", children: children })] }), summary && jsx("div", { className: "rls-datatable__tsummary", children: summary }), footer && jsx("div", { className: "rls-datatable__tfooter", children: footer })] }));
|
|
1565
1595
|
}
|
|
1566
1596
|
|
|
1597
|
+
function rangeFormatTemplate({ maxDate, minDate }) {
|
|
1598
|
+
const minFormat = dateFormatTemplate(minDate, DATE_RANGE_FORMAT);
|
|
1599
|
+
const maxFormat = dateFormatTemplate(maxDate, DATE_RANGE_FORMAT);
|
|
1600
|
+
return `${minFormat} - ${maxFormat}`;
|
|
1601
|
+
}
|
|
1602
|
+
|
|
1567
1603
|
const controlIsValid = (props) => {
|
|
1568
1604
|
const { state, validators } = props;
|
|
1569
1605
|
return validators.reduce((errors, validator) => {
|
|
@@ -1660,74 +1696,47 @@ function useReactControl(controlProps, controlValidators) {
|
|
|
1660
1696
|
return useControl(controlProps, controlValidators);
|
|
1661
1697
|
}
|
|
1662
1698
|
|
|
1663
|
-
var PickerListenerType;
|
|
1664
|
-
(function (PickerListenerType) {
|
|
1665
|
-
PickerListenerType["Select"] = "PickerSelect";
|
|
1666
|
-
PickerListenerType["Now"] = "PickerNow";
|
|
1667
|
-
PickerListenerType["Cancel"] = "PickerCancel";
|
|
1668
|
-
})(PickerListenerType || (PickerListenerType = {}));
|
|
1669
|
-
|
|
1670
|
-
function verifyDateRange(date, min, max) {
|
|
1671
|
-
return min && before(min, date) ? min : max && after(max, date) ? max : date;
|
|
1672
|
-
}
|
|
1673
|
-
|
|
1674
1699
|
const FORMAT_DESCRIPTION = '{dw}, {mx} {dd} de {aa}';
|
|
1675
|
-
|
|
1676
|
-
|
|
1677
|
-
|
|
1678
|
-
year: false
|
|
1679
|
-
};
|
|
1680
|
-
const VISIBILITY$1 = {
|
|
1681
|
-
DAY: {
|
|
1682
|
-
...VISIBILITY_STATE$1,
|
|
1683
|
-
day: true
|
|
1684
|
-
},
|
|
1685
|
-
MONTH: {
|
|
1686
|
-
...VISIBILITY_STATE$1,
|
|
1687
|
-
month: true
|
|
1688
|
-
},
|
|
1689
|
-
YEAR: {
|
|
1690
|
-
...VISIBILITY_STATE$1,
|
|
1691
|
-
year: true
|
|
1692
|
-
}
|
|
1693
|
-
};
|
|
1694
|
-
function RlsDatePicker({ automatic, date, formControl, disabled, maxDate, minDate, rlsTheme, onListener }) {
|
|
1695
|
-
const dateInitial = formControl?.state || date || new Date();
|
|
1700
|
+
function RlsDatePicker({ automatic, date, disabled, formControl, maxDate, minDate, onListener, rlsTheme }) {
|
|
1701
|
+
const today = new Date(); // Initial current date in component
|
|
1702
|
+
const dateInitial = formControl?.state || date || today;
|
|
1696
1703
|
const yearControl = useReactControl(dateInitial.getFullYear());
|
|
1697
1704
|
const dayControl = useReactControl(dateInitial.getDate());
|
|
1698
1705
|
const monthControl = useReactControl(dateInitial.getMonth());
|
|
1699
1706
|
const [value, setValue] = useState(dateInitial);
|
|
1700
|
-
const [
|
|
1701
|
-
const title = formatDate(value, FORMAT_DESCRIPTION);
|
|
1707
|
+
const [visibility, setVisibility] = useState('DAY');
|
|
1702
1708
|
useEffect(() => {
|
|
1703
|
-
|
|
1704
|
-
|
|
1705
|
-
|
|
1706
|
-
|
|
1709
|
+
const dateCheck = checkDateRange({
|
|
1710
|
+
date: formControl?.state || date || today,
|
|
1711
|
+
minDate,
|
|
1712
|
+
maxDate
|
|
1707
1713
|
});
|
|
1714
|
+
setValue(dateCheck);
|
|
1715
|
+
formControl?.setState(dateCheck);
|
|
1716
|
+
}, []);
|
|
1717
|
+
useEffect(() => {
|
|
1718
|
+
setValue((prevValue) => itIsDefined(yearControl.state)
|
|
1719
|
+
? assignYearInDate(prevValue, yearControl.state)
|
|
1720
|
+
: prevValue);
|
|
1708
1721
|
}, [yearControl.state]);
|
|
1709
1722
|
useEffect(() => {
|
|
1710
|
-
setValue((prevValue) =>
|
|
1711
|
-
|
|
1712
|
-
|
|
1713
|
-
: prevValue;
|
|
1714
|
-
});
|
|
1723
|
+
setValue((prevValue) => itIsDefined(monthControl.state)
|
|
1724
|
+
? assignMonthInDate(prevValue, monthControl.state)
|
|
1725
|
+
: prevValue);
|
|
1715
1726
|
}, [monthControl.state]);
|
|
1716
1727
|
useEffect(() => {
|
|
1717
|
-
setValue((prevValue) =>
|
|
1718
|
-
|
|
1719
|
-
|
|
1720
|
-
: prevValue;
|
|
1721
|
-
});
|
|
1728
|
+
setValue((prevValue) => itIsDefined(dayControl.state)
|
|
1729
|
+
? assignDayInDate(prevValue, dayControl.state)
|
|
1730
|
+
: prevValue);
|
|
1722
1731
|
}, [dayControl.state]);
|
|
1723
1732
|
function onVisibilityDay() {
|
|
1724
|
-
setVisibility(
|
|
1733
|
+
setVisibility('DAY');
|
|
1725
1734
|
}
|
|
1726
1735
|
function onVisibilityMonth() {
|
|
1727
|
-
setVisibility(
|
|
1736
|
+
setVisibility('MONTH');
|
|
1728
1737
|
}
|
|
1729
1738
|
function onVisibilityYear() {
|
|
1730
|
-
setVisibility(
|
|
1739
|
+
setVisibility('YEAR');
|
|
1731
1740
|
}
|
|
1732
1741
|
function onCancel() {
|
|
1733
1742
|
if (onListener) {
|
|
@@ -1735,14 +1744,12 @@ function RlsDatePicker({ automatic, date, formControl, disabled, maxDate, minDat
|
|
|
1735
1744
|
}
|
|
1736
1745
|
}
|
|
1737
1746
|
function onToday() {
|
|
1738
|
-
|
|
1739
|
-
|
|
1740
|
-
|
|
1741
|
-
|
|
1742
|
-
dayControl.setState(value.getDate());
|
|
1743
|
-
monthControl.setState(value.getMonth());
|
|
1747
|
+
yearControl.setState(today.getFullYear());
|
|
1748
|
+
dayControl.setState(today.getDate());
|
|
1749
|
+
monthControl.setState(today.getMonth());
|
|
1750
|
+
formControl?.setState(today);
|
|
1744
1751
|
if (onListener) {
|
|
1745
|
-
onListener({ type: PickerListenerType.Now, value });
|
|
1752
|
+
onListener({ type: PickerListenerType.Now, value: today });
|
|
1746
1753
|
}
|
|
1747
1754
|
}
|
|
1748
1755
|
function onSelect() {
|
|
@@ -1751,27 +1758,38 @@ function RlsDatePicker({ automatic, date, formControl, disabled, maxDate, minDat
|
|
|
1751
1758
|
onListener({ type: PickerListenerType.Select, value });
|
|
1752
1759
|
}
|
|
1753
1760
|
}
|
|
1754
|
-
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:
|
|
1755
|
-
|
|
1756
|
-
|
|
1757
|
-
|
|
1758
|
-
}), children: [jsx(RlsDayPicker, { formControl: dayControl, date:
|
|
1761
|
+
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: dateFormatTemplate(dateInitial, FORMAT_DESCRIPTION) }) }), 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, disabled: visibility === 'YEAR', type: 'month', onClick: onVisibilityMonth })] }), jsxs("div", { className: renderClassStatus('rls-date-picker__component', {
|
|
1762
|
+
day: visibility === 'DAY',
|
|
1763
|
+
month: visibility === 'MONTH',
|
|
1764
|
+
year: visibility === 'YEAR'
|
|
1765
|
+
}), children: [jsx(RlsDayPicker, { formControl: dayControl, date: dateInitial, month: monthControl.state, year: yearControl.state, maxDate: maxDate, minDate: minDate, disabled: disabled }), jsx(RlsMonthPicker, { formControl: monthControl, date: dateInitial, year: yearControl.state, maxDate: maxDate, minDate: minDate, disabled: disabled, onValue: onVisibilityDay }), jsx(RlsYearPicker, { formControl: yearControl, date: dateInitial, maxDate: maxDate, minDate: minDate, disabled: disabled, onValue: onVisibilityDay })] }), 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, disabled: dateOutRange({ date: today, maxDate, minDate }), children: reactI18n('dateActionToday') }) }), jsx("div", { className: "rls-date-picker__actions--ok", children: jsx(RlsButton, { type: "raised", onClick: onSelect, children: reactI18n('dateActionSelect') }) })] }) })] }));
|
|
1759
1766
|
}
|
|
1760
1767
|
|
|
1761
1768
|
function RlsModal({ children, visible, rlsTheme }) {
|
|
1762
1769
|
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);
|
|
1763
1770
|
}
|
|
1764
1771
|
|
|
1765
|
-
function RlsDateField({ children, date, disabled, formControl, maxDate, minDate, placeholder, rlsTheme
|
|
1766
|
-
const
|
|
1767
|
-
const [value, setValue] = useState(
|
|
1768
|
-
const [
|
|
1769
|
-
const
|
|
1772
|
+
function RlsDateField({ children, date, disabled, formControl, maxDate, minDate, onValue, placeholder, rlsTheme }) {
|
|
1773
|
+
const today = new Date(); // Initial current date in component
|
|
1774
|
+
const [value, setValue] = useState();
|
|
1775
|
+
const [modalIsVisible, setModalIsVisible] = useState(false);
|
|
1776
|
+
const description = useRef('');
|
|
1777
|
+
useEffect(() => {
|
|
1778
|
+
const dateCheck = checkDateRange({
|
|
1779
|
+
date: formControl?.state || date || today,
|
|
1780
|
+
minDate,
|
|
1781
|
+
maxDate
|
|
1782
|
+
});
|
|
1783
|
+
setValue(dateCheck);
|
|
1784
|
+
formControl?.setState(dateCheck);
|
|
1785
|
+
}, []);
|
|
1770
1786
|
useEffect(() => {
|
|
1771
|
-
|
|
1787
|
+
description.current = value
|
|
1788
|
+
? dateFormatTemplate(value, DATE_RANGE_FORMAT)
|
|
1789
|
+
: '';
|
|
1772
1790
|
}, [value]);
|
|
1773
1791
|
function onClickInput() {
|
|
1774
|
-
|
|
1792
|
+
setModalIsVisible(true);
|
|
1775
1793
|
}
|
|
1776
1794
|
function onChange(value, ignoreControl = false) {
|
|
1777
1795
|
if (!ignoreControl) {
|
|
@@ -1790,40 +1808,21 @@ function RlsDateField({ children, date, disabled, formControl, maxDate, minDate,
|
|
|
1790
1808
|
}
|
|
1791
1809
|
}
|
|
1792
1810
|
else {
|
|
1793
|
-
|
|
1811
|
+
setModalIsVisible(true);
|
|
1794
1812
|
}
|
|
1795
1813
|
}
|
|
1796
|
-
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:
|
|
1814
|
+
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.current, 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: modalIsVisible, rlsTheme: rlsTheme, children: jsx(RlsDatePicker, { formControl: formControl, date: date, disabled: disabled, maxDate: maxDate, minDate: minDate, onListener: ({ value, type }) => {
|
|
1797
1815
|
if (type !== PickerListenerType.Cancel) {
|
|
1798
1816
|
onChange(value, true);
|
|
1799
1817
|
}
|
|
1800
|
-
|
|
1801
|
-
if (
|
|
1802
|
-
formControl
|
|
1818
|
+
setModalIsVisible(false);
|
|
1819
|
+
if (!formControl?.touched) {
|
|
1820
|
+
formControl?.touch();
|
|
1803
1821
|
}
|
|
1804
1822
|
} }) })] }));
|
|
1805
1823
|
}
|
|
1806
1824
|
|
|
1807
|
-
|
|
1808
|
-
month: false,
|
|
1809
|
-
day: false,
|
|
1810
|
-
year: false
|
|
1811
|
-
};
|
|
1812
|
-
const VISIBILITY = {
|
|
1813
|
-
DAY: {
|
|
1814
|
-
...VISIBILITY_STATE,
|
|
1815
|
-
day: true
|
|
1816
|
-
},
|
|
1817
|
-
MONTH: {
|
|
1818
|
-
...VISIBILITY_STATE,
|
|
1819
|
-
month: true
|
|
1820
|
-
},
|
|
1821
|
-
YEAR: {
|
|
1822
|
-
...VISIBILITY_STATE,
|
|
1823
|
-
year: true
|
|
1824
|
-
}
|
|
1825
|
-
};
|
|
1826
|
-
function RlsDateRangePicker({ automatic, date: datePicker, disabled, formControl, maxDate, minDate, rlsTheme, onListener }) {
|
|
1825
|
+
function RlsDateRangePicker({ automatic, date: datePicker, disabled, formControl, maxDate, minDate, onListener, rlsTheme }) {
|
|
1827
1826
|
const dateInitial = normalizeMinTime(datePicker || new Date());
|
|
1828
1827
|
const rangeInitial = formControl?.state || DateRange.now();
|
|
1829
1828
|
const yearControl = useReactControl(dateInitial.getFullYear());
|
|
@@ -1831,18 +1830,18 @@ function RlsDateRangePicker({ automatic, date: datePicker, disabled, formControl
|
|
|
1831
1830
|
const dayControl = useReactControl(rangeInitial);
|
|
1832
1831
|
const [value, setValue] = useState(rangeInitial);
|
|
1833
1832
|
const [date, setDate] = useState(dateInitial);
|
|
1834
|
-
const [
|
|
1833
|
+
const [visibility, setVisibility] = useState('DAY');
|
|
1835
1834
|
useEffect(() => {
|
|
1836
1835
|
setDate((prevValue) => {
|
|
1837
1836
|
return typeof yearControl.state === 'number'
|
|
1838
|
-
?
|
|
1837
|
+
? assignYearInDate(prevValue, yearControl.state)
|
|
1839
1838
|
: prevValue;
|
|
1840
1839
|
});
|
|
1841
1840
|
}, [yearControl.state]);
|
|
1842
1841
|
useEffect(() => {
|
|
1843
1842
|
setDate((prevValue) => {
|
|
1844
1843
|
return typeof monthControl.state === 'number'
|
|
1845
|
-
?
|
|
1844
|
+
? assignMonthInDate(prevValue, monthControl.state)
|
|
1846
1845
|
: prevValue;
|
|
1847
1846
|
});
|
|
1848
1847
|
}, [monthControl.state]);
|
|
@@ -1850,16 +1849,16 @@ function RlsDateRangePicker({ automatic, date: datePicker, disabled, formControl
|
|
|
1850
1849
|
if (dayControl.state) {
|
|
1851
1850
|
setValue(dayControl.state);
|
|
1852
1851
|
}
|
|
1853
|
-
setVisibility(
|
|
1852
|
+
setVisibility('DAY');
|
|
1854
1853
|
}, [dayControl.state]);
|
|
1855
1854
|
function onVisibilityDay() {
|
|
1856
|
-
setVisibility(
|
|
1855
|
+
setVisibility('DAY');
|
|
1857
1856
|
}
|
|
1858
1857
|
function onVisibilityMonth() {
|
|
1859
|
-
setVisibility(
|
|
1858
|
+
setVisibility('MONTH');
|
|
1860
1859
|
}
|
|
1861
1860
|
function onVisibilityYear() {
|
|
1862
|
-
setVisibility(
|
|
1861
|
+
setVisibility('YEAR');
|
|
1863
1862
|
}
|
|
1864
1863
|
function onCancel() {
|
|
1865
1864
|
if (onListener) {
|
|
@@ -1872,11 +1871,11 @@ function RlsDateRangePicker({ automatic, date: datePicker, disabled, formControl
|
|
|
1872
1871
|
onListener({ type: PickerListenerType.Select, value });
|
|
1873
1872
|
}
|
|
1874
1873
|
}
|
|
1875
|
-
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:
|
|
1876
|
-
|
|
1877
|
-
|
|
1878
|
-
|
|
1879
|
-
}), children: [jsx(RlsDayRangePicker, { formControl: dayControl, date: date, maxDate: maxDate, minDate: minDate, disabled: disabled }), jsx(RlsMonthPicker, { formControl: monthControl,
|
|
1874
|
+
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: rangeFormatTemplate(value) }) }), 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, disabled: visibility === 'YEAR', type: visibility === 'MONTH' ? 'year' : 'month', onClick: onVisibilityMonth })] }), jsxs("div", { className: renderClassStatus('rls-date-range-picker__component', {
|
|
1875
|
+
day: visibility === 'DAY',
|
|
1876
|
+
month: visibility === 'MONTH',
|
|
1877
|
+
year: visibility === 'YEAR'
|
|
1878
|
+
}), children: [jsx(RlsDayRangePicker, { formControl: dayControl, date: date, maxDate: maxDate, minDate: minDate, disabled: disabled }), jsx(RlsMonthPicker, { formControl: monthControl, year: yearControl.state, maxDate: maxDate, minDate: minDate, disabled: disabled, onValue: onVisibilityDay }), jsx(RlsYearPicker, { formControl: yearControl, maxDate: maxDate, minDate: minDate, disabled: disabled, onValue: onVisibilityDay })] }), jsx("div", { className: renderClassStatus('rls-date-range-picker__footer', {
|
|
1880
1879
|
automatic
|
|
1881
1880
|
}), 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') }) })] }) })] }));
|
|
1882
1881
|
}
|
|
@@ -1887,9 +1886,9 @@ function RlsDateRangeField({ children, date: datePicker, disabled, formControl,
|
|
|
1887
1886
|
const [value, setValue] = useState(rangeInitial);
|
|
1888
1887
|
const [date] = useState(dateInitial);
|
|
1889
1888
|
const [show, setShow] = useState(false);
|
|
1890
|
-
const
|
|
1889
|
+
const description = useRef('');
|
|
1891
1890
|
useEffect(() => {
|
|
1892
|
-
|
|
1891
|
+
description.current = value ? rangeFormatTemplate(value) : '';
|
|
1893
1892
|
}, [value]);
|
|
1894
1893
|
function onClickInput() {
|
|
1895
1894
|
setShow(true);
|
|
@@ -1903,7 +1902,7 @@ function RlsDateRangeField({ children, date: datePicker, disabled, formControl,
|
|
|
1903
1902
|
setShow(true);
|
|
1904
1903
|
}
|
|
1905
1904
|
}
|
|
1906
|
-
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, rlsTheme: rlsTheme, children: jsx(RlsDateRangePicker, { formControl: formControl, date: date, disabled: disabled, maxDate: maxDate, minDate: minDate, onListener: ({ value }) => {
|
|
1905
|
+
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.current, 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, rlsTheme: rlsTheme, children: jsx(RlsDateRangePicker, { formControl: formControl, date: date, disabled: disabled, maxDate: maxDate, minDate: minDate, onListener: ({ value }) => {
|
|
1907
1906
|
if (value) {
|
|
1908
1907
|
setValue(value);
|
|
1909
1908
|
}
|
|
@@ -1918,31 +1917,27 @@ function RlsFormNavigation({ children, visible, rlsTheme }) {
|
|
|
1918
1917
|
function useSelectField({ suggestions, formControl, onSelect, onValue }) {
|
|
1919
1918
|
const listControl = useListControl({ suggestions, formControl });
|
|
1920
1919
|
const { collection, inputRef, visible, navigationElement, navigationInput, setFocused, setValue, setVisible } = listControl;
|
|
1921
|
-
const
|
|
1920
|
+
const changeInternal = useRef(false);
|
|
1922
1921
|
useEffect(() => {
|
|
1923
|
-
|
|
1922
|
+
if (changeInternal.current) {
|
|
1923
|
+
changeInternal.current = false;
|
|
1924
|
+
}
|
|
1925
|
+
else {
|
|
1926
|
+
resetState(formControl?.state);
|
|
1927
|
+
}
|
|
1924
1928
|
}, [formControl?.state]);
|
|
1925
1929
|
useEffect(() => resetCollection(collection, formControl?.state), [collection]);
|
|
1926
1930
|
function setFormState(value) {
|
|
1927
|
-
|
|
1928
|
-
|
|
1931
|
+
if (formControl) {
|
|
1932
|
+
changeInternal.current = true;
|
|
1933
|
+
formControl.setState(value);
|
|
1934
|
+
}
|
|
1929
1935
|
}
|
|
1930
1936
|
function resetCollection(collection, state) {
|
|
1931
|
-
|
|
1932
|
-
const element = collection.find(state);
|
|
1933
|
-
if (element) {
|
|
1934
|
-
setValue(element.description);
|
|
1935
|
-
}
|
|
1936
|
-
else {
|
|
1937
|
-
setValue('');
|
|
1938
|
-
}
|
|
1939
|
-
}
|
|
1940
|
-
else {
|
|
1941
|
-
setValue('');
|
|
1942
|
-
}
|
|
1937
|
+
setValue(state ? collection.find(state)?.description || '' : '');
|
|
1943
1938
|
}
|
|
1944
1939
|
function resetState(state) {
|
|
1945
|
-
|
|
1940
|
+
resetCollection(collection, state);
|
|
1946
1941
|
}
|
|
1947
1942
|
function onFocusInput() {
|
|
1948
1943
|
setFocused(true);
|
|
@@ -1950,20 +1945,16 @@ function useSelectField({ suggestions, formControl, onSelect, onValue }) {
|
|
|
1950
1945
|
function onBlurInput() {
|
|
1951
1946
|
setFocused(false);
|
|
1952
1947
|
}
|
|
1953
|
-
function
|
|
1948
|
+
function onClickInput() {
|
|
1954
1949
|
setVisible(true);
|
|
1955
1950
|
}
|
|
1956
1951
|
function onKeydownInput(event) {
|
|
1957
1952
|
switch (event.code) {
|
|
1958
1953
|
case 'Space':
|
|
1959
|
-
setVisible(true);
|
|
1960
|
-
break;
|
|
1961
1954
|
case 'Enter':
|
|
1962
1955
|
setVisible(true);
|
|
1963
1956
|
break;
|
|
1964
1957
|
case 'Escape':
|
|
1965
|
-
setVisible(false);
|
|
1966
|
-
break;
|
|
1967
1958
|
case 'Tab':
|
|
1968
1959
|
setVisible(false);
|
|
1969
1960
|
break;
|
|
@@ -1989,14 +1980,7 @@ function useSelectField({ suggestions, formControl, onSelect, onValue }) {
|
|
|
1989
1980
|
}
|
|
1990
1981
|
function onKeydownElement(element) {
|
|
1991
1982
|
return (event) => {
|
|
1992
|
-
|
|
1993
|
-
case 'Enter':
|
|
1994
|
-
onChange(element);
|
|
1995
|
-
break;
|
|
1996
|
-
default:
|
|
1997
|
-
navigationElement(event);
|
|
1998
|
-
break;
|
|
1999
|
-
}
|
|
1983
|
+
event.code === 'Enter' ? onChange(element) : navigationElement(event);
|
|
2000
1984
|
};
|
|
2001
1985
|
}
|
|
2002
1986
|
function onChange({ description, value }) {
|
|
@@ -2006,9 +1990,7 @@ function useSelectField({ suggestions, formControl, onSelect, onValue }) {
|
|
|
2006
1990
|
onSelect(value);
|
|
2007
1991
|
}
|
|
2008
1992
|
else {
|
|
2009
|
-
|
|
2010
|
-
setFormState(value);
|
|
2011
|
-
}
|
|
1993
|
+
setFormState(value);
|
|
2012
1994
|
setValue(description);
|
|
2013
1995
|
}
|
|
2014
1996
|
if (onValue) {
|
|
@@ -2020,7 +2002,7 @@ function useSelectField({ suggestions, formControl, onSelect, onValue }) {
|
|
|
2020
2002
|
onBlurInput,
|
|
2021
2003
|
onClickAction,
|
|
2022
2004
|
onClickBackdrop,
|
|
2023
|
-
onClickInput
|
|
2005
|
+
onClickInput,
|
|
2024
2006
|
onClickElement,
|
|
2025
2007
|
onFocusInput,
|
|
2026
2008
|
onKeydownElement,
|
|
@@ -2042,7 +2024,7 @@ function RlsSelectFieldTemplate({ suggestions, children, disabled, formControl,
|
|
|
2042
2024
|
visible: listControl.visible,
|
|
2043
2025
|
hide: !listControl.visible,
|
|
2044
2026
|
higher: listControl.higher
|
|
2045
|
-
}), 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 })] })] }));
|
|
2027
|
+
}), 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: "rls-label-bold truncate", children: reactI18n('listEmptyTitle') }), jsx("p", { className: "rls-caption-regular", children: reactI18n('listEmptyDescription') })] }) }))] }) }), jsx("div", { className: "rls-list-field__backdrop", onClick: onClickBackdrop })] })] }));
|
|
2046
2028
|
}
|
|
2047
2029
|
function RlsSelectField(props) {
|
|
2048
2030
|
return (jsx(RlsSelectFieldTemplate, { ...props, render: (element) => (jsx(RlsBallot, { subtitle: element.subtitle, img: element.img, initials: element.initials, children: element.title })) }));
|
|
@@ -2109,5 +2091,5 @@ function RlsApplication({ children }) {
|
|
|
2109
2091
|
return (jsxs(RlsContext.Provider, { value: { confirmation, snackbar }, children: [jsx("div", { className: "rls-app__body", children: children }), RlsSnackbar, RlsConfirmation] }));
|
|
2110
2092
|
}
|
|
2111
2093
|
|
|
2112
|
-
export { ConfirmationResult,
|
|
2094
|
+
export { ConfirmationResult, RlsAmount, RlsApplication, RlsAutocompleteField, RlsAutocompleteFieldTemplate, RlsAvatar, RlsBadge, RlsBallot, RlsBreadcrumb, RlsButton, RlsButtonAction, RlsButtonProgress, RlsButtonToggle, RlsCard, RlsCheckBox, RlsCheckBoxControl, RlsCheckBoxLabel, RlsConfirmation, RlsContext, RlsDatatable, RlsDatatableCell, RlsDatatableData, RlsDatatableHeader, RlsDatatableInfo, RlsDatatableTitle, RlsDatatableTotals, RlsDateField, RlsDatePicker, RlsDateRangeField, RlsDateRangePicker, RlsDayPicker, RlsDayRangePicker, RlsFormNavigation, RlsIcon, RlsInput, RlsInputMoney, RlsInputNumber, RlsInputPassword, RlsInputText, RlsLabel, RlsMessageIcon, RlsModal, RlsMoneyField, RlsMonthPicker, RlsMonthTitlePicker, RlsNumberField, RlsPagination, RlsPasswordField, RlsPoster, RlsProgressBar, RlsProgressCircular, RlsRadioButton, RlsRadioButtonLabel, RlsSearchInput, RlsSelectField, RlsSelectFieldTemplate, RlsSkeleton, RlsSkeletonText, RlsSnackbar, RlsSwitch, RlsSwitchControl, RlsSwitchLabel, RlsTabularText, RlsTextField, RlsToolbar, RlsYearPicker, rangeFormatTemplate, renderClassStatus, useConfirmationService, useDatatable, useListControl, useSnackbarService };
|
|
2113
2095
|
//# sourceMappingURL=index.js.map
|