@@ -6,9 +6,28 @@ type ExampleProps = {
66 multiple ?: boolean ;
77 title : string ;
88 description ?: string ;
9+ placeholder ?: string ;
10+ multipleText ?: string ;
11+ // For the sake of keeping the examples simple for now
12+ items ?: ItemType < string > [ ] ;
913 dropdownProps ?: Partial < DropDownPickerProps < string > > ;
1014} ;
1115
16+ const DEFAULT_ITEMS = [
17+ { label : 'Apple' , value : 'apple' } ,
18+ { label : 'Banana' , value : 'banana' } ,
19+ { label : 'Nectarines' , value : 'nectarines' } ,
20+ { label : 'Kiwis' , value : 'kiwis' } ,
21+ { label : 'Raspberries' , value : 'raspberries' } ,
22+ { label : 'Pears' , value : 'pears' } ,
23+ { label : 'Guava' , value : 'guava' } ,
24+ { label : 'Grapes' , value : 'grapes' } ,
25+ { label : 'Manderins' , value : 'manderins' } ,
26+ { label : 'Pineapple' , value : 'pineapple' } ,
27+ { label : 'Dragon Fruit' , value : 'dragon_fruit' } ,
28+ { label : 'Prickly Pear' , value : 'prickly_pear' } ,
29+ ] ;
30+
1231const styles = StyleSheet . create ( {
1332 title : {
1433 fontSize : 24 ,
@@ -21,7 +40,11 @@ const styles = StyleSheet.create({
2140 exampleContainer : {
2241 display : 'flex' ,
2342 flexDirection : 'column' ,
24- gap : 16
43+ position : 'relative' ,
44+ gap : 16 ,
45+ } ,
46+ dropdownContainer : {
47+ zIndex : 1
2548 }
2649} ) ;
2750
@@ -35,6 +58,9 @@ export default function DropDownPickerExample({
3558 title,
3659 description,
3760 dropdownProps,
61+ placeholder = 'Choose a fruit' ,
62+ multipleText= 'You have chosen {count} fruits.' ,
63+ items = DEFAULT_ITEMS ,
3864} : ExampleProps ) : JSX . Element {
3965 const [ open , setOpen ] = useState < boolean > ( false ) ;
4066 const [ singleValue , setSingleValue ] = useState < string | null > ( null ) ;
@@ -43,55 +69,48 @@ export default function DropDownPickerExample({
4369 const color = colorScheme === 'dark' ? '#fff' : '#222' ;
4470 const theme = colorScheme === 'dark' ? 'DARK' : 'LIGHT' ;
4571
46- const [ items , setItems ] = useState < Array < ItemType < string > > > ( [
47- { label : 'Apple' , value : 'apple' } ,
48- { label : 'Banana' , value : 'banana' } ,
49- { label : 'Nectarines' , value : 'nectarines' } ,
50- { label : 'Kiwis' , value : 'kiwis' } ,
51- { label : 'Raspberries' , value : 'raspberries' } ,
52- { label : 'Pears' , value : 'pears' } ,
53- ] ) ;
54-
72+ const [ _items , setItems ] = useState < Array < ItemType < string > > > ( items ) ;
73+
5574 return (
56- < View style = { styles . exampleContainer } >
75+ < View style = { {
76+ ...styles . exampleContainer ,
77+ zIndex : open ? 10 : 1
78+ } } >
5779 < View >
5880 < Text style = { { ...styles . title , color} } > { title } </ Text >
5981 { description && (
6082 < Text style = { { ...styles . description , color} } > { description } </ Text >
6183 ) }
6284 </ View >
6385
64- < View >
65- { multiple ? (
66- < DropDownPicker
67- open = { open }
68- value = { multiValue }
69- items = { items }
70- setOpen = { setOpen }
71- setValue = { setMultiValue }
72- setItems = { setItems }
73- theme = { theme }
74- placeholder = 'Choose a fruit'
75- multiple
76- multipleText = 'You have chosen {count} fruits.'
77- { ...dropdownProps }
78- />
79- ) : (
80- < DropDownPicker
81- open = { open }
82- value = { singleValue }
83- items = { items }
84- setOpen = { setOpen }
85- setValue = { setSingleValue }
86- setItems = { setItems }
87- theme = { theme }
88- placeholder = 'Choose a fruit'
89- multiple = { false }
90- { ...dropdownProps }
91- />
92- ) }
93- </ View >
94-
86+ { multiple ? (
87+ < DropDownPicker
88+ open = { open }
89+ value = { multiValue }
90+ items = { _items }
91+ setOpen = { setOpen }
92+ setValue = { setMultiValue }
93+ setItems = { setItems }
94+ theme = { theme }
95+ placeholder = { placeholder }
96+ multipleText = { multipleText }
97+ multiple
98+ { ...dropdownProps }
99+ />
100+ ) : (
101+ < DropDownPicker
102+ open = { open }
103+ value = { singleValue }
104+ items = { _items }
105+ setOpen = { setOpen }
106+ setValue = { setSingleValue }
107+ setItems = { setItems }
108+ theme = { theme }
109+ placeholder = { placeholder }
110+ multiple = { false }
111+ { ...dropdownProps }
112+ />
113+ ) }
95114 < View >
96115 < Text style = { { ...styles . description , color} } >
97116 { multiple ? 'Fruits currently are: ' : 'Fruit currently is: ' }
0 commit comments