Subrow
When you have two or more items who's relevance's intersect, you would expect them to stack on top of each other.
Each item in that stack should be rendered inside a subrow of some kind, that will seprate stacked items into different containers inside the same row.
dnd-timeline
does not have this behaviour by default, but provides you with a simple util to help you stack.
function Timeline(props: TimelineProps) {
const { setTimelineRef, style, timeframe } = useTimelineContext()
const groupedSubrows = useMemo(
() => groupItemsToSubrows(items, timeframe),
[items, timeframe]
)
return (
<div ref={setTimelineRef} style={style}>
{props.rows.map((row) =>
<Row key={row.id} id={row.id} sidebar={<Sidebar row={row} />}>
{groupedSubrows[row.id]?.map((subrow, index) =>
<div key={`${row.id}-${index}`}>
{subrow.map((item) =>
// Render item here...
)}
</div>
)}
</Row>
)}
</div>
)
}
groupItemsToSubrows
groupItemsToSubrows
A helper function to group intersecting items of the same row into different subrows.
The function receives and returns items of a certain type. If your items are of a different shape, you have to solutions:
Serialize and deserialize you own items into and out of this type.
Implement you own helper function. The code is pretty simple, and available here for you.
API
groupItemsToSubrows:
(items: ItemDefinition[], timeframe?: Relevance) =>
Record<string, ItemDefinition[][]>
The function returns an object where the key is a rowId
, and the value is a matrix of items, where the first index is the subrow index, and the second index the the index of an item inside of that subrow.
Props
items
items
items: ItemDefinition[]
An array of items in the shape of ItemDefinition
type ItemDefinition = {
id: string
rowId: string
relevance: Relevance
disabled?: boolean
}
timeframe?
timeframe?
timeframe?: Relevance
An optional timeframe object to filter out items that do not intersect with the current timeframe. This is to reduce the amount of items rendered at a time.
Last updated