npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

react-mail-inbox

v1.0.18

Published

A customizable Gmail-style inbox component with rich text editing

Downloads

586

Readme

React Mail Inbox Component

A fully customizable, Gmail-style inbox component built with React, featuring a rich text editor powered by Lexical.

Features

  • 📧 Email Composition: Full-featured email composer with To/CC/BCC fields
  • ✍️ Rich Text Editor: Powered by Lexical with formatting options (bold, italic, underline, lists, links, etc.)
  • 🎨 Theme Support: Built-in dark/light theme switching
  • 📎 File Attachments: Drag-and-drop file upload with preview
  • 🔍 Email Autocomplete: Async email suggestions as you type
  • 🎯 Fully Typed: Written in TypeScript with complete type definitions
  • 🎭 Customizable: Flexible API with slots for custom content

Installation

npm install react-mail-inbox
# or
yarn add react-mail-inbox
# or
pnpm add react-mail-inbox

Peer Dependencies

This package requires the following peer dependencies:

{
  "react": "^18.0.0 || ^19.0.0",
  "react-dom": "^18.0.0 || ^19.0.0"
}

Usage

Basic Example

import GmailInbox, { type EmailData, type EmailOption } from "react-mail-inbox";
import "react-mail-inbox/styles.css";

function App() {
  // Fetch email suggestions from your API
  const fetchEmailOptions = async (query: string): Promise<EmailOption[]> => {
    const response = await fetch(`/api/emails/search?q=${query}`);
    return response.json();
  };

  // Handle email submission
  const handleSendEmail = (emailData: EmailData) => {
    console.log("Sending email:", emailData);
    // Send to your backend API
    fetch("/api/emails/send", {
      method: "POST",
      headers: { "Content-Type": "application/json" },
      body: JSON.stringify(emailData),
    });
  };

  return (
    <GmailInbox
      fetchEmailOptions={fetchEmailOptions}
      handleChange={handleSendEmail}
      initialTheme="dark"
    />
  );
}

With Theme Control

import GmailInbox, { useTheme, type Theme } from "react-mail-inbox";

function ThemeToggle() {
  const { theme, toggleTheme } = useTheme();

  return (
    <button onClick={toggleTheme}>
      {theme === "dark" ? "☀️ Light" : "🌙 Dark"}
    </button>
  );
}

function App() {
  const handleThemeChange = (theme: Theme) => {
    console.log("Theme changed to:", theme);
    // Save to localStorage, etc.
  };

  return (
    <GmailInbox
      fetchEmailOptions={fetchEmailOptions}
      handleChange={handleSendEmail}
      initialTheme="dark"
      onThemeChange={handleThemeChange}
      leftChildren={<ThemeToggle />}
    />
  );
}

With Initial Data

import GmailInbox, { type EmailData } from "react-mail-inbox";

function ReplyToEmail() {
  const initialData: Partial<EmailData> = {
    to: [{ email: "[email protected]", name: "John Doe" }],
    subject: "Re: Previous conversation",
    body: "<p>Thanks for your message!</p>",
  };

  return (
    <GmailInbox
      fetchEmailOptions={fetchEmailOptions}
      handleChange={handleSendEmail}
      initialData={initialData}
    />
  );
}

API Reference

GmailInbox Props

| Prop | Type | Required | Description | | ------------------- | ------------------------------------------- | -------- | ----------------------------------------- | | fetchEmailOptions | (query: string) => Promise<EmailOption[]> | ✅ | Async function to fetch email suggestions | | handleChange | (emailData: EmailData) => void | ✅ | Callback fired when user sends email | | initialData | Partial<EmailData> | ❌ | Pre-populate email fields | | initialTheme | 'light' \| 'dark' | ❌ | Initial theme (default: 'dark') | | onThemeChange | (theme: Theme) => void | ❌ | Callback when theme changes | | leftChildren | ReactNode | ❌ | Custom content for left side of header | | rightChildren | ReactNode | ❌ | Custom content for right side of header |

Types

EmailData

interface EmailData {
  to: EmailOption[];
  cc: EmailOption[];
  bcc: EmailOption[];
  subject: string;
  body: string; // HTML string
  attachments: File[];
}

EmailOption

interface EmailOption {
  email: string;
  name: string;
}

Theme

type Theme = "light" | "dark";

useTheme Hook

Access theme state and controls from anywhere within the component tree:

const { theme, toggleTheme, setTheme } = useTheme();

Styling

The component comes with default styles that you must import:

// Option 1 (recommended)
import "react-mail-inbox/styles.css";

// Option 2 (if the above doesn't work with your bundler)
import "react-mail-inbox/dist/index.css";

CSS Custom Properties

You can customize the appearance using CSS variables:

:root {
  --toolbar-bg: #f5f5f5;
  --toolbar-popup-bg: #ffffff;
  --text-color: #000000;
  --input-border: #cccccc;
  /* ... more variables */
}

[data-theme="dark"] {
  --toolbar-bg: #2d2d2d;
  --toolbar-popup-bg: #1e1e1e;
  --text-color: #ffffff;
  --input-border: #555555;
  /* ... more variables */
}

Editor Features

The rich text editor includes:

  • Text Formatting: Bold, Italic, Underline, Strikethrough
  • Lists: Ordered and unordered lists
  • Alignment: Left, center, right alignment
  • Font: Font family and size selection
  • Colors: Text and background color picker
  • Links: Insert and edit hyperlinks
  • Indentation: Increase/decrease indent
  • Undo/Redo: Full history support

File Uploads

The component supports drag-and-drop file uploads with:

  • Multiple file selection
  • File preview with name and size
  • Remove individual files
  • HEIC to JPEG conversion support
  • Configurable file size limits

Browser Support

  • Chrome (latest)
  • Firefox (latest)
  • Safari (latest)
  • Edge (latest)

License

MIT

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

Support

For issues and feature requests, please use the GitHub issue tracker.