Commit bce370cf 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": "classwork",
"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": {
"react": "^18.2.0",
"react-dom": "^18.2.0"
},
"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
.Person {
width: 250px;
height: 220px;
border: 2px solid white;
background-color: aliceblue;
border-radius: 20px;
display: flex;
justify-content: center;
align-items: center;
flex-direction: column;
}
.text_block {
width: 90%;
text-align: center;
margin-bottom: 20px;
}
h2 {
color: black;
}
p {
color: black;
}
.pagination {
width: 100%;
display: flex;
justify-content: center;
align-items: center;
margin-bottom: 20px;
}
button {
background-color: black;
color: white;
width: 80%;
height: 30px;
border: none;
border-radius: 10px;
}
\ No newline at end of file
import React from "react";
import "./Person.css";
type TProps = {
name: string;
age: string;
onClick: VoidFunction;
onRemove: VoidFunction;
onChange: React.ChangeEventHandler<HTMLInputElement>
};
export const Person = (data: TProps) => {
return (
<div className="Person">
<div className="text_block">
<h2>Name: {data.name}</h2>
<p>Age: {data.age}</p>
</div>
<div className="pagination">
<button onClick={data.onClick}>Change</button>
<button onClick={data.onRemove}>Remove</button>
</div>
<div className="input_block">
<input type="text" onChange={data.onChange}/>
</div>
</div>
);
};
\ No newline at end of file
.PersonContainer {
background-color: rgb(60, 57, 57);
height: 100vh;
padding: 20px;
display: flex;
align-items: center;
justify-content: space-between;
}
.inp {
position: fixed;
bottom: 50px;
width: 250px;
right: 45%;
}
.show {
position: fixed;
bottom: 50px;
width: 50px;
right: 40%;
}
.hide {
position: fixed;
bottom: 50px;
width: 50px;
right: 35%;
}
\ No newline at end of file
import React, {useState} from "react";
import { Person } from "../components/Person";
import "./PersonContainer.css";
type TPersonInfo = {
name: string;
age: string;
show: boolean
}
export const PersonContainer = () => {
const [personsInfo, setPersonsInfo] = useState<TPersonInfo[]>([
{name: "John", age: "25", show: true},
{name: "Donny", age: "18", show: true},
{name: "Jack", age: "55", show: true},
{name: "Dima", age: "35", show: true}
]);
const [selectedPerson, setSelectedPerson] = useState<number | null>(null);
const onClickHandler = (index: number) => {
const copyState = personsInfo;
copyState[index].age = "5";
setPersonsInfo([...copyState]);
};
const onRemoveHandler = (index: number) => {
const copyState = personsInfo;
copyState.splice(index, 1);
setPersonsInfo([...copyState]);
};
const onChangeHandler = (e: React.ChangeEvent<HTMLInputElement>, index: number) => {
const copyState = personsInfo;
copyState[index].name = e.target.value;
setPersonsInfo([...copyState]);
};
const onChangeShowInput = (e: React.ChangeEvent<HTMLInputElement>) => {
const index = personsInfo.findIndex(item => item.name === e.target.value);
if(index >= 0) {
setSelectedPerson(index);
}
};
const onClickShow = () => {
const copyState = personsInfo;
copyState[selectedPerson!].show = true;
setPersonsInfo([...copyState]);
};
const onClickHide = () => {
const copyState = personsInfo;
copyState[selectedPerson!].show = false;
setPersonsInfo([...copyState]);
}
return (
<div className="PersonContainer">
{
personsInfo.map((item, index) => (
item.show ?
<Person
key={index}
name={item.name}
age={item.age}
onClick={() => onClickHandler(index)}
onRemove={() => onRemoveHandler(index)}
onChange={(e) => onChangeHandler(e, index)}
/> : null
))
}
<input className="inp" type="text" onChange={onChangeShowInput}/>
<button className="show" onClick={onClickShow}>Show</button>
<button className="hide" onClick={onClickHide}>Hide</button>
</div>
);
};
\ 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 { PersonContainer } from './containers/PersonContainer'
import './index.css'
ReactDOM.createRoot(document.getElementById('root')!).render(
<PersonContainer />
)
/// <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