import { AccentColor, MainColor } from "@/constants/color-palet"; import { GStyles } from "@/styles/global-styles"; import React, { useEffect, useState } from "react"; import { TextInput as RNTextInput, StyleProp, Text, View, ViewStyle, useColorScheme, } from "react-native"; import { PlaceholderColor } from "@/constants/color-palet"; type IconType = React.ReactNode | string; type BaseProps = { iconLeft?: IconType; iconRight?: IconType; label?: string; required?: boolean; error?: string; fontColor?: string; disabled?: boolean; borderRadius?: number; autosize?: boolean; minRows?: number; maxRows?: number; showCount?: boolean; maxLength?: number; height?: number; style?: StyleProp; }; type NativeTextInputProps = Omit< React.ComponentProps, "style" >; export type TextAreaCustomProps = BaseProps & NativeTextInputProps; const TextAreaCustom: React.FC = ({ iconLeft, iconRight, label, required = false, error = "", fontColor = "#000", disabled = false, borderRadius = 8, autosize = false, minRows = 4, maxRows = 6, showCount = false, maxLength = 1000, value, onChangeText, height = 100, style, ...rest }) => { const [numberOfLines, setNumberOfLines] = useState(minRows); // Autosizing logic useEffect(() => { if (!autosize || !value) return; const text = value as string; const lines = text.split("\n").length; const newLines = Math.max(minRows, Math.min(maxRows, lines)); setNumberOfLines(newLines); }, [value, autosize, minRows, maxRows]); const hasError = Boolean(error); const renderIcon = (icon: IconType) => { if (!icon) return null; return typeof icon === "string" ? ( {icon} ) : ( icon ); }; const colorScheme = useColorScheme(); const theme = PlaceholderColor[colorScheme || "light"]; return ( {label && ( {label} {required && *} )} {iconLeft && ( {renderIcon(iconLeft)} )} {iconRight && ( {renderIcon(iconRight)} )} {/* Error Message atau Counter */} {hasError ? ( {error} ) : null} {showCount && maxLength ? ( {(value as string)?.length || 0}/{maxLength} ) : null} ); }; export default TextAreaCustom;