3.1.0 β€’ Published 8 months ago

react-mui-scheduler-ru v3.1.0

Weekly downloads
-
License
MIT
Repository
github
Last release
8 months ago

React mui scheduler is a react component based on @mui v5 that allows you to manage events in a calendar.

πŸš€ Installation

  npm install react-mui-scheduler

πŸ’» Usage

import React, { useState } from "react";
import ReactDOM from "react-dom";
import Scheduler, { Event, Mode, StartWeek, TransitionMode } from "react-mui-scheduler";
import PlayCircleOutlineIcon from "@mui/icons-material/PlayCircleOutline";
import AutorenewIcon from "@mui/icons-material/Autorenew";
import ArchiveIcon from "@mui/icons-material/Archive";
import LocalPrintshopIcon from "@mui/icons-material/LocalPrintshop";

const App = () => {
  const [state] = useState({
    options: {
      transitionMode: TransitionMode.ZOOM, // or TransitionMode.FADE
      startWeekOn: StartWeek.MON,     // or StartWeek.SUN
      defaultMode: Mode.MONTH,    // or Mode.WEEK | Mode.DAY | Mode.TIMELINE
      minWidth: 540,
      maxWidth: 540,
      minHeight: 540,
      maxHeight: 540,
      reverseTimelineOrder: false,
    },
    alertProps: {
      open: true,
      color: "info",          // info | success | warning | error
      severity: "info",       // info | success | warning | error
      message: "πŸš€ Let's start with awesome react-mui-scheduler πŸ”₯ πŸ”₯ πŸ”₯",
      showActionButton: true,
      showNotification: true,
      delay: 1500,
    },
    toolbarProps: {
      showSearchBar: true,
      showSwitchModeButtons: {
        showMonthButton: true,
        showWeekButton: true,
        showDayButton: true,
        showTimelineButton: true,
      },
      showDatePicker: true,
      showTodayAction: true,
      showOptions: true,
      optionMenus: [
        {
          label: "Read events",
          icon: <PlayCircleOutlineIcon fontSize="small"/>,
        },
        {
          label: "Refresh",
          icon: <AutorenewIcon fontSize="small"/>,
        },
        {
          label: "Export",
          icon: <ArchiveIcon fontSize="small"/>,
        },
        {
          label: "Print",
          icon: <LocalPrintshopIcon fontSize="small"/>,
        },
      ],
    },
  });

  const events = [
    {
      id: "event-1",
      label: "Medical consultation",
      groupLabel: "Dr Shaun Murphy",
      user: "Dr Shaun Murphy",
      color: "#f28f6a",
      startDate: new Date("2022-05-05 04:00"),
      endDate: new Date("2022-05-05 05:00"),
      createdAt: new Date(),
      createdBy: "Kristina Mayer",
    },
    {
      id: "event-2",
      label: "Medical consultation",
      groupLabel: "Dr Claire Brown",
      user: "Dr Claire Brown",
      color: "#099ce5",
      startDate: new Date("2022-05-09 09:00"),
      endDate: new Date("2022-05-09 10:00"),
      createdAt: new Date(),
      createdBy: "Kristina Mayer",
    },
    {
      id: "event-3",
      label: "Medical consultation",
      groupLabel: "Dr Menlendez Hary",
      user: "Dr Menlendez Hary",
      color: "#263686",
      startDate: new Date("2022-05-10 13:00"),
      endDate: new Date("2022-05-10 14:00"),
      createdAt: new Date(),
      createdBy: "Kristina Mayer",
    },
    {
      id: "event-4",
      label: "Consultation prΓ©natale",
      groupLabel: "Dr Shaun Murphy",
      user: "Dr Shaun Murphy",
      color: "#f28f6a",
      startDate: new Date("2022-05-11 08:00"),
      endDate: new Date("2022-05-11 09:00"),
      createdAt: new Date(),
      createdBy: "Kristina Mayer",
    },
  ];

  const handleCellClick = (event: React.MouseEvent<HTMLTableCellElement, MouseEvent>, row: any, day: any) => {
    // Do something...
  };

  const handleEventClick = (event: React.MouseEvent<HTMLDivElement, MouseEvent>, task: Event) => {
    // Do something...
  };

  const handleEventsChange = (item: Event) => {
    // Do something...
  };

  const handleAlertCloseButtonClicked = (event: React.MouseEvent<HTMLButtonElement, MouseEvent>) => {
    // Do something...
  };

  const handleDateChange = (day: number, date: number | Date | null) => {
    // Do something...
  };

  return (
    <Scheduler
      locale="en"
      events={ events }
      legacyStyle={ false }
      options={ state?.options }
      alertProps={ state?.alertProps }
      toolbarProps={ state?.toolbarProps }
      onEventsChange={ handleEventsChange }
      onCellClick={ handleCellClick }
      onTaskClick={ handleEventClick }
      onAlertCloseButtonClicked={ handleAlertCloseButtonClicked }
      onDateChange={ handleDateChange }
    />
  );
};

ReactDOM.render(<App/>, document.querySelector("#yourComponentRootId"));

Event structure

