Skip to content

Commit

Permalink
feat: add button
Browse files Browse the repository at this point in the history
  • Loading branch information
CraftyDragon678 committed Nov 9, 2020
1 parent e86a21e commit c2382da
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 29 deletions.
16 changes: 4 additions & 12 deletions src/components/Button.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,22 +1,14 @@
import React from "react";
import { text } from "@storybook/addon-knobs";
import { action } from "@storybook/addon-actions";
import { text, select } from "@storybook/addon-knobs";
import Button from "./Button";

export default {
title: "Button",
component: Button,
};

export const Text = () => {
export const Simple = () => {
const content = text("content", "button!");
return <Button>{content}</Button>;
const size = select("size", ["short", "medium", "long"], "medium");
return <Button size={size}>{content}</Button>;
};

export const Emoji = () => (
<Button onClick={action("clicked")}>
<span role="img" aria-label="so cool">
😀 😎 👍 💯
</span>
</Button>
);
44 changes: 27 additions & 17 deletions src/components/Button.tsx
Original file line number Diff line number Diff line change
@@ -1,21 +1,31 @@
import React from 'react'
import css from '@emotion/css';
import variables from "../scss/_variables.scss";
import styled from '@emotion/styled';
import variables from '../styles/variables';

const style = {
btn: css`
height: 35px;
padding: 0 20px;
border: 0;
background: ${variables.yellow};
`,
}
type TButtonSize = 'short' | 'medium' | 'long' | number;

export const Button: React.FC = ({ children }) => {
console.log(style.btn);
return (
<button css={style.btn}>
{children}
</button>
)
interface IButton {
size?: TButtonSize;
}

const getWidth = (size?: TButtonSize) => (
!size || size === "medium" ? "100px"
: size === "long" ? "140px"
: size === "short" ? "70px"
: `${size}px`
);

const buttonStyle = css`
height: 40px;
border: none;
border-radius: 4px;
padding: 0;
background-color: ${variables.blue};
color: white;
`;

export default styled.button<IButton>`
${buttonStyle}
width: ${({ size }) => getWidth(size)};
`;

0 comments on commit c2382da

Please sign in to comment.