1import { RefreshCwIcon } from "lucide-react";
2import { cva, type VariantProps } from "class-variance-authority";
3
4import { cn } from "~/lib/utils";
5import { observeVisibleAnimation } from "~/lib/visibleAnimation";
6
7// No default size: inside a Button the parent's svg rule sizes the glyph.
8const refreshIconVariants = cva("", {
9 variants: {
10 size: {
11 xs: "size-3",
12 sm: "size-3.5",
13 md: "size-4",
14 lg: "size-5",
15 },
16 },
17});
18
19/** Keep the refresh glyph in place while its owning action is running. */
20export function RefreshIcon({
21 refreshing = false,
22 className,
23 size,
24 ...props
25}: React.ComponentPropsWithoutRef<typeof RefreshCwIcon> &
26 VariantProps<typeof refreshIconVariants> & { refreshing?: boolean }) {
27 return (
28 <RefreshCwIcon
29 aria-hidden
30 ref={refreshing ? observeVisibleAnimation : undefined}
31 className={cn(
32 refreshIconVariants({ size }),
33 refreshing && "motion-safe:visible-animate-spin",
34 className,
35 )}
36 {...props}
37 />
38 );
39}