-
-
Notifications
You must be signed in to change notification settings - Fork 5.3k
/
Copy pathListToolbar.tsx
67 lines (61 loc) · 1.87 KB
/
ListToolbar.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import * as React from 'react';
import { FC, memo } from 'react';
import { styled } from '@mui/material/styles';
import { ReactElement } from 'react';
import { ToolbarProps } from '@mui/material';
import { Exporter } from 'ra-core';
import { FilterForm } from './filter';
import { FilterContext } from './FilterContext';
export const ListToolbar: FC<ListToolbarProps> = memo(props => {
const { filters, actions, className, ...rest } = props;
return Array.isArray(filters) ? (
<FilterContext.Provider value={filters}>
<Root className={className}>
<FilterForm />
<span />
{actions}
</Root>
</FilterContext.Provider>
) : (
<Root className={className}>
{filters &&
React.cloneElement(filters, {
...rest,
context: 'form',
})}
<span />
{actions &&
React.cloneElement(actions, {
...rest,
filters,
...actions.props,
})}
</Root>
);
});
export interface ListToolbarProps
extends Omit<ToolbarProps, 'classes' | 'onSelect'> {
actions?: ReactElement | false;
exporter?: Exporter | false;
filters?: ReactElement | ReactElement[];
hasCreate?: boolean;
}
const PREFIX = 'RaListToolbar';
const Root = styled('div', {
name: PREFIX,
overridesResolver: (props, styles) => styles.root,
})(({ theme }) => ({
display: 'flex',
position: 'relative',
justifyContent: 'space-between',
alignItems: 'flex-end',
width: '100%',
[theme.breakpoints.down('md')]: {
flexWrap: 'wrap',
},
[theme.breakpoints.down('sm')]: {
backgroundColor: theme.palette.background.paper,
flexWrap: 'inherit',
flexDirection: 'column-reverse',
},
}));