Skip to content

Commit

Permalink
Merge pull request #31486 from JKobrynski/migrateCopyTextToClipboardT…
Browse files Browse the repository at this point in the history
…oTypeScript

[TS Migration] Migrate CopyTextToClipboard.js to TypeScript
  • Loading branch information
mountiny authored Dec 13, 2023
2 parents 1fd0989 + 42e7f61 commit 2782381
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 49 deletions.
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

0 comments on commit 2782381

Please sign in to comment.