2022-12-13 14:19:21 +01:00
|
|
|
import { VFC } from 'react';
|
|
|
|
import { IconButton, IconButtonProps } from '@mui/material';
|
2022-12-02 08:16:03 +01:00
|
|
|
import { ConditionallyRender } from '../ConditionallyRender/ConditionallyRender';
|
|
|
|
import {
|
|
|
|
Star as StarIcon,
|
|
|
|
StarBorder as StarBorderIcon,
|
|
|
|
} from '@mui/icons-material';
|
2022-12-08 13:41:51 +01:00
|
|
|
import { TooltipResolver } from '../TooltipResolver/TooltipResolver';
|
2022-12-02 08:16:03 +01:00
|
|
|
|
2022-12-13 14:19:21 +01:00
|
|
|
interface IFavoriteIconButtonProps extends IconButtonProps {
|
2022-12-02 08:16:03 +01:00
|
|
|
isFavorite: boolean;
|
|
|
|
size?: 'medium' | 'large';
|
|
|
|
}
|
|
|
|
|
|
|
|
export const FavoriteIconButton: VFC<IFavoriteIconButtonProps> = ({
|
|
|
|
isFavorite,
|
|
|
|
size = 'large',
|
2022-12-13 14:19:21 +01:00
|
|
|
...props
|
2022-12-02 08:16:03 +01:00
|
|
|
}) => {
|
|
|
|
return (
|
2022-12-13 14:19:21 +01:00
|
|
|
<TooltipResolver
|
|
|
|
title={isFavorite ? 'Remove from favorites' : 'Add to favorites'}
|
2022-12-08 13:41:51 +01:00
|
|
|
>
|
2022-12-13 14:19:21 +01:00
|
|
|
<IconButton size={size} data-loading {...props}>
|
|
|
|
<ConditionallyRender
|
|
|
|
condition={isFavorite}
|
|
|
|
show={
|
2022-12-08 13:41:51 +01:00
|
|
|
<StarIcon
|
2023-10-02 14:25:46 +02:00
|
|
|
color='primary'
|
2022-12-08 13:41:51 +01:00
|
|
|
sx={{
|
2023-10-02 14:25:46 +02:00
|
|
|
fontSize: (theme) =>
|
2022-12-08 13:41:51 +01:00
|
|
|
size === 'medium'
|
|
|
|
? theme.spacing(2)
|
|
|
|
: theme.spacing(3),
|
|
|
|
}}
|
|
|
|
/>
|
2022-12-13 14:19:21 +01:00
|
|
|
}
|
|
|
|
elseShow={
|
2022-12-08 13:41:51 +01:00
|
|
|
<StarBorderIcon
|
2023-10-02 14:25:46 +02:00
|
|
|
color='primary'
|
2022-12-08 13:41:51 +01:00
|
|
|
sx={{
|
2023-10-02 14:25:46 +02:00
|
|
|
fontSize: (theme) =>
|
2022-12-08 13:41:51 +01:00
|
|
|
size === 'medium'
|
|
|
|
? theme.spacing(2)
|
|
|
|
: theme.spacing(3),
|
|
|
|
}}
|
|
|
|
/>
|
2022-12-13 14:19:21 +01:00
|
|
|
}
|
|
|
|
/>
|
|
|
|
</IconButton>
|
|
|
|
</TooltipResolver>
|
2022-12-02 08:16:03 +01:00
|
|
|
);
|
|
|
|
};
|