Last modified: 18/Nov/2024
Number input
The number input is a number specific input type. Use it when you need numerical data from the user.
#Usage
import { NumberInput } from '@kinsta/stratus'
const MyComponent = () => (
<NumberInput
steps={10}
label="Type a number"
/>
)
Controlled example:
import type { JSX } from 'react'
import { useState } from 'react'
import { NumberInput } from '@kinsta/stratus'
const MyComponent = (): JSX.Element | null => {
const [inputValue, setInputValue] = useState(0)
return (
<NumberInput
value={inputValue}
onChange={setInputValue}
/>
)
}
Example with tooltip:
import { NumberInput } from '@kinsta/stratus'
import { useState } from 'react'
const MyComponent = () => (
const [inputValue, setInputValue] = useState(0)
const minValue = 0
const maxValue = 3
return (
<NumberInput
value={inputValue}
onChange={setInputValue}
min={minValue}
max={maxValue}
tooltip={{
max: {
content: 'You reached the maximum value',
shouldShowOnMinMaxLimitReached: true,
},
}}
/>
)
)
#Props
#steps
number
The incrementation applied by the +/- buttons
#onChange
(value: number | "") => void
Use to get the value of the number input
#value
number | ""
The value of the input
#tooltip
{ min?: AddonTooltipProps; max?: AddonTooltipProps; }
Tooltip settings for the +/- buttons
#isDisabled
boolean
Set the disabled state of input
#hasAutoFocus
boolean
Set that the input should be focused when rendered
#hasError
boolean
Set the error state of the input
#prefixItem
ReactNode
Content of the prefix of the input
#suffixItem
ReactNode
Content of the suffix of the input
#label
string | ReactElement<any, string | JSXElementConstructor<any>>
Content of the label
#description
string | ReactElement<any, string | JSXElementConstructor<any>>
Content of the description
#errorMessage
string | ReactElement<any, string | JSXElementConstructor<any>>
Content of the error message
#unit
string
Sets the unit of the input
#Types
NumberInputInterface
: props of theNumberInput
component extended byOmit<InputInterface, 'type' | 'isReadOnly' | 'onChange' | 'addonBefore' | 'addonAfter'>
Read more about types here