shadcn.io is not affiliated with official shadcn/ui
Avatar Upload Account Block for React
The current picture of an account with a file chooser that checks the type and size in words, the last five pictures kept as tiles with Restore and an in-place Delete, and a switch that keeps the history.
Installation
Overview
Show the picture an account has and the ones it used to have, with this picture panel for React with Base UI. There are no photos here: a picture is initials in a neutral tone, or the file the visitor chooses. A band at the top holds the current picture, where it shows (comments, mentions, your profile) and the block's one Shine Button, Replace picture, which opens the file chooser through a File Upload trigger and says in words what is wrong with a file it refuses. Under it, "Pictures we keep" is a hairline row of five tiles, each with the day it was set, a Restore that swaps places with the current picture and a Delete that asks in the tile itself. The last band is a Switch that keeps the history; turning it off deletes the kept pictures after an Alert Dialog. A chosen file is read in this tab with an object URL, drawn with an Avatar and released when the page goes. It's built from File Upload, Avatar, Switch, Alert Dialog, Empty, Button, Shine Button and Guides, with a CSS entrance only. For the account page of any app that shows its members.
FAQ
Why are there no photos?
The block draws pictures as initials in a shape and a tone taken from the theme's neutral colours, so it never ships a stock portrait. The only real picture is the one a visitor chooses, and it is read in their own tab with an object URL: nothing is uploaded, it is not kept past a reload and the URL is released when the page goes, when a picture is deleted and when the oldest one drops off the history.
What does the file chooser accept?
A PNG, a JPEG or a WebP of 2 MB or less. The type and size come from the file's own properties, and a file that fails is named with its reason ("banner.gif is not a PNG, JPEG or WebP", "huge.png is 3 MB. The limit is 2 MB.") in a slot that is always there, so the panel does not move. The current picture stays. Change ACCEPT, TYPES and LIMIT to your own rules, and validate again on your server.
How does the history work?
Replacing the picture puts the old one at the front of the kept row. The row holds the last five, so a sixth pushes the oldest out and the status line says so. Restore swaps the chosen tile with the current picture, so nothing is lost. Delete turns the tile's buttons into "Delete" and "Keep" with the question "Delete this one?"; Escape keeps it, and focus moves to the next tile. Free slots stay drawn, so the row keeps its height.
What does the switch do?
It keeps the history. With pictures kept, turning it off opens an alert dialog that says they are deleted for good and that new ones will no longer be kept; Keep history is focused first and Escape closes it with the switch still on. Confirming deletes them and the grid becomes an empty state that says history is off, with one button to turn it back on. With nothing kept, the switch just flips.
What stays local, and how do I make it real?
Everything: choosing, restoring and deleting change this page's state and say so in the foot. To make it real, upload the accepted file to your storage in accepted, keep the returned address in the picture's url, and call your endpoints in restore, remove and confirmOff. Show a failure in the same status line and keep the old picture until the server answers.
Is it accessible, and how does it look on a phone?
Every tile's buttons say which picture they are for ("Restore the picture from 12 Aug"), the pictures are drawn with their words beside them, and the status line is a polite live region present from the start. On a phone the tiles go three across in two rows with a sixth slot that reads "Free", and the Replace button takes the full width.
Related
- Pro
Avatar Customizer Account
ProfileA designer for the initials avatar: a framed preview at three sizes and in an account chip, with initials, shape, one of eight neutral tones and a ring, saved or discarded in the page.
- Pro
Basic Info Account
ProfileThe identity fields of an account as ruled rows that edit in place: full name, a username checked against taken names, an email that stays unverified until confirmed, a masked phone and a date of birth.
- Pro
Profile Appearance Account
ProfileHow a member's name shows to other people: a display name choice, a switch each for the avatar and the handle, and three drawn cells that re-render live as a comment, a mention and a team-list row.
- Pro
Avatar Upload Onboarding
Profile and accountA picture step split in two: the member's initials turn into a round cropper for a file chosen on the device, and the crop shows live at 96, 40 and 24 pixels.
- Pro
A profile page with its cover-crop dialog shown open: a drawn landscape in an image cropper with shape, zoom, turn and reset controls, and the same crop shown live as an avatar, a card thumbnail and a banner strip.
- Pro
Profile Completion Account
ProfileHow complete a profile is by section: a derived percent over a segmented bar, four sections that open one at a time to their items, and a Not applicable that counts as done and can be undone.