Skip to content

Commit fc2e7a1

Browse files
Merge pull request #81 from linked-planet/dev
time table - changed types of custom header row, enabled showcase exa…
2 parents 6282289 + 15b8430 commit fc2e7a1

File tree

4 files changed

+30
-24
lines changed

4 files changed

+30
-24
lines changed

library/src/components/timetable/TimeTable.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ export interface LPTimeTableProps<
188188

189189
/** custom header row */
190190
customHeaderRow?: {
191-
timeSlot: (props: CustomHeaderRowTimeSlotProps<G, I>) => JSX.Element
191+
timeSlot: (props: CustomHeaderRowTimeSlotProps<G, I>) => React.ReactNode
192192
header: (props: CustomHeaderRowHeaderProps<G, I>) => JSX.Element
193193
}
194194

library/src/components/timetable/TimeTableHeader.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,8 @@ type TimeTableHeaderProps<
103103

104104
entries: TimeTableEntry<G, I>[]
105105
customHeaderRow?: {
106-
timeSlot: (props: CustomHeaderRowTimeSlotProps<G, I>) => JSX.Element
107-
header: (props: CustomHeaderRowHeaderProps<G, I>) => JSX.Element
106+
timeSlot: (props: CustomHeaderRowTimeSlotProps<G, I>) => React.ReactNode
107+
header: (props: CustomHeaderRowHeaderProps<G, I>) => React.ReactNode
108108
}
109109

110110
tableHeaderRef: React.Ref<HTMLTableSectionElement>
@@ -356,8 +356,8 @@ function CustomHeaderRowCell<
356356
slotsArray: readonly Dayjs[]
357357
showTimeSlotHeader: boolean
358358
customHeaderRow: {
359-
timeSlot: (props: CustomHeaderRowTimeSlotProps<G, I>) => JSX.Element
360-
header: (props: CustomHeaderRowHeaderProps<G, I>) => JSX.Element
359+
timeSlot: (props: CustomHeaderRowTimeSlotProps<G, I>) => React.ReactNode
360+
header: (props: CustomHeaderRowHeaderProps<G, I>) => React.ReactNode
361361
}
362362
}) {
363363
// this is the same as in the TableCell component

showcase/public/showcase-sources.txt

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7718,7 +7718,7 @@ const exampleEntries: TimeTableTypes.TimeTableEntry<
77187718
},
77197719
items: [],
77207720
},
7721-
{
7721+
/*{
77227722
group: {
77237723
id: "group-1",
77247724
title: "Group 1",
@@ -8017,7 +8017,7 @@ const exampleEntries: TimeTableTypes.TimeTableEntry<
80178017
title: "Item 7-1",
80188018
},
80198019
],
8020-
},
8020+
},*/
80218021
]
80228022

80238023
function createTestItems(
@@ -8093,8 +8093,8 @@ function createMoreTestGroups(
80938093
return newGroups
80948094
}
80958095

8096-
const startDateInitial = dayjs().startOf("day").add(-1, "day").add(8, "hours")
8097-
const endDateInitial = dayjs().startOf("day").add(5, "days").add(23, "hours")
8096+
const startDateInitial = dayjs().startOf("day").add(-1, "day")
8097+
const endDateInitial = dayjs().startOf("day").add(6, "days")
80988098

80998099
function TestCustomHeaderRowTimeSlot<
81008100
G extends TimeTableTypes.TimeTableGroup,
@@ -8109,10 +8109,13 @@ function TestCustomHeaderRowTimeSlot<
81098109
entries,
81108110
tableCellRef,
81118111
}: TimeTableTypes.CustomHeaderRowTimeSlotProps<G, I>) {
8112-
const groupItems = entries[1].items
8112+
const groupItems = entries[0].items
8113+
if (!groupItems.length) {
8114+
return null
8115+
}
81138116

81148117
const groupItemsOfCell: I[] = []
8115-
const startAndEndInSlow: {
8118+
const startAndEndInSlot: {
81168119
status: "in" | "before" | "after"
81178120
startSlot: number
81188121
endSlot: number
@@ -8128,12 +8131,15 @@ function TestCustomHeaderRowTimeSlot<
81288131
)
81298132
if (slotsArray[startAndEnd.startSlot] === timeSlot) {
81308133
groupItemsOfCell.push(item)
8131-
startAndEndInSlow.push(startAndEnd)
8134+
startAndEndInSlot.push(startAndEnd)
81328135
}
81338136
}
8137+
if (!groupItemsOfCell.length) {
8138+
return null
8139+
}
81348140

81358141
const leftAndWidths = groupItemsOfCell.map((it, i) => {
8136-
const startAndEnd = startAndEndInSlow[i]
8142+
const startAndEnd = startAndEndInSlot[i]
81378143
if (startAndEnd.status === "before" || startAndEnd.status === "after") {
81388144
return null
81398145
}
@@ -8148,6 +8154,10 @@ function TestCustomHeaderRowTimeSlot<
81488154
)
81498155
})
81508156

