Commit efed09ae authored by Nurasyl's avatar Nurasyl

Initial commit

parents
module.exports = {
root: true,
env: { browser: true, es2020: true },
extends: [
'eslint:recommended',
'plugin:@typescript-eslint/recommended',
'plugin:react-hooks/recommended',
],
ignorePatterns: ['dist', '.eslintrc.cjs'],
parser: '@typescript-eslint/parser',
plugins: ['react-refresh'],
rules: {
'react-refresh/only-export-components': [
'warn',
{ allowConstantExport: true },
],
},
}
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
pnpm-debug.log*
lerna-debug.log*
node_modules
dist
dist-ssr
*.local
# Editor directories and files
.vscode/*
!.vscode/extensions.json
.idea
.DS_Store
*.suo
*.ntvs*
*.njsproj
*.sln
*.sw?
# React + TypeScript + Vite
This template provides a minimal setup to get React working in Vite with HMR and some ESLint rules.
Currently, two official plugins are available:
- [@vitejs/plugin-react](https://github.com/vitejs/vite-plugin-react/blob/main/packages/plugin-react/README.md) uses [Babel](https://babeljs.io/) for Fast Refresh
- [@vitejs/plugin-react-swc](https://github.com/vitejs/vite-plugin-react-swc) uses [SWC](https://swc.rs/) for Fast Refresh
## Expanding the ESLint configuration
If you are developing a production application, we recommend updating the configuration to enable type aware lint rules:
- Configure the top-level `parserOptions` property like this:
```js
export default {
// other rules...
parserOptions: {
ecmaVersion: 'latest',
sourceType: 'module',
project: ['./tsconfig.json', './tsconfig.node.json'],
tsconfigRootDir: __dirname,
},
}
```
- Replace `plugin:@typescript-eslint/recommended` to `plugin:@typescript-eslint/recommended-type-checked` or `plugin:@typescript-eslint/strict-type-checked`
- Optionally add `plugin:@typescript-eslint/stylistic-type-checked`
- Install [eslint-plugin-react](https://github.com/jsx-eslint/eslint-plugin-react) and add `plugin:react/recommended` & `plugin:react/jsx-runtime` to the `extends` list
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Vite + React + TS</title>
</head>
<body>
<div id="root"></div>
<script type="module" src="/src/main.tsx"></script>
</body>
</html>
This source diff could not be displayed because it is too large. You can view the blob instead.
{
"name": "vebinar",
"private": true,
"version": "0.0.0",
"type": "module",
"scripts": {
"dev": "vite",
"build": "tsc && vite build",
"lint": "eslint . --ext ts,tsx --report-unused-disable-directives --max-warnings 0",
"preview": "vite preview"
},
"dependencies": {
"antd": "^5.16.2",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"uuidv4": "^6.2.13"
},
"devDependencies": {
"@types/react": "^18.2.66",
"@types/react-dom": "^18.2.22",
"@typescript-eslint/eslint-plugin": "^7.2.0",
"@typescript-eslint/parser": "^7.2.0",
"@vitejs/plugin-react": "^4.2.1",
"eslint": "^8.57.0",
"eslint-plugin-react-hooks": "^4.6.0",
"eslint-plugin-react-refresh": "^0.4.6",
"typescript": "^5.2.2",
"vite": "^5.2.0"
}
}
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" class="iconify iconify--logos" width="31.88" height="32" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 257"><defs><linearGradient id="IconifyId1813088fe1fbc01fb466" x1="-.828%" x2="57.636%" y1="7.652%" y2="78.411%"><stop offset="0%" stop-color="#41D1FF"></stop><stop offset="100%" stop-color="#BD34FE"></stop></linearGradient><linearGradient id="IconifyId1813088fe1fbc01fb467" x1="43.376%" x2="50.316%" y1="2.242%" y2="89.03%"><stop offset="0%" stop-color="#FFEA83"></stop><stop offset="8.333%" stop-color="#FFDD35"></stop><stop offset="100%" stop-color="#FFA800"></stop></linearGradient></defs><path fill="url(#IconifyId1813088fe1fbc01fb466)" d="M255.153 37.938L134.897 252.976c-2.483 4.44-8.862 4.466-11.382.048L.875 37.958c-2.746-4.814 1.371-10.646 6.827-9.67l120.385 21.517a6.537 6.537 0 0 0 2.322-.004l117.867-21.483c5.438-.991 9.574 4.796 6.877 9.62Z"></path><path fill="url(#IconifyId1813088fe1fbc01fb467)" d="M185.432.063L96.44 17.501a3.268 3.268 0 0 0-2.634 3.014l-5.474 92.456a3.268 3.268 0 0 0 3.997 3.378l24.777-5.718c2.318-.535 4.413 1.507 3.936 3.838l-7.361 36.047c-.495 2.426 1.782 4.5 4.151 3.78l15.304-4.649c2.372-.72 4.652 1.36 4.15 3.788l-11.698 56.621c-.732 3.542 3.979 5.473 5.943 2.437l1.313-2.028l72.516-144.72c1.215-2.423-.88-5.186-3.54-4.672l-25.505 4.922c-2.396.462-4.435-1.77-3.759-4.114l16.646-57.705c.677-2.35-1.37-4.583-3.769-4.113Z"></path></svg>
\ No newline at end of file
import React, { useState } from 'react'
import { Layout } from 'antd'
import { DataTable } from './Components/DataTable/DataTable'
import { TData } from './types/dataSource'
import { Form } from './Components/Form/Form'
import { v4 as uuidv4 } from 'uuid';
const LayoutStyle: React.CSSProperties = {
background: "#444444",
height: "100vh",
width: "100vw"
}
function App() {
const [data, setData] = useState<TData[]>([]);
const [inputData, setInputData] = useState({
title: "",
price: 0,
stock: 0
})
const onClickHandler = () => {
setData(prevState => ([...prevState, {...inputData, key: uuidv4()}]));
setInputData({title: "", price: 0, stock: 0});
};
const onChangeHandler = (e: React.ChangeEvent<HTMLInputElement>) => {
const {name, value} = e.target;
setInputData(prevState => ({...prevState, [name]: value}));
};
const onDeleteHandler = (key: string) => {
const dataCopy = [...data];
const index = dataCopy.findIndex(item => item.key === key);
dataCopy.splice(0, index);
setData(dataCopy);
};
return (
<Layout style={LayoutStyle}>
<DataTable
data={data}
/>
<Form
inputData={inputData}
onChange={onChangeHandler}
onClick={onClickHandler}
/>
</Layout>
)
}
export default App
import type { TableColumnsType } from 'antd';
interface DataType {
key: React.Key;
name: string;
price: number;
stock: number;
}
export const columns: TableColumnsType<DataType> = [
{
title: 'Title',
dataIndex: 'title',
key: 'title',
sorter: true,
},
{
title: 'Price',
dataIndex: 'price',
key: 'price',
defaultSortOrder: 'descend',
sorter: (a, b) => a.price - b.price,
},
{
title: 'Stock',
dataIndex: 'stock',
key: 'stock',
defaultSortOrder: 'descend',
sorter: (a, b) => a.stock - b.stock,
},
{
title: 'Action',
dataIndex: '',
key: 'x',
render: () => <a>Delete</a>,
},
];
\ No newline at end of file
import React from "react";
import { Table } from "antd";
import { columns } from "./DataTable.data";
import { TData } from "../../types/dataSource";
const TableStyle: React.CSSProperties = {
width: "50%",
margin: "0 auto",
marginTop: "30px"
};
export const DataTable = ({data}: {data: TData[]}) => {
return (
<Table
style={TableStyle}
dataSource={data}
columns={columns}
/>
);
};
\ No newline at end of file
export type TProps = {
onChange: (e: React.ChangeEvent<HTMLInputElement>) => void,
onClick: VoidFunction,
inputData: {
title: string,
price: number,
stock: number
}
};
export const RowStyle: React.CSSProperties = {
height: "200px",
width: "25%",
margin: "0 auto",
marginTop: "50px",
justifyContent: "center",
alignItems: "center",
alignContent: "space-around"
};
export const BtnStyle: React.CSSProperties = {
height: "40px",
width: "100%",
fontSize: "20px"
};
export const InpStyle: React.CSSProperties = {
height: "35px",
fontSize: "20px",
textAlign: "center",
textTransform: "capitalize"
};
\ No newline at end of file
import React from "react";
import { Button, Input, Row } from 'antd';
import { TProps, RowStyle, InpStyle, BtnStyle } from "./Form.data";
export const Form = ({inputData, onChange, onClick}: TProps) => {
return (
<Row style={RowStyle}>
<Input
style={InpStyle}
placeholder="Title"
value={inputData.title}
onChange={onChange}
name={"title"}
/>
<Input
style={InpStyle}
placeholder="Price"
value={inputData.price}
onChange={onChange}
name={"price"}
type={"number"}
/>
<Input
style={InpStyle}
placeholder="Stock"
value={inputData.stock}
onChange={onChange}
type={"number"}
name={"stock"}
/>
<Button
style={BtnStyle}
type="primary"
onClick={onClick}
>
Add
</Button>
</Row>
);
};
\ No newline at end of file
* {
box-sizing: border-box;
margin: 0;
}
\ No newline at end of file
import React from 'react'
import ReactDOM from 'react-dom/client'
import App from './App.tsx'
import './index.css'
ReactDOM.createRoot(document.getElementById('root')!).render(
<React.StrictMode>
<App />
</React.StrictMode>,
)
export type TData = {
key: string,
title: string,
price: number,
stock: number
}
\ No newline at end of file
/// <reference types="vite/client" />
{
"compilerOptions": {
"target": "ES2020",
"useDefineForClassFields": true,
"lib": ["ES2020", "DOM", "DOM.Iterable"],
"module": "ESNext",
"skipLibCheck": true,
/* Bundler mode */
"moduleResolution": "bundler",
"allowImportingTsExtensions": true,
"resolveJsonModule": true,
"isolatedModules": true,
"noEmit": true,
"jsx": "react-jsx",
/* Linting */
"strict": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"noFallthroughCasesInSwitch": true
},
"include": ["src"],
"references": [{ "path": "./tsconfig.node.json" }]
}
{
"compilerOptions": {
"composite": true,
"skipLibCheck": true,
"module": "ESNext",
"moduleResolution": "bundler",
"allowSyntheticDefaultImports": true,
"strict": true
},
"include": ["vite.config.ts"]
}
import { defineConfig } from 'vite'
import react from '@vitejs/plugin-react'
// https://vitejs.dev/config/
export default defineConfig({
plugins: [react()],
})
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