@rolster/react-components 18.12.4 → 18.12.6
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-XotqmUMW.css → index-r16o2aIF.css} +21 -8
- package/dist/cjs/index.js +52 -26
- package/dist/cjs/index.js.map +1 -1
- package/dist/es/assets/{index-XotqmUMW.css → index-r16o2aIF.css} +21 -8
- package/dist/es/index.js +53 -27
- package/dist/es/index.js.map +1 -1
- package/dist/esm/components/definitions.d.ts +1 -1
- package/dist/esm/components/molecules/DayRangePicker/DayRangePicker.css +17 -3
- package/dist/esm/components/molecules/DayRangePicker/DayRangePicker.js +14 -7
- package/dist/esm/components/molecules/DayRangePicker/DayRangePicker.js.map +1 -1
- package/dist/esm/components/organisms/DateField/DateField.js +1 -1
- package/dist/esm/components/organisms/DateField/DateField.js.map +1 -1
- package/dist/esm/components/organisms/DatePicker/DatePicker.js +3 -3
- package/dist/esm/components/organisms/DatePicker/DatePicker.js.map +1 -1
- package/dist/esm/components/organisms/DateRangeField/DateRangeField.js +1 -1
- package/dist/esm/components/organisms/DateRangeField/DateRangeField.js.map +1 -1
- package/dist/esm/components/organisms/DateRangePicker/DateRangePicker.css +4 -5
- package/dist/esm/components/organisms/DateRangePicker/DateRangePicker.js +3 -3
- package/dist/esm/components/organisms/DateRangePicker/DateRangePicker.js.map +1 -1
- package/dist/esm/helpers/date-range-picker.d.ts +2 -0
- package/dist/esm/helpers/date-range-picker.js +18 -13
- package/dist/esm/helpers/date-range-picker.js.map +1 -1
- package/dist/esm/models.d.ts +3 -2
- package/package.json +5 -5
|
@@ -1066,15 +1066,25 @@
|
|
|
1066
1066
|
--pvt-span-nothover-font-color: inherit;
|
|
1067
1067
|
--pvt-span-background: transparent;
|
|
1068
1068
|
position: relative;
|
|
1069
|
-
|
|
1069
|
+
display: flex;
|
|
1070
1070
|
width: 100%;
|
|
1071
1071
|
max-width: 140rem;
|
|
1072
|
+
flex-direction: column;
|
|
1073
|
+
row-gap: var(--sizing-x4);
|
|
1072
1074
|
box-sizing: border-box;
|
|
1073
1075
|
user-select: none;
|
|
1074
1076
|
}
|
|
1077
|
+
.rls-day-range-picker__title {
|
|
1078
|
+
color: var(--color-rolster-500);
|
|
1079
|
+
text-align: center;
|
|
1080
|
+
padding: var(--sizing-x4) 0rem;
|
|
1081
|
+
font-size: var(--subtitle-font-size);
|
|
1082
|
+
letter-spacing: var(--subtitle-letter-spacing);
|
|
1083
|
+
line-height: var(--subtitle-line-height);
|
|
1084
|
+
font-weight: var(--font-weight-bold);
|
|
1085
|
+
}
|
|
1075
1086
|
.rls-day-range-picker__header {
|
|
1076
1087
|
display: flex;
|
|
1077
|
-
margin-bottom: var(--sizing-x4);
|
|
1078
1088
|
background: var(--background-theme-100);
|
|
1079
1089
|
color: var(--color-theme-500);
|
|
1080
1090
|
border-radius: var(--sizing-x2);
|
|
@@ -1113,7 +1123,11 @@
|
|
|
1113
1123
|
color: var(--color-light-500);
|
|
1114
1124
|
background: var(--color-rolster-900);
|
|
1115
1125
|
}
|
|
1116
|
-
.rls-day-range-picker__day--
|
|
1126
|
+
.rls-day-range-picker__day--end {
|
|
1127
|
+
--pvt-span-nothover-background: var(--color-theme-500);
|
|
1128
|
+
--pvt-span-nothover-font-color: var(--background-theme-500);
|
|
1129
|
+
}
|
|
1130
|
+
.rls-day-range-picker__day--source {
|
|
1117
1131
|
--pvt-span-nothover-background: var(--color-rolster-500);
|
|
1118
1132
|
--pvt-span-nothover-font-color: var(--color-light-500);
|
|
1119
1133
|
}
|
|
@@ -1924,6 +1938,7 @@
|
|
|
1924
1938
|
position: relative;
|
|
1925
1939
|
display: flex;
|
|
1926
1940
|
flex-direction: column;
|
|
1941
|
+
row-gap: var(--sizing-x4);
|
|
1927
1942
|
overflow: hidden;
|
|
1928
1943
|
max-width: 150rem;
|
|
1929
1944
|
}
|
|
@@ -1931,7 +1946,6 @@
|
|
|
1931
1946
|
background: var(--color-rolster-100);
|
|
1932
1947
|
padding: var(--sizing-x4);
|
|
1933
1948
|
box-sizing: border-box;
|
|
1934
|
-
margin-bottom: var(--sizing-x8);
|
|
1935
1949
|
}
|
|
1936
1950
|
.rls-date-range-picker__title {
|
|
1937
1951
|
color: var(--color-theme-500);
|
|
@@ -1967,17 +1981,16 @@
|
|
|
1967
1981
|
}
|
|
1968
1982
|
.rls-date-range-picker__component {
|
|
1969
1983
|
display: flex;
|
|
1984
|
+
justify-content: center;
|
|
1970
1985
|
width: 150rem;
|
|
1971
1986
|
padding: 0rem var(--sizing-x2);
|
|
1972
1987
|
box-sizing: border-box;
|
|
1973
|
-
margin-bottom: var(--sizing-x4);
|
|
1974
1988
|
}
|
|
1975
1989
|
.rls-date-range-picker__component > * {
|
|
1976
|
-
margin: 0rem auto;
|
|
1977
1990
|
display: none;
|
|
1978
1991
|
}
|
|
1979
1992
|
.rls-date-range-picker__component--day .rls-day-range-picker {
|
|
1980
|
-
display:
|
|
1993
|
+
display: flex;
|
|
1981
1994
|
}
|
|
1982
1995
|
.rls-date-range-picker__component--month .rls-month-picker {
|
|
1983
1996
|
display: grid;
|
|
@@ -1992,7 +2005,7 @@
|
|
|
1992
2005
|
display: flex;
|
|
1993
2006
|
flex-wrap: wrap;
|
|
1994
2007
|
gap: var(--sizing-x4);
|
|
1995
|
-
padding:
|
|
2008
|
+
padding: 0rem var(--sizing-x8) var(--sizing-x6) var(--sizing-x8);
|
|
1996
2009
|
overflow: hidden;
|
|
1997
2010
|
box-sizing: border-box;
|
|
1998
2011
|
}
|
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
3
|
import { currencyFormat, PartialSealed } from '@rolster/helpers-advanced';
|
|
4
|
-
import { daysFromMonth, weight, assignDay, DAY_LABELS, formatDate, between, DateRange, normalizeMinTime, Month, MONTH_NAMES,
|
|
4
|
+
import { daysFromMonth, weight, assignDay, DAY_LABELS, formatDate, between, DateRange, normalizeMinTime, before, Month, MONTH_NAMES, after, assignYear, assignMonth } 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';
|
|
@@ -382,12 +382,13 @@ function RlsDayPicker({ date, disabled: disabledPicker, formControl, maxDate, mi
|
|
|
382
382
|
}, children: jsx("span", { className: "rls-day-picker__day__span", children: value || '??' }) }, index))) }, index))) })] }));
|
|
383
383
|
}
|
|
384
384
|
|
|
385
|
-
const
|
|
385
|
+
const DATE_RANGE_FORMAT = '{dd}/{mx}/{aa}';
|
|
386
386
|
class DateRangePickerFactory {
|
|
387
387
|
constructor(props) {
|
|
388
|
-
const { date, range, maxDate, minDate } = props;
|
|
388
|
+
const { date, range, sourceDate, maxDate, minDate } = props;
|
|
389
389
|
this.date = new Date(date.getTime());
|
|
390
390
|
this.range = range;
|
|
391
|
+
this.sourceDate = sourceDate;
|
|
391
392
|
this.maxDate = maxDate;
|
|
392
393
|
this.minDate = minDate;
|
|
393
394
|
this.date.setDate(1);
|
|
@@ -440,16 +441,10 @@ class DateRangePickerFactory {
|
|
|
440
441
|
}
|
|
441
442
|
return daysPending;
|
|
442
443
|
}
|
|
443
|
-
|
|
444
|
-
return
|
|
445
|
-
value: day,
|
|
446
|
-
disabled: this.overflowDay(day || 0),
|
|
447
|
-
forbidden: !day,
|
|
448
|
-
ranged: day ? this.isRangedFromDate(day) : false,
|
|
449
|
-
selected: day ? this.isSelected(day) : false
|
|
450
|
-
};
|
|
444
|
+
isSelectedSource(day) {
|
|
445
|
+
return this.isSelectedForDate(this.sourceDate, day);
|
|
451
446
|
}
|
|
452
|
-
|
|
447
|
+
isSelectedEnd(day) {
|
|
453
448
|
return (this.isSelectedForDate(this.range.minDate, day) ||
|
|
454
449
|
this.isSelectedForDate(this.range.maxDate, day));
|
|
455
450
|
}
|
|
@@ -474,10 +469,20 @@ class DateRangePickerFactory {
|
|
|
474
469
|
? weight(assignDay(this.date, day)) > weight(this.maxDate)
|
|
475
470
|
: false;
|
|
476
471
|
}
|
|
472
|
+
createDayRangeState(day) {
|
|
473
|
+
return {
|
|
474
|
+
value: day,
|
|
475
|
+
disabled: this.overflowDay(day || 0),
|
|
476
|
+
forbidden: !day,
|
|
477
|
+
ranged: day ? this.isRangedFromDate(day) : false,
|
|
478
|
+
end: day ? this.isSelectedEnd(day) : false,
|
|
479
|
+
source: day ? this.isSelectedSource(day) : false
|
|
480
|
+
};
|
|
481
|
+
}
|
|
477
482
|
}
|
|
478
483
|
function formatRange(range) {
|
|
479
|
-
const minFormat = formatDate(range.minDate,
|
|
480
|
-
const maxFormat = formatDate(range.maxDate,
|
|
484
|
+
const minFormat = formatDate(range.minDate, DATE_RANGE_FORMAT);
|
|
485
|
+
const maxFormat = formatDate(range.maxDate, DATE_RANGE_FORMAT);
|
|
481
486
|
return `${minFormat} - ${maxFormat}`;
|
|
482
487
|
}
|
|
483
488
|
function createRangePicker(props) {
|
|
@@ -487,26 +492,33 @@ function createRangePicker(props) {
|
|
|
487
492
|
function RlsDayRangePicker({ date, disabled: disabledPicker, formControl, maxDate, minDate, rlsTheme }) {
|
|
488
493
|
const initialRange = formControl?.state || DateRange.now();
|
|
489
494
|
const initialDate = normalizeMinTime(date || initialRange.minDate);
|
|
495
|
+
const sourceDate = useRef(initialRange.minDate);
|
|
490
496
|
const [weeks, setWeeks] = useState([]);
|
|
491
497
|
const [range, setRange] = useState(initialRange);
|
|
492
498
|
useEffect(() => {
|
|
493
499
|
setWeeks(createRangePicker({
|
|
494
500
|
date: initialDate,
|
|
495
501
|
range,
|
|
502
|
+
sourceDate: sourceDate.current,
|
|
496
503
|
minDate,
|
|
497
504
|
maxDate
|
|
498
505
|
}));
|
|
499
506
|
}, [range, date, minDate, maxDate]);
|
|
500
507
|
function onChange(value) {
|
|
501
|
-
const
|
|
508
|
+
const newDate = assignDay(initialDate, value);
|
|
509
|
+
const newRange = before(newDate, sourceDate.current)
|
|
510
|
+
? new DateRange(sourceDate.current, newDate)
|
|
511
|
+
: new DateRange(newDate, sourceDate.current);
|
|
512
|
+
sourceDate.current = newDate;
|
|
502
513
|
setRange(newRange);
|
|
503
514
|
formControl?.setState(newRange);
|
|
504
515
|
}
|
|
505
|
-
return (jsxs("div", { className: "rls-day-range-picker", "rls-theme": rlsTheme, children: [jsx("div", { className: "rls-day-range-picker__header", children: DAY_LABELS().map((title, index) => (jsx("label", { className: "rls-day-range-picker__label", children: title }, index))) }), jsx("div", { className: "rls-day-range-picker__component", children: weeks.map(({ days }, index) => (jsx("div", { className: "rls-day-range-picker__week", children: days.map(({
|
|
516
|
+
return (jsxs("div", { className: "rls-day-range-picker", "rls-theme": rlsTheme, children: [jsx("div", { className: "rls-day-range-picker__title", children: formatDate(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', {
|
|
506
517
|
disabled: disabled || disabledPicker,
|
|
518
|
+
end,
|
|
507
519
|
forbidden,
|
|
508
|
-
|
|
509
|
-
|
|
520
|
+
ranged,
|
|
521
|
+
source
|
|
510
522
|
}), onClick: () => {
|
|
511
523
|
if (value && !disabled) {
|
|
512
524
|
onChange(value);
|
|
@@ -1538,7 +1550,21 @@ const controlIsValid = (props) => {
|
|
|
1538
1550
|
}, []);
|
|
1539
1551
|
};
|
|
1540
1552
|
|
|
1541
|
-
function
|
|
1553
|
+
function instanceOfReactControlProps(props) {
|
|
1554
|
+
return (typeof props === 'object' && ('state' in props || 'validators' in props));
|
|
1555
|
+
}
|
|
1556
|
+
function createReactControlProps(...argsProps) {
|
|
1557
|
+
if (argsProps.length < 1) {
|
|
1558
|
+
return { state: undefined, validators: undefined };
|
|
1559
|
+
}
|
|
1560
|
+
const [state, validators] = argsProps;
|
|
1561
|
+
if (argsProps.length < 2 && instanceOfReactControlProps(state)) {
|
|
1562
|
+
return state;
|
|
1563
|
+
}
|
|
1564
|
+
return { state: state, validators };
|
|
1565
|
+
}
|
|
1566
|
+
function useReactControl(controlProps, controlValidators) {
|
|
1567
|
+
const props = createReactControlProps(controlProps, controlValidators);
|
|
1542
1568
|
const [state, setCurrentState] = useState(props.state);
|
|
1543
1569
|
const [value, setValue] = useState(props.state);
|
|
1544
1570
|
const [touched, setTouched] = useState(props.touched || false);
|
|
@@ -1652,9 +1678,9 @@ const VISIBILITY$1 = {
|
|
|
1652
1678
|
};
|
|
1653
1679
|
function RlsDatePicker({ automatic, date, formControl, disabled, maxDate, minDate, rlsTheme, onListener }) {
|
|
1654
1680
|
const dateInitial = formControl?.state || date || new Date();
|
|
1655
|
-
const yearControl = useReactControl(
|
|
1656
|
-
const dayControl = useReactControl(
|
|
1657
|
-
const monthControl = useReactControl(
|
|
1681
|
+
const yearControl = useReactControl(dateInitial.getFullYear());
|
|
1682
|
+
const dayControl = useReactControl(dateInitial.getDate());
|
|
1683
|
+
const monthControl = useReactControl(dateInitial.getMonth());
|
|
1658
1684
|
const [value, setValue] = useState(dateInitial);
|
|
1659
1685
|
const [{ day, month, year }, setVisibility] = useState(VISIBILITY$1.DAY);
|
|
1660
1686
|
const title = formatDate(value, FORMAT_DESCRIPTION);
|
|
@@ -1752,7 +1778,7 @@ function RlsDateField({ children, date, disabled, formControl, maxDate, minDate,
|
|
|
1752
1778
|
setShow(true);
|
|
1753
1779
|
}
|
|
1754
1780
|
}
|
|
1755
|
-
return (jsxs("div", { className: "rls-date-field", "rls-theme": rlsTheme, children: [jsxs("div", { className: renderClassStatus('rls-box-field', { disabled }), children: [children && jsx("label", { className: "rls-box-field__label", children: children }), jsx("div", { className: "rls-box-field__component", children: jsxs("div", { className: "rls-box-field__body", children: [jsx("input", { className: "rls-date-field__control", type: "text", value: description, readOnly: true, placeholder: placeholder, onClick: onClickInput, disabled: disabled }), jsx("button", { className: "rls-date-field__action", onClick: onClean, disabled: disabled, children: jsx(RlsIcon, { value: value ? 'trash-2' : 'calendar' }) })] }) }), formControl?.touched && formControl?.error && (jsx("div", { className: "rls-box-field__error", children: jsx(RlsMessageIcon, { icon: "alert-triangle", rlsTheme: "danger", children: formControl.error.message }) }))] }), jsx(RlsModal, { visible: show, children: jsx(RlsDatePicker, { formControl: formControl, date: date, disabled: disabled, maxDate: maxDate, minDate: minDate, onListener: ({ value, type }) => {
|
|
1781
|
+
return (jsxs("div", { className: "rls-date-field", "rls-theme": rlsTheme, children: [jsxs("div", { className: renderClassStatus('rls-box-field', { disabled }), children: [children && jsx("label", { className: "rls-box-field__label", children: children }), jsx("div", { className: "rls-box-field__component", children: jsxs("div", { className: "rls-box-field__body", children: [jsx("input", { className: "rls-date-field__control", type: "text", value: description, readOnly: true, placeholder: placeholder, onClick: onClickInput, disabled: disabled }), jsx("button", { className: "rls-date-field__action", onClick: onClean, disabled: disabled, children: jsx(RlsIcon, { value: value ? 'trash-2' : 'calendar' }) })] }) }), formControl?.touched && formControl?.error && (jsx("div", { className: "rls-box-field__error", children: jsx(RlsMessageIcon, { icon: "alert-triangle", rlsTheme: "danger", children: formControl.error.message }) }))] }), jsx(RlsModal, { visible: show, rlsTheme: rlsTheme, children: jsx(RlsDatePicker, { formControl: formControl, date: date, disabled: disabled, maxDate: maxDate, minDate: minDate, onListener: ({ value, type }) => {
|
|
1756
1782
|
if (type !== PickerListenerType.Cancel) {
|
|
1757
1783
|
onChange(value, true);
|
|
1758
1784
|
}
|
|
@@ -1785,9 +1811,9 @@ const VISIBILITY = {
|
|
|
1785
1811
|
function RlsDateRangePicker({ automatic, date: datePicker, disabled, formControl, maxDate, minDate, rlsTheme, onListener }) {
|
|
1786
1812
|
const dateInitial = normalizeMinTime(datePicker || new Date());
|
|
1787
1813
|
const rangeInitial = formControl?.state || DateRange.now();
|
|
1788
|
-
const yearControl = useReactControl(
|
|
1789
|
-
const monthControl = useReactControl(
|
|
1790
|
-
const dayControl = useReactControl(
|
|
1814
|
+
const yearControl = useReactControl(dateInitial.getFullYear());
|
|
1815
|
+
const monthControl = useReactControl(dateInitial.getMonth());
|
|
1816
|
+
const dayControl = useReactControl(rangeInitial);
|
|
1791
1817
|
const [value, setValue] = useState(rangeInitial);
|
|
1792
1818
|
const [date, setDate] = useState(dateInitial);
|
|
1793
1819
|
const [{ day, month, year }, setVisibility] = useState(VISIBILITY.DAY);
|
|
@@ -1862,7 +1888,7 @@ function RlsDateRangeField({ children, date: datePicker, disabled, formControl,
|
|
|
1862
1888
|
setShow(true);
|
|
1863
1889
|
}
|
|
1864
1890
|
}
|
|
1865
|
-
return (jsxs("div", { className: "rls-date-field", "rls-theme": rlsTheme, children: [jsxs("div", { className: "rls-box-field", children: [children && jsx("label", { className: "rls-box-field__label", children: children }), jsx("div", { className: "rls-box-field__component", children: jsxs("div", { className: "rls-box-field__body", children: [jsx("input", { className: "rls-date-field__control", type: "text", value: description, readOnly: true, placeholder: placeholder, onClick: onClickInput }), jsx("button", { className: "rls-date-field__action", onClick: onClickAction, children: jsx(RlsIcon, { value: value ? 'trash-2' : 'calendar' }) })] }) })] }), jsx(RlsModal, { visible: show, children: jsx(RlsDateRangePicker, { formControl: formControl, date: date, disabled: disabled, maxDate: maxDate, minDate: minDate, onListener: ({ value }) => {
|
|
1891
|
+
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 }) => {
|
|
1866
1892
|
if (value) {
|
|
1867
1893
|
setValue(value);
|
|
1868
1894
|
}
|