Skip to content

Commit

Permalink
Add CleanUpButton component (#1599)
Browse files Browse the repository at this point in the history
  • Loading branch information
arbulu89 committed Jul 6, 2023
1 parent b8173ce commit fd447b5
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 0 deletions.
34 changes: 34 additions & 0 deletions assets/js/components/CleanUpButton/CleanUpButton.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import React from 'react';

import { EOS_CLEANING_SERVICES } from 'eos-icons-react';

import Button from '@components/Button';
import Spinner from '@components/Spinner';

function CleanUpButton({ cleaning, onClick }) {
return (
<Button
type="primary-white"
className="inline-block mx-0.5 border-green-500 border w-fit"
size="small"
disabled={cleaning}
onClick={() => onClick()}
>
{cleaning === true ? (
<Spinner className="justify-center flex" />
) : (
<>
<EOS_CLEANING_SERVICES
size="base"
className="fill-jungle-green-500 inline"
/>
<span className="text-jungle-green-500 text-sm font-bold pl-1.5">
Clean up
</span>
</>
)}
</Button>
);
}

export default CleanUpButton;
28 changes: 28 additions & 0 deletions assets/js/components/CleanUpButton/CleanUpButton.stories.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import CleanUpButton from '.';

export default {
title: 'CleanUpButton',
component: CleanUpButton,
argTypes: {
cleaning: {
control: { type: 'boolean' },
description: 'Cleaning state',
table: {
type: { summary: 'string' },
defaultValue: { summary: false },
},
},
onClick: { action: 'Click button' },
},
};

export const Default = {
args: {},
};

export const Cleaning = {
args: {
...Default.args,
cleaning: true,
},
};
18 changes: 18 additions & 0 deletions assets/js/components/CleanUpButton/CleanUpButton.test.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import React from 'react';
import { render, screen } from '@testing-library/react';
import '@testing-library/jest-dom';

import CleanUpButton from '.';

describe('Button', () => {
it('should display the clean up button', () => {
render(<CleanUpButton />);
expect(screen.getByRole('button')).toHaveTextContent('Clean up');
});

it('should display the clean up in cleaning state', () => {
render(<CleanUpButton cleaning />);
const spinnerElement = screen.getByRole('alert');
expect(spinnerElement).toBeInTheDocument();
});
});
3 changes: 3 additions & 0 deletions assets/js/components/CleanUpButton/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import CleanUpButton from './CleanUpButton';

export default CleanUpButton;

0 comments on commit fd447b5

Please sign in to comment.