diff --git a/src/component-library/TextLink/TextLink.stories.tsx b/src/component-library/TextLink/TextLink.stories.tsx new file mode 100644 index 0000000000..e76e18b70e --- /dev/null +++ b/src/component-library/TextLink/TextLink.stories.tsx @@ -0,0 +1,19 @@ +import { Meta, Story } from '@storybook/react'; + +import { TextLink, TextLinkProps } from '.'; + +const Template: Story = (args) => ; + +const Default = Template.bind({}); +Default.args = { + external: true, + to: 'https://interlay.io/', + children: 'Link' +}; + +export { Default }; + +export default { + title: 'Components/TextLink', + component: TextLink +} as Meta; diff --git a/src/component-library/TextLink/TextLink.style.tsx b/src/component-library/TextLink/TextLink.style.tsx new file mode 100644 index 0000000000..1fb3264656 --- /dev/null +++ b/src/component-library/TextLink/TextLink.style.tsx @@ -0,0 +1,14 @@ +import styled from 'styled-components'; + +import { resolveTextColor } from '../Text'; +import { Colors } from '../utils/prop-types'; + +type BaseTextLinkProps = { + $color?: Colors; +}; + +const BaseTextLink = styled.a` + color: ${({ $color }) => resolveTextColor($color)}; +`; + +export { BaseTextLink }; diff --git a/src/component-library/TextLink/TextLink.tsx b/src/component-library/TextLink/TextLink.tsx new file mode 100644 index 0000000000..c0c20707d0 --- /dev/null +++ b/src/component-library/TextLink/TextLink.tsx @@ -0,0 +1,27 @@ +import { forwardRef } from 'react'; +import { Link, LinkProps } from 'react-router-dom'; + +import { Colors } from '../utils/prop-types'; +import { BaseTextLink } from './TextLink.style'; + +type Props = { + color?: Colors; + external?: boolean; +}; + +type NativeAttrs = Omit; + +type TextLinkProps = Props & NativeAttrs; + +const TextLink = forwardRef( + ({ color = 'primary', external, to, ...props }, ref): JSX.Element => { + const linkProps: TextLinkProps = external ? { to: { pathname: to }, target: '_blank', rel: 'noreferrer' } : { to }; + + return ; + } +); + +TextLink.displayName = 'TextLink'; + +export { TextLink }; +export type { TextLinkProps }; diff --git a/src/component-library/TextLink/index.tsx b/src/component-library/TextLink/index.tsx new file mode 100644 index 0000000000..59c5bb6f04 --- /dev/null +++ b/src/component-library/TextLink/index.tsx @@ -0,0 +1,2 @@ +export type { TextLinkProps } from './TextLink'; +export { TextLink } from './TextLink'; diff --git a/src/component-library/index.tsx b/src/component-library/index.tsx index 56ef74b180..a7d760be75 100644 --- a/src/component-library/index.tsx +++ b/src/component-library/index.tsx @@ -26,6 +26,8 @@ export type { TabsItemProps, TabsProps } from './Tabs'; export { Tabs, TabsItem } from './Tabs'; export type { DlProps, TextProps } from './Text'; export { Dl, Em, H1, H2, H3, H4, H5, H6, P, Span, Strong } from './Text'; +export type { TextLinkProps } from './TextLink'; +export { TextLink } from './TextLink'; export type { ComponentLibraryTheme } from './theme'; export { theme } from './theme'; export type { TokenBalanceProps } from './TokenBalance'; diff --git a/src/component-library/utils/prop-types.ts b/src/component-library/utils/prop-types.ts index a8e7131065..2937f167bb 100644 --- a/src/component-library/utils/prop-types.ts +++ b/src/component-library/utils/prop-types.ts @@ -6,12 +6,16 @@ const status = tuple('error', 'warning', 'success'); const sizes = tuple('small', 'medium', 'large'); +export const colors = tuple('primary', 'secondary', 'tertiary'); + export type CTAVariants = typeof ctaVariants[number]; export type Status = typeof status[number]; export type Sizes = typeof sizes[number]; +export type Colors = typeof colors[number]; + export { ctaVariants, sizes, status }; export { tuple };