import * as React from 'react';
const getYear = (date) => date.getFullYear()
const getMonth = (date) => date.toLocaleString('en', { month: 'long' })
const MultiMonthHeader = ({
customHeaderCount,
decreaseMonth,
increaseMonth,
monthDate,
nextMonthButtonDisabled,
prevMonthButtonDisabled,
}) => (
{getMonth(monthDate)} {getYear(monthDate)}
)
MultiMonthHeader.displayName = 'DatePicker.MultiMonthHeader'
const SingleMonthHeader = ({
decreaseMonth,
increaseMonth,
monthDate,
nextMonthButtonDisabled,
prevMonthButtonDisabled,
}) => (
{getMonth(monthDate)} {getYear(monthDate)}
)
SingleMonthHeader.displayName = 'DatePicker.SingleMonthHeader'
const CustomInput = React.forwardRef(
(
{
// @ts-ignore
className,
// @ts-ignore
errorText,
// @ts-ignore
hasError,
// @ts-ignore
inputId,
// @ts-ignore
inputName,
// @ts-ignore
placeholderText,
// @ts-ignore
value,
// @ts-ignore
onChange,
// @ts-ignore
onClick,
// @ts-ignore
disabled,
// @ts-ignore
readOnly,
// @ts-ignore
onFocus,
},
ref
) => {
let inputGroupClassName = hasError ? 'is-invalid input-group ' : 'input-group '
inputGroupClassName += className;
const renderError = (hasError, errorText) => {
if (hasError === true) {
return {errorText}
}
}
return (
<>
{renderError(hasError, errorText)}
>
)
}
)
export interface MmuiBlueDatepickerOptions {
selected?: any,
startDate?: any,
endDate?: any,
selectsRange?: boolean,
errorText?: string,
hasError?: boolean,
id: string,
name: string,
placeholderText?: string,
inputReadOnly?: boolean,
}
export function getMmuiBlueDatepickerProps(
options: MmuiBlueDatepickerOptions =
{
selected: null,
startDate: null,
endDate: null,
selectsRange: false,
errorText: 'Please select a date',
hasError: false,
id: 'id_input_cal',
name: 'calendar-input',
placeholderText: '',
inputReadOnly: false,
}
) {
const popperMods = [{ name: 'offset', options: { offset: [0, -10] } }];
const customInput = (
);
let customHeader;
if (options.selectsRange) {
customHeader = MultiMonthHeader;
} else {
customHeader = SingleMonthHeader;
}
let props = {
customInput: customInput,
popperModifiers: popperMods,
renderCustomHeader: customHeader,
showPopperArrow: false,
monthsShown: options.selectsRange ? 2 : 1,
preventOpenOnFocus: true,
selected: options.selected,
selectsRange: options.selectsRange,
startDate: options.startDate,
endDate: options.endDate,
closeOnScroll: true,
dateFormat: "MMM d, yyyy",
};
return(props);
}