0.0.0-alpha.9 • Published 2 years ago

@_--/react-calendar v0.0.0-alpha.9

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

@_--/react-calendar

a zero-dependency calendar component for react.

many parts still incomplete/todo, and shoddy coding style oops.

features

  • single, multi, and range selection of dates; multi selection also supports drag-and-hold to (un)select multiple dates at once.
  • keyboard navigation; unfortunately not aria-compliant grid, but supports...
    • arrow keys to navigate along tiles with wrapping,
    • tab to toggle between nav and tiles
    • shift + tab from nav to escape focus from calendar; shift+tab again after that to go to the previos element
    • home/end) to go to the start (end) of the row
    • shift + home/end to go to the first (last) tile
    • esc to unselect partial range dates, or otherwise escape focus from the calendar; tab after that to go to the next element
  • highlight/disable dates
  • hide dates before/after/outside the current month
  • set which day of the week the calendar begins on
  • set which days of the week are "weekends" to highlight
  • customize how dates/months/years/decades are displayed
  • calendar view locking
  • separate css for core styles, default styles, and useful/common add-ons, all using low-precedence selectors and css custom properties

installation

# npm
npm install @_--/react-calendar

# yarn
yarn add @_--/react-calendar

usage

import React, { useState } from 'react';
import { Calendar } from '@_--/react-calendar';

const App = () => {
  const [selectedDates, setSelectedDates] = useState([]);
  return (
      <Calendar
        onChangeSelectedDates={(newState, oldState) => { setSelectedDates(newState); }}
      />
  )
}

styling

import the main stylesheet to make a minimally unstyled calendar

import '@_--/react-calendar/dist/styles/index.css';

you can separately use or build upon the default styles

import '@_--/react-calendar/dist/styles/default.css';

a preset is also provided to force calendar tiles in the month view to be square

import '@_--/react-calendar/dist/styles/preset/square-tiles.css';

the component is styled using css custom properties, making them easy to re-style and customize

calendar props

types

nametype
DayOfWeek0 <= x < 7

props

propdescriptiontypedefault
classNameclassname to add to the calendar container elementstring
selectModehow dates are to be "selected"."single" | "multi" | "range""single"
weekStartwhich day of the week occupies the leftmost column of the calendar, where 0=Sunday, 1=Monday, ...DayOfWeek0
weekendDayswhich days of the week constitute as "weekends". weekends can be styled differently.DayOfWeek[][0, 6]
initialDatethe date the calendar will initialize its displayed dates withDatenew Date()
initialViewwhat "view" the calendar should begin with"month" | "year" | "decade""month"
hideAdjacentMonthsDateswhether dates from the adjacent months should be hidden in the "month" view (ie the 30th of the previous month, or the 1st of the next month). true hides bothboolean | "prev" | "next"
lockViewwhether the calendar view cannot be changed from its initial view of decade, year, or monthbooleanfalse
lockTileswhether the calendar view and tiles should be locked.booleanfalse
disabledDatesfunction describing which dates should be disabled. disabled dates cannot be selected.(Date) => boolean | "past" | "today" | "future"
highlightedDatesfunction describing which dates should be highlighted. highlighted dates can be styled differently(Date) => boolean | "today""today"
prevButtonIconicon for the previous button for calendar navigation within a viewstring \| JSX.element"←"
nextButtonIconicon for the next button for calendar navigation within a viewstring \| JSX.element"→"
formatDecadehow to format the decade view heading, given the first year of the decade(default formatter; ie "2000 - 2009")
formatYearhow to format the year view heading and decade view tiles(default formatter; ie "2000")
formatMonthYearhow to format the month view heading(Date) => string(default formatter; ie "January 2000")
formatMonthhow to format the year view tile labels(Date) => string(default formatter; ie "January")
formatDayOfMonthhow to format the month view tiles(Date) => string(default formatter; ie "1")
formatDayOfWeekhow to format the day of week labels(DayOfWeek) => string(default formatter; ie "Mon")
onChangeViewfunction called whenever the calendar view is changed(newView, oldView) => unknown
onChangeSelectModefunction called whenever the select mode is changed(newSelectMode, oldSelectMode) => unknown(default callback: if switching from range to multi select mode, selects all dates in the range; otherwise, clears selected dates)
onChangeSelectedDatesfunction called whenever the selected dates change(newSelectedDates, oldSelectedDates) => unknown
onChangePartialRangeDatesfunction called whenever the partial range dates, used for "soft highlighting" while in range select or drag-and-holding in multi select(newPartialRangeDates, oldPartialRangeDates) => unknown
0.0.0-alpha.9

2 years ago

0.0.0-alpha.7

2 years ago

0.0.0-alpha.8

2 years ago

0.0.0-alpha.6

2 years ago

0.0.0-alpha.5

3 years ago

0.0.0-alpha.4

3 years ago

0.0.0-alpha.3

3 years ago

0.0.0-alpha.2

3 years ago

0.0.0-alpha.1

3 years ago

0.0.0-alpha.0

3 years ago