import { memo } from 'react'; import Button from '../../../../common/components/buttons/Button'; import Input from '../../../../common/components/input/input/Input'; import style from './EditableImage.module.scss'; interface EditableImageProps { initialValue: string; readOnly?: boolean; updateValue: (newValue: string) => void; } export default memo(EditableImage); function EditableImage({ initialValue, readOnly, updateValue }: EditableImageProps) { const handleUpdate = (newValue: string) => { if (newValue === initialValue) { return; } if (newValue !== '' && !newValue.startsWith('http')) { return; } updateValue(newValue); }; const openInNewTab = () => { if (initialValue) { window.open(initialValue, '_blank', 'noopener,noreferrer'); } }; if (!initialValue && readOnly) { return null; } if (!initialValue) { return ( handleUpdate(event.currentTarget.value)} onKeyDown={(event) => { if (event.key === 'Enter') { handleUpdate(event.currentTarget.value); } }} defaultValue={initialValue} /> ); } return (
{!readOnly && (
)} {Boolean(initialValue) && }
); }