Skip to content

Commit a0ddb4f

Browse files
committed
Allow to set default props for List.
1 parent 6ccfde5 commit a0ddb4f

File tree

2 files changed

+46
-33
lines changed

2 files changed

+46
-33
lines changed

packages/ra-ui-materialui/src/list/List.tsx

Lines changed: 44 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import * as React from 'react';
22
import { ReactElement } from 'react';
33
import { ListBase, ListBaseProps, RaRecord } from 'ra-core';
4+
import { useThemeProps } from '@mui/material/styles';
45

56
import { ListView, ListViewProps } from './ListView';
67
import { Loading } from '../layout';
@@ -55,42 +56,53 @@ import { Loading } from '../layout';
5556
* </List>
5657
* );
5758
*/
58-
export const List = <RecordType extends RaRecord = any>({
59-
debounce,
60-
disableAuthentication,
61-
disableSyncWithLocation,
62-
exporter,
63-
filter = defaultFilter,
64-
filterDefaultValues,
65-
loading = defaultLoading,
66-
perPage = 10,
67-
queryOptions,
68-
resource,
69-
sort,
70-
storeKey,
71-
...rest
72-
}: ListProps<RecordType>): ReactElement => (
73-
<ListBase<RecordType>
74-
debounce={debounce}
75-
disableAuthentication={disableAuthentication}
76-
disableSyncWithLocation={disableSyncWithLocation}
77-
exporter={exporter}
78-
filter={filter}
79-
filterDefaultValues={filterDefaultValues}
80-
loading={loading}
81-
perPage={perPage}
82-
queryOptions={queryOptions}
83-
resource={resource}
84-
sort={sort}
85-
storeKey={storeKey}
86-
>
87-
<ListView<RecordType> {...rest} />
88-
</ListBase>
89-
);
59+
export const List = <RecordType extends RaRecord = any>(
60+
props: ListProps<RecordType>
61+
): ReactElement => {
62+
const {
63+
debounce,
64+
disableAuthentication,
65+
disableSyncWithLocation,
66+
exporter,
67+
filter = defaultFilter,
68+
filterDefaultValues,
69+
loading = defaultLoading,
70+
perPage = 10,
71+
queryOptions,
72+
resource,
73+
sort,
74+
storeKey,
75+
...rest
76+
} = useThemeProps({
77+
props: props,
78+
name: PREFIX,
79+
});
80+
81+
return (
82+
<ListBase<RecordType>
83+
debounce={debounce}
84+
disableAuthentication={disableAuthentication}
85+
disableSyncWithLocation={disableSyncWithLocation}
86+
exporter={exporter}
87+
filter={filter}
88+
filterDefaultValues={filterDefaultValues}
89+
loading={loading}
90+
perPage={perPage}
91+
queryOptions={queryOptions}
92+
resource={resource}
93+
sort={sort}
94+
storeKey={storeKey}
95+
>
96+
<ListView<RecordType> {...rest} />
97+
</ListBase>
98+
);
99+
};
90100

91101
export interface ListProps<RecordType extends RaRecord = any>
92102
extends ListBaseProps<RecordType>,
93103
ListViewProps {}
94104

95105
const defaultFilter = {};
96106
const defaultLoading = <Loading />;
107+
108+
const PREFIX = 'RaList'; // Types declared in ListView.

packages/ra-ui-materialui/src/list/ListView.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import { ListToolbar } from './ListToolbar';
1616
import { Pagination as DefaultPagination } from './pagination';
1717
import { ListActions as DefaultActions } from './ListActions';
1818
import { Empty } from './Empty';
19+
import { ListProps } from './List';
1920

2021
const defaultActions = <DefaultActions />;
2122
const defaultPagination = <DefaultPagination />;
@@ -372,7 +373,7 @@ declare module '@mui/material/styles' {
372373
}
373374

374375
interface ComponentsPropsList {
375-
RaList: Partial<ListViewProps>;
376+
RaList: Partial<ListProps>;
376377
}
377378

378379
interface Components {

0 commit comments

Comments
 (0)