Inputs

Avatar Crop

An avatar upload with a circular crop: the frame shows exactly what others will see, and the zoom slider rescues a shot with the face near the edge.

  • file
  • avatar
  • crop
  • image

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/file-005?lang=en

Profile photo

Квадрат обрежется по кругу — так фото увидят в комментариях.

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 "file-005" (Avatar Crop) 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/file-005.json

Registry item: https://vibeui.ru/r/file-005.json
Installs to: components/vibeui/file-005.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
An avatar upload with a circular crop: the frame shows exactly what others will see, and the zoom slider rescues a shot with the face near the edge.

The avatar is picked and cropped in one place: a circular frame shows the final shot, the slider changes the scale through transform, and initials fill the frame before a file is chosen. Zero dependencies, one file, its own palette.

## 3. How to use it
import { File005 } from "@/components/vibeui/file-005"

<File005 label="Profile photo" initials="AK" zoom={1.2} />

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-file-005-* palette — do not swap it for your theme tokens (bg-muted, border-input and the like)
- the circular frame with overflow:hidden: it shows exactly what others will see, not a square from roughly there
- the scale through transform:scale and the --vibeui-file-005-zoom variable — the image is not re-laid-out
- the native input[type=range] for the scale: arrow keys and value announcement come for free
- the disabled slider while there is no file — there is nothing to move, and it shows
- initials instead of an empty circle before the pick: an empty frame reads as a broken image
- releasing the previous URL with revokeObjectURL

## 6. You may change
- the label copy and the initials shown before a file is picked
- zoom — the starting scale of the preview
- the onChange handler: it receives the chosen file name
- the accent through the accent prop — it colours the slider and the focus ring
- the frame diameter and the explanation beside it

## 7. Rules
- The component shows the crop but does not cut the file: the real crop happens on the server from the scale value.
- Send the scale to the server along with the file, otherwise the shot reverts to the original framing.
- Panning with the mouse is deliberately absent: it needs dragging, while zoom covers most cases.
- 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/file-005.json
https://vibeui.ru/r/file-005.json

Компонент самодостаточен: один файл, без зависимостей, собственная палитра в локальных переменных --vibeui-file-005-*. Клиентский: "use client". Круглая рамка — <label> со скрытым input type="file" и overflow:hidden, поэтому обрезка видна сразу. Масштаб живёт в переменной --vibeui-file-005-zoom и применяется через transform:scale, а не через размеры — картинка не перерисовывается. Ползунок — нативный input[type=range], поэтому стрелки с клавиатуры и объявление значения достаются даром. Прошлая ссылка освобождается через revokeObjectURL.

Component source

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

"use client"

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

export type File005Props = Omit<
  ComponentPropsWithoutRef<"div">,
  "children" | "onChange"
> & {
  label?: string
  initials?: string
  zoom?: number
  onChange?: (name: string | null) => void
  accent?: string
}

