List
A component for generating a list component.
Typedefs
- props
props for List
- defaultProps
default props for List
The List component maps a collection of data objects into an array of elements. It also manages the selection and focus of those elements.
Returns{react.element}: A React component that displays list data.
Parameters
Name | Type | Description |
---|---|---|
props | props | React Component props |
props for List
Properties
Name | Type | Description |
---|---|---|
classes | Object | css classes prop for List |
classes.root | string | css classes for List root container |
getItemKey | func | item key value getter |
initialSelection | array | object | A single or list of objects that should start off selected |
items | iterable | An iterable that yields [key, item] pairs such as an ES2015 Map |
render | func | string | A render prop for the list element. A tagname string, such as "div" , is also valid. |
renderItem | func | string | A render prop for the list item elements. A tagname string, such as "div" , is also valid |
onSelectionChange | func | A callback that fires when the selection state changes |
selectionModel | checkbox | radio | A string corresponding to a selection model |
default props for List
Source Code: pwa-studio/packages/peregrine/lib/List/list.js
Selection models#
The selectionModel
currently accepts the following values:
- radio (default)
- checkbox
Example#
Copied to your clipboard1import { List } from '@magento/peregrine';23const simpleData = new Map()4 .set('s', 'Small')5 .set('m', 'Medium')6 .set('l', 'Large')78<List9 classes={{ root: 'foo' }}10 items={simpleData}11 render={'ul'}12 renderItem={'li'}13/>1415const complexData = new Map()16 .set('s', { id: 's', value: 'Small' })17 .set('m', { id: 'm', value: 'Medium' })18 .set('l', { id: 'l', value: 'Large' })1920<List21 classes={{ root: 'bar' }}22 items={complexData}23 render={props => (<ul>{props.children}</ul>)}24 renderItem={props => (<li>{props.value}</li>)}25/>