Skip to content

Commit

Permalink
feat: 🎉 added ButtonSpinner as loading component for Button
Browse files Browse the repository at this point in the history
  • Loading branch information
Karthik-B-06 committed Dec 1, 2021
1 parent d7e8e15 commit 3653303
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions src/components/button/ButtonSpinner.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { isValidElement } from 'react';
import React from 'react';
import {
RenderPropType,
Spinner,
SpinnerSizes,
useTheme,
} from 'react-native-system';
import { ButtonSizes } from './buttonTypes';

interface ButtonSpinnerProps {
size: ButtonSizes;
spinner?: RenderPropType;
}
export const ButtonSpinner: React.FC<ButtonSpinnerProps> = ({
spinner,
size,
}) => {
const buttonTheme = useTheme('button');
const tailwind = useTheme();
return isValidElement(spinner) ? (
React.cloneElement(spinner, {
size: buttonTheme.loading.size[size] as SpinnerSizes,
})
) : (
<Spinner
size={buttonTheme.loading.size[size] as SpinnerSizes}
style={tailwind.style(buttonTheme.loading.default)}
/>
);
};

0 comments on commit 3653303

Please sign in to comment.