Timeline · Use cases
Meal planner
Meals as rows and days as columns. A click on an empty day adds a dish for the whole day.
Live demo
Click an empty cell to add a dish · Drag lunch to another day
Fullscreenimport { ProScheduler } from "@andreisaac/pro-scheduler"
import { mealPlan, mealSlots } from "./data/operations"
import { useEvents } from "./kit"
export function MealPlannerDemo() {
const { events, handlers } = useEvents(mealPlan)
return (
<ProScheduler
data={events}
resources={mealSlots}
view={{ timeline: { type: "week", resolutionHorizontal: "day" } }}
styleConfig={{ laneHeight: 40, minRowHeight: 64, resourceColWidth: 140 }}
clickToCreate
extendDefaultEvent={({ start, resource }) => ({
// A dish lasts the whole day it's planned for.
start: new Date(start.getFullYear(), start.getMonth(), start.getDate()),
end: new Date(start.getFullYear(), start.getMonth(), start.getDate() + 1),
allDay: true,
color: mealSlots.find((m) => m.id === resource)?.color,
})}
renderResource={(slot) => (
<span className="flex items-center gap-2 text-sm font-semibold">
<span className="h-6 w-1 rounded-full" style={{ background: String(slot.color) }} />
{slot.name}
</span>
)}
height={400}
{...handlers}
/>
)
}// data/operations.ts — sample data, relative to the current week or month.
import type { SchedulerEvent, SchedulerResource } from "@andreisaac/pro-scheduler"
import { weekStart } from "./studio"
export const mealSlots: SchedulerResource[] = [
{ id: "breakfast", name: "Breakfast", color: "#f59e0b" },
{ id: "lunch", name: "Lunch", color: "#10b981" },
{ id: "dinner", name: "Dinner", color: "#6366f1" },
{ id: "snack", name: "Snack", color: "#ec4899" },
]
const menu: Record<string, string[]> = {
breakfast: ["Oat porridge", "Greek yogurt", "Avocado toast", "Pancakes", "Smoothie bowl", "Eggs & rye", "Granola"],
lunch: ["Lentil soup", "Caesar salad", "Chicken wrap", "Poke bowl", "Minestrone", "Falafel", "Quiche"],
dinner: ["Salmon & greens", "Mushroom risotto", "Chili", "Stir-fry", "Roast chicken", "Pasta al pesto", "Curry"],
snack: ["Apple", "Hummus & carrots", "Almonds", "Banana bread", "Cheese", "Berries", "Dark chocolate"],
}
/** One dish per meal per day, as all-day entries (a menu has no clock time). */
export function mealPlan(base = weekStart()): SchedulerEvent[] {
return mealSlots.flatMap((slot) =>
menu[String(slot.id)].map((title, day) => {
const start = new Date(base.getFullYear(), base.getMonth(), base.getDate() + day)
return {
id: `meal-${slot.id}-${day}`,
title,
start,
end: new Date(start.getFullYear(), start.getMonth(), start.getDate() + 1),
allDay: true,
resource: slot.id,
}
})
)
}About this demo
Meals as rows and days as columns. A click on an empty day adds a dish for the whole day.
Things to try
- Click an empty cell to add a dish
- Drag lunch to another day
The props behind it are explained in Drag, resize & create.