вынесен заголовок регистрации
This commit is contained in:
@@ -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;
|
||||
Reference in New Issue
Block a user