opensourceui
GitHubTwitter/X
  1. Home
  2. Components
  3. Notifications
  4. Email Notification
Back to Notifications

Components / Notifications

Email Notification

Free Notifications React component — EmailNotificationBanner. MIT licensed, copy-paste ready for Next.js and Tailwind CSS.

Mail alert on the iOS grid — sender avatar, app name header, natural from: subject — preview body line.

Preview

Sender

Mail

9:41 AM

Alex Morgan: Re: Q3 roadmap draft — Looks good — I left two notes on the timeline slide. Can you take a look before Thursday?

Setup

How to use

Free for personal and commercial use. No UI attribution required. Include the MIT copyright notice when copying component source into your project. Read the MIT license.

  1. 1

    Run in your terminal:

    $npm install clsx tailwind-merge lucide-react
  2. 2

    Copy lib/cn.ts below. Skip if you already have cn().

  3. 3

    Copy the code below and create components/notifications/email-notification-banner.tsx in your project.

  4. 4

    Import and render:

    Example

    import { EmailNotificationBanner } from "@/components/notifications/email-notification-banner";

    <EmailNotificationBanner appName="Mail" from="Alex" subject="Re: roadmap" preview="Two notes on the timeline..." />

lib/cn.ts

1
2
3
4
5
6
import { type ClassValue, clsx } from "clsx";
import { twMerge } from "tailwind-merge";
 
export function cn(...inputs: ClassValue[]) {
return twMerge(clsx(inputs));
}

components/notifications/email-notification-banner.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
"use client";
 
import {
forwardRef,
useEffect,
useState,
type ComponentPropsWithoutRef,
} from "react";
 
import Image from "next/image";
 
import { cn } from "@/lib/cn";
import { X } from "lucide-react";
 
const EXIT_MS = 260;
 
export type EmailNotificationBannerProps = Readonly<
{
appName?: string;
from?: string;
subject?: string;
preview?: string;
time?: string;
avatarSrc?: string;
avatarAlt?: string;
showTriggerLabel?: string;
onDismiss?: () => void;
onShow?: () => void;
} & ComponentPropsWithoutRef<"output">
>;
 
// Mail alert — iOS grid, sender avatar, single natural body line.
export const EmailNotificationBanner = forwardRef<
HTMLOutputElement,
EmailNotificationBannerProps
>(
(
{
className,
appName = "Mail",
from = "Alex Morgan",
subject = "Re: Q3 roadmap draft",
preview = "Looks good — I left two notes on the timeline slide. Can you take a look before Thursday?",
time = "9:41 AM",
avatarSrc = "/woman.png",
avatarAlt = "Sender",
showTriggerLabel = "Show email alert",
onDismiss,
onShow,
...props
},
ref,
) => {
const [phase, setPhase] = useState<"open" | "closing" | "closed">("open");
 
useEffect(() => {
if (phase !== "closing") return;
const timer = globalThis.setTimeout(() => setPhase("closed"), EXIT_MS);
return () => globalThis.clearTimeout(timer);
}, [phase]);
 
const handleDismiss = () => {
if (phase !== "open") return;
setPhase("closing");
onDismiss?.();
};
 
const handleShow = () => {
setPhase("open");
onShow?.();
};
 
if (phase === "closed") {
return (
<button
type="button"
onClick={handleShow}
className={cn(
"cursor-pointer rounded-xl bg-[#f2f2f7] px-4 py-2 text-xs font-medium text-neutral-700",
"opacity-100 starting:opacity-0",
"transition-opacity duration-280 ease-out hover:bg-[#e8e8ed]",
className,
)}
>
{showTriggerLabel}
</button>
);
}
 
return (
<output
ref={ref}
data-slot="email-notification-banner"
data-phase={phase}
className={cn(
"relative block w-80 overflow-hidden rounded-[1.25rem] border border-white/70 bg-white/90 p-0 font-sans",
"shadow-[0_8px_32px_-4px_rgba(0,0,0,0.10)] backdrop-blur-xl",
"translate-y-0 opacity-100 starting:-translate-y-2.5 starting:opacity-0",
"transition-all duration-340 ease-[cubic-bezier(0.25,0.46,0.45,0.94)]",
"data-[phase=closing]:-translate-y-2 data-[phase=closing]:opacity-0",
"data-[phase=closing]:duration-260 data-[phase=closing]:ease-[cubic-bezier(0.4,0,0.6,1)]",
className,
)}
{...props}
>
<button
type="button"
onClick={handleDismiss}
aria-label="Dismiss notification"
className="absolute top-2 right-2 z-10 flex size-6 cursor-pointer items-center justify-center rounded-full text-neutral-400 transition-colors duration-150 hover:bg-black/5 hover:text-neutral-600"
>
<X size={10} />
</button>
 
<div className="grid grid-cols-[2.375rem_minmax(0,1fr)] items-start gap-x-3 gap-y-1 px-3.5 py-3 pr-9">
<div className="relative row-span-2 mt-0.5 size-9.5 shrink-0 overflow-hidden rounded-[0.625rem] shadow-sm ring-1 ring-black/2">
<Image
src={avatarSrc}
alt={avatarAlt}
fill
sizes="38px"
className="object-cover"
/>
</div>
 
<div className="col-start-2 flex min-w-0 items-center justify-between gap-2">
<p className="truncate text-[13px] leading-tight font-semibold text-neutral-900">
{appName}
</p>
<span className="shrink-0 text-[11px] leading-none tracking-tight text-neutral-400">
{time}
</span>
</div>
 
<p className="col-start-2 line-clamp-3 text-[13px] leading-[1.38] text-neutral-700">
<span className="font-semibold text-neutral-900">{from}</span>
<span className="text-neutral-500">: </span>
<span className="font-medium text-neutral-800">{subject}</span>
<span className="text-neutral-500"> — </span>
{preview}
</p>
</div>
</output>
);
},
);
 
EmailNotificationBanner.displayName = "EmailNotificationBanner";
PreviousNext

On this

page

Jump to a section on this page.

  • lib/cn.ts
  • components/notifications/email-notification-banner.tsx

Sponsor spot · demo preview

Logo

Your brand name

Your tagline or category

A short pitch about your product or service goes here. This is a preview of how sponsor cards will look in this sidebar.

Your call to action

This slot is available. Sponsor Opensource UI and reach developers browsing components every day.