1.3.0 • Published 2 years ago

yet-another-calendar v1.3.0

Weekly downloads
-
License
-
Repository
github
Last release
2 years ago

yet-another-calendar

A simple yet highly customizable calendar library for React.

Prides itself on having both a very simple API, but also extreme flexibility.

Installation

npm i yet-another-calendar or yarn add yet-another-calendar

Usage

import { useState } from "react";
import { Calendar, Page, nextPage } from "yet-another-calendar";

const Date = ({ date }) => <button>{date.getDate()}</button>;

const App = () => {
  const [page, setPage] = useState<Page>({ month: "may", year: 2022 });

  return (
    <div>
      {page.month} {page.year}
      <button onClick={() => setPage(nextPage)}>⮕</button>
      <Calendar page={page} renderDate={Date} />
    </div>
  );
};

Looks like this - but don't worry, a little styling and it can look however you want!

Simple calendar example

More Complex Example - "Date Range Picker"

date range selector

See this example on CodePen

Why this Calendar Library?

  • Complete behaviour flexibility, support for:
    • date pickers
    • Multiple range selectors
    • Disabled dates
    • & more!
  • Simple API
    • Just 2 props!
  • All styles can be controlled like any other React component
    • For example, using styled-components
  • Fully controlled!
  • Fully typed!
  • Fully tested - 100% code coverage!
  • Loads of examples!
  • 32x smaller bundle size compared to the most popular competitors!

When is this not the right library?

If you don't care what your calendar looks like, or how it behaves, and just want a calendar in your website ASAP - this library might not be for you.

API

<Calendar>

This is the only exported React Component. All the props are optional, but you'll probably want to set page and renderDate.

CalendarProps

PropTypeExample
pagePage{ year: 2022, month: 'jan' }
renderDate(props: DateRenderProps) => JSX.Element({date}) => <span>{date.getDate()}</span>
styleCSSProperties{ backgroundColor: 'red' }
calendarStartDayCalendarStartDay"sunday"

DateRenderProps

For Calendar's renderDate prop (above).

PropType
dateDate
belongsToPage"previous" \| "current" \| "next"

Page

FieldType
yearnumber
month"jan" \| "feb" \| ... \| "dec"

CalendarStartDay

Used to control if the calendar starts on a Monday or Sunday.

Utility Functions

FunctionType
nextPage(page: Page) => Page
previousPage(page: Page) => Page
firstDate(page: Page) => Date
lastDate(page: Page) => Date
pageForDate(date: Date) => Page

Motivation

Calendars shouldn't have a mind of their own.

Developers should be able to control their calendars with props!

This way the behaviour of the calendar is predictable and customisable.

This library was built with the idea that the developer should have complete control over their components state. It is proof that 'dumb' components only allow for greater flexibility, but also make interfaces simpler!

1.3.0

2 years ago

1.2.0

2 years ago

1.1.1

2 years ago

1.1.0

2 years ago

1.0.0

2 years ago

0.0.8

2 years ago

0.0.7

2 years ago

0.0.6

2 years ago

0.0.5

2 years ago

0.0.4

2 years ago

0.0.3

2 years ago

0.0.2

2 years ago

0.0.1

2 years ago