Reputation: 2055
Fullcalendar React component:
import FullCalendar from "@fullcalendar/react";
import timeGrid from "@fullcalendar/resource-timegrid";
import resourceDayGridPlugin from '@fullcalendar/resource-daygrid';
class FC extends React.Component {
calendarComponentRef = React.createRef();
constructor(props) {
super(props);
this.state = {
events:[{ "id": 1, "title": "event 1", "description":"some description"},......]
}
}
eventRender(info){
var tooltip = new Tooltip(info.el, {
title: info.event.extendedProps.description,
placement: 'top',
trigger: 'hover',
container: 'body'
});
}
render() {
return <FullCalendar
events={this.state.getEvents}
defaultView="resourceTimeGridDay"
plugins={[timeGrid, interactionPlugin, resourceDayGridPlugin]}
eventRender={this.eventRender}
schedulerLicenseKey="GPL-My-Project-Is-Open-Source"
/>
}
}
Tooltip.js included in header
<script src="https://unpkg.com/popper.js/dist/umd/popper.min.js"></script>
<script rc="https://unpkg.com/tooltip.js/dist/umd/tooltip.min.js">/script>
Exactly trying to this demo in react, but it is not working in react version.
But tooltip not working
Fullcalendar react example project sample project react fullcalendar
Upvotes: 10
Views: 8732
Reputation: 2555
Inspired by @user-rebo, here’s an explanation with TypeScript on how to customize event rendering in fullcalendar
.
fullcalendar
's default event rendering method is renderInnerContent
. You can find this method in the fullcalendar
GitHub repository: FullCalendar StandardEvent.tsx - renderInnerContent
Since fullcalendar
does not export this method directly, you will need to copy the renderInnerContent
method into your project. This allows you to customize it as needed.
function renderInnerContent(innerProps: EventContentArg) {
return (
<div className="fc-event-main-frame">
{innerProps.timeText && (
<div className="fc-event-time">{innerProps.timeText}</div>
)}
<div className="fc-event-title-container">
<div className="fc-event-title fc-sticky">
{innerProps.event.title || <Fragment> </Fragment>}
</div>
</div>
</div>
)
}
Use a custom renderCustomEventContent
method in your fullcalendar
configuration. Here’s an example of how to integrate this within your FullCalendar setup:
const renderCustomEventContent = (eventInfo: EventContentArg) => (
<Tooltip title="My custom tooltip title" arrow placement="top">
{ renderInnerContent(eventInfo )}
</Tooltip>
);
To add a tooltip for a custom view, include the custom rendering of the event as follows:
views={{
resourceTimeGridSevenDays: {
...,
eventContent: renderCustomEventContent,
}
}}
If you want to override this for all views, simply use the eventContent method directly in FullCalendar.
<Calendar
...
eventContent={renderCustomEventContent}
/>
Result:
Upvotes: 0
Reputation: 778
Best I did so far. This will at least give a title to an event.
<FullCalendar eventDidMount={renderEventContent} .....
function renderEventContent(info) {
info.el.setAttribute('title', info.event.title)
}
Upvotes: 1
Reputation: 4580
With content injection hook e.g. for Material-ui tooltip:
eventContent: ( arg ) => {
return (
<Tooltip title={ <Typography color="inherit">Tooltip with HTML</Typography> } arrow>
{ renderInnerContent( arg ) }
</Tooltip>
);
}
If you want to have the exact same content as the default, then copy the function from fullcalendar source:
/**
* https://github.com/fullcalendar/fullcalendar/blob/495d925436e533db2fd591e09a0c887adca77053/packages/common/src/common/StandardEvent.tsx#L79
*/
function renderInnerContent( innerProps ) {
return (
<div className='fc-event-main-frame'>
{ innerProps.timeText &&
<div className='fc-event-time'>{ innerProps.timeText }</div>
}
<div className='fc-event-title-container'>
<div className='fc-event-title fc-sticky'>
{ innerProps.event.title || <Fragment> </Fragment> }
</div>
</div>
</div>
);
}
To differentiate ListView
content from default content you can use this code (given a Calendar reference calendarRef):
eventContent: ( arg ) => {
const data = calendarRef.current.getApi().getCurrentData();
const viewSpec = data.viewSpecs[arg.view.type];
let innerContent;
if (viewSpec.component === ListView) {
/**
* https://github.com/fullcalendar/fullcalendar/blob/495d925436e533db2fd591e09a0c887adca77053/packages/list/src/ListViewEventRow.tsx#L55
*/
innerContent = renderListInnerContent( arg );
} else {
innerContent = renderInnerContent( arg );
}
return ( <Tooltip ... >{ innerContent }</Tooltip>);
};
Upvotes: 12
Reputation: 41
Tooltip using tippy with eventMouseEnter
handleMouseEnter = (arg) =>{
tippy(arg.el, {
content: "my tooltip!"
});
}
in component
render() {
return (
<FullCalendar ref={this.calendarRef}
plugins={[dayGridPlugin, interactionPlugin]}
initialView="dayGridMonth"
weekends={true}
eventMouseEnter={this.handleMouseEnter}
/>
)
}
Upvotes: 4
Reputation: 2055
Tooltip using Tooltip.js
eventRender(info){
var tooltip = new Tooltip(info.el, {
title: info.event.extendedProps.description,
placement: 'top',
trigger: 'hover',
container: 'body'
});
}
In component :
render() {
return <FullCalendar
events={this.state.getEvents}
defaultView="resourceTimeGridDay"
plugins={[timeGrid, interactionPlugin, resourceDayGridPlugin]}
eventRender={this.eventRender}
schedulerLicenseKey="GPL-My-Project-Is-Open-Source"
/>
}
OR
using react-tooltip
import ReactTooltip from 'react-tooltip'
and method to handle eventPosition
handleEventPositioned(info) {
info.el.setAttribute("data-tip","some text tip");
ReactTooltip.rebuild();
}
and
render() {
return <FullCalendar
events={this.state.getEvents}
defaultView="resourceTimeGridDay"
plugins={[timeGrid, interactionPlugin, resourceDayGridPlugin]}
eventPositioned={this.handleEventPositioned}
schedulerLicenseKey="GPL-My-Project-Is-Open-Source"
/>
}
Upvotes: 4