CaliJS :palm_tree:
Build simple, lightweight React calendars & datepickers with a single hook
Installation
This module is distributed via [npm][npm] which is bundled with [node][node] and
should be installed as one of your project's dependencies
:
npm install --save calijs
This package also depends on react
and dayjs
. Please make sure you have them installed
as well. 👍
Usage
Try it out in the browser
const {
date,
selectedDate,
nextMonth,
previousMonth,
nextYear,
previousYear,
selectDay,
getMonthDays,
setMonth,
setYear,
} = useCali();
The useCali()
hook returns the hook object based on now as the initial date.
Pass a different date to the hook such as useCali("12-19-1989");
to start at a different date.
The hook
date
dayjs()
The current date as a dayjs object
selectedDate
dayjs()
The selected date as a dayjs object
nextMonth()
function()
Sets the date one month ahead
previousMonth()
function()
Sets the date one month before
nextYear()
function()
Sets the current date one year ahead
previousYear()
function()
Sets the current date one year before
selectDay(date)
function(date)
Call with a date to set the selectedDate
getMonthDays()
function()
When called it turns a 42 item array of day objects ({ date: dayjs(), inMonth: boolean, isSelected: boolean })
to be used in 6 x 7 grid for calendars and datepickers
setYear(year)
function(year) | year: string || number | optional
Sets the current year to the passed year. Year parameter can be a string or a number. If year is not valid it throws an invalid year error
setMonth(month)
function(month) | month: string || number | optional
Sets the current month to the passed month.
Month parameter can be a string or a number from 0 - 11. If range is exceeded, it will be bubbled up to the year.
If month is not valid it throws an invalid month error.
LISENCE
MIT