Sha256: b3cac3435b4a6c3946c0b4552e82242a44b11e60f08abf63c3c0798a03a670fd
Contents?: true
Size: 1.04 KB
Versions: 55
Compression:
Stored size: 1.04 KB
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'; import { isPositiveNumber } from './FormHelpers'; export const NumberInput = ({ formProps, inputProps }) => { const [validated, setValidated] = useState(); const name = inputProps.id.replace(/-/g, ' '); return ( <FormGroup {...formProps} helperTextInvalid={__('Has to be a positive number')} validated={validated} > <TextInput aria-label={name} type="text" {...inputProps} onChange={newValue => { setValidated( isPositiveNumber(newValue) || newValue === '' ? ValidatedOptions.noval : ValidatedOptions.error ); inputProps.onChange(newValue); }} /> </FormGroup> ); }; NumberInput.propTypes = { formProps: PropTypes.object.isRequired, inputProps: PropTypes.object.isRequired, };
Version data entries
55 entries across 55 versions & 1 rubygems