PercentInput
Users type percentages; maths wants fractions. This field shows 12.5 and emits 0.125, so the ×100 that usually lives in four different places in a codebase lives in exactly one. precision constrains the number of decimal places on the displayed percentage, not on the fraction.
$ npx shadcn@latest add https://input-cn.vercel.app/r/percent-input.jsonHand this to Claude Code
Most people reach this component through an agent rather than by reading the page. Pick how you want it wired and take a prompt that already carries the canonical value, the real prop names and the mistakes worth avoiding.
Nothing runs on its own. The link opens the tool with the prompt typed into the box; you read it and press Enter. If the button does nothing, Claude Code is not installed on this machine — use Copy prompt instead.
Live demo
Shows 12.5, emits 0.125.
value = 0 · fraction
Constraints
Validation rules, declared as props. Each one produces its own message and its own data-rule value, so a test can assert the rule rather than the sentence.
Props
Shared props
Implemented identically by all eleven components. These tables are generated from the source interfaces at build time, so a renamed prop changes this page rather than quietly making it wrong.
With react-hook-form
import { useForm, Controller } from "react-hook-form"
import { zodResolver } from "@hookform/resolvers/zod"
import { percentSchema } from "@inputcn/percent/schema"
import { PercentInput } from "@/components/ui/percent-input"
import { z } from "zod"
// The companion schema validates the CANONICAL value, so the resolver and the
// field can never disagree about what "valid" means.
const schema = z.object({ rate: percentSchema() })
export function Example() {
const { control } = useForm({ resolver: zodResolver(schema) })
return (
<Controller
name="rate"
control={control}
render={({ field, fieldState }) => (
<PercentInput
label="Discount rate"
{...field}
aria-invalid={fieldState.invalid}
/>
)}
/>
)
}With a Server Action
import { PercentInput } from "@/components/ui/percent-input"
export default function Page() {
return (
<form action={save}>
<PercentInput name="rate" label="Discount rate" />
<button>Save</button>
</form>
)
}
async function save(data: FormData) {
"use server"
// The hidden canonical input carries the real value, not the display text.
const rate = Number(data.get("rate")) // 0.125
}Emits number, for example 0.125. Keyboard operation is covered by automated tests; screen readers have not been verified yet.