1
0
Fork 0
mirror of https://github.com/portainer/portainer.git synced 2025-07-20 13:59:40 +02:00
portainer/app/react/components/buttons/LoadingButton.tsx
Ali d78b762f7b
refactor(icons): replace fa icons [EE-4459] (#7907)
refactor(icons): remove fontawesome EE-4459

refactor(icon) replace feather with lucide EE-4472
2022-11-28 15:00:28 +13:00

46 lines
966 B
TypeScript

import { PropsWithChildren, ReactNode } from 'react';
import { Loader2 } from 'lucide-react';
import { Icon } from '@@/Icon';
import { type Props as ButtonProps, Button } from './Button';
interface Props extends ButtonProps {
loadingText: string;
isLoading: boolean;
}
export function LoadingButton({
loadingText,
isLoading,
disabled,
type = 'submit',
children,
icon,
...buttonProps
}: PropsWithChildren<Props>) {
return (
<Button
// eslint-disable-next-line react/jsx-props-no-spreading
{...buttonProps}
type={type}
disabled={disabled || isLoading}
icon={loadingButtonIcon(isLoading, icon)}
>
{isLoading ? loadingText : children}
</Button>
);
}
function loadingButtonIcon(isLoading: boolean, defaultIcon: ReactNode) {
if (!isLoading) {
return defaultIcon;
}
return (
<Icon
icon={Loader2}
className="animate-spin-slow ml-1"
aria-label="loading"
/>
);
}