Badge
Expiry Badge
An expiry badge whose wording changes along with the tone: "21 days left", "expires in 3 days", "expires today", "overdue".
- badge
- expiry
- deadline
- 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-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 "badge-020" (Expiry Badge) 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-020.json
Registry item: https://vibeui.ru/r/badge-020.json
Installs to: components/vibeui/badge-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 expiry badge whose wording changes along with the tone: "21 days left", "expires in 3 days", "expires today", "overdue".
An expiry badge: thresholds switch both the tone and the wording itself, and the day count is declined in Russian. Zero dependencies, one file, no client JS.
## 3. How to use it
import { Badge020 } from "@/components/vibeui/badge-020"
<Badge020 days={3} warnAt={7} />
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-020-* palette — do not swap it for your theme tokens
- the change of wording, not just of tone: colour is the first thing lost in print and colour blindness
- the plural function with the 11–14 exception: "11 дня" reads as a typo and undermines trust in the number
- the separate "today" state: "expires in 0 days" is meaningless
- tabular figures — otherwise the badge jitters as the term is recomputed
- the badge's own light surface: without it the dark text disappears on a dark background
## 6. You may change
- the number of days through days
- the warning threshold through warnAt
- the wording in the component body
- the state hues in the data-state rules
## 7. Rules
- The component takes a ready day count, not a date: the caller computes the difference, otherwise server and client disagree on time zones.
- A negative value means overdue: the sign is not lost, its absolute value feeds the phrase.
- There is one threshold: if you need "a month", "a week", "a day", add states instead of stretching warnAt.
- 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-020.jsonhttps://vibeui.ru/r/badge-020.jsonОдин файл, ноль зависимостей, палитра в локальных переменных --vibeui-badge-020-*. Серверный: хуков нет. Состояние выводится из числа дней и порога warnAt и попадает в data-state, который меняет только --hue и --chroma — четыре тона держатся на двух переменных. Главное здесь не цвет: для каждого состояния своя фраза, поэтому срок понятен в чёрно-белом списке и вслух в скринридере. Число склоняется функцией plural по русским правилам, включая исключение для 11–14. Часы — inline SVG под aria-hidden.
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 Badge020Props = Omit<
ComponentPropsWithoutRef<"span">,
"children"
> & {
days?: number
warnAt?: number
}
// Идея компонента: срок, у которого меняется не только тон, но и формулировка.
// «Ещё 21 день», «истекает через 3 дня», «истекает сегодня» и «просрочено на
// 2 дня» — четыре разные фразы, поэтому состояние понятно и в чёрно-белом
// списке, и вслух в скринридере. Число склоняется по русским правилам:
// «1 день», «3 дня», «11 дней».
const STYLES = `
:where([data-vibeui-block="badge-020"]){
--vibeui-badge-020-hue:265;
--vibeui-badge-020-chroma:0.02;
--vibeui-badge-020-bg:oklch(0.97 calc(var(--vibeui-badge-020-chroma) * 0.4) var(--vibeui-badge-020-hue));
--vibeui-badge-020-fg:oklch(0.36 var(--vibeui-badge-020-chroma) var(--vibeui-badge-020-hue));
--vibeui-badge-020-border:oklch(0.89 calc(var(--vibeui-badge-020-chroma) * 0.6) var(--vibeui-badge-020-hue));
--vibeui-badge-020-mark:oklch(0.55 calc(var(--vibeui-badge-020-chroma) * 1.4) var(--vibeui-badge-020-hue));
--vibeui-badge-020-font:ui-sans-serif,system-ui,-apple-system,"Segoe UI",Roboto,"Helvetica Neue",Arial,sans-serif;
}
[data-vibeui-block="badge-020"]{
display:inline-flex;align-items:center;gap:0.375rem;
box-sizing:border-box;height:1.75rem;padding:0 0.6875rem;
border:1px solid var(--vibeui-badge-020-border);border-radius:9999px;
background:var(--vibeui-badge-020-bg);color:var(--vibeui-badge-020-fg);
font-family:var(--vibeui-badge-020-font);font-size:0.75rem;font-weight:600;line-height:1;
font-variant-numeric:tabular-nums;vertical-align:middle;
}
[data-vibeui-block="badge-020"][data-state="soon"]{--vibeui-badge-020-hue:75;--vibeui-badge-020-chroma:0.09}
[data-vibeui-block="badge-020"][data-state="today"]{--vibeui-badge-020-hue:50;--vibeui-badge-020-chroma:0.14}
[data-vibeui-block="badge-020"][data-state="expired"]{--vibeui-badge-020-hue:25;--vibeui-badge-020-chroma:0.16}
[data-vibeui-block="badge-020"] [data-part="icon"]{
width:0.875rem;height:0.875rem;flex:none;color:var(--vibeui-badge-020-mark);
}
@media (prefers-reduced-motion:reduce){[data-vibeui-block="badge-020"] *{animation:none!important;transition:none!important}}
`
/** Русское склонение: 1 день, 3 дня, 11 дней. */
function plural(count: number) {
const rest100 = count % 100
const rest10 = count % 10
if (rest100 >= 11 && rest100 <= 14) {
return "дней"
}
if (rest10 === 1) {
return "день"
}
if (rest10 >= 2 && rest10 <= 4) {
return "дня"
}
return "дней"
}
/**
* Плашка срока: тон и формулировка меняются по порогу.
* Один файл, ноль зависимостей, собственная палитра.
*/
export function Badge020({
days = 3,
warnAt = 7,
className,
style,
...props
}: Badge020Props) {
const left = Math.round(days)
const overdue = Math.abs(left)
const state =
left < 0
? "expired"
: left === 0
? "today"
: left <= warnAt
? "soon"
: "calm"
const text =
state === "expired"
? `Просрочено на ${overdue} ${plural(overdue)}`
: state === "today"
? "Истекает сегодня"
: state === "soon"
? `Истекает через ${left} ${plural(left)}`
: `Ещё ${left} ${plural(left)}`
return (
<>
<style href="vibeui-badge-020" precedence="medium">
{STYLES}
</style>
<span
{...props}
data-vibeui-block="badge-020"
data-state={state}
className={className}
style={style as CSSProperties}
>
<svg
data-part="icon"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
strokeWidth="2.2"
strokeLinecap="round"
strokeLinejoin="round"
aria-hidden="true"
focusable="false"
>
<path d="M12 7v5.2l3.2 2M21 12a9 9 0 1 1-18 0 9 9 0 0 1 18 0Z" />
</svg>
{text}
</span>
</>
)
}