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 <FilterButton> does not support the variant prop #9751

Merged
merged 3 commits into from
Mar 29, 2024
Merged
Show file tree
Hide file tree
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
94 changes: 83 additions & 11 deletions packages/ra-ui-materialui/src/list/filter/FilterButton.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
TextInput,
TopToolbar,
SearchInput,
FilterButtonProps,
} from 'react-admin';
import fakerestDataProvider from 'ra-data-fakerest';
import {
Expand Down Expand Up @@ -162,6 +163,7 @@ const data = {
const ListToolbar = (props: {
postFilters: React.ReactElement[];
args: { disableSaveQuery?: boolean };
buttonProps?: FilterButtonProps;
}) => {
return (
<TopToolbar>
Expand All @@ -170,6 +172,7 @@ const ListToolbar = (props: {
<FilterButton
filters={props.postFilters}
disableSaveQuery={props.args.disableSaveQuery}
{...props.buttonProps}
/>
<CreateButton />
</div>
Expand All @@ -179,17 +182,24 @@ const ListToolbar = (props: {
const PostList = (props: {
postFilters: React.ReactElement[];
args: { disableSaveQuery?: boolean };
}) => (
<ListBase>
<ListToolbar postFilters={props.postFilters} args={props.args} />
<Datagrid>
<TextField source="id" />
<TextField source="title" />
<TextField source="body" />
</Datagrid>
<Pagination />
</ListBase>
);
buttonProps?: FilterButtonProps;
}) => {
return (
<ListBase>
<ListToolbar
postFilters={props.postFilters}
args={props.args}
buttonProps={props.buttonProps}
/>
<Datagrid>
<TextField source="id" />
<TextField source="title" />
<TextField source="body" />
</Datagrid>
<Pagination />
</ListBase>
);
};

export const Basic = (args: { disableSaveQuery?: boolean }) => {
const postFilters: React.ReactElement[] = [
Expand Down Expand Up @@ -372,3 +382,65 @@ export const WithAutoCompleteArrayInput = (args: {
</MemoryRouter>
);
};

export const Variant = () => {
const postFilters: React.ReactElement[] = [
<TextInput
label="Title"
source="title"
defaultValue="Accusantium qui nihil voluptatum quia voluptas maxime ab similique"
/>,
];
return (
<MemoryRouter>
<Admin
dataProvider={fakerestDataProvider(data)}
store={memoryStore()}
>
<Resource
name="posts"
list={
<PostList
postFilters={postFilters}
args={{}}
buttonProps={{
variant: 'outlined',
}}
/>
}
/>
</Admin>
</MemoryRouter>
);
};

export const Size = () => {
const postFilters: React.ReactElement[] = [
<TextInput
label="Title"
source="title"
defaultValue="Accusantium qui nihil voluptatum quia voluptas maxime ab similique"
/>,
];
return (
<MemoryRouter>
<Admin
dataProvider={fakerestDataProvider(data)}
store={memoryStore()}
>
<Resource
name="posts"
list={
<PostList
postFilters={postFilters}
args={{}}
buttonProps={{
size: 'large',
}}
/>
}
/>
</Admin>
</MemoryRouter>
);
};
15 changes: 13 additions & 2 deletions packages/ra-ui-materialui/src/list/filter/FilterButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,12 @@ import {
useContext,
} from 'react';
import PropTypes from 'prop-types';
import { Menu, MenuItem, styled } from '@mui/material';
import {
Menu,
MenuItem,
styled,
ButtonProps as MuiButtonProps,
} from '@mui/material';
import ContentFilter from '@mui/icons-material/FilterList';
import lodashGet from 'lodash/get';
import isEqual from 'lodash/isEqual';
Expand All @@ -28,6 +33,8 @@ export const FilterButton = (props: FilterButtonProps): JSX.Element => {
filters: filtersProp,
className,
disableSaveQuery,
size,
variant,
...rest
} = props;
const filters = useContext(FilterContext) || filtersProp;
Expand Down Expand Up @@ -141,6 +148,8 @@ export const FilterButton = (props: FilterButtonProps): JSX.Element => {
label="ra.action.add_filter"
aria-haspopup="true"
onClick={handleClickButton}
variant={variant}
size={size}
>
<ContentFilter />
</Button>
Expand Down Expand Up @@ -256,7 +265,9 @@ FilterButton.propTypes = {
className: PropTypes.string,
};

export interface FilterButtonProps extends HtmlHTMLAttributes<HTMLDivElement> {
export interface FilterButtonProps
extends HtmlHTMLAttributes<HTMLDivElement>,
Pick<MuiButtonProps, 'variant' | 'size'> {
className?: string;
resource?: string;
filterValues?: any;
Expand Down
Loading