'use client'; import React, { forwardRef, useState } from 'react'; import { bool, string } from 'prop-types'; import { type TextFieldInterface } from './text-field.types'; export const TextField = forwardRef( ( { variant = 'filled', withAfterIcon, withBeforeIcon, supportingText, ...props }, ref, ) => { const [raised, setRaised] = useState( props.placeholder ?? false, ); const callback = (e: any): void => { if ( e.type === 'blur' && e.target.value.length === 0 && !props.placeholder ) { setRaised(false); } else if (e.type === 'focus') { setRaised(true); } }; const iconStyles = withBeforeIcon && withAfterIcon ? 'with-before-icon with-after-icon' : withBeforeIcon ? 'with-before-icon' : withAfterIcon ? 'with-after-icon' : ''; return (
{variant === 'outlined' && (
Label
)} {withBeforeIcon && ( {withBeforeIcon && 'search'} )} { callback(event); if (props.onBlur) { props.onBlur(event); } }} onFocus={event => { callback(event); if (props.onFocus) { props.onFocus(event); } }} /> {withAfterIcon && ( {withAfterIcon && 'cancel'} )}
{supportingText !== '' && ( {supportingText} )}
); }, ); TextField.propTypes = { children: string, withBeforeIcon: bool, withAfterIcon: bool, className: string, variant: string, placeholder: string, supportingText: string, };