Skip to content

Commit

Permalink
fix(TextLink): Add TextLink and TextLinkRenderer components (#102)
Browse files Browse the repository at this point in the history
  • Loading branch information
markdalgleish authored Feb 22, 2019
1 parent 9b21dc7 commit 29ae7ae
Show file tree
Hide file tree
Showing 20 changed files with 173 additions and 13 deletions.
12 changes: 4 additions & 8 deletions docs/src/App/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ import * as themes from '../../../lib/themes';
import * as components from '../../../lib/components';
import React, { Component } from 'react';
import { withRouter, Route, RouteComponentProps } from 'react-router';
import { Link } from 'react-router-dom';
import classnames from 'classnames';
import Logo from './Logo/Logo';
import ComponentRoute from './ComponentRoute/ComponentRoute';
import { Link, ExternalLink } from './Link';
import styles from './App.css.js';

const { ThemeProvider, Text, Box, BulletList, Bullet } = components;
Expand Down Expand Up @@ -55,7 +55,7 @@ export default withRouter(
paddingRight="gutter"
>
<div style={{ position: 'relative' }}>
<Link to="/" style={{ display: 'inline-block' }}>
<Link to="/">
<Logo />
</Link>

Expand Down Expand Up @@ -111,19 +111,17 @@ export default withRouter(
<Box paddingBottom="small">
<BulletList>
<Bullet>
<a
style={{ color: 'inherit' }}
<ExternalLink
href="https://github.com/seek-oss/braid-design-system"
target="_blank"
rel="noopener noreferrer"
onClick={this.closeMenu}
>
Source
</a>
</ExternalLink>
</Bullet>
<Bullet>
<Link
style={{ color: 'inherit' }}
to="/playroom"
target="_blank"
onClick={this.closeMenu}
Expand All @@ -146,7 +144,6 @@ export default withRouter(
.map(componentName => (
<Bullet key={componentName}>
<Link
style={{ color: 'inherit' }}
to={`/components/${componentName}`}
onClick={this.closeMenu}
>
Expand All @@ -168,7 +165,6 @@ export default withRouter(
.map(iconName => (
<Bullet key={iconName}>
<Link
style={{ color: 'inherit' }}
to={`/icons/${iconName}`}
onClick={this.closeMenu}
>
Expand Down
11 changes: 8 additions & 3 deletions docs/src/App/ComponentRoute/ComponentRoute.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import React, { Component } from 'react';
import reactElementToJSXString from 'react-element-to-jsx-string';
import dedent from 'dedent';
import ComponentProps from '../ComponentProps/ComponentProps';
import { ExternalLink } from '../Link';
import { ThemeProvider, Box, Text } from '../../../../lib/components';
import {
wireframe,
Expand Down Expand Up @@ -81,7 +82,7 @@ export default class ComponentRoute extends Component<ComponentRouteProps> {
}}
>
<Text component="pre" color="white">
{render
{render && !code
? reactElementToJSXString(render({ id: 'id' }), {
useBooleanShorthandSyntax: false,
showDefaultProps: false,
Expand All @@ -103,9 +104,13 @@ export default class ComponentRoute extends Component<ComponentRouteProps> {
</Box>
<Box paddingBottom="large">
<Text>
<a href={sourceUrl} target="_blank" rel="noopener noreferrer">
<ExternalLink
href={sourceUrl}
target="_blank"
rel="noopener noreferrer"
>
View on GitHub
</a>
</ExternalLink>
</Text>
</Box>
</Box>
Expand Down
11 changes: 11 additions & 0 deletions docs/src/App/Link.tsx
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;
19 changes: 19 additions & 0 deletions lib/components/TextLink/TextLink.docs.tsx
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;
19 changes: 19 additions & 0 deletions lib/components/TextLink/TextLink.tsx
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>
);
}
}
8 changes: 8 additions & 0 deletions lib/components/TextLinkRenderer/TextLinkRenderer.css.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
export default {
'.textDecoration': {
textDecoration: 'none',
'&:hover': {
textDecoration: 'underline'
}
}
};
3 changes: 3 additions & 0 deletions lib/components/TextLinkRenderer/TextLinkRenderer.css.js.d.ts
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;
43 changes: 43 additions & 0 deletions lib/components/TextLinkRenderer/TextLinkRenderer.docs.tsx
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;
35 changes: 35 additions & 0 deletions lib/components/TextLinkRenderer/TextLinkRenderer.tsx
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>
);
}
}
4 changes: 4 additions & 0 deletions lib/components/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ export { default as Radio } from './Radio/Radio';
export { default as Reset } from './Reset/Reset';
export { default as Strong } from './Strong/Strong';
export { default as Text } from './Text/Text';
export { default as TextLink } from './TextLink/TextLink';
export {
default as TextLinkRenderer
} from './TextLinkRenderer/TextLinkRenderer';
export { default as ChevronIcon } from './icons/ChevronIcon/ChevronIcon';
export { default as ErrorIcon } from './icons/ErrorIcon/ErrorIcon';
export { default as InfoIcon } from './icons/InfoIcon/InfoIcon';
Expand Down
5 changes: 4 additions & 1 deletion lib/stories/all.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { storiesOf } from 'sku/@storybook/react';
import React from 'react';
import { BrowserRouter } from 'react-router-dom';
import values from 'lodash/values';
import * as themes from '../themes';
import { ThemeProvider } from '../components';
Expand Down Expand Up @@ -27,7 +28,9 @@ req.keys().forEach(filename => {

values(themes).forEach(theme => {
stories.add(`${label} (${theme.name})`, () => (
<ThemeProvider theme={theme}>{render({ id: 'id' })}</ThemeProvider>
<BrowserRouter>
<ThemeProvider theme={theme}>{render({ id: 'id' })}</ThemeProvider>
</BrowserRouter>
));
});
});
Expand Down
6 changes: 6 additions & 0 deletions lib/themes/jobStreet/atoms/color.css.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
export default {
'.link': {
color: '#1c3f94',
'&:hover,&:focus': {
color: '#142d69'
}
},
'.black': { color: '#333' },
'.white': { color: '#fff' },
'.critical': { color: 'red' },
Expand Down
1 change: 1 addition & 0 deletions lib/themes/jobStreet/atoms/color.css.js.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
export const black: string;
export const critical: string;
export const formAccent: string;
export const link: string;
export const neutral: string;
export const positive: string;
export const secondary: string;
Expand Down
1 change: 1 addition & 0 deletions lib/themes/seekAnz/atoms/color.css.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export default {
'.link': { color: '#2765cf' },
'.black': { color: '#1c1c1c' },
'.white': { color: '#fff' },
'.critical': { color: '#e60278' },
Expand Down
1 change: 1 addition & 0 deletions lib/themes/seekAnz/atoms/color.css.js.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
export const black: string;
export const critical: string;
export const formAccent: string;
export const link: string;
export const neutral: string;
export const positive: string;
export const secondary: string;
Expand Down
1 change: 1 addition & 0 deletions lib/themes/seekAsia/atoms/color.css.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
} from './private/palette';

export default {
'.link': { color: blue2 },
'.black': { color: black },
'.white': { color: white },
'.critical': { color: alert },
Expand Down
1 change: 1 addition & 0 deletions lib/themes/seekAsia/atoms/color.css.js.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
export const black: string;
export const critical: string;
export const formAccent: string;
export const link: string;
export const neutral: string;
export const positive: string;
export const secondary: string;
Expand Down
3 changes: 2 additions & 1 deletion lib/themes/theme.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ export type ColorVariants =
| 'positive'
| 'secondary'
| 'formAccent'
| 'neutral';
| 'neutral'
| 'link';
type FillVariants =
| 'currentColor'
| 'formAccent'
Expand Down
1 change: 1 addition & 0 deletions lib/themes/wireframe/atoms/color.css.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export default {
'.link': { color: '#4c77bb' },
'.black': { color: '#2b2b2b' },
'.white': { color: 'white' },
'.critical': { color: 'red' },
Expand Down
1 change: 1 addition & 0 deletions lib/themes/wireframe/atoms/color.css.js.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
export const black: string;
export const critical: string;
export const formAccent: string;
export const link: string;
export const neutral: string;
export const positive: string;
export const secondary: string;
Expand Down

0 comments on commit 29ae7ae

Please sign in to comment.