A modern MDX editor component for Next.js applications with image upload support.
- Rich text editing with MDX support
- Image upload with drag & drop
- Image URL insertion
- Markdown formatting toolbar
- Auto-resizing textarea
- Supabase storage integration
- TypeScript support
- Tailwind CSS styling
npm install nextjs-mdx-editor
# or
yarn add nextjs-mdx-editorThis package uses Tailwind CSS for styling. Make sure you have Tailwind CSS installed and configured in your Next.js project. Add the following to your tailwind.config.js:
module.exports = {
content: [
// ... your existing content paths
'./node_modules/nextjs-mdx-editor/dist/**/*.{js,ts,jsx,tsx}',
],
// ... rest of your config
}For image upload functionality, you need to configure Supabase:
- Create a Supabase project at https://supabase.com
- Create a storage bucket named 'blog' (or your preferred name)
- Add your Supabase URL and anon key to your environment variables:
NEXT_PUBLIC_SUPABASE_URL=your_supabase_url
NEXT_PUBLIC_SUPABASE_ANON_KEY=your_supabase_anon_keyimport { Editor } from 'nextjs-mdx-editor';
export default function MyPage() {
const handleContentChange = (content: string) => {
console.log('Content changed:', content);
};
const handleContentCompiled = (mdxSource: any) => {
console.log('MDX compiled:', mdxSource);
};
return (
<Editor
initialContent="# Hello World"
onChange={handleContentChange}
onContentCompiled={handleContentCompiled}
/>
);
}| Prop | Type | Default | Description |
|---|---|---|---|
| initialContent | string | '' | Initial content of the editor |
| onChange | (content: string) => void | - | Callback when content changes |
| onContentCompiled | (mdxSource: any) => void | - | Callback when MDX is compiled |
| onImageInsert | () => void | () => {} | Callback when image is inserted |
| className | string | '' | Additional CSS classes |
| Prop | Type | Default | Description |
|---|---|---|---|
| isOpen | boolean | - | Whether the modal is open |
| onClose | () => void | () => {} | Callback when modal is closed |
| onImageInsert | (markdownText: string) => void | () => {} | Callback when image is inserted |
| title | string | "Upload Image" | Modal title |
| description | string | "Upload an image" | Upload description |
| uploadingText | string | "Uploading..." | Upload progress text |
| bucket | string | "blog" | Supabase storage bucket name |
| showUrlTab | boolean | true | Whether to show URL tab |
| supabaseUrl | string | process.env.NEXT_PUBLIC_SUPABASE_URL | Supabase project URL |
| supabaseKey | string | process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY | Supabase anon key |
This package requires the following peer dependencies:
- react: ^18.0.0
- next: ^14.0.0
- next-mdx-remote: ^4.0.0
- lucide-react: ^0.300.0
- @heroicons/react: ^2.0.0
- react-hot-toast: ^2.4.0
- @supabase/supabase-js: ^2.0.0
- tailwindcss: ^3.0.0
MIT