Skip to main content

Calendar

The Calendar component offers an interactive month view with extensive customization options, including localization, event rendering, and drag-and-drop support.

Quick Start

  1. Install the package:

    npm install @ijavad805/react-datepicker
  2. Render a calendar with default styling and an empty event list:

    import { Calendar } from '@ijavad805/react-datepicker';

    function AppSimple() {
    return <Calendar events={[]} />;
    }

Usage Example

import { Calendar, IEvent } from '@ijavad805/react-datepicker';
import moment from 'moment';

function App() {
return (
<Calendar
lang="en"
theme="blue"
events={[
{
id: 1,
title: 'Test',
date: '2023-09-16',
className: 'test',
dotColor: '#000',
disabled: false,
icon: '$',
},
]}
onDropEvent={(item: IEvent) => {
console.log(item);
}}
onClickEvent={(item: IEvent) => console.log(item)}
onDoubleClickEvent={(item: IEvent) => console.log(item)}
style={{
height: 600,
}}
onDateClick={(date: moment.Moment) => console.log(date)}
/>
);
}

Properties

PropertyTypeDescription
lang"en" | "fa"Language for the calendar. Either English ("en") or Persian ("fa").
theme"blue"Theme for the calendar. Currently, only "blue" is supported.
eventsIEvent[]Array of calendar events.
onDay(date: string) => { className?: string }Customize the appearance of a day by returning a class name.
disabledDate(date: moment.Moment) => booleanDisable specific dates by returning true.
onClickEvent(item: IEvent) => voidHandle event click interactions.
onDoubleClickEvent(item: IEvent) => voidHandle event double-click interactions.
onDropEvent(item: IEvent) => voidHandle event drag-and-drop interactions. Provide this prop to enable drag-and-drop.
onDateClick(date: string) => voidHandle clicks on calendar dates.
onMonthChange(start: string, end: string) => voidRespond to month changes with the new visible range.
styleReact.CSSPropertiesApply inline styles to the calendar container.
allowClearbooleanAllow users to clear the current selection.

IEvent Interface

Events displayed in the calendar implement the IEvent interface:

PropertyTypeDescription
idnumberUnique identifier for the event.
titleReact.ReactNode | stringEvent title as a React node or string.
dateDateEventEvent date as a string or an object with start and end.
styleReact.CSSPropertiesAdditional styles for the event.
classNamestringAdditional class names.
dotColorstringColor of the event indicator dot.
disabledbooleanWhether the event is disabled.
iconReact.ReactNodeIcon displayed with the event.

Reporting Issues

If you encounter any problems, please let us know: