-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* #77 feat: add ComponentsTest page at Home * #77 refactor: refactor dropdown component * #77 fix: set overlap order between dropdowns at same level * #77 feat: add dropdown with write option * #77 feat: replace dropdown component
- Loading branch information
1 parent
c3298cc
commit 6ac2a6e
Showing
5 changed files
with
257 additions
and
99 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,57 +1,116 @@ | ||
import { Dispatch, SetStateAction } from 'react'; | ||
import { View, TouchableOpacity, ViewStyle } from 'react-native'; | ||
import { Dispatch, SetStateAction, useState } from 'react'; | ||
import { | ||
View, | ||
TouchableOpacity, | ||
ViewStyle, | ||
StyleSheet, | ||
DimensionValue, | ||
ScrollView, | ||
} from 'react-native'; | ||
import { Body14M } from '../styles/GlobalText'; | ||
import { BLACK, BLACK2, GRAY } from '../styles/GlobalColor'; | ||
import ArrowIcon from '../assets/common/Arrow.svg'; | ||
|
||
export interface DropdownProps { | ||
items: string[]; | ||
value: string | undefined | null; | ||
interface DropdownProps { | ||
title: string; | ||
value: string | undefined; | ||
setValue: (text: string) => void; | ||
setOpen: Dispatch<SetStateAction<boolean>>; | ||
open: boolean; | ||
items: string[]; | ||
index?: number | undefined; // 동일 레벨에서 dropdown을 여러번 사용할 경우 z-index 사용 | ||
width?: DimensionValue; | ||
style?: ViewStyle; | ||
} | ||
const ITEM_HEIGHT = 40; | ||
|
||
export default function Dropdown({ | ||
items, | ||
value, | ||
setValue, | ||
setOpen, | ||
open, | ||
title, | ||
style, | ||
setValue, | ||
value, | ||
items, | ||
index = undefined, | ||
width = '90%', | ||
}: DropdownProps) { | ||
const handleSelect = (text: string) => { | ||
setValue(text); | ||
const [open, setOpen] = useState(false); | ||
|
||
const handlePress = () => { | ||
setOpen(prev => !prev); | ||
}; | ||
|
||
const handleSelect = (value: string) => { | ||
setValue(value); | ||
setOpen(false); | ||
}; | ||
|
||
return ( | ||
<View | ||
style={{ | ||
position: 'absolute', | ||
display: 'flex', | ||
flexDirection: 'column', | ||
borderBottomWidth: 0, | ||
zIndex: 1, | ||
...style, | ||
position: 'relative', | ||
height: ITEM_HEIGHT + 4, | ||
marginVertical: 8, | ||
zIndex: index, | ||
}}> | ||
{open && | ||
items.map((item, index) => { | ||
return ( | ||
<View key={index}> | ||
<TouchableOpacity | ||
onPress={() => { | ||
handleSelect(item); | ||
}} | ||
style={{ | ||
backgroundColor: 'white', | ||
paddingLeft: 16, | ||
height: 30, | ||
borderWidth: 1, | ||
}}> | ||
<Body14M>{item}</Body14M> | ||
</TouchableOpacity> | ||
</View> | ||
); | ||
})} | ||
<View | ||
style={{ | ||
width: width, | ||
...style, | ||
...Styles.container, | ||
}}> | ||
<View style={{ ...Styles.item }}> | ||
<TouchableOpacity | ||
style={{ | ||
...Styles.pressArea, | ||
}} | ||
onPress={handlePress}> | ||
<Body14M>{value !== undefined ? value : title}</Body14M> | ||
<ArrowIcon | ||
color={BLACK2} | ||
style={{ transform: [{ rotate: open ? '270deg' : '180deg' }] }} | ||
/> | ||
</TouchableOpacity> | ||
</View> | ||
<ScrollView | ||
style={{ | ||
maxHeight: open ? ITEM_HEIGHT * 3 : ITEM_HEIGHT + 4, | ||
borderTopWidth: open ? 2 : 0, | ||
borderColor: BLACK2, | ||
}}> | ||
{open && | ||
items.map((value, index) => { | ||
return ( | ||
<View style={Styles.item} key={index}> | ||
<TouchableOpacity | ||
style={Styles.pressArea} | ||
onPress={() => handleSelect(value)}> | ||
<Body14M>{value}</Body14M> | ||
</TouchableOpacity> | ||
</View> | ||
); | ||
})} | ||
</ScrollView> | ||
</View> | ||
</View> | ||
); | ||
} | ||
|
||
const Styles = StyleSheet.create({ | ||
container: { | ||
position: 'absolute', | ||
alignSelf: 'center', | ||
borderWidth: 2, | ||
borderRadius: 5, | ||
borderColor: BLACK2, | ||
backgroundColor: 'white', | ||
}, | ||
item: { | ||
height: ITEM_HEIGHT, | ||
paddingHorizontal: 16, | ||
borderColor: BLACK2, | ||
}, | ||
pressArea: { | ||
flexDirection: 'row', | ||
justifyContent: 'space-between', | ||
alignItems: 'center', | ||
flex: 1, | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
import { useState } from 'react'; | ||
import { | ||
View, | ||
TouchableOpacity, | ||
StyleSheet, | ||
ScrollView, | ||
TextInput, | ||
} from 'react-native'; | ||
import { Body14M } from '../styles/GlobalText'; | ||
import { BLACK2 } from '../styles/GlobalColor'; | ||
import Dropdown from './Dropdown'; | ||
import ArrowIcon from '../assets/common/Arrow.svg'; | ||
|
||
const ITEM_HEIGHT = 40; | ||
|
||
export default function DropdownWrite({ | ||
title, | ||
style, | ||
setValue, | ||
value, | ||
items, | ||
index = undefined, | ||
width = '90%', | ||
}: Parameters<typeof Dropdown>[0]) { | ||
const [open, setOpen] = useState(false); | ||
|
||
const handlePress = () => { | ||
setOpen(prev => !prev); | ||
}; | ||
|
||
const handleSelect = (value: string) => { | ||
setValue(value); | ||
setOpen(false); | ||
}; | ||
|
||
return ( | ||
<View | ||
style={{ | ||
width: width, | ||
position: 'relative', | ||
height: ITEM_HEIGHT + 4, | ||
marginVertical: 8, | ||
zIndex: index, | ||
}}> | ||
<View | ||
style={{ | ||
...style, | ||
...Styles.container, | ||
}}> | ||
<View style={{ ...Styles.pressArea, ...Styles.item }}> | ||
<TextInput | ||
defaultValue={value} | ||
onChangeText={setValue} | ||
placeholderTextColor={BLACK2} | ||
placeholder={title} | ||
autoCapitalize="none" | ||
autoCorrect={false} | ||
style={{ flex: 1 }} | ||
/> | ||
<TouchableOpacity onPress={handlePress}> | ||
<ArrowIcon | ||
color={BLACK2} | ||
style={{ transform: [{ rotate: open ? '270deg' : '180deg' }] }} | ||
/> | ||
</TouchableOpacity> | ||
</View> | ||
<ScrollView | ||
style={{ | ||
maxHeight: open ? ITEM_HEIGHT * 3 : ITEM_HEIGHT + 4, | ||
borderTopWidth: open ? 2 : 0, | ||
borderColor: BLACK2, | ||
}}> | ||
{open && | ||
items.map((value, index) => { | ||
return ( | ||
<View style={Styles.item} key={index}> | ||
<TouchableOpacity | ||
style={Styles.pressArea} | ||
onPress={() => handleSelect(value)}> | ||
<Body14M>{value}</Body14M> | ||
</TouchableOpacity> | ||
</View> | ||
); | ||
})} | ||
</ScrollView> | ||
</View> | ||
</View> | ||
); | ||
} | ||
|
||
const Styles = StyleSheet.create({ | ||
container: { | ||
position: 'absolute', | ||
top: 0, | ||
left: 0, | ||
width: '100%', | ||
alignSelf: 'center', | ||
borderWidth: 2, | ||
borderRadius: 5, | ||
borderColor: BLACK2, | ||
backgroundColor: 'white', | ||
}, | ||
item: { | ||
height: ITEM_HEIGHT, | ||
paddingHorizontal: 16, | ||
}, | ||
pressArea: { | ||
flexDirection: 'row', | ||
justifyContent: 'space-between', | ||
alignItems: 'center', | ||
flex: 1, | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.