({
selectDate,
format,
minDate,
maxDate,
onChange,
handleClear,
label,
showLabel = true,
showClear = true,
dateClassName = ""
})
| 10 | import { useTranslation } from "react-i18next"; |
| 11 | |
| 12 | const DatePicker = ({ |
| 13 | selectDate, |
| 14 | format, |
| 15 | minDate, |
| 16 | maxDate, |
| 17 | onChange, |
| 18 | handleClear, |
| 19 | label, |
| 20 | showLabel = true, |
| 21 | showClear = true, |
| 22 | dateClassName = "" |
| 23 | }) => { |
| 24 | const { t } = useTranslation(); |
| 25 | |
| 26 | const CustomInput = forwardRef(({ value, onClick }, ref) => ( |
| 27 | <div |
| 28 | className="w-full border-gray-400 rounded-[50px] border-[1px] px-3 text-xs py-2 focus:outline-none hover:border-base-content flex items-center justify-between" |
| 29 | onClick={onClick} |
| 30 | ref={ref} |
| 31 | > |
| 32 | <span className={`${dateClassName} truncate`}>{value}</span> |
| 33 | <i className={`fa-light fa-calendar`}></i> |
| 34 | </div> |
| 35 | )); |
| 36 | CustomInput.displayName = "CustomInput"; |
| 37 | |
| 38 | return ( |
| 39 | <> |
| 40 | {showLabel && ( |
| 41 | <span className="flex-shrink-0">{label || t("default-date")}: </span> |
| 42 | )} |
| 43 | <ReactDatePicker |
| 44 | renderCustomHeader={({ date, changeYear, changeMonth }) => ( |
| 45 | <div className="flex justify-start md:ml-2"> |
| 46 | <select |
| 47 | className="bg-transparent outline-none" |
| 48 | value={months[getMonth(date)]} |
| 49 | onChange={({ target: { value } }) => |
| 50 | changeMonth(months.indexOf(value)) |
| 51 | } |
| 52 | > |
| 53 | {months.map((option) => ( |
| 54 | <option key={option} value={option}> |
| 55 | {option} |
| 56 | </option> |
| 57 | ))} |
| 58 | </select> |
| 59 | <select |
| 60 | className="bg-transparent outline-none" |
| 61 | value={getYear(date)} |
| 62 | onChange={({ target: { value } }) => changeYear(value)} |
| 63 | > |
| 64 | {years.map((option) => ( |
| 65 | <option key={option} value={option}> |
| 66 | {option} |
| 67 | </option> |
| 68 | ))} |
| 69 | </select> |
nothing calls this directly
no test coverage detected