Skip to content

Commit

Permalink
Merge pull request #4735 from WiXSL/docs-defs-simplelist
Browse files Browse the repository at this point in the history
Updated documentation and propType for SimpleList linkType.
  • Loading branch information
fzaninotto authored Apr 30, 2020
2 parents 8b44b5a + 9f5683f commit 98a8d04
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
6 changes: 4 additions & 2 deletions docs/List.md
Original file line number Diff line number Diff line change
Expand Up @@ -1607,12 +1607,13 @@ export const PostList = (props) => (
primaryText={record => record.title}
secondaryText={record => `${record.views} views`}
tertiaryText={record => new Date(record.published_at).toLocaleDateString()}
linkType={record => record.canEdit ? "edit" : "show"}
/>
</List>
);
```

`<SimpleList>` iterates over the list data. For each record, it executes the `primaryText`, `secondaryText`, `leftAvatar`, `leftIcon`, `rightAvatar`, and `rightIcon` props function, and passes the result as the corresponding `<ListItem>` prop.
`<SimpleList>` iterates over the list data. For each record, it executes the `primaryText`, `secondaryText`, `linkType`, `leftAvatar`, `leftIcon`, `rightAvatar`, and `rightIcon` props function, and passes the result as the corresponding `<ListItem>` prop.

**Tip**: To use a `<SimpleList>` on small screens and a `<Datagrid>` on larger screens, use material-ui's `useMediaQuery` hook:

Expand All @@ -1631,6 +1632,7 @@ export const PostList = (props) => {
primaryText={record => record.title}
secondaryText={record => `${record.views} views`}
tertiaryText={record => new Date(record.published_at).toLocaleDateString()}
linkType={record => record.canEdit ? "edit" : "show"}
/>
) : (
<Datagrid>
Expand All @@ -1642,7 +1644,7 @@ export const PostList = (props) => {
}
```

**Tip**: The `<SimpleList>` items link to the edition page by default. You can set the `linkType` prop to `show` to link to the `<Show>` page instead.
**Tip**: The `<SimpleList>` items link to the edition page by default. You can also set the `linkType` prop to `show` directly to link to the `<Show>` page instead.

```jsx
// in src/posts.js
Expand Down
7 changes: 5 additions & 2 deletions packages/ra-ui-materialui/src/list/SimpleList.js
Original file line number Diff line number Diff line change
Expand Up @@ -163,8 +163,11 @@ SimpleList.propTypes = {
ids: PropTypes.array,
leftAvatar: PropTypes.func,
leftIcon: PropTypes.func,
linkType: PropTypes.oneOfType([PropTypes.string, PropTypes.bool])
.isRequired,
linkType: PropTypes.oneOfType([
PropTypes.string,
PropTypes.bool,
PropTypes.func,
]).isRequired,
onToggleItem: PropTypes.func,
primaryText: PropTypes.func,
rightAvatar: PropTypes.func,
Expand Down

0 comments on commit 98a8d04

Please sign in to comment.