8157+
if (entries[0].items.length) {
8158+
console.log("LEFT", entries[0].items, leftAndWidths, startAndEndInSlot)
8159+
}
8160+
81518161
const cellWidth = tableCellRef.current?.offsetWidth ?? 70
81528162

81538163
const ret = leftAndWidths.map((it, i) =>
@@ -8180,7 +8190,7 @@ function CustomHeaderRowHeader<
81808190
}: TimeTableTypes.CustomHeaderRowHeaderProps<G, I>) {
81818191
return (
81828192
<div className="bg-surface-pressed">
8183-
{entries[1].group.title} has {entries.length} entries
8193+
{entries[0].group.title} has {entries.length} entries
81848194
</div>
81858195
)
81868196
}

showcase/src/components/showcase/wrapper/TimeTableShowcase.tsx

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ const exampleEntries: TimeTableTypes.TimeTableEntry<
4444
},
4545
items: [],
4646
},
47-
/*{
47+
{
4848
group: {
4949
id: "group-1",
5050
title: "Group 1",
@@ -343,7 +343,7 @@ const exampleEntries: TimeTableTypes.TimeTableEntry<
343343
title: "Item 7-1",
344344
},
345345
],
346-
},*/
346+
},
347347
]
348348

349349
function createTestItems(
@@ -435,7 +435,7 @@ function TestCustomHeaderRowTimeSlot<
435435
entries,
436436
tableCellRef,
437437
}: TimeTableTypes.CustomHeaderRowTimeSlotProps<G, I>) {
438-
const groupItems = entries[0].items
438+
const groupItems = entries[1].items
439439
if (!groupItems.length) {
440440
return null
441441
}
@@ -480,10 +480,6 @@ function TestCustomHeaderRowTimeSlot<
480480
)
481481
})
482482

483-
if (entries[0].items.length) {
484-
console.log("LEFT", entries[0].items, leftAndWidths, startAndEndInSlot)
485-
}
486-
487483
const cellWidth = tableCellRef.current?.offsetWidth ?? 70
488484

489485
const ret = leftAndWidths.map((it, i) =>
@@ -516,7 +512,7 @@ function CustomHeaderRowHeader<
516512
}: TimeTableTypes.CustomHeaderRowHeaderProps<G, I>) {
517513
return (
518514
<div className="bg-surface-pressed">
519-
{entries[0].group.title} has {entries.length} entries
515+
{entries[1].group.title} has {entries.length} entries
520516
</div>
521517
)
522518
}
@@ -657,7 +653,6 @@ function Example() {
657653
)
658654

659655
useEffect(() => {
660-
/*requestMoreEntriesCB()
661656
requestMoreEntriesCB()
662657
requestMoreEntriesCB()
663658
requestMoreEntriesCB()
@@ -669,7 +664,8 @@ function Example() {
669664
requestMoreEntriesCB()
670665
requestMoreEntriesCB()
671666
requestMoreEntriesCB()
672-
requestMoreEntriesCB()*/
667+
requestMoreEntriesCB()
668+
requestMoreEntriesCB()
673669
/*requestMoreEntriesCB()
674670
requestMoreEntriesCB()
675671
requestMoreEntriesCB()

0 commit comments

Comments
 (0)