2021-11-30 17:00:58 +03:00
|
|
|
|
import React, { useState, useEffect } from 'react'
|
|
|
|
|
import ellipse from '../../images/ellipse.png'
|
|
|
|
|
import rectangle from '../../images/rectangle__calendar.png'
|
|
|
|
|
import calendarIcon from '../../images/calendar_icon.png'
|
|
|
|
|
import moment from 'moment'
|
|
|
|
|
import 'moment/locale/ru'
|
2021-12-07 10:58:19 +03:00
|
|
|
|
import { calendarHelper, currentMonthAndDay, } from './calendarHelper'
|
2021-11-30 17:00:58 +03:00
|
|
|
|
|
|
|
|
|
import './calendarComponent.scss'
|
2021-06-17 18:21:48 +03:00
|
|
|
|
|
2021-12-07 10:58:19 +03:00
|
|
|
|
const CalendarComponent = ({ onSelect }) => {
|
2021-11-30 17:00:58 +03:00
|
|
|
|
const [value, setValue] = useState(moment())
|
|
|
|
|
const [calendar, setCalendar] = useState([])
|
2021-06-17 18:21:48 +03:00
|
|
|
|
|
|
|
|
|
useEffect(() => {
|
2021-11-30 17:00:58 +03:00
|
|
|
|
setCalendar(calendarHelper(value))
|
|
|
|
|
}, [value])
|
2021-06-17 18:21:48 +03:00
|
|
|
|
|
2021-06-18 17:16:08 +03:00
|
|
|
|
function beforeToday(day) {
|
2021-11-30 17:00:58 +03:00
|
|
|
|
return day.isBefore(new Date(), 'day')
|
2021-06-17 18:21:48 +03:00
|
|
|
|
}
|
|
|
|
|
|
2021-06-18 17:16:08 +03:00
|
|
|
|
function isToday(day) {
|
2021-11-30 17:00:58 +03:00
|
|
|
|
return day.isSame(new Date(), 'day')
|
2021-06-18 17:16:08 +03:00
|
|
|
|
}
|
2021-06-17 18:21:48 +03:00
|
|
|
|
|
2021-06-18 17:16:08 +03:00
|
|
|
|
function dayStyles(day) {
|
2021-11-30 17:00:58 +03:00
|
|
|
|
if (beforeToday(day)) return `before`
|
|
|
|
|
if (isToday(day)) return `today`
|
|
|
|
|
if (day.day() === 6 || day.day() === 0) return `selected`
|
|
|
|
|
return ''
|
2021-06-17 18:21:48 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function prevMonth() {
|
2021-11-30 17:00:58 +03:00
|
|
|
|
return value.clone().subtract(1, 'month')
|
2021-06-17 18:21:48 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function nextMonth() {
|
2021-12-07 10:58:19 +03:00
|
|
|
|
return value.clone().add(1, 'month');
|
2021-11-30 17:00:58 +03:00
|
|
|
|
}
|
2021-06-23 13:17:59 +03:00
|
|
|
|
|
2021-06-17 18:21:48 +03:00
|
|
|
|
return (
|
2021-11-30 17:00:58 +03:00
|
|
|
|
<div className='calendar-component'>
|
|
|
|
|
<div className='calendar-component__header'>
|
2021-06-17 18:21:48 +03:00
|
|
|
|
<h3>Мои отчеты</h3>
|
2021-11-30 17:00:58 +03:00
|
|
|
|
<div className='calendar-component__header-box'>
|
|
|
|
|
<img src={ellipse} alt='' />
|
2021-12-07 10:58:19 +03:00
|
|
|
|
<span onClick={() => setValue(prevMonth())}>{prevMonth().format('MMMM')}</span>
|
2021-06-17 18:21:48 +03:00
|
|
|
|
</div>
|
2021-11-30 17:00:58 +03:00
|
|
|
|
<div className='calendar-component__header-box'>
|
|
|
|
|
<img src={ellipse} alt='' />
|
2021-12-07 10:58:19 +03:00
|
|
|
|
<span onClick={() => setValue(nextMonth())}>{nextMonth().format('MMMM')}</span>
|
2021-06-17 18:21:48 +03:00
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
|
2021-11-30 17:00:58 +03:00
|
|
|
|
<div className='calendar-component__rectangle'>
|
|
|
|
|
<img src={rectangle} alt='' />
|
2021-06-17 18:21:48 +03:00
|
|
|
|
</div>
|
|
|
|
|
|
2021-11-30 17:00:58 +03:00
|
|
|
|
<div className='calendar-component__body'>
|
2021-06-17 18:21:48 +03:00
|
|
|
|
<div>
|
2021-06-21 17:41:26 +03:00
|
|
|
|
<p>Пн</p>
|
|
|
|
|
<p>Вт</p>
|
|
|
|
|
<p>Ср</p>
|
|
|
|
|
<p>Чт</p>
|
|
|
|
|
<p>Пт</p>
|
|
|
|
|
<p>Сб</p>
|
|
|
|
|
<p>Вс</p>
|
2021-06-17 18:21:48 +03:00
|
|
|
|
</div>
|
|
|
|
|
|
2021-11-30 17:00:58 +03:00
|
|
|
|
<div className='calendar-component__form'>
|
2021-06-17 18:21:48 +03:00
|
|
|
|
{calendar.map((week) =>
|
|
|
|
|
week.map((day) => (
|
2021-06-18 17:16:08 +03:00
|
|
|
|
<button
|
2021-12-07 10:58:19 +03:00
|
|
|
|
onClick={() => { setValue(day); onSelect(day) }}
|
2021-06-18 17:16:08 +03:00
|
|
|
|
key={day}
|
|
|
|
|
className={dayStyles(day)}
|
|
|
|
|
name={day.format('dddd')}
|
2021-11-30 17:00:58 +03:00
|
|
|
|
id='btn'
|
2021-06-18 17:16:08 +03:00
|
|
|
|
>
|
2021-11-30 17:00:58 +03:00
|
|
|
|
<img className={'calendar__icon'} src={calendarIcon} alt='' />
|
2021-06-23 12:48:02 +03:00
|
|
|
|
{currentMonthAndDay(day)}
|
2021-06-17 18:21:48 +03:00
|
|
|
|
</button>
|
|
|
|
|
))
|
|
|
|
|
)}
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
2021-11-30 17:00:58 +03:00
|
|
|
|
)
|
|
|
|
|
}
|
2021-06-17 18:21:48 +03:00
|
|
|
|
|
2021-11-30 17:00:58 +03:00
|
|
|
|
export default CalendarComponent
|