2.9.2 • Published 9 days ago

@aldabil/react-scheduler v2.9.2

Weekly downloads
-
License
MIT
Repository
github
Last release
9 days ago

React Scheduler Component

npm package Twitter URL

:warning: Notice: This component uses mui/emotion/date-fns. if your project is not already using these libs, this component may not be suitable.

Installation

npm i @aldabil/react-scheduler

Usage

import { Scheduler } from "@aldabil/react-scheduler";

Example

<Scheduler
  view="month"
  events={[
    {
      event_id: 1,
      title: "Event 1",
      start: new Date("2021/5/2 09:30"),
      end: new Date("2021/5/2 10:30"),
    },
    {
      event_id: 2,
      title: "Event 2",
      start: new Date("2021/5/4 10:00"),
      end: new Date("2021/5/4 11:00"),
    },
  ]}
/>

Scheduler Props

All props are optional

PropValue
heightnumber. Min height of table. Default: 600
viewstring. Initial view to load. options: "week", "month", "day". Default: "week" (if it's not null)
agendaboolean. Activate agenda view
alwaysShowAgendaDaysboolean. if true, day rows without events will be shown
monthObject. Month view props. default: {weekDays: 0, 1, 2, 3, 4, 5, weekStartOn: 6, startHour: 9, endHour: 17,cellRenderer?:(props: CellProps) => JSX.Element,navigation: true,disableGoToDay: false}
weekObject. Week view props. default: { weekDays: 0, 1, 2, 3, 4, 5, weekStartOn: 6, startHour: 9, endHour: 17,step: 60,cellRenderer?:(props: CellProps) => JSX.Element,navigation: true,disableGoToDay: false}
dayObject. Day view props. default: {startHour: 9, endHour: 17, step: 60,cellRenderer?:(props: CellProps) => JSX.Element,hourRenderer?:(hour: string) => JSX.Element,navigation: true}
selectedDateDate. Initial selected date. Default: new Date()
navigationboolean. Show/Hide top bar date navigation. Default: true
navigationPickerPropsCalendarPickerProps for top bar date navigation. Ref: CalendarPicker API
disableViewNavigatorboolean. Show/Hide top bar date View navigator. Default: false
eventsArray of ProcessedEvent. Default: [] type ProcessedEvent = {event_id: number or string;title: string;start: Date;end: Date;disabled?: boolean;color?: string or "palette.path";textColor?: string or "palette.path";editable?: boolean;deletable?: boolean;draggable?: boolean;allDay?: boolean;agendaAvatar?: React.ReactElement | stringsx?: Mui sx prop}
eventRendererFunction(event:ProcessedEvent): JSX.Element. A function that overrides the event item render function, see demo Custom Event Renderer below
editableboolean. If true, the scheduler cell click will not open the editor, and the event item will not show the edit button, this is applied to all events, and can be overridden in each event property, see ProcessedEvent type.
deletableboolean. Whether the event item will show the delete button, this is applied to all events, and can be overridden in each event property, see ProcessedEvent type.
draggableboolean. Whether activate drag&drop for the events, this is applied to all events, and can be overridden in each event property, see ProcessedEvent type.
getRemoteEventsFunction(RemoteQuery). Return promise of array of events. Can be used as a callback to fetch events by parent component or fetch.type RemoteQuery = { start: Date; end: Date; view: "day" | "week" | "month";}
fieldsArray of extra fields with configurations. Example: { name: "description", type: "input" , config: { label: "Description", required: true, min: 3, email: true, variant: "outlined", ....}
loadingboolean. Loading state of the calendar table
loadingComponentCustom component to override the default CircularProgress
onConfirmFunction(event, action). Return promise with the new added/edited event use with remote data. action: "add", "edit"
onDeleteFunction(id) Return promise with the deleted event id to use with remote data.
customEditorFunction(scheduler). Override editor modal. Provided prop scheduler object with helper props: {state: state obj, close(): voidloading(status: boolean): voidedited?: ProcessedEventonConfirm(event: ProcessedEvent, action:EventActions): void}
customViewerFunction(event: ProcessedEvent, close: () => void). Used to render fully customized content of the event popper. If used, viewerExtraComponent & viewerTitleComponent will be ignored
viewerExtraComponentFunction(fields, event) OR Component. Additional component in event viewer popper
viewerTitleComponentFunction(event). Helper function to render custom title in event popper
disableViewerboolean. If true, the viewer popover will be disabled globally
resourcesArray. Resources array to split event views with resources Example {assignee: 1,text: "User One", subtext: "Sales Manager", avatar: "https://picsum.photos/200/300", color: "#ab2d2d", }
resourceFieldsObject. Map the resources correct fields. Example:{idField: "admin_id", textField: "title", subTextField: "mobile",avatarField: "title", colorField: "background",}
resourceHeaderComponentFunction(resource). Override header component of resource
resourceViewModeDisplay resources mode. Options: "default" | "vertical" | "tabs"
directionstring. Table direction. "rtl" | "ltr"
dialogMaxWidthEdito dialog maxWith. Ex: "lg" | "md" | "sm"... Default:"md"
localeLocale of date-fns. Default:enUS
hourFormatHour format. Options: "12" | "24"...Default: "12"
timeZoneString, time zone IANA ID: https://en.wikipedia.org/wiki/List_of_tz_database_time_zones
translationsObject. Translations view props. default: { navigation: { month: "Month", week: "Week", day: "Day", today: "Today" agenda: "Agenda" }, form: { addTitle: "Add Event", editTitle: "Edit Event", confirm: "Confirm", delete: "Delete", cancel: "Cancel" }, event: { title: "Title", start: "Start", end: "End", allDay: "All Day"}, validation: { required: "Required", invalidEmail: "Invalid Email", onlyNumbers: "Only Numbers Allowed", min: "Minimum {{min}} letters", max: "Maximum {{max}} letters" }, moreEvents: "More...", noDataToDisplay: "No data to display", loading: "Loading..."}
onEventDropFunction(event: DragEvent, droppedOn: Date, updatedEvent: ProcessedEvent, originalEvent: ProcessedEvent). Return a promise, used to update remote data of the dropped event. Return an event to update state internally, or void if event state is managed within component
onEventClickFunction(event: ProcessedEvent): void. Triggered when an event item is clicked
onEventEditFunction(event: ProcessedEvent): void. Triggered when an event item is being edited from the popover
onCellClickFunction(start: Date, end: Date, resourceKey?: string, resourceVal?: stringnumber): void. Triggered when a cell in the grid is clicked
onSelectedDateChangeFunction(date: Date): void. Triggered when the selectedDate prop changes by navigation date picker or today button
onViewChangeFunction(view: View, agenda?: boolean): void. Triggered when navigation view changes
stickyNavigationIf true, the navigation controller bar will be sticky
onClickMoreFunction(date: Date, goToDay: Function(date: Date): void): void. Triggered when the "More..." button is clicked, it receives the date and a goToDay function that shows a day view for a specfic date.

SchedulerRef

Used to help manage and control the internal state of the Scheduler component from outside of Scheduler props, Example:

import { Scheduler } from "@aldabil/react-scheduler";
import type { SchedulerRef } from "@aldabil/react-scheduler/types"

const SomeComponent = () => {
  const calendarRef = useRef<SchedulerRef>(null);

  return <Fragment>
    <div>
      <Button onClick={()=>{
        calendarRef.current.scheduler.handleState("day", "view");
      }}>
        Change View
      </Button>
      <Button onClick={()=>{
        calendarRef.current.scheduler.triggerDialog(true, {
          start: /*Put the start date*/,
          end: /*Put the end date*/
        })
      }}>
        Add Event Tomorrow
      </Button>
    </div>

    <Scheduler
      ref={calendarRef}
      events={EVENTS}
      //...
    />
  </Fragment>
};

The calendarRef holds the entire internal state of the Scheduler component. Perhaps the most useful method inside the calendarRef is handleState, example:

calendarRef.current.scheduler.handleState(value, key);

consider looking inside SchedulerRef type to see all fields & methods available.

Demos

Todos

  • Tests
  • Drag&Drop - partially
  • Resizable
  • Recurring events
  • Localization
  • Hour format 12 | 24
2.9.2

9 days ago

2.9.1

14 days ago

2.9.0

22 days ago

2.8.5

27 days ago

2.8.7

26 days ago

2.8.6

27 days ago

2.8.8

25 days ago

2.8.4

1 month ago

2.8.3

2 months ago

2.8.2

4 months ago

2.8.1

4 months ago

2.8.0

5 months ago

2.7.26

6 months ago

2.7.19

9 months ago

2.7.18

9 months ago

2.7.17

9 months ago

2.7.16

9 months ago

2.7.11

10 months ago

2.7.15

9 months ago

2.7.14

9 months ago

2.7.13

10 months ago

2.7.12

10 months ago

2.7.22

8 months ago

2.7.21

8 months ago

2.7.20

9 months ago

2.7.25

7 months ago

2.7.24

7 months ago

2.7.23

8 months ago

2.7.10

11 months ago

2.7.9

1 year ago

2.6.11

1 year ago

2.6.12

1 year ago

2.6.13

1 year ago

2.6.14

1 year ago

2.7.0

1 year ago

2.7.2

1 year ago

2.7.1

1 year ago

2.7.4

1 year ago

2.7.3

1 year ago

2.7.6

1 year ago

2.7.5

1 year ago

2.7.8

1 year ago

2.7.7

1 year ago

2.6.10

1 year ago

2.6.5

1 year ago

2.6.4

1 year ago

2.6.7

1 year ago

2.6.6

1 year ago

2.6.9

1 year ago

2.6.8

1 year ago

2.4.1

2 years ago

2.6.1

1 year ago

2.6.0

1 year ago

2.6.3

1 year ago

2.6.2

1 year ago

2.5.6

1 year ago

2.5.5

2 years ago

2.5.8

1 year ago

2.5.7

1 year ago

2.5.14

1 year ago

2.5.10

1 year ago

2.5.11

1 year ago

2.5.12

1 year ago

2.5.13

1 year ago

2.5.0

2 years ago

2.5.2

2 years ago

2.5.1

2 years ago

2.5.4

2 years ago

2.5.3

2 years ago

2.4.0

2 years ago

2.3.8

2 years ago

2.3.7

2 years ago

2.3.9

2 years ago

2.3.2

2 years ago

2.3.4

2 years ago

2.3.3

2 years ago

2.3.6

2 years ago

2.3.5

2 years ago

2.3.10

2 years ago

2.3.0

2 years ago

2.3.1

2 years ago

2.2.3

2 years ago

2.2.2

2 years ago

2.2.4

2 years ago

2.2.1

2 years ago

2.2.0

2 years ago

2.1.4

2 years ago

2.1.3

2 years ago

2.1.2

2 years ago

2.1.1

2 years ago

2.1.0

2 years ago

2.0.0

3 years ago

1.0.38

3 years ago

1.0.37

3 years ago

1.0.36

3 years ago

1.0.35

3 years ago

1.0.34

3 years ago

1.0.33

3 years ago

1.0.32

3 years ago

1.0.31

3 years ago

1.0.30

3 years ago

1.0.29

3 years ago

1.0.28

3 years ago

1.0.27

3 years ago

1.0.26

3 years ago

1.0.25

3 years ago

1.0.24

3 years ago

1.0.23

3 years ago

1.0.22

3 years ago

1.0.21

3 years ago

1.0.20

3 years ago

1.0.19

3 years ago

1.0.18

3 years ago

1.0.17

3 years ago

1.0.16

3 years ago

1.0.15

3 years ago

1.0.14

3 years ago

1.0.13

3 years ago

1.0.12

3 years ago

1.0.11

3 years ago

1.0.10

3 years ago

1.0.9

3 years ago

1.0.8

3 years ago

1.0.7

3 years ago

1.0.6

3 years ago

1.0.5

3 years ago

1.0.4

3 years ago

1.0.3

3 years ago

1.0.2

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago