diff --git a/cypress/cypress.json b/cypress/cypress.json index 16f0f0ddbb3..ce5115dca8a 100644 --- a/cypress/cypress.json +++ b/cypress/cypress.json @@ -8,7 +8,5 @@ "videosFolder": "videos", "viewportWidth": 1280, "viewportHeight": 720, - "blockHosts": [ - "source.unsplash.com" - ] -} \ No newline at end of file + "blockHosts": ["source.unsplash.com"] +} diff --git a/cypress/package.json b/cypress/package.json index 2217c31213b..83f4cb7891d 100644 --- a/cypress/package.json +++ b/cypress/package.json @@ -11,4 +11,4 @@ "cypress": "^5.1.0", "cypress-skip-and-only-ui": "^1.2.7" } -} \ No newline at end of file +} diff --git a/docs/List.md b/docs/List.md index 1c46f93676c..916f92b7538 100644 --- a/docs/List.md +++ b/docs/List.md @@ -2209,17 +2209,18 @@ For mobile devices, a `` is often unusable - there is simply not enoug ### Properties -| Prop | Required | Type | Default | Description | -| --------------- | -------- | ----------------------------------------- | ------- | -------------------------------------------------------------------------------------------------------------------------------------------------------- | -| `primaryText` | Required | `Function` | - | Passed as `` prop | -| `secondaryText` | Optional | `Function` | - | Passed as `` prop | -| `tertiaryText` | Optional | `Function` | - | Passed as a complement to `` with a custom style | -| `linkType` | Optional | `string` | `Function` | `false` | `edit` | Target of the `` link. Set to `false` to disable the link. Set to a function `(record, id) => string` to have the link target vary per record. | -| `leftAvatar` | Optional | `Function` | - | When present, the `` renders a `` before the `` | -| `leftIcon` | Optional | `Function` | - | When present, the `` renders a `` before the `` | -| `rightAvatar` | Optional | `Function` | - | When present, the `` renders a `` after the `` | -| `rightIcon` | Optional | `Function` | - | When present, the `` renders a `` after the `` | -| `className` | Optional | `string` | - | Applied to the root element | +| Prop | Required | Type | Default | Description +| --------------- | -------- | ----------------------------------------- | ------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------| +| `primaryText` | Required | `Function` | - | Passed as `` prop | +| `secondaryText` | Optional | `Function` | - | Passed as `` prop | +| `tertiaryText` | Optional | `Function` | - | Passed as a complement to `` with a custom style | +| `linkType` | Optional | `string` | `Function` | `false` | `edit` | Target of the `` link. Set to `false` to disable the link. Set to a function `(record, id) => string` to have the link target vary per record. | +| `leftAvatar` | Optional | `Function` | - | When present, the `` renders a `` before the `` | +| `leftIcon` | Optional | `Function` | - | When present, the `` renders a `` before the `` | +| `rightAvatar` | Optional | `Function` | - | When present, the `` renders a `` after the `` | +| `rightIcon` | Optional | `Function` | - | When present, the `` renders a `` after the `` | +| `className` | Optional | `string` | - | Applied to the root element | +| `rowStyle` | Optional | `Function` | - | Applied to the `` styles prop. The function get's called for each row. Receives the current record and index as arguments and should return a style object.| ### Usage @@ -2230,6 +2231,10 @@ You can use `` as `` or `` child: import * as React from "react"; import { List, SimpleList } from 'react-admin'; +const postRowStyle = (record, index) => ({ + backgroundColor: record.nb_views >= 500 ? '#efe' : 'white', +}); + export const PostList = (props) => ( ( secondaryText={record => `${record.views} views`} tertiaryText={record => new Date(record.published_at).toLocaleDateString()} linkType={record => record.canEdit ? "edit" : "show"} + rowStyle={postRowStyle} /> ); ``` -For each record, `` executes the `primaryText`, `secondaryText`, `linkType`, `leftAvatar`, `leftIcon`, `rightAvatar`, and `rightIcon` props functions, and creates a `` with the result. +For each record, `` executes the `primaryText`, `secondaryText`, `linkType`, `rowStyle`, `leftAvatar`, `leftIcon`, `rightAvatar`, and `rightIcon` props functions, and creates a `` with the result. **Tip**: To use a `` on small screens and a `` on larger screens, use material-ui's `useMediaQuery` hook: diff --git a/packages/ra-ui-materialui/src/list/SimpleList.tsx b/packages/ra-ui-materialui/src/list/SimpleList.tsx index efa246565fd..457996c6a01 100644 --- a/packages/ra-ui-materialui/src/list/SimpleList.tsx +++ b/packages/ra-ui-materialui/src/list/SimpleList.tsx @@ -74,6 +74,7 @@ const SimpleList: FC = props => { rightIcon, secondaryText, tertiaryText, + rowStyle, ...rest } = props; const { basePath, data, ids, loaded, total } = useListContext(props); @@ -95,7 +96,7 @@ const SimpleList: FC = props => { return ( total > 0 && ( - {ids.map(id => ( + {ids.map((id, rowIndex) => ( = props => { key={id} record={data[id]} > - + {leftIcon && ( {leftIcon(data[id], id)} @@ -166,6 +174,7 @@ SimpleList.propTypes = { rightIcon: PropTypes.func, secondaryText: PropTypes.func, tertiaryText: PropTypes.func, + rowStyle: PropTypes.func, }; export type FunctionToElement = ( @@ -185,6 +194,7 @@ export interface SimpleListProps extends Omit { rightIcon?: FunctionToElement; secondaryText?: FunctionToElement; tertiaryText?: FunctionToElement; + rowStyle?: (record: Record, index: number) => any; } const useLinkOrNotStyles = makeStyles(