Inputs
Image Preview
A single-image upload whose preview appears right where you pick it: a name like IMG_2047.jpg does not tell the right shot from the next one.
- file
- image
- preview
- upload
Preview
Use it with AI
- 1. Copy the link.
- 2. Write to your agent in your own words and drop the link into the sentence.
- 3. The agent opens the link and installs the component from the registry.
put this in the header: https://vibeui.ru/c/file-004?lang=en
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-004" (Image Preview) 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-004.json
Registry item: https://vibeui.ru/r/file-004.json
Installs to: components/vibeui/file-004.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
A single-image upload whose preview appears right where you pick it: a name like IMG_2047.jpg does not tell the right shot from the next one.
A single-image picker with the preview living in the tile: empty it invites a choice, filled it shows the shot plus the name and a Remove button. Nothing reaches the server before the form is submitted. Zero dependencies, one file, its own palette.
## 3. How to use it
import { File004 } from "@/components/vibeui/file-004"
<File004 label="Article cover" onChange={setCover} />
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-004-* palette — do not swap it for your theme tokens (bg-muted, border-input and the like)
- the preview built from the file itself with createObjectURL: a file name does not tell the right shot from the next one
- releasing the previous URL with revokeObjectURL — without it the tab piles up images in memory
- the <label> tile with a hidden input: picking works from the keyboard and on a phone, not only with a mouse
- object-fit:cover on the preview and a fixed tile ratio: otherwise the layout jumps with every new file
- the alt naming the file — a bare "image" aloud does not help pick the right one
- the <style> block inside the component — it holds the palette, the tile and its two states
## 6. You may change
- the label copy and the hint under the pick caption
- accept — which formats the dialog offers
- the onChange handler: it receives the file name, or null after clearing
- the accent through the accent prop
- the tile ratio to match your image format
## 7. Rules
- The preview shows the original file in full: cropping and compression belong to the server or to a separate component.
- A heavy file is drawn as-is — noticeable on a slow device, so cap the size.
- createObjectURL does not exist on the server: the component has to stay a client one.
- 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-004.jsonhttps://vibeui.ru/r/file-004.jsonКомпонент самодостаточен: один файл, без зависимостей, собственная палитра в локальных переменных --vibeui-file-004-*. Клиентский: "use client". Превью строится из выбранного файла через URL.createObjectURL, поэтому на сервер до отправки формы ничего не летит; прошлая ссылка освобождается в useEffect через URL.revokeObjectURL, иначе вкладка копит изображения в памяти. Плитка — это <label> со скрытым input type="file": и место выбора, и место показа совпадают.
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 File004Props = Omit<
ComponentPropsWithoutRef<"div">,
"children" | "onChange"
> & {
label?: string
hint?: string
accept?: string
onChange?: (name: string | null) => void
accent?: string
}
// Идея компонента: одна картинка и её превью на месте выбора. Имя файла
// ничего не говорит о содержимом — «IMG_2047.jpg» одинаково похоже и на
// нужный кадр, и на соседний. Превью строится из самого файла через
// createObjectURL, поэтому ничего не грузится на сервер до отправки формы, а
// прошлая ссылка обязательно освобождается: иначе вкладка копит изображения.
const STYLES = `
:where([data-vibeui-block="file-004"]){
--vibeui-file-004-surface:oklch(1 0 0);
--vibeui-file-004-tile:oklch(0.975 0.004 265);
--vibeui-file-004-fg:oklch(0.23 0.014 265);
--vibeui-file-004-muted:oklch(0.55 0.014 265);
--vibeui-file-004-border:oklch(0.88 0.008 265);
--vibeui-file-004-shell:oklch(0.91 0.006 265);
--vibeui-file-004-accent:oklch(0.55 0.16 200);
--vibeui-file-004-font:ui-sans-serif,system-ui,-apple-system,"Segoe UI",Roboto,"Helvetica Neue",Arial,sans-serif;
}
/* Своя светлая подложка: поле показывают поверх любого фона. */
[data-vibeui-block="file-004"]{
display:flex;flex-direction:column;gap:0.5rem;
width:100%;max-width:20rem;box-sizing:border-box;padding:0.875rem;
background:var(--vibeui-file-004-surface);
border:1px solid var(--vibeui-file-004-shell);border-radius:0.875rem;
font-family:var(--vibeui-file-004-font);color:var(--vibeui-file-004-fg);
}
[data-vibeui-block="file-004"] *{box-sizing:border-box}
[data-vibeui-block="file-004"] [data-part="caption"]{font-size:0.8125rem;font-weight:650}
/* Плитка превью: и место выбора, и место показа — одно и то же. */
[data-vibeui-block="file-004"] label{
position:relative;display:flex;flex-direction:column;
align-items:center;justify-content:center;gap:0.3125rem;
aspect-ratio:16 / 10;padding:0.75rem;overflow:hidden;cursor:pointer;
background:var(--vibeui-file-004-tile);
border:1.5px dashed var(--vibeui-file-004-border);border-radius:0.75rem;
text-align:center;
transition:border-color .16s ease,background-color .16s ease;
}
[data-vibeui-block="file-004"] label:hover{border-color:var(--vibeui-file-004-accent)}
[data-vibeui-block="file-004"] label:has(input:focus-visible){
outline:2px solid var(--vibeui-file-004-accent);outline-offset:2px;
}
[data-vibeui-block="file-004"][data-filled="true"] label{border-style:solid;padding:0}
[data-vibeui-block="file-004"] input{
position:absolute;width:1px;height:1px;padding:0;margin:-1px;
overflow:hidden;clip-path:inset(50%);border:0;
}
[data-vibeui-block="file-004"] img{
width:100%;height:100%;object-fit:cover;display:block;
}
[data-vibeui-block="file-004"] [data-part="frame"]{
position:relative;width:1.75rem;height:1.5rem;
border:1.5px solid var(--vibeui-file-004-muted);border-radius:0.25rem;
overflow:hidden;
}
[data-vibeui-block="file-004"] [data-part="frame"]::before{
content:"";position:absolute;left:0.25rem;bottom:0.1875rem;
width:0.5rem;height:0.5rem;transform:rotate(45deg);
background:var(--vibeui-file-004-muted);
}
[data-vibeui-block="file-004"] [data-part="frame"]::after{
content:"";position:absolute;right:0.25rem;top:0.25rem;
width:0.3125rem;height:0.3125rem;border-radius:9999px;
background:var(--vibeui-file-004-muted);
}
[data-vibeui-block="file-004"] [data-part="pick"]{font-size:0.8125rem;font-weight:600}
[data-vibeui-block="file-004"] [data-part="hint"]{
margin:0;font-size:0.6875rem;line-height:1.4;color:var(--vibeui-file-004-muted);
}
[data-vibeui-block="file-004"] [data-part="foot"]{
display:flex;align-items:center;justify-content:space-between;gap:0.5rem;
font-size:0.75rem;color:var(--vibeui-file-004-muted);
}
[data-vibeui-block="file-004"] [data-part="file"]{
min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;
}
[data-vibeui-block="file-004"] button{
appearance:none;flex:none;cursor:pointer;
padding:0.25rem 0.5rem;border-radius:0.375rem;
border:1px solid var(--vibeui-file-004-border);background:none;color:inherit;
font:inherit;font-size:0.6875rem;font-weight:650;
}
[data-vibeui-block="file-004"] button:hover{border-color:var(--vibeui-file-004-accent);color:var(--vibeui-file-004-accent)}
[data-vibeui-block="file-004"] button:focus-visible{outline:2px solid var(--vibeui-file-004-accent);outline-offset:2px}
@media (prefers-reduced-motion:reduce){[data-vibeui-block="file-004"] *{animation:none!important;transition:none!important}}
`
/**
* Загрузка одной картинки: превью строится из файла, до отправки ничего не летит.
* Один файл, ноль зависимостей, собственная палитра.
*/
export function File004({
label = "Обложка статьи",
hint = "JPG или PNG, лучше 1200 × 750",
accept = "image/png,image/jpeg,image/webp",
onChange,
accent,
className,
style,
...props
}: File004Props) {
const id = useId()
const [preview, setPreview] = useState<string | null>(null)
const [name, setName] = useState<string | null>(null)
// Ссылку обязательно освобождаем: иначе вкладка копит изображения в памяти.
useEffect(() => {
if (!preview) return
return () => URL.revokeObjectURL(preview)
}, [preview])
const palette = {
...(accent ? { "--vibeui-file-004-accent": accent } : null),
...style,
} as CSSProperties
const take = (file: File | undefined) => {
if (!file) return
setPreview(URL.createObjectURL(file))
setName(file.name)
onChange?.(file.name)
}
const clear = () => {
setPreview(null)
setName(null)
onChange?.(null)
}
return (
<>
<style href="vibeui-file-004" precedence="medium">
{STYLES}
</style>
<div
{...props}
data-vibeui-block="file-004"
data-filled={preview ? "true" : undefined}
className={className}
style={palette}
>
<span data-part="caption">{label}</span>
<label htmlFor={id}>
{preview ? (
<img src={preview} alt={`Превью файла ${name ?? ""}`} />
) : (
<>
<span data-part="frame" aria-hidden="true" />
<span data-part="pick">Выбрать изображение</span>
<span data-part="hint">{hint}</span>
</>
)}
<input
id={id}
type="file"
accept={accept}
onChange={(event) => take(event.target.files?.[0])}
/>
</label>
<div data-part="foot">
<span data-part="file">{name ?? "Файл не выбран"}</span>
{name ? (
<button type="button" onClick={clear}>
Убрать
</button>
) : null}
</div>
</div>
</>
)
}