-
Notifications
You must be signed in to change notification settings - Fork 703
/
Copy pathTextInput.tsx
42 lines (39 loc) · 1.44 KB
/
TextInput.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import { Input } from 'antd';
import React from 'react';
import { InputComponent, TSlobsInputProps, useTextInput, ValuesOf } from './inputs';
import InputWrapper from './InputWrapper';
import { InputProps } from 'antd/lib/input';
// select which features from the antd lib we are going to use
// note: to add a submit button for the text input, pass in a button to the `addonAfter` or `addonBefore` prop
export const ANT_INPUT_FEATURES = ['addonBefore', 'addonAfter', 'autoFocus', 'prefix'] as const;
export type TTextInputProps = TSlobsInputProps<
{
uncontrolled?: boolean;
onFocus?: React.FocusEventHandler<HTMLInputElement>;
onBlur?: React.FocusEventHandler<HTMLInputElement>;
onKeyDown?: React.KeyboardEventHandler<HTMLInputElement>;
onMouseDown?: React.MouseEventHandler<HTMLInputElement>;
inputRef?: React.Ref<Input>;
isPassword?: boolean;
},
string,
InputProps,
ValuesOf<typeof ANT_INPUT_FEATURES>
>;
export const TextInput = InputComponent((p: TTextInputProps) => {
const { inputAttrs, wrapperAttrs } = useTextInput('text', p, ANT_INPUT_FEATURES);
const textInputAttrs = {
...inputAttrs,
onFocus: p.onFocus,
onKeyDown: p.onKeyDown,
onMouseDown: p.onMouseDown,
ref: p.inputRef,
prefix: p.prefix,
};
return (
<InputWrapper {...wrapperAttrs}>
{p.isPassword && <Input.Password {...textInputAttrs} />}
{!p.isPassword && <Input {...textInputAttrs} />}
</InputWrapper>
);
});