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

Add cleanup button component #1599

Merged
merged 1 commit into from
Jul 6, 2023
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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;