|
1 | 1 | import * as React from 'react';
|
2 |
| -import { Text, TextStyle } from 'react-native'; |
| 2 | +import { StyleProp, Text, TextInput, TextStyle } from 'react-native'; |
3 | 3 |
|
4 | 4 | import { GLOBAL } from '../styles/global';
|
| 5 | +import { TYPOGRAPHY } from '../styles/typography'; |
5 | 6 |
|
6 |
| -export interface Props { |
7 |
| - style: TextStyle; |
| 7 | +export interface TextProps { |
| 8 | + children: React.ReactElement | string; |
| 9 | + style?: StyleProp<TextStyle>; |
8 | 10 | }
|
9 | 11 |
|
10 |
| -interface State {} |
| 12 | +export interface TextInputProps { |
| 13 | + style?: Object; |
| 14 | + disabled?: boolean; |
| 15 | + textInputRef?: any; |
| 16 | + placeholderTextColor?: string; |
| 17 | +} |
11 | 18 |
|
12 |
| -class CText extends React.PureComponent<Props, State> { |
13 |
| - static defaultProps = { |
14 |
| - style: GLOBAL.TEXT.Default, |
15 |
| - }; |
| 19 | +const CTEXT: React.FC<TextProps> = (props: TextProps) => ( |
| 20 | + <Text style={[GLOBAL.TEXT.Default, props.style]}> |
| 21 | + {props.children} |
| 22 | + </Text> |
| 23 | +); |
16 | 24 |
|
17 |
| - render() { |
18 |
| - const { style, children } = this.props; |
| 25 | +const CTEXTINPUT: React.FC<TextInputProps> = (props: TextInputProps) => { |
| 26 | + const { |
| 27 | + style, |
| 28 | + placeholderTextColor = TYPOGRAPHY.COLOR.Secondary, |
| 29 | + textInputRef, |
| 30 | + disabled = false, |
| 31 | + } = props; |
| 32 | + const [data, setData] = React.useState(''); |
19 | 33 |
|
20 |
| - return ( |
21 |
| - <Text {...this.props} style={[GLOBAL.TEXT.Default, style]}> |
22 |
| - {children} |
23 |
| - </Text> |
24 |
| - ); |
25 |
| - } |
26 |
| -} |
| 34 | + return ( |
| 35 | + <TextInput |
| 36 | + ref={textInputRef} |
| 37 | + value={data} |
| 38 | + editable={!disabled} |
| 39 | + onChange={e => setData(e.nativeEvent.text)} |
| 40 | + placeholderTextColor={placeholderTextColor} |
| 41 | + underlineColorAndroid={'transparent'} |
| 42 | + {...props} |
| 43 | + style={[GLOBAL.TEXT_INPUT.Style.Default, style]} |
| 44 | + autoCorrect={false} |
| 45 | + /> |
| 46 | + ); |
| 47 | +}; |
27 | 48 |
|
28 |
| -export { CText }; |
| 49 | +export { CTEXT, CTEXTINPUT }; |
0 commit comments