Inputs
Percent Guard
A percent input that will not silently clamp 150 to 100: the wrong number stays in the field, gets highlighted and explained in words.
- number
- percent
- validation
- form
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/number-004?lang=en
Останется 85% от цены
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 "number-004" (Percent Guard) 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/number-004.json
Registry item: https://vibeui.ru/r/number-004.json
Installs to: components/vibeui/number-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 percent input that will not silently clamp 150 to 100: the wrong number stays in the field, gets highlighted and explained in words.
A percent field with honest 0–100 validation: the error is not hidden by autocorrection, it is highlighted and captioned. Zero dependencies, one file.
## 3. How to use it
import { Number004 } from "@/components/vibeui/number-004"
<Number004 label="Discount share" defaultValue={15} error="A percent only goes from 0 to 100." />
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-number-004-* palette — do not swap it for your theme tokens
- its own light surface: the field gets shown over any background
- the refusal to clamp silently: 150 instead of 15 is a typo, and rewriting it to 100 hides it all the way to checkout
- the data-invalid and aria-invalid pair: the highlight has to be mirrored for screen readers
- aria-live on the explanation: the error text changes without a reload and must be announced
- storing the value as a string — otherwise an in-progress empty field collapses to zero
- the bar under the field: a share reads faster as an area than as a digit
## 6. You may change
- label — the field caption
- defaultValue — the starting percent
- error — the error text under the field
- the wording of the calm-state hint
- the accent through the accent prop
## 7. Rules
- The component does not block submission: check invalid on your side before submit.
- The bar is capped at zero and a hundred even for invalid input — otherwise it escapes the frame.
- A fractional percent is allowed on input, but the hint rounds the remainder to a whole number.
- 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/number-004.jsonhttps://vibeui.ru/r/number-004.jsonКомпонент самодостаточен: один файл, ноль зависимостей, палитра в локальных переменных --vibeui-number-004-*. Клиентский: значение и признак ошибки живут в состоянии. Ввод хранится строкой, поэтому промежуточное пустое поле не превращается в ноль. Выход за 0–100 не исправляется автоматически: он помечается data-invalid на корне, aria-invalid на поле и текстом в области aria-live. Полоса под полем показывает долю площадью — процент так считывается быстрее цифры.
Component source
The same file your agent installs. Here in case you would rather copy it by hand.
"use client"
import { useId, useState } from "react"
import type { ComponentPropsWithoutRef, CSSProperties } from "react"
export type Number004Props = Omit<
ComponentPropsWithoutRef<"div">,
"children" | "defaultValue" | "onChange"
> & {
label?: string
defaultValue?: number
error?: string
accent?: string
}
// Идея компонента: процент, который не зажимается молча. 150 вместо 15 —
// это опечатка, и подменять её на 100 значит спрятать ошибку: пользователь
// увидит верное на вид число и уедет с неверными данными. Поэтому выход за
// 0–100 остаётся в поле, помечается aria-invalid и объясняется словами.
// Полоса под полем показывает долю сразу: проценты воспринимают площадью.
const STYLES = `
:where([data-vibeui-block="number-004"]){
--vibeui-number-004-surface:oklch(1 0 0);
--vibeui-number-004-field:oklch(1 0 0);
--vibeui-number-004-shell:oklch(0.9 0.006 265);
--vibeui-number-004-fg:oklch(0.23 0.014 265);
--vibeui-number-004-muted:oklch(0.55 0.014 265);
--vibeui-number-004-border:oklch(0.88 0.008 265);
--vibeui-number-004-track:oklch(0.93 0.006 265);
--vibeui-number-004-accent:oklch(0.58 0.17 285);
--vibeui-number-004-danger:oklch(0.55 0.19 25);
--vibeui-number-004-font:ui-sans-serif,system-ui,-apple-system,"Segoe UI",Roboto,"Helvetica Neue",Arial,sans-serif;
--vibeui-number-004-fill:0%;
}
/* Своя светлая подложка: поле показывают поверх любого фона. */
[data-vibeui-block="number-004"]{
display:flex;flex-direction:column;gap:0.5rem;
width:100%;max-width:17rem;box-sizing:border-box;padding:0.875rem;
background:var(--vibeui-number-004-surface);
border:1px solid var(--vibeui-number-004-shell);border-radius:0.875rem;
font-family:var(--vibeui-number-004-font);color:var(--vibeui-number-004-fg);
}
[data-vibeui-block="number-004"] label{font-size:0.8125rem;font-weight:650}
[data-vibeui-block="number-004"] [data-part="field"]{
display:flex;align-items:center;gap:0.25rem;
padding:0 0.75rem;box-sizing:border-box;height:2.75rem;
border:1px solid var(--vibeui-number-004-border);border-radius:0.625rem;
background:var(--vibeui-number-004-field);
transition:border-color .14s ease,box-shadow .14s ease;
}
[data-vibeui-block="number-004"] [data-part="field"]:focus-within{
border-color:var(--vibeui-number-004-accent);
box-shadow:0 0 0 2px oklch(0.58 0.17 285 / 20%);
}
/* Ошибка не прячется: неверное число остаётся в поле и подсвечивается. */
[data-vibeui-block="number-004"][data-invalid="true"] [data-part="field"]{
border-color:var(--vibeui-number-004-danger);
box-shadow:0 0 0 2px oklch(0.55 0.19 25 / 18%);
}
[data-vibeui-block="number-004"] input{
flex:1 1 auto;min-width:0;width:100%;
appearance:none;border:0;background:none;outline:none;
height:100%;color:inherit;
font:inherit;font-size:1.375rem;font-weight:700;text-align:right;
font-variant-numeric:tabular-nums;
}
[data-vibeui-block="number-004"] input::-webkit-outer-spin-button,
[data-vibeui-block="number-004"] input::-webkit-inner-spin-button{appearance:none;margin:0}
[data-vibeui-block="number-004"] [data-part="sign"]{
flex:none;font-size:1.125rem;font-weight:650;color:var(--vibeui-number-004-muted);
}
/* Долю читают площадью, а не цифрой: полоса отвечает мгновенно. */
[data-vibeui-block="number-004"] [data-part="bar"]{
height:0.375rem;border-radius:9999px;overflow:hidden;
background:var(--vibeui-number-004-track);
}
[data-vibeui-block="number-004"] [data-part="fill"]{
display:block;height:100%;width:var(--vibeui-number-004-fill);
background:var(--vibeui-number-004-accent);
transition:width .18s ease;
}
[data-vibeui-block="number-004"][data-invalid="true"] [data-part="fill"]{background:var(--vibeui-number-004-danger)}
[data-vibeui-block="number-004"] [data-part="note"]{
margin:0;min-height:1.05rem;font-size:0.75rem;line-height:1.4;color:var(--vibeui-number-004-muted);
}
[data-vibeui-block="number-004"][data-invalid="true"] [data-part="note"]{color:var(--vibeui-number-004-danger);font-weight:600}
@media (prefers-reduced-motion:reduce){[data-vibeui-block="number-004"] *{animation:none!important;transition:none!important}}
`
/**
* Ввод процента: выход за 0–100 не зажимается, а объясняется.
* Один файл, ноль зависимостей, собственная палитра.
*/
export function Number004({
label = "Доля скидки",
defaultValue = 15,
error = "Процент бывает только от 0 до 100.",
accent,
className,
style,
...props
}: Number004Props) {
const id = useId()
const [raw, setRaw] = useState(String(defaultValue))
const value = Number(raw)
const filled = raw !== "" && Number.isFinite(value)
const invalid = filled && (value < 0 || value > 100)
const fill = filled ? Math.min(100, Math.max(0, value)) : 0
const palette = {
"--vibeui-number-004-fill": `${fill}%`,
...(accent ? { "--vibeui-number-004-accent": accent } : null),
...style,
} as CSSProperties
return (
<>
<style href="vibeui-number-004" precedence="medium">
{STYLES}
</style>
<div
{...props}
data-vibeui-block="number-004"
data-invalid={invalid ? "true" : "false"}
className={className}
style={palette}
>
<label htmlFor={id}>{label}</label>
<div data-part="field">
<input
id={id}
type="number"
inputMode="decimal"
min={0}
max={100}
step={1}
value={raw}
aria-invalid={invalid}
aria-describedby={`${id}-note`}
onChange={(event) => setRaw(event.target.value)}
/>
<span data-part="sign" aria-hidden="true">
%
</span>
</div>
<div
data-part="bar"
role="progressbar"
aria-hidden="true"
aria-valuenow={fill}
aria-valuemin={0}
aria-valuemax={100}
>
<span data-part="fill" />
</div>
<p id={`${id}-note`} data-part="note" aria-live="polite">
{invalid ? error : `Останется ${(100 - fill).toFixed(0)}% от цены`}
</p>
</div>
</>
)
}