Skip to content

Commit 5418364

Browse files
refactor(calendar-web): improve preview component structure and styling
1 parent df43cc2 commit 5418364

File tree

1 file changed

+66
-14
lines changed

1 file changed

+66
-14
lines changed

packages/pluggableWidgets/calendar-web/src/Calendar.editorPreview.tsx

Lines changed: 66 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
1-
import classNames from "classnames";
1+
import classnames from "classnames";
2+
import * as dateFns from "date-fns";
23
import { ReactElement, createElement } from "react";
34
import { 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";
57
import "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

811
const 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

Comments
 (0)