Some checks failed
No response / noResponse (push) Has been cancelled
CI / Continuous releases (push) Has been cancelled
CI / test-dev (macos-latest) (push) Has been cancelled
CI / test-dev (ubuntu-latest) (push) Has been cancelled
CI / test-dev (windows-latest) (push) Has been cancelled
Maintenance / main (push) Has been cancelled
Scorecards supply-chain security / Scorecards analysis (push) Has been cancelled
CodeQL / Analyze (push) Has been cancelled
54 lines
1.4 KiB
TypeScript
54 lines
1.4 KiB
TypeScript
import * as React from 'react';
|
|
import Avatar from '@mui/material/Avatar';
|
|
import ButtonBase from '@mui/material/ButtonBase';
|
|
|
|
export default function UploadAvatars() {
|
|
const [avatarSrc, setAvatarSrc] = React.useState<string | undefined>(undefined);
|
|
|
|
const handleAvatarChange = (event: React.ChangeEvent<HTMLInputElement>) => {
|
|
const file = event.target.files?.[0];
|
|
if (file) {
|
|
// Read the file as a data URL
|
|
const reader = new FileReader();
|
|
reader.onload = () => {
|
|
setAvatarSrc(reader.result as string);
|
|
};
|
|
reader.readAsDataURL(file);
|
|
}
|
|
};
|
|
|
|
return (
|
|
<ButtonBase
|
|
component="label"
|
|
role={undefined}
|
|
tabIndex={-1} // prevent label from tab focus
|
|
aria-label="Avatar image"
|
|
sx={{
|
|
borderRadius: '40px',
|
|
'&:has(:focus-visible)': {
|
|
outline: '2px solid',
|
|
outlineOffset: '2px',
|
|
},
|
|
}}
|
|
>
|
|
<Avatar alt="Upload new avatar" src={avatarSrc} />
|
|
<input
|
|
type="file"
|
|
accept="image/*"
|
|
style={{
|
|
border: 0,
|
|
clip: 'rect(0 0 0 0)',
|
|
height: '1px',
|
|
margin: '-1px',
|
|
overflow: 'hidden',
|
|
padding: 0,
|
|
position: 'absolute',
|
|
whiteSpace: 'nowrap',
|
|
width: '1px',
|
|
}}
|
|
onChange={handleAvatarChange}
|
|
/>
|
|
</ButtonBase>
|
|
);
|
|
}
|