Rework profile header
This commit is contained in:
parent
cb310ab1c1
commit
2ec09ba545
7 changed files with 224 additions and 40 deletions
73
src/view/com/util/Selector.tsx
Normal file
73
src/view/com/util/Selector.tsx
Normal file
|
@ -0,0 +1,73 @@
|
|||
import React, {useState} from 'react'
|
||||
import {
|
||||
StyleProp,
|
||||
StyleSheet,
|
||||
Text,
|
||||
TouchableWithoutFeedback,
|
||||
View,
|
||||
ViewStyle,
|
||||
} from 'react-native'
|
||||
import {colors} from '../../lib/styles'
|
||||
|
||||
export interface SelectorItem {
|
||||
label: string
|
||||
}
|
||||
|
||||
export function Selector({
|
||||
style,
|
||||
items,
|
||||
onSelect,
|
||||
}: {
|
||||
style?: StyleProp<ViewStyle>
|
||||
items: SelectorItem[]
|
||||
onSelect?: (index: number) => void
|
||||
}) {
|
||||
const [selectedIndex, setSelectedIndex] = useState<number>(0)
|
||||
const onPressItem = (index: number) => {
|
||||
setSelectedIndex(index)
|
||||
onSelect?.(index)
|
||||
}
|
||||
|
||||
return (
|
||||
<View style={[styles.outer, style]}>
|
||||
{items.map((item, i) => {
|
||||
const selected = i === selectedIndex
|
||||
return (
|
||||
<TouchableWithoutFeedback key={i} onPress={() => onPressItem(i)}>
|
||||
<View style={selected ? styles.itemSelected : styles.item}>
|
||||
<Text style={selected ? styles.labelSelected : styles.label}>
|
||||
{item.label}
|
||||
</Text>
|
||||
</View>
|
||||
</TouchableWithoutFeedback>
|
||||
)
|
||||
})}
|
||||
</View>
|
||||
)
|
||||
}
|
||||
|
||||
const styles = StyleSheet.create({
|
||||
outer: {
|
||||
flexDirection: 'row',
|
||||
paddingHorizontal: 14,
|
||||
},
|
||||
item: {
|
||||
paddingBottom: 12,
|
||||
marginRight: 20,
|
||||
},
|
||||
label: {
|
||||
fontWeight: '600',
|
||||
fontSize: 16,
|
||||
color: colors.gray5,
|
||||
},
|
||||
itemSelected: {
|
||||
paddingBottom: 8,
|
||||
marginRight: 20,
|
||||
borderBottomWidth: 4,
|
||||
borderBottomColor: colors.purple3,
|
||||
},
|
||||
labelSelected: {
|
||||
fontWeight: '600',
|
||||
fontSize: 16,
|
||||
},
|
||||
})
|
Loading…
Add table
Add a link
Reference in a new issue