|
1 | 1 | import * as React from 'react';
|
2 |
| -import { FC, memo } from 'react'; |
| 2 | +import { memo, isValidElement, ReactElement } from 'react'; |
3 | 3 | import {
|
4 | 4 | IconButton,
|
5 | 5 | ListItem,
|
@@ -27,9 +27,10 @@ const useStyles = makeStyles(theme => ({
|
27 | 27 | *
|
28 | 28 | * Expects 2 props:
|
29 | 29 | *
|
30 |
| - * - label: The text to be displayed for this item. Will be translated. |
| 30 | + * - label: The text (or React element) to be displayed for this item. |
| 31 | + * If it's a string, the component will translate it. |
31 | 32 | * - value: An object to be merged into the filter value when enabling the filter
|
32 |
| - * (e.g. { is_published: true, published_at_gte: '2020-07-08' }) |
| 33 | + * (e.g. { is_published: true, published_at_gte: '2020-07-08' }) |
33 | 34 | *
|
34 | 35 | * @example
|
35 | 36 | *
|
@@ -143,7 +144,10 @@ const useStyles = makeStyles(theme => ({
|
143 | 144 | * </Card>
|
144 | 145 | * );
|
145 | 146 | */
|
146 |
| -const FilterListItem: FC<{ label: string; value: any }> = props => { |
| 147 | +const FilterListItem = (props: { |
| 148 | + label: string | ReactElement; |
| 149 | + value: any; |
| 150 | +}) => { |
147 | 151 | const { label, value } = props;
|
148 | 152 | const { filterValues, setFilters } = useListFilterContext();
|
149 | 153 | const translate = useTranslate();
|
@@ -180,7 +184,11 @@ const FilterListItem: FC<{ label: string; value: any }> = props => {
|
180 | 184 | className={classes.listItem}
|
181 | 185 | >
|
182 | 186 | <ListItemText
|
183 |
| - primary={translate(label, { _: label })} |
| 187 | + primary={ |
| 188 | + isValidElement(label) |
| 189 | + ? label |
| 190 | + : translate(label, { _: label }) |
| 191 | + } |
184 | 192 | className={classes.listItemText}
|
185 | 193 | data-selected={isSelected ? 'true' : 'false'}
|
186 | 194 | />
|
|
0 commit comments