Avatar
Unread Avatar
An avatar with an unread counter: the badge sits in a mask cut-out, anything above ninety-nine shows as "99+", and zero is not drawn at all.
- avatar
- badge
- unread
- counter
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/avatar-020?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 "avatar-020" (Unread Avatar) 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-020.json
Registry item: https://vibeui.ru/r/avatar-020.json
Installs to: components/vibeui/avatar-020.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 with an unread counter: the badge sits in a mask cut-out, anything above ninety-nine shows as "99+", and zero is not drawn at all.
An avatar with an unread counter: the badge lives in a mask cut-out, "99+" replaces an exact large number, and zero draws nothing. Zero dependencies, one file, no client JS.
## 3. How to use it
import { Avatar020 } from "@/components/vibeui/avatar-020"
<Avatar020
name="Ilya Mokhov"
count={12}
label="unread messages"
size="md"
/>
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-020-* palette — do not swap it for your theme tokens
- the mask cut-out instead of a background-coloured ring — the gap must hold on any surface
- the "99+" cap: an exact large number in a circle is unreadable and changes nothing
- the hidden zero: an empty circle reads as "there is something new"
- the hidden caption spelling out the number — otherwise the badge is mute
- tabular numerals in the badge: the number must not jump in width
## 6. You may change
- the name and the number through count
- the caption word through label
- the size through size
- the badge colour in the variable
## 7. Rules
- The "99+" cap lives in the markup: change it together with the badge width or the number overflows.
- Grammatical agreement in the caption is yours: "1 message" and "5 messages" differ.
- The badge is not clickable: jumping to the unread items belongs to the caller.
- 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-020.jsonhttps://vibeui.ru/r/avatar-020.jsonКомпонент самодостаточен: один файл, без зависимостей, собственная палитра в локальных переменных --vibeui-avatar-020-*. Серверный: хуков нет. Значок сидит в вырезе mask-image, поэтому зазор между числом и портретом остаётся ровным на любом фоне. Больше девяноста девяти показывается как «99+»: точное число в кружке нечитаемо и ни на что не влияет. Ноль не рисуется вовсе — пустой кружок читается как «есть что-то новое». Число продублировано словами в скрытой подписи, иначе для скринридера оно останется немым значком.
Component source
The same file your agent installs. Here in case you would rather copy it by hand.
import type { ComponentPropsWithoutRef, CSSProperties } from "react"
export type Avatar020Props = Omit<
ComponentPropsWithoutRef<"span">,
"children"
> & {
name?: string
count?: number
label?: string
size?: "sm" | "md" | "lg"
}
// Идея компонента: аватар со счётчиком непрочитанного. Число сидит в вырезе
// маски, как и точка присутствия, поэтому зазор ровный на любом фоне. Больше
// девяноста девяти показывается как «99+»: точное число в кружке нечитаемо и
// не влияет на решение — важно, что накопилось много. Ноль не рисуется вовсе:
// пустой кружок читается как «есть что-то новое». Число продублировано словами
// в подписи для скринридера, иначе оно останется немым значком.
const STYLES = `
:where([data-vibeui-block="avatar-020"]){
--vibeui-avatar-020-size:2.75rem;
--vibeui-avatar-020-badge:1.125rem;
--vibeui-avatar-020-color:oklch(0.56 0.19 25);
--vibeui-avatar-020-font:ui-sans-serif,system-ui,-apple-system,"Segoe UI",Roboto,"Helvetica Neue",Arial,sans-serif;
}
[data-vibeui-block="avatar-020"]{
position:relative;display:inline-flex;flex:none;
width:var(--vibeui-avatar-020-size);height:var(--vibeui-avatar-020-size);
font-family:var(--vibeui-avatar-020-font);
}
[data-vibeui-block="avatar-020"] [data-part="face"]{
display:grid;place-items:center;width:100%;height:100%;border-radius:9999px;
background:oklch(0.9 0.06 var(--vibeui-avatar-020-hue,265));
color:oklch(0.36 0.12 var(--vibeui-avatar-020-hue,265));
font-size:calc(var(--vibeui-avatar-020-size) * 0.36);font-weight:700;
}
/* Вырез маской под значок: зазор остаётся ровным на любом фоне. */
[data-vibeui-block="avatar-020"][data-badged="true"] [data-part="face"]{
mask-image:radial-gradient(circle calc(var(--vibeui-avatar-020-badge) * 0.72) at calc(100% - var(--vibeui-avatar-020-badge) * 0.3) calc(var(--vibeui-avatar-020-badge) * 0.3),transparent 99%,#000 100%);
}
[data-vibeui-block="avatar-020"] [data-part="count"]{
position:absolute;top:0;right:0;
display:inline-flex;align-items:center;justify-content:center;
min-width:var(--vibeui-avatar-020-badge);height:var(--vibeui-avatar-020-badge);
padding:0 0.25rem;box-sizing:border-box;border-radius:9999px;
background:var(--vibeui-avatar-020-color);color:oklch(1 0 0);
font-size:calc(var(--vibeui-avatar-020-badge) * 0.58);font-weight:700;line-height:1;
font-variant-numeric:tabular-nums;
}
[data-vibeui-block="avatar-020"][data-size="sm"]{--vibeui-avatar-020-size:2rem;--vibeui-avatar-020-badge:1rem}
[data-vibeui-block="avatar-020"][data-size="lg"]{--vibeui-avatar-020-size:3.5rem;--vibeui-avatar-020-badge:1.375rem}
[data-vibeui-block="avatar-020"] [data-part="sr"]{
position:absolute;width:1px;height:1px;overflow:hidden;clip-path:inset(50%);white-space:nowrap;
}
@media (prefers-reduced-motion:reduce){[data-vibeui-block="avatar-020"] *{animation:none!important;transition:none!important}}
`
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.charAt(0).toUpperCase())
.join("")
}
/**
* Аватар со счётчиком: значок в вырезе, «99+» вместо точного большого числа.
* Один файл, ноль зависимостей, собственная палитра.
*/
export function Avatar020({
name = "Илья Мохов",
count = 12,
label = "непрочитанных сообщения",
size = "md",
className,
style,
...props
}: Avatar020Props) {
// Ноль не рисуется: пустой кружок читается как «что-то новое».
const badged = count > 0
const palette = {
"--vibeui-avatar-020-hue": hue(name),
...style,
} as CSSProperties
return (
<>
<style href="vibeui-avatar-020" precedence="medium">
{STYLES}
</style>
<span
{...props}
data-vibeui-block="avatar-020"
data-badged={badged ? "true" : "false"}
data-size={size}
className={className}
style={palette}
>
<span data-part="face" aria-hidden="true">
{initials(name)}
</span>
{badged ? (
<span data-part="count" aria-hidden="true">
{count > 99 ? "99+" : count}
</span>
) : null}
<span data-part="sr">
{name}
{badged ? `, ${count} ${label}` : ""}
</span>
</span>
</>
)
}