Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix loader component #73

Merged
merged 1 commit into from
Oct 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
15 changes: 0 additions & 15 deletions src/components/Loader/Loader.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,24 +9,11 @@ const meta: Meta<typeof Loader> = {
controls: { expanded: true },
},
argTypes: {
type: {
control: {
control: { type: 'radio' },
options: ['default', 'raccord'],
},
description: 'Type of the loader',
defaultValue: 'default',
},
size: {
control: 'number',
description: 'Size of the loader',
defaultValue: 24,
},
customClass: {
control: 'text',
description: 'Additional custom CSS classes for styling',
defaultValue: '',
},
},
};

Expand All @@ -37,8 +24,6 @@ type Story = StoryObj<typeof Loader>;
export const _Loader: Story = {
render: (args) => <Loader {...args} />,
args: {
type: 'default',
size: 24,
customClass: '',
},
};
11 changes: 0 additions & 11 deletions src/components/Loader/Loader.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,3 @@ describe('Components | loader', () => {
expect(loader).toBeTruthy();
});
});

// loader with type secondary
describe('Components | loader', () => {
test('it should render', () => {
render(<Loader type="raccord" />);

let loader = screen.getByTestId('loader');

expect(loader).toBeTruthy();
});
});
40 changes: 18 additions & 22 deletions src/components/Loader/Loader.tsx
Original file line number Diff line number Diff line change
@@ -1,32 +1,28 @@
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
import React, { ComponentPropsWithoutRef } from 'react';
import React, { forwardRef } from 'react';

import { LoaderCircle } from 'lucide-react';

import Logo from '../../assets/images/loading.gif';
import { cn } from '../../lib/utils';

const TypeLoader = {
default: 'default',
raccord: 'raccord',
};

interface LoaderProps extends ComponentPropsWithoutRef<'div'> {
customClass?: string;
interface LoaderProps extends React.HTMLAttributes<SVGSVGElement> {
size?: number;
type?: keyof typeof TypeLoader;
}

export function Loader(props: LoaderProps) {
const { size = 24, customClass = '', type = 'default', ...rest } = props;
const Loader = forwardRef<SVGSVGElement, LoaderProps>((props, ref) => {
const { size = 24, className, ...rest } = props;

return (
<div data-testid="loader" className={customClass} {...rest}>
{type === 'default' ? (
<LoaderCircle size={size} className="animate-spin text-primary" />
) : (
<img src={Logo} alt="loading" width={size} height={size} />
)}
</div>
<LoaderCircle
ref={ref}
data-testid="loader"
strokeWidth={2}
size={size}
className={cn('animate-spin text-primary', className)}
{...rest}
/>
);
}
});

Loader.displayName = 'Loader';

export { Loader };
Loading