matrix-react-sdk
Version:
SDK for matrix.org using React
75 lines (74 loc) • 2.42 kB
TypeScript
import React, { InputHTMLAttributes, SelectHTMLAttributes, TextareaHTMLAttributes, RefObject } from "react";
import { IFieldState, IValidationResult } from "./Validation";
import { Alignment } from "./Tooltip";
export interface IValidateOpts {
focused?: boolean;
allowEmpty?: boolean;
}
interface IProps {
id?: string;
label?: string;
placeholder?: string;
usePlaceholderAsHint?: boolean;
prefixComponent?: React.ReactNode;
postfixComponent?: React.ReactNode;
onValidate?: (input: IFieldState) => Promise<IValidationResult>;
forceValidity?: boolean;
tooltipContent?: React.ReactNode;
forceTooltipVisible?: boolean;
tooltipAlignment?: Alignment;
tooltipClassName?: string;
className?: string;
validateOnFocus?: boolean;
validateOnBlur?: boolean;
validateOnChange?: boolean;
}
export interface IInputProps extends IProps, InputHTMLAttributes<HTMLInputElement> {
inputRef?: RefObject<HTMLInputElement>;
element: "input";
value: string;
}
interface ISelectProps extends IProps, SelectHTMLAttributes<HTMLSelectElement> {
inputRef?: RefObject<HTMLSelectElement>;
element: "select";
value: string;
}
interface ITextareaProps extends IProps, TextareaHTMLAttributes<HTMLTextAreaElement> {
inputRef?: RefObject<HTMLTextAreaElement>;
element: "textarea";
value: string;
}
export interface INativeOnChangeInputProps extends IProps, InputHTMLAttributes<HTMLInputElement> {
inputRef?: RefObject<HTMLInputElement>;
element: "input";
value: string;
}
type PropShapes = IInputProps | ISelectProps | ITextareaProps | INativeOnChangeInputProps;
interface IState {
valid?: boolean;
feedback?: React.ReactNode;
feedbackVisible: boolean;
focused: boolean;
}
export default class Field extends React.PureComponent<PropShapes, IState> {
private readonly id;
private readonly _inputRef;
static readonly defaultProps: {
element: string;
type: string;
validateOnFocus: boolean;
validateOnBlur: boolean;
validateOnChange: boolean;
};
private validateOnChange;
constructor(props: PropShapes);
focus(): void;
private onFocus;
private onChange;
private onBlur;
validate({ focused, allowEmpty }: IValidateOpts): Promise<boolean | undefined>;
private get inputRef();
private onKeyDown;
render(): React.ReactNode;
}
export {};