-
Notifications
You must be signed in to change notification settings - Fork 65
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(component): add external prop to link component
- Loading branch information
1 parent
e6fce3e
commit 2acee91
Showing
7 changed files
with
131 additions
and
9 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 |
---|---|---|
@@ -1,17 +1,28 @@ | ||
import { OpenInNewIcon } from '@bigcommerce/big-design-icons'; | ||
import React, { memo, Ref } from 'react'; | ||
|
||
import { MarginProps } from '../../mixins'; | ||
|
||
import { StyledLink } from './styled'; | ||
|
||
export type LinkProps = React.AnchorHTMLAttributes<HTMLAnchorElement> & MarginProps; | ||
export interface LinkProps extends React.AnchorHTMLAttributes<HTMLAnchorElement>, MarginProps { | ||
external?: boolean; | ||
} | ||
|
||
interface PrivateProps { | ||
forwardedRef: Ref<HTMLAnchorElement>; | ||
isExternal?: boolean; | ||
} | ||
|
||
const StyleableLink: React.FC<LinkProps & PrivateProps> = memo(props => <StyledLink {...props} />); | ||
|
||
export const Link = React.forwardRef<HTMLAnchorElement, LinkProps>((props, ref) => ( | ||
<StyleableLink {...props} forwardedRef={ref} /> | ||
)); | ||
export const Link = React.forwardRef<HTMLAnchorElement, LinkProps>(({ children, external, ...props }, ref) => { | ||
const isExternal = external && props.target === '_blank'; | ||
|
||
return ( | ||
<StyleableLink {...props} isExternal={isExternal} forwardedRef={ref}> | ||
{isExternal ? <span>{children}</span> : children} | ||
{isExternal && <OpenInNewIcon size="medium" />} | ||
</StyleableLink> | ||
); | ||
}); |
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
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 |
---|---|---|
@@ -1,18 +1,29 @@ | ||
import { theme as defaultTheme } from '@bigcommerce/big-design-theme'; | ||
import styled from 'styled-components'; | ||
import styled, { css } from 'styled-components'; | ||
|
||
import { withMargins } from '../../mixins'; | ||
|
||
import { LinkProps } from './Link'; | ||
|
||
export const StyledLink = styled.a<LinkProps>` | ||
export const StyledLink = styled.a<LinkProps & { isExternal?: boolean }>` | ||
${withMargins()}; | ||
color: ${({ theme }) => theme.colors.primary}; | ||
cursor: pointer; | ||
font-size: ${({ theme }) => theme.typography.fontSize.medium}; | ||
font-weight: ${({ theme }) => theme.typography.fontWeight.regular}; | ||
text-decoration: none; | ||
${({ isExternal, theme }) => | ||
isExternal && | ||
css` | ||
display: inline-flex; | ||
align-items: center; | ||
svg { | ||
margin-left: ${theme.spacing.xxSmall}; | ||
} | ||
`} | ||
`; | ||
|
||
StyledLink.defaultProps = { theme: defaultTheme }; |
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,17 @@ | ||
import { Code, NextLink, Prop, PropTable, PropTableWrapper } from '../components'; | ||
|
||
const linkProps: Prop[] = [ | ||
{ | ||
name: 'external', | ||
types: 'boolean', | ||
description: ( | ||
<> | ||
Shows and external icons When the <Code primary>external</Code> flag is set and target="_blank". | ||
</> | ||
), | ||
}, | ||
]; | ||
|
||
export const LinkPropTable: React.FC<PropTableWrapper> = props => ( | ||
<PropTable title="Link" propList={linkProps} {...props} /> | ||
); |
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