refactor: update Spinner component to accept size prop

This commit updates the `Spinner` component to accept a `size` prop that determines the width of the spinner
This commit is contained in:
Aaron William Po
2023-03-27 19:00:12 -04:00
parent cf6a8309f1
commit 7194f140aa

View File

@@ -1,8 +1,22 @@
const Spinner = () => ( import { FC } from 'react';
interface SpinnerProps {
size?: 'xs' | 'sm' | 'md' | 'lg';
}
const Spinner: FC<SpinnerProps> = ({ size = 'md' }) => {
const spinnerWidths: Record<NonNullable<SpinnerProps['size']>, `w-[${number}px]`> = {
xs: 'w-[10px]',
sm: 'w-[20px]',
md: 'w-[100px]',
lg: 'w-[150px]',
};
return (
<div role="status" className="flex flex-col items-center justify-center rounded-3xl"> <div role="status" className="flex flex-col items-center justify-center rounded-3xl">
<svg <svg
aria-hidden="true" aria-hidden="true"
className="w-[100px] animate-spin fill-success text-gray-500" className={`${spinnerWidths[size]} animate-spin fill-success text-gray-500`}
viewBox="0 0 100 101" viewBox="0 0 100 101"
fill="none" fill="none"
xmlns="http://www.w3.org/2000/svg" xmlns="http://www.w3.org/2000/svg"
@@ -18,6 +32,7 @@ const Spinner = () => (
</svg> </svg>
<span className="sr-only">Loading...</span> <span className="sr-only">Loading...</span>
</div> </div>
); );
};
export default Spinner; export default Spinner;