Compare commits

..

10 Commits

9 changed files with 271 additions and 65 deletions
+13
View File
@@ -5,6 +5,19 @@
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Vite + React</title>
<style>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
font-family: Arial, Helvetica, sans-serif;
}
body {
background-color: rgb(249, 249, 249);
}
</style>
</head>
<body>
<div id="root"></div>
+17 -7
View File
@@ -9,7 +9,8 @@
"version": "0.0.0",
"dependencies": {
"react": "^19.1.0",
"react-dom": "^19.1.0"
"react-dom": "^19.1.0",
"react-icons": "^5.5.0"
},
"devDependencies": {
"@eslint/js": "^9.25.0",
@@ -321,9 +322,9 @@
}
},
"node_modules/@bufbuild/protobuf": {
"version": "2.12.0",
"resolved": "https://registry.npmjs.org/@bufbuild/protobuf/-/protobuf-2.12.0.tgz",
"integrity": "sha512-B/XlCaFIP8LOwzo+bz5uFzATYokcwCKQcghqnlfwSmM5eX/qTkvDBnDPs+gXtX/RyjxJ4DRikECcPJbyALA8FA==",
"version": "2.5.2",
"resolved": "https://registry.npmjs.org/@bufbuild/protobuf/-/protobuf-2.5.2.tgz",
"integrity": "sha512-foZ7qr0IsUBjzWIq+SuBLfdQCpJ1j8cTuNNT4owngTHoN5KsJb8L9t65fzz7SCeSWzescoOil/0ldqiL041ABg==",
"dev": true,
"license": "(Apache-2.0 AND BSD-3-Clause)"
},
@@ -2829,6 +2830,15 @@
"react": "^19.1.0"
}
},
"node_modules/react-icons": {
"version": "5.5.0",
"resolved": "https://registry.npmjs.org/react-icons/-/react-icons-5.5.0.tgz",
"integrity": "sha512-MEFcXdkP3dLo8uumGI5xN3lDFNsRtrjbOEKDLD7yv76v4wpnEq2Lt2qeHaQOr34I/wPN3s3+N08WkQ+CW37Xiw==",
"license": "MIT",
"peerDependencies": {
"react": "*"
}
},
"node_modules/react-refresh": {
"version": "0.17.0",
"resolved": "https://registry.npmjs.org/react-refresh/-/react-refresh-0.17.0.tgz",
@@ -3396,9 +3406,9 @@
}
},
"node_modules/sync-message-port": {
"version": "1.2.0",
"resolved": "https://registry.npmjs.org/sync-message-port/-/sync-message-port-1.2.0.tgz",
"integrity": "sha512-gAQ9qrUN/UCypHtGFbbe7Rc/f9bzO88IwrG8TDo/aMKAApKyD6E3W4Cm0EfhfBb6Z6SKt59tTCTfD+n1xmAvMg==",
"version": "1.1.3",
"resolved": "https://registry.npmjs.org/sync-message-port/-/sync-message-port-1.1.3.tgz",
"integrity": "sha512-GTt8rSKje5FilG+wEdfCkOcLL7LWqpMlr2c3LRuKt/YXxcJ52aGSbGBAdI4L3aaqfrBt6y711El53ItyH1NWzg==",
"dev": true,
"license": "MIT",
"engines": {
+2 -1
View File
@@ -11,7 +11,8 @@
},
"dependencies": {
"react": "^19.1.0",
"react-dom": "^19.1.0"
"react-dom": "^19.1.0",
"react-icons": "^5.5.0"
},
"devDependencies": {
"@eslint/js": "^9.25.0",
-15
View File
@@ -1,15 +0,0 @@
.container {
/* display: flex;
flex-direction: column;
flex-wrap: nowrap;*/
height: 500px;
overflow: auto;
border: 1px solid black;
}
.item {
font-size: 16pt;
border: 1px dotted gray;
/*margin: 5px 10px;
padding: 10px;*/
border-radius: 5px;
}
+96 -44
View File
@@ -1,51 +1,103 @@
import { useEffect, useRef, useState } from 'react';
import styles from './App.module.scss';
import styles from './App.module.scss'
import SneakersImage from './assets/images/sneakers-image.jpg'
import { FaRegUser } from 'react-icons/fa'
import { FaHeart } from "react-icons/fa";
import { BsCheckSquare } from "react-icons/bs";
import { useState } from 'react'
const InfiniteList = () => {
const [items, setItems] = useState([...Array(20).keys()]); // Initial data
const loaderRef = useRef(null);
const loadMore = () => {
setItems((prev) => [...prev, ...Array(10).keys()].map((_, i) => prev.length + i));
};
useEffect(() => {
const observer = new IntersectionObserver((entries) => {
if (entries[0].isIntersecting) {
loadMore(); // Load next batch when the loader is seen
}
});
if (loaderRef.current) observer.observe(loaderRef.current);
return () => observer.disconnect();
}, []);
return (
<ul>
{items.map(item => <li key={item} className={ styles.item }>Item {item}</li>)}
<div ref={loaderRef}>Loading more...</div>
</ul>
);
};
function App() {
const generatedBigDataSet = () => {
return Array.from({ length: 100 }, (_, index) => ({
id: index,
name: `Элемент № ${index}`,
value: Math.floor(Math.random() * 1000)
}))
}
const [data] = useState(generatedBigDataSet);
function Header() {
const handleChange = event => {
const newValue = event.target.value
console.log('Новое значение:', newValue)
}
return (
<>
<div>
<h2>Визуализация большого списка</h2>
<div className={ styles.container }>
<InfiniteList />
</div>
<header className={styles.header}>
<div>
<h2>Store</h2>
<input type='text ' placeholder='Search...' onChange={handleChange} />
</div>
<div>
<FaRegUser size={24} color='#3258e3' />
<button>Profile</button>
</div>
</header>
)
}
function Product() {
function LikeCounter() {
const [likes,setLikes] = useState(0);
return (
<>
<h2>Лайков: {likes}</h2>
{likes < 10 && <button onClick={() => setLikes(likes + 1)}>👍 Лайк</button>}
{likes > 0 && <button onClick={() => setLikes(0)}>🔄 Сбросить</button> }
{likes >= 10 && <h3>Вы достигли лимита!</h3>}
<div className={styles.progress}>
<div className={styles.value} style={{ width: `${likes*10}%`}}></div>
</div>
</>
)
}
function handleClick() {
console.log('Working!')
}
function Counter() {
const [isLiked,setIsLiked] = useState(false);
const toggleLike = () => {
setIsLiked(!isLiked);
}
return (
<>
<BsCheckSquare
onClick={toggleLike}
fill={isLiked==true ? 'red' : 'grey'}
size={44}
/>
</>
)
}
return (
<div className={styles.product}>
<img src={SneakersImage} alt='' />
<div className={styles.content}>
<div className={styles.title}>
<h4>Sneakers Red & White 2025</h4>
<button onClick={event => handleClick(event)}>+</button>
</div>
<p className={styles.description}>NIKE</p>
<p className={styles.price}>$38.00</p>
</div>
<LikeCounter />
</div>
)
}
function App() {
return (
<>
<div className={styles.container}>
<Header />
</div>
<div className={styles.container}>
<ul className={styles.list}>
<li>
<Product />
</li>
<li>
<Product />
</li>
<li>
<Product />
</li>
</ul>
</div>
</>
)
}
+141
View File
@@ -0,0 +1,141 @@
@use './assets/styles/variables' as *;
.progress {
width: 100%;
height: 10px;
border: 1px solid black;
}
.value {
/*width:70%;*/
height: 100%;
background-color: green;
}
.header {
display: flex;
justify-content: space-between;
align-items: center;
padding: 20px;
background-color: white;
border-bottom-left-radius: 10px;
border-bottom-right-radius: 10px;
div {
&:first-child {
display: flex;
align-items: center;
gap: 20px;
h2 {
color: $primary-color;
}
input {
border-radius: 5px;
outline: none;
font-size: 16px;
border: 1px solid gainsboro;
padding: 5px 10px;
&:focus {
border: 1px solid $primary-color;
}
}
}
&:last-child {
display: flex;
align-items: center;
gap: 10px;
button {
outline: 0;
border: 0;
border-radius: 5px;
padding: 5px 15px;
font-size: 16px;
background-color: $primary-color;
color: $white-color;
font-weight: 600;
cursor: pointer;
&:hover {
background-color: $seconday-color;
}
}
}
}
}
.container {
max-width: 1220px;
margin: 0 auto;
}
.list {
display: flex;
justify-content: space-between;
flex-wrap: wrap;
border-radius: 10px;
margin-top: 100px; /* временно */
padding: 20px;
background-color: white;
list-style: none;
}
.product {
display: flex;
flex-direction: column;
width: 350px;
gap: 20px;
border-radius: 10px;
}
.content {
display: flex;
flex-direction: column;
gap: 10px;
}
.title {
display: flex;
justify-content: space-between;
align-items: center;
h4 {
font-size: 18px;
}
button {
border: 1px solid $primary-color;
background-color: $white-color;
color: $primary-color;
border-radius: 5px;
outline: 0;
font-size: 20px;
padding: 5px 10px;
cursor: pointer;
&:hover {
background-color: $seconday-color;
color: $white-color;
}
}
}
img {
border-radius: 10px;
}
.description {
color: gray;
}
.price {
font-weight: bold;
}
Binary file not shown.

After

Width:  |  Height:  |  Size: 23 KiB

+5
View File
@@ -0,0 +1,5 @@
$white-color: white;
$black-color: black;
$primary-color: #3258e3;
$seconday-color: #4432e3;
-1
View File
@@ -1,6 +1,5 @@
import { StrictMode } from 'react'
import { createRoot } from 'react-dom/client'
// удаляем import './index.css'
import App from './App.jsx'
createRoot(document.getElementById('root')).render(