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

feat: add button link component #219

Closed
wants to merge 3 commits into from
Closed
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
8 changes: 7 additions & 1 deletion components/Button/Button.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from 'react';
import { ComponentStory, ComponentMeta } from '@storybook/react';

import { ButtonForStory } from './Button';
import { ButtonForStory, LinkButton } from './Button';
import { Flex } from '../Flex';
import { Text } from '../Text';
import { InfoCircledIcon } from '@radix-ui/react-icons';
Expand Down Expand Up @@ -86,3 +86,9 @@ export const Waiting = Template.bind({});
Waiting.args = {
state: 'waiting',
};

const LinkTemplate: ComponentStory<typeof LinkButton> = (args) => (<LinkButton {...args}>Link</LinkButton>)
export const Link = LinkTemplate.bind({});
Link.args = {
href: `https://traefik.io`,
};
20 changes: 18 additions & 2 deletions components/Button/Button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import React from 'react';
import { styled, keyframes, CSS } from '../../stitches.config';
import { modifyVariantsForStory } from '../../utils/modifyVariantsForStory';

export const StyledButton = styled('button', {
const buttonStyles = {
// Reset
all: 'unset',
alignItems: 'center',
Expand Down Expand Up @@ -234,8 +234,12 @@ export const StyledButton = styled('button', {
size: 'medium',
variant: 'primary',
},
});
}

export const StyledLinkButton = styled('a', buttonStyles);
paulocfjunior marked this conversation as resolved.
Show resolved Hide resolved
export const StyledButton = styled('button', buttonStyles);

type LinkButtonVariants = VariantProps<typeof StyledLinkButton>;
type ButtonVariants = VariantProps<typeof StyledButton>;

const Waiting = styled('div', {
Expand Down Expand Up @@ -281,8 +285,20 @@ const Waiting = styled('div', {
},
});

type LinkButtonProps = React.AnchorHTMLAttributes<any> & LinkButtonVariants & { css?: CSS };
type ButtonProps = React.ButtonHTMLAttributes<any> & ButtonVariants & { css?: CSS };

export const LinkButton = React.forwardRef<React.ElementRef<typeof StyledLinkButton>, LinkButtonProps>(
({ children, ...props }, forwardedRef) => (
<StyledLinkButton {...props} ref={forwardedRef}>
<>
{children}
{props.state === 'waiting' && <Waiting size={props.size} />}
</>
</StyledLinkButton>
)
)

export const Button = React.forwardRef<React.ElementRef<typeof StyledButton>, ButtonProps>(
({ children, ...props }, forwardedRef) => {
return (
Expand Down
2 changes: 1 addition & 1 deletion index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export { AspectRatio } from '@radix-ui/react-aspect-ratio';
export { Badge } from './components/Badge';
export { Box } from './components/Box';
export { Bubble } from './components/Bubble';
export { Button } from './components/Button';
export { Button, LinkButton } from './components/Button';
export { Card } from './components/Card';
export { Checkbox } from './components/Checkbox';
// export { Code } from './components/Code';
Expand Down