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

Add iconOnly mode to CopyButton #2733

Merged
merged 1 commit into from
Jan 14, 2025
Merged
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
34 changes: 32 additions & 2 deletions components/CopyButton.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
import * as React from 'react';
import { Platform } from 'react-native';
import { Platform, TouchableOpacity, ViewStyle } from 'react-native';
import { Icon } from 'react-native-elements';
import Clipboard from '@react-native-clipboard/clipboard';
import Button from './../components/Button';
import { localeString } from './../utils/LocaleUtils';
import { themeColor } from './../utils/ThemeUtils';

interface CopyButtonProps {
title?: string;
copyValue: string;
icon?: any;
noUppercase?: boolean;
iconOnly?: boolean;
iconSize?: number;
copyIconContainerStyle?: ViewStyle;
}

interface CopyButtonState {
Expand Down Expand Up @@ -52,12 +57,37 @@ export default class CopyButton extends React.Component<

render() {
const { copied } = this.state;
const { title, icon, noUppercase } = this.props;
const {
title,
icon,
noUppercase,
iconOnly,
iconSize,
copyIconContainerStyle
} = this.props;

const buttonTitle = copied
? localeString('components.CopyButton.copied')
: title || localeString('components.CopyButton.copy');

if (iconOnly) {
return (
<TouchableOpacity
// "padding: 5" leads to a larger area where users can click on
// "copyIconContainerStyle" allows contextual spacing (marginRight)
// when used alongside ShareButton
style={[{ padding: 5 }, copyIconContainerStyle]}
onPress={() => this.copyToClipboard()}
>
<Icon
name={copied ? 'check' : 'content-copy'}
size={iconSize ?? 27}
color={themeColor('secondaryText')}
/>
</TouchableOpacity>
);
}

return (
<Button
title={buttonTitle}
Expand Down
Loading