Skip to main content

List

The List component is used to display a collection of items in a vertical arrangement. It supports various customization options including icons, subtitles, and selection states.

Import

import { List } from '@lazy-panda-ui/lazy-panda-ui';

Usage

Basic List

import { List } from '@lazy-panda-ui/lazy-panda-ui';

function Example() {
const items = [
{ label: 'Item 1' },
{ label: 'Item 2' },
{ label: 'Item 3' },
];

return <List items={items} />;
}

Interactive List

import { List } from '@lazy-panda-ui/lazy-panda-ui';

function Example() {
const items = [
{
label: 'Settings',
onPress: () => console.log('Settings pressed'),
},
{
label: 'Profile',
onPress: () => console.log('Profile pressed'),
},
{
label: 'Logout',
onPress: () => console.log('Logout pressed'),
},
];

return <List items={items} />;
}

With Icons and Subtitles

import { List } from '@lazy-panda-ui/lazy-panda-ui';

function Example() {
const items = [
{
label: 'Photos',
subtitle: '235 items',
startIcon: <Icon name="photo" />,
endIcon: <Icon name="chevron-right" />,
onPress: () => console.log('Photos pressed'),
},
{
label: 'Music',
subtitle: '48 songs',
startIcon: <Icon name="music" />,
endIcon: <Icon name="chevron-right" />,
onPress: () => console.log('Music pressed'),
},
];

return <List items={items} />;
}

Different Variants

import { List } from '@lazy-panda-ui/lazy-panda-ui';

function Example() {
const items = [
{ label: 'Item 1' },
{ label: 'Item 2' },
{ label: 'Item 3' },
];

return (
<>
<List
items={items}
variant="default"
/>

<List
items={items}
variant="outlined"
/>

<List
items={items}
variant="contained"
/>
</>
);
}

With Selection State

import { List } from '@lazy-panda-ui/lazy-panda-ui';

function Example() {
const items = [
{
label: 'Option 1',
selected: true,
onPress: () => console.log('Option 1 selected'),
},
{
label: 'Option 2',
selected: false,
onPress: () => console.log('Option 2 selected'),
},
];

return <List items={items} />;
}

With Custom Components

import { List } from '@lazy-panda-ui/lazy-panda-ui';

function Example() {
return (
<List
items={[/* ... */]}
ListHeaderComponent={<Text>Header</Text>}
ListEmptyComponent={<Text>No items</Text>}
ListFooterComponent={<Text>Footer</Text>}
/>
);
}

Props

Main Props

PropTypeDefaultDescription
itemsListItem[]RequiredArray of items to display
variant'default' | 'outlined' | 'contained''default'Visual variant of the list
showDividersbooleantrueWhether to show dividers between items

Style Props

PropTypeDescription
containerStyleViewStyleAdditional styles for the container
itemStyleViewStyleAdditional styles for list items
labelStyleTextStyleAdditional styles for item labels
subtitleStyleTextStyleAdditional styles for item subtitles

Custom Components

PropTypeDescription
ListEmptyComponentReact.ReactNodeComponent to show when list is empty
ListHeaderComponentReact.ReactNodeHeader component
ListFooterComponentReact.ReactNodeFooter component

Accessibility Props

PropTypeDescription
accessibilityLabelstringAccessibility label
testIDstringTest ID for testing

ListItem Props

PropTypeDescription
labelstringText label for the item
subtitlestringOptional secondary text
onPress() => voidCalled when item is pressed
startIconReact.ReactNodeIcon to show at start
endIconReact.ReactNodeIcon to show at end
disabledbooleanWhether item is disabled
selectedbooleanWhether item is selected

Theme Customization

You can customize the List component through the theme:

const theme = {
components: {
list: {
container: {
// container styles
},
item: {
// item styles
},
selectedItem: {
// selected item styles
},
disabledItem: {
// disabled item styles
},
iconContainer: {
// icon container styles
},
textContainer: {
// text container styles
},
label: {
// label text styles
},
subtitle: {
// subtitle text styles
},
},
},
};