/** * External dependencies */ import PropTypes from 'prop-types'; import classnames from 'classnames'; import { useState } from '@wordpress/element'; import withComponentId from '@woocommerce/base-hocs/with-component-id'; /** * Internal dependencies */ import Label from '../label'; import './style.scss'; const TextInput = ( { className, componentId, id, type = 'text', ariaLabel, label, screenReaderLabel, disabled, help, autoComplete = 'off', value = '', onChange, } ) => { const [ isActive, setIsActive ] = useState( false ); const onChangeValue = ( event ) => onChange( event.target.value ); const textInputId = id || 'textinput-' + componentId; return (
setIsActive( true ) } onBlur={ () => setIsActive( false ) } aria-label={ ariaLabel || label } disabled={ disabled } aria-describedby={ !! help ? textInputId + '__help' : undefined } />
); }; TextInput.propTypes = { onChange: PropTypes.func.isRequired, id: PropTypes.string, value: PropTypes.string, ariaLabel: PropTypes.string, label: PropTypes.string, screenReaderLabel: PropTypes.string, disabled: PropTypes.bool, help: PropTypes.string, autoComplete: PropTypes.string, }; export default withComponentId( TextInput );