Урок 2 делали

This commit is contained in:
2026-04-30 18:50:22 +03:00
parent 91a6340078
commit 80fd4ed7cc
2 changed files with 41 additions and 14 deletions
+27 -12
View File
@@ -1,7 +1,9 @@
import styles from './App.module.scss' import styles from './App.module.scss'
import SneakersImage from './assets/images/sneakers-image.jpg' import SneakersImage from './assets/images/sneakers-image.jpg'
import { FaRegUser } from 'react-icons/fa' import { FaRegUser } from 'react-icons/fa'
import React from 'react' import { FaHeart } from "react-icons/fa";
import { BsCheckSquare } from "react-icons/bs";
import { useState } from 'react'
function Header() { function Header() {
const handleChange = event => { const handleChange = event => {
@@ -24,26 +26,39 @@ function Header() {
} }
function Product() { 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}></div>
</div>
</>
)
}
function handleClick() { function handleClick() {
console.log('Working!') console.log('Working!')
} }
function Counter() { function Counter() {
const [title,setTitle] = React.useState(''); const [isLiked,setIsLiked] = useState(false);
const [titleValue,setTitleValue] = React.useState({
title:'',
});
console.log(titleValue); const toggleLike = () => {
setIsLiked(!isLiked);
}
return ( return (
<> <>
<input <BsCheckSquare
value={title} onClick={toggleLike}
type="text" fill={isLiked==true ? 'red' : 'grey'}
onChange={e => setTitle(e.target.value)} size={44}
/> />
<button onClick={setTitleValue(title)}>Установить заголовок</button>
</> </>
) )
} }
@@ -59,7 +74,7 @@ function Product() {
<p className={styles.description}>NIKE</p> <p className={styles.description}>NIKE</p>
<p className={styles.price}>$38.00</p> <p className={styles.price}>$38.00</p>
</div> </div>
<Counter /> <LikeCounter />
</div> </div>
) )
} }
+12
View File
@@ -1,5 +1,17 @@
@use './assets/styles/variables' as *; @use './assets/styles/variables' as *;
.progress {
width: 100%;
height: 10px;
border: 1px solid black;
}
.value {
width:70%;
height: 100%;
background-color: green;
}
.header { .header {
display: flex; display: flex;
justify-content: space-between; justify-content: space-between;