3.0.5 • Published 1 year ago

@demark-pro/react-booking-calendar v3.0.5

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

Demo

Online demo!

Getting started

How can I use another locale?

If you want to use a different locale, you need to pass the dateFnsOptions parameter to the locale. Read more date-fns

Installation

Add React-Booking-Calendar to your project by executing npm i @demark-pro/react-booking-calendar --save.

Usage

Here's an example of usage with range:

import React, { useState } from "react";
import Calendar from "@demark-pro/react-booking-calendar";

const reserved = [
  {
    startDate: new Date(2023, 3, 22),
    endDate: new Date(2016, 4, 05),
  },
];

const MyBookingCalendar = () => {
  const [selectedDates, setSelectedDates] = useState([]);
  const handleChange = (e) => setSelectedDates(e);

  return (
    <Calendar
      selected={selectedDates}
      onChange={handleChange}
      onOverbook={(e, err) => alert(err)}
      components={{
        DayCellFooter: ({ innerProps }) => (
          <div {...innerProps}>My custom day footer</div>
        ),
      }}
      disabled={(date, state) => !state.isSameMonth}
      reserved={reserved}
      variant="events"
      dateFnsOptions={{ weekStartsOn: 1 }}
      range={true}
    />
  );
};

Styles

If you provide the classNamePrefix prop to Calendar, all inner elements will be given a className with the provided prefix.

InfiniteСalendar example

<InfiniteCalendar classNamePrefix="calendar" />

and CSS...

.calendar__dayCell-footer {
  color: "red";
}

Options

PropTypeDefaultDescription
selected(Date/number/null)[][]selectedStartDate, selectedEndDate
monthnumbercurrent monthOptional
yearnumbercurrent yearOptional
isStartbooleantrueCurrent value selection
reservedArray[]Array of objects { startDate: Date, endDate: Date }
dateFnsOptionsObject{weekStartsOn: 1}Read more date-fns documentation
rangebooleanfalseadd range logic
classNamestringClass name(s) main Calendar <div> element
disabledboolean/funcfalse
componentsfalseCustom components
varianteventsbookingbooking
onOverbookFuncReturns date and type of overbooking error
onChangeFuncCallback after date selection. Returns (date)
onMonthChangeFuncCallback after month change. Returns (month, year)

Utils

getFreeTimeofDate

(date: Date | number, reserved: Reserved[])

Returns free check-in and check-out time { startDate: Date, endDate: Date }

3.0.5

1 year ago

3.0.4

1 year ago

3.0.3

1 year ago

3.0.2

1 year ago

3.0.1

1 year ago

3.0.0

1 year ago

2.0.4

1 year ago

2.0.3

1 year ago

2.0.2

1 year ago

2.0.1

1 year ago

2.0.0

1 year ago

1.2.9

1 year ago

1.2.8

1 year ago

1.2.7

1 year ago

1.2.6

1 year ago

1.2.5

1 year ago

1.2.4

1 year ago

1.2.3

1 year ago

1.2.2

1 year ago

1.2.1

1 year ago

1.2.0

1 year ago

1.1.4

1 year ago

1.1.3

1 year ago

1.1.2

1 year ago

1.1.1

1 year ago

1.1.0

1 year ago

1.0.6

1 year ago

1.0.5

1 year ago

1.0.4

1 year ago