-
Notifications
You must be signed in to change notification settings - Fork 100
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(TextLink): Add TextLink and TextLinkRenderer components (#102)
- Loading branch information
1 parent
9b21dc7
commit 29ae7ae
Showing
20 changed files
with
173 additions
and
13 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
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 |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import React from 'react'; | ||
import { Link as ReactRouterLink, LinkProps } from 'react-router-dom'; | ||
import { TextLinkRenderer, TextLink } from '../../../lib/components'; | ||
|
||
export const Link = (props: LinkProps) => ( | ||
<TextLinkRenderer> | ||
{textLinkProps => <ReactRouterLink {...props} {...textLinkProps} />} | ||
</TextLinkRenderer> | ||
); | ||
|
||
export const ExternalLink = 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import React from 'react'; | ||
import TextLink from './TextLink'; | ||
import Text from '../Text/Text'; | ||
import { ComponentDocs } from '../../../docs/src/types'; | ||
|
||
const docs: ComponentDocs = { | ||
examples: [ | ||
{ | ||
label: 'Standard Text Link', | ||
render: () => ( | ||
<Text> | ||
<TextLink href="">Link</TextLink> | ||
</Text> | ||
) | ||
} | ||
] | ||
}; | ||
|
||
export default docs; |
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 React, { Component, AllHTMLAttributes } from 'react'; | ||
import { Omit } from 'utility-types'; | ||
import TextLinkRenderer from '../TextLinkRenderer/TextLinkRenderer'; | ||
|
||
type AnchorProps = AllHTMLAttributes<HTMLAnchorElement>; | ||
export interface TextLinkProps | ||
extends Omit<AnchorProps, 'className' | 'style'> {} | ||
|
||
export default class TextLink extends Component<TextLinkProps> { | ||
static displayName = 'TextLink'; | ||
|
||
render() { | ||
return ( | ||
<TextLinkRenderer> | ||
{props => <a {...this.props} {...props} />} | ||
</TextLinkRenderer> | ||
); | ||
} | ||
} |
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,8 @@ | ||
export default { | ||
'.textDecoration': { | ||
textDecoration: 'none', | ||
'&:hover': { | ||
textDecoration: 'underline' | ||
} | ||
} | ||
}; |
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,3 @@ | ||
// This file is automatically generated. | ||
// Please do not change this file! | ||
export const textDecoration: string; |
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,43 @@ | ||
import React from 'react'; | ||
import { Link } from 'react-router-dom'; | ||
import TextLinkRenderer from './TextLinkRenderer'; | ||
import Text from '../Text/Text'; | ||
import { ComponentDocs } from '../../../docs/src/types'; | ||
|
||
const docs: ComponentDocs = { | ||
examples: [ | ||
{ | ||
label: 'TextLink with Custom Renderer', | ||
render: () => ( | ||
<Text> | ||
<TextLinkRenderer> | ||
{textLinkProps => ( | ||
<Link to="" {...textLinkProps}> | ||
Link | ||
</Link> | ||
)} | ||
</TextLinkRenderer> | ||
</Text> | ||
), | ||
code: ` | ||
import React from 'react'; | ||
import { Link } from 'react-router-dom'; | ||
import { TextLinkRenderer } from 'braid-design-system'; | ||
export default () => ( | ||
<Text> | ||
<TextLinkRenderer> | ||
{textLinkProps => ( | ||
<Link to="/" {...textLinkProps}> | ||
Link | ||
</Link> | ||
)} | ||
</TextLinkRenderer> | ||
</Text> | ||
); | ||
` | ||
} | ||
] | ||
}; | ||
|
||
export default docs; |
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,35 @@ | ||
import React, { Component, ReactNode, CSSProperties } from 'react'; | ||
import classnames from 'classnames'; | ||
import ThemeConsumer from '../ThemeConsumer/ThemeConsumer'; | ||
import styles from './TextLinkRenderer.css.js'; | ||
|
||
interface StyleProps { | ||
style: CSSProperties; | ||
className: string; | ||
} | ||
export interface TextLinkRendererProps { | ||
children: (styleProps: StyleProps) => ReactNode; | ||
} | ||
|
||
export default class TextLinkRenderer extends Component<TextLinkRendererProps> { | ||
static displayName = 'TextLinkRenderer'; | ||
|
||
render() { | ||
const { children } = this.props; | ||
|
||
return ( | ||
<ThemeConsumer> | ||
{theme => | ||
children({ | ||
style: {}, | ||
className: classnames([ | ||
theme.atoms.reset.a, | ||
theme.atoms.color.link, | ||
styles.textDecoration | ||
]) | ||
}) | ||
} | ||
</ThemeConsumer> | ||
); | ||
} | ||
} |
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
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
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
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