Skip to content

Commit c6c1fad

Browse files
committed
add resource and events to headRenderer
1 parent 17ab025 commit c6c1fad

File tree

10 files changed

+41
-17
lines changed

10 files changed

+41
-17
lines changed

src/App.tsx

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Scheduler } from "./lib";
2-
import { EVENTS } from "./events";
2+
import { EVENTS, RESOURCES } from "./events";
33
import { useRef } from "react";
44
import { SchedulerRef } from "./lib/types";
55
import { Link } from "react-router-dom";
@@ -16,6 +16,21 @@ function App() {
1616
<Scheduler
1717
ref={calendarRef}
1818
events={EVENTS}
19+
resources={RESOURCES}
20+
week={{
21+
weekStartOn: 0,
22+
weekDays: [0, 1, 2, 3, 4, 5, 6],
23+
startHour: 8,
24+
endHour: 20,
25+
step: 30,
26+
}}
27+
resourceFields={{
28+
idField: "admin_id",
29+
textField: "title",
30+
subTextField: "mobile",
31+
avatarField: "title",
32+
colorField: "color",
33+
}}
1934
// events={generateRandomEvents(200)}
2035
/>
2136
</>

src/lib/components/month/MonthTable.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,9 @@ const MonthTable = ({ daysList, resource, eachWeekStart }: Props) => {
9292
/>
9393
<Fragment>
9494
{typeof headRenderer === "function" ? (
95-
<div style={{ position: "absolute", top: 0 }}>{headRenderer(today)}</div>
95+
<div style={{ position: "absolute", top: 0 }}>
96+
{headRenderer({ day: today, events: resourcedEvents, resource })}
97+
</div>
9698
) : (
9799
<Avatar
98100
style={{

src/lib/components/week/WeekTable.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ const WeekTable = ({
142142
style={{ height: headerHeight }}
143143
>
144144
{typeof headRenderer === "function" ? (
145-
<div>{headRenderer(date)}</div>
145+
<div>{headRenderer({ day: date, events: resourcedEvents, resource })}</div>
146146
) : (
147147
<TodayTypo
148148
date={date}

src/lib/types.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,11 @@ interface CommonViewProps {
4848
startHour: DayHours;
4949
endHour: DayHours;
5050
cellRenderer?(props: CellRenderedProps): JSX.Element;
51-
headRenderer?(day: Date): JSX.Element;
51+
headRenderer?(props: {
52+
day: Date;
53+
events: ProcessedEvent[];
54+
resource?: DefaultResource;
55+
}): JSX.Element;
5256
navigation?: boolean;
5357
step: number;
5458
}

src/lib/views/Day.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ const Day = () => {
132132
}
133133

134134
if (agenda) {
135-
return <DayAgenda events={resourcedEvents} />;
135+
return <DayAgenda resource={resource} events={resourcedEvents} />;
136136
}
137137

138138
// Equalizing multi-day section height
@@ -153,7 +153,7 @@ const Day = () => {
153153
style={{ height: headerHeight }}
154154
>
155155
{typeof headRenderer === "function" ? (
156-
<div>{headRenderer(selectedDate)}</div>
156+
<div>{headRenderer({ day: selectedDate, events: resourcedEvents, resource })}</div>
157157
) : (
158158
<TodayTypo date={selectedDate} locale={locale} />
159159
)}

src/lib/views/DayAgenda.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { useMemo } from "react";
22
import { format } from "date-fns";
33
import { AgendaDiv } from "../styles/styles";
4-
import { ProcessedEvent } from "../types";
4+
import { DefaultResource, ProcessedEvent } from "../types";
55
import useStore from "../hooks/useStore";
66
import { Typography } from "@mui/material";
77
import { filterTodayAgendaEvents } from "../helpers/generals";
@@ -10,8 +10,9 @@ import EmptyAgenda from "../components/events/EmptyAgenda";
1010

1111
type Props = {
1212
events: ProcessedEvent[];
13+
resource?: DefaultResource;
1314
};
14-
const DayAgenda = ({ events }: Props) => {
15+
const DayAgenda = ({ events, resource }: Props) => {
1516
const { day, locale, selectedDate, translations, alwaysShowAgendaDays } = useStore();
1617
const { headRenderer } = day!;
1718

@@ -28,7 +29,7 @@ const DayAgenda = ({ events }: Props) => {
2829
<div className="rs__agenda_row rs__today_cell">
2930
<div className="rs__cell rs__agenda__cell">
3031
{typeof headRenderer === "function" ? (
31-
<div>{headRenderer(selectedDate)}</div>
32+
<div>{headRenderer({ day: selectedDate, events, resource })}</div>
3233
) : (
3334
<Typography variant="body2">{format(selectedDate, "dd E", { locale })}</Typography>
3435
)}

src/lib/views/Month.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ const Month = () => {
6868
resourcedEvents = getResourcedEvents(events, resource, resourceFields, fields);
6969
}
7070

71-
return <MonthAgenda events={resourcedEvents} />;
71+
return <MonthAgenda resource={resource} events={resourcedEvents} />;
7272
}
7373

7474
return <MonthTable daysList={daysList} eachWeekStart={eachWeekStart} resource={resource} />;

src/lib/views/MonthAgenda.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { useMemo } from "react";
22
import { format, isSameMonth, getDaysInMonth, isToday } from "date-fns";
33
import { AgendaDiv } from "../styles/styles";
4-
import { ProcessedEvent } from "../types";
4+
import { DefaultResource, ProcessedEvent } from "../types";
55
import useStore from "../hooks/useStore";
66
import { Typography } from "@mui/material";
77
import { filterTodayAgendaEvents, isTimeZonedToday } from "../helpers/generals";
@@ -10,8 +10,9 @@ import EmptyAgenda from "../components/events/EmptyAgenda";
1010

1111
type Props = {
1212
events: ProcessedEvent[];
13+
resource?: DefaultResource;
1314
};
14-
const MonthAgenda = ({ events }: Props) => {
15+
const MonthAgenda = ({ events, resource }: Props) => {
1516
const {
1617
month,
1718
handleGotoDay,
@@ -46,7 +47,7 @@ const MonthAgenda = ({ events }: Props) => {
4647
<div key={i} className={`rs__agenda_row ${isToday(day) ? "rs__today_cell" : ""}`}>
4748
<div className="rs__cell rs__agenda__cell">
4849
{typeof headRenderer === "function" ? (
49-
<div>{headRenderer(day)}</div>
50+
<div>{headRenderer({ day, events, resource })}</div>
5051
) : (
5152
<Typography
5253
sx={{ fontWeight: today ? "bold" : "inherit" }}

src/lib/views/Week.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ const Week = () => {
7171
}
7272

7373
if (agenda) {
74-
return <WeekAgenda daysList={daysList} events={resourcedEvents} />;
74+
return <WeekAgenda daysList={daysList} resource={resource} events={resourcedEvents} />;
7575
}
7676

7777
return (

src/lib/views/WeekAgenda.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { useMemo } from "react";
22
import { format, isToday } from "date-fns";
33
import { AgendaDiv } from "../styles/styles";
4-
import { ProcessedEvent } from "../types";
4+
import { DefaultResource, ProcessedEvent } from "../types";
55
import useStore from "../hooks/useStore";
66
import { Typography } from "@mui/material";
77
import { filterTodayAgendaEvents, isTimeZonedToday } from "../helpers/generals";
@@ -10,9 +10,10 @@ import EmptyAgenda from "../components/events/EmptyAgenda";
1010

1111
type Props = {
1212
daysList: Date[];
13+
resource?: DefaultResource;
1314
events: ProcessedEvent[];
1415
};
15-
const WeekAgenda = ({ daysList, events }: Props) => {
16+
const WeekAgenda = ({ daysList, resource, events }: Props) => {
1617
const { week, handleGotoDay, locale, timeZone, translations, alwaysShowAgendaDays } = useStore();
1718
const { disableGoToDay, headRenderer } = week!;
1819

@@ -36,7 +37,7 @@ const WeekAgenda = ({ daysList, events }: Props) => {
3637
<div key={i} className={`rs__agenda_row ${isToday(day) ? "rs__today_cell" : ""}`}>
3738
<div className="rs__cell rs__agenda__cell">
3839
{typeof headRenderer === "function" ? (
39-
<div>{headRenderer(day)}</div>
40+
<div>{headRenderer({ day, events, resource })}</div>
4041
) : (
4142
<Typography
4243
sx={{ fontWeight: today ? "bold" : "inherit" }}

0 commit comments

Comments
 (0)