Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

React Fullcalendar v4 tooltip

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

like image 964
ramamoorthy_villi Avatar asked Jul 25 '19 04:07

ramamoorthy_villi


2 Answers

FullCalendar v5

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>&nbsp;</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>);
};
like image 192
User Rebo Avatar answered Sep 18 '22 15:09

User Rebo


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"
            />

      }
like image 27
ramamoorthy_villi Avatar answered Sep 19 '22 15:09

ramamoorthy_villi