Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix custom actions example in List documentation #4327

Merged
merged 2 commits into from
Jan 22, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 35 additions & 16 deletions docs/List.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,25 +86,33 @@ The title can be either a string, or an element of your own.
You can replace the list of default actions by your own element using the `actions` prop:

```jsx
import Button from '@material-ui/core/Button';
import { CreateButton, ExportButton, RefreshButton } from 'react-admin';
import Toolbar from '@material-ui/core/Toolbar';
import React, { cloneElement, useMemo } from 'react';
import PropTypes from 'prop-types';
import {
TopToolbar, CreateButton, ExportButton, Button, sanitizeListRestProps,
} from 'react-admin';
import IconEvent from '@material-ui/icons/Event';

const PostActions = ({
basePath,
const ListActions = ({
currentSort,
displayedFilters,
exporter,
className,
resource,
filters,
displayedFilters,
exporter, // you can hide ExportButton if exporter = (null || false)
filterValues,
onUnselectItems,
resource,
permanentFilter,
hasCreate, // you can hide CreateButton if hasCreate = false
basePath,
selectedIds,
onUnselectItems,
showFilter,
total
maxResults,
total,
...rest
}) => (
<Toolbar>
{filters && React.cloneElement(filters, {
<TopToolbar className={className} {...sanitizeListRestProps(rest)}>
{filters && cloneElement(filters, {
resource,
showFilter,
displayedFilters,
Expand All @@ -116,16 +124,27 @@ const PostActions = ({
disabled={total === 0}
resource={resource}
sort={currentSort}
filter={filterValues}
filter={{ ...filterValues, ...permanentFilter }}
exporter={exporter}
maxResults={maxResults}
/>
{/* Add your custom actions */}
<Button color="primary" onClick={customAction}>Custom Action</Button>
</Toolbar>
<Button
onClick={() => { alert('Your custom action'); }}
label="Show calendar"
>
<IconEvent />
</Button>
</TopToolbar>
);

ListActions.defaultProps = {
selectedIds: [],
onUnselectItems: () => null,
};

export const PostList = (props) => (
<List {...props} actions={<PostActions />}>
<List {...props} actions={<ListActions />}>
...
</List>
);
Expand Down