Back

Calendar Event Card

A styled card for displaying calendar events with color indicators, status states, and action buttons.

Category
CardReact
CSS
Tailwind

Manual

Create a file and paste the following code into it.

calendar-event-card.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
"use client";

import type { FC, ReactNode } from "react";
import { HugeiconsIcon, Loading03Icon, Tick02Icon } from "@/components/icons";
import { cn } from "@/lib/cn";

export type EventStatus = "idle" | "loading" | "completed";
export type EventVariant = "display" | "action";

export interface CalendarEventCardProps {
	eventColor: string;
	status?: EventStatus;
	label?: string;
	children: ReactNode;
	variant?: EventVariant;
	buttonColor?: "primary" | "danger";
	completedLabel?: string;
	onAction?: () => void;
	isDotted?: boolean;
	opacity?: number;
	className?: string;
}

export const CalendarEventCard: FC<CalendarEventCardProps> = ({
	eventColor,
	status = "idle",
	label,
	children,
	variant = "display",
	buttonColor = "primary",
	completedLabel = "Completed",
	onAction,
	isDotted = false,
	opacity = 1,
	className,
}) => {
	const hasAction = variant === "action" && onAction;
	const finalOpacity = status === "completed" ? 0.5 : opacity;

	const buttonColorClasses = {
		primary: "bg-sky-500 hover:bg-sky-600 text-white",
		danger: "bg-red-500 hover:bg-red-600 text-white",
	};

	return (
		<div
			className={cn(
				"relative flex gap-2 rounded-lg p-3 pr-2 pl-5 transition-colors",
				hasAction ? "items-end" : "items-start",
				isDotted && "border-2 border-dashed",
				className,
			)}
			style={{
				...(isDotted
					? {
							borderColor: `${eventColor}80`,
							backgroundColor: `${eventColor}10`,
						}
					: {
							backgroundColor: `${eventColor}20`,
						}),
				opacity: finalOpacity,
			}}
		>
			{/* Color indicator bar */}
			<div className="absolute top-0 left-1 flex h-full items-center">
				<div
					className="h-[80%] w-1 flex-shrink-0 rounded-full"
					style={{
						backgroundColor: eventColor,
					}}
				/>
			</div>

			{/* Content */}
			<div className="min-w-0 flex-1">
				{label && (
					<div
						className={cn(
							"mb-1 text-xs font-medium",
							isDotted
								? "text-blue-600 dark:text-blue-400"
								: "text-zinc-600 dark:text-zinc-500",
						)}
					>
						{label}
					</div>
				)}
				{children}
			</div>

			{/* Action button */}
			{hasAction && (
				<button
					type="button"
					className={cn(
						"flex items-center gap-2 rounded-lg px-4 py-2 text-sm font-medium transition-colors disabled:opacity-50 disabled:cursor-not-allowed",
						buttonColorClasses[buttonColor],
					)}
					disabled={status === "completed"}
					onClick={onAction}
				>
					{status === "loading" ? (
						<>
							<HugeiconsIcon
								icon={Loading03Icon}
								size={16}
								className="animate-spin"
							/>
							Confirm
						</>
					) : status === "completed" ? (
						<>
							<HugeiconsIcon icon={Tick02Icon} size={16} />
							{completedLabel}
						</>
					) : (
						"Confirm"
					)}
				</button>
			)}
		</div>
	);
};

// Event content components for convenience
export interface EventTitleProps {
	children: ReactNode;
	className?: string;
}

export const EventTitle: FC<EventTitleProps> = ({ children, className }) => (
	<h3 className={cn("font-medium text-zinc-900 dark:text-zinc-100", className)}>
		{children}
	</h3>
);

export interface EventTimeProps {
	startTime: string;
	endTime?: string;
	className?: string;
}

export const EventTime: FC<EventTimeProps> = ({
	startTime,
	endTime,
	className,
}) => (
	<p className={cn("text-sm text-zinc-600 dark:text-zinc-400", className)}>
		{startTime}
		{endTime && ` - ${endTime}`}
	</p>
);

export interface EventLocationProps {
	children: ReactNode;
	className?: string;
}

export const EventLocation: FC<EventLocationProps> = ({
	children,
	className,
}) => (
	<p className={cn("text-xs text-zinc-500 dark:text-zinc-500", className)}>
		{children}
	</p>
);

Update the import paths to match your project setup.

Similar screens