Skip to content

Commit

Permalink
Merge pull request #205 from storybookjs/forward-ref
Browse files Browse the repository at this point in the history
Pass refs to componenent pickers for button, link
  • Loading branch information
kylesuss authored Aug 18, 2020
2 parents 3b16471 + 7fbbf43 commit e924d62
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 32 deletions.
28 changes: 12 additions & 16 deletions src/components/Button.js
Original file line number Diff line number Diff line change
Expand Up @@ -399,22 +399,18 @@ const ButtonLink = styled.a``;
// The main purpose of this component is to strip certain props that get passed
// down to the styled component, so that we don't end up passing them to a
// tag which would throw warnings for non-standard props.
function ButtonComponentPicker({
appearance,
ButtonWrapper,
containsIcon,
isLink,
isLoading,
isUnclickable,
size,
...rest
}) {
// Use the UnstyledButton here to avoid duplicating styles and creating
// specificity conflicts by first rendering the StyledLink higher up the chain
// and then re-rendering it through the 'as' prop.
const ButtonComponent = isLink ? ButtonLink : ButtonWrapper || UnstyledButton;
return <ButtonComponent {...rest} />;
}
const ButtonComponentPicker = forwardRef(
(
{ appearance, ButtonWrapper, containsIcon, isLink, isLoading, isUnclickable, size, ...rest },
ref
) => {
// Use the UnstyledButton here to avoid duplicating styles and creating
// specificity conflicts by first rendering the StyledLink higher up the chain
// and then re-rendering it through the 'as' prop.
const ButtonComponent = isLink ? ButtonLink : ButtonWrapper || UnstyledButton;
return <ButtonComponent {...rest} />;
}
);

const buttonStyleProps = {
appearance: PropTypes.oneOf(Object.values(APPEARANCES)),
Expand Down
28 changes: 12 additions & 16 deletions src/components/Link.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,22 +130,18 @@ const LinkButton = styled.button`
// The main purpose of this component is to strip certain props that get passed
// down to the styled component, so that we don't end up passing them to a
// tag which would throw warnings for non-standard props.
function LinkComponentPicker({
containsIcon,
inverse,
isButton,
LinkWrapper,
nochrome,
secondary,
tertiary,
...rest
}) {
// Use the UnstyledLink here to avoid duplicating styles and creating
// specificity conflicts by first rendering the StyledLink higher up the chain
// and then re-rendering it through the 'as' prop.
const LinkComponent = isButton ? LinkButton : LinkWrapper || UnstyledLink;
return <LinkComponent {...rest} />;
}
const LinkComponentPicker = forwardRef(
(
{ containsIcon, inverse, isButton, LinkWrapper, nochrome, secondary, tertiary, ...rest },
ref
) => {
// Use the UnstyledLink here to avoid duplicating styles and creating
// specificity conflicts by first rendering the StyledLink higher up the chain
// and then re-rendering it through the 'as' prop.
const LinkComponent = isButton ? LinkButton : LinkWrapper || UnstyledLink;
return <LinkComponent {...rest} />;
}
);

const linkStyleProps = {
containsIcon: PropTypes.bool,
Expand Down

0 comments on commit e924d62

Please sign in to comment.