Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions lib/Button/Button.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React from 'react';
import clsx from 'clsx';
import { generateClasses } from '../utils';
import Loading from "./Loading";

interface ClassNames {
button?: string;
Expand All @@ -11,24 +12,28 @@ interface Props {
displayText: string;
onClick: () => {};
overrideClasses?: boolean;
isLoading?: boolean;
LoadingIndicator?: React.FC;
}
const Button: React.FC<Props> = ({
classNames,
disabled,
displayText,
onClick,
overrideClasses,
isLoading = false,
LoadingIndicator
}) => (
<button
className={clsx([
generateClasses(
'py-xs px-sm text-basefont-medium bg-primary text-white w-full hover:bg-primary-dark',
'py-xs px-sm text-basefont-medium bg-primary text-white w-full hover:bg-primary-dark flex justify-center item-center',
classNames?.button,
overrideClasses,
),
{
'bg-gray-500': disabled,
'hover:bg-gray-600': disabled,
'hover:bg-gray-600': disabled || isLoading
},
])}
disabled={disabled}
Expand All @@ -39,7 +44,9 @@ const Button: React.FC<Props> = ({
}
}}
>
{displayText}
{isLoading ?
<Loading/>:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's run Prettier to clean this up

<span className="items-center">{displayText}</span>}
</button>
);

Expand Down
20 changes: 20 additions & 0 deletions lib/Button/Loading.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import React from 'react';
interface Props {
LoadingIndicator?: React.FC
}
const Loading: React.FC<Props> = ({LoadingIndicator}) => {
return (
<>
{LoadingIndicator ?
LoadingIndicator :
<svg className="w-5 h-5 text-white animate-spin" fill="none" viewBox="0 0 24 24"
xmlns="http://www.w3.org/2000/svg">
<circle className="opacity-25" cx="12" cy="12" r="10" stroke="currentColor" strokeWidth="4"/>
<path className="opacity-75" d="M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z" fill="currentColor"/>
</svg>
}
</>
);
};

export default Loading;