Skip to content

Commit

Permalink
add fetching component
Browse files Browse the repository at this point in the history
  • Loading branch information
pivilartisant committed Jan 29, 2024
1 parent 9df7446 commit dc0feec
Show file tree
Hide file tree
Showing 5 changed files with 106 additions and 0 deletions.
34 changes: 34 additions & 0 deletions src/components/Fetching/Fetch.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// https://react-icons.github.io/react-icons/icons?name=fi
// https://github.com/react-icons/react-icons

import { FetchingLine, FetchingRound, FetchingStatus } from './Fetching';

export default {
title: 'Components/Fetching',
};

// to render the icon
// set icon color, size... etc using className and then normal tailwind presents
export const _FetchingRound = {
render: () => (
<div data-testid="fi-sun">
<FetchingRound />
</div>
),
};

export const _FetchingLine = {
render: () => (
<div data-testid="fi-sun">
<FetchingLine />
</div>
),
};

export const _FetchingStatus = {
render: () => (
<div data-testid="fi-sun">
<FetchingStatus text={'foo'} />
</div>
),
};
33 changes: 33 additions & 0 deletions src/components/Fetching/Fetching.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import '@testing-library/jest-dom';
import { render, screen } from '@testing-library/react';
import { FetchingLine, FetchingRound, FetchingStatus } from './Fetching';

describe('Components | Fetching | Fetching Round', () => {
test('it should render', () => {
render(<FetchingRound />);

let fetchingRound = screen.getByTestId('fetching-round');

expect(fetchingRound).toBeInTheDocument();
});
});

describe('Components | Fetching | Fetching Line', () => {
test('it should render', () => {
render(<FetchingLine />);

let fetchingLine = screen.getByTestId('fetching-line');

expect(fetchingLine).toBeInTheDocument();
});
});

describe('Components | Fetching | Fetching Status', () => {
test('it should render', () => {
render(<FetchingStatus text="foo" />);

let fetchingStatus = screen.getByTestId('fetching-status');

expect(fetchingStatus).toBeInTheDocument();
});
});
37 changes: 37 additions & 0 deletions src/components/Fetching/Fetching.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore

export function FetchingRound() {
return (
<span data-testid="fetching-round" className="relative flex h-3 w-3">
<span className="animate-ping absolute inline-flex h-full w-full rounded-full bg-s-success opacity-75"></span>
<span className="relative inline-flex rounded-full h-3 w-3 bg-s-success"></span>
</span>
);
}

export function FetchingLine() {
return (
<div
data-testid="fetching-line"
className={`shadow rounded-md w-24 pt-0.5`}
>
<div className="animate-pulse flex">
<div className="flex-1 space-y-6 py-1">
<div className="h-2 bg-c-disabled-1 rounded"></div>
</div>
</div>
</div>
);
}

export function FetchingStatus({ text }: { text: string }) {
return (
<div
data-testid="fetching-status"
className="bg-tertiary rounded-full w-fit px-3 pb-0.5 opacity-30"
>
{text}
</div>
);
}
1 change: 1 addition & 0 deletions src/components/Fetching/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from '.';
1 change: 1 addition & 0 deletions src/components/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,4 @@ export * from './Tooltip';
export * from './Token';
export * from './Tag';
export * from './Accordion';
export * from './Fetching';

0 comments on commit dc0feec

Please sign in to comment.