#13 made Text Input and Text Area the same sizes as in Figma

This commit is contained in:
autun12 2019-05-12 19:37:12 -05:00
parent 63ac7ae18d
commit 08890b2962
No known key found for this signature in database
GPG Key ID: C184B80D045EA3C8
3 changed files with 196 additions and 71 deletions

View File

@ -3,68 +3,161 @@ import PropTypes from 'prop-types'
import { import {
ViewPropTypes, ViewPropTypes,
StyleSheet, StyleSheet,
Text, Animated,
View, View,
TouchableOpacity, TouchableOpacity,
Easing,
} from 'react-native' } from 'react-native'
import TextInput from './TextInput' import TextInput from "./TextInput";
// Theme // Theme
import theme from '../theme' import theme from '../theme'
const { colors } = theme const { colors } = theme
const SEARCH_SHRINK_WIDTH = 375 - 65;
const styles = StyleSheet.create({ const styles = StyleSheet.create({
searchContainer: { searchContainer: {
flexDirection: 'row', flexDirection: 'row',
alignItems: 'center', alignItems: 'center',
flexWrap: 'wrap', justifyContent: 'center',
},
searchInputContainer: {
backgroundColor: colors.main.lightGrey.rgb,
flex: 1,
flexDirection: 'row',
alignItems: 'center',
justifyContent: 'center', justifyContent: 'center',
borderRadius: 8, borderRadius: 8,
marginVertical: 16,
marginHorizontal: 16,
height: 36,
}, },
search: { search: {
flex: 1,
paddingLeft: 8,
backgroundColor: colors.main.lightGrey.rgb, backgroundColor: colors.main.lightGrey.rgb,
fontWeight: '400', flex: 1,
flexDirection: 'row',
alignItems: 'center',
justifyContent: 'center',
borderRadius: 8,
},
searchIcon: {
marginRight: 4,
height: 24,
width: 24,
},
cancelSearch: {
flex: 1,
position: "absolute",
marginHorizontal: 16,
textAlign: "center",
justifyContent: "center",
alignSelf: "center"
},
cancelSearchText: {
flex: 1,
backgroundColor: colors.main.white.rgb,
color: colors.main.accentBlue.rgb,
marginLeft: 16,
fontFamily: "Inter",
fontSize: 15, fontSize: 15,
lineHeight: '140%', lineHeight: '140%',
marginVertical: 10, textAlign: "center",
},
closeIcon: {
height: 16,
width: 16,
marginRight: 30
}, },
}) })
class SearchInput extends TextInput { class SearchInput extends TextInput {
constructor(props) {
super(props);
this.state = {
inputLength: new Animated.Value(410),
cancelPosition: new Animated.Value(0),
opacity: new Animated.Value(0),
searchBarFocused: false,
};
}
onFocus = () => {
Animated.parallel([
Animated.timing(this.state.inputLength, {
toValue: SEARCH_SHRINK_WIDTH,
duration: 350,
easing: Easing.quad,
}),
Animated.timing(this.state.cancelPosition, {
toValue: 16,
duration: 350
}),
Animated.timing(this.state.opacity, {
toValue: 1,
duration: 350
})
]).start();
}
onBlur = () => {
Animated.parallel([
Animated.timing(this.state.inputLength, {
toValue: 410,
duration: 350,
easing: Easing.quad
}),
Animated.timing(this.state.cancelPosition, {
toValue: 0,
duration: 350
}),
Animated.timing(this.state.opacity, {
toValue: 0,
duration: 350
})
]).start();
};
render() { render() {
const { text } = this.props const { text, } = this.props
return ( return (
<View> <View style={[styles.searchContainer, ]}>
<View style={[styles.searchContainer]}> <Animated.Image source={require('../../public/icons/main/search.svg')}style={[styles.searchIcon]}/>
<img src="/icons/main/search.svg" /> <View styles={[styles.searchInputContainer]}>
<TouchableOpacity <Animated.View style={[{width: this.state.inputLength,}]}>
activeOpacity={0.6}
onPress={() => console.log('Pressed')}
>
<TextInput <TextInput
style={[styles.search]} style={[styles.search]}
{...this.props} {...this.props}
placeholderTextColor={'gray'} placeholderTextColor={'gray'}
autoCapitalize={'none'} autoCapitalize={'none'}
onFocus={this.onFocus}
onBlur={this.onBlur}
value={text} value={text}
labelishidden={true}
/> />
</TouchableOpacity> </Animated.View>
</View> </View>
<View style={[styles.closeIcon,{width: 16, height: 16}]}>
<Animated.Image source={require('../../public/icons/main/close.svg')}style={[styles.closeIcon, {opacity: this.state.opacity}]}/>
</View>
<TouchableOpacity styles={[styles.cancelSearch, { marginLeft: 16, right: this.state.cancelPosition}]}>
<Animated.Text style={[styles.cancelSearchText, {opacity: this.state.opacity}]}>
Cancel
</Animated.Text>
</TouchableOpacity>
</View> </View>
) )
} }
} }
SearchInput.propTypes = { SearchInput.propTypes = {
text: PropTypes.string, text: PropTypes.string
} }
export default SearchInput export default SearchInput

