0.1.3 • Published 7 months ago

scroll-calendar-component v0.1.3

Weekly downloads
-
License
-
Repository
-
Last release
7 months ago

React Scroll Calendar Component

Features

  • 📅 Scrollable multi-month view (default: 13 months).
  • 📍 Start and end date selection with visual highlights.
  • 🎨 Fully customizable with styled-components.

Usage

import React, { useState } from "react";
import { Calendar } from "react-scroll-calendar";

function App() {
  const [selectedDates, setSelectedDates] = useState<Date[]>([]);

  const handleDateClick = (date: Date) => {
    if (selectedDates.length === 2) {
      setSelectedDates([date]);
    } else if (selectedDates.length === 0) {
      setSelectedDates([date]);
    } else {
      setSelectedDates(
        [...selectedDates, date].sort((a, b) => a.getTime() - b.getTime())
      );
    }
  };

  return (
    <div>
      <Calendar selectedDates={selectedDates} onDateClick={handleDateClick} />
    </div>
  );
}

export default App;

Props

PropTypeRequiredDescriptionDefault
currentDateDateNoThe initial date for the calendar view.new Date()
selectedDatesDate[]YesAn array of selected dates (start and end dates).[]
onDateClick(date: Date) => voidYesCallback when a date is clicked.-
totalMonthsnumberNoNumber of months to display in the calendar.13