add features

parent 40b8111f
This source diff could not be displayed because it is too large. You can view the blob instead.
......@@ -10,8 +10,11 @@
"preview": "vite preview"
},
"dependencies": {
"@ant-design/icons": "^5.5.2",
"antd": "^5.22.5",
"react": "^18.3.1",
"react-dom": "^18.3.1"
"react-dom": "^18.3.1",
"sass": "^1.83.0"
},
"devDependencies": {
"@eslint/js": "^9.15.0",
......
#root {
max-width: 1280px;
margin: 0 auto;
padding: 2rem;
text-align: center;
}
.logo {
height: 6em;
padding: 1.5em;
will-change: filter;
transition: filter 300ms;
}
.logo:hover {
filter: drop-shadow(0 0 2em #646cffaa);
}
.logo.react:hover {
filter: drop-shadow(0 0 2em #61dafbaa);
}
@keyframes logo-spin {
from {
transform: rotate(0deg);
}
to {
transform: rotate(360deg);
}
}
@media (prefers-reduced-motion: no-preference) {
a:nth-of-type(2) .logo {
animation: logo-spin infinite 20s linear;
}
}
.card {
padding: 2em;
}
.read-the-docs {
color: #888;
}
import { useState } from 'react'
import reactLogo from './assets/react.svg'
import viteLogo from '/vite.svg'
import './App.css'
function App() {
const [count, setCount] = useState(0)
return (
<>
<div>
<a href="https://vite.dev" target="_blank">
<img src={viteLogo} className="logo" alt="Vite logo" />
</a>
<a href="https://react.dev" target="_blank">
<img src={reactLogo} className="logo react" alt="React logo" />
</a>
</div>
<h1>Vite + React</h1>
<div className="card">
<button onClick={() => setCount((count) => count + 1)}>
count is {count}
</button>
<p>
Edit <code>src/App.tsx</code> and save to test HMR
</p>
</div>
<p className="read-the-docs">
Click on the Vite and React logos to learn more
</p>
</>
)
}
export default App
import { Button, Form, Input, InputNumber } from 'antd';
import { FieldType } from '../Interfaces/Stock';
type TProps = {
onFinish: ((values: FieldType) => void) | undefined
}
const StockForm = ({onFinish}: TProps) => {
return (
<Form
name="basic"
labelCol={{ span: 8 }}
wrapperCol={{ span: 16 }}
style={{ width: 300 }}
initialValues={{ remember: true }}
onFinish={onFinish}
autoComplete="off"
>
<Form.Item<FieldType>
label="Title"
name="title"
rules={[{ required: true, message: 'Please input your title!' }]}
>
<Input />
</Form.Item>
<Form.Item<FieldType>
label="Price"
name="price"
>
<InputNumber />
</Form.Item>
<Form.Item<FieldType>
label="Count"
name="count"
>
<InputNumber />
</Form.Item>
<Form.Item label={null}>
<Button type="primary" htmlType="submit">
Submit
</Button>
</Form.Item>
</Form>
)
}
export default StockForm
\ No newline at end of file
import { useState } from 'react'
import { FieldType, IStock } from '../Interfaces/Stock'
import { FormProps, Row, Table, Typography } from 'antd'
import { columns } from '../data/Stock';
import StockForm from '../Components/StockForm';
const Stock = () => {
const [items, setItems] = useState<IStock[]>([
{title: 'Acer', price: 1000, count: 2},
{title: 'Lenova', price: 2000, count: 1}
])
const minusHandler = (title: string) => {
const index = items.findIndex(item => item.title === title)
const copyItems = [...items]
copyItems[index].count--
if(copyItems[index].count >= 0) setItems(copyItems)
}
const onFinish: FormProps<FieldType>['onFinish'] = (values) => {
const copyItems = [...items]
copyItems.push(values)
setItems(copyItems)
};
const isItems = items.map(item => item.count).reduce((a, b) => a + b, 0)
return (
<Row style={{height: '100%', width: '100%', flexDirection: 'column'}}>
<Row justify={'center'}>
{
isItems > 0 ?
<Table
columns={columns({onClick: minusHandler})}
dataSource={items}
style={{width: '80%'}}
/>
:
<Typography.Title>
No Products
</Typography.Title>
}
</Row>
<Row justify={'center'}>
<StockForm
onFinish={onFinish}
/>
</Row>
</Row>
)
}
export default Stock
\ No newline at end of file
export interface IStock {
title: string
price: number
count: number
}
export type FieldType = {
title: string;
price: number;
count: number;
}
\ No newline at end of file
import { TableColumnsType, Button } from "antd";
import { MinusOutlined } from "@ant-design/icons"
import { IStock } from "../Interfaces/Stock";
type TProps = {
onClick: (title: string) => void
}
export const columns = ({onClick}: TProps): TableColumnsType<IStock> => {
return [
{
key: 'title',
title: 'Title',
dataIndex: 'title',
sorter: (a, b) => a.title.length - b.title.length,
},
{
key: 'price',
title: 'Price',
dataIndex: 'price',
sorter: (a, b) => a.price - b.price,
},
{
key: 'count',
title: 'Count',
dataIndex: 'count',
sorter: (a, b) => a.count - b.count,
render: (val) => {
return val === 0 ? 'Not avalible' : val
}
},
{
key: 'action',
title: 'Action',
dataIndex: 'action',
render: (_, record) => {
return (
<Button
danger
type={'primary'}
icon={<MinusOutlined />}
onClick={() => onClick(record.title)}
/>
)
}
}
]
}
\ No newline at end of file
:root {
font-family: Inter, system-ui, Avenir, Helvetica, Arial, sans-serif;
line-height: 1.5;
font-weight: 400;
color-scheme: light dark;
color: rgba(255, 255, 255, 0.87);
background-color: #242424;
font-synthesis: none;
text-rendering: optimizeLegibility;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
}
a {
font-weight: 500;
color: #646cff;
text-decoration: inherit;
}
a:hover {
color: #535bf2;
}
body {
margin: 0;
display: flex;
place-items: center;
min-width: 320px;
min-height: 100vh;
}
h1 {
font-size: 3.2em;
line-height: 1.1;
}
button {
border-radius: 8px;
border: 1px solid transparent;
padding: 0.6em 1.2em;
font-size: 1em;
font-weight: 500;
font-family: inherit;
background-color: #1a1a1a;
cursor: pointer;
transition: border-color 0.25s;
}
button:hover {
border-color: #646cff;
}
button:focus,
button:focus-visible {
outline: 4px auto -webkit-focus-ring-color;
}
@media (prefers-color-scheme: light) {
:root {
color: #213547;
background-color: #ffffff;
}
a:hover {
color: #747bff;
}
button {
background-color: #f9f9f9;
}
}
import { StrictMode } from 'react'
import { createRoot } from 'react-dom/client'
import './index.css'
import App from './App.tsx'
import Stock from './Containers/Stock'
import './Styles/main.scss'
createRoot(document.getElementById('root')!).render(
<StrictMode>
<App />
<Stock />
</StrictMode>,
)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment