Calendar Widgets
einui/calendar-widgetFreeComponent
Calendar widgets for displaying dates, events, and scheduling information.
Live preview
live · rendered by the registry
Rendered by einui on their own page — this is the component running, not a screenshot of it.Install it
npx shadcn@latest add https://ui.eindev.ir/r/calendar-widget.jsonSource
1"use client";23import * as React from "react";4import { cn } from "@/lib/utils";5import { ChevronLeft, ChevronRight, Plus, Clock } from "lucide-react";6import { GlassWidgetBase } from "./base-widget";78// Helper: returns the start-of-month Date for a given date9function getMonthStart(date: Date) {10 return new Date(date.getFullYear(), date.getMonth(), 1);11}1213interface CalendarWidgetProps {14 date?: Date;15 selectedDate?: Date;16 onDateSelect?: (date: Date) => void;17 className?: string;18}1920function CalendarWidget({21 date,22 selectedDate,23 onDateSelect,24 className,25}: CalendarWidgetProps) {26 const [internalDate, setInternalDate] = React.useState<Date | null>(date ?? null);2728 // Always create the month state (avoid conditional hooks). Use a deterministic fallback date.29 const [currentMonth, setCurrentMonth] = React.useState<Date>(() =>30 getMonthStart(date ?? new Date(0))31 );3233 // On mount/client, set "now" if no date prop was provided.34 React.useLayoutEffect(() => {35 // eslint-disable-next-line react-hooks/set-state-in-effect36 if (!date) setInternalDate(new Date());37 }, [date]);3839 // When internalDate is ready, sync currentMonth.40 React.useLayoutEffect(() => {41 if (internalDate) {42 // eslint-disable-next-line react-hooks/set-state-in-effect43 setCurrentMonth(getMonthStart(internalDate));44 }45 }, [internalDate]);4647 if (!internalDate) {48 // Lightweight client-side loading state to avoid using `new Date()` during prerender49 return (50 <GlassWidgetBase className={cn("min-w-60 p-4", className)} glowColor="purple">51 <div className="h-6 w-36 bg-white/8 rounded animate-pulse" />52 <div className="h-36 w-full mt-3 bg-white/8 rounded animate-pulse" />53 </GlassWidgetBase>54 );55 }5657 const selected = selectedDate ?? internalDate;5859 const monthName = currentMonth.toLocaleDateString("en-US", { month: "short" });60 const year = currentMonth.getFullYear();6162 const firstDay = new Date(currentMonth.getFullYear(), currentMonth.getMonth(), 1);63 const lastDay = new Date(currentMonth.getFullYear(), currentMonth.getMonth() + 1, 0);64 const startPadding = firstDay.getDay();65 const daysInMonth = lastDay.getDate();6667 const days = Array.from({ length: startPadding + daysInMonth }, (_, i) => {68 if (i < startPadding) return null;69 return i - startPadding + 1;70 });7172 const prevMonth = () => {73 setCurrentMonth(new Date(currentMonth.getFullYear(), currentMonth.getMonth() - 1, 1));74 };7576// … truncated
What it pulls in
npm packages
Other registry items
Files it writes
More from einui
All 44 items| Component | Registry | Kind | Access | Installs | Command |
|---|---|---|---|---|---|
| Base Widgetbase-widget | einui | Components | Free | 1 dep | |
| Clock Widgetsclock-widget | einui | Components | Free | 1 dep | |
| Glass Alert Dialogglass-alert-dialog | einui | Components | Free | 1 dep | |
| Glass Avatarglass-avatar | einui | Components | Free | 1 dep | |
| Glass Badgeglass-badge | einui | Components | Free | 1 dep | |
| Glass Breadcrumbglass-breadcrumb | einui | Components | Free | 1 dep | |
| Glass Buttonglass-button | einui | Components | Free | 2 deps | |
| Glass Cardglass-card | einui | Components | Free | no deps |
