-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(TextLink): add component (#496)
- Loading branch information
1 parent
163b874
commit 0228f95
Showing
6 changed files
with
68 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { Meta, Story } from '@storybook/react'; | ||
|
||
import { TextLink, TextLinkProps } from '.'; | ||
|
||
const Template: Story<TextLinkProps> = (args) => <TextLink {...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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<BaseTextLinkProps>` | ||
color: ${({ $color }) => resolveTextColor($color)}; | ||
`; | ||
|
||
export { BaseTextLink }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<LinkProps, keyof Props | 'href'>; | ||
|
||
type TextLinkProps = Props & NativeAttrs; | ||
|
||
const TextLink = forwardRef<HTMLAnchorElement, TextLinkProps>( | ||
({ color = 'primary', external, to, ...props }, ref): JSX.Element => { | ||
const linkProps: TextLinkProps = external ? { to: { pathname: to }, target: '_blank', rel: 'noreferrer' } : { to }; | ||
|
||
return <BaseTextLink ref={ref} as={Link} $color={color} {...props} {...linkProps} />; | ||
} | ||
); | ||
|
||
TextLink.displayName = 'TextLink'; | ||
|
||
export { TextLink }; | ||
export type { TextLinkProps }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export type { TextLinkProps } from './TextLink'; | ||
export { TextLink } from './TextLink'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters