Skip to content

harshalone/nextjs-mdx-editor

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

NextJS MDX Editor

A modern MDX editor component for Next.js applications with image upload support.

Features

  • 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

Installation

npm install nextjs-mdx-editor
# or
yarn add nextjs-mdx-editor

Setup

1. Tailwind CSS

This 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
}

2. Supabase Configuration

For image upload functionality, you need to configure Supabase:

  1. Create a Supabase project at https://supabase.com
  2. Create a storage bucket named 'blog' (or your preferred name)
  3. 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_key

Usage

import { 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}
    />
  );
}

Props

Editor

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

ImageUploadModal

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

Dependencies

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

License

MIT

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published