Skip to content

Commit 6dd0798

Browse files
committed
Refactor icon loading state in AIAction components
Introduced IconWithLoading component to handle icon rendering with loading state for both Button and link variants in AIActionWrapper. Also reset copied and loading states in CopyMarkdown cleanup. This improves code reuse and UI consistency for loading indicators.
1 parent 7212345 commit 6dd0798

File tree

2 files changed

+18
-7
lines changed

2 files changed

+18
-7
lines changed

.changeset/great-baboons-smell.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'gitbook': patch
3+
---
4+
5+
Refactor icon loading state in AIAction components

packages/gitbook/src/components/AIActions/AIActions.tsx

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,9 @@ export function CopyMarkdown(props: {
107107
if (timeoutRef.current) {
108108
clearTimeout(timeoutRef.current);
109109
}
110+
111+
setCopied(false);
112+
setLoading(false);
110113
};
111114
}, []);
112115

@@ -239,21 +242,24 @@ function AIActionWrapper(props: {
239242
href={href}
240243
target="_blank"
241244
onClick={onClick}
242-
disabled={disabled}
245+
disabled={disabled || loading}
243246
>
244-
{icon ? (
245-
<div className="flex size-5 items-center justify-center text-tint">
246-
{typeof icon === 'string' ? (
247+
<div className="flex size-5 items-center justify-center text-tint">
248+
{loading ? (
249+
<Icon icon="spinner-third" className="size-4 animate-spin" />
250+
) : icon ? (
251+
typeof icon === 'string' ? (
247252
<Icon
248253
icon={icon as IconName}
249254
iconStyle={IconStyle.Regular}
250255
className="size-4 fill-transparent stroke-current"
251256
/>
252257
) : (
253258
icon
254-
)}
255-
</div>
256-
) : null}
259+
)
260+
) : null}
261+
</div>
262+
257263
<div className="flex flex-1 flex-col gap-0.5">
258264
<span className="flex items-center gap-2 text-tint-strong">
259265
<span className="truncate font-medium text-sm">{label}</span>

0 commit comments

Comments
 (0)