Skip to content

Commit 4fe61bd

Browse files
feat: apply theme for TextInput (#121)
1 parent be07f4e commit 4fe61bd

File tree

4 files changed

+24
-5
lines changed

4 files changed

+24
-5
lines changed

src/components/TextInput/TextInput.tsx

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,13 @@ import type {
66
TextStyle,
77
ViewStyle,
88
} from 'react-native'
9-
import {TextInput as RNTextInput, View} from 'react-native'
9+
import {TextInput as RNTextInput, StyleSheet, View} from 'react-native'
1010
import styled from 'styled-components/native'
1111
import TextInputOutlined from './TextInputOutlined'
1212
import {CustomIcon, CustomIconProps, Error} from './components'
1313
import {isIOS} from '../../helpers'
1414
import TextInputFlat from './TextInputFlat'
15+
import {useTheme} from '../../hooks'
1516

1617
export interface TextInputProps extends RNTextInputProperties {
1718
/** Style for container */
@@ -96,6 +97,7 @@ export const TextInput = forwardRef<TextInputRef, TextInputProps>(
9697
},
9798
ref,
9899
) => {
100+
const TextInputTheme = useTheme().components.TextInput
99101
const inputRef = useRef<RNTextInput>(null)
100102

101103
useImperativeHandle(ref, () => ({
@@ -109,23 +111,29 @@ export const TextInput = forwardRef<TextInputRef, TextInputProps>(
109111
}, [])
110112

111113
return (
112-
<View style={containerStyle}>
114+
<View style={[StyleSheet.flatten(TextInputTheme.containerStyle), StyleSheet.flatten(containerStyle)]}>
113115
{!!label && (
114-
<Title testID="test-title" style={labelStyle} {...labelProps}>
116+
<Title
117+
testID="test-title"
118+
style={[StyleSheet.flatten(TextInputTheme.labelStyle), StyleSheet.flatten(labelStyle)]}
119+
{...labelProps}>
115120
{label}
116121
{!!isRequire && <StarText testID="test-startText"> *</StarText>}
117122
</Title>
118123
)}
119124
<TouchableContainer
120-
style={inputContainerStyle}
125+
style={[
126+
StyleSheet.flatten(TextInputTheme.inputContainerStyle),
127+
StyleSheet.flatten(inputContainerStyle),
128+
]}
121129
activeOpacity={1}
122130
onPress={handleFocus}
123131
disabled={editable}>
124132
{!!leftComponent && leftComponent}
125133
<TextInputComponent
126134
testID="test-TextInputComponent"
127135
ref={inputRef}
128-
style={inputStyle}
136+
style={[StyleSheet.flatten(TextInputTheme.inputStyle), StyleSheet.flatten(inputStyle)]}
129137
editable={editable}
130138
multiline={multiline}
131139
numberOfLines={numberOfLines}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import type {TextInputProps} from '../../../components/TextInput/TextInput'
2+
3+
export type TextInputThemeProps = Pick<
4+
TextInputProps,
5+
'containerStyle' | 'inputContainerStyle' | 'inputStyle' | 'labelStyle'
6+
>
7+
8+
export const TextInputTheme: TextInputThemeProps = {}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from './TextInput'

src/theme/components/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,15 @@ import {
77
} from './Button'
88
import {CheckboxTheme} from './Checkbox'
99
import {TextTheme} from './Text'
10+
import {TextInputTheme} from './TextInput'
1011

1112
export default {
1213
Button: ButtonTheme,
1314
ButtonOutline: ButtonOutlineTheme,
1415
ButtonPrimary: ButtonPrimaryTheme,
1516
ButtonSecondary: ButtonSecondaryTheme,
1617
ButtonTransparent: ButtonTransparentTheme,
18+
TextInput: TextInputTheme,
1719
Checkbox: CheckboxTheme,
1820
Text: TextTheme,
1921
}

0 commit comments

Comments
 (0)