A thin wrapper over react-day-picker for full day-level selection — single, range, or multiple modes, all supported by the underlying library.
npx chandra-asri-ui add calendar| Su | Mo | Tu | We | Th | Fr | Sa |
|---|---|---|---|---|---|---|
"use client";
import { Calendar } from "@/app/components/ui/calendar";
import * as React from "react";
export function CalendarDemo() {
const [date, setDate] = React.useState<Date | undefined>(new Date());
return (
<Calendar
mode="single"
selected={date}
onSelect={setDate}
className="border-border rounded-md border"
/>
);
}
Most of this component's classNames already resolved to real tokens in this bundle (bg-accent, text-muted, bg-background) — the one exception was the selected-day state, which used the generic bg-primary text-primary-foreground shadcn tokens that this bundle doesn't define. That's remapped to bg-primary-70 text-white — the same pair the base Button's default variant uses.
"use client";
import { buttonVariants } from "@/app/components/ui/button";
import { cn } from "@/lib/utils";
import { ChevronLeft, ChevronRight } from "lucide-react";
import * as React from "react";
import { DayPicker } from "react-day-picker";
export type CalendarProps = React.ComponentProps<typeof DayPicker>;
/**
* Thin wrapper over react-day-picker, styled through its `classNames` prop.
* Two fixes from the source: (1) nav icons were react-icons' BiChevronLeft/
* BiChevronRight — replaced with lucide-react to match every other icon in
* this bundle; (2) `day_selected` used the generic shadcn tokens `bg-primary
* text-primary-foreground`, which aren't real tokens here — this bundle only
* has literal brand steps (`primary-70`) plus a handful of real semantic
* tokens (`accent`, `muted`, `background`, `foreground`) that `day_today`/
* `day_outside`/`day_range_middle` already use correctly, so only the
* selected-day classes needed remapping to `bg-primary-70 text-white`.
*/
export function Calendar({
className,
classNames,
showOutsideDays = true,
...props
}: CalendarProps) {
return (
<DayPicker
showOutsideDays={showOutsideDays}
className={cn("p-3", className)}
classNames={{
months: "flex flex-col sm:flex-row space-y-4 sm:space-x-4 sm:space-y-0",
month: "space-y-4",
caption: "flex justify-center pt-1 relative items-center",
caption_label: "text-sm font-medium",
nav: "space-x-1 flex items-center",
nav_button: cn(
buttonVariants({ variant: "outline" }),
"h-7 w-7 bg-transparent p-0 opacity-50 hover:opacity-100",
),
nav_button_previous: "absolute left-1",
nav_button_next: "absolute right-1",
table: "w-full border-collapse space-y-1",
head_row: "flex",
head_cell: "text-muted rounded-md w-8 font-normal text-[0.8rem]",
row: "flex w-full mt-2",
cell: cn(
"relative p-0 text-center text-sm focus-within:relative focus-within:z-20",
"[&:has([aria-selected])]:bg-accent [&:has([aria-selected].day-range-end)]:rounded-r-md",
props.mode === "range"
? "[&:has(>.day-range-start)]:rounded-l-md [&:has(>.day-range-end)]:rounded-r-md [&:has([aria-selected].day-outside)]:bg-accent/50 first:[&:has([aria-selected])]:rounded-l-md last:[&:has([aria-selected])]:rounded-r-md"
: "[&:has([aria-selected])]:rounded-md",
),
day: cn(
buttonVariants({ variant: "ghost" }),
"h-8 w-8 p-0 font-normal aria-selected:opacity-100",
),
day_range_start: "day-range-start",
day_range_end: "day-range-end",
day_selected:
"bg-primary-70 text-white hover:bg-primary-70 hover:text-white focus:bg-primary-70 focus:text-white",
day_today: "bg-accent text-accent-foreground",
day_outside:
"day-outside text-muted aria-selected:bg-accent/50 aria-selected:text-muted",
day_disabled: "text-muted opacity-50",
day_range_middle:
"aria-selected:bg-accent aria-selected:text-accent-foreground",
day_hidden: "invisible",
...classNames,
}}
components={{
IconLeft: () => <ChevronLeft className="h-4 w-4" />,
IconRight: () => <ChevronRight className="h-4 w-4" />,
}}
{...props}
/>
);
}
Calendar.displayName = "Calendar";