The Event Calendar is a simple and responsive React component that displays a monthly calendar with support for events. This component is built with React and SCSS and can be easily integrated into your React applications.
The Event Calendar component provides a visual representation of a calendar month, where users can see events for each day. It highlights the current day, handles long event titles by truncating them, and separates event times to ensure a clean layout.
- Monthly View: Displays a complete month with days and events.
- Current Day Highlighting: Highlights the current day with a circular background.
-
Event Handling:
- Events are displayed under each day.
- Event titles are truncated with ellipses to prevent overflow.
- Each event occupies a single line, with the title taking up 60% of the width and the time taking up 40%.
- Responsive Design: Adjusts the layout and font size based on screen size to maintain readability and usability.
- Customizable Title and Button: Allows setting custom titles for the calendar and the "Add Event" button.
Install the @farango/calendar_library
package:
npm install @farango/calendar_library
Here's how to use the EventCalendar
component with default settings:
import React from 'react';
import { EventCalendar } from '@farango/calendar_library';
const App = () => {
const events = [
{ date: '2024-10-21', title: 'Meeting', time: '10:00 AM' },
{ date: '2024-10-22', title: 'Workshop', time: '2:00 PM' },
{ date: '2024-10-23', title: 'Webinar', time: '11:00 AM' },
];
return (
<div>
<EventCalendar eventsData={events} />
</div>
);
};
export default App;
You can customize the appearance of the calendar by passing a styles
object as a prop:
const customStyles = {
colorActualDay: '#FF5733',
colorFontTitle: '#1E90FF',
colorFontButtons: '#2ECC71',
colorFontNameDays: '#34495E',
colorFontDays: '#000',
sizeFontAppointment: '1rem',
sizeFontButtons: '0.9rem',
sizeFontNameDays: '0.8rem',
sizeFontDays: '0.85rem',
bgHeader: '#E0E0E0',
bgDaysNames: '#F8F8F8',
bgCells: '#FFFFFF',
bgActualDay: '#FFC107',
visibilityOptions: {
todayButton: true,
dropdownFilter: true,
addEventButton: false,
header: true,
daysNames: true,
},
};
<EventCalendar eventsData={events} styles={customStyles} />
The component allows you to toggle visibility for specific elements:
- todayButton: Shows/hides the "Today" button.
- dropdownFilter: Shows/hides the filter dropdown.
- addEventButton: Shows/hides the "Add Event" button.
- header: Shows/hides the calendar header.
- daysNames: Shows/hides the row of day names.
- Type: String
-
Default:
"Event Calendar"
- Description: Sets a custom title for the calendar.
-
Example:
<EventCalendar title="My Custom Calendar" />
- Type: String
-
Default:
"Add Event"
- Description: Sets a custom label for the "Add Event" button.
-
Example:
<EventCalendar titleButton="Create New Event" />
- Type: Function
-
Default:
() => {}
- Description: Callback function triggered when an event is selected.
-
Example:
const handleEventSelection = (event) => { console.log('Selected Event:', event); }; <EventCalendar onSelectedEvent={handleEventSelection} />
- Type: Function
-
Default:
() => {}
- Description: Callback function triggered when the "Add Event" button is clicked.
-
Example:
const handleAddEvent = () => { console.log('Add Event clicked'); }; <EventCalendar addEvent={handleAddEvent} />
-
Type: Array
-
Default:
[]
-
Description: An array of event objects. Each event should have:
-
date
(in YYYY-MM-DD format) -
title
(string) -
time
(string)
-
-
Example:
const events = [ { date: '2024-10-21', title: 'Meeting', time: '10:00 AM' }, { date: '2024-10-22', title: 'Workshop', time: '2:00 PM' }, ];
- Type: Object
-
Default: See
defaultStyles
in the component - Description: An object to customize the appearance of the calendar. It contains properties for colors, font sizes, background colors, and visibility options.
<EventCalendar eventsData={events} />
<EventCalendar eventsData={events} styles={customStyles} />
<EventCalendar
title="Team Calendar"
titleButton="Schedule Event"
addEvent={() => alert('Add Event clicked')}
/>
- Type: MIT Lic
- Name: Andrés Arango