UNPKG

6.81 kBTypeScriptView Raw
1/// <reference types="react" />
2
3import * as React from 'react';
4import CommonProps from '../util';
5
6interface HTMLAttributesWeak extends React.InputHTMLAttributes<HTMLElement> {
7 defaultValue?: any;
8 onChange?: any;
9 onKeyDown?: any;
10 size?: any;
11}
12
13export interface TextAreaProps extends HTMLAttributesWeak, CommonProps {
14 /**
15 * 当前值
16 */
17 value?: string | number;
18
19 /**
20 * 初始化值
21 */
22 defaultValue?: string | number;
23
24 /**
25 * 发生改变的时候触发的回调
26 */
27 onChange?: (value: string, e: React.ChangeEvent<HTMLTextAreaElement>, type?: string) => void;
28
29 /**
30 * 键盘按下的时候触发的回调
31 */
32 onKeyDown?: (e: React.KeyboardEvent<HTMLTextAreaElement>, opts: {}) => void;
33
34 /**
35 * 禁用状态
36 */
37 disabled?: boolean;
38
39 /**
40 * 最大长度
41 */
42 maxLength?: number;
43
44 /**
45 * 是否展现最大长度样式
46 */
47 hasLimitHint?: boolean;
48 showLimitHint?: boolean;
49
50 /**
51 * 当设置了maxLength时,是否截断超出字符串
52 */
53 cutString?: boolean;
54
55 /**
56 * 只读
57 */
58 readOnly?: boolean;
59
60 /**
61 * onChange返回会自动去除头尾空字符
62 */
63 trim?: boolean;
64
65 /**
66 * 输入提示
67 */
68 placeholder?: string;
69
70 /**
71 * 获取焦点时候触发的回调
72 */
73 onFocus?: (e: React.FocusEvent<HTMLTextAreaElement>) => void;
74
75 /**
76 * 失去焦点时候触发的回调
77 */
78 onBlur?: (e: React.FocusEvent<HTMLTextAreaElement>) => void;
79
80 /**
81 * 自定义字符串计算长度方式
82 */
83 getValueLength?: (value: string) => number;
84
85 /**
86 * 自定义class
87 */
88 className?: string;
89
90 /**
91 * 自定义内联样式
92 */
93 style?: React.CSSProperties;
94
95 /**
96 * 原生type
97 */
98 htmlType?: string;
99
100 /**
101 * name
102 */
103 name?: string;
104
105 /**
106 * 状态
107 */
108 state?: 'error' | 'warning';
109
110 /**
111 * 是否有边框
112 */
113 hasBorder?: boolean;
114
115 /**
116 * 自动高度 true / {minRows: 2, maxRows: 4}
117 */
118 autoHeight?: boolean | {};
119
120 /**
121 * 多行文本框高度 <br />(不要直接用height设置多行文本框的高度, ie9 10会有兼容性问题)
122 */
123 rows?: number;
124
125 /**
126 * 是否为预览态
127 */
128 isPreview?: boolean;
129
130 renderPreview?: (value: string | number) => React.ReactNode;
131
132 /**
133 * 开启后会过滤输入法中间字母状态,文字输入完成后才会触发 onChange
134 */
135 composition?: boolean;
136}
137
138export class TextArea extends React.Component<TextAreaProps, any> {}
139
140export interface GroupProps extends React.HTMLAttributes<HTMLElement>, CommonProps {
141 /**
142 * 样式前缀
143 */
144 prefix?: string;
145
146 /**
147 * 输入框前附加内容
148 */
149 addonBefore?: React.ReactNode;
150
151 /**
152 * 输入框前附加内容css
153 */
154 addonBeforeClassName?: string;
155
156 /**
157 * 输入框后附加内容
158 */
159 addonAfter?: React.ReactNode;
160
161 /**
162 * 输入框后额外css
163 */
164 addonAfterClassName?: string;
165
166 /**
167 * rtl
168 */
169 rtl?: boolean;
170}
171
172export class Group extends React.Component<GroupProps, any> {}
173
174export interface InputProps extends HTMLAttributesWeak, CommonProps {
175 /**
176 * 当前值
177 */
178 value?: string | number;
179
180 /**
181 * 初始化值
182 */
183 defaultValue?: string | number;
184
185 /**
186 * 发生改变的时候触发的回调
187 */
188 onChange?: (value: string, e: React.ChangeEvent<HTMLInputElement>, type?: string) => void;
189
190 /**
191 * 键盘按下的时候触发的回调
192 */
193 onKeyDown?: (e: React.KeyboardEvent<HTMLInputElement>, opts: {}) => void;
194
195 /**
196 * 禁用状态
197 */
198 disabled?: boolean;
199
200 /**
201 * 最大长度
202 */
203 maxLength?: number;
204
205 /**
206 * 是否展现最大长度样式
207 */
208 hasLimitHint?: boolean;
209 showLimitHint?: boolean;
210
211 /**
212 * 当设置了maxLength时,是否截断超出字符串
213 */
214 cutString?: boolean;
215
216 /**
217 * 只读
218 */
219 readOnly?: boolean;
220
221 /**
222 * onChange返回会自动去除头尾空字符
223 */
224 trim?: boolean;
225
226 /**
227 * 输入提示
228 */
229 placeholder?: string;
230
231 /**
232 * 获取焦点时候触发的回调
233 */
234 onFocus?: (e: React.FocusEvent<HTMLInputElement>) => void;
235
236 /**
237 * 失去焦点时候触发的回调
238 */
239 onBlur?: (e: React.FocusEvent<HTMLInputElement>) => void;
240
241 /**
242 * 自定义字符串计算长度方式
243 */
244 getValueLength?: (value: string) => number;
245
246 /**
247 * 自定义class
248 */
249 className?: string;
250
251 /**
252 * 自定义内联样式
253 */
254 style?: React.CSSProperties;
255
256 /**
257 * 原生type
258 */
259 htmlType?: string;
260
261 /**
262 * name
263 */
264 name?: string;
265
266 /**
267 * 状态
268 */
269 state?: 'error' | 'loading' | 'success' | 'warning';
270
271 /**
272 * label
273 */
274 label?: React.ReactNode;
275
276 /**
277 * 是否出现clear按钮
278 */
279 hasClear?: boolean;
280
281 /**
282 * 是否有边框
283 */
284 hasBorder?: boolean;
285
286 /**
287 * 尺寸
288 */
289 size?: 'small' | 'medium' | 'large';
290
291 /**
292 * 按下回车的回调
293 */
294 onPressEnter?: (e: React.KeyboardEvent<HTMLInputElement>) => void;
295
296 /**
297 * 水印 (Icon的type类型,和hasClear占用一个地方)
298 */
299 hint?: string | React.ReactNode;
300
301 /**
302 * 文字前附加内容
303 */
304 innerBefore?: React.ReactNode;
305
306 /**
307 * 文字后附加内容
308 */
309 innerAfter?: React.ReactNode;
310
311 /**
312 * 输入框前附加内容
313 */
314 addonBefore?: React.ReactNode;
315
316 /**
317 * 输入框后附加内容
318 */
319 addonAfter?: React.ReactNode;
320
321 /**
322 * 输入框前附加文字
323 */
324 addonTextBefore?: React.ReactNode;
325
326 /**
327 * 输入框后附加文字
328 */
329 addonTextAfter?: React.ReactNode;
330
331 /**
332 * (原生input支持)
333 */
334 autoComplete?: string;
335
336 /**
337 * 自动聚焦(原生input支持)
338 */
339 autoFocus?: boolean;
340
341 /**
342 * 是否为预览态
343 */
344 isPreview?: boolean;
345
346 renderPreview?: (value: string | number) => React.ReactNode;
347 /**
348 * hover展示clear (配合 hasClear=true使用)
349 * @version 1.24
350 */
351 hoverShowClear?: boolean;
352}
353export interface PasswordProps extends InputProps {
354 /**
355 * 是否展示切换按钮
356 */
357 showToggle?: boolean;
358}
359export class Password extends React.Component<PasswordProps, any> {}
360
361export default class Input extends React.Component<InputProps, any> {
362 static TextArea: typeof TextArea;
363 static Group: typeof Group;
364 static Password: typeof Password;
365 getInputNode: () => HTMLInputElement;
366}
367