View File

@ -17,35 +17,49 @@ const { colors } = theme
const styles = StyleSheet.create({ const styles = StyleSheet.create({
label: { label: {
fontSize: 14, position: 'relative',
alignItems: 'center',
display: 'flex',
fontFamily: 'Inter UI', fontFamily: 'Inter UI',
paddingBottom: 8, fontSize: 15,
fontStyle: 'normal',
fontWeight: 'normal',
width: 343,
top: 12,
height: 26,
}, },
inputContainer: { inputContainer: {
paddingTop: 8, flex: 1,
padding: 16,
justifyContent: 'center', justifyContent: 'center',
alignItems: 'center',
},
inputTouch: {
alignItems: 'center',
flexDirection: 'column',
backgroundColor: colors.main.white.rgb, backgroundColor: colors.main.white.rgb,
marginVertical: 16,
marginHorizontal: 16,
borderRadius: 8,
}, },
input: { input: {
padding: 0, position: 'relative',
backgroundColor: colors.main.lightGrey.rgb, backgroundColor: colors.main.lightGrey.rgb,
borderRadius: 8,
marginHorizontal: 16,
marginVertical: 16,
minHeight: 52, minHeight: 52,
overflowY: 'auto', overflowY: 'auto',
width: 343, width: 343,
height: 52,
}, },
// error: { // error: {
// color: colors.main.red.rgb, // color: colors.main.red.rgb,
// }, // },
text: { text: {
fontWeight: 'normal',
fontStyle: 'normal',
fontSize: 15,
fontFamily: 'Inter UI', fontFamily: 'Inter UI',
fontSize: 15,
fontStyle: 'normal',
fontWeight: 'normal',
lineHeight: 22, lineHeight: 22,
padding: 16,
}, },
}) })
@ -58,51 +72,76 @@ class TextInput extends React.Component {
} }
render() { render() {
const { label, error, text, multiLine, autoFocus } = this.props const { container, autoFocus, error, labeltext, labelishidden, text, textarea } = this.props
return ( function renderLabel() {
<View> if(labelishidden == true) {
<View style={[styles.inputContainer]}> return null;
<Text style={[styles.label, error && styles.error]}> } else {
{label} return <Text style={[styles.label, error && styles.error]}>{labeltext}</Text>
</Text> }
}
if(textarea == true) {
return (
<View style={[container && styles.inputContainer]}>
<TouchableOpacity <TouchableOpacity
activeOpacity={0.6} activeOpacity={0.6}
onPress={() => console.log('Pressed')} style={[styles.inputTouch]}>
> <View>{renderLabel()}</View>
<TextInputComponent <TextInputComponent
{...this.props} {...this.props}
onContentSizeChange={(event) => { onContentSizeChange={(event) => {
if(this.state.height <= 160) { if(this.state.height <= 202) {
this.setState({height: event.nativeEvent.contentSize.height}) this.setState({height: event.nativeEvent.contentSize.height})
} }
}} }}
placeholderTextColor={'gray'}
multiline={multiLine}
style={[styles.input, styles.text, {minHeight: Math.max(52, this.state.height)}]}
autoFocus={autoFocus}
autoCapitalize={'none'} autoCapitalize={'none'}
autoFocus={autoFocus}
multiline={true}
placeholderTextColor={'gray'}
style={[styles.input, styles.text, {minHeight: Math.max(95, this.state.height)}]}
value={text} value={text}
/> />
</TouchableOpacity> </TouchableOpacity>
</View> </View>
</View>
) )
} else {
return (
<View style={[container && styles.inputContainer]}>
<TouchableOpacity
activeOpacity={0.6}
style={[styles.inputTouch]}>
<View>{renderLabel()}</View>
<TextInputComponent
{...this.props}
autoCapitalize={'none'}
autoFocus={autoFocus}
multiline={false}
placeholderTextColor={'gray'}
style={[styles.input, styles.text, {minHeight: 32}]}
value={text}
/>
</TouchableOpacity>
</View>
)
}
} }
} }
TextInput.propTypes = { TextInput.propTypes = {
label: PropTypes.string,
error: PropTypes.bool,
text: PropTypes.string,
maxNumOfLines: PropTypes.number,
multiLine: PropTypes.bool,
autoFocus: PropTypes.bool, autoFocus: PropTypes.bool,
error: PropTypes.bool,
labeltext: PropTypes.string,
labelishidden: PropTypes.bool,
maxNumOfLines: PropTypes.number,
text: PropTypes.string,
} }
TextInput.defaultTypes = { TextInput.defaultTypes = {
multiLine: false, autoFocus: false,
autoFocus: true, labelishidden: false,
} }
export default TextInput export default TextInput

