Badge
Split Counter
A counter split in two: unread with a "9+" threshold on the left, the total on the right — the pair answers "twelve out of how many".
- badge
- counter
- unread
- threshold
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/badge-022?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 "badge-022" (Split Counter) 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/badge-022.json
Registry item: https://vibeui.ru/r/badge-022.json
Installs to: components/vibeui/badge-022.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 counter split in two: unread with a "9+" threshold on the left, the total on the right — the pair answers "twelve out of how many".
A split counter: unread with a threshold and the total inside one pill of constant width. Zero dependencies, one file, no client JS.
## 3. How to use it
import { Badge022 } from "@/components/vibeui/badge-022"
<Badge022 unread={12} total={48} max={9} />
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-badge-022-* palette — do not swap it for your theme tokens
- tabular figures and a minimum width on both halves: otherwise the badge jumps on every refresh
- the threshold on the left number only — "9+ of 9+" says nothing
- the dimmed but not removed left half at zero: dropping the zone changes the badge width
- the aria-label on the whole badge: two bare numbers read as "12 48" in a screen reader
- the badge's own light surface: without it the dark text disappears on a dark background
## 6. You may change
- the unread count through unread
- the total through total
- the threshold through max
- the accent colour in the accent variable
## 7. Rules
- total cannot be smaller than unread: the component raises it instead of showing a contradiction.
- The default threshold is 9, not 99: two zones take space and a three-digit number blows the pill apart.
- The aria-label wording is hard-coded in Russian — translate it when localising, or the screen reader mixes languages.
- 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/badge-022.jsonhttps://vibeui.ru/r/badge-022.jsonОдин файл, ноль зависимостей, палитра в локальных переменных --vibeui-badge-022-*. Серверный: хуков нет. Пилюля разделена на две зоны с общим overflow:hidden, граница между ними — левая рамка правой половины, поэтому разделитель не требует отдельного узла. Обе половины набраны табличными цифрами и имеют одинаковый минимум ширины: при пересчёте плашка не меняет габарит и не дёргает соседей. Порог применяется только к левому числу — «9+ из 48» осмысленно, а «9+ из 9+» нет. Когда новых ноль, левая половина гаснет, но остаётся: исчезающая зона меняла бы ширину. Числа помечены aria-hidden, вся плашка объявляется одной фразой через aria-label.
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 Badge022Props = Omit<
ComponentPropsWithoutRef<"span">,
"children"
> & {
unread?: number
total?: number
max?: number
}
// Идея компонента: счётчик из двух половин. Слева непрочитанные с порогом
// «9+», справа общее число без порога, между ними перегородка. Одно число
// заставляет гадать — «двенадцать чего?»: пара «новые из всех» отвечает сразу
// и занимает столько же места. Когда новых нет, левая половина гаснет, но не
// исчезает — иначе плашка меняет ширину и дёргает соседей.
const STYLES = `
:where([data-vibeui-block="badge-022"]){
--vibeui-badge-022-bg:oklch(0.97 0.004 265);
--vibeui-badge-022-border:oklch(0.89 0.006 265);
--vibeui-badge-022-accent:oklch(0.53 0.19 25);
--vibeui-badge-022-muted:oklch(0.54 0.014 265);
--vibeui-badge-022-font:ui-sans-serif,system-ui,-apple-system,"Segoe UI",Roboto,"Helvetica Neue",Arial,sans-serif;
}
[data-vibeui-block="badge-022"]{
display:inline-flex;align-items:stretch;box-sizing:border-box;
height:1.5rem;
border:1px solid var(--vibeui-badge-022-border);border-radius:9999px;
background:var(--vibeui-badge-022-bg);
font-family:var(--vibeui-badge-022-font);font-size:0.75rem;line-height:1;
/* Табличные цифры: половины не должны переставать совпадать по ширине. */
font-variant-numeric:tabular-nums;vertical-align:middle;overflow:hidden;
}
[data-vibeui-block="badge-022"] [data-part="unread"],
[data-vibeui-block="badge-022"] [data-part="total"]{
display:inline-flex;align-items:center;justify-content:center;
min-width:1.375rem;padding:0 0.5rem;
}
[data-vibeui-block="badge-022"] [data-part="unread"]{
color:var(--vibeui-badge-022-accent);font-weight:700;
background:color-mix(in oklab,var(--vibeui-badge-022-accent) 10%,oklch(1 0 0));
}
[data-vibeui-block="badge-022"] [data-part="total"]{
color:var(--vibeui-badge-022-muted);font-weight:500;
border-left:1px solid var(--vibeui-badge-022-border);
}
/* Ноль новых: половина остаётся на месте, но перестаёт звать. */
[data-vibeui-block="badge-022"][data-empty="true"] [data-part="unread"]{
color:var(--vibeui-badge-022-muted);font-weight:500;background:transparent;
}
@media (prefers-reduced-motion:reduce){[data-vibeui-block="badge-022"] *{animation:none!important;transition:none!important}}
`
/**
* Счётчик из двух половин: новые с порогом «9+» и общее число.
* Один файл, ноль зависимостей, собственная палитра.
*/
export function Badge022({
unread = 12,
total = 48,
max = 9,
className,
style,
...props
}: Badge022Props) {
const fresh = Math.max(0, Math.round(unread))
const all = Math.max(fresh, Math.round(total))
const shown = fresh > max ? `${max}+` : String(fresh)
return (
<>
<style href="vibeui-badge-022" precedence="medium">
{STYLES}
</style>
<span
{...props}
data-vibeui-block="badge-022"
data-empty={fresh === 0}
className={className}
style={style as CSSProperties}
aria-label={`${fresh} новых из ${all}`}
>
<span data-part="unread" aria-hidden="true">
{shown}
</span>
<span data-part="total" aria-hidden="true">
{all}
</span>
</span>
</>
)
}