|
| 1 | +import {ReactElement, Component} from 'react'; |
| 2 | +import { |
| 3 | + GestureResponderEvent, |
| 4 | + ImageSourcePropType, |
| 5 | + StyleProp, |
| 6 | + TextInputProps as RNTextInputProps, |
| 7 | + TextStyle, |
| 8 | + ViewStyle, |
| 9 | + ColorValue |
| 10 | +} from 'react-native'; |
| 11 | +// import {BaseComponent} from '../commons'; |
| 12 | +// import {TopBarProps} from './Modal'; |
| 13 | + |
| 14 | +export type BaseInputDefaultValidator = 'required' | 'email' | 'url' | 'number' | 'price'; |
| 15 | +export type BaseInputCustomValidator = (value?: string) => boolean; |
| 16 | +export type BaseInputValidator = BaseInputDefaultValidator | BaseInputCustomValidator; |
| 17 | +export type BaseInputValidateProp = BaseInputValidator | BaseInputValidator[]; |
| 18 | + |
| 19 | +export interface BaseInputProps extends RNTextInputProps { |
| 20 | + color?: ColorValue; |
| 21 | + containerStyle?: StyleProp<ViewStyle>; |
| 22 | + validate?: BaseInputValidateProp; |
| 23 | + markRequired?: boolean; |
| 24 | + errorMessage?: string | string[]; |
| 25 | + validateOnStart?: boolean; |
| 26 | + validateOnChange?: boolean; |
| 27 | + validateOnBlur?: boolean; |
| 28 | + onChangeValidity?: (isValid: boolean) => void; |
| 29 | +} |
| 30 | + |
| 31 | +export type InputColorValue = ColorValue | {[key: string]: ColorValue}; |
| 32 | + |
| 33 | +export interface TextBaseInputProps { |
| 34 | + migrate?: boolean; |
| 35 | + floatingPlaceholder?: boolean; |
| 36 | + floatingPlaceholderColor?: InputColorValue; |
| 37 | + helperText?: string; |
| 38 | + hideUnderline?: boolean; |
| 39 | + underlineColor?: InputColorValue; |
| 40 | + disabledColor?: ColorValue; |
| 41 | + centered?: boolean; |
| 42 | + error?: string; |
| 43 | + enableErrors?: boolean; |
| 44 | + expandable?: boolean; |
| 45 | + transformer?: (text?: string) => string | undefined; |
| 46 | + title?: string; |
| 47 | + titleColor?: InputColorValue; |
| 48 | + titleStyle?: StyleProp<TextStyle>; |
| 49 | + showCharacterCounter?: boolean; |
| 50 | + floatOnFocus?: boolean; |
| 51 | + useTopErrors?: boolean; |
| 52 | + rightIconSource?: ImageSourcePropType; |
| 53 | +} |
| 54 | + |
| 55 | +export interface TextFieldRightButtonProps { |
| 56 | + iconSource?: ImageSourcePropType; |
| 57 | + iconColor?: ColorValue; |
| 58 | + onPress?: (event: GestureResponderEvent) => void; |
| 59 | + style?: StyleProp<ViewStyle>; |
| 60 | +} |
| 61 | + |
| 62 | +export interface TextFieldProps extends BaseInputProps, TextBaseInputProps { |
| 63 | + renderExpandableInput?: (props: TextFieldProps) => ReactElement; |
| 64 | + renderExpandable?: (props: TextFieldProps, state: TextFieldState) => ReactElement; |
| 65 | + onToggleExpandableModal?: (value?: string) => void; |
| 66 | + // topBarProps?: TopBarProps; |
| 67 | + rightButtonProps?: TextFieldRightButtonProps; |
| 68 | +} |
| 69 | + |
| 70 | +export type TextFieldState = any; |
| 71 | + |
| 72 | +export class TextField extends BaseInput<TextFieldProps, TextFieldState> {} |
| 73 | + |
| 74 | +export interface TextInputProps extends BaseInputProps, TextBaseInputProps { |
| 75 | + renderExpandableInput?: (props: TextInputProps) => ReactElement | ReactElement[]; |
| 76 | + renderExpandable?: (props: TextInputProps, state: TextInputState) => ReactElement | ReactElement[]; |
| 77 | +} |
| 78 | + |
| 79 | +export type TextInputState = any; |
| 80 | + |
| 81 | +export class TextInput extends BaseInput<TextInputProps, TextInputState> {} |
| 82 | + |
| 83 | +export interface MaskedInputProps extends TextFieldProps { |
| 84 | + renderMaskedText?: (value?: string) => ReactElement | ReactElement[]; |
| 85 | + containerStyle?: StyleProp<ViewStyle>; |
| 86 | +} |
| 87 | + |
| 88 | +export class MaskedInput extends BaseInput<MaskedInputProps> {} |
| 89 | + |
| 90 | +export default class BaseInput<Props extends BaseInputProps = BaseInputProps, State = {}> extends Component< |
| 91 | + Props, |
| 92 | + State |
| 93 | +> { |
| 94 | + onBlur(): void; |
| 95 | +} |
0 commit comments