/** * External dependencies */ import { forwardRef } from 'react'; import PropTypes from 'prop-types'; import classnames from 'classnames'; import { useState } from '@wordpress/element'; import { Label } from '@woocommerce/blocks-checkout'; /** * Internal dependencies */ import './style.scss'; const TextInput = forwardRef( ( { className, id, type = 'text', ariaLabel, ariaDescribedBy, label, screenReaderLabel, disabled, help, autoCapitalize = 'off', autoComplete = 'off', value = '', onChange, required = false, onBlur = () => {}, feedback, }, ref ) => { const [ isActive, setIsActive ] = useState( false ); return (
{ onChange( event.target.value ); } } onFocus={ () => setIsActive( true ) } onBlur={ () => { onBlur(); setIsActive( false ); } } aria-label={ ariaLabel || label } disabled={ disabled } aria-describedby={ !! help && ! ariaDescribedBy ? id + '__help' : ariaDescribedBy } required={ required } />
); } ); TextInput.propTypes = { id: PropTypes.string.isRequired, onChange: PropTypes.func.isRequired, value: PropTypes.string, ariaLabel: PropTypes.string, ariaDescribedBy: PropTypes.string, label: PropTypes.string, screenReaderLabel: PropTypes.string, disabled: PropTypes.bool, help: PropTypes.string, autoCapitalize: PropTypes.string, autoComplete: PropTypes.string, required: PropTypes.bool, }; export default TextInput;