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

[TS Migration] Migrate CopyTextToClipboard.js to TypeScript #31486

Merged
Merged
Show file tree
Hide file tree
Changes from 6 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.copyEmailToClipboard')}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this the correct label in this case? copyEmailToClipboard? It can be other things than email right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

right, my bad

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
accessibilityLabel={translate('reportActionContextMenu.copyEmailToClipboard')}
accessibilityLabel={translate('reportActionContextMenu.copyToClipboard')}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated!

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
Loading