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

feat(fuselage): Disable CodeSnippet button prop #1338

Merged
merged 6 commits into from
Mar 27, 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
5 changes: 5 additions & 0 deletions .changeset/big-rockets-approve.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@rocket.chat/fuselage": minor
---

Accept disable button prop on CodeSnippet component
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import React from 'react';

import * as stories from './CodeSnippet.stories';

const { Default, CopyButton, CustomButtonName, LoadingCode } =
const { Default, CopyButton, CustomButtonName, LoadingCode, DisabledButton } =
composeStories(stories);

describe('[CodeSnippet Component]', () => {
Expand Down Expand Up @@ -44,4 +44,10 @@ describe('[CodeSnippet Component]', () => {
const { container } = render(<LoadingCode />);
expect(container.querySelector('.rcx-skeleton')).toBeInTheDocument();
});

it('should should render a disabled button, when buttonDisabled prop is passed', () => {
render(<DisabledButton />);
const button = screen.getByRole('button');
expect(button).toBeDisabled();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,11 @@ LoadingCode.args = {
children: '',
onClick: action('click'),
};

export const DisabledButton = Template.bind({});
DisabledButton.args = {
children: 'curl -L https://go.rocket.chat/i/docker-compose.yml -O',
onClick: action('click'),
buttonText: 'Disabled Button',
buttonDisabled: true,
};
4 changes: 3 additions & 1 deletion packages/fuselage/src/components/CodeSnippet/CodeSnippet.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,15 @@ import { Skeleton } from '../Skeleton';
type CodeSnippetProps = ComponentProps<typeof Box> & {
children: string;
buttonText?: string;
buttonDisabled?: boolean;
onClick?: () => void;
};

const CodeSnippet = ({
children,
onClick,
buttonText = 'Copy',
buttonDisabled = false,
...props
}: CodeSnippetProps): ReactElement<CodeSnippetProps> => {
if (!children) {
Expand All @@ -32,7 +34,7 @@ const CodeSnippet = ({
</Box>
{onClick && children && (
<Box>
<Button small primary onClick={onClick}>
<Button small primary onClick={onClick} disabled={buttonDisabled}>
{buttonText}
</Button>
</Box>
Expand Down
Loading