Skip to content

Commit

Permalink
🎨 improve Button example
Browse files Browse the repository at this point in the history
  • Loading branch information
Yago committed Dec 17, 2020
1 parent d1fdec0 commit c1b13b3
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 15 deletions.
10 changes: 2 additions & 8 deletions src/components/atoms/Button/Button.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import React from 'react';

import Button from './Button';
import Button, { Props } from './Button';

export default {
title: 'Atoms/Button',
component: Button,
};

const Template = (args) => <Button {...args} />;
const Template = (args: Props) => <Button {...args} />;

export const Primary = Template.bind({});
Primary.args = {
Expand All @@ -20,12 +20,6 @@ Secondary.args = {
label: 'Button',
};

export const Large = Template.bind({});
Large.args = {
size: 'large',
label: 'Button',
};

export const Small = Template.bind({});
Small.args = {
size: 'small',
Expand Down
26 changes: 19 additions & 7 deletions src/components/atoms/Button/Button.tsx
Original file line number Diff line number Diff line change
@@ -1,17 +1,29 @@
import React from 'react';

type Props = {
primary?: boolean,
size?: 'small' | 'medium' | 'large',
label: string,
onClick?: () => void,
}
export type Props = {
primary?: boolean;
size?: 'small' | 'medium';
label: string;
onClick?: () => void;
};

const Button = ({ primary, size, label, ...props }: Props): JSX.Element => {
const color = primary ? 'indigo' : 'gray';

const paddings = () => {
switch (size) {
case 'small':
return 'px-3 py-1';

default:
return 'px-5 py-3';
}
};

return (
<button
type="button"
className="inline-flex items-center justify-center px-5 py-3 border border-transparent text-base font-medium rounded-md text-white bg-indigo-600 hover:bg-indigo-700"
className={`inline-flex items-center justify-center ${paddings()} text-base font-medium text-white bg-${color}-600 border border-transparent rounded-md hover:bg-${color}-700`}
{...props}
>
{label}
Expand Down

0 comments on commit c1b13b3

Please sign in to comment.