Skip to content

Commit

Permalink
remove depreacted rowStyle prop from <SimpleList>
Browse files Browse the repository at this point in the history
  • Loading branch information
adguernier committed Apr 26, 2024
1 parent 7761b2a commit 8649d33
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 33 deletions.
21 changes: 0 additions & 21 deletions docs/SimpleList.md
Expand Up @@ -49,7 +49,6 @@ export const PostList = () => (
| `leftIcon` | Optional | function | | A function returning an `<Icon>` component to display before the primary text. |
| `rightAvatar` | Optional | function | | A function returning an `<Avatar>` component to display after the primary text. |
| `rightIcon` | Optional | function | | A function returning an `<Icon>` component to display after the primary text. |
| `rowStyle` | Optional | function | | A function returning a style object to apply to each row. |
| `rowSx` | Optional | function | | A function returning a sx object to apply to each row. |
| `empty` | Optional | ReactElement | | A ReactElement to display instead of the list when the data is empty. |

Expand Down Expand Up @@ -190,26 +189,6 @@ This prop should be a function returning an `<Avatar>` component. When present,

This prop should be a function returning an `<Icon>` component. When present, the `<ListItem>` renders a `<ListIcon>` after the `<ListItemText>`.

## `rowStyle`

*Deprecated - use [`rowSx`](#rowsx) instead.*

This optional prop should be a function, which gets called for each row. It receives the current record and index as arguments, and should return a style object. The style object is applied to the `<ListItem>` styles prop.

```jsx
import { List, SimpleList } from 'react-admin';

const postRowStyle = (record, index) => ({
backgroundColor: record.nb_views >= 500 ? '#efe' : 'white',
});

export const PostList = () => (
<List>
<SimpleList primaryText={record => record.title} rowStyle={postRowStyle} />
</List>
);
```

## `rowSx`

This optional prop should be a function, which gets called for each row. It receives the current record and index as arguments, and should return a Material UI [`sx`](https://mui.com/system/getting-started/the-sx-prop/). The style object is applied to the `<ListItem>` `sx` prop.
Expand Down
4 changes: 4 additions & 0 deletions docs/Upgrade.md
Expand Up @@ -980,6 +980,10 @@ The deprecated `formClassName` prop of `CommonInputProps` type has been removed

`InjectedFieldProps` interface has been removed. Use `FieldProps` instead.

## `<SimpleList rowStyle>` Is No Longer Supported

The deprecated `rowStyle` prop from `<SimpleList>` is no longer supported. Use [`rowSx`](./SimpleList.md#rowsx) instead.

## Upgrading to v4

If you are on react-admin v3, follow the [Upgrading to v4](https://marmelab.com/react-admin/doc/4.16/Upgrade.html) guide before upgrading to v5.
13 changes: 1 addition & 12 deletions packages/ra-ui-materialui/src/list/SimpleList/SimpleList.tsx
Expand Up @@ -47,7 +47,6 @@ import { ListNoResults } from '../ListNoResults';
* - rightAvatar: same
* - rightIcon: same
* - linkType: 'edit' or 'show', or a function returning 'edit' or 'show' based on the record
* - rowStyle: function returning a style object based on (record, index)
* - rowSx: function returning a sx object based on (record, index)
*
* @example // Display all posts as a List
Expand Down Expand Up @@ -83,7 +82,6 @@ export const SimpleList = <RecordType extends RaRecord = any>(
secondaryText,
tertiaryText,
rowSx,
rowStyle,
...rest
} = props;
const { data, isPending, total } = useListContextWithProps<RecordType>(
Expand Down Expand Up @@ -137,11 +135,6 @@ export const SimpleList = <RecordType extends RaRecord = any>(
resource={resource}
id={record.id}
record={record}
style={
rowStyle
? rowStyle(record, rowIndex)
: undefined
}
sx={rowSx?.(record, rowIndex)}
>
{leftIcon && (
Expand Down Expand Up @@ -261,7 +254,6 @@ SimpleList.propTypes = {
PropTypes.element,
PropTypes.string,
]),
rowStyle: PropTypes.func,
rowSx: PropTypes.func,
};

Expand All @@ -284,10 +276,7 @@ export interface SimpleListProps<RecordType extends RaRecord = any>
secondaryText?: FunctionToElement<RecordType> | ReactElement | string;
tertiaryText?: FunctionToElement<RecordType> | ReactElement | string;
rowSx?: (record: RecordType, index: number) => SxProps;
/**
* @deprecated Use rowSx instead
*/
rowStyle?: (record: RecordType, index: number) => any;

// can be injected when using the component without context
resource?: string;
data?: RecordType[];
Expand Down

0 comments on commit 8649d33

Please sign in to comment.