This commit is contained in:
Андрей Дувакин 2025-01-28 18:51:35 +05:00
parent 7eda0718a8
commit 9b67ebf431
3 changed files with 252 additions and 148 deletions

View File

@ -110,8 +110,8 @@
.calendar { .calendar {
margin: 2vw; margin: 2vw;
border: 1px solid black;
height: 25vw; height: 25vw;
padding: 2vw;
} }
.events { .events {
@ -131,3 +131,56 @@
flex-direction: row; flex-direction: row;
justify-content: space-between; justify-content: space-between;
} }
.calendar-container {
width: 350px;
text-align: center;
font-family: Arial, sans-serif;
}
.calendar-header {
display: flex;
justify-content: space-between;
align-items: center;
background-color: #2f9836;
color: white;
padding: 10px;
border-radius: 8px;
}
.calendar-header button {
background: none;
border: none;
color: white;
font-size: 20px;
cursor: pointer;
}
.calendar-grid {
display: grid;
grid-template-columns: repeat(7, 1fr);
gap: 5px;
margin-top: 10px;
}
.calendar-weekday {
font-weight: bold;
text-align: center;
}
.calendar-day, .empty-cell {
width: 40px;
height: 40px;
display: flex;
align-items: center;
justify-content: center;
border-radius: 5px;
}
.calendar-day {
cursor: pointer;
}
.calendar-day:hover {
background-color: #cfcfcf;
}

View File

@ -0,0 +1,48 @@
'use client';
import {useState} from "react";
const Calendar = () => {
const [currentDate, setCurrentDate] = useState(new Date());
const year = currentDate.getFullYear();
const month = currentDate.getMonth();
const prevMonth = () => setCurrentDate(new Date(year, month - 1, 1));
const nextMonth = () => setCurrentDate(new Date(year, month + 1, 1));
const generateCalendar = () => {
const firstDayOfMonth = new Date(year, month, 1).getDay(); // День недели 1-го числа (0 - воскресенье)
const daysInMonth = new Date(year, month + 1, 0).getDate(); // Количество дней в месяце
const startOffset = firstDayOfMonth === 0 ? 6 : firstDayOfMonth - 1;
const daysArray = Array.from({length: daysInMonth}, (_, i) => i + 1);
return [...Array(startOffset).fill(null), ...daysArray];
};
const days = generateCalendar();
const weekDays = ["Пн", "Вт", "Ср", "Чт", "Пт", "Сб", "Вс"];
return (
<div className="calendar-container">
<div className="calendar-header">
<button onClick={prevMonth}>{"<"}</button>
<h2>{currentDate.toLocaleString("ru-RU", {month: "long", year: "numeric"})}</h2>
<button onClick={nextMonth}>{">"}</button>
</div>
<div className="calendar-grid">
{weekDays.map((day) => (
<div key={day} className="calendar-weekday">{day}</div>
))}
{days.map((day, index) =>
day ? <div key={index} className="calendar-day">{day}</div> :
<div key={index} className="empty-cell"></div>
)}
</div>
</div>
);
};
export default Calendar;

View File

@ -3,9 +3,10 @@
import './app.css'; import './app.css';
import Header from './components/header.js'; import Header from './components/header.js';
import EmployeeCard from './components/employee-card.js'; import EmployeeCard from './components/employee-card.js';
import { useEffect, useState } from 'react'; import {useEffect, useState} from 'react';
import RSSFeed from './components/news-card.js'; import RSSFeed from './components/news-card.js';
import EventCard from './components/event-card'; import EventCard from './components/event-card';
import Calendar from "./components/сalendar";
export default function Home() { export default function Home() {
const [searchString, setSearchString] = useState(''); const [searchString, setSearchString] = useState('');
@ -97,7 +98,7 @@ export default function Home() {
return ( return (
<> <>
<Header setSearchString={setSearchString} /> <Header setSearchString={setSearchString}/>
<div className="page"> <div className="page">
<div className="user-list"> <div className="user-list">
@ -110,7 +111,7 @@ export default function Home() {
{filteredEmployees.length > 0 ? ( {filteredEmployees.length > 0 ? (
filteredEmployees.map( filteredEmployees.map(
(employee) => ( (employee) => (
<EmployeeCard key={employee.id} employee={employee} /> <EmployeeCard key={employee.id} employee={employee}/>
) )
) )
) : ( ) : (
@ -129,6 +130,8 @@ export default function Home() {
<h1> <h1>
Календарь Календарь
</h1> </h1>
<Calendar/>
</div> </div>
<div className="events"> <div className="events">
@ -138,7 +141,7 @@ export default function Home() {
{filteredEvents.length > 0 ? (filteredEvents.map( {filteredEvents.length > 0 ? (filteredEvents.map(
(event, index) => ( (event, index) => (
<EventCard key={index} event={event} /> <EventCard key={index} event={event}/>
) )
)) : ( )) : (
<h2>События не найдены</h2> <h2>События не найдены</h2>
@ -154,8 +157,8 @@ export default function Home() {
</h1> </h1>
<div className='news-block'> <div className='news-block'>
{filteredNews.length > 0? (filteredNews.map((article, index) => ( {filteredNews.length > 0 ? (filteredNews.map((article, index) => (
<RSSFeed key={index} article={article} index={index} /> <RSSFeed key={index} article={article} index={index}/>
))) : ( ))) : (
<h2>Новости не найдены</h2> <h2>Новости не найдены</h2>
) )