-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathFloatingLabelDemo.tsx
More file actions
76 lines (71 loc) · 1.87 KB
/
Copy pathFloatingLabelDemo.tsx
File metadata and controls
76 lines (71 loc) · 1.87 KB
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
import { useState } from 'react';
import { View, TextInput, StyleSheet } from 'react-native';
import { EaseText } from 'react-native-ease';
import { Section } from '../components/Section';
function FloatingInput({ label }: { label: string }) {
const [focused, setFocused] = useState(false);
const [value, setValue] = useState('');
const compact = focused || value.length > 0;
return (
<View style={styles.inputContainer}>
<View style={styles.labelWrapper}>
<EaseText
interpolateColor={compact ? '#e94560' : '#8892b0'}
animate={{
translateY: compact ? -24 : 0,
scale: compact ? 0.75 : 1,
}}
transition={{
color: { type: 'timing', duration: 150 },
transform: { type: 'spring', damping: 12, stiffness: 250 },
}}
transformOrigin={{ x: 0, y: 0.5 }}
style={styles.floatingLabel}
>
{label}
</EaseText>
</View>
<TextInput
style={styles.textInput}
value={value}
onChangeText={setValue}
onFocus={() => setFocused(true)}
onBlur={() => setFocused(false)}
placeholderTextColor="transparent"
/>
</View>
);
}
export function FloatingLabelDemo() {
return (
<Section title="Floating Label Input">
<FloatingInput label="Email" />
<FloatingInput label="Password" />
<FloatingInput label="Full Name" />
</Section>
);
}
const styles = StyleSheet.create({
inputContainer: {
position: 'relative',
marginBottom: 20,
borderBottomWidth: 1,
borderBottomColor: '#2a2a4a',
paddingTop: 22,
},
labelWrapper: {
position: 'absolute',
left: 0,
top: 22,
},
floatingLabel: {
fontSize: 15,
fontWeight: '400',
},
textInput: {
fontSize: 15,
color: '#fff',
paddingVertical: 8,
paddingHorizontal: 0,
},
});