From b5042682a300f8dd9384a427c50fceb0499b4397 Mon Sep 17 00:00:00 2001 From: Hazem Krimi Date: Sat, 10 Apr 2021 00:01:20 +0100 Subject: [PATCH] Start working on button component --- src/App.tsx | 14 ++++- src/components/Button/index.tsx | 38 +++++++++++++- src/components/Button/styles.ts | 93 ++++++++++++++++++++++++++++++++- src/components/index.tsx | 4 +- 4 files changed, 143 insertions(+), 6 deletions(-) diff --git a/src/App.tsx b/src/App.tsx index b0a2f38..711bd8a 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -1,4 +1,6 @@ import { Route, Switch } from 'react-router-dom'; +import { Button } from './components'; +// import { Add } from './assets'; import GlobalStyles from './GlobalStyles'; const App = () => { @@ -7,7 +9,17 @@ const App = () => { -

TEST

+
+
diff --git a/src/components/Button/index.tsx b/src/components/Button/index.tsx index 9bfb9aa..78d7e40 100644 --- a/src/components/Button/index.tsx +++ b/src/components/Button/index.tsx @@ -1,7 +1,41 @@ import { Wrapper } from './styles'; -const Button = () => { - return ; +type ButtonProps = Omit, 'size'> & { + color: 'client' | 'productOwner' | 'developer' | 'admin'; + size?: 'small' | 'big'; + variant?: 'primary-action' | 'secondary-action' | 'outlined' | 'text'; + iconLeft?: React.SVGProps; + iconRight?: React.SVGProps; + fullWidth?: boolean; + text: string; + onClick: () => void; +}; + +const Button = ({ + color, + size = 'small', + variant = 'text', + iconLeft, + iconRight, + fullWidth = false, + text, + onClick, +}: ButtonProps) => { + return ( + + {iconLeft && iconLeft} + {text} + {iconRight && iconRight} + + ); }; export default Button; diff --git a/src/components/Button/styles.ts b/src/components/Button/styles.ts index 14ea300..cf9aeee 100644 --- a/src/components/Button/styles.ts +++ b/src/components/Button/styles.ts @@ -1,3 +1,92 @@ -import styled from 'styled-components'; +import styled, { css } from 'styled-components'; -export const Wrapper = styled.div``; +type WrapperProps = { + color: 'client' | 'productOwner' | 'developer' | 'admin'; + size?: 'small' | 'big'; + variant?: 'primary-action' | 'secondary-action' | 'outlined' | 'text'; + iconLeft?: React.SVGProps; + iconRight?: React.SVGProps; + fullWidth?: boolean; +}; + +export const Wrapper = styled.button` + cursor: pointer; + outline: none; + border: none; + border-radius: 6px; + background: none; + font-weight: bold; + + ${({ size }) => { + switch (size) { + case 'small': + return css` + padding: 0.625rem 1.875rem; + font-size: 1rem; + `; + case 'big': + return css` + padding: 0.625rem 1.875rem; + font-size: 1.25rem; + `; + default: + return css` + padding: 0.625rem 1.875rem; + font-size: 1rem; + `; + } + }} + + ${({ fullWidth }) => + fullWidth && + css` + width: 100%; + font-size: 1.25rem; + `}; + + ${({ variant, color, theme }) => { + switch (variant) { + case 'primary-action': + return css` + background: ${theme.colors[color].main}; + color: ${theme.colors.white.main}; + + &:hover { + background: ${theme.colors[color].dark}; + } + `; + case 'secondary-action': + return css` + background: ${theme.colors[color].light}; + color: #262628; + + &:hover { + color: ${theme.colors.white.main}; + } + `; + case 'outlined': + return css` + background: none; + color: ${theme.colors[color].main}; + border: 2px solid ${theme.colors[color].main}; + + &:hover { + background: ${theme.colors[color].main}; + color: ${theme.colors.white.main}; + } + `; + case 'text': + return css` + background: none; + color: ${theme.colors[color].main}; + padding: 0; + `; + default: + return css` + background: none; + color: ${theme.colors[color].main}; + padding: 0; + `; + } + }} +`; diff --git a/src/components/index.tsx b/src/components/index.tsx index cb0ff5c..d0db3c1 100644 --- a/src/components/index.tsx +++ b/src/components/index.tsx @@ -1 +1,3 @@ -export {}; +import Button from './Button'; + +export { Button };