Spaces:
Running
Running
File size: 1,431 Bytes
2e9c97f |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
/**
* @license
* SPDX-License-Identifier: Apache-2.0
*/
import React, { useRef, useEffect } from 'react';
import type { ResumeSection, ResumeSectionType } from '../lib/types';
interface EditableSectionProps {
section: ResumeSection;
onContentChange: (sectionId: ResumeSectionType, newContent: string) => void;
isActive: boolean;
onFocus: (sectionId: ResumeSectionType, content: string) => void;
onBlur: () => void;
}
export default function EditableSection({
section,
onContentChange,
isActive,
onFocus,
onBlur,
}: EditableSectionProps) {
const contentRef = useRef<HTMLDivElement>(null);
useEffect(() => {
if (contentRef.current && section.content !== contentRef.current.innerText) {
contentRef.current.innerText = section.content;
}
}, [section.content]);
const handleInput = (e: React.FormEvent<HTMLDivElement>) => {
onContentChange(section.id, e.currentTarget.innerText);
};
return (
<div
className={`editable-section ${isActive ? 'active' : ''}`}
onFocus={() => onFocus(section.id, contentRef.current?.innerText || '')}
onBlur={onBlur}
>
<h2 className="section-title">{section.title}</h2>
<div
ref={contentRef}
className="section-content"
contentEditable
suppressContentEditableWarning={true}
onInput={handleInput}
aria-label={`${section.title} content`}
/>
</div>
);
}
|