Docs
Single date selection

Single date selection

For selecting one date at a time.

The default selection mode of the Calendar component is single. This means that only one date can be selected at a time.

Usage

import { Calendar } from '@bryanberger/datepicker';
import { ChevronLeft, ChevronRight } from 'lucide-react';
 
const MyDatePicker = () => {
 
	return (
		<Calendar
			className="border rounded-md p-3"
			mode="single" // (optional when set to "single")
		>
			{ /* ... */ }
		</Calendar>
	);
};
 
export default MyDatePicker;
January 2024
SuMoTuWeThFrSa
31123456
78910111213
14151617181920
21222324252627
28293031123

Default selected date

You can set the default selected date by setting a Date object to the defaultSelected prop.

import { Calendar } from '@bryanberger/datepicker';
import { ChevronLeft, ChevronRight } from 'lucide-react';
 
const MyDatePicker = () => {
 
	const today = new Date();
 
	return (
		<Calendar
			className="border rounded-md p-3"
			mode="single"
			defaultSelected={ today }
		>
			{ /* ... */ }
		</Calendar>
	);
};
January 2024
SuMoTuWeThFrSa
31123456
78910111213
14151617181920
21222324252627
28293031123

Control the selected date

You can make the Calendar component controlled by passing the selected prop. You will then have to update the selected prop yourself by using the onSelect callback function.

import { Calendar } from '@bryanberger/datepicker';
import { ChevronLeft, ChevronRight } from 'lucide-react';
import { useState } from 'react';
 
const MyDatePicker = () => {
 
	const today = new Date();
	const [selected, setSelected] = useState<Date>(today);
 
	return (
		<div>
			<Calendar
				className="border rounded-md p-3"
				mode="single"
				selected={ selected }
				onSelect={ setSelected }
			>
				{ /* ... */ }
			</Calendar>
			<p>Selected date: { selected.toLocaleDateString() }</p>
		</div>
	);
};
January 2024
SuMoTuWeThFrSa
31123456
78910111213
14151617181920
21222324252627
28293031123

Selected date: 1/8/2024