@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.
@@ -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", flex: "auto", children: [name && (_jsxs(Flex, { align: "center", gap: "base", 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 } }) => {
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 Calendar from '@hassanmojab/react-modern-calendar-datepicker';
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
- const handleOnChange = (selectedDay) => {
13
- setDay(selectedDay);
14
- const newDay = joinDayMonthYear(selectedDay) || '';
15
- onChange(newDay);
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
- setDay(formatedValue);
36
+ if (formatedValue) {
37
+ setDay(new Date(formatedValue.year, formatedValue.month - 1, formatedValue.day));
38
+ }
20
39
  }, [value]);
21
- const renderCustomInput = ({ ref }) => {
22
- return (_jsxs(Flex, { gap: "base", minW: width, children: [_jsx(Tooltip, { label: placeholder, children: _jsx(Input, { placeholder: placeholder, value: joinedValue, readOnly: true, ref: ref, _placeholder: { color: 'gray.2' } }) }), showCalendarIcon && (_jsx(IconButton, { "aria-label": "Calendar icon", variant: "iconOutlined", icon: _jsx(CalendarIcon, { size: 28, stroke: colors.blue[3] }), maxH: "input.md", flexShrink: 0 }))] }));
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(Calendar, { value: day, onChange: handleOnChange, renderInput: renderCustomInput, colorPrimary: colors.blue['3'] }));
43
+ return (_jsx(DatePickerComponent, { selected: day, onChange: handleOnChange, customInput: renderCustomInput(), calendarClassName: "custom-calendar" }));
25
44
  };
@@ -1,3 +1,5 @@
1
+ import 'react-datepicker/dist/react-datepicker.css';
2
+ import '../../styles/calendar.css';
1
3
  export declare const DateRangePicker: ({ handleClick, }: {
2
4
  handleClick: (date: string) => void;
3
5
  }) => import("react/jsx-runtime").JSX.Element;
@@ -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 { formatInputValue, selectedDayRange, setSelectedDayRange } = useDateRangePicker({ handleClick });
9
- const renderCustomInput = ({ ref }) => (_jsxs(Flex, { align: "center", justify: "end", gap: "base", children: [_jsx(CalendarIcon, {}), _jsx(Input, { value: selectedDayRange.from && selectedDayRange.to ? formatInputValue() : '', readOnly: true, ref: ref, placeholder: "Select date range", variant: "date", size: "sm", maxW: "9rem" })] }));
10
- return (_jsx(Calendar, { value: selectedDayRange, onChange: setSelectedDayRange, renderInput: renderCustomInput, calendarClassName: "custom-calendar", colorPrimary: colors.blue['3'], colorPrimaryLight: colors.lightBlue['3'] }));
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
  };