Back to Mantine

Resources Week View

apps/mantine.dev/src/pages/schedule/resources-week-view.mdx

9.6.07.6 KB
Original Source

import { ResourcesWeekViewDemos } from '@docs/demos'; import { Layout } from '@/layout'; import { MDX_DATA } from '@/mdx';

export default Layout(MDX_DATA.ResourcesWeekView);

Usage

ResourcesWeekView displays resources as rows and a full week of time slots as columns with a two-level header showing day names and time labels. Each row represents a resource (e.g., conference room, person, equipment) and shows events assigned to that resource via the resourceId property on event data.

<Demo data={ResourcesWeekViewDemos.usage} />

All-day events

Events that span a whole day (start at 00:00:00 and end at the next day 00:00:00) are rendered as full-width bars within their day column. Foreground all-day events are pinned to the top of the column and stack when there are several; all-day events with display: 'background' tint the whole day column.

<Demo data={ResourcesWeekViewDemos.allDayEvents} />

Interactive background events

Set withInteractiveBackgroundEvents prop to make background events clickable. Clicking a background event calls onEventClick with the event object, the same as for regular events – use event.display === 'background' to tell them apart in the handler.

Note that an interactive background event covers the time slots underneath it: clicks and drag-to-select in its range go to the event instead of the grid. Background events still cannot be dragged or resized.

<Demo data={ResourcesWeekViewDemos.interactiveBackgroundEvents} />

Drag and drop

Enable cross-resource drag and drop with withEventsDragAndDrop prop. The onEventDrop callback receives the target resourceId as the fifth argument, allowing you to update the event's resource assignment. Events can be dragged across both resources and days.

<Demo data={ResourcesWeekViewDemos.dragDrop} />

Drag interval

By default events snap to intervalMinutes when moved by drag and drop. Set eventDragInterval to use a different snap step for dragging – for example, a grid with 30-minute slots whose events can be moved in 15-minute increments. A ghost preview shows where the event will land:

<Demo data={ResourcesWeekViewDemos.eventDragInterval} />

Event form

Use onTimeSlotClick, onSlotDragEnd, and onEventClick callbacks to open a form for creating or editing events. Combine with withDragSlotSelect to allow selecting a time range by dragging across slots.

<Demo data={ResourcesWeekViewDemos.eventForm} />

Time range and intervals

Use startTime, endTime and intervalMinutes props to control the visible time range and slot granularity.

<Demo data={ResourcesWeekViewDemos.timeRange} />

Multi-hour intervals

intervalMinutes accepts values that divide evenly into an hour (for example 15 or 30) or whole numbers of hours (for example 120 or 240). Multi-hour intervals render wider columns that each span several hours, which is useful for displaying long time ranges compactly.

<Demo data={ResourcesWeekViewDemos.multiHourIntervals} />

Current time indicator

Use withCurrentTimeIndicator to display a line at the current time. Set withCurrentTimeBubble={false} to hide the time bubble label.

<Demo data={ResourcesWeekViewDemos.currentTimeIndicator} />

Current time indicator in a different timezone

@mantine/schedule works with timezone-agnostic YYYY-MM-DD HH:mm:ss strings and does not perform any timezone conversions on its own. By default, the current time indicator is positioned based on the user's local time.

To display the indicator in a different timezone, use the getCurrentTime prop. It is a function that returns the current time and is called on every tick, so the indicator keeps updating automatically. In the example below, the current time is converted to the selected timezone with the dayjs timezone plugin – switch the timezone to see the indicator and the time bubble move accordingly:

<Demo data={ResourcesWeekViewDemos.timezone} />

First day of week

Use firstDayOfWeek to set the first day of the week. Set weekdayFormat to customize the day label format.

<Demo data={ResourcesWeekViewDemos.firstDayOfWeek} />

Custom week label

Use renderWeekLabel to fully customize the week label in the header. When provided, it takes full control of the label. Use weekLabelFormat instead if you only need to change the date format.

<Demo data={ResourcesWeekViewDemos.renderWeekLabel} />

Business hours

Use highlightBusinessHours prop to visually distinguish business hours from non-business hours across all time slot columns.

<Demo data={ResourcesWeekViewDemos.businessHours} />

Without weekend days

Set withWeekendDays={false} to hide weekend days from the view.

<Demo data={ResourcesWeekViewDemos.withoutWeekendDays} />

Custom resource label

Use renderResourceLabel prop to customize how resource labels are rendered.

<Demo data={ResourcesWeekViewDemos.renderResourceLabel} />

Resource groups

Use groups prop to group resources under labeled headers. The group labels are displayed as a column to the left of resource labels, spanning vertically across their resources. Use renderGroupLabel to customize group label rendering and groupLabelWidth to control the group column width.

<Demo data={ResourcesWeekViewDemos.resourceGroups} />

Custom event rendering

Use renderEvent prop to customize how events are rendered. The example below shows event details in a hover card.

<Demo data={ResourcesWeekViewDemos.renderEvent} />

Recurring events

ResourcesWeekView automatically expands recurring events for the visible week. See Recurring events guide for full documentation.

<Demo data={ResourcesWeekViewDemos.recurringEvents} />

Max events per time slot

Use maxEventsPerTimeSlot prop to limit the number of visible overlapping events per time slot. When events exceed the limit, a "+N more" indicator is displayed. Clicking the indicator opens a popover with all events in the group. Use moreEventsProps to customize the popover behavior.

<Demo data={ResourcesWeekViewDemos.maxEventsPerTimeSlot} />

Localization

Use locale prop to set the locale for date formatting and labels prop to override default labels.

<Demo data={ResourcesWeekViewDemos.localization} />

Radius

Use radius prop to change the border radius of events.

<Demo data={ResourcesWeekViewDemos.radius} />

Start scroll date time

Use startScrollDateTime prop to scroll to a specific time on mount.

<Demo data={ResourcesWeekViewDemos.startScrollDateTime} />

Scroll area props

Use scrollAreaProps to pass props to the underlying ScrollArea component.

<Demo data={ResourcesWeekViewDemos.scrollAreaProps} />

Event resize

Enable event resizing with withEventResize prop. Events can be resized by dragging their left or right edges, and the onEventResize callback is called with the updated event start and end times.

<Demo data={ResourcesWeekViewDemos.eventResize} />

Resizing is constrained to the day the event belongs to: an event cannot be resized to span multiple days. To make an event cover several days, update its start and end dates directly in your data.

Use canResizeEvent to control which events can be resized.

Resize interval

By default events snap to intervalMinutes when resized. Set eventResizeInterval to use a different snap step for resizing – for example, a grid with 30-minute slots whose events can be resized in 15-minute increments:

<Demo data={ResourcesWeekViewDemos.eventResizeInterval} />

Static mode

Set mode="static" to disable all interactions. Events and time slots become non-interactive, useful for display-only views.

<Demo data={ResourcesWeekViewDemos.staticMode} />