# @pndr/record-list-item

> Used for displaying a record as a list item.

Latest version **0.12.0** (published 2019-11-04) · MIT license · 0 weekly downloads

## Install

```sh
npm install @pndr/record-list-item
pnpm add @pndr/record-list-item
yarn add @pndr/record-list-item
bun add @pndr/record-list-item
```

## Health

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

Positive: esm support; no vulnerabilities.

Warnings: low downloads; no types; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.12.0 |
| Published | 2019-11-04 |
| First published | 2019-05-11 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 210 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Maintainers | andev |
| Keywords | react-component |

## Links

- npm: https://www.npmjs.com/package/@pndr/record-list-item
- Repository: https://github.com/entercosmos/record-list-item
- Homepage: https://github.com/entercosmos/record-list-item#readme
- Issues: https://github.com/entercosmos/record-list-item/issues
- npm.io page: https://npm.io/package/@pndr/record-list-item

## Recent versions

- 0.12.0 (latest) — 2019-11-04
- 0.11.0 — 2019-11-01
- 0.10.0 — 2019-09-17
- 0.9.0 — 2019-05-13
- 0.8.0 — 2019-05-11

## README

# RecordListItem

[![npm package][npm-badge]][npm]

Used for displaying a record as a list item.	

## Getting started

````
npm install @cmds/record-list-item --save
````

### Prop Types

| Property | Type | Required? | Description |
|:---|:---|:---:|:---|
| recordId | String | ✓ | Unique id for the instance of this record |
| primaryFieldId | String | ✓ | Used for rendering the value of the primary field as record name |
| fields | Array | ✓ | A list of fields |
| visibleFieldOrder | Array | ✓ | A list of ids for the fields that need to be displayed and in which order |
| fieldRenderer | Function | ✓ | Responsible for rendering a field given it's configuration: `({recordId: string, index: number, field: object}): jsx` [Learn more](#fieldRenderer) |
| onClick | Function | ✓ | Triggers when the user clicks the record list item: `({id: string, e: ClickEvent})` |

#### fieldRenderer

Responsible for rendering a field given it's configuration.

```jsx harmony
import SingleLineTextField from '@cmds/single-line-text-field'
// import all other fields that need to be supported...

const renderers = {
    singleLineText: ({props}) => (
        <SingleLineTextField
            {...props}
            text={'Luke Skywalker'}
            onChange={({id, text}) => {
                
                // store new value
            }}
        />
    ),
    // and all other fields that need to be supported
}

function fieldRenderer({recordId, index, field, props}) {

    const renderer = renderers[field.typeId]
    
    if (!renderer) {
        throw new Error(`Renderer for typeId '${field.typeId}' not found`)
    }
    
    /**
     * Note — props already contains properties
     * related to the context in which the field
     * gets rendered.
     * 
     * {
     *      id: 'fld1', // the field's id
     *      contextId: 'recordListItem',
     *      roleId: 'readOnly'
     * }
     */
    
    return renderer({ 
        recordId, 
        field,
        props
    })
}
```

### More information

This component is designed and developed as part of [Cosmos Design System][cmds]. 

[cmds]: https://github.com/entercosmos/cosmos
[npm-badge]: https://img.shields.io/npm/v/@cmds/record-list-item.svg
[npm]: https://www.npmjs.org/package/@cmds/record-list-item

---
_Source: https://npm.io/package/@pndr/record-list-item · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
