Skip to content

Commit

Permalink
wip fix 4
Browse files Browse the repository at this point in the history
  • Loading branch information
ssandino committed Jan 14, 2025
1 parent 4304be9 commit 5dd5de4
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 21 deletions.
16 changes: 8 additions & 8 deletions ui/src/components/use-glow-hover/glow-hover-effect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@ export type GlowHoverOptions = {
enableBurst?: boolean;
} & (
| {
preset: keyof typeof presets;
lightColor?: string;
}
preset: keyof typeof presets;
lightColor?: string;
}
| {
preset?: undefined;
lightColor: string;
}
);
preset?: undefined;
lightColor: string;
}
);

type Coords = {
x: number;
Expand Down Expand Up @@ -263,4 +263,4 @@ export const glowHoverEffect = (el: HTMLElement, { preset, ...options }: GlowHov
resizeObserver.disconnect();
}
};
};
};
28 changes: 15 additions & 13 deletions ui/src/components/use-glow-hover/linear-animation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,35 +2,37 @@

interface LinearAnimationParams {
onProgress: (progress: number) => void;
onIdUpdate?: (id: number) => void;
onIdUpdate?: (id: number | undefined) => void;
time: number;
initialProgress?: number;
}

export const linearAnimation = ({
onProgress,
onIdUpdate = () => {},
time,
initialProgress = 0,
}: LinearAnimationParams) => {
onProgress,
onIdUpdate = () => {},
time,
initialProgress = 0,
}: LinearAnimationParams) => {
if (time === 0) {
onProgress(1);
onIdUpdate(null);
onIdUpdate(undefined);
return;
}

let start: number = null;
let start: number | undefined = undefined;
const step = (timestamp: number) => {
if (!start) start = timestamp;
if (start === undefined) start = timestamp;
const progress = Math.min((timestamp - start) / time + initialProgress, 1);

onProgress(progress);

if (progress < 1) {
onIdUpdate(window.requestAnimationFrame(step));
const id = window.requestAnimationFrame(step);
onIdUpdate(id);
} else {
onIdUpdate(null);
onIdUpdate(undefined);
}
};
onIdUpdate(window.requestAnimationFrame(step));
};
const id = window.requestAnimationFrame(step);
onIdUpdate(id);
};

0 comments on commit 5dd5de4

Please sign in to comment.