mirror of
https://github.com/christianvidalwolf-prog/Craze-Data-check.git
synced 2026-08-03 15:15:24 +02:00
feat: implement auto-resize textareas in EditPanel for descriptions and details
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import React, { useState, useRef, useCallback } from 'react';
|
||||
import React, { useState, useRef, useCallback, useEffect } from 'react';
|
||||
import { ExcelRow } from '../types';
|
||||
import { useColumns } from '../contexts/ColumnsContext';
|
||||
import { X, Sparkles, Save, Loader2, Languages, Package, CheckCircle2, Mic, MicOff } from 'lucide-react';
|
||||
@@ -40,6 +40,48 @@ const DimensionInput = ({ label, value, isModified, onChange, placeholder }: Dim
|
||||
</div>
|
||||
);
|
||||
|
||||
const AutoResizeTextarea = ({
|
||||
id,
|
||||
value,
|
||||
onChange,
|
||||
onKeyDown,
|
||||
className,
|
||||
placeholder
|
||||
}: {
|
||||
id?: string;
|
||||
value: string;
|
||||
onChange: (e: React.ChangeEvent<HTMLTextAreaElement>) => void;
|
||||
onKeyDown?: (e: React.KeyboardEvent) => void;
|
||||
className?: string;
|
||||
placeholder?: string;
|
||||
}) => {
|
||||
const textareaRef = useRef<HTMLTextAreaElement>(null);
|
||||
|
||||
const adjustHeight = useCallback(() => {
|
||||
const textarea = textareaRef.current;
|
||||
if (textarea) {
|
||||
textarea.style.height = 'auto';
|
||||
textarea.style.height = `${textarea.scrollHeight}px`;
|
||||
}
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
adjustHeight();
|
||||
}, [value, adjustHeight]);
|
||||
|
||||
return (
|
||||
<textarea
|
||||
id={id}
|
||||
ref={textareaRef}
|
||||
value={value}
|
||||
onChange={onChange}
|
||||
onKeyDown={onKeyDown}
|
||||
className={cn(className, "overflow-hidden resize-none")}
|
||||
placeholder={placeholder}
|
||||
/>
|
||||
);
|
||||
};
|
||||
|
||||
interface FieldEditorProps {
|
||||
title: string;
|
||||
field: string;
|
||||
@@ -112,13 +154,13 @@ const FieldEditor = ({
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
<textarea
|
||||
<AutoResizeTextarea
|
||||
id={`field-${field}`}
|
||||
value={value}
|
||||
onChange={e => onChange(e.target.value)}
|
||||
onKeyDown={onKeyDown}
|
||||
className={cn(
|
||||
"w-full h-32 bg-slate-900 border rounded-md p-3 text-sm text-white focus:outline-none focus:ring-1 transition-colors resize-none",
|
||||
"w-full min-h-[128px] bg-slate-900 border rounded-md p-3 text-sm text-white focus:outline-none focus:ring-1 transition-colors",
|
||||
isModified ? "border-blue-500 focus:ring-blue-500" : "border-slate-700 focus:border-slate-500 focus:ring-slate-500"
|
||||
)}
|
||||
placeholder={`Enter ${title}...`}
|
||||
@@ -359,11 +401,11 @@ export function EditPanel({ row, rowIndex, onSave, onClose, onCaptureState }: Ed
|
||||
</div>
|
||||
<div className="col-span-2">
|
||||
<span className="block text-xs text-slate-500 mb-1">Details (DE)</span>
|
||||
<textarea
|
||||
<AutoResizeTextarea
|
||||
value={formData.detailsDe}
|
||||
onChange={e => setFormData(prev => ({ ...prev, detailsDe: e.target.value }))}
|
||||
className={cn(
|
||||
"w-full h-20 bg-slate-900 border rounded p-2 text-sm text-white focus:outline-none focus:ring-1 transition-colors resize-none",
|
||||
"w-full min-h-[80px] bg-slate-900 border rounded p-2 text-sm text-white focus:outline-none focus:ring-1 transition-colors",
|
||||
isModified('detailsDe') ? "border-blue-500 focus:ring-blue-500" : "border-slate-700/50"
|
||||
)}
|
||||
placeholder="Enter details in German..."
|
||||
@@ -371,11 +413,11 @@ export function EditPanel({ row, rowIndex, onSave, onClose, onCaptureState }: Ed
|
||||
</div>
|
||||
<div className="col-span-2">
|
||||
<span className="block text-xs text-slate-500 mb-1">Details (EN)</span>
|
||||
<textarea
|
||||
<AutoResizeTextarea
|
||||
value={formData.detailsEn}
|
||||
onChange={e => setFormData(prev => ({ ...prev, detailsEn: e.target.value }))}
|
||||
className={cn(
|
||||
"w-full h-20 bg-slate-900 border rounded p-2 text-sm text-white focus:outline-none focus:ring-1 transition-colors resize-none",
|
||||
"w-full min-h-[80px] bg-slate-900 border rounded p-2 text-sm text-white focus:outline-none focus:ring-1 transition-colors",
|
||||
isModified('detailsEn') ? "border-blue-500 focus:ring-blue-500" : "border-slate-700/50"
|
||||
)}
|
||||
placeholder="Enter details in English..."
|
||||
|
||||
Reference in New Issue
Block a user