Skip to main content

Hooks

Kaal provides React hooks for managing date and time picker state.

useDatePicker

A hook for managing DatePicker state with optional constraints.

Import

import { useDatePicker } from '@dreamstack-us/kaal';

Usage

const {
selectedDate,
setSelectedDate,
displayMonth,
setDisplayMonth,
goToNextMonth,
goToPrevMonth,
goToToday,
isDateDisabled,
} = useDatePicker({
initialDate: new Date(),
minDate: new Date('2024-01-01'),
maxDate: new Date('2024-12-31'),
disabledDates: [],
});

Options

OptionTypeDescription
initialDateDateThe initial selected date
minDateDateMinimum selectable date
maxDateDateMaximum selectable date
disabledDatesDate[]Array of disabled dates

Returns

PropertyTypeDescription
selectedDateDateCurrent selected date
setSelectedDate(date: Date) => voidSet the selected date
displayMonth{ year: number; month: number }Currently displayed month
setDisplayMonth(year: number, month: number) => voidSet display month
goToNextMonth() => voidNavigate to next month
goToPrevMonth() => voidNavigate to previous month
goToToday() => voidNavigate to current month
isDateDisabled(date: Date) => booleanCheck if date is disabled

useCalendar

A hook for generating calendar data for a given month.

Import

import { useCalendar } from '@dreamstack-us/kaal';

Usage

const { days, weekDays, monthName } = useCalendar({
year: 2024,
month: 0, // January
locale: 'en-US',
firstDayOfWeek: 0, // Sunday
});

Options

OptionTypeDescription
yearnumberThe year
monthnumberThe month (0-11)
localestringLocale for formatting
firstDayOfWeek0-6First day of week

Returns

PropertyTypeDescription
daysDate[]All days in the month
weekDaysstring[]Localized weekday names
monthNamestringLocalized month name
weeksInMonthnumberNumber of weeks

useTimePicker

A hook for managing TimePicker state.

Import

import { useTimePicker, type TimeValue } from '@dreamstack-us/kaal';

Usage

const {
time,
setTime,
hours,
minutes,
period,
setHours,
setMinutes,
setPeriod,
isTimeDisabled,
} = useTimePicker({
initialTime: { hours: 9, minutes: 30 },
is24Hour: false,
minuteInterval: 15,
minTime: { hours: 9, minutes: 0 },
maxTime: { hours: 17, minutes: 0 },
});

Options

OptionTypeDescription
initialTimeTimeValueInitial time value
is24HourbooleanUse 24-hour format
minuteIntervalnumberMinute selection interval
minTimeTimeValueMinimum selectable time
maxTimeTimeValueMaximum selectable time

Returns

PropertyTypeDescription
timeTimeValueCurrent time
setTime(time: TimeValue) => voidSet the time
hoursnumberCurrent hours (in 12h or 24h based on format)
minutesnumberCurrent minutes
period'AM' | 'PM'AM/PM (only in 12h mode)
setHours(hours: number) => voidSet hours
setMinutes(minutes: number) => voidSet minutes
setPeriod(period: 'AM' | 'PM') => voidSet period
isTimeDisabled(time: TimeValue) => booleanCheck if time is disabled