Start working on button component

This commit is contained in:
Hazem Krimi
2021-04-10 00:01:20 +01:00
parent 2c55550b7c
commit b5042682a3
4 changed files with 143 additions and 6 deletions
+13 -1
View File
@@ -1,4 +1,6 @@
import { Route, Switch } from 'react-router-dom'; import { Route, Switch } from 'react-router-dom';
import { Button } from './components';
// import { Add } from './assets';
import GlobalStyles from './GlobalStyles'; import GlobalStyles from './GlobalStyles';
const App = () => { const App = () => {
@@ -7,7 +9,17 @@ const App = () => {
<GlobalStyles /> <GlobalStyles />
<Switch> <Switch>
<Route path='/' exact> <Route path='/' exact>
<h2>TEST</h2> <div style={{ margin: '2rem', width: '95vw' }}>
<Button
color='client'
// size='big'
variant='outlined'
text='Button'
// fullWidth
// iconLeft={<Add />}
onClick={() => {}}
/>
</div>
</Route> </Route>
</Switch> </Switch>
</> </>
+36 -2
View File
@@ -1,7 +1,41 @@
import { Wrapper } from './styles'; import { Wrapper } from './styles';
const Button = () => { type ButtonProps = Omit<React.AllHTMLAttributes<HTMLButtonElement>, 'size'> & {
return <Wrapper></Wrapper>; color: 'client' | 'productOwner' | 'developer' | 'admin';
size?: 'small' | 'big';
variant?: 'primary-action' | 'secondary-action' | 'outlined' | 'text';
iconLeft?: React.SVGProps<SVGSVGElement>;
iconRight?: React.SVGProps<SVGSVGElement>;
fullWidth?: boolean;
text: string;
onClick: () => void;
};
const Button = ({
color,
size = 'small',
variant = 'text',
iconLeft,
iconRight,
fullWidth = false,
text,
onClick,
}: ButtonProps) => {
return (
<Wrapper
color={color}
size={size}
variant={variant}
iconLeft={iconLeft || undefined}
iconRight={iconRight || undefined}
fullWidth={fullWidth}
onClick={onClick}
>
{iconLeft && iconLeft}
{text}
{iconRight && iconRight}
</Wrapper>
);
}; };
export default Button; export default Button;
+91 -2
View File
@@ -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<SVGSVGElement>;
iconRight?: React.SVGProps<SVGSVGElement>;
fullWidth?: boolean;
};
export const Wrapper = styled.button<WrapperProps>`
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;
`;
}
}}
`;
+3 -1
View File
@@ -1 +1,3 @@
export {}; import Button from './Button';
export { Button };