setDate prop was added

This commit is contained in:
Vladimir Khvan 2023-07-06 20:19:50 +05:00
parent cce45a11d2
commit f614c1628c
3 changed files with 12 additions and 3 deletions

View File

@ -33,3 +33,4 @@ import DatePicker from "@docspace/components/date-picker";
| `minDate` | `date` | - | - | - | Minimum date that the user can select. |
| `onChange` | `func` | - | - | - | Function called when the user select a day |
| `showCalendarIcon` | `bool` | - | - | - | Shows calendar icon in selected item |
| `setDate` | `func` | - | - | - | Sets date |

View File

@ -62,7 +62,7 @@ const Template = ({ ...args }) => {
return (
<Wrapper>
<DatePicker {...args} date={date} onChange={setDate} />
<DatePicker {...args} date={date} setDate={setDate} />
</Wrapper>
);
};

View File

@ -59,6 +59,7 @@ const StyledCalendar = styled(Calendar)`
const DatePicker = (props) => {
const {
date,
setDate,
onChange,
selectDateText,
className,
@ -75,6 +76,11 @@ const DatePicker = (props) => {
const [isCalendarOpen, setIsCalendarOpen] = useState(false);
const handleChange = (date) => {
onChange && onChange(date);
setDate(date);
};
const toggleCalendar = () =>
setIsCalendarOpen((prevIsCalendarOpen) => !prevIsCalendarOpen);
@ -84,14 +90,14 @@ const DatePicker = (props) => {
const deleteSelectedDate = (propKey, label, group, e) => {
e.stopPropagation();
onChange(null);
handleChange(null);
setIsCalendarOpen(false);
};
const CalendarElement = () => (
<StyledCalendar
selectedDate={date}
setSelectedDate={onChange}
setSelectedDate={handleChange}
onChange={closeCalendar}
isMobile={isMobileOnly}
forwardedRef={calendarRef}
@ -168,6 +174,8 @@ DatePicker.propTypes = {
locale: PropTypes.string,
/** Shows calendar icon in selected item */
showCalendarIcon: PropTypes.bool,
/** Sets date */
setDate: PropTypes.func,
};
DatePicker.defaultProps = {