Skip to content

PercentInput

A share typed as a percent. The value is a fraction: 25 % is 0.25.

import { PercentInput } from '@sypnia/ui/react'

On this page
  1. A discount
  2. When to use it
  3. For everyone
  4. Props

A discount

Saved as 0.15

Code
import { useState } from 'react';
import { Field, PercentInput } from '@sypnia/ui/react';

// Typed as a percent, saved as a fraction: 25 % is 0.25.
export default function Discount() {
  const [v, setV] = useState<number | null>(0.15);
  return <Field label="Discount for yearly plans" hint={`Saved as ${v ?? '—'}`}><PercentInput value={v} onChange={setV} /></Field>;
}

When to use it

Use it when

  • Discounts, thresholds, sampling rates.

Do not use it when

  • Whole numbers of things: use NumberInput.

For everyone

  • The percent sign is read with the value.

Props

PercentInputTypeDefault
aria-describedby string
aria-label

The name for screen readers when there is no Field around it.

string
aria-labelledby string
className string
decimals number
defaultValue number
disabled boolean
id

Inside a Field it comes from the Field.

string
invalid

Marks the value as wrong. Inside a `<Field error>` it is set for you.

boolean
max number
min number
name string
onChange ((value: number | null) => void)
placeholder string
size "sm" | "md" | "lg"
step

How much each press of a stepper or an arrow key adds.

number
value

The number, or null while the box is empty.

number | null
  1. A discount
  2. When to use it
  3. For everyone
  4. Props

    Search pages, sections and terms