// Идея компонента: аватар обрезается там же, где выбирается. Круглая рамка
// показывает ровно то, что увидят другие, а ползунок масштаба закрывает
// главный случай — лицо у края кадра. Масштаб живёт в transform, поэтому
// картинка не перерисовывается, а сам ползунок — нативный input[type=range]:
// его двигают стрелками с клавиатуры, и подпись значения объявляется вслух.
const STYLES = `
:where([data-vibeui-block="file-005"]){
--vibeui-file-005-surface:oklch(1 0 0);
--vibeui-file-005-tile:oklch(0.96 0.006 265);
--vibeui-file-005-fg:oklch(0.23 0.014 265);
--vibeui-file-005-muted:oklch(0.55 0.014 265);
--vibeui-file-005-border:oklch(0.88 0.008 265);
--vibeui-file-005-shell:oklch(0.91 0.006 265);
--vibeui-file-005-accent:oklch(0.55 0.19 20);
--vibeui-file-005-zoom:1;
--vibeui-file-005-font:ui-sans-serif,system-ui,-apple-system,"Segoe UI",Roboto,"Helvetica Neue",Arial,sans-serif;
}
/* Своя светлая подложка: карточку показывают поверх любого фона. */
[data-vibeui-block="file-005"]{
display:flex;align-items:center;gap:0.875rem;
width:100%;max-width:21rem;box-sizing:border-box;padding:0.875rem;
background:var(--vibeui-file-005-surface);
border:1px solid var(--vibeui-file-005-shell);border-radius:0.875rem;
font-family:var(--vibeui-file-005-font);color:var(--vibeui-file-005-fg);
}
[data-vibeui-block="file-005"] *{box-sizing:border-box}
/* Круглая рамка показывает ровно то, что увидят другие. */
[data-vibeui-block="file-005"] label{
position:relative;flex:none;display:grid;place-items:center;
width:5rem;height:5rem;overflow:hidden;cursor:pointer;
border-radius:9999px;background:var(--vibeui-file-005-tile);
box-shadow:0 0 0 1px var(--vibeui-file-005-border),0 0 0 4px var(--vibeui-file-005-surface),0 0 0 5px var(--vibeui-file-005-border);
}
[data-vibeui-block="file-005"] label:has(input:focus-visible){
outline:2px solid var(--vibeui-file-005-accent);outline-offset:5px;
}
[data-vibeui-block="file-005"] input[type="file"]{
position:absolute;width:1px;height:1px;padding:0;margin:-1px;
overflow:hidden;clip-path:inset(50%);border:0;
}
/* Масштаб через transform: картинка не перерисовывается на каждый шаг. */
[data-vibeui-block="file-005"] img{
width:100%;height:100%;object-fit:cover;display:block;
transform:scale(var(--vibeui-file-005-zoom));transform-origin:center;
transition:transform .12s linear;
}
[data-vibeui-block="file-005"] [data-part="initials"]{
font-size:1.375rem;font-weight:700;color:var(--vibeui-file-005-muted);
letter-spacing:0.02em;
}
[data-vibeui-block="file-005"] [data-part="veil"]{
position:absolute;inset:auto 0 0;padding:0.1875rem 0;
background:color-mix(in oklab,oklch(0 0 0) 55%,transparent);
color:oklch(1 0 0);font-size:0.5625rem;font-weight:650;text-align:center;
text-transform:uppercase;letter-spacing:0.04em;
}
[data-vibeui-block="file-005"] [data-part="side"]{
display:flex;flex-direction:column;gap:0.375rem;min-width:0;flex:1;
}
[data-vibeui-block="file-005"] [data-part="title"]{font-size:0.8125rem;font-weight:650}
[data-vibeui-block="file-005"] [data-part="note"]{
margin:0;font-size:0.6875rem;line-height:1.4;color:var(--vibeui-file-005-muted);
}
[data-vibeui-block="file-005"] [data-part="zoom"]{
display:flex;flex-direction:column;gap:0.125rem;
font-size:0.6875rem;color:var(--vibeui-file-005-muted);
}
/* Нативный range: стрелки с клавиатуры и объявление значения даром. */
[data-vibeui-block="file-005"] input[type="range"]{
appearance:none;width:100%;height:1rem;background:none;cursor:pointer;margin:0;
}
[data-vibeui-block="file-005"] input[type="range"]::-webkit-slider-runnable-track{
height:0.25rem;border-radius:9999px;background:var(--vibeui-file-005-tile);
}
[data-vibeui-block="file-005"] input[type="range"]::-moz-range-track{
height:0.25rem;border-radius:9999px;background:var(--vibeui-file-005-tile);
}
[data-vibeui-block="file-005"] input[type="range"]::-webkit-slider-thumb{
appearance:none;width:0.875rem;height:0.875rem;margin-top:-0.3125rem;
border-radius:9999px;background:var(--vibeui-file-005-accent);
border:2px solid var(--vibeui-file-005-surface);
}
[data-vibeui-block="file-005"] input[type="range"]::-moz-range-thumb{
width:0.875rem;height:0.875rem;border-radius:9999px;
background:var(--vibeui-file-005-accent);
border:2px solid var(--vibeui-file-005-surface);
}
[data-vibeui-block="file-005"] input[type="range"]:focus-visible{outline:2px solid var(--vibeui-file-005-accent);outline-offset:2px;border-radius:9999px}
[data-vibeui-block="file-005"] input[type="range"]:disabled{cursor:not-allowed;opacity:.45}
@media (prefers-reduced-motion:reduce){[data-vibeui-block="file-005"] *{animation:none!important;transition:none!important}}
`

/**
 * Загрузка аватара с круглой обрезкой и ползунком масштаба.
 * Один файл, ноль зависимостей, собственная палитра.
 */
export function File005({
  label = "Фото профиля",
  initials = "АК",
  zoom = 1.1,
  onChange,
  accent,
  className,
  style,
  ...props
}: File005Props) {
  const id = useId()
  const [preview, setPreview] = useState<string | null>(null)
  const [scale, setScale] = useState(zoom)

  // Ссылку обязательно освобождаем: иначе вкладка копит изображения в памяти.
  useEffect(() => {
    if (!preview) return
    return () => URL.revokeObjectURL(preview)
  }, [preview])

  const palette = {
    "--vibeui-file-005-zoom": String(scale),
    ...(accent ? { "--vibeui-file-005-accent": accent } : null),
    ...style,
  } as CSSProperties

  return (
    <>
      <style href="vibeui-file-005" precedence="medium">
        {STYLES}
      </style>
      <div
        {...props}
        data-vibeui-block="file-005"
        className={className}
        style={palette}
      >
        <label htmlFor={id}>
          {preview ? (
            <img src={preview} alt="Выбранное фото профиля" />
          ) : (
            <span data-part="initials" aria-hidden="true">
              {initials}
            </span>
          )}
          <span data-part="veil">сменить</span>
          <input
            id={id}
            type="file"
            accept="image/*"
            onChange={(event) => {
              const file = event.target.files?.[0]
              if (!file) return
              setPreview(URL.createObjectURL(file))
              onChange?.(file.name)
            }}
          />
        </label>

        <div data-part="side">
          <span data-part="title">{label}</span>
          <p data-part="note">
            Квадрат обрежется по кругу — так фото увидят в комментариях.
          </p>
          <span data-part="zoom">
            <label htmlFor={`${id}-zoom`}>
              Масштаб · {Math.round(scale * 100)}%
            </label>
            <input
              id={`${id}-zoom`}
              type="range"
              min={1}
              max={2}
              step={0.05}
              value={scale}
              disabled={!preview}
              onChange={(event) => setScale(Number(event.target.value))}
            />
          </span>
        </div>
      </div>
    </>
  )
}