1- import classNames from "classnames" ;
1+ import classnames from "classnames" ;
2+ import * as dateFns from "date-fns" ;
23import { ReactElement , createElement } from "react" ;
34import { Calendar , dateFnsLocalizer } from "react-big-calendar" ;
4- import * as dateFns from "date-fns" ;
5+ import { CalendarPreviewProps } from "../typings/CalendarProps" ;
6+ import { CustomToolbar } from "./components/Toolbar" ;
57import "react-big-calendar/lib/css/react-big-calendar.css" ;
6- import { CalendarPreviewProps } from "typings/CalendarProps" ;
8+ import { constructWrapperStyle , WrapperStyleProps } from "./utils/utils" ;
9+ import { eventPropGetter } from "./utils/calendar-utils" ;
710
811const localizer = dateFnsLocalizer ( {
912 format : dateFns . format ,
@@ -13,20 +16,69 @@ const localizer = dateFnsLocalizer({
1316 locales : { }
1417} ) ;
1518
16- export function preview ( _props : CalendarPreviewProps ) : ReactElement {
19+ export function preview ( props : CalendarPreviewProps ) : ReactElement {
20+ const className = props . class ;
21+ const wrapperStyle = constructWrapperStyle ( props as WrapperStyleProps ) ;
22+ const events = [
23+ {
24+ title : "Leave" ,
25+ allDay : true ,
26+ start : new Date ( new Date ( ) . setDate ( new Date ( ) . getDate ( ) - 15 ) ) ,
27+ end : new Date ( new Date ( ) . setDate ( new Date ( ) . getDate ( ) - 7 ) ) ,
28+ guid : "" ,
29+ color : ""
30+ } ,
31+ {
32+ title : "Leave" ,
33+ allDay : true ,
34+ start : new Date ( new Date ( ) . setDate ( new Date ( ) . getDate ( ) - 9 ) ) ,
35+ end : new Date ( new Date ( ) . setDate ( new Date ( ) . getDate ( ) - 5 ) ) ,
36+ guid : "" ,
37+ color : "green"
38+ } ,
39+ {
40+ title : "BD" ,
41+ allDay : true ,
42+ start : new Date ( ) ,
43+ end : new Date ( ) ,
44+ guid : "" ,
45+ color : "red"
46+ } ,
47+ {
48+ title : "Bank Holiday" ,
49+ allDay : true ,
50+ start : new Date ( new Date ( ) . valueOf ( ) + 6000 * 3600 * 24 ) ,
51+ end : new Date ( new Date ( ) . valueOf ( ) + 9000 * 3600 * 24 ) ,
52+ guid : "" ,
53+ color : "grey"
54+ } ,
55+ {
56+ title : "Bank Holiday" ,
57+ allDay : true ,
58+ start : new Date ( new Date ( ) . valueOf ( ) + 4000 * 3600 * 24 ) ,
59+ end : new Date ( new Date ( ) . valueOf ( ) + 8000 * 3600 * 24 ) ,
60+ guid : "" ,
61+ color : "purple"
62+ } ,
63+ {
64+ title : "Leave" ,
65+ allDay : true ,
66+ start : new Date ( new Date ( ) . valueOf ( ) + 10000 * 3600 * 24 ) ,
67+ end : new Date ( new Date ( ) . valueOf ( ) + 14000 * 3600 * 24 ) ,
68+ guid : "" ,
69+ color : ""
70+ }
71+ ] ;
72+
1773 return (
18- < div className = { classNames ( "widget-events-preview" ) } style = { { minHeight : "250px" } } >
74+ < div className = { classnames ( "widget-events-preview" , "widget-calendar" , className ) } style = { wrapperStyle } >
1975 < Calendar
76+ components = { { toolbar : CustomToolbar } }
77+ defaultView = { props . defaultView }
78+ events = { events }
2079 localizer = { localizer }
21- events = { [
22- {
23- title : "My event" ,
24- start : new Date ( ) ,
25- end : new Date ( )
26- }
27- ] }
28- startAccessor = "start"
29- endAccessor = "end"
80+ views = { [ "day" , "week" , "month" ] }
81+ eventPropGetter = { eventPropGetter }
3082 />
3183 </ div >
3284 ) ;
0 commit comments