Nextjs React Big Calendar
-gcal/outlook like calendar component
We have created the design of the React Big Calendar. We have changed the colors, typography and buttons, so it can look like the rest of the dashboard.
Styles
You will find the styles for this component in
assets/scss/nextjs-material-dashboard-pro/plugins/_plugin-react-big-calendar.scss
.
Example
Unfortunately, we are experiencing some difficulties with our live preview docs, and for some reason, the code demo does not work for this plugin and components. Please check them out here.
import React from "react";
// react components used to create a calendar with events on it
import { Calendar as BigCalendar, momentLocalizer } from "react-big-calendar";
// dependency plugin for react-big-calendar
import moment from "moment";
// react component used to create alerts
import SweetAlert from "react-bootstrap-sweetalert";
// @material-ui/core components
import { makeStyles } from "@material-ui/core/styles";
// layout for this page
// core components
import GridContainer from "components/Grid/GridContainer.js";
import GridItem from "components/Grid/GridItem.js";
import Card from "components/Card/Card.js";
import CardBody from "components/Card/CardBody.js";
import styles from "assets/jss/nextjs-material-dashboard-pro/components/buttonStyle.js";
import { events as calendarEvents } from "variables/general.js";
const localizer = momentLocalizer(moment);
const useStyles = makeStyles(styles);
const sweetAlertStyles = { display: "block", marginTop: "-100px" };
function Calendar() {
const classes = useStyles();
const [events, setEvents] = React.useState(calendarEvents);
const [alert, setAlert] = React.useState(null);
const selectedEvent = (event) => {
window.alert(event.title);
};
const addNewEventAlert = (slotInfo) => {
setAlert(
<SweetAlert
input
showCancel
style={ sweetAlertStyles }
title="Input something"
onConfirm={(e) => addNewEvent(e, slotInfo)}
onCancel={() => hideAlert()}
confirmBtnCssClass={classes.button + " " + classes.success}
cancelBtnCssClass={classes.button + " " + classes.danger}
/>
);
};
const addNewEvent = (e, slotInfo) => {
var newEvents = events;
newEvents.push({
title: e,
start: slotInfo.start,
end: slotInfo.end,
});
setAlert(null);
setEvents(newEvents);
};
const hideAlert = () => {
setAlert(null);
};
const eventColors = (event) => {
var backgroundColor = "event-";
event.color
? (backgroundColor = backgroundColor + event.color)
: (backgroundColor = backgroundColor + "default");
return {
className: backgroundColor,
};
};
return (
<>
{alert}
<GridContainer justify="center">
<GridItem xs={12} sm={12} md={10}>
<Card>
<CardBody calendar>
<BigCalendar
selectable
localizer={localizer}
events={events}
defaultView="month"
scrollToTime={new Date(1970, 1, 1, 6)}
defaultDate={new Date()}
onSelectEvent={(event) => selectedEvent(event)}
onSelectSlot={(slotInfo) => addNewEventAlert(slotInfo)}
eventPropGetter={eventColors}
/>
</CardBody>
</Card>
</GridItem>
</GridContainer>
</>
);
}
export default Calendar;
Props
If you want to see more examples and properties please check the official react-big-calendar Documentation.
You can also check the Official Github Repository.