it('should show full size when multiline with no editting', () => {
const { container } = setupWithProps();
- const copyButton = screen.getByRole('button', { name: 'copy' });
+ const copyButton = screen.getByRole('button', { name: 'Copy' });
expect(copyButton).toHaveStyle('top: 1.5rem');
expect(container).toMatchSnapshot();
});
it('should show reduced size when single line with no editting', () => {
const { container } = setupWithProps({ isOneLine: true, snippet: 'foobar' });
- const copyButton = screen.getByRole('button', { name: 'copy' });
+ const copyButton = screen.getByRole('button', { name: 'Copy' });
expect(copyButton).toHaveStyle('top: 1.5rem');
expect(container).toMatchSnapshot();
});
const user = userEvent.setup({ delay: null });
renderClipboardButton();
- expect(screen.getByRole('button', { name: 'copy' })).toBeInTheDocument();
+ expect(screen.getByRole('button', { name: 'Copy' })).toBeInTheDocument();
- await user.click(screen.getByRole('button', { name: 'copy' }));
+ await user.click(screen.getByRole('button', { name: 'Copy' }));
- expect(await screen.findByText('copied_action')).toBeVisible();
+ expect(await screen.findByText('Copied')).toBeVisible();
- await waitForElementToBeRemoved(() => screen.queryByText('copied_action'));
+ await waitForElementToBeRemoved(() => screen.queryByText('Copied'));
jest.runAllTimers();
});
it('should display correctly', () => {
renderWithContext(<ClipboardIconButton copyValue="foo" />);
- const copyButton = screen.getByRole('button', { name: 'copy_to_clipboard' });
+ const copyButton = screen.getByRole('button', { name: 'Copy to clipboard' });
expect(copyButton).toBeInTheDocument();
});
});
import Clipboard from 'clipboard';
import React from 'react';
import { INTERACTIVE_TOOLTIP_DELAY } from '../helpers/constants';
-import { translate } from '../helpers/l10n';
+import { DiscreetInteractiveIcon, InteractiveIcon, InteractiveIconSize } from './InteractiveIcon';
+import Tooltip from './Tooltip';
import { ButtonSecondary } from './buttons';
import { CopyIcon } from './icons/CopyIcon';
import { IconProps } from './icons/Icon';
-import { DiscreetInteractiveIcon, InteractiveIcon, InteractiveIconSize } from './InteractiveIcon';
-import Tooltip from './Tooltip';
const COPY_SUCCESS_NOTIFICATION_LIFESPAN = 1000;
interface ButtonProps {
children?: React.ReactNode;
className?: string;
+ copiedLabel?: string;
+ copyLabel?: string;
copyValue: string;
icon?: React.ReactNode;
}
className,
children,
copyValue,
+ copiedLabel = 'Copied',
+ copyLabel = 'Copy',
}: ButtonProps) {
return (
<ClipboardBase>
{({ setCopyButton, copySuccess }) => (
- <Tooltip overlay={translate('copied_action')} visible={copySuccess}>
+ <Tooltip overlay={copiedLabel} visible={copySuccess}>
<ButtonSecondary
className={classNames('sw-select-none', className)}
data-clipboard-text={copyValue}
icon={icon}
innerRef={setCopyButton}
>
- {children ?? translate('copy')}
+ {children ?? copyLabel}
</ButtonSecondary>
</Tooltip>
)}
Icon?: React.ComponentType<IconProps>;
'aria-label'?: string;
className?: string;
+ copiedLabel?: string;
+ copyLabel?: string;
copyValue: string;
discreet?: boolean;
size?: InteractiveIconSize;
}
export function ClipboardIconButton(props: IconButtonProps) {
- const { className, copyValue, discreet, size = 'small', Icon = CopyIcon } = props;
+ const {
+ className,
+ copyValue,
+ discreet,
+ size = 'small',
+ Icon = CopyIcon,
+ copiedLabel = 'Copied',
+ copyLabel = 'Copy to clipboard',
+ } = props;
const InteractiveIconComponent = discreet ? DiscreetInteractiveIcon : InteractiveIcon;
return (
mouseEnterDelay={INTERACTIVE_TOOLTIP_DELAY}
overlay={
<div className="sw-w-abs-150 sw-text-center">
- {translate(copySuccess ? 'copied_action' : 'copy_to_clipboard')}
+ {copySuccess ? copiedLabel : copyLabel}
</div>
}
{...(copySuccess ? { visible: copySuccess } : undefined)}
>
<InteractiveIconComponent
Icon={Icon}
- aria-label={props['aria-label'] ?? translate('copy_to_clipboard')}
+ aria-label={props['aria-label'] ?? copyLabel}
className={className}
data-clipboard-text={copyValue}
innerRef={setCopyButton}