Avatar

Photo Uploader

Changing the profile photo with a label and a hidden file input: clickable, keyboard-reachable, no JavaScript.

  • avatar
  • upload
  • file
  • no-js

Preview

1440pxHost theme

Use it with AI

  1. 1. Copy the link.
  2. 2. Write to your agent in your own words and drop the link into the sentence.
  3. 3. The agent opens the link and installs the component from the registry.

put this in the header: https://vibeui.ru/c/avatar-006?lang=en

Anna PetrovaJPG or PNG, square, up to 2 MB
Show the full instructions

What the link says, spelled out. Use it when your agent cannot open links — paste this text instead.

# Install and place "avatar-006" (Photo Uploader) from VibeUI

## 1. Install first — do not skip, do not recreate
Run this exact command before writing any code:
npx shadcn@latest add https://vibeui.ru/r/avatar-006.json

Registry item: https://vibeui.ru/r/avatar-006.json
Installs to: components/vibeui/avatar-006.tsx (the exact path follows this project's components.json aliases).
npm dependencies: none.
Registry dependencies: none.

Install it from the registry. Do not recreate it from the description,
do not substitute a similar component from another library, and do not
rewrite it to match the project's existing style.

## 2. What it is
Changing the profile photo with a label and a hidden file input: clickable, keyboard-reachable, no JavaScript.

Profile photo replacement: a circle with a "Change photo" veil, a hidden file input and a line of requirements. Works with no client code. Zero dependencies, one file, its own palette.

## 3. How to use it
import { Avatar006 } from "@/components/vibeui/avatar-006"

<Avatar006 name="Anna Petrova" hint="JPG or PNG, up to 2 MB" />

Read the installed file for the full prop list.

## 4. Where to place it
This is a small inline component. Put it exactly where the user asked,
inside the existing markup. Do not create a new page, section or
wrapper for it. If a similar control already sits in that spot,
replace it instead of adding a second one.

Placement: ___
(The user fills this line in. If it is still blank, ask where to put it
instead of guessing.)

## 5. Keep exactly as installed
- the local --vibeui-avatar-006-* palette — do not swap it for your theme tokens
- the label instead of a button with onClick: it is already keyboard-reachable and announced as a file picker
- hiding the input with size and opacity rather than display:none — that would remove it from focus order
- revealing the veil on hover and on focus: a keyboard user otherwise cannot tell where they are
- the visible ring via :has(input:focus-visible) — focus must show on the circle
- the file requirements next to the control, not in a dialog after the failure

## 6. You may change
- name, src, label and hint — the requirements copy
- accept — the formats you take
- the circle size through the variable
- the veil colour for your theme

## 7. Rules
- The component only picks a file: preview, cropping and upload belong to the caller.
- The size limit in the copy validates nothing: check the file on the server, not in a sentence.
- accept is a hint to the dialog, not a guard: "All files" still lets anything through.
- Do not lift the CSS variables into globals.css: the component has to stay a single file.

## 8. Verify
- it renders with no console errors;
- it looks like the preview on the VibeUI page you copied this from;
- if it does not, you changed something listed in section 5 — put it back.

For developers

npx shadcn@latest add https://vibeui.ru/r/avatar-006.json
https://vibeui.ru/r/avatar-006.json

Компонент самодостаточен: один файл, без зависимостей, собственная палитра в локальных переменных --vibeui-avatar-006-*. Роль кнопки играет <label>, связанный с input type="file" через useId. Поле спрятано размером и прозрачностью, но остаётся в потоке — display:none забрал бы у него фокус. Плёнка с подписью проявляется и на наведении, и при фокусе поля через соседний селектор, обводка ставится на обёртку через :has().

Component source

The same file your agent installs. Here in case you would rather copy it by hand.

import { useId } from "react"
import type { ComponentPropsWithoutRef, CSSProperties } from "react"

export type Avatar006Props = Omit<
  ComponentPropsWithoutRef<"div">,
  "children"
> & {
  name?: string
  src?: string
  label?: string
  hint?: string
  accept?: string
}

// Идея компонента: смена фотографии без единой строки JS. Поле выбора файла
// спрятано, а его роль играет <label>: он уже кликабелен, доступен с
// клавиатуры и объявлен скринридеру как кнопка выбора файла. Подпись
// появляется при наведении и при фокусе — фокус без подсветки бесполезен.
const STYLES = `
:where([data-vibeui-block="avatar-006"]){
--vibeui-avatar-006-size:5rem;
--vibeui-avatar-006-bg:oklch(1 0 0);
--vibeui-avatar-006-fg:oklch(0.22 0.014 265);
--vibeui-avatar-006-muted:oklch(0.52 0.014 265);
--vibeui-avatar-006-border:oklch(0.9 0.006 265);
--vibeui-avatar-006-hue:250;
--vibeui-avatar-006-shape:oklch(0.92 0.05 var(--vibeui-avatar-006-hue));
--vibeui-avatar-006-initials:oklch(0.38 0.09 var(--vibeui-avatar-006-hue));
--vibeui-avatar-006-veil:oklch(0.2 0.02 265 / 62%);
--vibeui-avatar-006-accent:oklch(0.55 0.17 265);
--vibeui-avatar-006-font:ui-sans-serif,system-ui,-apple-system,"Segoe UI",Roboto,"Helvetica Neue",Arial,sans-serif;
}
[data-vibeui-block="avatar-006"]{
display:flex;align-items:center;gap:0.875rem;
box-sizing:border-box;padding:0.875rem;
background:var(--vibeui-avatar-006-bg);
border:1px solid var(--vibeui-avatar-006-border);border-radius:0.875rem;
color:var(--vibeui-avatar-006-fg);font-family:var(--vibeui-avatar-006-font);
}
[data-vibeui-block="avatar-006"] [data-part="picker"]{
position:relative;display:flex;align-items:center;justify-content:center;flex:none;
width:var(--vibeui-avatar-006-size);height:var(--vibeui-avatar-006-size);
overflow:hidden;border-radius:9999px;cursor:pointer;
background:var(--vibeui-avatar-006-shape);color:var(--vibeui-avatar-006-initials);
font-size:calc(var(--vibeui-avatar-006-size) * 0.32);font-weight:650;line-height:1;user-select:none;
}
[data-vibeui-block="avatar-006"] img{position:absolute;inset:0;width:100%;height:100%;object-fit:cover}
/* Плёнка проявляется и на наведении, и на фокусе: с клавиатуры иначе
   непонятно, где находишься. */
[data-vibeui-block="avatar-006"] [data-part="veil"]{
position:absolute;inset:0;display:flex;align-items:center;justify-content:center;
background:var(--vibeui-avatar-006-veil);color:oklch(0.99 0.003 265);
font-size:0.6875rem;font-weight:600;text-align:center;line-height:1.2;
opacity:0;transition:opacity .16s ease;
}
[data-vibeui-block="avatar-006"] [data-part="picker"]:hover [data-part="veil"],
[data-vibeui-block="avatar-006"] input:focus-visible + [data-part="veil"]{opacity:1}
[data-vibeui-block="avatar-006"] [data-part="picker"]:has(input:focus-visible){outline:2px solid var(--vibeui-avatar-006-accent);outline-offset:2px}
/* Поле спрятано, но не выключено: удалять его из потока нельзя — с ним
   исчезнет и фокус. */
[data-vibeui-block="avatar-006"] input{
position:absolute;width:1px;height:1px;opacity:0;
}
[data-vibeui-block="avatar-006"] [data-part="text"]{display:flex;flex-direction:column;gap:0.1875rem;min-width:0}
[data-vibeui-block="avatar-006"] [data-part="name"]{font-size:0.9375rem;font-weight:600;line-height:1.2}
[data-vibeui-block="avatar-006"] [data-part="hint"]{font-size:0.75rem;line-height:1.4;color:var(--vibeui-avatar-006-muted)}
@media (prefers-reduced-motion:reduce){[data-vibeui-block="avatar-006"] *{animation:none!important;transition:none!important}}
`

// Оттенок из имени: FNV-1a, разложенный по двенадцати ступеням круга.
// Сумма кодов символов не годится — кириллические имена ложатся в один
// розовый сектор; ступени в 30° дают заведомо различимые цвета.
function hue(name: string) {
  let hash = 2166136261

  for (const symbol of name) {
    hash ^= symbol.codePointAt(0)!
    hash = Math.imul(hash, 16777619)
  }

  return ((hash >>> 0) % 12) * 30
}

function initials(name: string) {
  return name
    .split(" ")
    .slice(0, 2)
    .map((part) => part[0]?.toUpperCase() ?? "")
    .join("")
}

/**
 * Смена фотографии профиля на label и скрытом input — без JS.
 * Один файл, ноль зависимостей, собственная палитра.
 */
export function Avatar006({
  name = "Анна Петрова",
  src = "",
  label = "Сменить фото",
  hint = "JPG или PNG, квадрат, до 2 МБ",
  accept = "image/png,image/jpeg",
  className,
  style,
  ...props
}: Avatar006Props) {
  const id = useId()
  const palette = {
    "--vibeui-avatar-006-hue": hue(name),
    ...style,
  } as CSSProperties

  return (
    <>
      <style href="vibeui-avatar-006" precedence="medium">
        {STYLES}
      </style>
      <div
        {...props}
        data-vibeui-block="avatar-006"
        className={className}
        style={palette}
      >
        <label data-part="picker" htmlFor={id}>
          {src ? (
            <img src={src} alt="" loading="lazy" decoding="async" />
          ) : null}
          {src ? null : initials(name)}
          <input id={id} type="file" accept={accept} />
          <span data-part="veil">{label}</span>
        </label>
        <span data-part="text">
          <span data-part="name">{name}</span>
          <span data-part="hint">{hint}</span>
        </span>
      </div>
    </>
  )
}