|
| 1 | +# SelectionList components |
| 2 | + |
| 3 | +This doc explains when and how to use the `SelectionList` and `SelectionListWithSections` components in New Expensify. |
| 4 | + |
| 5 | +## Overview |
| 6 | + |
| 7 | + |
| 8 | +There are two main components: |
| 9 | + |
| 10 | +- [**`SelectionList`**](../src/components/SelectionList/BaseSelectionList.tsx) - For displaying a single array of data (no sections) |
| 11 | +- [**`SelectionListWithSections`**](../src/components/SelectionListWithSections/BaseSelectionListWithSections.tsx) - For displaying data organized into multiple sections |
| 12 | + |
| 13 | +## When to Use Each Component |
| 14 | + |
| 15 | +### Use `SelectionList` when: |
| 16 | + |
| 17 | +- Your data is a **single flat array** of items |
| 18 | +- You don't need to group items into sections with headers |
| 19 | +- You want a simpler, more performant solution for flat lists |
| 20 | +- Your data structure looks like: `[{item1}, {item2}, {item3}]` |
| 21 | + |
| 22 | + |
| 23 | +### Use `SelectionListWithSections` when: |
| 24 | + |
| 25 | +- Your data is organized into **multiple sections** with headers |
| 26 | +- You need to group related items together (e.g., "Recent", "All Contacts", "Groups") |
| 27 | +- Your data structure looks like: |
| 28 | + ```typescript |
| 29 | + [ |
| 30 | + { title: 'Section 1', data: [{item1}, {item2}] }, |
| 31 | + { title: 'Section 2', data: [{item3}, {item4}] } |
| 32 | + ] |
| 33 | + ``` |
| 34 | + |
| 35 | +## Basic Usage Examples |
| 36 | + |
| 37 | +### Example 1: Simple SelectionList |
| 38 | + |
| 39 | +```tsx |
| 40 | +<SelectionList |
| 41 | + data={options} |
| 42 | + ListItem={RadioListItem} |
| 43 | + onSelectRow={(item) => { |
| 44 | + setSelectedOption(item.keyForList); |
| 45 | + Navigation.goBack(); |
| 46 | + }} |
| 47 | + shouldShowTextInput |
| 48 | + textInputOptions={{ |
| 49 | + label: "Search items", |
| 50 | + value: searchText, |
| 51 | + onChangeText: setSearchText, |
| 52 | + headerMessage |
| 53 | + }} |
| 54 | +/> |
| 55 | +``` |
| 56 | + |
| 57 | +### Example 2: SelectionListWithSections |
| 58 | + |
| 59 | +```tsx |
| 60 | +<SelectionListWithSections |
| 61 | + sections={[ |
| 62 | + { title: 'Recent', data: recentContacts }, |
| 63 | + { title: 'All Contacts', data: allContacts }, |
| 64 | + ]} |
| 65 | + ListItem={UserListItem} |
| 66 | + onSelectRow={handleSelectContact} |
| 67 | + shouldShowTextInput |
| 68 | + textInputLabel="Search contacts" |
| 69 | +/> |
| 70 | +``` |
| 71 | + |
| 72 | +## Related Components |
| 73 | + |
| 74 | +- `SelectionScreen` - Wrapper component that includes screen layout (1 section) |
| 75 | +- `SelectionListWithModal` - Selection list with modal interaction (1 section) |
| 76 | + |
0 commit comments