react-mail-inbox 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +249 -0
- package/dist/index.css +716 -0
- package/dist/index.css.map +1 -0
- package/dist/index.d.mts +39 -0
- package/dist/index.d.ts +39 -0
- package/dist/index.js +2263 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +2255 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +61 -0
package/README.md
ADDED
|
@@ -0,0 +1,249 @@
|
|
|
1
|
+
# Gmail Inbox Component
|
|
2
|
+
|
|
3
|
+
A fully customizable, Gmail-style inbox component built with React, featuring a rich text editor powered by Lexical.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- 📧 **Email Composition**: Full-featured email composer with To/CC/BCC fields
|
|
8
|
+
- ✍️ **Rich Text Editor**: Powered by Lexical with formatting options (bold, italic, underline, lists, links, etc.)
|
|
9
|
+
- 🎨 **Theme Support**: Built-in dark/light theme switching
|
|
10
|
+
- 📎 **File Attachments**: Drag-and-drop file upload with preview
|
|
11
|
+
- 🔍 **Email Autocomplete**: Async email suggestions as you type
|
|
12
|
+
- 🎯 **Fully Typed**: Written in TypeScript with complete type definitions
|
|
13
|
+
- 🎭 **Customizable**: Flexible API with slots for custom content
|
|
14
|
+
|
|
15
|
+
## Installation
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
npm install @your-org/gmail-inbox
|
|
19
|
+
# or
|
|
20
|
+
yarn add @your-org/gmail-inbox
|
|
21
|
+
# or
|
|
22
|
+
pnpm add @your-org/gmail-inbox
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
### Peer Dependencies
|
|
26
|
+
|
|
27
|
+
This package requires the following peer dependencies:
|
|
28
|
+
|
|
29
|
+
```json
|
|
30
|
+
{
|
|
31
|
+
"react": "^18.0.0 || ^19.0.0",
|
|
32
|
+
"react-dom": "^18.0.0 || ^19.0.0"
|
|
33
|
+
}
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
## Usage
|
|
37
|
+
|
|
38
|
+
### Basic Example
|
|
39
|
+
|
|
40
|
+
```tsx
|
|
41
|
+
import GmailInbox, { type EmailData, type EmailOption } from '@your-org/gmail-inbox';
|
|
42
|
+
import '@your-org/gmail-inbox/styles.css';
|
|
43
|
+
|
|
44
|
+
function App() {
|
|
45
|
+
// Fetch email suggestions from your API
|
|
46
|
+
const fetchEmailOptions = async (query: string): Promise<EmailOption[]> => {
|
|
47
|
+
const response = await fetch(`/api/emails/search?q=${query}`);
|
|
48
|
+
return response.json();
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
// Handle email submission
|
|
52
|
+
const handleSendEmail = (emailData: EmailData) => {
|
|
53
|
+
console.log('Sending email:', emailData);
|
|
54
|
+
// Send to your backend API
|
|
55
|
+
fetch('/api/emails/send', {
|
|
56
|
+
method: 'POST',
|
|
57
|
+
headers: { 'Content-Type': 'application/json' },
|
|
58
|
+
body: JSON.stringify(emailData)
|
|
59
|
+
});
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
return (
|
|
63
|
+
<GmailInbox
|
|
64
|
+
fetchEmailOptions={fetchEmailOptions}
|
|
65
|
+
handleChange={handleSendEmail}
|
|
66
|
+
initialTheme="dark"
|
|
67
|
+
/>
|
|
68
|
+
);
|
|
69
|
+
}
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
### With Theme Control
|
|
73
|
+
|
|
74
|
+
```tsx
|
|
75
|
+
import GmailInbox, { useTheme, type Theme } from '@your-org/gmail-inbox';
|
|
76
|
+
|
|
77
|
+
function ThemeToggle() {
|
|
78
|
+
const { theme, toggleTheme } = useTheme();
|
|
79
|
+
|
|
80
|
+
return (
|
|
81
|
+
<button onClick={toggleTheme}>
|
|
82
|
+
{theme === 'dark' ? '☀️ Light' : '🌙 Dark'}
|
|
83
|
+
</button>
|
|
84
|
+
);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
function App() {
|
|
88
|
+
const handleThemeChange = (theme: Theme) => {
|
|
89
|
+
console.log('Theme changed to:', theme);
|
|
90
|
+
// Save to localStorage, etc.
|
|
91
|
+
};
|
|
92
|
+
|
|
93
|
+
return (
|
|
94
|
+
<GmailInbox
|
|
95
|
+
fetchEmailOptions={fetchEmailOptions}
|
|
96
|
+
handleChange={handleSendEmail}
|
|
97
|
+
initialTheme="dark"
|
|
98
|
+
onThemeChange={handleThemeChange}
|
|
99
|
+
leftChildren={<ThemeToggle />}
|
|
100
|
+
/>
|
|
101
|
+
);
|
|
102
|
+
}
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
### With Initial Data
|
|
106
|
+
|
|
107
|
+
```tsx
|
|
108
|
+
import GmailInbox, { type EmailData } from '@your-org/gmail-inbox';
|
|
109
|
+
|
|
110
|
+
function ReplyToEmail() {
|
|
111
|
+
const initialData: Partial<EmailData> = {
|
|
112
|
+
to: [{ email: 'recipient@example.com', name: 'John Doe' }],
|
|
113
|
+
subject: 'Re: Previous conversation',
|
|
114
|
+
body: '<p>Thanks for your message!</p>',
|
|
115
|
+
};
|
|
116
|
+
|
|
117
|
+
return (
|
|
118
|
+
<GmailInbox
|
|
119
|
+
fetchEmailOptions={fetchEmailOptions}
|
|
120
|
+
handleChange={handleSendEmail}
|
|
121
|
+
initialData={initialData}
|
|
122
|
+
/>
|
|
123
|
+
);
|
|
124
|
+
}
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
## API Reference
|
|
128
|
+
|
|
129
|
+
### GmailInbox Props
|
|
130
|
+
|
|
131
|
+
| Prop | Type | Required | Description |
|
|
132
|
+
|------|------|----------|-------------|
|
|
133
|
+
| `fetchEmailOptions` | `(query: string) => Promise<EmailOption[]>` | ✅ | Async function to fetch email suggestions |
|
|
134
|
+
| `handleChange` | `(emailData: EmailData) => void` | ✅ | Callback fired when user sends email |
|
|
135
|
+
| `initialData` | `Partial<EmailData>` | ❌ | Pre-populate email fields |
|
|
136
|
+
| `initialTheme` | `'light' \| 'dark'` | ❌ | Initial theme (default: `'dark'`) |
|
|
137
|
+
| `onThemeChange` | `(theme: Theme) => void` | ❌ | Callback when theme changes |
|
|
138
|
+
| `leftChildren` | `ReactNode` | ❌ | Custom content for left side of header |
|
|
139
|
+
| `rightChildren` | `ReactNode` | ❌ | Custom content for right side of header |
|
|
140
|
+
|
|
141
|
+
### Types
|
|
142
|
+
|
|
143
|
+
#### EmailData
|
|
144
|
+
|
|
145
|
+
```typescript
|
|
146
|
+
interface EmailData {
|
|
147
|
+
to: EmailOption[];
|
|
148
|
+
cc: EmailOption[];
|
|
149
|
+
bcc: EmailOption[];
|
|
150
|
+
subject: string;
|
|
151
|
+
body: string; // HTML string
|
|
152
|
+
attachments: File[];
|
|
153
|
+
}
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
#### EmailOption
|
|
157
|
+
|
|
158
|
+
```typescript
|
|
159
|
+
interface EmailOption {
|
|
160
|
+
email: string;
|
|
161
|
+
name: string;
|
|
162
|
+
}
|
|
163
|
+
```
|
|
164
|
+
|
|
165
|
+
#### Theme
|
|
166
|
+
|
|
167
|
+
```typescript
|
|
168
|
+
type Theme = 'light' | 'dark';
|
|
169
|
+
```
|
|
170
|
+
|
|
171
|
+
### useTheme Hook
|
|
172
|
+
|
|
173
|
+
Access theme state and controls from anywhere within the component tree:
|
|
174
|
+
|
|
175
|
+
```typescript
|
|
176
|
+
const { theme, toggleTheme, setTheme } = useTheme();
|
|
177
|
+
```
|
|
178
|
+
|
|
179
|
+
## Styling
|
|
180
|
+
|
|
181
|
+
The component comes with default styles that you must import:
|
|
182
|
+
|
|
183
|
+
```tsx
|
|
184
|
+
import '@your-org/gmail-inbox/styles.css';
|
|
185
|
+
```
|
|
186
|
+
|
|
187
|
+
### CSS Custom Properties
|
|
188
|
+
|
|
189
|
+
You can customize the appearance using CSS variables:
|
|
190
|
+
|
|
191
|
+
```css
|
|
192
|
+
:root {
|
|
193
|
+
--toolbar-bg: #f5f5f5;
|
|
194
|
+
--toolbar-popup-bg: #ffffff;
|
|
195
|
+
--text-color: #000000;
|
|
196
|
+
--input-border: #cccccc;
|
|
197
|
+
/* ... more variables */
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
[data-theme="dark"] {
|
|
201
|
+
--toolbar-bg: #2d2d2d;
|
|
202
|
+
--toolbar-popup-bg: #1e1e1e;
|
|
203
|
+
--text-color: #ffffff;
|
|
204
|
+
--input-border: #555555;
|
|
205
|
+
/* ... more variables */
|
|
206
|
+
}
|
|
207
|
+
```
|
|
208
|
+
|
|
209
|
+
## Editor Features
|
|
210
|
+
|
|
211
|
+
The rich text editor includes:
|
|
212
|
+
|
|
213
|
+
- **Text Formatting**: Bold, Italic, Underline, Strikethrough
|
|
214
|
+
- **Lists**: Ordered and unordered lists
|
|
215
|
+
- **Alignment**: Left, center, right alignment
|
|
216
|
+
- **Font**: Font family and size selection
|
|
217
|
+
- **Colors**: Text and background color picker
|
|
218
|
+
- **Links**: Insert and edit hyperlinks
|
|
219
|
+
- **Indentation**: Increase/decrease indent
|
|
220
|
+
- **Undo/Redo**: Full history support
|
|
221
|
+
|
|
222
|
+
## File Uploads
|
|
223
|
+
|
|
224
|
+
The component supports drag-and-drop file uploads with:
|
|
225
|
+
|
|
226
|
+
- Multiple file selection
|
|
227
|
+
- File preview with name and size
|
|
228
|
+
- Remove individual files
|
|
229
|
+
- HEIC to JPEG conversion support
|
|
230
|
+
- Configurable file size limits
|
|
231
|
+
|
|
232
|
+
## Browser Support
|
|
233
|
+
|
|
234
|
+
- Chrome (latest)
|
|
235
|
+
- Firefox (latest)
|
|
236
|
+
- Safari (latest)
|
|
237
|
+
- Edge (latest)
|
|
238
|
+
|
|
239
|
+
## License
|
|
240
|
+
|
|
241
|
+
MIT
|
|
242
|
+
|
|
243
|
+
## Contributing
|
|
244
|
+
|
|
245
|
+
Contributions are welcome! Please feel free to submit a Pull Request.
|
|
246
|
+
|
|
247
|
+
## Support
|
|
248
|
+
|
|
249
|
+
For issues and feature requests, please use the GitHub issue tracker.
|