Skip to content

Commit da8288b

Browse files
committed
Add link copy component to claims form
1 parent f6b628f commit da8288b

2 files changed

Lines changed: 53 additions & 15 deletions

File tree

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
import { Text } from '@/src/common/components';
2+
import Icon from '@/src/common/components/Icon';
3+
import { Atoms, useTheme } from '@/src/common/theme';
4+
import * as Clipboard from 'expo-clipboard';
5+
import { useEffect, useRef, useState } from 'react';
6+
import { Pressable } from 'react-native';
7+
8+
export function CopyLinkComponent({ link }: { link: string }) {
9+
const { theme } = useTheme();
10+
const [copied, setCopied] = useState(false);
11+
const timeout = useRef<ReturnType<typeof setTimeout> | undefined>(undefined);
12+
13+
useEffect(() => () => clearTimeout(timeout.current), []);
14+
15+
const onCopy = () => {
16+
void Clipboard.setStringAsync(link);
17+
setCopied(true);
18+
clearTimeout(timeout.current);
19+
timeout.current = setTimeout(() => setCopied(false), 2000);
20+
};
21+
22+
return (
23+
<Pressable
24+
onPress={onCopy}
25+
style={({ hovered }) => [
26+
Atoms.flex_row,
27+
Atoms.items_center,
28+
Atoms.gap_sm,
29+
Atoms.p_md,
30+
Atoms.rounded_md,
31+
{
32+
backgroundColor: hovered
33+
? theme.palette.neutral_200
34+
: theme.palette.neutral_100,
35+
},
36+
]}
37+
>
38+
<Text
39+
variant="body"
40+
style={[Atoms.flex_1, theme.atoms.text, { fontFamily: 'monospace' }]}
41+
>
42+
{link}
43+
</Text>
44+
<Icon
45+
name={copied ? 'checkmark' : 'copy'}
46+
size={18}
47+
color={copied ? 'positive_500' : 'neutral_500'}
48+
/>
49+
</Pressable>
50+
);
51+
}

apps/polycentric/src/features/verifications/PlatformPicker.tsx

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import Animated, {
99
FadeOutDown,
1010
useAnimatedRef,
1111
} from 'react-native-reanimated';
12+
import { CopyLinkComponent } from './CopyLinkComponent';
1213
import { SelectChip } from './SelectChip';
1314
import { useScrollIntoView } from './VerificationsScrollContext';
1415

@@ -192,21 +193,7 @@ export function PlatformPicker() {
192193
/>
193194

194195
{/* Loop-back link the user adds to their profile. */}
195-
<View
196-
style={[
197-
Atoms.p_md,
198-
Atoms.rounded_md,
199-
{ backgroundColor: theme.palette.neutral_100 },
200-
]}
201-
>
202-
<Text
203-
variant="body"
204-
style={[theme.atoms.text, { fontFamily: 'monospace' }]}
205-
selectable={true}
206-
>
207-
{loopbackLink}
208-
</Text>
209-
</View>
196+
<CopyLinkComponent link={loopbackLink} />
210197
<Text variant="small" style={theme.atoms.text_neutral_medium}>
211198
{selected.generic
212199
? 'Add this link anywhere on your website.'

0 commit comments

Comments
 (0)