Skip to content

Commit

Permalink
homework3 Add types for base components
Browse files Browse the repository at this point in the history
  • Loading branch information
sosninroman committed Oct 11, 2024
1 parent 739b609 commit 23a0b09
Show file tree
Hide file tree
Showing 27 changed files with 203 additions and 172 deletions.
13 changes: 0 additions & 13 deletions src/shared/header/Header.jsx

This file was deleted.

10 changes: 0 additions & 10 deletions src/shared/header/Header.stories.js

This file was deleted.

11 changes: 11 additions & 0 deletions src/shared/header/Header.stories.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { Header } from './Header';
import type { Meta, StoryObj } from '@storybook/react';

const meta: Meta<typeof Header> = {
title: 'Otus/Common/Header',
component: Header,
};

export default meta;

export const Default: StoryObj<typeof Header> = {};
13 changes: 13 additions & 0 deletions src/shared/header/Header.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import React from 'react';
import './header.css';
import { Logo } from '../logo/Logo';

export const Header = (): React.ReactElement => {
return (
<header className="appheader">
<div className="appheader-content">
<Logo></Logo>
</div>
</header>
);
};
12 changes: 0 additions & 12 deletions src/shared/layout/Layout.jsx

This file was deleted.

15 changes: 0 additions & 15 deletions src/shared/layout/Layout.stories.js

This file was deleted.

16 changes: 16 additions & 0 deletions src/shared/layout/Layout.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import React from 'react';
import { Layout } from './Layout';
import type { Meta, StoryObj } from '@storybook/react';

const meta: Meta<typeof Layout> = {
title: 'Otus/Common/Layout',
component: Layout,
};

export default meta;

export const Default: StoryObj<typeof Layout> = {
args: {
children: [<div key={1} style={{ margin: 0, height: '500px' }} />],
},
};
16 changes: 16 additions & 0 deletions src/shared/layout/Layout.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import React from 'react';
import './layout.css';
import { Header } from '../header/Header';

interface LayoutContent {
children: React.ReactNode;
}

export const Layout = ({ children }: LayoutContent): React.ReactElement => {
return (
<div className="layout">
<Header></Header>
{children}
</div>
);
};
8 changes: 0 additions & 8 deletions src/shared/logo/Logo.jsx

This file was deleted.

10 changes: 0 additions & 10 deletions src/shared/logo/Logo.stories.js

This file was deleted.

11 changes: 11 additions & 0 deletions src/shared/logo/Logo.stories.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { Logo } from './Logo';
import type { Meta, StoryObj } from '@storybook/react';

const meta: Meta<typeof Logo> = {
title: 'Otus/Common/Logo',
component: Logo,
};

export default meta;

export const Default: StoryObj<typeof Logo> = {};
6 changes: 6 additions & 0 deletions src/shared/logo/Logo.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import React from 'react';
import './logo.css';

export const Logo = (): React.ReactElement => {
return <div className="logo" />;
};
16 changes: 0 additions & 16 deletions src/shared/modal/Modal.jsx

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { React } from 'react';
import React from 'react';
import { Modal } from './Modal';
import type { Meta, StoryObj } from '@storybook/react';

const meta = {
const meta: Meta<typeof Modal> = {
title: 'Otus/Common/Modal',
component: Modal,
argTypes: {
Expand All @@ -11,7 +12,7 @@ const meta = {

export default meta;

export const Default = {
export const Default: StoryObj<typeof Modal> = {
args: {
visible: true,
children: [
Expand Down
19 changes: 19 additions & 0 deletions src/shared/modal/Modal.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import React from 'react';
import './modal.css';

interface ModalProps {
visible: boolean;
children: React.ReactNode;
}

export const Modal = ({ visible, children }: ModalProps): React.ReactElement => {
if (!visible) return null;
return (
<div className="modal-background">
<div className="modal-dialog">
<span className="modal-close">&times;</span>
<div className="modal-body">{children}</div>
</div>
</div>
);
};
14 changes: 0 additions & 14 deletions src/shared/shopping/cartitem/CartItem.jsx

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { CartItem } from './CartItem';
import type { Meta, StoryObj } from '@storybook/react';

const meta = {
const meta: Meta<typeof CartItem> = {
title: 'Otus/Shopping/CartItem',
component: CartItem,
tags: ['autodocs'],
Expand All @@ -13,7 +14,7 @@ const meta = {

export default meta;

export const Default = {
export const Default: StoryObj<typeof CartItem> = {
args: {
title: 'Awesome thing',
},
Expand Down
18 changes: 18 additions & 0 deletions src/shared/shopping/cartitem/CartItem.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import React from 'react';
import { Trash2 } from 'lucide-react';
import './cartitem.css';

interface CartItemProps {
title: string;
}

export const CartItem = ({ title }: CartItemProps): React.ReactElement => {
return (
<div className="cart-item">
<p className="cart-item__title">{title}</p>
<div className="cart-item__remove-button">
<Trash2 color="red" />
</div>
</div>
);
};
17 changes: 0 additions & 17 deletions src/shared/shopping/itemcard/ItemCard.jsx

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { ItemCard } from './ItemCard';
import { Meta, StoryObj } from '@storybook/react';

const meta = {
const meta: Meta<typeof ItemCard> = {
title: 'Otus/Shopping/ItemCard',
component: ItemCard,
tags: ['autodocs'],
Expand All @@ -19,7 +20,7 @@ const meta = {

export default meta;

export const Default = {
export const Default: StoryObj<typeof ItemCard> = {
args: {
price: 100,
title: 'Awesome thing',
Expand Down
23 changes: 23 additions & 0 deletions src/shared/shopping/itemcard/ItemCard.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import React from 'react';
import { PurchaseButton } from '../purchasebutton/PurchaseButton';
import './itemcard.css';

interface ItemCardProps {
price: number;
title: string;
desc: string;
}

export const ItemCard = ({ price, title, desc }: ItemCardProps): React.ReactElement => {
return (
<div className="card">
<img className="card__image" src="https://prd.place/200/200" />
<p className="card__text card__title">{title}</p>
<p className="card__text card__description">{desc}</p>
<div className="card__price-group">
<p className="card__price">{price}</p>
<PurchaseButton additionalClass="card__button" />
</div>
</div>
);
};
23 changes: 0 additions & 23 deletions src/shared/shopping/itempage/ItemPage.jsx

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
import { ItemPage } from './ItemPage';
import { Meta, StoryObj } from '@storybook/react';

const meta = {
const meta: Meta<typeof ItemPage> = {
title: 'Otus/Shopping/ItemPage',
component: ItemPage,
tags: ['autodocs'],
};

export default meta;

export const Default = {
export const Default: StoryObj<typeof ItemPage> = {
args: {
price: 100,
title: 'Awesome thing',
Expand Down
28 changes: 28 additions & 0 deletions src/shared/shopping/itempage/ItemPage.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import React from 'react';
import { PurchaseButton } from '../purchasebutton/PurchaseButton';
import './itempage.css';

interface ItemPageProps {
price: number;
images: Array<number>;
category: string;
title: string;
desc: string;
}

export const ItemPage = ({ price, images, category, title, desc }: ItemPageProps) => {
return (
<div>
<div className="page__images">
{images.map((imageId) => {
return <img key={imageId} src={`https://prd.place/200/200?id=${imageId}`}></img>;
})}
</div>
<p>Item: {title}</p>
<p>Description: {desc}</p>
<p>Category: {category}</p>
<p>Price: {price}</p>
<PurchaseButton />
</div>
);
};
Loading

0 comments on commit 23a0b09

Please sign in to comment.