1import React, { ComponentType, forwardRef } from 'react';
2import { Linking, Platform } from 'react-native';
3
4import { LinkProps } from './Text.types';
5import Text from '../primitives/Text';
6
7export const A = forwardRef(({ href, target, download, rel, ...props }: LinkProps, ref) => {
8  const nativeProps = Platform.select<LinkProps>({
9    web: {
10      href,
11      hrefAttrs: {
12        target,
13        download,
14        rel,
15      },
16    },
17    default: {
18      onPress: (event) => {
19        props.onPress && props.onPress(event);
20        if (Platform.OS !== 'web' && href !== undefined) {
21          Linking.openURL(href);
22        }
23      },
24    },
25  });
26  return <Text accessibilityRole="link" {...props} {...nativeProps} ref={ref} />;
27}) as ComponentType<LinkProps>;
28