venice-ui 2.4.1 → 2.4.2
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/components/DatePicker/Calendar.js +43 -21
- package/dist/cjs/components/DatePicker/CalendarContent.js +3 -18
- package/dist/cjs/components/DatePicker/CalendarHeader.js +9 -3
- package/dist/cjs/components/DatePicker/DatePicker.js +2 -2
- package/dist/esm/components/DatePicker/Calendar.js +43 -21
- package/dist/esm/components/DatePicker/CalendarContent.js +3 -18
- package/dist/esm/components/DatePicker/CalendarHeader.js +10 -4
- package/dist/esm/components/DatePicker/DatePicker.js +2 -2
- package/dist/types/components/DatePicker/Calendar.d.ts +12 -1
- package/dist/types/components/DatePicker/CalendarContent.d.ts +7 -2
- package/dist/types/components/DatePicker/CalendarHeader.d.ts +5 -0
- package/dist/types/components/DatePicker/DatePicker.d.ts +11 -0
- package/package.json +1 -1
|
@@ -31,14 +31,20 @@ const CalendarHeader_1 = require("./CalendarHeader");
|
|
|
31
31
|
const date_fns_1 = require("date-fns");
|
|
32
32
|
const CalendarContent_1 = require("./CalendarContent");
|
|
33
33
|
const ButtonsFooter_1 = require("../ButtonsFooter");
|
|
34
|
-
const Calendar = ({ value, top, left, size, handleClose, handleSelect, zIndex }) => {
|
|
35
|
-
const
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
34
|
+
const Calendar = ({ value, top, left, size, handleClose, handleSelect, isAdvance = false, autoConfirm: autoConfirmProp, labels = { close: 'Close', confirm: 'Select', today: 'Today' }, localeLabels, zIndex }) => {
|
|
35
|
+
const defaultLocale = {
|
|
36
|
+
months: [
|
|
37
|
+
'January', 'February', 'March', 'April', 'May', 'June',
|
|
38
|
+
'July', 'August', 'September', 'October', 'November', 'December'
|
|
39
|
+
],
|
|
40
|
+
weekdaysShort: ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'],
|
|
41
|
+
firstDayOfWeek: 0,
|
|
42
|
+
};
|
|
43
|
+
const effectiveLocale = {
|
|
44
|
+
months: (localeLabels && localeLabels.months) || defaultLocale.months,
|
|
45
|
+
weekdaysShort: (localeLabels && localeLabels.weekdaysShort) || defaultLocale.weekdaysShort,
|
|
46
|
+
firstDayOfWeek: (localeLabels && typeof localeLabels.firstDayOfWeek === 'number') ? localeLabels.firstDayOfWeek : defaultLocale.firstDayOfWeek,
|
|
47
|
+
};
|
|
42
48
|
const setYearScope = (date) => {
|
|
43
49
|
const year = (0, date_fns_1.getYear)(date);
|
|
44
50
|
const yearIndex = year % 12;
|
|
@@ -46,15 +52,28 @@ const Calendar = ({ value, top, left, size, handleClose, handleSelect, zIndex })
|
|
|
46
52
|
const futureYears = Array.from({ length: 12 - yearIndex - 1 }, (_, i) => year + (i + 1));
|
|
47
53
|
return [...pastYears, year, ...futureYears];
|
|
48
54
|
};
|
|
55
|
+
const effectiveAutoConfirm = isAdvance
|
|
56
|
+
? false
|
|
57
|
+
: (typeof autoConfirmProp !== 'undefined' ? Boolean(autoConfirmProp) : true);
|
|
58
|
+
const [calendarSettings, updateCalendarSettings] = (0, react_1.useState)(() => {
|
|
59
|
+
const initialDate = value !== undefined ? new Date(value) : new Date();
|
|
60
|
+
return {
|
|
61
|
+
mode: 'day',
|
|
62
|
+
value: (0, date_fns_1.getTime)(initialDate),
|
|
63
|
+
date: initialDate,
|
|
64
|
+
yearsScope: setYearScope(initialDate),
|
|
65
|
+
};
|
|
66
|
+
});
|
|
67
|
+
const [selectedDate, setSellectedDate] = (0, react_1.useState)(() => (value !== undefined ? new Date(value) : new Date()));
|
|
49
68
|
(0, react_1.useEffect)(() => {
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
}, [
|
|
69
|
+
updateCalendarSettings((prev) => ({
|
|
70
|
+
...prev,
|
|
71
|
+
value: (0, date_fns_1.getTime)(selectedDate),
|
|
72
|
+
date: selectedDate,
|
|
73
|
+
yearsScope: setYearScope(selectedDate),
|
|
74
|
+
}));
|
|
75
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
76
|
+
}, [selectedDate]);
|
|
58
77
|
const setPeriod = (mode, forward) => {
|
|
59
78
|
const operations = {
|
|
60
79
|
day: forward ? date_fns_1.addMonths : date_fns_1.subMonths,
|
|
@@ -72,11 +91,14 @@ const Calendar = ({ value, top, left, size, handleClose, handleSelect, zIndex })
|
|
|
72
91
|
});
|
|
73
92
|
};
|
|
74
93
|
const setNewDate = (newDate) => {
|
|
75
|
-
console.log('setNewDate', newDate);
|
|
76
94
|
setSellectedDate(newDate);
|
|
95
|
+
if (effectiveAutoConfirm && handleSelect) {
|
|
96
|
+
handleSelect((0, date_fns_1.getTime)(newDate));
|
|
97
|
+
handleClose && handleClose();
|
|
98
|
+
}
|
|
77
99
|
};
|
|
78
100
|
const confirmDate = () => {
|
|
79
|
-
handleSelect((0, date_fns_1.getTime)(
|
|
101
|
+
handleSelect((0, date_fns_1.getTime)(selectedDate));
|
|
80
102
|
};
|
|
81
103
|
const setToday = () => {
|
|
82
104
|
setSellectedDate(new Date());
|
|
@@ -84,9 +106,9 @@ const Calendar = ({ value, top, left, size, handleClose, handleSelect, zIndex })
|
|
|
84
106
|
return (react_1.default.createElement(react_1.default.Fragment, null,
|
|
85
107
|
react_1.default.createElement(DatePiocker_styles_1.CalendarWrapper, { top: top, left: left, size: size, zIndex: zIndex },
|
|
86
108
|
react_1.default.createElement(Aligment_1.Aligment, { direction: "row" },
|
|
87
|
-
react_1.default.createElement(CalendarHeader_1.CalendarHeader, { mode: calendarSettings.mode, date: calendarSettings.date, yearsScope: calendarSettings.yearsScope, handleChange: setPeriod, handleSelect: setMode }),
|
|
88
|
-
react_1.default.createElement(CalendarContent_1.CalendarContent, { date: calendarSettings.date, mode: calendarSettings.mode, handleChange: setNewDate, changeMode: setMode, yearsScope: calendarSettings.yearsScope }),
|
|
89
|
-
react_1.default.createElement(ButtonsFooter_1.ButtonsFooter, { handleClose: handleClose, handleConfirm: confirmDate, handleAdditional: setToday, labelClose: '
|
|
109
|
+
react_1.default.createElement(CalendarHeader_1.CalendarHeader, { mode: calendarSettings.mode, date: calendarSettings.date, yearsScope: calendarSettings.yearsScope, handleChange: setPeriod, handleSelect: setMode, localeLabels: effectiveLocale }),
|
|
110
|
+
react_1.default.createElement(CalendarContent_1.CalendarContent, { date: calendarSettings.date, mode: calendarSettings.mode, handleChange: setNewDate, changeMode: setMode, yearsScope: calendarSettings.yearsScope, localeLabels: effectiveLocale }),
|
|
111
|
+
isAdvance && (react_1.default.createElement(ButtonsFooter_1.ButtonsFooter, { handleClose: handleClose, handleConfirm: confirmDate, handleAdditional: setToday, labelClose: labels.close || 'Close', labelConfirm: labels.confirm || 'Select', labelAdditional: labels.today || 'Today', additionaNormalMode: true })))),
|
|
90
112
|
react_1.default.createElement(DatePiocker_styles_1.CalendarOverlay, { zIndex: zIndex })));
|
|
91
113
|
};
|
|
92
114
|
exports.Calendar = Calendar;
|
|
@@ -28,7 +28,7 @@ const react_1 = __importStar(require("react"));
|
|
|
28
28
|
const DatePiocker_styles_1 = require("./DatePiocker.styles");
|
|
29
29
|
const date_fns_1 = require("date-fns");
|
|
30
30
|
const Aligment_1 = require("../Aligment");
|
|
31
|
-
const CalendarContent = ({ date, handleChange, changeMode,
|
|
31
|
+
const CalendarContent = ({ date, mode, handleChange, changeMode, yearsScope, localeLabels, }) => {
|
|
32
32
|
const [days, setDays] = (0, react_1.useState)([]);
|
|
33
33
|
const firstDayOfMonth = (0, date_fns_1.startOfMonth)(date);
|
|
34
34
|
const daysInMonth = (0, date_fns_1.getDaysInMonth)(date);
|
|
@@ -64,28 +64,13 @@ const CalendarContent = ({ date, handleChange, changeMode, mode, yearsScope, })
|
|
|
64
64
|
changeMode('month');
|
|
65
65
|
}
|
|
66
66
|
};
|
|
67
|
-
const daysName = ['Pon', 'Wt', 'Śr', 'Cz', 'P', 'Sob', 'Nd'];
|
|
68
|
-
const monthNames = [
|
|
69
|
-
'styczeń',
|
|
70
|
-
'luty',
|
|
71
|
-
'marzec',
|
|
72
|
-
'kwiecień',
|
|
73
|
-
'maj',
|
|
74
|
-
'czerwiec',
|
|
75
|
-
'lipiec',
|
|
76
|
-
'sierpień',
|
|
77
|
-
'wrzesień',
|
|
78
|
-
'październik',
|
|
79
|
-
'listopad',
|
|
80
|
-
'grudzień',
|
|
81
|
-
];
|
|
82
67
|
return (react_1.default.createElement(DatePiocker_styles_1.CalendarContentWrapper, null,
|
|
83
68
|
mode === 'day' && (react_1.default.createElement(Aligment_1.Aligment, { wrap: "wrap" },
|
|
84
|
-
react_1.default.createElement(DatePiocker_styles_1.DaysHeader, null,
|
|
69
|
+
react_1.default.createElement(DatePiocker_styles_1.DaysHeader, null, localeLabels?.weekdaysShort?.map((_item) => (react_1.default.createElement(DatePiocker_styles_1.DayLabelWrapper, null,
|
|
85
70
|
react_1.default.createElement(DatePiocker_styles_1.DayLabel, null, _item))))),
|
|
86
71
|
react_1.default.createElement(DatePiocker_styles_1.DaysContent, null, days.map((_day) => (react_1.default.createElement(DatePiocker_styles_1.DayWrapper, null,
|
|
87
72
|
react_1.default.createElement(DatePiocker_styles_1.Day, { active: parseInt(_day) === (0, date_fns_1.getDate)(date), haveContent: _day !== '', onClick: () => setDay(parseInt(_day)) }, _day))))))),
|
|
88
|
-
mode === 'month' && (react_1.default.createElement(Aligment_1.Aligment, { wrap: "wrap" },
|
|
73
|
+
mode === 'month' && (react_1.default.createElement(Aligment_1.Aligment, { wrap: "wrap" }, localeLabels?.months?.map((_month, index) => (react_1.default.createElement(DatePiocker_styles_1.MonthWrapper, null,
|
|
89
74
|
react_1.default.createElement(DatePiocker_styles_1.Month, { active: index === (0, date_fns_1.getMonth)(date), onClick: () => handleSetMonth(index) }, _month)))))),
|
|
90
75
|
mode === 'year' && (react_1.default.createElement(Aligment_1.Aligment, { wrap: "wrap" }, yearsScope.map((_year) => (react_1.default.createElement(DatePiocker_styles_1.MonthWrapper, null,
|
|
91
76
|
react_1.default.createElement(DatePiocker_styles_1.Month, { active: _year === (0, date_fns_1.getYear)(date), onClick: () => handleSetYear(_year) }, _year))))))));
|
|
@@ -10,8 +10,7 @@ const Aligment_1 = require("../Aligment");
|
|
|
10
10
|
const Icons_1 = require("../Icons");
|
|
11
11
|
const Typography_1 = require("../Typography");
|
|
12
12
|
const date_fns_1 = require("date-fns");
|
|
13
|
-
const
|
|
14
|
-
const CalendarHeader = ({ date, mode, yearsScope, handleChange, handleSelect, }) => {
|
|
13
|
+
const CalendarHeader = ({ date, mode, yearsScope, handleChange, handleSelect, localeLabels, }) => {
|
|
15
14
|
const prev = () => {
|
|
16
15
|
handleChange(mode, false);
|
|
17
16
|
};
|
|
@@ -21,11 +20,18 @@ const CalendarHeader = ({ date, mode, yearsScope, handleChange, handleSelect, })
|
|
|
21
20
|
const setMode = (mode) => {
|
|
22
21
|
handleSelect(mode);
|
|
23
22
|
};
|
|
23
|
+
const defaultMonths = [
|
|
24
|
+
'January', 'February', 'March', 'April', 'May', 'June',
|
|
25
|
+
'July', 'August', 'September', 'October', 'November', 'December'
|
|
26
|
+
];
|
|
27
|
+
const months = (localeLabels && localeLabels.months && localeLabels.months.length === 12)
|
|
28
|
+
? localeLabels.months
|
|
29
|
+
: defaultMonths;
|
|
24
30
|
return (react_1.default.createElement(DatePiocker_styles_1.CalendarHeaderWrapper, null,
|
|
25
31
|
react_1.default.createElement(Aligment_1.Aligment, null,
|
|
26
32
|
react_1.default.createElement(Icons_1.Icon, { name: 'back', onClick: prev }),
|
|
27
33
|
react_1.default.createElement(DatePiocker_styles_1.CalendarHeaderTexts, null,
|
|
28
|
-
mode === 'day' && (react_1.default.createElement(Typography_1.Text, { action: true, onClick: () => setMode('month') },
|
|
34
|
+
mode === 'day' && (react_1.default.createElement(Typography_1.Text, { action: true, onClick: () => setMode('month') }, months[date.getMonth()])),
|
|
29
35
|
mode === 'year' ? (react_1.default.createElement(Typography_1.Text, null, `${yearsScope[0]} - ${yearsScope[yearsScope.length - 1]}`)) : (react_1.default.createElement(Typography_1.Text, { action: true, onClick: () => setMode('year') }, (0, date_fns_1.getYear)(date)))),
|
|
30
36
|
react_1.default.createElement(Icons_1.Icon, { name: 'forward', onClick: next }))));
|
|
31
37
|
};
|
|
@@ -35,7 +35,7 @@ const react_dom_1 = require("react-dom");
|
|
|
35
35
|
const Calendar_1 = require("./Calendar");
|
|
36
36
|
const date_fns_1 = require("date-fns");
|
|
37
37
|
const Icons_1 = require("../Icons");
|
|
38
|
-
const DatePicker = ({ label, labelPosition = 'top', value, name, disabled = false, size = 'medium', width, error, errorMsg, theme = Theme_1.mainTheme, readOnly = false, position = 'left', placeholder = 'Select date', handleChange, zIndex }) => {
|
|
38
|
+
const DatePicker = ({ label, labelPosition = 'top', value, name, disabled = false, size = 'medium', width, error, errorMsg, theme = Theme_1.mainTheme, readOnly = false, position = 'left', placeholder = 'Select date', handleChange, zIndex, calendarLabels, localeLabels, isAdvance = true }) => {
|
|
39
39
|
const [open, toogleOpen] = (0, react_1.useState)(false);
|
|
40
40
|
const sourceRef = (0, react_1.useRef)(null);
|
|
41
41
|
const [dropdownStyles, setDropdownStyles] = (0, react_1.useState)({
|
|
@@ -71,6 +71,6 @@ const DatePicker = ({ label, labelPosition = 'top', value, name, disabled = fals
|
|
|
71
71
|
value && (react_1.default.createElement(Input_1.EyeIconWrapper, { size: size },
|
|
72
72
|
react_1.default.createElement(Icons_1.Icon, { name: 'close', size: 24, onClick: clearDate, iconColor: theme.inputDefaultTextColor, iconBgHoverColor: "transparent" }))),
|
|
73
73
|
open &&
|
|
74
|
-
(0, react_dom_1.createPortal)(react_1.default.createElement(Calendar_1.Calendar, { top: dropdownStyles.top, left: dropdownStyles.left, size: size, handleClose: () => toogleOpen(false),
|
|
74
|
+
(0, react_dom_1.createPortal)(react_1.default.createElement(Calendar_1.Calendar, { top: dropdownStyles.top, left: dropdownStyles.left, size: size, handleClose: () => toogleOpen(false), value: value, handleSelect: onSubmit, isAdvance: isAdvance, zIndex: zIndex, labels: calendarLabels, localeLabels: localeLabels }), document.body)))))));
|
|
75
75
|
};
|
|
76
76
|
exports.DatePicker = DatePicker;
|
|
@@ -5,14 +5,20 @@ import { CalendarHeader } from './CalendarHeader';
|
|
|
5
5
|
import { addMonths, addYears, getTime, getYear, subMonths, subYears, } from 'date-fns';
|
|
6
6
|
import { CalendarContent } from './CalendarContent';
|
|
7
7
|
import { ButtonsFooter } from '../ButtonsFooter';
|
|
8
|
-
export const Calendar = ({ value, top, left, size, handleClose, handleSelect, zIndex }) => {
|
|
9
|
-
const
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
8
|
+
export const Calendar = ({ value, top, left, size, handleClose, handleSelect, isAdvance = false, autoConfirm: autoConfirmProp, labels = { close: 'Close', confirm: 'Select', today: 'Today' }, localeLabels, zIndex }) => {
|
|
9
|
+
const defaultLocale = {
|
|
10
|
+
months: [
|
|
11
|
+
'January', 'February', 'March', 'April', 'May', 'June',
|
|
12
|
+
'July', 'August', 'September', 'October', 'November', 'December'
|
|
13
|
+
],
|
|
14
|
+
weekdaysShort: ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'],
|
|
15
|
+
firstDayOfWeek: 0,
|
|
16
|
+
};
|
|
17
|
+
const effectiveLocale = {
|
|
18
|
+
months: (localeLabels && localeLabels.months) || defaultLocale.months,
|
|
19
|
+
weekdaysShort: (localeLabels && localeLabels.weekdaysShort) || defaultLocale.weekdaysShort,
|
|
20
|
+
firstDayOfWeek: (localeLabels && typeof localeLabels.firstDayOfWeek === 'number') ? localeLabels.firstDayOfWeek : defaultLocale.firstDayOfWeek,
|
|
21
|
+
};
|
|
16
22
|
const setYearScope = (date) => {
|
|
17
23
|
const year = getYear(date);
|
|
18
24
|
const yearIndex = year % 12;
|
|
@@ -20,15 +26,28 @@ export const Calendar = ({ value, top, left, size, handleClose, handleSelect, zI
|
|
|
20
26
|
const futureYears = Array.from({ length: 12 - yearIndex - 1 }, (_, i) => year + (i + 1));
|
|
21
27
|
return [...pastYears, year, ...futureYears];
|
|
22
28
|
};
|
|
29
|
+
const effectiveAutoConfirm = isAdvance
|
|
30
|
+
? false
|
|
31
|
+
: (typeof autoConfirmProp !== 'undefined' ? Boolean(autoConfirmProp) : true);
|
|
32
|
+
const [calendarSettings, updateCalendarSettings] = useState(() => {
|
|
33
|
+
const initialDate = value !== undefined ? new Date(value) : new Date();
|
|
34
|
+
return {
|
|
35
|
+
mode: 'day',
|
|
36
|
+
value: getTime(initialDate),
|
|
37
|
+
date: initialDate,
|
|
38
|
+
yearsScope: setYearScope(initialDate),
|
|
39
|
+
};
|
|
40
|
+
});
|
|
41
|
+
const [selectedDate, setSellectedDate] = useState(() => (value !== undefined ? new Date(value) : new Date()));
|
|
23
42
|
useEffect(() => {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
}, [
|
|
43
|
+
updateCalendarSettings((prev) => ({
|
|
44
|
+
...prev,
|
|
45
|
+
value: getTime(selectedDate),
|
|
46
|
+
date: selectedDate,
|
|
47
|
+
yearsScope: setYearScope(selectedDate),
|
|
48
|
+
}));
|
|
49
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
50
|
+
}, [selectedDate]);
|
|
32
51
|
const setPeriod = (mode, forward) => {
|
|
33
52
|
const operations = {
|
|
34
53
|
day: forward ? addMonths : subMonths,
|
|
@@ -46,11 +65,14 @@ export const Calendar = ({ value, top, left, size, handleClose, handleSelect, zI
|
|
|
46
65
|
});
|
|
47
66
|
};
|
|
48
67
|
const setNewDate = (newDate) => {
|
|
49
|
-
console.log('setNewDate', newDate);
|
|
50
68
|
setSellectedDate(newDate);
|
|
69
|
+
if (effectiveAutoConfirm && handleSelect) {
|
|
70
|
+
handleSelect(getTime(newDate));
|
|
71
|
+
handleClose && handleClose();
|
|
72
|
+
}
|
|
51
73
|
};
|
|
52
74
|
const confirmDate = () => {
|
|
53
|
-
handleSelect(getTime(
|
|
75
|
+
handleSelect(getTime(selectedDate));
|
|
54
76
|
};
|
|
55
77
|
const setToday = () => {
|
|
56
78
|
setSellectedDate(new Date());
|
|
@@ -58,8 +80,8 @@ export const Calendar = ({ value, top, left, size, handleClose, handleSelect, zI
|
|
|
58
80
|
return (React.createElement(React.Fragment, null,
|
|
59
81
|
React.createElement(CalendarWrapper, { top: top, left: left, size: size, zIndex: zIndex },
|
|
60
82
|
React.createElement(Aligment, { direction: "row" },
|
|
61
|
-
React.createElement(CalendarHeader, { mode: calendarSettings.mode, date: calendarSettings.date, yearsScope: calendarSettings.yearsScope, handleChange: setPeriod, handleSelect: setMode }),
|
|
62
|
-
React.createElement(CalendarContent, { date: calendarSettings.date, mode: calendarSettings.mode, handleChange: setNewDate, changeMode: setMode, yearsScope: calendarSettings.yearsScope }),
|
|
63
|
-
React.createElement(ButtonsFooter, { handleClose: handleClose, handleConfirm: confirmDate, handleAdditional: setToday, labelClose: '
|
|
83
|
+
React.createElement(CalendarHeader, { mode: calendarSettings.mode, date: calendarSettings.date, yearsScope: calendarSettings.yearsScope, handleChange: setPeriod, handleSelect: setMode, localeLabels: effectiveLocale }),
|
|
84
|
+
React.createElement(CalendarContent, { date: calendarSettings.date, mode: calendarSettings.mode, handleChange: setNewDate, changeMode: setMode, yearsScope: calendarSettings.yearsScope, localeLabels: effectiveLocale }),
|
|
85
|
+
isAdvance && (React.createElement(ButtonsFooter, { handleClose: handleClose, handleConfirm: confirmDate, handleAdditional: setToday, labelClose: labels.close || 'Close', labelConfirm: labels.confirm || 'Select', labelAdditional: labels.today || 'Today', additionaNormalMode: true })))),
|
|
64
86
|
React.createElement(CalendarOverlay, { zIndex: zIndex })));
|
|
65
87
|
};
|
|
@@ -2,7 +2,7 @@ import React, { useState, useEffect } from 'react';
|
|
|
2
2
|
import { CalendarContentWrapper, Day, DayLabel, DayLabelWrapper, DaysContent, DaysHeader, DayWrapper, Month, MonthWrapper, } from './DatePiocker.styles';
|
|
3
3
|
import { getDate, getDay, getDaysInMonth, getMonth, getYear, setDate, setMonth, setYear, startOfMonth, } from 'date-fns';
|
|
4
4
|
import { Aligment } from '../Aligment';
|
|
5
|
-
export const CalendarContent = ({ date, handleChange, changeMode,
|
|
5
|
+
export const CalendarContent = ({ date, mode, handleChange, changeMode, yearsScope, localeLabels, }) => {
|
|
6
6
|
const [days, setDays] = useState([]);
|
|
7
7
|
const firstDayOfMonth = startOfMonth(date);
|
|
8
8
|
const daysInMonth = getDaysInMonth(date);
|
|
@@ -38,28 +38,13 @@ export const CalendarContent = ({ date, handleChange, changeMode, mode, yearsSco
|
|
|
38
38
|
changeMode('month');
|
|
39
39
|
}
|
|
40
40
|
};
|
|
41
|
-
const daysName = ['Pon', 'Wt', 'Śr', 'Cz', 'P', 'Sob', 'Nd'];
|
|
42
|
-
const monthNames = [
|
|
43
|
-
'styczeń',
|
|
44
|
-
'luty',
|
|
45
|
-
'marzec',
|
|
46
|
-
'kwiecień',
|
|
47
|
-
'maj',
|
|
48
|
-
'czerwiec',
|
|
49
|
-
'lipiec',
|
|
50
|
-
'sierpień',
|
|
51
|
-
'wrzesień',
|
|
52
|
-
'październik',
|
|
53
|
-
'listopad',
|
|
54
|
-
'grudzień',
|
|
55
|
-
];
|
|
56
41
|
return (React.createElement(CalendarContentWrapper, null,
|
|
57
42
|
mode === 'day' && (React.createElement(Aligment, { wrap: "wrap" },
|
|
58
|
-
React.createElement(DaysHeader, null,
|
|
43
|
+
React.createElement(DaysHeader, null, localeLabels?.weekdaysShort?.map((_item) => (React.createElement(DayLabelWrapper, null,
|
|
59
44
|
React.createElement(DayLabel, null, _item))))),
|
|
60
45
|
React.createElement(DaysContent, null, days.map((_day) => (React.createElement(DayWrapper, null,
|
|
61
46
|
React.createElement(Day, { active: parseInt(_day) === getDate(date), haveContent: _day !== '', onClick: () => setDay(parseInt(_day)) }, _day))))))),
|
|
62
|
-
mode === 'month' && (React.createElement(Aligment, { wrap: "wrap" },
|
|
47
|
+
mode === 'month' && (React.createElement(Aligment, { wrap: "wrap" }, localeLabels?.months?.map((_month, index) => (React.createElement(MonthWrapper, null,
|
|
63
48
|
React.createElement(Month, { active: index === getMonth(date), onClick: () => handleSetMonth(index) }, _month)))))),
|
|
64
49
|
mode === 'year' && (React.createElement(Aligment, { wrap: "wrap" }, yearsScope.map((_year) => (React.createElement(MonthWrapper, null,
|
|
65
50
|
React.createElement(Month, { active: _year === getYear(date), onClick: () => handleSetYear(_year) }, _year))))))));
|
|
@@ -3,9 +3,8 @@ import { CalendarHeaderTexts, CalendarHeaderWrapper, } from './DatePiocker.style
|
|
|
3
3
|
import { Aligment } from '../Aligment';
|
|
4
4
|
import { Icon } from '../Icons';
|
|
5
5
|
import { Text } from '../Typography';
|
|
6
|
-
import {
|
|
7
|
-
|
|
8
|
-
export const CalendarHeader = ({ date, mode, yearsScope, handleChange, handleSelect, }) => {
|
|
6
|
+
import { getYear } from 'date-fns';
|
|
7
|
+
export const CalendarHeader = ({ date, mode, yearsScope, handleChange, handleSelect, localeLabels, }) => {
|
|
9
8
|
const prev = () => {
|
|
10
9
|
handleChange(mode, false);
|
|
11
10
|
};
|
|
@@ -15,11 +14,18 @@ export const CalendarHeader = ({ date, mode, yearsScope, handleChange, handleSel
|
|
|
15
14
|
const setMode = (mode) => {
|
|
16
15
|
handleSelect(mode);
|
|
17
16
|
};
|
|
17
|
+
const defaultMonths = [
|
|
18
|
+
'January', 'February', 'March', 'April', 'May', 'June',
|
|
19
|
+
'July', 'August', 'September', 'October', 'November', 'December'
|
|
20
|
+
];
|
|
21
|
+
const months = (localeLabels && localeLabels.months && localeLabels.months.length === 12)
|
|
22
|
+
? localeLabels.months
|
|
23
|
+
: defaultMonths;
|
|
18
24
|
return (React.createElement(CalendarHeaderWrapper, null,
|
|
19
25
|
React.createElement(Aligment, null,
|
|
20
26
|
React.createElement(Icon, { name: 'back', onClick: prev }),
|
|
21
27
|
React.createElement(CalendarHeaderTexts, null,
|
|
22
|
-
mode === 'day' && (React.createElement(Text, { action: true, onClick: () => setMode('month') },
|
|
28
|
+
mode === 'day' && (React.createElement(Text, { action: true, onClick: () => setMode('month') }, months[date.getMonth()])),
|
|
23
29
|
mode === 'year' ? (React.createElement(Text, null, `${yearsScope[0]} - ${yearsScope[yearsScope.length - 1]}`)) : (React.createElement(Text, { action: true, onClick: () => setMode('year') }, getYear(date)))),
|
|
24
30
|
React.createElement(Icon, { name: 'forward', onClick: next }))));
|
|
25
31
|
};
|
|
@@ -9,7 +9,7 @@ import { createPortal } from 'react-dom';
|
|
|
9
9
|
import { Calendar } from './Calendar';
|
|
10
10
|
import { format } from 'date-fns';
|
|
11
11
|
import { Icon } from '../Icons';
|
|
12
|
-
export const DatePicker = ({ label, labelPosition = 'top', value, name, disabled = false, size = 'medium', width, error, errorMsg, theme = mainTheme, readOnly = false, position = 'left', placeholder = 'Select date', handleChange, zIndex }) => {
|
|
12
|
+
export const DatePicker = ({ label, labelPosition = 'top', value, name, disabled = false, size = 'medium', width, error, errorMsg, theme = mainTheme, readOnly = false, position = 'left', placeholder = 'Select date', handleChange, zIndex, calendarLabels, localeLabels, isAdvance = true }) => {
|
|
13
13
|
const [open, toogleOpen] = useState(false);
|
|
14
14
|
const sourceRef = useRef(null);
|
|
15
15
|
const [dropdownStyles, setDropdownStyles] = useState({
|
|
@@ -45,5 +45,5 @@ export const DatePicker = ({ label, labelPosition = 'top', value, name, disabled
|
|
|
45
45
|
value && (React.createElement(EyeIconWrapper, { size: size },
|
|
46
46
|
React.createElement(Icon, { name: 'close', size: 24, onClick: clearDate, iconColor: theme.inputDefaultTextColor, iconBgHoverColor: "transparent" }))),
|
|
47
47
|
open &&
|
|
48
|
-
createPortal(React.createElement(Calendar, { top: dropdownStyles.top, left: dropdownStyles.left, size: size, handleClose: () => toogleOpen(false),
|
|
48
|
+
createPortal(React.createElement(Calendar, { top: dropdownStyles.top, left: dropdownStyles.left, size: size, handleClose: () => toogleOpen(false), value: value, handleSelect: onSubmit, isAdvance: isAdvance, zIndex: zIndex, labels: calendarLabels, localeLabels: localeLabels }), document.body)))))));
|
|
49
49
|
};
|
|
@@ -4,10 +4,21 @@ interface ICalendar {
|
|
|
4
4
|
value: number | undefined;
|
|
5
5
|
top: number;
|
|
6
6
|
left: number;
|
|
7
|
+
labels?: {
|
|
8
|
+
close?: string;
|
|
9
|
+
confirm?: string;
|
|
10
|
+
today?: string;
|
|
11
|
+
};
|
|
12
|
+
localeLabels?: {
|
|
13
|
+
months?: string[];
|
|
14
|
+
weekdaysShort?: string[];
|
|
15
|
+
firstDayOfWeek?: number;
|
|
16
|
+
};
|
|
7
17
|
size: InputSize;
|
|
8
18
|
handleClose: () => void;
|
|
9
19
|
handleSelect: (date: number) => void;
|
|
10
|
-
|
|
20
|
+
isAdvance?: boolean;
|
|
21
|
+
autoConfirm?: boolean;
|
|
11
22
|
zIndex?: number;
|
|
12
23
|
}
|
|
13
24
|
export declare const Calendar: FC<ICalendar>;
|
|
@@ -1,10 +1,15 @@
|
|
|
1
1
|
import { FC } from 'react';
|
|
2
2
|
interface ICalendarContent {
|
|
3
3
|
date: Date;
|
|
4
|
-
handleChange: (newDate: Date) => void;
|
|
5
|
-
changeMode: (mode: string) => void;
|
|
6
4
|
mode: string;
|
|
5
|
+
handleChange: (d: Date) => void;
|
|
6
|
+
changeMode: (mode: string) => void;
|
|
7
7
|
yearsScope: number[];
|
|
8
|
+
localeLabels?: {
|
|
9
|
+
months?: string[];
|
|
10
|
+
weekdaysShort?: string[];
|
|
11
|
+
firstDayOfWeek?: number;
|
|
12
|
+
};
|
|
8
13
|
}
|
|
9
14
|
export declare const CalendarContent: FC<ICalendarContent>;
|
|
10
15
|
export {};
|
|
@@ -5,6 +5,11 @@ interface ICalendarHeader {
|
|
|
5
5
|
yearsScope: number[];
|
|
6
6
|
handleChange: (mode: string, forward: boolean) => void;
|
|
7
7
|
handleSelect: (mode: string) => void;
|
|
8
|
+
localeLabels?: {
|
|
9
|
+
months?: string[];
|
|
10
|
+
weekdaysShort?: string[];
|
|
11
|
+
firstDayOfWeek?: number;
|
|
12
|
+
};
|
|
8
13
|
}
|
|
9
14
|
export declare const CalendarHeader: FC<ICalendarHeader>;
|
|
10
15
|
export {};
|
|
@@ -5,5 +5,16 @@ export interface IDatePicker extends IFormElement {
|
|
|
5
5
|
position?: string;
|
|
6
6
|
handleChange: (name: string, value: string | number | undefined) => void;
|
|
7
7
|
zIndex?: number;
|
|
8
|
+
calendarLabels?: {
|
|
9
|
+
close?: string;
|
|
10
|
+
confirm?: string;
|
|
11
|
+
today?: string;
|
|
12
|
+
};
|
|
13
|
+
localeLabels?: {
|
|
14
|
+
months?: string[];
|
|
15
|
+
weekdaysShort?: string[];
|
|
16
|
+
firstDayOfWeek?: number;
|
|
17
|
+
};
|
|
18
|
+
isAdvance?: boolean;
|
|
8
19
|
}
|
|
9
20
|
export declare const DatePicker: FC<IDatePicker>;
|