import { StyleProp, ViewStyle, TextStyle, TextInputProps } from 'react-native'; import { ReactNode } from 'react'; /** 输入框类型 */ export type InputType = 'text' | 'password' | 'number' | 'integer' | 'phone' | 'email' | 'url' | 'textarea'; /** 输入框状态 */ export type InputStatus = 'default' | 'success' | 'warning' | 'error'; /** 图标配置 */ export interface InputIconConfig { /** 图标名称 */ name: string; /** 图标库 */ family?: 'Ionicons' | 'FontAwesome' | 'MaterialIcons' | 'Entypo'; /** 图标大小 */ size?: number; /** 图标颜色 */ color?: string; } /** 输入规则 */ export interface InputRule { /** 是否必填 */ required?: boolean; /** 必填错误提示 */ requiredMessage?: string; /** 最小长度 */ minLength?: number; /** 最小长度错误提示 */ minLengthMessage?: string; /** 最大长度 */ maxLength?: number; /** 最大长度错误提示 */ maxLengthMessage?: string; /** 正则校验 */ pattern?: RegExp; /** 正则校验错误提示 */ patternMessage?: string; /** 自定义校验函数 */ validator?: (value: string) => boolean | string | Promise; } /** XSS 过滤选项 */ export interface XSSFilterOptions { /** 是否启用 XSS 过滤 */ enabled?: boolean; /** 是否过滤 HTML 标签 */ stripHtml?: boolean; /** 是否过滤脚本标签 */ stripScript?: boolean; /** 是否编码特殊字符 */ encodeEntities?: boolean; /** 自定义过滤函数 */ customFilter?: (value: string) => string; } /** DbInput 组件属性 */ export interface DbInputProps extends Omit { /** 输入框类型 */ type?: InputType; /** 输入框的值 */ value?: string; /** 默认值 */ defaultValue?: string; /** 占位文字 */ placeholder?: string; /** 占位文字颜色 */ placeholderTextColor?: string; /** 标签文字 */ label?: string; /** 标签位置 */ labelPosition?: 'top' | 'left' | 'floating'; /** 是否必填(显示红色星号) */ required?: boolean; /** 提示文字 */ hint?: string; /** 错误提示 */ error?: string; /** 状态 */ status?: InputStatus; /** 左侧图标 */ leftIcon?: InputIconConfig | ReactNode; /** 右侧图标 */ rightIcon?: InputIconConfig | ReactNode; /** 点击左侧图标 */ onLeftIconPress?: () => void; /** 点击右侧图标 */ onRightIconPress?: () => void; /** 是否显示密码可见切换 */ showPasswordToggle?: boolean; /** 密码可见图标 */ passwordVisibleIcon?: InputIconConfig; /** 密码隐藏图标 */ passwordHiddenIcon?: InputIconConfig; /** 是否显示清除按钮 */ showClear?: boolean; /** 清除图标配置 */ clearIcon?: InputIconConfig; /** 清除回调 */ onClear?: () => void; /** 是否显示字数统计 */ showCount?: boolean; /** 最大字符数 */ maxLength?: number; /** 数字精度(小数位数) */ precision?: number; /** 最小值 */ min?: number; /** 最大值 */ max?: number; /** 是否显示增减按钮 */ showStepper?: boolean; /** 步长 */ step?: number; /** 是否格式化电话号码显示 */ formatPhone?: boolean; /** 电话号码区号 */ phonePrefix?: string; /** 行数(textarea 模式) */ rows?: number; /** 是否自动增高 */ autoGrow?: boolean; /** 最小高度 */ minHeight?: number; /** 最大高度 */ maxHeight?: number; /** 校验规则 */ rules?: InputRule[]; /** 校验触发时机 */ validateTrigger?: 'onChange' | 'onBlur' | 'onSubmit'; /** 校验回调 */ onValidate?: (isValid: boolean, error?: string) => void; /** XSS 过滤选项 */ xssFilter?: XSSFilterOptions | boolean; /** 是否禁用 */ disabled?: boolean; /** 是否只读 */ readonly?: boolean; /** 输入框形状 */ shape?: 'default' | 'round' | 'underline'; /** 输入框尺寸 */ size?: 'small' | 'medium' | 'large'; /** 容器样式 */ style?: StyleProp; /** 输入框容器样式 */ inputContainerStyle?: StyleProp; /** 输入框样式 */ inputStyle?: StyleProp; /** 标签样式 */ labelStyle?: StyleProp; /** 提示文字样式 */ hintStyle?: StyleProp; /** 错误文字样式 */ errorStyle?: StyleProp; /** 值变化回调(经过 XSS 过滤后的值) */ onChangeText?: (text: string, rawText?: string) => void; /** 提交回调 */ onSubmit?: (text: string) => void; /** 聚焦回调 */ onFocus?: () => void; /** 失焦回调 */ onBlur?: () => void; } /** 输入框引用方法 */ export interface DbInputRef { /** 聚焦 */ focus: () => void; /** 失焦 */ blur: () => void; /** 清空 */ clear: () => void; /** 获取值 */ getValue: () => string; /** 设置值 */ setValue: (value: string) => void; /** 校验 */ validate: () => Promise; /** 重置校验状态 */ resetValidation: () => void; }