import React, { ExoticComponent, forwardRef, PropsWithChildren, ReactNode, useState } from 'react'; import cn from 'classnames'; import { baseStyles, inputStyles, sizeStyles, TextFieldVariants, variantStyles } from './text_field_styles'; import IconButton from '@mui/material/IconButton'; import VisibilityOffIcon from '@mui/icons-material/VisibilityOff'; import VisibilityIcon from '@mui/icons-material/Visibility'; interface CustomProps { containerElement?: string | ExoticComponent; containerProps?: any; className?: string; inputClassName?: string; fullWidth?: boolean; inputRef?: any; containerRef?: any; beforeChildren?: ReactNode; multiline?: boolean; rows?: number; variant?: TextFieldVariants; type?: HTMLInputElement['type']; disabled?: boolean; classes?: { container?: string; input?: string }; size?: 'small' | 'regular'; onFocus?: (...args: any[]) => void; onBlur?: (...args: any[]) => void; passwordLabels?: { show: string; hide: string; }; } export type TextFieldProps = Omit, 'size'> & CustomProps; export const TextField = forwardRef>( ( { containerElement: ContainerElement = 'div', containerProps, className, inputClassName, fullWidth, inputRef, containerRef, beforeChildren = null, multiline, rows, children, variant = 'raised', type = 'text', disabled, size = 'regular', classes = {}, ...other }, ref ) => { const InputComponent = multiline ? 'textarea' : 'input'; const isPassword = type === 'password'; const [showHidePassword, changeShowHidePassword] = useState(false); const togglePasswordVisiblity = () => { changeShowHidePassword(!showHidePassword); }; return ( {beforeChildren} {isPassword && ( {showHidePassword ? : } )} {children} ); } );