Added custom date picker BOD-246

This commit is contained in:
Patrick Fic
2020-08-04 13:10:18 -07:00
parent 0a7305ff8e
commit c1522ca5b2
3 changed files with 54 additions and 16 deletions

View File

@@ -0,0 +1,31 @@
import React, { forwardRef, useEffect } from "react";
import { DatePicker } from "antd";
import { useTranslation } from "react-i18next";
import moment from "moment";
//To be used as a form element only.
const CustomDatePicker = ({ value, onChange, onBlur, ...restProps }, ref) => {
const { t } = useTranslation();
const handleChange = (newDate) => {
if (value !== newDate && onChange) {
onChange(newDate);
}
};
const handleKeyDown = (e) => {
if (e.key.toLowerCase() === "t") {
if (onChange) {
onChange(new moment());
}
}
};
return (
<div onKeyDown={handleKeyDown}>
<DatePicker value={value} onChange={handleChange} {...restProps} />
</div>
);
};
export default forwardRef(CustomDatePicker);