Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

create an all day event by drag and drop

import React from "react";
import { Calendar, momentLocalizer } from "react-big-calendar";
import moment from "moment";
import withDragAndDrop from "react-big-calendar/lib/addons/dragAndDrop";
import "react-big-calendar/lib/css/react-big-calendar.css";
import "react-big-calendar/lib/addons/dragAndDrop/styles.css";

const DnDCalendar = withDragAndDrop(Calendar);

const localizer = momentLocalizer(moment);

const events = [
  {
    id: 0,
    title: "All Day Event very long title",
    allDay: true,
    start: new Date(2015, 3, 0),
    end: new Date(2015, 3, 1)
  },
  {
    id: 1,
    title: "Long Event",
    start: new Date(2015, 3, 7),
    end: new Date(2015, 3, 10)
  },

  {
    id: 2,
    title: "DTS STARTS",
    start: new Date(2016, 2, 13, 0, 0, 0),
    end: new Date(2016, 2, 20, 0, 0, 0)
  },

  {
    id: 3,
    title: "DTS ENDS",
    start: new Date(2016, 10, 6, 0, 0, 0),
    end: new Date(2016, 10, 13, 0, 0, 0),
    desc: "Description is shown here"
  },

  {
    id: 4,
    title: "Leave",
    start: new Date(new Date().setHours(new Date().getHours() - 3)),
    end: new Date(new Date().setHours(new Date().getHours() + 3)),
    desc: "Description is shown here"
  }
];

const onEventDrop = ({ event, start, end, allDay }) => {
  console.log("event clicked");
  console.log(start, event, end, allDay);
};

const Scheduler = () => {
  return (
    <>
      <div className="wrapper" style={{ minHeight: "100vh" }}>
        <DnDCalendar
          selectable
          events={events}
          startAccessor="start"
          endAccessor="end"
          defaultDate={moment().toDate()}
          localizer={localizer}
          toolbar
          resizable
          onEventDrop={onEventDrop}
          components={{
            event: EventComponent,
            agenda: {
              event: EventAgenda
            }
          }}
          onSelectSlot={() => console.log("selected")}
          onSelectEvent={event => alert(event.desc)}
        />
      </div>
    </>
  );
};

export default Scheduler;

const EventComponent = ({ start, end, title }) => {
  return (
    <>
      <p>{title}</p>
      <p>{start}</p>
      <p>{end}</p>
    </>
  );
};

const EventAgenda = ({ event }) => {
  return (
    <span>
      <em style={{ color: "magenta" }}>{event.title}</em>
      <p>{event.desc}</p>
    </span>
  );
};
Comment

PREVIOUS NEXT
Code Example
Javascript :: Could not read source map for f@google-cloud/storage/build/src/channel.js: ENOENT: no such file or directory 
Javascript :: angular pwa app deploy script 
Javascript :: bad request while authenticating locally with passport-local-mongoose stackoverflow 
Javascript :: 4.3.2. Evaluating Variables¶ 
Javascript :: 5.1.1. Boolean Values¶ 
Javascript :: html click to copy to clipboard 
Javascript :: bjsmasth create 
Javascript :: ng serve -- port 5200 
Javascript :: exchange array.include(string) in Javascript to array.indexOf(string) == -1 in Typescript 
Javascript :: key being passed as prop react 
Javascript :: 8.1.3. Varying Data Types¶ Arrays 
Javascript :: javascrip loop array 
Javascript :: isempty is not a function javascript 
Javascript :: call a method of component from outside react 
Javascript :: Uso mixto de comillas simples 
Javascript :: get single element typeorm 
Javascript :: multiple confition checking jasvascript 
Javascript :: node red using tcp request 
Javascript :: read value state inside render 
Javascript :: how does we know which field is selected by user in nestjs query 
Javascript :: micromodal scrolls to bottom 
Javascript :: how to get the number of days in a month in javascript 
Javascript :: iife syntax 
Javascript :: js window selection get new line 
Javascript :: how to remove tashkeel from arabic charactor 
Javascript :: NetSuite Add Line Item to a Sales Order in afterSubmit 
Javascript :: check if a package is compatible with node 14 
Javascript :: check screen rotated js 
Javascript :: Javascript highest to lowest 
Javascript :: grapql file upload 
ADD CONTENT
Topic
Content
Source link
Name
9+9 =