Skip to content
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
48 changes: 0 additions & 48 deletions src/components/CopyTextToClipboard.js

This file was deleted.

45 changes: 45 additions & 0 deletions src/components/CopyTextToClipboard.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import React, {useCallback} from 'react';
import {AccessibilityRole, StyleProp, TextStyle} from 'react-native';
import useLocalize from '@hooks/useLocalize';
import Clipboard from '@libs/Clipboard';
import * as Expensicons from './Icon/Expensicons';
import PressableWithDelayToggle from './Pressable/PressableWithDelayToggle';

type CopyTextToClipboardProps = {
/** The text to display and copy to the clipboard */
text: string;

/** Styles to apply to the text */
textStyles?: StyleProp<TextStyle>;

urlToCopy?: string;

accessibilityRole?: AccessibilityRole;
};

function CopyTextToClipboard({text, textStyles, urlToCopy, accessibilityRole}: CopyTextToClipboardProps) {
const {translate} = useLocalize();

const copyToClipboard = useCallback(() => {
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing -- nullish coalescing doesn't achieve the same result in this case
Clipboard.setString(urlToCopy || text);
}, [text, urlToCopy]);

return (
<PressableWithDelayToggle
text={text}
tooltipText={translate('reportActionContextMenu.copyToClipboard')}
tooltipTextChecked={translate('reportActionContextMenu.copied')}
icon={Expensicons.Copy}
textStyles={textStyles}
onPress={copyToClipboard}
accessible
accessibilityLabel={translate('reportActionContextMenu.copyToClipboard')}
accessibilityRole={accessibilityRole}
/>
);
}

CopyTextToClipboard.displayName = 'CopyTextToClipboard';

export default CopyTextToClipboard;
2 changes: 1 addition & 1 deletion src/components/Pressable/PressableWithDelayToggle.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ type PressableWithDelayToggleProps = PressableProps & {
text: string;

/** The text to display once the pressable is pressed */
textChecked: string;
textChecked?: string;

/** The tooltip text to display */
tooltipText: string;
Expand Down