|
1 | | -/** |
2 | | - * Sample React Native App |
3 | | - * https://github.com/facebook/react-native |
4 | | - * |
5 | | - * Generated with the TypeScript template |
6 | | - * https://github.com/react-native-community/react-native-template-typescript |
7 | | - * |
8 | | - * @format |
9 | | - */ |
| 1 | +/* eslint-disable react-native/no-inline-styles */ |
| 2 | +import React, { useState } from 'react' |
| 3 | +import { Text, View } from 'react-native' |
| 4 | +import { xorBy } from 'lodash' |
| 5 | +import { SelectBox } from './lib' |
| 6 | +import { ItemSelected } from './lib/src/constants/types' |
10 | 7 |
|
11 | | -import React from 'react' |
12 | | -import { SafeAreaView, ScrollView, StatusBar, StyleSheet, Text, useColorScheme, View } from 'react-native' |
| 8 | +// Options data must contain 'item' & 'id' keys |
13 | 9 |
|
14 | | -import { |
15 | | - Colors, |
16 | | - DebugInstructions, |
17 | | - Header, |
18 | | - LearnMoreLinks, |
19 | | - ReloadInstructions |
20 | | -} from 'react-native/Libraries/NewAppScreen' |
| 10 | +const K_OPTIONS: ItemSelected[] = [ |
| 11 | + { |
| 12 | + item: 'Juventus', |
| 13 | + id: 'JUVE' |
| 14 | + }, |
| 15 | + { |
| 16 | + item: 'Real Madrid', |
| 17 | + id: 'RM' |
| 18 | + }, |
| 19 | + { |
| 20 | + item: 'Barcelona', |
| 21 | + id: 'BR' |
| 22 | + }, |
| 23 | + { |
| 24 | + item: 'PSG', |
| 25 | + id: 'PSG' |
| 26 | + }, |
| 27 | + { |
| 28 | + item: 'FC Bayern Munich', |
| 29 | + id: 'FBM' |
| 30 | + }, |
| 31 | + { |
| 32 | + item: 'Manchester United FC', |
| 33 | + id: 'MUN' |
| 34 | + }, |
| 35 | + { |
| 36 | + item: 'Manchester City FC', |
| 37 | + id: 'MCI' |
| 38 | + }, |
| 39 | + { |
| 40 | + item: 'Everton FC', |
| 41 | + id: 'EVE' |
| 42 | + }, |
| 43 | + { |
| 44 | + item: 'Tottenham Hotspur FC', |
| 45 | + id: 'TOT' |
| 46 | + }, |
| 47 | + { |
| 48 | + item: 'Chelsea FC', |
| 49 | + id: 'CHE' |
| 50 | + }, |
| 51 | + { |
| 52 | + item: 'Liverpool FC', |
| 53 | + id: 'LIV' |
| 54 | + }, |
| 55 | + { |
| 56 | + item: 'Arsenal FC', |
| 57 | + id: 'ARS' |
| 58 | + }, |
21 | 59 |
|
22 | | -const Section: React.FC<{ |
23 | | - title: string |
24 | | -}> = ({ children, title }) => { |
25 | | - const isDarkMode = useColorScheme() === 'dark' |
| 60 | + { |
| 61 | + item: 'Leicester City FC', |
| 62 | + id: 'LEI' |
| 63 | + } |
| 64 | +] |
| 65 | + |
| 66 | +function App() { |
| 67 | + const [selectedTeam, setSelectedTeam] = useState<ItemSelected>({}) |
| 68 | + const [selectedTeams, setSelectedTeams] = useState<ItemSelected[]>([]) |
26 | 69 | return ( |
27 | | - <View style={styles.sectionContainer}> |
28 | | - <Text |
29 | | - style={[ |
30 | | - styles.sectionTitle, |
31 | | - { |
32 | | - color: isDarkMode ? Colors.white : Colors.black |
33 | | - } |
34 | | - ]} |
35 | | - > |
36 | | - {title} |
37 | | - </Text> |
38 | | - <Text |
39 | | - style={[ |
40 | | - styles.sectionDescription, |
41 | | - { |
42 | | - color: isDarkMode ? Colors.light : Colors.dark |
43 | | - } |
44 | | - ]} |
45 | | - > |
46 | | - {children} |
47 | | - </Text> |
| 70 | + <View style={{ margin: 30 }}> |
| 71 | + <View style={{ width: '100%', alignItems: 'center' }}> |
| 72 | + <Text style={{ fontSize: 30, paddingBottom: 20 }}>Demos</Text> |
| 73 | + </View> |
| 74 | + <Text style={{ fontSize: 20, paddingBottom: 10 }}>Select Demo</Text> |
| 75 | + <SelectBox |
| 76 | + label='Select single' |
| 77 | + options={K_OPTIONS} |
| 78 | + value={selectedTeam} |
| 79 | + onChange={onChange()} |
| 80 | + hideInputFilter={false} |
| 81 | + /> |
| 82 | + <View style={{ height: 40 }} /> |
| 83 | + <Text style={{ fontSize: 20, paddingBottom: 10 }}>MultiSelect Demo</Text> |
| 84 | + <SelectBox |
| 85 | + label='Select multiple' |
| 86 | + options={K_OPTIONS} |
| 87 | + selectedValues={selectedTeams} |
| 88 | + onMultiSelect={onMultiChange()} |
| 89 | + onTapClose={onMultiChange()} |
| 90 | + isMulti |
| 91 | + /> |
48 | 92 | </View> |
49 | 93 | ) |
50 | | -} |
51 | 94 |
|
52 | | -const App = () => { |
53 | | - const isDarkMode = useColorScheme() === 'dark' |
54 | | - |
55 | | - const backgroundStyle = { |
56 | | - backgroundColor: isDarkMode ? Colors.darker : Colors.lighter |
| 95 | + function onMultiChange() { |
| 96 | + return (item: ItemSelected) => setSelectedTeams(xorBy(selectedTeams, [item], 'id')) |
57 | 97 | } |
58 | 98 |
|
59 | | - return ( |
60 | | - <SafeAreaView style={backgroundStyle}> |
61 | | - <StatusBar barStyle={isDarkMode ? 'light-content' : 'dark-content'} /> |
62 | | - <ScrollView contentInsetAdjustmentBehavior='automatic' style={backgroundStyle}> |
63 | | - <Header /> |
64 | | - <View |
65 | | - style={{ |
66 | | - backgroundColor: isDarkMode ? Colors.black : Colors.white |
67 | | - }} |
68 | | - > |
69 | | - <Section title='Step One'> |
70 | | - Edit <Text style={styles.highlight}>App.tsx</Text> to change this screen and then come back to see your |
71 | | - edits. |
72 | | - </Section> |
73 | | - <Section title='See Your Changes'> |
74 | | - <ReloadInstructions /> |
75 | | - </Section> |
76 | | - <Section title='Debug'> |
77 | | - <DebugInstructions /> |
78 | | - </Section> |
79 | | - <Section title='Learn More'>Read the docs to discover what to do next:</Section> |
80 | | - <LearnMoreLinks /> |
81 | | - </View> |
82 | | - </ScrollView> |
83 | | - </SafeAreaView> |
84 | | - ) |
85 | | -} |
86 | | - |
87 | | -const styles = StyleSheet.create({ |
88 | | - sectionContainer: { |
89 | | - marginTop: 32, |
90 | | - paddingHorizontal: 24 |
91 | | - }, |
92 | | - sectionTitle: { |
93 | | - fontSize: 24, |
94 | | - fontWeight: '600' |
95 | | - }, |
96 | | - sectionDescription: { |
97 | | - marginTop: 8, |
98 | | - fontSize: 18, |
99 | | - fontWeight: '400' |
100 | | - }, |
101 | | - highlight: { |
102 | | - fontWeight: '700' |
| 99 | + function onChange() { |
| 100 | + return (val: ItemSelected) => setSelectedTeam(val) |
103 | 101 | } |
104 | | -}) |
| 102 | +} |
105 | 103 |
|
106 | 104 | export default App |
0 commit comments