Reputation: 5566
I am using a full calendar API api to display a calendar on my website inspired by the promo.com calendar which looks like this.
Here is my solution using react js component
import React, { useState, useEffect, useContext, useRef } from 'react';
import { Calendar as FullCalendar } from '@fullcalendar/core';
import googleCalendarPlugin from '@fullcalendar/google-calendar';
import dayGridPlugin from '@fullcalendar/daygrid';
import timeGridPlugin from '@fullcalendar/timegrid';
import interactionPlugin from '@fullcalendar/interaction';
import calendartopbg from 'assets/images/calendar_bg.png';
import cloud from 'assets/images/calendar_chmurka.png';
import styled from 'styled-components';
const Calendar = () => {
const [calendar, setCalendar] = useState('');
const calendarRef = useRef('');
useEffect(() => {
if (calendarRef.current) {
console.log(FullCalendar);
setCalendar(new FullCalendar(calendarRef.current, {
plugins: [dayGridPlugin, timeGridPlugin, interactionPlugin, googleCalendarPlugin],
theme: false,
header: {
left: 'prev,next today',
center: 'title',
right: 'dayGridMonth,listYear',
},
views: {
day: {
titleFormat: 'dddd, MMMM Do YYYY'
}
},
googleCalendarApiKey: 'AIzaSyDcnW6WejpTOCffshGDDb4neIrXVUA1EAE',
events: 'en.usa#[email protected]',
eventClick: function(arg) {
// opens events in a popup window
window.open(arg.event.url, '_blank', 'width=700,height=600');
// prevents current tab from navigating
arg.jsEvent.preventDefault();
}
}));
}
}, [calendarRef.current]);
console.log(calendar);
return (
<>
<CalendarBackgroundWrapper>
<img style={imagestyle} src={calendartopbg} />
</CalendarBackgroundWrapper>
<CalendarContainer ref={calendarRef}>
{calendar && calendar.render ? calendar.render(): null}
</CalendarContainer>
</>
)
}
export default Calendar;
From the above solution I have the following
Now I would like to show date like that of the promo I provided above meaning
instead of 01
and 02
etc, it should be sun o1
, mon 02
, tue 03
etc
How can I achieve that using a full calendar API.?
Upvotes: 2
Views: 1604
Reputation: 798
@user9964622, As a starting point below code can be used, it should be optimized further by CSS and your code:
Write a function to get day name:
function getDayName(date) {
var days = new Array(7);
days[0] = "SUN";
days[1] = "MON";
days[2] = "TUE";
days[3] = "WED";
days[4] = "THU";
days[5] = "FRI";
days[6] = "SAT";
var r = days[date.getDay()];
return (r);
}
Include following code in FullCalendar:
columnHeader: false,
dayRender: function( dayRenderInfo ) {
var dayName = getDayName(dayRenderInfo.date);
var dayNumber = dayRenderInfo.date.getDate();
dayRenderInfo.el.innerHTML = dayName + "<br/>" + dayNumber;
}
You should apply css to hide the current date:
.fc-day-number {display: none;}
Further you can apply styles and include more html in dayRender.
Upvotes: 1