feat: refactor project structure

Refactored the project structure so that each page has its own tree of components and a global "Components" folder for the components that is used by more than one page.
- Added an "assets" directory that exports all static images/icons/fonts/...etc
This commit is contained in:
MTG2000
2021-12-30 15:12:40 +02:00
parent 5ae1da6369
commit 43bfab177e
51 changed files with 71 additions and 60 deletions

View File

@@ -0,0 +1,40 @@
import { ComponentStory, ComponentMeta } from '@storybook/react';
import Button from './Button';
export default {
title: 'Shared/Button',
component: Button,
} as ComponentMeta<typeof Button>;
const Template: ComponentStory<typeof Button> = (args) => <Button {...args} >Click Me 🔥</Button>;
export const Default = Template.bind({});
export const Primary = Template.bind({});
Primary.args = {
color: 'primary'
}
export const Gray = Template.bind({});
Gray.args = {
color: 'gray'
}
export const MediumSize = Template.bind({});
MediumSize.args = {
size: 'md'
}
export const FullWidth = Template.bind({});
FullWidth.args = {
fullWidth: true
}
export const Link = Template.bind({});
Link.args = {
href: '#'
}

View File

@@ -0,0 +1,32 @@
import { ReactNode } from 'react';
import { Link } from 'react-router-dom'
interface Props {
color?: 'primary' | 'white' | 'gray'
size?: 'md' | 'lg'
children: ReactNode;
href?: string;
fullWidth?: boolean;
onClick?: () => void;
className?: string
}
export default function Button(props: Props) {
let classes = "btn inline-block";
if (props.color === 'primary') classes += ' btn-primary';
else if (props.color === 'gray') classes += ' btn-gray';
if (props.size === 'md') classes += ' py-12 px-24';
if (props.fullWidth) classes += ' w-full'
const handleClick = () => {
if (props.onClick) props.onClick();
}
return (
props.href ? <Link to={props.href} className={`${classes} ${props.className}`} onClick={handleClick}>{props.children}</Link> : <button className={`${classes} ${props.className}`} onClick={handleClick}>{props.children}</button>
)
}