@@ -15,6 +15,7 @@ interface IDatePickerContext {
1515 setShowSelectedDate : Dispatch < SetStateAction < boolean > >
1616 selectedMonth : number
1717 selectedYear : number
18+ onClear : ( ) => void
1819 getFormattedDate : ( date : Date | number , formatOptions ?: Intl . DateTimeFormatOptions | null | undefined ) => string
1920}
2021
@@ -32,20 +33,21 @@ export const DatePickerContext = createContext<IDatePickerContext>({
3233 setShowSelectedDate : ( ) => { } ,
3334 selectedMonth : 0 ,
3435 selectedYear : 0 ,
36+ onClear : ( ) => { } ,
3537 getFormattedDate : ( ) => "" ,
3638} )
3739
3840interface IDatePickerProviderProps {
3941 children : ReactElement
4042 options ?: IOptions
4143 onChange ?: ( date : Date ) => void
44+ onClear : ( ) => void
4245 show : boolean
4346 setShow : ( show : boolean ) => void
4447 selectedDateState ?: [ Date , ( date : Date ) => void ]
4548}
4649
47- const DatePickerProvider = ( { children, options : customOptions , onChange, show, setShow, selectedDateState } : IDatePickerProviderProps ) => {
48-
50+ const DatePickerProvider = ( { children, options : customOptions , onChange, onClear, show, setShow, selectedDateState } : IDatePickerProviderProps ) => {
4951 const options = { ...defaultOptions , ...customOptions }
5052 const [ view , setView ] = useState < Views > ( "days" )
5153 const [ selectedDate , setSelectedDate ] = selectedDateState || useState < Date > ( options ?. defaultDate || new Date ( ) )
@@ -67,7 +69,7 @@ const DatePickerProvider = ({ children, options: customOptions, onChange, show,
6769
6870 return (
6971 < DatePickerContext . Provider
70- value = { { options, view, setView, show, setShow, selectedDate, changeSelectedDate, showSelectedDate, setShowSelectedDate, selectedMonth, selectedYear, getFormattedDate } }
72+ value = { { options, view, setView, show, setShow, selectedDate, changeSelectedDate, showSelectedDate, setShowSelectedDate, selectedMonth, selectedYear, onClear , getFormattedDate } }
7173 >
7274 { children }
7375 </ DatePickerContext . Provider >
0 commit comments