# react-native-bpk-component-section-list

> Backpack React Native section list component.

Latest version **6.0.1** (published 2020-02-26) · Apache-2.0 license · 0 weekly downloads

## Install

```sh
npm install react-native-bpk-component-section-list
pnpm add react-native-bpk-component-section-list
yarn add react-native-bpk-component-section-list
bun add react-native-bpk-component-section-list
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned.

## Facts

| | |
|---|---|
| Version | 6.0.1 |
| Published | 2020-02-26 |
| First published | 2018-05-01 |
| Weekly downloads | 0 |
| License | Apache-2.0 |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 8 |
| Unpacked size | 34.1 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 543 |
| Author | Backpack Design System |
| Maintainers | georgegillams, k0nserv, ojcurt, shaundon, tiagohngl |

## Links

- npm: https://www.npmjs.com/package/react-native-bpk-component-section-list
- Repository: https://github.com/Skyscanner/backpack
- Homepage: https://github.com/Skyscanner/backpack#readme
- Issues: https://github.com/Skyscanner/backpack/issues
- npm.io page: https://npm.io/package/react-native-bpk-component-section-list

## Dependencies (8)

- [bpk-tokens](https://npm.io/package/bpk-tokens.md) ^32.0.0
- [prop-types](https://npm.io/package/prop-types.md) ^15.5.8
- [react-native-bpk-theming](https://npm.io/package/react-native-bpk-theming.md) ^2.0.1
- [react-native-bpk-component-icon](https://npm.io/package/react-native-bpk-component-icon.md) ^3.0.1
- [react-native-bpk-component-text](https://npm.io/package/react-native-bpk-component-text.md) ^5.0.1
- [react-native-bpk-component-flat-list](https://npm.io/package/react-native-bpk-component-flat-list.md) ^6.0.1
- [react-native-bpk-component-touchable-overlay](https://npm.io/package/react-native-bpk-component-touchable-overlay.md) ^3.0.1
- [react-native-bpk-component-touchable-native-feedback](https://npm.io/package/react-native-bpk-component-touchable-native-feedback.md) ^3.0.1

## Recent versions

- 6.0.1 (latest) — 2020-02-26
- 5.1.2-alpha.1 (canary) — 2019-12-03
- 6.0.0 — 2020-02-19
- 5.3.4 — 2020-02-13
- 5.3.3 — 2020-01-30
- 5.3.2 — 2020-01-22
- 5.3.1 — 2020-01-20
- 5.3.0 — 2019-12-20
- 5.2.3 — 2019-12-17
- 5.2.2 — 2019-12-12
- 5.2.1 — 2019-12-06
- 5.2.0 — 2019-12-05
- 5.1.3 — 2019-12-04
- 5.1.2 — 2019-12-04
- 5.1.1 — 2019-11-29
- … 89 more at https://npm.io/package/react-native-bpk-component-section-list/versions

## README

# react-native-bpk-component-section-list

> Backpack React Native section list component.

## Installation

```sh
npm install react-native-bpk-component-section-list --save-dev
```

## Usage

```js
import React, { Component } from 'react';
import { Image } from 'react-native';
import BpkSectionList, {
  BpkSectionListHeader,
  BpkSectionListItem,
  BpkSectionListItemSeparator,
  BpkSectionListSearchField,
  BpkSectionListNoResultsText,
} from 'react-native-bpk-component-section-list';

const AIRPORTS = [
  {
    title: 'Beijing',
    country: 'CN',
    data: [{ id: 'PEK', name: 'Capital' }, { id: 'NAY', name: 'Nanyuan' }],
  },
  {
    title: 'Glasgow',
    country: 'UK',
    data: [
      {
        id: 'GLA',
        name: 'Glasgow International',
      },
      { id: 'PIK', name: 'Prestwick' },
    ],
  },
  {
    title: 'Paris',
    country: 'FR',
    data: [
      { id: 'BVA', name: 'Beauvais' },
      { id: 'CDG', name: 'Charles de Gaulle' },
      { id: 'ORY', name: 'Orly' },
    ],
  },
  {
    title: 'New York City',
    country: 'US',
    data: [
      { id: 'JFK', name: 'John F. Kennedy' },
      { id: 'LGA', name: 'LaGuardia' },
      { id: 'EWR', name: 'Newark' },
    ],
  },
];

