Various Changes On Calendar Component

Separating components from each other (it was showing them all as date pickers)
Adding The Data Model Mr.Gorji Made and Using it
Adding The Description of Event Showing in footer By Clicking the Day

Next Step: Making Changes On The Dots in Days Lists
                  Getting And Comparing Month and year from Data and into The
                  Component
master
Pedram Keshavarzi 3 years ago
parent 503ad23094
commit 44f6c02a02
  1. 78
      src/components/Calendar/CalendarComponents/Calendar.js
  2. 2
      src/components/Calendar/CalendarComponents/DatePicker.js
  3. 20
      src/components/Calendar/CalendarComponents/components/DaysList.js
  4. 2
      src/components/Calendar/CalendarComponents/index.js
  5. 8
      src/components/Calendar/index.css
  6. 3
      src/components/Calendar/index.js
  7. 3
      src/components/SimpleDatePicker/index.js

@ -14,7 +14,7 @@ import { useLocaleUtils, useLocaleLanguage } from './shared/hooks';
import { Header, MonthSelector, YearSelector, DaysList } from './components'; import { Header, MonthSelector, YearSelector, DaysList } from './components';
export const Calendar = ({ const Calendar = ({
value, value,
onChange, onChange,
onDisabledDayError, onDisabledDayError,
@ -37,6 +37,7 @@ export const Calendar = ({
renderFooter, renderFooter,
customDaysClassName, customDaysClassName,
events, events,
renderEvents,
}) => { }) => {
const calendarElement = useRef(null); const calendarElement = useRef(null);
const [mainState, setMainState] = useState({ const [mainState, setMainState] = useState({
@ -45,7 +46,7 @@ export const Calendar = ({
isMonthSelectorOpen: false, isMonthSelectorOpen: false,
isYearSelectorOpen: false, isYearSelectorOpen: false,
}); });
const [eventInFooter, setEventInFooter] = useState(null);
useEffect(() => { useEffect(() => {
const handleKeyUp = ({ key }) => { const handleKeyUp = ({ key }) => {
/* istanbul ignore else */ /* istanbul ignore else */
@ -188,11 +189,16 @@ export const Calendar = ({
shouldHighlightWeekends={shouldHighlightWeekends} shouldHighlightWeekends={shouldHighlightWeekends}
customDaysClassName={customDaysClassName} customDaysClassName={customDaysClassName}
events={events} events={events}
renderFooter={renderFooter}
renderEvents={renderEvents}
isQuickSelectorOpen={ isQuickSelectorOpen={
mainState.isYearSelectorOpen || mainState.isMonthSelectorOpen mainState.isYearSelectorOpen || mainState.isMonthSelectorOpen
} }
showEvent={event => setEventInFooter(event)}
/> />
<div className="Calendar__footer">{renderFooter()}</div> <div className="Calendar__footer">
<p className='footer__Events'>{eventInFooter}</p>
{renderFooter()}</div>
</div> </div>
); );
}; };
@ -207,36 +213,64 @@ Calendar.defaultProps = {
locale: 'en', locale: 'en',
value: null, value: null,
renderFooter: () => null, renderFooter: () => null,
renderEvents : () => null,
customDaysClassName: [], customDaysClassName: [],
events: [ events: [
{ {
id: 1, id: 2,
day: 15, description: "تست 2",
occasions: [ type: "global",
{ isHoliday: false,
title: 'دی به دین روز، چهارمین جشن دیگان', date: "2022-01-04T00:00:00.000Z",
dotColor: '#eeffds1', year: 2022,
month: 1,
day: 2
}, },
{ {
title: 'lorem', id: 4,
dotColor: 'blue' description: "تست 4",
} type: "global",
] isHoliday: true,
date: "2022-01-12T00:00:00.000Z",
year: 2022,
month: 1,
day: 3
}, },
{ {
id: 2, id: 1,
day: 22, description: "تست کاربر 1",
title: 'مصاحبه کاری', type: "userDefined",
dotColor: 'red', userId: "5",
date: "2022-01-12T00:00:00.000Z",
categoryId: 1,
year: 2022,
month: 1,
day: 3
}, },
{ {
id: 3, id: 4,
title: 'اجاره خانه', description: "تست کاربر 4",
day: 21, type: "userDefined",
dotColor: 'blue', userId: "5",
date: "2022-01-08T00:00:00.000Z",
categoryId: 3,
year: 2022,
month: 1,
day: 6
}, },
{
id: 5,
description: "تست کاربر 5",
type: "userDefined",
userId: "5",
date: "2022-01-12T00:00:00.000Z",
categoryId: 1,
year: 2022,
month: 1,
day: 3
}
], ],
}; };
export default Calendar;

@ -1,6 +1,6 @@
import React, { useState, useEffect, useRef, useLayoutEffect } from 'react'; import React, { useState, useEffect, useRef, useLayoutEffect } from 'react';
import { Calendar } from './Calendar'; import Calendar from './Calendar';
import DatePickerInput from './DatePickerInput'; import DatePickerInput from './DatePickerInput';
import { getValueType } from './shared/generalUtils'; import { getValueType } from './shared/generalUtils';
import { TYPE_SINGLE_DATE, TYPE_MUTLI_DATE, TYPE_RANGE } from './shared/constants'; import { TYPE_SINGLE_DATE, TYPE_MUTLI_DATE, TYPE_RANGE } from './shared/constants';

@ -39,6 +39,7 @@ const DaysList = ({
isQuickSelectorOpen, isQuickSelectorOpen,
customDaysClassName, customDaysClassName,
events, events,
showEvent,
}) => { }) => {
const calendarSectionWrapper = useRef(null); const calendarSectionWrapper = useRef(null);
const { isRtl, weekDays: weekDaysList } = useLocaleLanguage(locale); const { isRtl, weekDays: weekDaysList } = useLocaleLanguage(locale);
@ -254,10 +255,6 @@ const DaysList = ({
isStandard, isStandard,
}); });
const specialDay = (sDay) => { const specialDay = (sDay) => {
// let specialDayArray = [];
// console.log(sDay);
// specialDayArray.push(events[i].day);
var eventDate; var eventDate;
for (var i = 0; i < events.length; i++) { for (var i = 0; i < events.length; i++) {
if (sDay == events[i].day) { if (sDay == events[i].day) {
@ -266,13 +263,18 @@ const DaysList = ({
} }
} }
// sDay = events[0].day;
// return sDay;
// console.log(sDay);
// console.log(specialDayArray[0])
}; };
const showEventDescription = (sDay) => {
var eventDate;
for (var i = 0; i < events.length; i++) {
if (sDay == events[i].day) {
return(events[i].description);
}
}
}
return ( return (
<div <div
style={{ style={{
@ -286,7 +288,7 @@ const DaysList = ({
onClick={() => { onClick={() => {
handleDayPress({ ...dayItem, isDisabled }); handleDayPress({ ...dayItem, isDisabled });
console.log(specialDay(day)); console.log(specialDay(day));
console.log(day) showEvent(showEventDescription(day))
}} }}
onKeyDown={({ key }) => { onKeyDown={({ key }) => {
/* istanbul ignore else */ /* istanbul ignore else */

@ -1,3 +1,3 @@
export { default } from './DatePicker'; export { default} from './DatePicker';
export * from './Calendar'; export * from './Calendar';
export { default as utils } from './shared/localeUtils'; export { default as utils } from './shared/localeUtils';

@ -666,6 +666,14 @@
position: relative; position: relative;
z-index: 1; z-index: 1;
} }
.Calendar__footer .footer__Events{
display: flex;
flex-direction: column;
align-items: center;
font-size: 12px;
font-family: 'IranSans';
padding: 3px;
}
.Calendar .holiday span{ .Calendar .holiday span{
color:#ff2929; color:#ff2929;

@ -1,6 +1,6 @@
import React, { useState } from "react"; import React, { useState } from "react";
import './index.css'; import './index.css';
import Calendar from "./CalendarComponents"; import Calendar from "./CalendarComponents/Calendar";
import { utils } from "./CalendarComponents"; import { utils } from "./CalendarComponents";
import './index.css'; import './index.css';
@ -18,7 +18,6 @@ const SimpleCalendar = () =>{
shouldHighlightWeekends shouldHighlightWeekends
renderFooter={() => <center><button onClick={() => setSelectedDay(utils('fa').getToday())}>برو به امروز</button></center>} renderFooter={() => <center><button onClick={() => setSelectedDay(utils('fa').getToday())}>برو به امروز</button></center>}
// customDaysClassName={specialDays} // customDaysClassName={specialDays}
events={[]}
locale="fa" // add this locale="fa" // add this
/> />
</div> </div>

@ -1,5 +1,6 @@
import React, { useState } from 'react'; import React, { useState } from 'react';
import DatePicker, {utils} from "react-modern-calendar-datepicker"; import DatePicker from "../Calendar/CalendarComponents";
import { utils } from "../Calendar/CalendarComponents";
import '../Calendar/index.css'; import '../Calendar/index.css';
const SimpleDatePicker = (props) =>{ const SimpleDatePicker = (props) =>{
const [selectedDay, setSelectedDay] = useState(null); const [selectedDay, setSelectedDay] = useState(null);

Loading…
Cancel
Save