mantine-resource-timeline
v8.0.1
Published
A resource timeline component built with Mantine
Maintainers
Readme
mantine-resource-timeline
A simple but customizable resource scheduler/timeline component built with mantine.
Compatibility
This library uses subgrids, which is a rather new browser feature.
Peer dependencies
@mantine/hooksfor @mantine/core@mantine/corefor stylingdate-fnsfor handling of dates@tanstack/react-virtualfor virtualization of bigger timelinesvaltiofor more granular render control@use-gesture/reactfor panning and zoom gestures when holding CTRL
Minimal usage
import { addHours } from "date-fns";
import { useSchedulerController, Scheduler } from "mantine-resource-timeline";
interface MyDataType {
id: string | number;
resourceId: string | number | number[] | string[];
startDate: Date;
endDate: Date;
}
interface MyResourceType {
id: string | number;
name: string;
}
const data: MyDataType[] = [
{
id: "appointment-1",
title: "Bob & Alice Meet",
resourceId: [1, 2],
startDate: new Date(),
endDate: addHours(new Date(), 2),
},
];
const resources: MyResourceType[] = [
{
id: 1,
name: "Bob",
},
{
id: 2,
name: "Alice",
},
];
function MyTimeline() {
const controller = useSchedulerController<MyDataType, MyResourceType>({});
return (
<Scheduler
controller={controller}
data={data}
resources={resources}
width="100%"
height="95vh"
dataResourceIdAccessor="resourceId"
endDateAccessor="endDate"
startDateAccessor="startDate"
dataIdAccessor="id"
resourceIdAccessor="id"
tz="Europe/Berlin"
/>
);
}For how to activate other features of this library and adapting the timeline component to your needs take a look at the Advanced Example.
The controller object allows us to control multiple components state, such as the time to be displayed, from the outside. It's a valtio proxy object which allows us to pass it around in our app without having to fear unnecessary re-renders. Take a look at valtio's documentation to find out how a valtio proxy object is handled correctly.
Future development
I have mostly achieved what I initially wanted to achieve with this component library. This means I most likely won't re-iterate on it because I have lost my interest in this project. I'm still eager to answer questions via issues or review Pull Requests to this project though. Feel free to contribute anything you'd like as long as it's within the scope of this project. Especially if it includes documentation/tests.
Contributing
To develop code for this project you need pnpm. If you don't use pnpm already, you can follow their installation guide to install it. I personally recommend installation via corepack.
After that you can install dependencies via:
pnpm installNext you should be able to start the storybook server via:
pnpm storybookThen you can open the storybook via http://127.0.0.1:6006.
Before committing and pushing you should format and lint the project via the following commands:
pnpm format
pnpm lint