The profile picture preview and file uploader that needs to be implemented executes a file upload when the Profile Picture Preview is clicked. The design features a default image for the profile picture preview with text inside it. The development environment includes TypeScript, React, Next.js, and emotion/styled.
This is an SVG created to be similar to the original due to copyright reasons.
We set the default image for the file uploader.
We input the editable text and set the position according to the design.
Set the htmlFor attribute of the label tag and the id attribute of the input tag to be the same. Now, clicking the image will open the image file selection window.
To implement the profile picture preview, import useRef and useState.
Set up the ref and styles so that when the profile picture changes, the preview image updates accordingly.
We can complete the profile picture preview implementation by writing the updateImage arrow function and assigning it to the onChange event.
When using a non-square image, it may appear repeated, as shown in the above image. We can control the repeating method of the background image using the background-repeat property
[1].
The background-repeat
[1] has several options, and if we set it to no-repeat
, we can achieve a result like the image above.