Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: change refresh icon #631

Open
wants to merge 1 commit into
base: next
Choose a base branch
from

Conversation

samobasquiat
Copy link
Member

@samobasquiat samobasquiat commented Mar 8, 2024

Summary

Changed the refresh icon codes & icon to remove setIntervals and handling by css animations

Checklist:

  • I have performed a self-review of my code
  • Implemented a user interface (UI) change, referencing our Figma design to ensure pixel-perfect precision.

@samobasquiat
Copy link
Member Author

samobasquiat commented May 14, 2024

We can Also use 'react-lottie' in this way:

import { RefreshProgressButton } from '@rango-dev/ui';
import React, { useEffect, useRef, useState } from 'react';
import Lottie from 'react-lottie';
import * as animationData from './refresh.json';

import { HeaderButton, ProgressIcon } from './HeaderButtons.styles';

const PROGRESS_DURATION = 60;

function RefreshButton({ onClick }: { onClick: (() => void) | undefined }) {
  const isDisabled = !onClick;
  const [isRefreshed, setIsRefreshed] = useState(false);
  const [isPaused, setIsPaused] = useState(isDisabled);
  const ref = useRef<HTMLButtonElement>(null);

  const handleVisibilityChange = () => {
    setIsPaused(document.hidden || isDisabled);
  };

  useEffect(() => {
    setIsPaused(isDisabled);

    document.addEventListener('visibilitychange', handleVisibilityChange);

    return () => {
      document.removeEventListener('visibilitychange', handleVisibilityChange);
    };
  }, [onClick]);

  const handleRefreshClick = () => {
    onClick?.();
    setIsPaused(true);
    setIsRefreshed(true);
  };

  const handleRefreshComplete = () => {
    setIsPaused(false);
    setIsRefreshed(false);
  };

  return (
    <HeaderButton
      variant="ghost"
      ref={ref}
      size="small"
      style={{ paddingTop: 0, paddingBottom: 0 }}
      onClick={handleRefreshClick}
      disabled={isDisabled}>
      <ProgressIcon
        onTransitionEnd={handleRefreshComplete}
        isRefetched={isRefreshed}>
        <Lottie
          options={{
            animationData,
          }}
          isPaused={isPaused}
          height={24}
          width={24}
        />
      </ProgressIcon>
    </HeaderButton>
  );
}

export { RefreshButton };

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant