mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-12 20:38:52 +00:00
feat: add animation for add favorites (#4317)
This commit is contained in:
@@ -5,7 +5,10 @@ import {
|
||||
type IconButtonProps,
|
||||
} from '@toeverything/components/button';
|
||||
import { Tooltip } from '@toeverything/components/tooltip';
|
||||
import { forwardRef } from 'react';
|
||||
import Lottie from 'lottie-react';
|
||||
import { forwardRef, useCallback, useState } from 'react';
|
||||
|
||||
import favoritedAnimation from './favorited-animation/data.json';
|
||||
|
||||
export const FavoriteTag = forwardRef<
|
||||
HTMLButtonElement,
|
||||
@@ -13,20 +16,30 @@ export const FavoriteTag = forwardRef<
|
||||
active: boolean;
|
||||
} & Omit<IconButtonProps, 'children'>
|
||||
>(({ active, onClick, ...props }, ref) => {
|
||||
const [playAnimation, setPlayAnimation] = useState(false);
|
||||
const t = useAFFiNEI18N();
|
||||
const handleClick = useCallback(
|
||||
(e: React.MouseEvent<HTMLButtonElement>) => {
|
||||
e.stopPropagation();
|
||||
onClick?.(e);
|
||||
setPlayAnimation(!active);
|
||||
},
|
||||
[active, onClick]
|
||||
);
|
||||
return (
|
||||
<Tooltip content={active ? t['Favorited']() : t['Favorite']()} side="top">
|
||||
<IconButton
|
||||
ref={ref}
|
||||
active={active}
|
||||
onClick={e => {
|
||||
e.stopPropagation();
|
||||
onClick?.(e);
|
||||
}}
|
||||
{...props}
|
||||
>
|
||||
<IconButton ref={ref} active={active} onClick={handleClick} {...props}>
|
||||
{active ? (
|
||||
<FavoritedIcon data-testid="favorited-icon" />
|
||||
playAnimation ? (
|
||||
<Lottie
|
||||
loop={false}
|
||||
animationData={favoritedAnimation}
|
||||
onComplete={() => setPlayAnimation(false)}
|
||||
style={{ width: '20px', height: '20px' }}
|
||||
/>
|
||||
) : (
|
||||
<FavoritedIcon data-testid="favorited-icon" />
|
||||
)
|
||||
) : (
|
||||
<FavoriteIcon />
|
||||
)}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user