Ajout paramètre message bas de page personnalisable

This commit is contained in:
Yannick Le Duc
2025-08-27 12:21:09 +02:00
parent 28df167fee
commit aa859a1e44
15 changed files with 580 additions and 207 deletions

View File

@@ -3,9 +3,7 @@
import React, { useState, useEffect } from 'react';
import { Textarea } from '@/components/ui/textarea';
import { Label } from '@/components/ui/label';
import { Tabs, TabsContent, TabsList, TabsTrigger } from '@/components/ui/tabs';
import { Alert, AlertDescription } from '@/components/ui/alert';
import { Button } from '@/components/ui/button';
import { Eye, Edit3, AlertCircle, HelpCircle } from 'lucide-react';
import { previewMarkdown, validateMarkdown } from '@/lib/markdown';
@@ -51,89 +49,116 @@ export function MarkdownEditor({
{label}
</Label>
<div className="flex items-center gap-2">
<Button
<button
type="button"
variant="ghost"
size="sm"
onClick={() => setShowHelp(!showHelp)}
className="h-6 px-2 text-xs text-muted-foreground hover:text-foreground"
className="h-6 px-2 text-xs text-muted-foreground hover:text-foreground rounded border-0 bg-transparent cursor-pointer flex items-center gap-1"
tabIndex={-1}
onKeyDown={(e) => {
if (e.key === 'Enter' || e.key === ' ') {
e.preventDefault();
setShowHelp(!showHelp);
}
}}
>
<HelpCircle className="h-3 w-3 mr-1" />
<HelpCircle className="h-3 w-3" />
Aide Markdown
</Button>
</button>
<span className="text-sm text-muted-foreground">{value.length}/{maxLength}</span>
</div>
</div>
<Tabs value={activeTab} onValueChange={(value) => setActiveTab(value as 'edit' | 'preview')}>
<TabsList className="grid w-full grid-cols-2">
<TabsTrigger value="edit" className="flex items-center gap-2">
<div className="flex items-center justify-center mb-4">
<div className="flex rounded-lg border bg-muted p-1">
<button
type="button"
onClick={() => setActiveTab('edit')}
className={`px-3 py-1.5 text-sm font-medium rounded-md transition-colors flex items-center gap-2 ${
activeTab === 'edit'
? 'bg-background text-foreground shadow-sm'
: 'text-muted-foreground hover:text-foreground'
}`}
tabIndex={-1}
>
<Edit3 className="h-4 w-4" />
Éditer
</TabsTrigger>
<TabsTrigger value="preview" className="flex items-center gap-2">
</button>
<button
type="button"
onClick={() => setActiveTab('preview')}
className={`px-3 py-1.5 text-sm font-medium rounded-md transition-colors flex items-center gap-2 ${
activeTab === 'preview'
? 'bg-background text-foreground shadow-sm'
: 'text-muted-foreground hover:text-foreground'
}`}
tabIndex={-1}
>
<Eye className="h-4 w-4" />
Prévisualiser
</TabsTrigger>
</TabsList>
</button>
</div>
</div>
<TabsContent value="edit" className="space-y-4">
<Textarea
id="markdown-editor"
value={value}
onChange={(e) => handleChange(e.target.value)}
placeholder={placeholder}
className="min-h-[200px] font-mono text-sm"
/>
{/* Aide markdown (affichée conditionnellement) */}
{showHelp && (
<div className="rounded-lg border bg-muted/50 p-4 animate-in fade-in duration-200">
<div className="flex items-center justify-between mb-2">
<h4 className="text-sm font-medium">Syntaxe Markdown supportée</h4>
<Button
type="button"
variant="ghost"
size="sm"
onClick={() => setShowHelp(false)}
className="h-6 px-2 text-xs"
>
×
</Button>
</div>
<div className="grid grid-cols-2 gap-4 text-xs text-muted-foreground">
<div>
<p><strong>**gras**</strong> <strong>gras</strong></p>
<p><em>*italique*</em> <em>italique</em></p>
<p><u>__souligné__</u> <u>souligné</u></p>
<p><del>~~barré~~</del> <del>barré</del></p>
{activeTab === 'edit' && (
<div className="space-y-4">
<Textarea
id="markdown-editor"
value={value}
onChange={(e) => handleChange(e.target.value)}
placeholder={placeholder}
className="min-h-[200px] max-h-[300px] font-mono text-sm overflow-y-auto"
tabIndex={0}
/>
{/* Aide markdown (affichée conditionnellement) */}
{showHelp && (
<div className="rounded-lg border bg-muted/50 p-4 animate-in fade-in duration-200">
<div className="flex items-center justify-between mb-2">
<h4 className="text-sm font-medium">Syntaxe Markdown supportée</h4>
<button
type="button"
onClick={() => setShowHelp(false)}
className="h-6 px-2 text-xs rounded border-0 bg-transparent cursor-pointer hover:bg-muted"
tabIndex={-1}
>
×
</button>
</div>
<div>
<p># Titre 1</p>
<p>## Titre 2</p>
<p>- Liste à puces</p>
<p>[Lien](https://exemple.com)</p>
<div className="grid grid-cols-2 gap-4 text-xs text-muted-foreground">
<div>
<p><strong>**gras**</strong> <strong>gras</strong></p>
<p><em>*italique*</em> <em>italique</em></p>
<p><u>__souligné__</u> <u>souligné</u></p>
<p><del>~~barré~~</del> <del>barré</del></p>
</div>
<div>
<p># Titre 1</p>
<p>## Titre 2</p>
<p>- Liste à puces</p>
<p>[Lien](https://exemple.com)</p>
</div>
</div>
</div>
</div>
)}
</TabsContent>
<TabsContent value="preview" className="space-y-4">
<div className="min-h-[200px] rounded-lg border bg-background p-4">
{value ? (
<div
className="prose prose-sm max-w-none"
dangerouslySetInnerHTML={{ __html: previewContent }}
/>
) : (
<p className="text-muted-foreground italic">
Aucun contenu à prévisualiser
</p>
)}
</div>
</TabsContent>
</Tabs>
)}
{activeTab === 'preview' && (
<div className="space-y-4">
<div className="min-h-[200px] max-h-[300px] rounded-lg border bg-background p-4 overflow-y-auto">
{value ? (
<div
className="prose prose-sm max-w-none [&_ul]:space-y-1 [&_ol]:space-y-1 [&_li]:my-0"
dangerouslySetInnerHTML={{ __html: previewContent }}
/>
) : (
<p className="text-muted-foreground italic">
Aucun contenu à prévisualiser
</p>
)}
</div>
</div>
)}
{/* Messages d'erreur */}
{!validation.isValid && (