const FLAG_IMAGES = {
  'US': '/resources/usa.png',
  'FR': '/resources/france.png',
  'CN': '/resources/china.png',
  'UK': '/resources/uk.png',
};

export default class App extends Component {
  constructor() {
    super();
    this.itemOnPressCallbacks = {};
  }

  getItemOnPressCallback = airportId => {
    this.itemOnPressCallbacks[airportId] =
      this.itemOnPressCallbacks[airportId] ||
      (() => console.log(airportId));
    return this.itemOnPressCallbacks[airportId];
  };

  renderItem = ({ airport, section }) => (
    <BpkSectionListItem
      key={airport.id}
      title={airport.name}
      image={<Image source={require(FLAG_IMAGES[section.country])} />}
      onPress={this.getItemOnPressCallback(airportId)}
      titleProps={{ numberOfLines: 1 }}
    />
  );

    filterItems = text => {
      // Logic to filter the data based on user input.
    }

  render() {
    return (
      <BpkSectionList
        sections={AIRPORTS}
        renderItem={this.renderItem}
        renderSectionHeader={(section) => (
          <BpkSectionListHeader title={section.title} />
        )}
        ItemSeparatorComponent={BpkSectionListItemSeparator}
        ListHeaderComponent={
          <BpkSectionListSearchField
            placeholder="Search airports"
            onChangeText={this.filterItems}
          />
        }
        ListEmptyComponent={
          <BpkSectionListNoResultsText>No results</BpkFlatListNoResultsText>
        }
      />
    );
  }
}
```

## Props

### BpkSectionList

Inherits all props from React Native's [SectionList](https://facebook.github.io/react-native/docs/sectionlist.html) component.

### BpkSectionListItem

| Property           | PropType                              | Required | Default Value |
| ------------------ | ------------------------------------- | -------- | ------------- |
| onPress            | func                                  | true     | -             |
| title              | string                                | true     | -             |
| image              | instanceOf(Image)                     | false    | null          |
| selected           | bool                                  | false    | false         |
| titleProps         | object                                | false    | {}            |

#### `titleProps`

`titleProps` is passed down to the `BpkText` used for the title. It accepts anything that React Native's [`Text` component](https://facebook.github.io/react-native/docs/text.html#props) does.

### BpkSectionListHeader

| Property           | PropType                              | Required | Default Value |
| ------------------ | ------------------------------------- | -------- | ------------- |
| title              | string                                | true     | -             |

### BpkSectionListItemSeparator

Use this as the value for [`ItemSeparatorComponent`](https://facebook.github.io/react-native/docs/sectionlist#itemseparatorcomponent).

No props.

### BpkSectionListSearchField

This can be used as the value for [`ListHeaderComponent`](https://facebook.github.io/react-native/docs/sectionlist#listheadercomponent) to allow users to search the list.

It's an instance of React Native's [`TextInput`](https://facebook.github.io/react-native/docs/textinput) component and accepts the same props.

### BpkSectionListNoResultsText

Use this as the value for [`ListEmptyComponent`](https://facebook.github.io/react-native/docs/sectionlist#listemptycomponent). It's generally only needed when the list can be searched.

| Property           | PropType                              | Required | Default Value |
| ------------------ | ------------------------------------- | -------- | ------------- |
| children           | Node                                  | true     | -             |

## Theme Props

Same as [flat list](/components/native/flat-list?platform=native#theme-props).

---
_Source: https://npm.io/package/react-native-bpk-component-section-list · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
