Sha256: ba5d2d6ebcb5ad4a79ada0e92204586a7b535bde7f1e386fe2506354f30033b1
Contents?: true
Size: 922 Bytes
Versions: 5
Compression:
Stored size: 922 Bytes
Contents
import React, { useState } from 'react'; import PropTypes from 'prop-types'; import { FormGroup, TextInput, ValidatedOptions } from '@patternfly/react-core'; import { translate as __ } from 'foremanReact/common/I18n'; export const NumberInput = ({ formProps, inputProps }) => { const [validated, setValidated] = useState(); return ( <FormGroup {...formProps} helperTextInvalid={__('Has to be a number')} validated={validated} > <TextInput type="text" {...inputProps} onChange={newValue => { setValidated( /^\d+$/.test(newValue) || newValue === '' ? ValidatedOptions.noval : ValidatedOptions.error ); inputProps.onChange(newValue); }} /> </FormGroup> ); }; NumberInput.propTypes = { formProps: PropTypes.object.isRequired, inputProps: PropTypes.object.isRequired, };
Version data entries
5 entries across 5 versions & 1 rubygems