mirror of
https://github.com/glitch-soc/mastodon.git
synced 2025-12-13 07:49:29 +00:00
[Glitch] Fix icon buttons animating when they haven't changed
Port b53ee04475 to glitch-soc
Signed-off-by: Claire <claire.github-309c@sitedethib.com>
This commit is contained in:
@@ -2,6 +2,8 @@ import { useCallback, forwardRef } from 'react';
|
||||
|
||||
import classNames from 'classnames';
|
||||
|
||||
import { usePrevious } from '../hooks/usePrevious';
|
||||
|
||||
import { AnimatedNumber } from './animated_number';
|
||||
import type { IconProp } from './icon';
|
||||
import { Icon } from './icon';
|
||||
@@ -95,12 +97,15 @@ export const IconButton = forwardRef<HTMLButtonElement, Props>(
|
||||
...(active ? activeStyle : {}),
|
||||
};
|
||||
|
||||
const previousActive = usePrevious(active) ?? active;
|
||||
const shouldAnimate = animate && active !== previousActive;
|
||||
|
||||
const classes = classNames(className, 'icon-button', {
|
||||
active,
|
||||
disabled,
|
||||
inverted,
|
||||
activate: animate && active,
|
||||
deactivate: animate && !active,
|
||||
activate: shouldAnimate && active,
|
||||
deactivate: shouldAnimate && !active,
|
||||
overlayed: overlay,
|
||||
'icon-button--with-counter': typeof counter !== 'undefined',
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user