|
|
@ -1,20 +1,20 @@ |
|
|
|
import React, { useState, useRef, useEffect } from 'react'; |
|
|
|
import React, { useState, useRef, useEffect } from "react"; |
|
|
|
|
|
|
|
|
|
|
|
import { |
|
|
|
import { |
|
|
|
getDateAccordingToMonth, |
|
|
|
getDateAccordingToMonth, |
|
|
|
shallowClone, |
|
|
|
shallowClone, |
|
|
|
getValueType, |
|
|
|
getValueType, |
|
|
|
} from './shared/generalUtils'; |
|
|
|
} from "./shared/generalUtils"; |
|
|
|
import { |
|
|
|
import { |
|
|
|
TYPE_SINGLE_DATE, |
|
|
|
TYPE_SINGLE_DATE, |
|
|
|
TYPE_RANGE, |
|
|
|
TYPE_RANGE, |
|
|
|
TYPE_MUTLI_DATE, |
|
|
|
TYPE_MUTLI_DATE, |
|
|
|
} from './shared/constants'; |
|
|
|
} from "./shared/constants"; |
|
|
|
import { useLocaleUtils, useLocaleLanguage } from './shared/hooks'; |
|
|
|
import { useLocaleUtils, useLocaleLanguage } from "./shared/hooks"; |
|
|
|
|
|
|
|
|
|
|
|
import { Header, MonthSelector, YearSelector, DaysList } from './components'; |
|
|
|
import { Header, MonthSelector, YearSelector, DaysList } from "./components"; |
|
|
|
|
|
|
|
|
|
|
|
const Calendar = ({ |
|
|
|
const Calendar = ({ |
|
|
|
value, |
|
|
|
value, |
|
|
|
onChange, |
|
|
|
onChange, |
|
|
|
onDisabledDayError, |
|
|
|
onDisabledDayError, |
|
|
@ -38,12 +38,12 @@ import { Header, MonthSelector, YearSelector, DaysList } from './components'; |
|
|
|
customDaysClassName, |
|
|
|
customDaysClassName, |
|
|
|
events, |
|
|
|
events, |
|
|
|
renderEvents, |
|
|
|
renderEvents, |
|
|
|
type |
|
|
|
type, |
|
|
|
}) => { |
|
|
|
}) => { |
|
|
|
const calendarElement = useRef(null); |
|
|
|
const calendarElement = useRef(null); |
|
|
|
const [mainState, setMainState] = useState({ |
|
|
|
const [mainState, setMainState] = useState({ |
|
|
|
activeDate: null, |
|
|
|
activeDate: null, |
|
|
|
monthChangeDirection: '', |
|
|
|
monthChangeDirection: "", |
|
|
|
isMonthSelectorOpen: false, |
|
|
|
isMonthSelectorOpen: false, |
|
|
|
isYearSelectorOpen: false, |
|
|
|
isYearSelectorOpen: false, |
|
|
|
}); |
|
|
|
}); |
|
|
@ -51,10 +51,10 @@ import { Header, MonthSelector, YearSelector, DaysList } from './components'; |
|
|
|
useEffect(() => { |
|
|
|
useEffect(() => { |
|
|
|
const handleKeyUp = ({ key }) => { |
|
|
|
const handleKeyUp = ({ key }) => { |
|
|
|
/* istanbul ignore else */ |
|
|
|
/* istanbul ignore else */ |
|
|
|
if (key === 'Tab') |
|
|
|
if (key === "Tab") |
|
|
|
calendarElement.current.classList.remove('-noFocusOutline'); |
|
|
|
calendarElement.current.classList.remove("-noFocusOutline"); |
|
|
|
}; |
|
|
|
}; |
|
|
|
calendarElement.current.addEventListener('keyup', handleKeyUp, false); |
|
|
|
calendarElement.current.addEventListener("keyup", handleKeyUp, false); |
|
|
|
return () => { |
|
|
|
return () => { |
|
|
|
// calendarElement.current.removeEventListener('keyup', handleKeyUp, false);
|
|
|
|
// calendarElement.current.removeEventListener('keyup', handleKeyUp, false);
|
|
|
|
}; |
|
|
|
}; |
|
|
@ -68,8 +68,8 @@ import { Header, MonthSelector, YearSelector, DaysList } from './components'; |
|
|
|
setMainState({ ...mainState, [property]: !mainState[property] }); |
|
|
|
setMainState({ ...mainState, [property]: !mainState[property] }); |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
const toggleMonthSelector = createStateToggler('isMonthSelectorOpen'); |
|
|
|
const toggleMonthSelector = createStateToggler("isMonthSelectorOpen"); |
|
|
|
const toggleYearSelector = createStateToggler('isYearSelectorOpen'); |
|
|
|
const toggleYearSelector = createStateToggler("isYearSelectorOpen"); |
|
|
|
|
|
|
|
|
|
|
|
const getComputedActiveDate = () => { |
|
|
|
const getComputedActiveDate = () => { |
|
|
|
const valueType = getValueType(value); |
|
|
|
const valueType = getValueType(value); |
|
|
@ -85,8 +85,12 @@ import { Header, MonthSelector, YearSelector, DaysList } from './components'; |
|
|
|
: getComputedActiveDate(); |
|
|
|
: getComputedActiveDate(); |
|
|
|
|
|
|
|
|
|
|
|
const weekdays = weekDaysList.map((weekDay) => ( |
|
|
|
const weekdays = weekDaysList.map((weekDay) => ( |
|
|
|
<abbr key={weekDay.name} title={weekDay.name} className={`Calendar__weekDay ${type}`}> |
|
|
|
<abbr |
|
|
|
{ type == 'dashboard' ? weekDay.name : weekDay.short} |
|
|
|
key={weekDay.name} |
|
|
|
|
|
|
|
title={weekDay.name} |
|
|
|
|
|
|
|
className={`Calendar__weekDay ${type}`} |
|
|
|
|
|
|
|
> |
|
|
|
|
|
|
|
{type == "dashboard" ? weekDay.name : weekDay.short} |
|
|
|
</abbr> |
|
|
|
</abbr> |
|
|
|
)); |
|
|
|
)); |
|
|
|
|
|
|
|
|
|
|
@ -104,7 +108,7 @@ import { Header, MonthSelector, YearSelector, DaysList } from './components'; |
|
|
|
activeDate, |
|
|
|
activeDate, |
|
|
|
mainState.monthChangeDirection |
|
|
|
mainState.monthChangeDirection |
|
|
|
), |
|
|
|
), |
|
|
|
monthChangeDirection: '', |
|
|
|
monthChangeDirection: "", |
|
|
|
}); |
|
|
|
}); |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
@ -126,13 +130,14 @@ import { Header, MonthSelector, YearSelector, DaysList } from './components'; |
|
|
|
|
|
|
|
|
|
|
|
return ( |
|
|
|
return ( |
|
|
|
<div |
|
|
|
<div |
|
|
|
className={`Calendar ${type} -noFocusOutline ${calendarClassName} -${isRtl ? 'rtl' : 'ltr' |
|
|
|
className={`Calendar ${type} -noFocusOutline ${calendarClassName} -${ |
|
|
|
|
|
|
|
isRtl ? "rtl" : "ltr" |
|
|
|
}`}
|
|
|
|
}`}
|
|
|
|
role="grid" |
|
|
|
role="grid" |
|
|
|
style={{ |
|
|
|
style={{ |
|
|
|
'--cl-color-primary': colorPrimary, |
|
|
|
"--cl-color-primary": colorPrimary, |
|
|
|
'--cl-color-primary-light': colorPrimaryLight, |
|
|
|
"--cl-color-primary-light": colorPrimaryLight, |
|
|
|
'--animation-duration': slideAnimationDuration, |
|
|
|
"--animation-duration": slideAnimationDuration, |
|
|
|
}} |
|
|
|
}} |
|
|
|
ref={calendarElement} |
|
|
|
ref={calendarElement} |
|
|
|
> |
|
|
|
> |
|
|
@ -196,18 +201,28 @@ import { Header, MonthSelector, YearSelector, DaysList } from './components'; |
|
|
|
isQuickSelectorOpen={ |
|
|
|
isQuickSelectorOpen={ |
|
|
|
mainState.isYearSelectorOpen || mainState.isMonthSelectorOpen |
|
|
|
mainState.isYearSelectorOpen || mainState.isMonthSelectorOpen |
|
|
|
} |
|
|
|
} |
|
|
|
showEvent={event => setEventInFooter(event)} |
|
|
|
showEvent={(event) => setEventInFooter(event)} |
|
|
|
type={type} |
|
|
|
type={type} |
|
|
|
/> |
|
|
|
/> |
|
|
|
<div className="Calendar__footer"> |
|
|
|
<div className="Calendar__footer"> |
|
|
|
<div className={`footer__Events ${type}`}> |
|
|
|
<div className={`footer__Events ${type}`}> |
|
|
|
{ |
|
|
|
{type == "dashboard" ? ( |
|
|
|
type == 'dashboard' ? <><div className='text-xl font-black text-blue-400'>رویداد ها: </div><p className='text-blue-300 font-bold'>{eventInFooter ? eventInFooter : 'رویدادی در این روز وجود ندارد!'}</p></> : eventInFooter |
|
|
|
<> |
|
|
|
} |
|
|
|
<div className="text-xl font-black text-blue-400"> |
|
|
|
|
|
|
|
رویداد ها:{" "} |
|
|
|
|
|
|
|
</div> |
|
|
|
|
|
|
|
<p className="text-blue-300 font-sansbold"> |
|
|
|
|
|
|
|
{eventInFooter |
|
|
|
|
|
|
|
? eventInFooter |
|
|
|
|
|
|
|
: "رویدادی در این روز وجود ندارد!"} |
|
|
|
|
|
|
|
</p> |
|
|
|
|
|
|
|
</> |
|
|
|
|
|
|
|
) : ( |
|
|
|
|
|
|
|
eventInFooter |
|
|
|
|
|
|
|
)} |
|
|
|
|
|
|
|
</div> |
|
|
|
|
|
|
|
{renderFooter()} |
|
|
|
</div> |
|
|
|
</div> |
|
|
|
{renderFooter()}</div> |
|
|
|
|
|
|
|
</div> |
|
|
|
</div> |
|
|
|
); |
|
|
|
); |
|
|
|
}; |
|
|
|
}; |
|
|
@ -215,17 +230,16 @@ import { Header, MonthSelector, YearSelector, DaysList } from './components'; |
|
|
|
Calendar.defaultProps = { |
|
|
|
Calendar.defaultProps = { |
|
|
|
minimumDate: null, |
|
|
|
minimumDate: null, |
|
|
|
maximumDate: null, |
|
|
|
maximumDate: null, |
|
|
|
colorPrimary: '#0eca2d', |
|
|
|
colorPrimary: "#0eca2d", |
|
|
|
colorPrimaryLight: '#cff4d5', |
|
|
|
colorPrimaryLight: "#cff4d5", |
|
|
|
slideAnimationDuration: '0.4s', |
|
|
|
slideAnimationDuration: "0.4s", |
|
|
|
calendarClassName: '', |
|
|
|
calendarClassName: "", |
|
|
|
locale: 'en', |
|
|
|
locale: "en", |
|
|
|
value: null, |
|
|
|
value: null, |
|
|
|
renderFooter: () => null, |
|
|
|
renderFooter: () => null, |
|
|
|
renderEvents : () => null, |
|
|
|
renderEvents: () => null, |
|
|
|
customDaysClassName: [], |
|
|
|
customDaysClassName: [], |
|
|
|
events: [], |
|
|
|
events: [], |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
export default Calendar; |
|
|
|
export default Calendar; |