View File

@ -7,7 +7,7 @@ import 'typeface-roboto'
// Components // Components
import Button from '../components/Button' import Button from '../components/Button'
import TextInput from '../components/TextInput' import TextInput from "../components/TextInput"
import SearchInput from '../components/SearchInput' import SearchInput from '../components/SearchInput'
// Style Guide // Style Guide
@ -37,30 +37,23 @@ storiesOf('Theming', module)
storiesOf('TextInput', module) storiesOf('TextInput', module)
.add('Text Input', () => ( .add('Text Input', () => (
<View style={{ flexDirection: 'row', justifyContent: 'flex-start' }}> <View style={{ flexDirection: 'row', justifyContent: 'flex-start' }}>
<TextInput placeholder={'Placeholder'} /> <TextInput placeholder={'Placeholder'}
<TextInput text={'Content'} /> labeltext={'Input label'}
<TextInput labelishidden={false}/>
label="Input label"
text={'Lorem ipsum dolor sit amet, consectetur do'}
/>
</View> </View>
)) ))
.add('Text Area', () => ( .add('Text Area', () => (
<View style={{ flexDirection: 'row', justifyContent: 'flex-start' }}> <View style={{ flexDirection: 'row', justifyContent: 'flex-start' }}>
<TextInput placeholder={'Placeholder'} <TextInput placeholder={'Placeholder'}
multiLine={true}
autoFocus={false}/>
<TextInput
label="Textarea label"
multiLine={true}
autoFocus={false} autoFocus={false}
placeholder={'Placeholder'} labeltext={'Textarea label'}
labelishidden={false}
textarea={true}
/> />
</View> </View>
)) ))
.add('Search Input', () => ( .add('Search Input', () => (
<View style={{ flexDirection: 'row', justifyContent: 'flex-start' }}> <View style={{ flexDirection: 'row', justifyContent: 'flex-start' }}>
<SearchInput placeholder={'Search placeholder...'} autoFocus={true} />
<SearchInput placeholder={'Search placeholder...'} /> <SearchInput placeholder={'Search placeholder...'} />
</View> </View>
)) ))