1 | import type { CSSProperties, InputHTMLAttributes, KeyboardEventHandler, MouseEventHandler, ReactElement, ReactNode } from 'react';
|
2 | import type { InputFocusOptions } from './utils/commonUtils';
|
3 | import type { LiteralUnion } from './utils/types';
|
4 | export interface CommonInputProps {
|
5 | prefix?: ReactNode;
|
6 | suffix?: ReactNode;
|
7 | addonBefore?: ReactNode;
|
8 | addonAfter?: ReactNode;
|
9 |
|
10 | classes?: {
|
11 | affixWrapper?: string;
|
12 | group?: string;
|
13 | wrapper?: string;
|
14 | };
|
15 | classNames?: {
|
16 | affixWrapper?: string;
|
17 | prefix?: string;
|
18 | suffix?: string;
|
19 | groupWrapper?: string;
|
20 | wrapper?: string;
|
21 | };
|
22 | styles?: {
|
23 | affixWrapper?: CSSProperties;
|
24 | prefix?: CSSProperties;
|
25 | suffix?: CSSProperties;
|
26 | };
|
27 | allowClear?: boolean | {
|
28 | clearIcon?: ReactNode;
|
29 | };
|
30 | }
|
31 | type DataAttr = Record<`data-${string}`, string>;
|
32 | export type ValueType = InputHTMLAttributes<HTMLInputElement>['value'] | bigint;
|
33 | export interface BaseInputProps extends CommonInputProps {
|
34 | value?: ValueType;
|
35 |
|
36 | inputElement?: ReactElement;
|
37 | prefixCls?: string;
|
38 | className?: string;
|
39 | style?: CSSProperties;
|
40 | disabled?: boolean;
|
41 | focused?: boolean;
|
42 | triggerFocus?: () => void;
|
43 | readOnly?: boolean;
|
44 | handleReset?: MouseEventHandler;
|
45 | hidden?: boolean;
|
46 | dataAttrs?: {
|
47 | affixWrapper?: DataAttr;
|
48 | };
|
49 | components?: {
|
50 | affixWrapper?: 'span' | 'div';
|
51 | groupWrapper?: 'span' | 'div';
|
52 | wrapper?: 'span' | 'div';
|
53 | groupAddon?: 'span' | 'div';
|
54 | };
|
55 | children: ReactElement;
|
56 | }
|
57 | export type ShowCountFormatter = (args: {
|
58 | value: string;
|
59 | count: number;
|
60 | maxLength?: number;
|
61 | }) => ReactNode;
|
62 | export type ExceedFormatter = (value: string, config: {
|
63 | max: number;
|
64 | }) => string;
|
65 | export interface CountConfig {
|
66 | max?: number;
|
67 | strategy?: (value: string) => number;
|
68 | show?: boolean | ShowCountFormatter;
|
69 |
|
70 | exceedFormatter?: ExceedFormatter;
|
71 | }
|
72 | export interface InputProps extends CommonInputProps, Omit<InputHTMLAttributes<HTMLInputElement>, 'size' | 'prefix' | 'type' | 'value'> {
|
73 | value?: ValueType;
|
74 | prefixCls?: string;
|
75 | type?: LiteralUnion<'button' | 'checkbox' | 'color' | 'date' | 'datetime-local' | 'email' | 'file' | 'hidden' | 'image' | 'month' | 'number' | 'password' | 'radio' | 'range' | 'reset' | 'search' | 'submit' | 'tel' | 'text' | 'time' | 'url' | 'week', string>;
|
76 | onPressEnter?: KeyboardEventHandler<HTMLInputElement>;
|
77 |
|
78 | showCount?: boolean | {
|
79 | formatter: ShowCountFormatter;
|
80 | };
|
81 | autoComplete?: string;
|
82 | htmlSize?: number;
|
83 | classNames?: CommonInputProps['classNames'] & {
|
84 | input?: string;
|
85 | count?: string;
|
86 | };
|
87 | styles?: CommonInputProps['styles'] & {
|
88 | input?: CSSProperties;
|
89 | count?: CSSProperties;
|
90 | };
|
91 | count?: CountConfig;
|
92 | }
|
93 | export interface InputRef {
|
94 | focus: (options?: InputFocusOptions) => void;
|
95 | blur: () => void;
|
96 | setSelectionRange: (start: number, end: number, direction?: 'forward' | 'backward' | 'none') => void;
|
97 | select: () => void;
|
98 | input: HTMLInputElement | null;
|
99 | }
|
100 | export {};
|