@@ -83,29 +83,39 @@ const ItemTemplate = React.memo((props: ItemTemplateProps) => {
8383 ) ;
8484} ) ;
8585
86- const Shortcuts = ( ) => {
86+ const printItemText = ( item : ShortcutsItem ) => {
87+ return item . text ?? null ;
88+ } ;
89+
90+ const Shortcuts : React . FC = ( ) => {
8791 // Contexts
8892 const { configs } = useContext ( DatepickerContext ) ;
8993
9094 const callPastFunction = ( data : unknown , numberValue : number ) => {
9195 return typeof data === "function" ? data ( numberValue ) : null ;
9296 } ;
9397
94- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
95- // @ts -ignore
96- const printItemText = item => {
97- return "text" in item ? item . text : "" ;
98- } ;
98+ const shortcutOptions = configs
99+ ? Object . entries ( DEFAULT_SHORTCUTS ) . filter ( ( [ key ] ) => {
100+ return configs . shortcuts
101+ ? Object . keys ( configs . shortcuts ) . includes ( key ) &&
102+ configs . shortcuts [ key as keyof typeof configs . shortcuts ]
103+ : true ;
104+ } )
105+ : Object . entries ( DEFAULT_SHORTCUTS ) ;
99106
100107 return (
101108 < div className = "md:border-b mb-3 lg:mb-0 lg:border-r lg:border-b-0 border-gray-300 dark:border-gray-700 pr-1" >
102109 < ul className = "w-full tracking-wide flex flex-wrap lg:flex-col pb-1 lg:pb-0" >
103- { Object . entries ( DEFAULT_SHORTCUTS ) . map ( ( [ key , item ] , index ) =>
104- key === "past" ? (
105- ( Array . isArray ( item ) ? item : [ ] ) . map ( ( item , index ) => (
110+ { shortcutOptions . map ( ( [ key , item ] , index ) =>
111+ Array . isArray ( item ) ? (
112+ item . map ( ( item , index ) => (
106113 < ItemTemplate key = { index } item = { item } >
107114 < >
108- { configs && configs . shortcuts && key in configs . shortcuts
115+ { key === "past" &&
116+ configs ?. shortcuts &&
117+ key in configs . shortcuts &&
118+ item . daysNumber
109119 ? callPastFunction ( configs . shortcuts [ key ] , item . daysNumber )
110120 : item . text }
111121 </ >
@@ -114,7 +124,7 @@ const Shortcuts = () => {
114124 ) : (
115125 < ItemTemplate key = { index } item = { item } >
116126 < >
117- { configs && configs . shortcuts && key in configs . shortcuts
127+ { configs ? .shortcuts && key in configs . shortcuts
118128 ? configs . shortcuts [ key as keyof typeof configs . shortcuts ]
119129 : printItemText ( item ) }
120130 </ >
0 commit comments