diff --git a/components/rich-text-editor/index.js b/components/rich-text-editor/index.js new file mode 100644 index 0000000..71d987f --- /dev/null +++ b/components/rich-text-editor/index.js @@ -0,0 +1,123 @@ +'use client' + +import {useState, useEffect} from 'react' +import PropTypes from 'prop-types' +import dynamic from 'next/dynamic' +import Box from '@mui/material/Box' +import Typography from '@mui/material/Typography' +import {useTheme} from '@mui/material/styles' + +const MDEditor = dynamic( + () => import('@uiw/react-md-editor').then(mod => mod.default), + {ssr: false} +) + +export default function RichTextEditor({ + value = '', + onChange, + placeholder = 'Rédigez votre contenu...', + label, + isRequired = false, + name = 'content' +}) { + const [content, setContent] = useState(value) + const [wordCount, setWordCount] = useState(0) + const [charCount, setCharCount] = useState(0) + const theme = useTheme() + + useEffect(() => { + setContent(value) + }, [value]) + + useEffect(() => { + if (content) { + const words = content.trim().split(/\s+/).filter(word => word.length > 0) + setWordCount(words.length) + setCharCount(content.length) + } else { + setWordCount(0) + setCharCount(0) + } + }, [content]) + + const handleChange = val => { + setContent(val || '') + if (onChange) { + onChange({ + target: { + name, + value: val || '' + } + }) + } + } + + return ( + + {label && ( + + {label} {isRequired && '*'} + + )} + + + + + + + Formatage Markdown supporté + + + {charCount} caractères • {wordCount} mots + + + + {/* Hidden input for form submission */} + + + ) +} + +RichTextEditor.propTypes = { + value: PropTypes.string, + onChange: PropTypes.func, + placeholder: PropTypes.string, + label: PropTypes.string, + isRequired: PropTypes.bool, + name: PropTypes.string +}