Updated
Avatar Upload
NewCustomize
Size104px
circle
Blur10px
Max size5MB
Upload time2.4s
Installation
npx shadcn@latest add https://uibrik.com/r/avatar-upload.jsonInstall the packages
npm install @tabler/icons-react motionAdd the cn helper
Imports
cnfrom@/lib/utils, whichshadcn initcreates. Add it by hand without shadcn.Copy the source into your project
components/uibrik/avatar-upload/avatar-upload.tsx"use client"; import { useEffect, useId, useRef, useState, type ClipboardEvent, type DragEvent } from "react"; import { animate, AnimatePresence, motion, useMotionValue, useMotionValueEvent, useReducedMotion, useSpring, useTransform, } from "motion/react"; import { IconCameraFilled, IconCheck, IconUserFilled } from "@tabler/icons-react"; import { cn } from "@/lib/utils"; // Avatar Upload. Pick, drop or paste a photo and it shows at once, blurred, // inside the avatar, while a ring around the edge fills with the upload's // progress. The blur clears as the ring fills, so at 100% the photo is // already sharp: the picture you end on is the one you saw arrive, never a // swap to a fresh copy. // // The blur isn't a CSS filter: WebKit splits filtered layers into tiles (a // seam flickers down the middle) and can leave the photo soft after the
Adds the files to
components/uibrik/avatar-upload and installs @tabler/icons-react and motion. With the @uibrik namespace set up: npx shadcn@latest add @uibrik/avatar-upload.Usage
import { AvatarUpload } from "@/components/uibrik/avatar-upload/avatar-upload";const accept = "image/png,image/jpeg,image/webp,image/gif,image/avif";<AvatarUpload size={104} shape="circle" blur={10} maxSizeMb={5} removable showStatus defaultValue={null} name="Ada Park" accept={accept} disabled={false} onUpload={(file, { onProgress, signal }) => {}} // value="…" // onChange={(src, file) => {}}/>Where to use Avatar Upload
Profile settings
The new photo appears the moment it's picked, so the person sees the result while it saves.
Pairs with Settings Page
Onboarding
One tap, drag and drop or paste covers every way people add a photo.
Pairs with Multi-step Form
Team and workspace logos
The rounded shape fits logos, and failed uploads keep the image with a Retry.
Pairs with Team Roster
Props
AvatarUpload- size
- Type number
- 104
- Avatar diameter.
- shape
- Type "circle" | "rounded"
- "circle"
- Circle for people, rounded square for logos.
- blur
- Type number
- 10
- Blur on the photo at 0%. It clears as the upload runs.
- maxSizeMb
- Type number
- 5
- Largest file accepted.
- removable
- Type boolean
- true
- Show a Remove action under a set photo.
- showStatus
- Type boolean
- true
- Hints, progress and errors under the avatar.
- value / onChange
- Type string | null / (src, file?) => void
- –
- Controlled image URL. onChange gets the stored URL (or the local preview URL with no onUpload) and the picked file, or null on remove.
- defaultValue
- Type string | null
- –
- Image URL on mount when uncontrolled.
- onUpload
- Type (file, { onProgress, signal }) => Promise<string | void>
- –
- Uploads the file. Call onProgress with 0 to 1, resolve with the stored image's URL, throw to fail. The signal aborts when the person cancels. Leave out to accept files locally.
- name
- Type string
- –
- Initials shown with no photo, and the accessible name.
- accept
- Type string
- "image/png,image/jpeg,image/webp,image/gif,image/avif"
- Which files the picker offers.
- disabled
- Type boolean
- false
- Ignore presses and drops.
- className
- Type string
- –
- Classes for the wrapper.