Calendar
patchui/calendarFreeComponent
patchui publishes no description for this item.
Install it
npx shadcn@latest add https://ui.hotfix.jobs/r/calendar.jsonSource
1"use client";23import {4 useCallback,5 useEffect,6 useId,7 useMemo,8 useRef,9 useState,10} from "react";11import type * as React from "react";12import { Button } from "@/components/ui/button";13import { cn } from "@/lib/utils";14import { selectionFocus } from "@/lib/recipes";1516import { CaretLeft, CaretRight } from "@phosphor-icons/react/dist/ssr";17type Mode = "single" | "range" | "multiple";1819export interface DateRange {20 from?: Date;21 to?: Date;22}2324interface BaseProps {25 /** First day of the week (0 = Sunday). Default 0. */26 weekStartsOn?: 0 | 1 | 2 | 3 | 4 | 5 | 6;27 /** Disable interaction. */28 disabled?: boolean;29 /** Disable specific dates. */30 disabledDates?: (date: Date) => boolean;31 /** Earliest selectable date. */32 fromDate?: Date;33 /** Latest selectable date. */34 toDate?: Date;35 /** Initial month to display (defaults to today or the selected value). */36 defaultMonth?: Date;37 className?: string;38}3940type SingleCalendarProps = BaseProps & {41 mode?: "single";42 value?: Date | null;43 defaultValue?: Date | null;44 onValueChange?: (value: Date | null) => void;45};4647type RangeCalendarProps = BaseProps & {48 mode: "range";49 value?: DateRange;50 defaultValue?: DateRange;51 onValueChange?: (value: DateRange) => void;52};5354type MultipleCalendarProps = BaseProps & {55 mode: "multiple";56 value?: Date[];57 defaultValue?: Date[];58 onValueChange?: (value: Date[]) => void;59};6061export type CalendarProps =62 | SingleCalendarProps63 | RangeCalendarProps64 | MultipleCalendarProps;6566const DAY_MS = 24 * 60 * 60 * 1000;67const MONTH_NAMES = [68 "January", "February", "March", "April", "May", "June",69 "July", "August", "September", "October", "November", "December",70];71const DAY_NAMES_SHORT = ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"];72const DAY_NAMES_FULL = [73 "Sunday",74 "Monday",75 "Tuesday",76 "Wednesday",77 "Thursday",78 "Friday",79 "Saturday",80];8182function startOfDay(d: Date): Date {83 const x = new Date(d);84 x.setHours(0, 0, 0, 0);85 return x;86}87function isSameDay(a: Date, b: Date): boolean {88 return (89 a.getFullYear() === b.getFullYear() &&90 a.getMonth() === b.getMonth() &&91 a.getDate() === b.getDate()92 );93}94function isSameMonth(a: Date, b: Date): boolean {95 return a.getFullYear() === b.getFullYear() && a.getMonth() === b.getMonth();96}97function addMonths(d: Date, n: number): Date {98 const x = new Date(d);99 x.setDate(1);100 x.setMonth(x.getMonth() + n);101 return x;102}103function addMonthsClamped(d: Date, n: number): Date {104// … truncated
What it pulls in
npm packages
Other registry items
Files it writes
More from patchui
All 51 items| Component | Registry | Kind | Access | Installs | Command |
|---|---|---|---|---|---|
| Accordionaccordion | patchui | Components | Free | 2 deps | |
| Avataravatar | patchui | Components | Free | 3 deps | |
| Badgebadge | patchui | Components | Free | 2 deps | |
| Breadcrumbbreadcrumb | patchui | Components | Free | 1 dep | |
| Buttonbutton | patchui | Components | Free | 2 deps | |
| Cardcard | patchui | Components | Free | 1 dep | |
| Checkboxcheckbox | patchui | Components | Free | 2 deps | |
| Comboboxcombobox | patchui | Components | Free | 3 deps |
