mini-calendar
kibo-ui-registry/mini-calendarFreeComponent
A composable mini calendar component for picking dates close to today.
Live preview
live · rendered by the registry
Rendered by Kibo UI Registry on their own page — this is the component running, not a screenshot of it.Install it
npx shadcn@latest add https://www.kibo-ui.com/r/mini-calendar.jsonSource
1"use client";23import { useControllableState } from "@radix-ui/react-use-controllable-state";4import { addDays, format, isSameDay, isToday } from "date-fns";5import { ChevronLeftIcon, ChevronRightIcon } from "lucide-react";6import { Slot } from "radix-ui";7import {8 type ButtonHTMLAttributes,9 type ComponentProps,10 createContext,11 type HTMLAttributes,12 type MouseEventHandler,13 type ReactNode,14 useContext,15} from "react";16import { Button } from "@/components/ui/button";17import { cn } from "@/lib/utils";1819// Context for sharing state between components20type MiniCalendarContextType = {21 selectedDate: Date | null | undefined;22 onDateSelect: (date: Date) => void;23 startDate: Date;24 onNavigate: (direction: "prev" | "next") => void;25 days: number;26};2728const MiniCalendarContext = createContext<MiniCalendarContextType | null>(null);2930const useMiniCalendar = () => {31 const context = useContext(MiniCalendarContext);3233 if (!context) {34 throw new Error("MiniCalendar components must be used within MiniCalendar");35 }3637 return context;38};3940// Helper function to get array of consecutive dates41const getDays = (startDate: Date, count: number): Date[] => {42 const days: Date[] = [];43 for (let i = 0; i < count; i++) {44 days.push(addDays(startDate, i));45 }46 return days;47};4849// Helper function to format date50const formatDate = (date: Date) => {51 const month = format(date, "MMM");52 const day = format(date, "d");5354 return { month, day };55};5657export type MiniCalendarProps = HTMLAttributes<HTMLDivElement> & {58 value?: Date;59 defaultValue?: Date;60 onValueChange?: (date: Date | undefined) => void;61 startDate?: Date;62 defaultStartDate?: Date;63 onStartDateChange?: (date: Date | undefined) => void;64 days?: number;65};6667export const MiniCalendar = ({68 value,69 defaultValue,70 onValueChange,71 startDate,72 defaultStartDate = new Date(),73 onStartDateChange,74 days = 5,75 className,76 children,77 ...props78}: MiniCalendarProps) => {79 const [selectedDate, setSelectedDate] = useControllableState<80 Date | undefined81 >({82 prop: value,83 defaultProp: defaultValue,84 onChange: onValueChange,85 });8687 const [currentStartDate, setCurrentStartDate] = useControllableState({88 prop: startDate,89 defaultProp: defaultStartDate,90 onChange: onStartDateChange,91 });9293 const handleDateSelect = (date: Date) => {94 setSelectedDate(date);95 };9697 const handleNavigate = (direction: "prev" | "next") => {98 const newStartDate = addDays(99// … truncated
What it pulls in
npm packages
Other registry items
Files it writes
More from Kibo UI Registry
All 41 items| Component | Registry | Kind | Access | Installs | Command |
|---|---|---|---|---|---|
| announcementannouncement | Kibo UI Registry | Components | Free | no deps | |
| avatar-stackavatar-stack | Kibo UI Registry | Components | Free | no deps | |
| bannerbanner | Kibo UI Registry | Components | Free | 2 deps | |
| calendarcalendar | Kibo UI Registry | Components | Free | 3 deps | |
| choiceboxchoicebox | Kibo UI Registry | Components | Free | 2 deps | |
| code-blockcode-block | Kibo UI Registry | Components | Free | 5 deps · 2 files | |
| color-pickercolor-picker | Kibo UI Registry | Components | Free | 3 deps | |
| comboboxcombobox | Kibo UI Registry | Components | Free | 2 deps |
