NumericTextBox
Props
| Name | Type | Description |
|---|---|---|
| defaultValue | number | null | Default value |
| format | string | # is a placeholder for your numbers. . or , is a fractional pert separator, use either of them. The number of # after a fractional separator corresponds to the number of fractional digits. # => 1000 (any whole number) #. => 1000 #.# => 1000.0 #.### => 1000.000 You can use prefixes and suffixes alongside with numbers, they must be separated by a space. # min => 1000 min from # days => from 1000 days # is the default format |
| hasStepper | boolean | Whether or not to show stepper buttons. Default is false |
| isDisabled | boolean | Disable the component |
| max | number | Max allowed number |
| min | number | Min allowed number |
| onBlur | (event: BlurEvent) => void | Blur handler |
| onChange | (event: ChangeEvent<T>) => void | Value change handler |
| onEnterPress | (event: EnterPressEvent) => void | Enter press handler |
| onFocus | (event: FocusEvent) => void | Focus handler |
| placeholder | string | Placeholder |
| shouldTrimTrailingZeros | boolean | To trim or not to trim |
shouldRender | boolean | Pass false if you don't want the component to appear |
| step | number | How much the value is increased/decreased on mouse events |
| thousandsSeparator | string | A space by default (1 000 000.00) |
| value | number | null | Component value |
_[className] | [x: string]: unknown | E.g.: _w-48 adds a css class w-48 to the component's outer wrapper. |
<L.NumericTextBox format='#.# humans' hasStepper onChange={({ component }) => console.log(component.value)} _w-48 />
Validation components' props
| Name | Type | Description |
|---|---|---|
form | string | Form name |
invalidMessage | ReactNode | Text to show when the value does not match requirements |
isRequired | boolean | If you don't want the field to be empty |
isValid | boolean | Controlled valid state |
name | string | Component name |
persistence | 'sessionStorage' | 'localStorage' | Persist the value in web storage |
requiredMessage | ReactNode | Text to show when the field is not filled |
shouldValidateUnmounted | boolean | The field can still affect form submission even if it is not rendered |
validator | Validator
| PredefinedValidator
| RegExp
| ValidatorObject[] | |
interface Validator {
(value: any): boolean,
} | A validator is a function that takes a value and returns true or false depending on the logic it contains E.g. | |
type PredefinedValidator =
| 'creditCardNumber'
| 'email'
| 'url'
| ||
interface ValidatorObject {
validator: PredefinedValidator
| RegExp
| Validator,
invalidMessage?: string,
} |
E.g. [
{
validator: (value) => value.length > 4,
invalidMessage:
'More than 4 sympols please'
},
{
validator: /^\w+$/,
invalidMessage:
'Only a-z, A-Z, 0-9 and _ are allowed'
}
] |
<> <L.NumericTextBox onChange={({ component }) => console.log(component.value)} form='numeric_form' name='numeric' isRequired requiredMessage='Please enter something' validator={(val) => val === 42} invalidMessage='The number should be 42' _w-48 /> <br /> <L.Button form='numeric_form' onClick={({ form }) => console.log(form)} > Click me </Button> </>
Customization props
| Name | Type | |
|---|---|---|
| inputRender invalidMessageRender stepperRender wrapperRender | ({
Element,
elementprops,
componentProps,
componentState
}): React.ReactNode | Customization |
<L.NumericTextBox onChange={({ component }) => console.log(component.value)} _w-48 />
