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
Original file line number Diff line number Diff line change
@@ -1,44 +1,40 @@
import PropTypes from 'prop-types';
import React, {useCallback} from 'react';
import {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';
import withLocalize, {withLocalizePropTypes} from './withLocalize';
import {WithLocalizeProps} from './withLocalize';

const propTypes = {
type CopyTextToClipboardProps = WithLocalizeProps & {
/** The text to display and copy to the clipboard */
JKobrynski marked this conversation as resolved.
Show resolved Hide resolved
text: PropTypes.string.isRequired,
text: string;

/** Styles to apply to the text */
// eslint-disable-next-line react/forbid-prop-types
textStyles: PropTypes.arrayOf(PropTypes.object),

...withLocalizePropTypes,
textStyles?: StyleProp<TextStyle>;
};

const defaultProps = {
textStyles: [],
};
function CopyTextToClipboard(props: CopyTextToClipboardProps) {
const {translate} = useLocalize();
JKobrynski marked this conversation as resolved.
Show resolved Hide resolved

function CopyTextToClipboard(props) {
const copyToClipboard = useCallback(() => {
Clipboard.setString(props.text);
}, [props.text]);

return (
<PressableWithDelayToggle
text={props.text}
tooltipText={props.translate('reportActionContextMenu.copyToClipboard')}
tooltipTextChecked={props.translate('reportActionContextMenu.copied')}
tooltipText={translate('reportActionContextMenu.copyToClipboard')}
tooltipTextChecked={translate('reportActionContextMenu.copied')}
icon={Expensicons.Copy}
textStyles={props.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!

);
}

CopyTextToClipboard.propTypes = propTypes;
CopyTextToClipboard.defaultProps = defaultProps;
CopyTextToClipboard.displayName = 'CopyTextToClipboard';

export default withLocalize(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