Skip to content
Branch: master
Find file History
tresko docs(hooks): update docs
affects: @datepicker-react/hooks
Latest commit 4ba9420 Aug 23, 2019
Permalink
Type Name Latest commit message Commit time
..
Failed to load latest commit information.
lib feat(date-fns): we update date-fns to version v2.0.0 Aug 23, 2019
src feat(date-fns): we update date-fns to version v2.0.0 Aug 23, 2019
CHANGELOG.md v2.0.0 Aug 23, 2019
README.md
package.json v2.0.0 Aug 23, 2019
rollup.config.js
tsconfig.json fix(scope): change packages scope Mar 31, 2019
yarn.lock

README.md

@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

Table of Contents

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.

isDateBlocked: (date: Date) => boolean

If isDateBlocked returns true, then the date is blocked.

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.

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.

goToNextMonths: () => void

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

goToPreviousMonths: () => void

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

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

You can’t perform that action at this time.