@@ -92,6 +92,36 @@ The title can be either a string or an element of your own.
92
92
93
93
You can replace the list of default actions by your own element using the ` actions ` prop:
94
94
95
+ ``` jsx
96
+ import * as React from ' react' ;
97
+ import { cloneElement } from ' react' ;
98
+ import { List , ListActions , Button } from ' react-admin' ;
99
+ import IconEvent from ' @material-ui/icons/Event' ;
100
+
101
+ const ListActions = (props ) => (
102
+ < TopToolbar>
103
+ {cloneElement (props .filters , { context: ' button' })}
104
+ < CreateButton/ >
105
+ < ExportButton/ >
106
+ {/* Add your custom actions */ }
107
+ < Button
108
+ onClick= {() => { alert (' Your custom action' ); }}
109
+ label= " Show calendar"
110
+ >
111
+ < IconEvent/ >
112
+ < / Button>
113
+ < / TopToolbar>
114
+ );
115
+
116
+ export const PostList = (props ) => (
117
+ < List {... props} actions= {< ListActions/ > }>
118
+ ...
119
+ < / List>
120
+ );
121
+ ```
122
+
123
+ This allows you to further control how the default actions behave. For example, you could disable the ` <ExportButton> ` when the list is empty:
124
+
95
125
{% raw %}
96
126
``` jsx
97
127
import * as React from ' react' ;
@@ -103,46 +133,25 @@ import {
103
133
CreateButton ,
104
134
ExportButton ,
105
135
Button ,
106
- sanitizeListRestProps ,
136
+ sanitizeListRestProps
107
137
} from ' react-admin' ;
108
138
import IconEvent from ' @material-ui/icons/Event' ;
109
139
110
140
const ListActions = (props ) => {
111
141
const {
112
142
className ,
113
- exporter ,
114
143
filters ,
115
144
maxResults ,
116
145
... rest
117
146
} = props;
118
147
const {
119
- currentSort ,
120
- resource ,
121
- displayedFilters ,
122
- filterValues ,
123
- hasCreate ,
124
- basePath ,
125
- selectedIds ,
126
- showFilter ,
127
148
total ,
128
149
} = useListContext ();
129
150
return (
130
151
< TopToolbar className= {className} {... sanitizeListRestProps (rest)}>
131
- {filters && cloneElement (filters, {
132
- resource,
133
- showFilter,
134
- displayedFilters,
135
- filterValues,
136
- context: ' button' ,
137
- })}
138
- < CreateButton basePath= {basePath} / >
139
- < ExportButton
140
- disabled= {total === 0 }
141
- resource= {resource}
142
- sort= {currentSort}
143
- filterValues= {filterValues}
144
- maxResults= {maxResults}
145
- / >
152
+ {cloneElement (filters, { context: ' button' })}
153
+ < CreateButton / >
154
+ < ExportButton disabled= {total === 0 } maxResults= {maxResults} / >
146
155
{/* Add your custom actions */ }
147
156
< Button
148
157
onClick= {() => { alert (' Your custom action' ); }}
0 commit comments