Skip to content

Commit

Permalink
fix: button logic
Browse files Browse the repository at this point in the history
  • Loading branch information
Federico Zivolo committed Dec 10, 2018
1 parent 20c534d commit 16d5e71
Showing 1 changed file with 18 additions and 13 deletions.
31 changes: 18 additions & 13 deletions packages/react-core/src/Button/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,23 @@ const reset = css`
color: inherit;
`;

const BaseButton = styled.button`
const Button = styled(
({ to, href, transparent, size, importance, disabled, ...props }: Props) => {
let Tag, specificProps;
if (to && !disabled) {
Tag = Link;
specificProps = { to };
} else if ((href || to) && !disabled) {
Tag = 'a';
specificProps = { href };
} else {
Tag = 'button';
specificProps = { disabled };
}

return <Tag {...specificProps} {...props} />;
}
)`
${reset}
${textStyles('normal', 'bold')}
Expand Down Expand Up @@ -145,21 +161,10 @@ const BaseButton = styled.button`
}
`;

const Button = (props: Props) => {
let tag;
if (props.to && !props.disabled) {
tag = Link;
} else if (props.href || (props.to && props.disabled)) {
tag = 'a';
} else {
tag = 'button';
}

return <BaseButton as={tag} {...props} />;
};
Button.defaultProps = {
importance: 'primary',
size: 'regular',
};

// @component
export default Button;

0 comments on commit 16d5e71

Please sign in to comment.