Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 2775fc8283 | |||
| c9759fbfc7 |
-13
@@ -5,19 +5,6 @@
|
||||
<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: #ecfeff;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div id="root"></div>
|
||||
|
||||
Generated
-11
@@ -20,7 +20,6 @@
|
||||
"eslint-plugin-react-hooks": "^5.2.0",
|
||||
"eslint-plugin-react-refresh": "^0.4.19",
|
||||
"globals": "^16.0.0",
|
||||
"react-icons": "^5.6.0",
|
||||
"vite": "^6.3.5"
|
||||
}
|
||||
},
|
||||
@@ -2462,16 +2461,6 @@
|
||||
"react": "^19.1.0"
|
||||
}
|
||||
},
|
||||
"node_modules/react-icons": {
|
||||
"version": "5.6.0",
|
||||
"resolved": "https://registry.npmjs.org/react-icons/-/react-icons-5.6.0.tgz",
|
||||
"integrity": "sha512-RH93p5ki6LfOiIt0UtDyNg/cee+HLVR6cHHtW3wALfo+eOHTp8RnU2kRkI6E+H19zMIs03DyxUG/GfZMOGvmiA==",
|
||||
"dev": true,
|
||||
"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",
|
||||
|
||||
+1
-2
@@ -4,7 +4,7 @@
|
||||
"version": "0.0.0",
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"dev": "vite",
|
||||
"dev": "vite",
|
||||
"build": "vite build",
|
||||
"lint": "eslint .",
|
||||
"preview": "vite preview"
|
||||
@@ -22,7 +22,6 @@
|
||||
"eslint-plugin-react-hooks": "^5.2.0",
|
||||
"eslint-plugin-react-refresh": "^0.4.19",
|
||||
"globals": "^16.0.0",
|
||||
"react-icons": "^5.6.0",
|
||||
"vite": "^6.3.5"
|
||||
}
|
||||
}
|
||||
|
||||
+81
-57
@@ -1,72 +1,96 @@
|
||||
import styles from './App.module.css'
|
||||
import SneakersImage from './assets/images/sneakers-image.jpg'
|
||||
import { FaRegUser } from 'react-icons/fa'
|
||||
import React from 'react'
|
||||
import styles from './App.module.scss'
|
||||
|
||||
function handleClick(i) {
|
||||
console.log(i);
|
||||
class Clock extends React.Component {
|
||||
constructor(props) {
|
||||
super(props);
|
||||
this.state = { date: new Date() };
|
||||
}
|
||||
componentDidMount() {
|
||||
this.timerId = setInterval( () => this.tick(), 1000);
|
||||
}
|
||||
componentWillUnmount() {
|
||||
clearInterval(this.timerId)
|
||||
}
|
||||
tick() {
|
||||
this.setState({ date: new Date() })
|
||||
}
|
||||
render() {
|
||||
return <div>{this.state.date.toLocaleTimeString()}</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 Clock2() {
|
||||
const [date, setDate] = React.useState(new Date());
|
||||
|
||||
React.useEffect(()=>{
|
||||
const timerId = setInterval(()=> setDate(new Date()),1000);
|
||||
return () => clearInterval(timerId);
|
||||
},[])
|
||||
|
||||
return <div>{date.toLocaleTimeString()}</div>
|
||||
}
|
||||
|
||||
function Product() {
|
||||
const handlerMouseEnter = event => {
|
||||
const img = event.target;
|
||||
img.style.border = '5px solid yellow';
|
||||
function MouseTracker() {
|
||||
const [x,setX] = React.useState(0);
|
||||
const [y,setY] = React.useState(0);
|
||||
|
||||
const mouseMoveHandler = event => {
|
||||
setX(event.clientX);
|
||||
setY(event.clientY);
|
||||
}
|
||||
const handlerMouseOut = event => {
|
||||
const img = event.target;
|
||||
img.style.border = '';
|
||||
console.log(event);
|
||||
|
||||
React.useEffect(()=>{
|
||||
document.addEventListener('mousemove', mouseMoveHandler);
|
||||
return () => {
|
||||
document.removeEventListener('mousemove',mouseMoveHandler);
|
||||
}
|
||||
},[]);
|
||||
|
||||
return <div className={styles.container}>
|
||||
<p>Координаты мыши:<br /> X:<b>{x}</b>, Y:<b>{y}</b></p>
|
||||
</div>
|
||||
}
|
||||
|
||||
function DataFetcher() {
|
||||
const [posts,setPosts] = React.useState([]);
|
||||
const [users,setUsers] = React.useState([]);
|
||||
|
||||
const getPosts = async () => {
|
||||
const response = await fetch('https://jsonplaceholder.typicode.com/posts');
|
||||
const data = await response.json();
|
||||
setUsers(data.reduce((acc, value) => {
|
||||
if (!(value.userId in acc))
|
||||
return [...acc,value.userId]
|
||||
return acc
|
||||
}))
|
||||
console.log(users);
|
||||
setPosts(data.slice(1,10));
|
||||
|
||||
}
|
||||
return (
|
||||
<div className={styles.product}>
|
||||
<img src={SneakersImage} alt='' onMouseEnter={handlerMouseEnter} onMouseOut={handlerMouseOut} />
|
||||
<div className={styles.content}>
|
||||
<div className={styles.title}>
|
||||
<h4>Sneakers Red & White 2025</h4>
|
||||
<button onClick={() => handleClick(0)} onMouseEnter={handlerMouseEnter} onMouseOut={handlerMouseOut}>+</button>
|
||||
</div>
|
||||
<p className={styles.description}>NIKE</p>
|
||||
<p className={styles.price}>$38.00</p>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
|
||||
React.useEffect(() => {
|
||||
console.log("Компонент создан");
|
||||
getPosts();
|
||||
return () => {console.log("Компонент удален");setPosts([])};
|
||||
},[])
|
||||
|
||||
return <div><ol>{posts.map(post => <li id={post.id}>{post.title}</li>)}</ol></div>
|
||||
}
|
||||
|
||||
function App() {
|
||||
const [tracker,setTracker] = React.useState(false);
|
||||
const [dataFetcher,setDataFetcher] = React.useState(false);
|
||||
|
||||
return (
|
||||
<>
|
||||
<div className={styles.container}>
|
||||
<Header />
|
||||
<ul className={styles.list}>
|
||||
<li>
|
||||
<Product />
|
||||
</li>
|
||||
<li>
|
||||
<Product />
|
||||
</li>
|
||||
<li>
|
||||
<Product />
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
<h1>Hello, React!</h1>
|
||||
<Clock />
|
||||
<Clock2 />
|
||||
<button onClick={() => setTracker(!tracker)}>Показать/Скрыть трекер</button>
|
||||
{ tracker && <MouseTracker /> }
|
||||
<button onClick={() => setDataFetcher(!dataFetcher)}>Показать/Скрыть посты</button>
|
||||
{ dataFetcher && <DataFetcher /> }
|
||||
</>
|
||||
)
|
||||
}
|
||||
|
||||
@@ -1,123 +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;
|
||||
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 {
|
||||
background-color: black;
|
||||
color: white;
|
||||
border: 0;
|
||||
border-radius: 50%;
|
||||
outline: 0;
|
||||
|
||||
font-size: 20px;
|
||||
padding: 5px 10px;
|
||||
|
||||
cursor: pointer;
|
||||
}
|
||||
}
|
||||
|
||||
img {
|
||||
border-radius: 10px;
|
||||
}
|
||||
|
||||
.description {
|
||||
color: gray;
|
||||
}
|
||||
|
||||
.price {
|
||||
font-weight: bold;
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
.container {
|
||||
width: 300px;
|
||||
height: 200px;
|
||||
border: 2px dashed grey;
|
||||
margin: 10px;
|
||||
text-align: center;
|
||||
p {
|
||||
margin-top: 20%;
|
||||
}
|
||||
}
|
||||
|
||||
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 { createRoot } from 'react-dom/client'
|
||||
// удаляем import './index.css'
|
||||
import App from './App.jsx'
|
||||
|
||||
createRoot(document.getElementById('root')).render(
|
||||
|
||||
Reference in New Issue
Block a user