React Native Calendar Kit

repository·main·Indexed 20 days ago

https://github.com/howljs/react-native-calendar-kit

A modern, timezone-aware calendar component for React Native and Expo applications. It features multiple view modes (Day, 3-days, week), resource-based scheduling, and interactive capabilities including drag-and-drop event creation, pinch-to-zoom, and haptic feedback. The kit provides a customizable theming system and core components such as CalendarContainer, CalendarHeader, and CalendarBody.

Tokens
29.9K
Snippets
91
Records
117
Agent score
65%

What's inside react-native-calendar-kit

  1. Overview of React Native Calendar Kit features

    main

    React Native Calendar Kit is a feature-rich calendar solution with the following capabilities:

    View Modes

    • Multiple view types: Day, 3-days, and week views with smooth transitions.
    • All-day events: Support for holidays, meetings, and multi-day events.
    • Resource calendar: Side-by-side display of multiple resources (e.g., rooms, employees, equipment).

    Interactions

    • Drag & drop: Intuitive event creation and editing.
    • Pinch to zoom: Gesture-based zoom controls.
    • Haptic feedback: Tactile responses for user actions.
    • Horizontal scrolling: Swipe between different calendar views.

    Customization & Performance

    • Theming system: Complete visual customization.
    • Flexible day view: Ability to hide/show specific days of the week.
    • Unavailable hours: Ability to mark blocked time slots.
    • Recurring events: Full support for repeating events.
    • Timezone aware: Effortless handling of multiple timezones.
    • Overlap handling: Smart event positioning and spacing.
  2. Create all-day events

    main

    There are two ways to define all-day events in React Native Calendar Kit:

    1. Timezone-dependent: Set start and end using dateTime and timeZone to cover the full day range.
    2. Timezone-independent: Omit dateTime and timeZone, and use only the date property (YYYY-MM-DD) for both start and end. This is recommended for holidays or events that should span entire days regardless of local time.

    For multi-day events, specify different start and end dates using the date property.

    // Timezone-independent all-day event
    {
      id: '3',
      title: 'Company Holiday',
      start: { date: '2024-03-17' },
      end: { date: '2024-03-17' },
      color: '#FBBC05',
    }
    
    // Multi-day all-day event
    {
      id: '4',
      title: 'Annual Leave',
      start: { date: '2024-03-18' },
      end: { date: '2024-03-22' },
      color: '#EA4335',
    }
  3. Set up a Resources Calendar

    main

    The Resources Calendar allows you to display events for multiple resources (e.g., rooms, employees, equipment) side by side. To implement this, pass a resources array to the CalendarContainer component. Each resource object must contain a unique id.

    import {
      CalendarContainer,
      CalendarHeader,
      CalendarBody,
    } from "@howljs/calendar-kit";
    
    const resources = [
        { id: 'room1', name: 'Meeting Room 1' },
        { id: 'room2', name: 'Meeting Room 2' },
        { id: 'room3', name: 'Conference Room' },
    ];
    
    function MyCalendar() {
        return (
        <CalendarContainer
            resources={resources}
            // ... other props
        >
            <CalendarHeader />
            <CalendarBody />
        </CalendarContainer>
        );
    }
  4. Enable Drag-to-Create events

    main

    To allow users to create new events by dragging on the calendar interface, set the allowDragToCreate prop to true on the CalendarContainer component.

    import {
      CalendarContainer,
      CalendarHeader,
      CalendarBody,
    } from "@howljs/calendar-kit";
    
    const MyCalendar = () => {
      return (
        <CalendarContainer
          allowDragToCreate={true}
          // ... other props
        >
          <CalendarHeader />
          <CalendarBody />
        </CalendarContainer>
      );
    };
  5. Customize the Resources Header

    main

    You can customize how resources are rendered in the header by using the renderHeaderItem prop on the CalendarHeader component. This allows you to inject custom UI (like icons or specific text formatting) for each resource item.

    function MyCalendar() {
    const _renderResource = useCallback((resource: ResourceItem) => {
        return (
          <View style={styles.resourceContainer}>
            <Ionicons name="person-circle-outline" size={24} color="black" />
            <Text>{resource.title}</Text>
          </View>
        );
      }, []);
    
      const _renderResourceHeaderItem = useCallback(
        (item: HeaderItemProps) => {
          const start = parseDateTime(item.startUnix);
          const dateStr = start.toFormat('yyyy-MM-dd');
    
          return (
            <ResourceHeaderItem
              startUnix={item.startUnix}
              resources={item.extra.resources}
              renderResource={_renderResource}
              DateComponent={
                <View style={styles.dateContainer}>
                  <Text style={{ fontSize: 16, fontWeight: 'bold' }}>
                    {dateStr}
                  </Text>
                </View>
              }
            />
          );
        },
        [_renderResource]
      );
    
      return (
        <CalendarContainer
          resources={resources}
          events={events}
          // ... other props
        >
          <CalendarHeader renderHeaderItem={_renderResourceHeaderItem}/>
          <CalendarBody  />
        </CalendarContainer>
      );
    }
  6. Customize the calendar appearance with a theme

    main

    You can customize the visual appearance of the calendar by passing a theme prop to the CalendarContainer component. The theme object accepts a DeepPartial<ThemeConfigs> object that allows you to override colors, text styles, and container styles for specific calendar components like the hour column, day bar, and event containers.

    import {
      CalendarBody,
      CalendarContainer,
      CalendarHeader,
      DeepPartial,
      ThemeConfigs,
    } from '@howljs/calendar-kit';
    import React from 'react';
    
    const customTheme: DeepPartial<ThemeConfigs> = {
      // Your custom theme properties here
    };
    
    const Calendar = () => {
      return (
        <CalendarContainer theme={customTheme}>
          <CalendarHeader />
          <CalendarBody />
        </CalendarContainer>
      );
    };
    
    export default Calendar;
  7. Enable Drag-to-Edit events

    main

    To allow users to edit existing events by dragging them to new times or dates, set the allowDragToEdit prop to true on the CalendarContainer component.

    import {
      CalendarContainer,
      CalendarHeader,
      CalendarBody,
    } from "@howljs/calendar-kit";
    
    const MyCalendar = () => {
      return (
        <CalendarContainer
          allowDragToEdit={true}
          // ... other props
        >
          <CalendarHeader />
          <CalendarBody />
        </CalendarContainer>
      );
    };
  8. Deploy the documentation website

    main

    You can deploy the built website using either SSH or GitHub Pages.

    To deploy via SSH, set the USE_SSH environment variable to true.

    To deploy to GitHub Pages, provide your GitHub username via the GIT_USER environment variable. This command will build the site and push it to the gh-pages branch.

    # Deploy using SSH
    $ USE_SSH=true yarn deploy
    
    # Deploy to GitHub Pages
    $ GIT_USER=<Your GitHub username> yarn deploy