NameTypeRequiredDetails
idnumber \| stringtrueUnique id for every event
labelstringtrue
colorstringfalseIf not set, the primary color of the theme will be applied
groupLabelstringtrue
startDateDatetrueStarting Date object of the event
endDatestringtrueEnding Date object of the event

For more details about date formats, see date-fns docs

Props

NameTypeDefaultDescriptionValues
localestringenUSThis prop is used to set the locale of the schedulerar, br, de, enUS, es, fr, ja, ko, zh
eventsEvent[]This prop sets event events
legacyStylebooleanfalseThis prop allows to use the old display stylefalse, true
optionsOptionThis prop is used to set scheduler properties
alertPropsAlertPropsThis prop is used to set scheduler properties
toolbarPropsToolbarPropsThis prop is used to set toolbar properties
onEventsChangeeventThis event is fired when the event change occurs
onCellClickeventThis event is fired when a cell is clicked
onTaskClickeventThis event is fired when a task is clicked
onAlertCloseButtonClickedeventThis event is fired when the close button of the alert component
onDateChangeeventThis event is fired when a date from the DatePicker is clicked

Options

NameTypeDefaultDescriptionValues
transitionModeTransitionModeTransitionMode.ZOOMThis option is used to define the type of scheduler transitionTransitionMode.ZOOM, TransitionMode.FADE, TransitionMode.SLIDE
startWeekOnStartWeekStartWeek.MONThis option is used to set the start of the calendar week to Monday or SundayStartWeek.MON, StartWeek.SUN
defaultModeModeMode.WEEKThis option allows you to define the type of view to displayMode.MONTH, Mode.WEEK, Mode.DAY, Mode.TIMELINE
minWidthnumber540This option allows you to define the minimum width of the containernumber
maxWidthnumber540This option allows you to define the maximum width of the containernumber
minHeightnumber540This option allows you to define the minimum height of the containernumber
maxHeightnumber540This option allows you to define the maximum height of the containernumber
reverseTimelineOrderbooleanfalseThis option allows you to define the order of events displayed in Timeline viewfalse, true
displayTimelineByGroupLabelbooleanfalseThis option allows you to display multiple timelines to display events by group labelsfalse, true

alertProps

NameTypeDefaultDescriptionValues
openbooleantrueThis option opens the notification Alert componenttrue, false
colorAlertColorinfoAlert notification colorinfo, success, warning, error
severityAlertColorinfoAlert notification severityinfo, success, warning, error
messagestringπŸš€ Let's start with awesome react-mui-scheduler πŸ”₯ πŸ”₯ πŸ”₯Alert notification message to displaystring
showActionButtonbooleantrueThis option displays or not the action button on the Alerttrue, false
showNotificationbooleantrueThis option allows to display or not a notification when events changetrue, false
delaynumber1500This option allows you to define the display delay in milliseconds of the Alert

toolbarProps

NameTypeDefaultDescriptionValues
showSearchBarbooleantrueShow or hide the search bartrue, false
showSwitchModeButtonsobject
showSwitchModeButtons.showMonthButtonbooleantrueShow or hide the view mode button monthtrue, false
showSwitchModeButtons.showWeekButtonbooleantrueShow or hide the view mode button weektrue, false
showSwitchModeButtons.showDayButtonbooleantrueShow or hide the view mode button daytrue, false
showSwitchModeButtons.showTimelineButtonbooleantrueShow or hide the view mode button timelinetrue, false
showDatePickerbooleantrueShow or hide the date picker buttonstrue, false
showTodayActionbooleantrueShow Today button when opening DatePickertrue, false
showOptionsbooleantrueShow options menutrue, false
optionMenusobjectOptions to display when opening menu

Methods

MethodParamsTypeDescription
onCellClickevent: React.MouseEvent<HTMLTableCellElement, MouseEvent>, row: any, day: anyEventTriggered when clicking on a cell
onEventsChangeitem: EventEventTriggered when clicking on an event
onAlertCloseButtonClickedevent: React.MouseEvent<HTMLButtonElement>EventTriggers when clicking on the close button of the notification alert
onTaskClickevent: React.MouseEvent<HTMLDivElement, MouseEvent>, task: EventEventTriggers when clicking on a task event
onDateChangeday: number, date: number \| Date \| nullEventTriggers when clicking on a date from the DatePicker

😁 Authors

πŸ€” FAQ

  • Where can I find more documentation?

    This library is a marriage of @mui and a React setup created with React. Either one would be a great place to start!

πŸ™‡β€β™‚οΈ Extra

Do you like this library ? Buy me a coffee or support me with a star on Github

  • Btc address: bc1qettgagenn9nc8ks7ghntjfme96yvvkfhntk774

  • Eth address: 0xB0413d8D0336E263e289A915c383e152155881E0

πŸ”₯ Some features to add in next releases

  • βœ… Week, day and timeline mode switch view
  • πŸ‘‰ Option menu
  • πŸ‘‰ Export events as PDF and CSV
  • βœ… Internationalization
  • βœ… Typescript support
  • βœ… Display style customization

License

react-mui-scheduler

MIT License

Copyright (c) 2022 rouftom Copyright (c) 2023 emulienfou

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.