-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #31486 from JKobrynski/migrateCopyTextToClipboardT…
…oTypeScript [TS Migration] Migrate CopyTextToClipboard.js to TypeScript
- Loading branch information
Showing
3 changed files
with
46 additions
and
49 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters