Skip to content

Commit

Permalink
feat(fuselage): Disable CodeSnippet button prop (#1338)
Browse files Browse the repository at this point in the history
Co-authored-by: Douglas Fabris <devfabris@gmail.com>
  • Loading branch information
yash-rajpal and dougfabris committed Mar 27, 2024
1 parent 977f452 commit ea37a31
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 2 deletions.
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

0 comments on commit ea37a31

Please sign in to comment.