Compare commits
8 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| c168c96820 | |||
| b70fa47bbc | |||
| bd35029fc1 | |||
| 92dc5df96b | |||
| 3d34262203 | |||
| 1bc2e883a1 | |||
| 8a8a17f44d | |||
| 8f46470a26 |
@@ -1,25 +0,0 @@
|
|||||||
{
|
|
||||||
"products": [
|
|
||||||
{
|
|
||||||
"id":1,
|
|
||||||
"name":"Кросовки Red & White 2025",
|
|
||||||
"brand":"NIKE",
|
|
||||||
"price":38.0,
|
|
||||||
"imageUrl":"./assets/images/sneakers-image.jpg"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"id":2,
|
|
||||||
"name":"Кросовки белые 2024",
|
|
||||||
"brand":"NIKE",
|
|
||||||
"price":40.0,
|
|
||||||
"imageUrl":"./assets/images/sneakers-image.jpg"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"id":3,
|
|
||||||
"name":"Sneakers Red & White 2025",
|
|
||||||
"brand":"NIKE",
|
|
||||||
"price":46.0,
|
|
||||||
"imageUrl":"./assets/images/sneakers-image.jpg"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
-13
@@ -5,19 +5,6 @@
|
|||||||
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
|
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||||
<title>Vite + React</title>
|
<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>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<div id="root"></div>
|
<div id="root"></div>
|
||||||
|
|||||||
Generated
+965
-105
File diff suppressed because it is too large
Load Diff
+4
-4
@@ -4,17 +4,15 @@
|
|||||||
"version": "0.0.0",
|
"version": "0.0.0",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"server": "json-server --watch db.json --port 8000",
|
|
||||||
"dev": "vite",
|
"dev": "vite",
|
||||||
"build": "vite build",
|
"build": "vite build",
|
||||||
"lint": "eslint .",
|
"lint": "eslint .",
|
||||||
"preview": "vite preview"
|
"preview": "vite preview"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
"info": "^1.0.0",
|
||||||
"react": "^19.1.0",
|
"react": "^19.1.0",
|
||||||
"react-dom": "^19.1.0",
|
"react-dom": "^19.1.0"
|
||||||
"react-icons": "^5.5.0",
|
|
||||||
"sass-embedded": "^1.89.2"
|
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@eslint/js": "^9.25.0",
|
"@eslint/js": "^9.25.0",
|
||||||
@@ -25,6 +23,8 @@
|
|||||||
"eslint-plugin-react-hooks": "^5.2.0",
|
"eslint-plugin-react-hooks": "^5.2.0",
|
||||||
"eslint-plugin-react-refresh": "^0.4.19",
|
"eslint-plugin-react-refresh": "^0.4.19",
|
||||||
"globals": "^16.0.0",
|
"globals": "^16.0.0",
|
||||||
|
"sass": "^1.99.0",
|
||||||
|
"sass-embedded": "^1.99.0",
|
||||||
"vite": "^6.3.5"
|
"vite": "^6.3.5"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+18
-189
@@ -1,200 +1,29 @@
|
|||||||
import styles from './App.module.scss'
|
import styles from './styles/App.module.scss'
|
||||||
import SneakersImage from './assets/images/sneakers-image.jpg'
|
import React, { useState, useCallback } from 'react'
|
||||||
import { FaRegUser } from 'react-icons/fa'
|
|
||||||
import React from 'react'
|
|
||||||
|
|
||||||
function EffectComponent() {
|
function CounterButton({label, onClick}) {
|
||||||
const [size, setSize] = React.useState(100);
|
|
||||||
const boxRef = React.useRef(null);
|
|
||||||
|
|
||||||
React.useEffect(() => {
|
|
||||||
const box = boxRef.current
|
|
||||||
if (box) {
|
|
||||||
const { width, height } = box.getBoundingClientRect()
|
|
||||||
console.log('[useEffect] Размеры (EffectComponent):', { width, height })
|
|
||||||
}
|
|
||||||
}, [size]);
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div style={{ marginBottom: '30px' }}>
|
<button onClick={onClick} className={styles.counter_button}>{label}</button>
|
||||||
<h3>useEffect</h3>
|
)
|
||||||
<div
|
|
||||||
ref={boxRef}
|
|
||||||
style={{
|
|
||||||
width: size,
|
|
||||||
height: size,
|
|
||||||
backgroundColor: 'lightblue',
|
|
||||||
transition: 'all 1.3s',
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
<button onClick={() => setSize(prev => prev + 20)}>Увеличить</button>
|
|
||||||
</div>
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
function CounterDisplay({value}) {
|
||||||
function LayoutEffectComponent() {
|
return (<div className={styles.counter_display}>
|
||||||
const [size, setSize] = React.useState(100)
|
Значение счетчика: <b>{value}</b>
|
||||||
const boxRef = React.useRef(null)
|
</div>)
|
||||||
|
|
||||||
React.useLayoutEffect(() => {
|
|
||||||
const box = boxRef.current
|
|
||||||
if (box) {
|
|
||||||
const { width, height } = box.getBoundingClientRect()
|
|
||||||
console.log('[useLayoutEffect] Размеры (LayoutEffectComponent):', {
|
|
||||||
width,
|
|
||||||
height,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}, [size])
|
|
||||||
|
|
||||||
return (
|
|
||||||
<div>
|
|
||||||
<h3>useLayoutEffect</h3>
|
|
||||||
<div
|
|
||||||
ref={boxRef}
|
|
||||||
style={{
|
|
||||||
width: size,
|
|
||||||
height: size,
|
|
||||||
backgroundColor: 'lightgreen',
|
|
||||||
transition: 'all 1.3s',
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
<button onClick={() => setSize(prev => prev + 20)}>Увеличить</button>
|
|
||||||
</div>
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
function Header() {
|
|
||||||
const handleChange = event => {
|
|
||||||
const newValue = event.target.value
|
|
||||||
console.log('Новое значение:', newValue)
|
|
||||||
}
|
|
||||||
|
|
||||||
return (
|
|
||||||
<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 ToolTip() {
|
|
||||||
const ref = React.useRef(null);
|
|
||||||
const [height,setHeight] = React.useState(0);
|
|
||||||
|
|
||||||
React.useLayoutEffect(()=>{
|
|
||||||
if (ref.current) {
|
|
||||||
const rect = ref.current.getBoundingClientRect();
|
|
||||||
setHeight(rect.height);
|
|
||||||
}
|
|
||||||
},[])
|
|
||||||
|
|
||||||
return <div ref={ref} style={{height: '40px'}}>Высота: {height}</div>
|
|
||||||
}
|
|
||||||
|
|
||||||
function Product({ name, brand, price, url }) {
|
|
||||||
const [isLiked, setIsLiked] = React.useState(false)
|
|
||||||
|
|
||||||
const toggleLike = () => {
|
|
||||||
setIsLiked(!isLiked)
|
|
||||||
}
|
|
||||||
|
|
||||||
function handleAddClick() {
|
|
||||||
console.log('Working!')
|
|
||||||
}
|
|
||||||
|
|
||||||
return (
|
|
||||||
<div className={styles.product}>
|
|
||||||
<img src={SneakersImage} alt='' />
|
|
||||||
<ToolTip />
|
|
||||||
<div className={styles.content}>
|
|
||||||
<div className={styles.title}>
|
|
||||||
<h4>{name}</h4>
|
|
||||||
<div className={styles.actions}>
|
|
||||||
<button
|
|
||||||
className={styles.likeButton}
|
|
||||||
onClick={toggleLike}
|
|
||||||
aria-label={isLiked ? 'Убрать лайк' : 'Добавить лайк'}
|
|
||||||
>
|
|
||||||
<svg
|
|
||||||
width='18'
|
|
||||||
height='18'
|
|
||||||
viewBox='0 0 24 24'
|
|
||||||
fill={isLiked ? 'red' : 'none'}
|
|
||||||
stroke={isLiked ? 'red' : 'currentColor'}
|
|
||||||
strokeWidth='1.5'
|
|
||||||
>
|
|
||||||
<path d='M12 21.35L10.55 20.03C5.4 15.36 2 12.28 2 8.5C2 5.42 4.42 3 7.5 3C9.24 3 10.91 3.81 12 5.09C13.09 3.81 14.76 3 16.5 3C19.58 3 22 5.42 22 8.5C22 12.28 18.6 15.36 13.45 20.04L12 21.35Z' />
|
|
||||||
</svg>
|
|
||||||
</button>
|
|
||||||
<button onClick={handleAddClick}>+</button>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<p className={styles.description}>{brand}</p>
|
|
||||||
<p className={styles.price}>${price}</p>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
function MyComponent({ children }) {
|
|
||||||
return <div className="wrapper">{children}</div>;
|
|
||||||
}
|
|
||||||
|
|
||||||
function RowList({ children }) {
|
|
||||||
return (
|
|
||||||
<div className="rowList">
|
|
||||||
{children.map(child => (
|
|
||||||
<div className="row">{child}</div>
|
|
||||||
))}
|
|
||||||
<p>{React.Children.count(children)}</p>
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function App() {
|
function App() {
|
||||||
const [products,setProducts] = React.useState([]);
|
const [counter,setCounter] = useState(0);
|
||||||
|
|
||||||
const getProducts = async () => {
|
const increment = () => setCounter(prev => prev + 1);
|
||||||
const responce = await fetch('http://localhost:8000/products');
|
const decrement = () => setCounter(prev => prev - 1);
|
||||||
const data = await responce.json();
|
|
||||||
setProducts(data);
|
return (
|
||||||
}
|
|
||||||
React.useEffect(() => {
|
|
||||||
getProducts();
|
|
||||||
},[]);
|
|
||||||
console.log({...products});
|
|
||||||
return (
|
|
||||||
<>
|
<>
|
||||||
<div className={styles.container}>
|
<h2>Практика по созданию счетчика с колбэками</h2>
|
||||||
<Header />
|
<CounterButton label="Увеличить" onClick={increment} />
|
||||||
</div>
|
<CounterButton label="уменьшить" onClick={decrement} />
|
||||||
<div className={styles.container}>
|
<CounterDisplay value={counter} />
|
||||||
<ul className={styles.list}>
|
|
||||||
{products.map(product => (
|
|
||||||
<li>
|
|
||||||
<Product {...product} />
|
|
||||||
</li>
|
|
||||||
))}
|
|
||||||
</ul>
|
|
||||||
<MyComponent>
|
|
||||||
<h4>Заголовок</h4>
|
|
||||||
<p>Привет!</p>
|
|
||||||
</MyComponent>
|
|
||||||
<ol>
|
|
||||||
<RowList>
|
|
||||||
<li>первый</li>
|
|
||||||
<li>второй</li>
|
|
||||||
<li>третий</li>
|
|
||||||
</RowList>
|
|
||||||
</ol>
|
|
||||||
</div>
|
|
||||||
</>
|
</>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,135 +0,0 @@
|
|||||||
@use './assets/styles/variables' as *;
|
|
||||||
|
|
||||||
.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;
|
|
||||||
}
|
|
||||||
|
|
||||||
.actions {
|
|
||||||
display: flex;
|
|
||||||
align-items: center;
|
|
||||||
gap: 5px;
|
|
||||||
|
|
||||||
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.
|
Before Width: | Height: | Size: 23 KiB |
@@ -1,5 +0,0 @@
|
|||||||
$white-color: white;
|
|
||||||
$black-color: black;
|
|
||||||
|
|
||||||
$primary-color: #3258e3;
|
|
||||||
$seconday-color: #4432e3;
|
|
||||||
@@ -1,5 +1,6 @@
|
|||||||
import { StrictMode } from 'react'
|
import { StrictMode } from 'react'
|
||||||
import { createRoot } from 'react-dom/client'
|
import { createRoot } from 'react-dom/client'
|
||||||
|
|
||||||
import App from './App.jsx'
|
import App from './App.jsx'
|
||||||
|
|
||||||
createRoot(document.getElementById('root')).render(
|
createRoot(document.getElementById('root')).render(
|
||||||
|
|||||||
@@ -0,0 +1,22 @@
|
|||||||
|
.container {
|
||||||
|
display:flex;
|
||||||
|
flex-direction: row;
|
||||||
|
border: 1px solid black;
|
||||||
|
border-radius: 5px;
|
||||||
|
margin-bottom: 10px;
|
||||||
|
p {
|
||||||
|
padding: 5px 10px;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.counter {
|
||||||
|
&_display{
|
||||||
|
border: 1px solid black;
|
||||||
|
border-width: 3px;
|
||||||
|
border-radius: 10px;
|
||||||
|
padding: 10px;
|
||||||
|
width: 300px;
|
||||||
|
}
|
||||||
|
&_button{
|
||||||
|
padding: 10px;
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user