-
Notifications
You must be signed in to change notification settings - Fork 538
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1011 from primer/VanAnderson/convert-link-component
convert link component to typescript
- Loading branch information
Showing
6 changed files
with
198 additions
and
73 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,5 @@ | ||
--- | ||
"@primer/components": patch | ||
--- | ||
|
||
Migrate `Link` to TypeScript |
This file was deleted.
Oops, something went wrong.
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,76 @@ | ||
import React from 'react' | ||
import PropTypes from 'prop-types' | ||
import styled from 'styled-components' | ||
import {system} from 'styled-system' | ||
import {COMMON, TYPOGRAPHY, get, SystemCommonProps, SystemTypographyProps} from './constants' | ||
import sx, {SxProp} from './sx' | ||
import theme from './theme' | ||
import {ComponentProps} from './utils/types' | ||
|
||
type StyledLinkProps = { | ||
hoverColor?: string | ||
muted?: boolean | ||
underline?: boolean | ||
} & SystemCommonProps & | ||
SxProp & | ||
SystemTypographyProps | ||
|
||
const buttonStyles = ` | ||
display: inline-block; | ||
padding: 0; | ||
font-size: inherit; | ||
white-space: nowrap; | ||
cursor: pointer; | ||
user-select: none; | ||
background-color: transparent; | ||
border: 0; | ||
appearance: none; | ||
` | ||
|
||
const hoverColor = system({ | ||
hoverColor: { | ||
property: 'color', | ||
scale: 'colors' | ||
} | ||
}) | ||
|
||
const Link = styled.a<StyledLinkProps>` | ||
color: ${props => (props.muted ? get('colors.gray.6')(props) : get('colors.blue.5')(props))}; | ||
text-decoration: ${props => (props.underline ? 'underline' : 'none')}; | ||
&:hover { | ||
text-decoration: ${props => (props.muted ? 'none' : 'underline')}; | ||
${props => (props.hoverColor ? hoverColor : props.muted ? `color: ${get('colors.blue.5')(props)}` : '')}; | ||
} | ||
&:is(button) { | ||
display: inline-block; | ||
padding: 0; | ||
font-size: inherit; | ||
white-space: nowrap; | ||
cursor: pointer; | ||
user-select: none; | ||
background-color: transparent; | ||
border: 0; | ||
appearance: none; | ||
} | ||
${TYPOGRAPHY}; | ||
${COMMON}; | ||
${sx}; | ||
` | ||
|
||
Link.defaultProps = { | ||
theme | ||
} | ||
|
||
Link.propTypes = { | ||
hoverColor: PropTypes.string, | ||
href: PropTypes.string, | ||
muted: PropTypes.bool, | ||
theme: PropTypes.object, | ||
underline: PropTypes.bool, | ||
...TYPOGRAPHY.propTypes, | ||
...COMMON.propTypes, | ||
...sx.propTypes | ||
} | ||
|
||
export type LinkProps = ComponentProps<typeof Link> | ||
export default Link |
File renamed without changes.
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
2047322
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs: