@ttoss/components 2.12.5 → 2.12.7
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/esm/DatePicker/index.js +44 -17
- package/package.json +4 -4
|
@@ -17,12 +17,18 @@ var DatePicker = /* @__PURE__ */__name(({
|
|
|
17
17
|
onChange
|
|
18
18
|
}) => {
|
|
19
19
|
const [date, setDate] = React.useState(value);
|
|
20
|
+
const [pickerSelection, setPickerSelection] = React.useState(value);
|
|
20
21
|
const [isOpen, setIsOpen] = React.useState(false);
|
|
21
22
|
const containerRef = React.useRef(null);
|
|
22
23
|
const isResettingRangeRef = React.useRef(false);
|
|
23
24
|
React.useEffect(() => {
|
|
24
25
|
setDate(value);
|
|
25
26
|
}, [value]);
|
|
27
|
+
React.useEffect(() => {
|
|
28
|
+
if (isOpen) {
|
|
29
|
+
setPickerSelection(date);
|
|
30
|
+
}
|
|
31
|
+
}, [isOpen, date]);
|
|
26
32
|
React.useEffect(() => {
|
|
27
33
|
const handleClickOutside = /* @__PURE__ */__name(event => {
|
|
28
34
|
if (containerRef.current && !containerRef.current.contains(event.target)) {
|
|
@@ -36,36 +42,50 @@ var DatePicker = /* @__PURE__ */__name(({
|
|
|
36
42
|
document.removeEventListener("mousedown", handleClickOutside);
|
|
37
43
|
};
|
|
38
44
|
}, [isOpen]);
|
|
39
|
-
const
|
|
45
|
+
const commitSelection = /* @__PURE__ */__name(range => {
|
|
40
46
|
setDate(range);
|
|
41
47
|
onChange?.(range);
|
|
42
|
-
}, "
|
|
48
|
+
}, "commitSelection");
|
|
43
49
|
const handlePresetClick = /* @__PURE__ */__name(preset => {
|
|
44
50
|
const range = preset.getValue();
|
|
45
|
-
|
|
51
|
+
commitSelection(range);
|
|
46
52
|
setIsOpen(false);
|
|
47
53
|
}, "handlePresetClick");
|
|
48
54
|
const handleDayPickerSelect = /* @__PURE__ */__name(selected => {
|
|
49
|
-
if (isResettingRangeRef.current && !selected) {
|
|
50
|
-
|
|
55
|
+
if (isResettingRangeRef.current && !selected && pickerSelection?.from && !pickerSelection?.to) {
|
|
56
|
+
commitSelection({
|
|
57
|
+
from: pickerSelection.from,
|
|
58
|
+
to: pickerSelection.from
|
|
59
|
+
});
|
|
60
|
+
setIsOpen(false);
|
|
51
61
|
return;
|
|
52
62
|
}
|
|
53
63
|
isResettingRangeRef.current = false;
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
64
|
+
const hadFullRange = date?.from && date?.to;
|
|
65
|
+
const hadPartialPicker = pickerSelection?.from && !pickerSelection?.to;
|
|
66
|
+
if (hadFullRange && !hadPartialPicker && selected?.from && selected?.to) {
|
|
67
|
+
const clickedDay = selected.from.getTime() === date?.from?.getTime() ? selected.to : selected.from;
|
|
68
|
+
setPickerSelection({
|
|
69
|
+
from: clickedDay,
|
|
70
|
+
to: void 0
|
|
71
|
+
});
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
setPickerSelection(selected);
|
|
75
|
+
if (selected?.from && selected?.to) {
|
|
76
|
+
commitSelection(selected);
|
|
77
|
+
setIsOpen(false);
|
|
78
|
+
} else if (!selected?.from && !selected?.to) {
|
|
79
|
+
commitSelection(void 0);
|
|
58
80
|
}
|
|
59
81
|
}, "handleDayPickerSelect");
|
|
60
82
|
const handleDayClick = /* @__PURE__ */__name(day => {
|
|
61
83
|
if (date?.from && date?.to) {
|
|
62
84
|
isResettingRangeRef.current = true;
|
|
63
|
-
|
|
85
|
+
setPickerSelection({
|
|
64
86
|
from: day,
|
|
65
87
|
to: void 0
|
|
66
88
|
});
|
|
67
|
-
} else {
|
|
68
|
-
setIsOpen(false);
|
|
69
89
|
}
|
|
70
90
|
}, "handleDayClick");
|
|
71
91
|
return /* @__PURE__ */React.createElement(Flex, {
|
|
@@ -242,16 +262,20 @@ var DatePicker = /* @__PURE__ */__name(({
|
|
|
242
262
|
border: "none",
|
|
243
263
|
fontSize: ["12px", "14px"],
|
|
244
264
|
width: ["32px", "36px"],
|
|
245
|
-
height: ["32px", "36px"]
|
|
265
|
+
height: ["32px", "36px"],
|
|
266
|
+
cursor: "pointer"
|
|
246
267
|
},
|
|
247
268
|
"& .rdp-range_start .rdp-day_button": {
|
|
248
|
-
backgroundColor: "action.background.
|
|
269
|
+
backgroundColor: "action.background.accent.default",
|
|
270
|
+
color: "black"
|
|
249
271
|
},
|
|
250
272
|
"& .rdp-range_end .rdp-day_button": {
|
|
251
|
-
backgroundColor: "action.background.
|
|
273
|
+
backgroundColor: "action.background.accent.default",
|
|
274
|
+
color: "black"
|
|
252
275
|
},
|
|
253
276
|
"& .rdp-day_button:hover": {
|
|
254
|
-
backgroundColor: "action.background.
|
|
277
|
+
backgroundColor: "action.background.primary.default",
|
|
278
|
+
color: "action.text.primary.default"
|
|
255
279
|
},
|
|
256
280
|
"& .rdp-day_selected": {
|
|
257
281
|
backgroundColor: "action.background.accent.default",
|
|
@@ -289,7 +313,10 @@ var DatePicker = /* @__PURE__ */__name(({
|
|
|
289
313
|
}, /* @__PURE__ */React.createElement(DayPicker, {
|
|
290
314
|
mode: "range",
|
|
291
315
|
locale: ptBR,
|
|
292
|
-
selected:
|
|
316
|
+
selected: pickerSelection?.from ? {
|
|
317
|
+
from: pickerSelection.from,
|
|
318
|
+
to: pickerSelection.to ?? pickerSelection.from
|
|
319
|
+
} : void 0,
|
|
293
320
|
onSelect: /* @__PURE__ */__name(selected => {
|
|
294
321
|
return handleDayPickerSelect(selected);
|
|
295
322
|
}, "onSelect"),
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ttoss/components",
|
|
3
|
-
"version": "2.12.
|
|
3
|
+
"version": "2.12.7",
|
|
4
4
|
"description": "React components for ttoss ecosystem.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "ttoss",
|
|
@@ -125,9 +125,9 @@
|
|
|
125
125
|
},
|
|
126
126
|
"peerDependencies": {
|
|
127
127
|
"react": ">=16.8.0",
|
|
128
|
-
"@ttoss/ui": "^6.5.1",
|
|
129
128
|
"@ttoss/react-hooks": "^2.1.12",
|
|
130
129
|
"@ttoss/react-i18n": "^2.0.26",
|
|
130
|
+
"@ttoss/ui": "^6.5.1",
|
|
131
131
|
"@ttoss/react-icons": "^0.5.7"
|
|
132
132
|
},
|
|
133
133
|
"devDependencies": {
|
|
@@ -138,11 +138,11 @@
|
|
|
138
138
|
"tsup": "^8.5.1",
|
|
139
139
|
"tsx": "^4.21.0",
|
|
140
140
|
"@ttoss/config": "^1.35.12",
|
|
141
|
+
"@ttoss/i18n-cli": "^0.7.38",
|
|
141
142
|
"@ttoss/react-hooks": "^2.1.12",
|
|
142
|
-
"@ttoss/react-icons": "^0.5.7",
|
|
143
143
|
"@ttoss/react-i18n": "^2.0.26",
|
|
144
|
-
"@ttoss/i18n-cli": "^0.7.38",
|
|
145
144
|
"@ttoss/test-utils": "^4.0.3",
|
|
145
|
+
"@ttoss/react-icons": "^0.5.7",
|
|
146
146
|
"@ttoss/ui": "^6.5.1"
|
|
147
147
|
},
|
|
148
148
|
"keywords": [
|