import { RtData, RtFormFieldBaseProps, RtFormFieldSize, RtFormFieldTextSymbol, RtFormFieldUI, } from '../types/rt-form-field-text.types'; import { RtFrame } from '@dpa/react-frame-intro'; import { RtText } from '@dpa/react-text'; import classNames from 'classnames/bind'; import styles from '../styles/rt-form-field.module.css'; import { ChangeEvent, FocusEvent, Fragment, KeyboardEvent, MouseEvent, RefObject, useContext, useRef, } from 'react'; import mergeRefs from 'merge-refs'; import { RtSymbolAction, RtSymbolActionOriginProps, } from '@dpa/react-symbol-action'; import { CSSTransition } from 'react-transition-group'; import { RtFormFieldChevronShowContext } from '../context/chevron-context'; import { RtPopover } from '@dpa/react-popover'; import { RtSnackbar } from '@dpa/react-snackbar'; const cn = classNames.bind(styles); export function useFormFieldLayout( props: RtFormFieldBaseProps & RtFormFieldTextSymbol & { ui: RtFormFieldUI; size: RtFormFieldSize; }, { formatLabel, id, canClear, symbolActionSize, data: RtData, showPrefixSuffix, localInputRef, formFieldDataContentRef, handleClear, handleChange, handleFocus, handleBlur, handleKeyUp, handleKeyDown, handleTrailingActionClick, isAmbulantLabelFloating, }: { formatLabel: string; id: string; canClear: boolean; showPrefixSuffix: boolean; isAmbulantLabelFloating: boolean; symbolActionSize: { width: RtSymbolActionOriginProps['width']; height: RtSymbolActionOriginProps['height']; }; localInputRef: RefObject; formFieldDataContentRef: RefObject; handleClear: (e: MouseEvent) => void; handleChange: (e: ChangeEvent) => void; handleFocus: (e: FocusEvent) => void; handleBlur: (e: FocusEvent) => void; handleKeyUp: (e: KeyboardEvent) => void; handleKeyDown: (e: KeyboardEvent) => void; handleTrailingActionClick: (e: MouseEvent) => void; data: RtData; } ) { const { leadingIcon: LeadingIcon, trailingIcon: TrailingIcon, trailingAction: TrailingAction, } = props; const closeIconRef = useRef(null); const chevronContext = useContext(RtFormFieldChevronShowContext); const isLarge = props.size === 'lg'; const LinesLabel = props.ui === 'ambulant-label' && props.label && ( ); const ContentLeadingSlotWrapper = props.leadingSlot && (
{props.leadingSlot}
); const ContentTrailingSlotWrapper = props.trailingSlot && (
{props.trailingSlot}
); const FormFieldLabel = (props.ui === 'normal' || props.ui === 'space') && props.label && (
{formatLabel}
); const FormFieldDetails = props.detailsSlot ? ( props.detailsSlot ) : props.details ? (
{props.details}
{props.counter && (
{String(props.value.length)} {props.maxLength ? `/${props.maxLength}` : ''}
)}
) : ( ); const ContentLeadingIcon = LeadingIcon && ( { } ); const ContentTrailingIcon = TrailingIcon && ( ); const ClearButton = ( { e.preventDefault(); e.stopPropagation(); }} /> ); const ChevronButton = chevronContext.isVisible && ( { e.preventDefault(); e.stopPropagation(); }} > ); const TrailingActionWithPopover = TrailingAction && ( ); const ContentLines = ( {LinesLabel}
{props.prefix && showPrefixSuffix && ( {props.prefix} )} {props.suffix && showPrefixSuffix && ( {props.suffix} )}
); const Hint = props.hint ? ( ) : ( ); return { LinesLabel, ContentLeadingIcon, ContentLeadingSlotWrapper, ContentTrailingSlotWrapper, FormFieldLabel, FormFieldDetails, ContentTrailingIcon, ClearButton, ChevronButton, ContentLines, TrailingAction: TrailingActionWithPopover, Hint, }; }