Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Destructure LinkWrapper props to avoid passing them down #11

Merged
merged 1 commit into from
Jun 12, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions src/components/Link.js
Original file line number Diff line number Diff line change
Expand Up @@ -146,10 +146,15 @@ export function Link({ isButton, withArrow, containsIcon, LinkWrapper, children,
);

if (LinkWrapper) {
const StyledLinkWrapper = LinkA.withComponent(LinkWrapper);
const { inverse, nochrome, secondary, tertiary, ...linkWrapperProps } = rest;

return <StyledLinkWrapper {...linkWrapperProps}>{content}</StyledLinkWrapper>;
const StyledLinkWrapper = styled(
({ inverse, nochrome, secondary, tertiary, ...linkWrapperRest }) => (
<LinkWrapper {...linkWrapperRest} />
)
)`
${linkStyles};
`;

return <StyledLinkWrapper {...rest}>{content}</StyledLinkWrapper>;
}

if (isButton) {
Expand Down
13 changes: 12 additions & 1 deletion src/components/Link.stories.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import React from 'react';
import styled from 'styled-components';
import { storiesOf } from '@storybook/react';
import { action } from '@storybook/addon-actions';

Expand All @@ -7,6 +8,12 @@ import { Icon } from './Icon';
import { Link } from './Link';
import { StoryLinkWrapper } from './StoryLinkWrapper';

const CustomLink = styled(Link)`
&& {
color: red;
}
`;

const onLinkClick = action('onLinkClick');
storiesOf('Design System|Link', module)
.addParameters({ component: Link })
Expand Down Expand Up @@ -51,10 +58,14 @@ storiesOf('Design System|Link', module)
is actually a button
</Link>
<br />
<Link LinkWrapper={StoryLinkWrapper} href="http://storybook.js.org">
<Link tertiary LinkWrapper={StoryLinkWrapper} href="http://storybook.js.org">
has a LinkWrapper like GatsbyLink or NextLink
</Link>
<br />
<CustomLink tertiary LinkWrapper={StoryLinkWrapper} href="http://storybook.js.org">
has a LinkWrapper like GatsbyLink or NextLink with custom styling
</CustomLink>
<br />
<Link LinkWrapper={StoryLinkWrapper} href="http://storybook.js.org">
<Button>has a LinkWrapper like GatsbyLink or NextLink and a Button child</Button>
</Link>
Expand Down