/** @jsxImportSource @emotion/react */ import { css } from '@emotion/react'; import { ReactNode, useCallback, useState } from 'react'; import { GlobalInputTheme } from './input'; type Types = { children: ReactNode; edge?: ReactNode; tab?: TabType; tabId?: string; sizes?: InputSizesType; themes?: ThemesType; events?: { error?: ErrorType; disabled?: boolean; }; }; function FieldContainer(props: Types) { const { children, edge, tab, tabId, sizes, themes, events } = props; const { disabled } = events ?? {}; const error = events?.error?.error; const [focus, setFocus] = useState(false); const handleFocus = () => { if (!disabled) setFocus(true); }; const handleBlur = () => { if (!disabled) setFocus(false); }; const inputEdgeColor = () => { if (disabled) return themes?.disabled?.edgeColor ?? '#999'; if (error) return themes?.error?.edgeColor ?? '#999'; if (focus && !error) return themes?.focus?.edgeColor ?? '#999'; return themes?.default?.edgeColor ?? '#888'; }; const borderColor = () => { if (disabled) return themes?.disabled?.borderColor ?? '#eee'; if (error) return themes?.error?.borderColor ?? '#FF6767'; if (focus && !error) return themes?.focus?.borderColor ?? '#b9d0e4'; return themes?.default?.borderColor ?? '#e0e0e0'; }; const backgroundColor = () => { if (disabled) return themes?.disabled?.backgroundColor ?? '#f5f5f5'; if (error) return themes?.error?.backgroundColor ?? '#fffbfb'; if (focus && !error) return themes?.focus?.backgroundColor ?? '#f8f9fc'; return themes?.default?.backgroundColor ?? '#fff'; }; const colorTheme = () => { if (focus && !error) return themes?.focus?.txtColor ?? '#555'; if (disabled) return themes?.disabled?.txtColor ?? '#797979'; if (error) return themes?.error?.txtColor ?? '#555'; return themes?.default?.txtColor ?? '#555'; }; const placeholderTheme = () => { if (disabled) return themes?.disabled?.placeholderColor ?? '#c2c2c2'; if (error) return themes?.error?.placeholderColor ?? '#c2c2c2'; if (focus && !error) return themes?.focus?.placeholderColor ?? '#c2c2c2'; return themes?.default?.placeholderColor ?? '#c2c2c2'; }; const handleClick = useCallback(() => { if (tab?.onClick && !tab.disabled) { tab.onClick(); } }, [tab]); return (