@aldabil/react-scheduler

中文文档
3.1.2发布于 2025/04/19MITTypeScriptES Module零依赖近 30 天下载 2.2万

React scheduler component based on Material-UI & date-fns

原始使用文档
文档目录7 节
  1. Installation
  2. Usage
  3. Example
  4. Scheduler Props
  5. SchedulerRef
  6. Demos
  7. Todos

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

If you plan to use recurring events in your scheduler, install rrule package

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) => React.ReactNode,
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) => React.ReactNode,
navigation: true,
disableGoToDay: false
}
dayObject. Day view props.
default:
{
startHour: 9,
endHour: 17,
step: 60,
cellRenderer?:(props: CellProps) => React.ReactNode,
hourRenderer?:(hour: string) => React.ReactNode,
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;
subtitle?: string;
start: Date;
end: Date;
disabled?: boolean;
recurring: RRule;
color?: string or "palette.path";
textColor?: string or "palette.path";
editable?: boolean;
deletable?: boolean;
draggable?: boolean;
allDay?: boolean;
agendaAvatar?: React.ReactElement | string
sx?: Mui sx prop
}
eventRendererFunction(event:ProcessedEvent): React.ReactNode.
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
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(): void
loading(status: boolean): void
edited?: ProcessedEvent
onConfirm(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
viewerSubtitleComponentFunction(event). Helper function to render custom subtitle 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
onResourceChangeFunction(resource: Resource): void. Triggered when the resource tabs changes, only applicable when resourceViewMode="tabs"
directionstring. Table direction. rtl
dialogMaxWidthEdito dialog maxWith. Ex: lg
localeLocale of date-fns. Default: enUS
hourFormatHour format.
Options: 12
timeZoneString, time zone IANA ID
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",
subtitle: "Subtitle",
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?: string
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 - partially
  • Localization
  • Hour format 12 | 24

版本与发布记录

@aldabil/react-scheduler 共发布 143 个版本,首次发布于 2021/05/06;过去 12 个月发布了 0 个版本。

版本发布日期距今
3.1.2latest2025/04/191.6 年前
3.1.12025/04/171.6 年前
3.1.02025/04/171.6 年前
3.0.52025/03/081.7 年前
3.0.42025/02/271.7 年前
3.0.32025/02/261.7 年前

关于 @aldabil/react-scheduler 的常见问题

@aldabil/react-scheduler 是什么?

React scheduler component based on Material-UI & date-fns

如何安装 @aldabil/react-scheduler?

在项目目录运行 npm install @aldabil/react-scheduler,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:@mui/icons-material(>=7.0.0)、@mui/material(>=7.0.0)、@mui/x-date-pickers(>=7.0.0 & <8.0.0)、date-fns(>=4.0.0)、react(>=18.0.0)、react-dom(>=18.0.0)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@aldabil/react-scheduler 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@aldabil/react-scheduler 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@aldabil/react-scheduler 可以商用吗?

@aldabil/react-scheduler 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@aldabil/react-scheduler 的下载量有多少?

根据 npm 官方下载统计,@aldabil/react-scheduler 在 2026/10/06 – 2026/11/04 这 30 天内被下载 21,535 次,日均约 718 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@aldabil/react-scheduler 还在维护吗?

最新版本 3.1.2 发布于 2025/04/19(1.6 年前);至今共发布 143 个版本,其中过去 12 个月发布了 0 个;首次发布于 2021/05/06。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。