вынесен заголовок регистрации

This commit is contained in:
2024-12-10 20:47:16 +03:00
parent ca360b2451
commit f8f6fb991a
5 changed files with 43 additions and 35 deletions
+47
View File
@@ -0,0 +1,47 @@
import * as React from 'react';
import { useState } from 'react';
import { AvatarStyled, PhotoStyled, InputStyled } from './index.style';
const Photo = ({ defaultPhoto, onPhotoChange }): React.ReactElement => {
const [photo, setPhoto] = useState(defaultPhoto);
const handleFileChange = (event) => {
const file = event.target.files[0];
if (file) {
const reader = new FileReader();
reader.onload = (e) => {
const newPhoto = e.target.result;
setPhoto(newPhoto);
if (onPhotoChange) onPhotoChange(newPhoto);
};
reader.readAsDataURL(file);
}
};
const handleAvatarClick = () => {
const fileInput = document.getElementById('fileInput') as HTMLInputElement;
fileInput.click();
}
return (
<PhotoStyled>
<AvatarStyled
src={photo}
alt="Выберите фотографию"
onClick={handleAvatarClick}
/>
<InputStyled
id="fileInput"
type="file"
accept="image/*"
onChange={handleFileChange}
/>
</PhotoStyled>
);
}
export default Photo;