0.1.31 • Published 2 years ago

@hammaadhrasheedh/react-event-calendar v0.1.31

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

React Event Calendar

A small & customizable react calendar component to show your daily events for a given month.

Features

  • Dotted and filled days for events
  • Customize day rendering
  • Customize event rendering
  • Show Holidays
  • Click a day to get the data to showcase on another component

Demo

Demo

Installation

Install react-event-calendar with npm

  npm install @hammaadhrasheedh/react-event-calendar

Styles

Get styles for the calendar

  import '@hammaadhrasheedh/react-event-calendar/dist/themes/default.css'

Other out of the box styling options

  import '@hammaadhrasheedh/react-event-calendar/dist/themes/circular.css'
  import '@hammaadhrasheedh/react-event-calendar/dist/themes/clean.css'
  import '@hammaadhrasheedh/react-event-calendar/dist/themes/neumorphic.css'
  import '@hammaadhrasheedh/react-event-calendar/dist/themes/dark.css'

Simple Example

import { Calendar } from '@hammaadhrasheedh/react-event-calendar'

var events = [
    {
        date: "2022-05-02",
        color: "red",
    },
    {
        date: new Date('2022-05-23'),
        color: "pink",
    },
    {
        date: "2022-05-02",
        color: "#c3c3c3",
    },
];

<Calendar
    eventType="Fill"
    date={'2022-05-09'}
    events={events}
/>

Props

PropTypeDescriptionExample
defaultSelectedMoment\|Date\|stringSelects a day by deafult when calendar renders'2022-12-22'
holidaysArray<Moment\|Date\|string>Highlight holidays in unified style['2022-12-22', new Date(), moment()]
eventsArray<Object>Events to mark on the calendar[{date: "2022-05-02", color: "red", extraData:any}]
eventType'Dots' \| 'Fill'Determines how the events will be dispalyed in calendar. Default: 'Dots'
prefixIDstringPrefixes to the unique id to each date block
defaultDayFormaterstringFormat how days are displayed in calednder. Default: 'DD'moment docs
dateMoment\|Date\|stringDetermines which month to be shown in calendar, Default: today'2022-12-22' \| new Date() \| moment()
displayWeekBooleanShow or hide week section of calendar
dateFormatstringFormat how calendar date is displayed in header of calednder. Default: 'MMM YYYY'moment docs
headerType'EvenSpread' \| 'ActionSeparate'Formats the layout of the header ( date and action buttons)

Methods

PropParamsDescriptionExample
renderDay{isToday, defaultFormatedDay, day, isSelectedDay, isSameMonth, isHoliday, events, index}Function to customize the render of the full day blockRender Day
renderDayContent{isToday, defaultFormatedDay, day, isSelectedDay, isSameMonth, isHoliday, events, index}Function to customize the content the day
renderEventevent, indexFunction to customize the UI of the events
prevBtnFunction to customize the icon/content of previous button
nextBtnFunction to customize the icon/content of next button
onClickDaydayCalls the function when a day is clicked

Examples

Render Day

const renderDay = ({
    isToday,
    defaultFormatedDay,
    day,
    isSelectedDay,
    isSameMonth,
    isHoliday,
    events,
    index,
  }) => {

    //   hide days from other months
    if(!isSameMonth){
      return null
    }

    return (
      <div>
        <div
          className={`day-block cursor-pointer\
           ${isToday ? "current-day" : ""}\
           ${isSelectedDay ? "selected-day" : ""}\
           ${!isSameMonth ? "another-month-day" : ""}\
           ${isHoliday ? "holiday" : ""} 
       `}
        >
          {defaultFormatedDay}
        </div>
      </div>
    );
  };

Render Event

  const eventsStyles =  `.events-container{
    top:0;
    right:0;
  }
  .has-events .day{
    color:white
  }
  `

  const renderEvent = (event:any, index:any) => {
    return (
      <div style={{backgroundImage: event.extraData.gradient, width:'100%', height:'100%', zIndex:-1}}>
      </div>
    )

  }
  return (
    <div>
      <style> {eventsStyles} </style>
      <Calendar
        date={"2022-05-09"}
        renderEvent={renderEvent}
        events={[
          {
            date: "2022-05-21",
            color: "#c3c3c3",
            extraData:{gradient:'linear-gradient(to top, #f77062 0%, #fe5196 100%)'}
          },
        ]}
      />
    </div>
  );