setDate prop was added
This commit is contained in:
parent
cce45a11d2
commit
f614c1628c
@ -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 |
|
||||
|
@ -62,7 +62,7 @@ const Template = ({ ...args }) => {
|
||||
|
||||
return (
|
||||
<Wrapper>
|
||||
<DatePicker {...args} date={date} onChange={setDate} />
|
||||
<DatePicker {...args} date={date} setDate={setDate} />
|
||||
</Wrapper>
|
||||
);
|
||||
};
|
||||
|
@ -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 = {
|
||||
|
Loading…
Reference in New Issue
Block a user