diff --git a/src/components/LinkWithStatus.tsx b/src/components/LinkWithStatus.tsx index 5655454d..6b00bf2c 100644 --- a/src/components/LinkWithStatus.tsx +++ b/src/components/LinkWithStatus.tsx @@ -17,10 +17,15 @@ const FLICKER_THRESHOLD = 400; // Clear loading status after long duration const MAX_LOADING_DURATION = 15_000; -export type LinkWithStatusProps = ComponentProps & { +export type LinkWithStatusProps = Omit< + ComponentProps, 'children' +> & { loadingElement?: ReactNode loadingClassName?: string contentClassName?: string + children: ReactNode | ((props: { + isLoading: boolean + }) => ReactNode) } export default function LinkWithStatus({ @@ -44,6 +49,8 @@ export default function LinkWithStatus({ const stopLoadingTimeout = useRef(undefined); const maxLoadingTimeout = useRef(undefined); + const isControlled = typeof children === 'function'; + const clearTimeouts = useCallback(() => { [startLoadingTimeout, stopLoadingTimeout, maxLoadingTimeout] .forEach(timeout => { @@ -114,11 +121,13 @@ export default function LinkWithStatus({ contentClassName, loadingElement ? isLoading ? 'opacity-0' : 'opacity-100' - : loadingClassName + : (loadingClassName || isControlled) ? 'opacity-100' : isLoading ? 'opacity-50' : 'opacity-100', )}> - {children} + {typeof children === 'function' + ? children({ isLoading }) + : children} {isLoading && loadingElement && - + ); };