2022-12-02 08:16:03 +01:00
|
|
|
import React, { VFC } from 'react';
|
2022-12-08 13:41:51 +01:00
|
|
|
import { IconButton, SxProps, Theme } 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
|
|
|
|
|
|
|
interface IFavoriteIconButtonProps {
|
|
|
|
onClick: (event?: any) => void;
|
|
|
|
isFavorite: boolean;
|
|
|
|
size?: 'medium' | 'large';
|
2022-12-08 13:41:51 +01:00
|
|
|
sx?: SxProps<Theme>;
|
2022-12-02 08:16:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
export const FavoriteIconButton: VFC<IFavoriteIconButtonProps> = ({
|
|
|
|
onClick,
|
|
|
|
isFavorite,
|
|
|
|
size = 'large',
|
2022-12-08 13:41:51 +01:00
|
|
|
sx,
|
2022-12-02 08:16:03 +01:00
|
|
|
}) => {
|
|
|
|
return (
|
2022-12-08 13:41:51 +01:00
|
|
|
<IconButton
|
|
|
|
size={size}
|
|
|
|
data-loading
|
|
|
|
sx={{ mr: 1, ...sx }}
|
|
|
|
onClick={onClick}
|
|
|
|
>
|
2022-12-02 08:16:03 +01:00
|
|
|
<ConditionallyRender
|
|
|
|
condition={isFavorite}
|
|
|
|
show={
|
2022-12-08 13:41:51 +01:00
|
|
|
<TooltipResolver title={'Remove from favorites'}>
|
|
|
|
<StarIcon
|
|
|
|
color="primary"
|
|
|
|
sx={{
|
|
|
|
fontSize: theme =>
|
|
|
|
size === 'medium'
|
|
|
|
? theme.spacing(2)
|
|
|
|
: theme.spacing(3),
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
</TooltipResolver>
|
2022-12-02 08:16:03 +01:00
|
|
|
}
|
|
|
|
elseShow={
|
2022-12-08 13:41:51 +01:00
|
|
|
<TooltipResolver title={'Add to favorites'}>
|
|
|
|
<StarBorderIcon
|
|
|
|
sx={{
|
|
|
|
fontSize: theme =>
|
|
|
|
size === 'medium'
|
|
|
|
? theme.spacing(2)
|
|
|
|
: theme.spacing(3),
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
</TooltipResolver>
|
2022-12-02 08:16:03 +01:00
|
|
|
}
|
|
|
|
/>
|
|
|
|
</IconButton>
|
|
|
|
);
|
|
|
|
};
|