@homefile/components-v2 2.8.17 → 2.8.18
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/components/forms/dynamicForm/fields/DateField.js +1 -1
- package/dist/components/inputs/DatePicker.d.ts +1 -0
- package/dist/components/inputs/DatePicker.js +30 -11
- package/dist/components/inputs/DateRangePicker.d.ts +2 -0
- package/dist/components/inputs/DateRangePicker.js +22 -6
- package/dist/styles/calendar.css +7 -672
- package/package.json +3 -2
- package/src/components/forms/dynamicForm/fields/DateField.tsx +2 -2
- package/src/components/inputs/DatePicker.tsx +40 -19
- package/src/components/inputs/DateRangePicker.tsx +39 -17
- package/src/styles/calendar.css +7 -672
|
@@ -4,7 +4,7 @@ import { Flex, Text } from '@chakra-ui/react';
|
|
|
4
4
|
import { DatePicker, FormIcon } from '../../..';
|
|
5
5
|
export const DateField = ({ id, icon, name, placeholder, showCalendarIcon = true, value, width, }) => {
|
|
6
6
|
const { control } = useFormContext();
|
|
7
|
-
return (_jsxs(Flex, { align: "center", gap: "base",
|
|
7
|
+
return (_jsxs(Flex, { align: "center", gap: "base", w: "full", children: [name && (_jsxs(Flex, { align: "center", gap: "base", flexShrink: 0, children: [_jsx(FormIcon, { icon: icon }), _jsx(Text, { fontFamily: "secondary", noOfLines: 1, overflow: "hidden", children: name })] })), _jsx(Controller, { control: control, name: id, defaultValue: value, render: ({ field: { value, onChange } }) => {
|
|
8
8
|
return (_jsx(DatePicker, { onChange: onChange, showCalendarIcon: showCalendarIcon, placeholder: placeholder, value: value, width: width }));
|
|
9
9
|
} })] }));
|
|
10
10
|
};
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import 'react-datepicker/dist/react-datepicker.css';
|
|
1
2
|
import '../../styles/calendar.css';
|
|
2
3
|
import { DatePickerI } from '../../interfaces';
|
|
3
4
|
export declare const DatePicker: ({ onChange, placeholder, showCalendarIcon, value, width, }: DatePickerI) => import("react/jsx-runtime").JSX.Element;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
2
|
import { useEffect, useState } from 'react';
|
|
3
|
-
import
|
|
3
|
+
import DatePickerComponent from 'react-datepicker';
|
|
4
|
+
import 'react-datepicker/dist/react-datepicker.css';
|
|
4
5
|
import '../../styles/calendar.css';
|
|
5
6
|
import { Flex, IconButton, Input, Tooltip } from '@chakra-ui/react';
|
|
6
7
|
import { Calendar as CalendarIcon } from '..';
|
|
@@ -8,18 +9,36 @@ import { colors } from '../../theme/colors';
|
|
|
8
9
|
import { extractDayMonthYear, joinDayMonthYear } from '../../utils';
|
|
9
10
|
export const DatePicker = ({ onChange, placeholder, showCalendarIcon, value, width = '290px', }) => {
|
|
10
11
|
const formatedValue = extractDayMonthYear(value);
|
|
11
|
-
const [day, setDay] = useState(formatedValue
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
12
|
+
const [day, setDay] = useState(formatedValue
|
|
13
|
+
? new Date(formatedValue.year, formatedValue.month - 1, formatedValue.day)
|
|
14
|
+
: null);
|
|
15
|
+
const handleOnChange = (date) => {
|
|
16
|
+
setDay(date);
|
|
17
|
+
const newDay = date
|
|
18
|
+
? joinDayMonthYear({
|
|
19
|
+
day: date.getDate(),
|
|
20
|
+
month: date.getMonth() + 1,
|
|
21
|
+
year: date.getFullYear(),
|
|
22
|
+
})
|
|
23
|
+
: '';
|
|
24
|
+
onChange(String(newDay));
|
|
25
|
+
};
|
|
26
|
+
const handleInputChange = (e) => {
|
|
27
|
+
const inputValue = e.target.value;
|
|
28
|
+
const [day, month, year] = inputValue.split('/').map(Number);
|
|
29
|
+
const date = new Date(year, month - 1, day);
|
|
30
|
+
onChange(inputValue);
|
|
31
|
+
if (!isNaN(date.getTime())) {
|
|
32
|
+
setDay(date);
|
|
33
|
+
}
|
|
16
34
|
};
|
|
17
|
-
const joinedValue = joinDayMonthYear(day);
|
|
18
35
|
useEffect(() => {
|
|
19
|
-
|
|
36
|
+
if (formatedValue) {
|
|
37
|
+
setDay(new Date(formatedValue.year, formatedValue.month - 1, formatedValue.day));
|
|
38
|
+
}
|
|
20
39
|
}, [value]);
|
|
21
|
-
const renderCustomInput = (
|
|
22
|
-
return (_jsxs(Flex, { gap: "base",
|
|
40
|
+
const renderCustomInput = () => {
|
|
41
|
+
return (_jsxs(Flex, { gap: "base", w: width, children: [_jsx(Tooltip, { label: placeholder, children: _jsx(Input, { placeholder: placeholder, onChange: handleInputChange, _placeholder: { color: 'gray.2' }, value: value }) }), showCalendarIcon && (_jsx(IconButton, { "aria-label": "Calendar icon", variant: "iconOutlined", icon: _jsx(CalendarIcon, { size: 28, stroke: colors.blue[3] }), maxH: "input.md", flexShrink: 0 }))] }));
|
|
23
42
|
};
|
|
24
|
-
return (_jsx(
|
|
43
|
+
return (_jsx(DatePickerComponent, { selected: day, onChange: handleOnChange, customInput: renderCustomInput(), calendarClassName: "custom-calendar" }));
|
|
25
44
|
};
|
|
@@ -1,11 +1,27 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useState } from 'react';
|
|
3
|
+
import DatePicker from 'react-datepicker';
|
|
4
|
+
import 'react-datepicker/dist/react-datepicker.css';
|
|
5
|
+
import '../../styles/calendar.css';
|
|
2
6
|
import { Flex, Input } from '@chakra-ui/react';
|
|
3
|
-
import Calendar from '@hassanmojab/react-modern-calendar-datepicker';
|
|
4
7
|
import { Calendar as CalendarIcon } from '..';
|
|
5
|
-
import { useDateRangePicker } from '../../hooks';
|
|
6
|
-
import { colors } from '../../theme/colors';
|
|
7
8
|
export const DateRangePicker = ({ handleClick, }) => {
|
|
8
|
-
const
|
|
9
|
-
const
|
|
10
|
-
|
|
9
|
+
const [startDate, setStartDate] = useState(null);
|
|
10
|
+
const [endDate, setEndDate] = useState(null);
|
|
11
|
+
const handleDateChange = (dates) => {
|
|
12
|
+
const [start, end] = dates;
|
|
13
|
+
setStartDate(start);
|
|
14
|
+
setEndDate(end);
|
|
15
|
+
if (start && end) {
|
|
16
|
+
const formattedStart = `${start.getDate()}/${start.getMonth() + 1}/${start.getFullYear()}`;
|
|
17
|
+
const formattedEnd = `${end.getDate()}/${end.getMonth() + 1}/${end.getFullYear()}`;
|
|
18
|
+
handleClick(`${formattedStart} - ${formattedEnd}`);
|
|
19
|
+
}
|
|
20
|
+
};
|
|
21
|
+
const renderCustomInput = ({ value = '' }) => (_jsxs(Flex, { align: "center", justify: "end", gap: "base", children: [_jsx(CalendarIcon, {}), _jsx(Input, { value: value, readOnly: true, placeholder: "Select date range", variant: "date", size: "sm" })] }));
|
|
22
|
+
return (_jsx(DatePicker, { selected: startDate, onChange: handleDateChange, startDate: startDate, endDate: endDate, selectsRange: true, customInput: renderCustomInput({
|
|
23
|
+
value: startDate && endDate
|
|
24
|
+
? `${startDate.getDate()}/${startDate.getMonth() + 1}/${startDate.getFullYear()} - ${endDate.getDate()}/${endDate.getMonth() + 1}/${endDate.getFullYear()}`
|
|
25
|
+
: '',
|
|
26
|
+
}), calendarClassName: "custom-calendar" }));
|
|
11
27
|
};
|