Event Rendering

Above the built in rendering mode you can either customize the full event or just the content of the event. If we break up the event into pieces there are six fields that we are interested in:

  • The event start and end time
  • Whether it is an allDay event or not
  • The event color
  • The event title
  • bufferBefore
  • bufferAfter

The scheduler takes care of positioning the event container and everything else is your responsibility. You will have to place and provide styling to all event fields. Beside the ones mentioned above you'll be able to render other custom fields, like description, location, participants ... and add buttons, custom interactions.

Pass a custom rendering function to the renderSchedulerEvent option. All original event fields along with computed fields like isMultiDay, lastDay can be reached inside the function.

The before/after buffers can help you visualise delays or added minutes for tasks. For example travel time for meetings/appointments, check in/check out for flights.

The buffers can be customized through the renderBufferBefore and renderBufferAfter options.

Get started with this example

Demo

Loading the live demo

Preview in full screen

Render custom event cards in the Scheduler — add color stripes, labels, avatars, action buttons, and travel-time buffers.

Code

import { Button, Eventcalendar, getJson, setOptions, Toast  } from '@mobiscroll/react';
import { useCallback, useEffect, useMemo, useState } from 'react';

setOptions({
  locale:  ,
  theme: ' ',
  themeVariant: ' '
});

function App() {
  const [myEvents, setEvents] = useState([]);
  const [isToastOpen, setToastOpen] = useState(false);

  const resp = useMemo(
    () => ({
      xsmall: {
        view: {
          scheduler: {
            type: 'day',
          },
        },
      },
      medium: {
        view: {
          scheduler: {
            type: 'week',
          },
        },
      },
    }),
    [],
  );

  const handleCloseToast = useCallback(() => {
    setToastOpen(false);
  }, []);

  const getCategory = useCallback((id) => {
    switch (id) {
      case 1:
        return {
          name: 'Project X',
          color: '#ff825d',
        };
      case 2:
        return {
          name: 'Stakeholder Mtg.',
          color: '#bd75d0',
        };
      case 3:
        return {
          name: 'Status Update',
          color: '#7f9230',
        };
      case 4:
        return {
          name: 'Information Sharing',
          color: '#f14590',
        };
      case 5:
        return {
          name: 'Team Building',
          color: '#64cad4',
        };
      default:
        return {
          name: '',
          color: '',
        };
    }
  }, []);

  const getParticipant = useCallback((id) => {
    switch (id) {
      case 1:
        return {
          name: 'Lisa',
          img: 'https://img.mobiscroll.com/demos/f1.png',
        };
      case 2:
        return {
          name: 'Sharon',
          img: 'https://img.mobiscroll.com/demos/f2.png',
        };
      case 3:
        return {
          name: 'Emily',
          img: 'https://img.mobiscroll.com/demos/f3.png',
        };
      case 4:
        return {
          name: 'Rose',
          img: 'https://img.mobiscroll.com/demos/f4.png',
        };
      case 5:
        return {
          name: 'Matt',
          img: 'https://img.mobiscroll.com/demos/m1.png',
        };
      case 6:
        return {
          name: 'Rick',
          img: 'https://img.mobiscroll.com/demos/m2.png',
        };
      case 7:
        return {
          name: 'John',
          img: 'https://img.mobiscroll.com/demos/m3.png',
        };
      case 8:
        return {
          name: 'Ethan',
          img: 'https://img.mobiscroll.com/demos/m4.png',
        };
      default:
        return {
          name: '',
          img: '',
        };
    }
  }, []);

  const edit = useCallback(() => {
    setToastOpen(true);
  }, []);

  const customScheduleEvent = useCallback(
    (data) => {
      const original = data.original;
      const cat = getCategory(original.category);
      if (data.allDay) {
        return (
          <div style={{ background: cat.color }} className="md-custom-event-allday-title">
            {data.title}
          </div>
        );
      } else {
        return (
          <div className="md-custom-event-cont" style={{ borderLeft: '5px solid ' + cat.color, background: cat.color }}>
            <div className="md-custom-event-wrapper">
              <div style={{ background: cat.color }} className="md-custom-event-category">
                {cat.name}
              </div>
              <div className="md-custom-event-details">
                <div className="md-custom-event-title">{data.title}</div>
                <div className="md-custom-event-time">
                  {data.start} - {data.end}
                </div>
                <Button className="md-custom-event-btn" color="dark" variant="outline" onClick={edit}>
                  Edit
                </Button>
                <div className="md-cutom-event-img-cont">
                  {original.participants.map((p) => (
                    <img key={p} className="md-custom-event-img" src={getParticipant(p).img} />
                  ))}
                </div>
              </div>
            </div>
          </div>
        );
      }
    },
    [edit, getCategory, getParticipant],
  );

  const myBeforeBuffer = useCallback(
    (args) => {
      const cat = getCategory(args.original.category);

      return (
        <div className="md-schedule-buffer md-schedule-before-buffer">
          <div
            className="md-schedule-buffer-background"
            style={{ background: `repeating-linear-gradient(-45deg,#fcfffc,#fcfffc 10px,${cat.color} 10px,${cat.color} 20px)` }}
          ></div>
          <span className="md-buffer-text">Travel time </span>
          <span className="md-buffer-time">{args.original.bufferBefore} minutes </span>
        </div>
      );
    },
    [getCategory],
  );

  useEffect(() => {
    getJson(
      'https://trial.mobiscroll.com/multi-events/',
      (events) => {
        setEvents(events);
      },
      'jsonp',
    );
  }, []);

  return (
    <div>
      <Eventcalendar
        clickToCreate={ }
        dragToCreate={ }
        dragToMove={ }
        dragToResize={ }
        eventDelete={ }
        renderSchedulerEvent={customScheduleEvent}
        renderBufferBefore={myBeforeBuffer}
        responsive={resp}
        data={myEvents}
      />
      <Toast message="Edit clicked" isOpen={isToastOpen} onClose={handleCloseToast} />
    </div>
  );
}

export default App;

Duplicate Session

You have signed in on a different machine. To keep everything in sync, you have been signed out of this session.

If you need to invite team members, manage seats and accounts you can do it from the licenses page.

Duplicate Session

We noticed you are logged in on a different machine and have closed your old session.

If you need to invite team members, manage seats and accounts you can do it from the licenses page.