Custom headers
Custom Headers
This new feature gives more control to dev to create customizable headers to provide better UI. Now user have more control through a set of new components to render headers. This new feature came with a breaking change though.
import Timeline, {
TimelineHeaders,
SidebarHeader,
DateHeader
} from 'react-calendar-timeline'
<Timeline>
<TimelineHeaders>
<SidebarHeader>
{({ getRootProps }) => {
return <div {...getRootProps()}>Left</div>
}}
</SidebarHeader>
<DateHeader unit="primaryHeader" />
<DateHeader />
<CustomHeader height={50} headerData={{someData: 'data'}} unit="year">
{({
headerContext: { intervals },
getRootProps,
getIntervalProps,
showPeriod,
data,
}) => {
return (
<div {...getRootProps()}>
{intervals.map(interval => {
const intervalStyle = {
lineHeight: '30px',
textAlign: 'center',
borderLeft: '1px solid black',
cursor: 'pointer',
backgroundColor: 'Turquoise',
color: 'white'
}
return (
<div
onClick={() => {
showPeriod(interval.startTime, interval.endTime)
}}
{...getIntervalProps({
interval,
style: intervalStyle
})}
>
<div className="sticky">
{interval.startTime.format('YYYY')}
</div>
</div>
)
})}
</div>
)
}}
</CustomHeader>
</TimelineHeaders>
</Timeline>Check out the new docs before please here
removed props
stickyOffsetandstickyHeadernow you can make your header sticky by following this examplesheaderRefto get the headerRef you need to pass ref callback toTimelineHeadercomponentheaderLabelGroupHeightandheaderLabelHeightnow you can pass aheightprop to bothCustomHeaderandDateHeaderheaderLabelFormatsandsubHeaderLabelFormatsnot you can passformatLabelfunction toDateHeaderwith label width and start and end time of intervals