npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@datepicker-react/hooks

v2.8.4

Published

React hooks for datepicker.

Downloads

132,595

Readme

@datepicker-react/hooks

Gzip size Coverage Status Build Status Netlify Status

NPM

Getting Started

Install

yarn add @datepicker-react/hooks

Include hooks

import {useDatepicker, useMonth, useDay} from '@datepicker-react/hooks'

Example (codesandbox)

Articles

useDatepicker

The useDatepicker hook returns functions like goToPreviousMonths, goToNextMonths, etc., which allows us to control the datepicker.

useDatepickerProps

onDatesChange: (data: OnDatesChangeProps) => void

A callback is triggered when the date is selected (onDaySelect).

minBookingDate: Date | undefined

If prop is set, then all dates before minBookingDate are disabled.

maxBookingDate: Date | undefined

If prop is set, then all dates after maxBookingDate are disabled.

startDate: Date | null

Current start date.

endDate: Date | null

Current end date.

focusedInput: 'startDate' | 'endDate' | null

Current focused date.

numberOfMonths: number | undefined (Default: 2)

Number of visible months.

minBookingDays: number | undefined (Default: 1)

Minimum allowed date range in days.

exactMinBookingDays: boolean | undefined (Default: false)

If exactMinBookingDays is true, then the range of dates is always the same as minBookingDays.

firstDayOfWeek: 0 | 1 | 2 | 3 | 4 | 5 | 6 (Default: 1 - Monday)

First day of the week.

initialVisibleMonth? Date

Initial visible month

isDateBlocked: (date: Date) => boolean

If isDateBlocked returns true, then the date is blocked.

changeActiveMonthOnSelect?: boolean

If this is false, the active month panel will not change when selecting the start date.

unavailableDates?: Date[]

Receives unavailable dates in array.

useDatepickerResult

firstDayOfWeek: 0 | 1 | 2 | 3 | 4 | 5 | 6

First day of the week.

activeMonths: ({year: number, month: number})[]

Array of visible months. Each month is an object that contains year and month.

numberOfMonths: number

Number of visible months.

focusedDate: Date | null

Focused date.

isDateSelected: (date: Date) => boolean

Returns true if a date is selected or within the selected range, otherwise false.

isDateHovered: (date: Date) => boolean

Returns true if a date is hovered, otherwise false.

isDateBlocked: (date: Date) => boolean

Returns true if a date is blocked, otherwise false.

isDateFocused: (date: Date) => boolean

Returns true if a date is focused, otherwise false.

isFirstOrLastSelectedDate: (date: Date) => boolean

Returns true if a date is the first or the last date in the selected range, otherwise false.

isStartDate: (date: Date) => boolean

Returns true if a date is the first or the last date in the selected range, otherwise false.

isEndDate: (date: Date) => boolean

Returns true if a date is the first or the last date in the selected range, otherwise false.

onResetDates: () => void

Reset start and end date.

onDateHover: (date: Date) => void

Set internal hovered state.

onDateSelect: (date: Date) => void

Select a date. Which date is selected, depends on focusedInput.

onDateFocus: (date: Date) => void

Set focusedDate.

goToDate: (date: Date) => void

Updates activeMonths to specific date.

goToNextMonths: () => void

Updates activeMonths (next months) in accordance with the numberOfMonths prop.

goToNextMonthsByOneMonth: () => void

Updates activeMonths (next months) by one month.

goToPreviousMonths: () => void

Updates activeMonths (previous months) in accordance with the numberOfMonths prop.

goToPreviousMonthsByOneMonth: () => void

Updates activeMonths (previous months) by one month.

goToPreviousYear: (numYears: number = 1) => void

Go to the previous year by default.

goToNextYear: (numYears: number = 1) => void

Go to the next year by default.

useMonth

The useMonth returns all days of the month, weekday labels and month label.

useMonthProps

year

Year

month

Month

firstDayOfWeek: number | undefined (Default: 1)

First day of the week.

dayLabelFormat: (date: Date) => string | undefined (Default: (date: Date) => format(date, 'MMMM yyyy'))

Formats day label.

weekdayLabelFormat: (date: Date) => string | undefined (Default: (date: Date) => format(date, 'eeeeee'))

Formats weekday label.

monthLabelFormat: (date: Date) => string | undefined (Default: (date: Date) => format(date, 'dd'))

Formats month label.

useMonthResult

days: ({date: Date, dayLabel: string})[]

Array of day objects. Each object contains date and dayLabel.

weekdayLabels: (string)[]

Array of weekday labels.

monthLabel: string

Month label.

useDay

useDayProps

date: Date

Day date

dayRef: React.RefObject<HTMLButtonElement>

Ref of a day button.

focusedDate: Date | null

isDateFocused: (date: Date) => boolean

isDateSelected: (date: Date) => boolean

isDateHovered: (date: Date) => boolean

isDateBlocked: (date: Date) => boolean

isFirstOrLastSelectedDate: (date: Date) => boolean

onDateFocus: (date: Date) => void

onDateSelect: (date: Date) => void

onDateHover: (date: Date) => void

useDayResult

tabIndex: 0 | -1

tabIndex that you pass to the day button tabIndex.

onKeyDown: (e: KeyboardEvent) => void

onKeyDown callback that you can pass to the day button onKeyDown.

onClick: () => void

onClick callback that you pass to the day button onClick.

onMouseEnter: () => void

onMouseEnter callback that you pass to the day button onMouseEnter.

disabledDate: boolean

If true, then the date is disabled.

isWithinHoverRange: boolean

If true, then the date is within hover range.

isSelectedStartOrEnd: boolean

If true, then the date is the first or the last selected date.

isSelected: boolean

If true, then the date is selected.

Who's using

LifeOnScreen @datepicker-react/styled

License

Licensed under the MIT License, Copyright © 2019-present Miha Sedej.

See LICENSE for more information.

Buy me a coffee