Gathering detailed insights and metrics for react-calendar-timeline
Gathering detailed insights and metrics for react-calendar-timeline
Gathering detailed insights and metrics for react-calendar-timeline
Gathering detailed insights and metrics for react-calendar-timeline
npm install react-calendar-timeline
Module System
Min. Node Version
Typescript Support
Node Version
NPM Version
1,953 Stars
1,036 Commits
639 Forks
50 Watching
14 Branches
51 Contributors
Updated on 26 Nov 2024
TypeScript (55.87%)
JavaScript (42.17%)
SCSS (1.15%)
Shell (0.81%)
Cumulative downloads
Total Downloads
Last day
-4.4%
6,279
Compared to previous day
Last week
0.6%
33,672
Compared to previous week
Last month
17.7%
138,925
Compared to previous month
Last year
7.9%
1,886,880
Compared to previous year
4
4
36
A modern and responsive React timeline component.
🎉 Version 0.30.0-beta.1 Now Available!
We're excited to announce the beta release of v0.30.0 which includes:
The beta version is available via:
1npm install react-calendar-timeline@beta
We encourage users to try out the beta and provide feedback before the stable release. Please report any issues on GitHub.
Note: Testing framework has been updated and some tests are currently being migrated.
please email me ahmad.ilaiwi@gmail.com and we will setup some time to speak and see if you can help maintain this library.
Checkout the examples here!
1# via yarn 2yarn add react-calendar-timeline 3 4# via npm 5npm install --save react-calendar-timeline
react-calendar-timeline
has react, react-dom, moment
and interactjs
as peer dependencies.
At the very minimum:
1import Timeline from 'react-calendar-timeline' 2// make sure you include the timeline stylesheet or the timeline will not be styled 3import 'react-calendar-timeline/lib/Timeline.css' 4import moment from 'moment' 5 6const groups = [{ id: 1, title: 'group 1' }, { id: 2, title: 'group 2' }] 7 8const items = [ 9 { 10 id: 1, 11 group: 1, 12 title: 'item 1', 13 start_time: moment(), 14 end_time: moment().add(1, 'hour') 15 }, 16 { 17 id: 2, 18 group: 2, 19 title: 'item 2', 20 start_time: moment().add(-0.5, 'hour'), 21 end_time: moment().add(0.5, 'hour') 22 }, 23 { 24 id: 3, 25 group: 1, 26 title: 'item 3', 27 start_time: moment().add(2, 'hour'), 28 end_time: moment().add(3, 'hour') 29 } 30] 31 32ReactDOM.render( 33 <div> 34 Rendered by react! 35 <Timeline 36 groups={groups} 37 items={items} 38 defaultTimeStart={moment().add(-12, 'hour')} 39 defaultTimeEnd={moment().add(12, 'hour')} 40 /> 41 </div>, 42 document.getElementById('root') 43)
NB! All props need to be immutable. For example, this means if you wish to change the title of one of your items, please pass in a whole new items array instead of changing the title in the old array. Here's more info.
The component can take many props:
Expects either a vanilla JS array or an immutableJS array, consisting of objects with the following attributes:
1{ 2 id: 1, 3 title: 'group 1', 4 rightTitle: 'title in the right sidebar', 5 stackItems?: true, 6 height?: 30 7}
If you use the right sidebar, you can pass optional rightTitle
property here.
If you want to overwrite the calculated height with a custom height, you can pass a height
property as an int in pixels here. This can be very useful for categorized groups.
Expects either a vanilla JS array or an immutableJS array, consisting of objects with the following attributes:
1{ 2 id: 1, 3 group: 1, 4 title: 'Random title', 5 start_time: 1457902922261, 6 end_time: 1457902922261 + 86400000, 7 canMove: true, 8 canResize: false, 9 canChangeGroup: false, 10 itemProps: { 11 // these optional attributes are passed to the root <div /> of each item as <div {...itemProps} /> 12 'data-custom-attribute': 'Random content', 13 'aria-hidden': true, 14 onDoubleClick: () => { console.log('You clicked double!') }, 15 className: 'weekend', 16 style: { 17 background: 'fuchsia' 18 } 19 } 20}
The preferred (fastest) option is to give Unix timestamps in milliseconds for start_time
and end_time
. Objects that convert to them (JavaScript Date
or moment()
) will also work, but will be a lot slower.
Unless overridden by visibleTimeStart
and visibleTimeEnd
, specify where the calendar begins and where it ends. This parameter expects a Date or moment object.
The exact viewport of the calendar. When these are specified, scrolling in the calendar must be orchestrated by the onTimeChange
function. This parameter expects a Unix timestamp in milliseconds.
Note that you need to provide either defaultTimeStart/End
or visibleTimeStart/End
for the timeline to function
a number (default to 3) which represents the extra timeline rendered on right and lift of the visible area which the user will scroll through before the time rerenders.
more explication in section behind the scenes
Note: setting buffer to 1 will disable the scrolling on the timeline
An array with id's corresponding to id's in items (item.id
). If this prop is set you have to manage the selected items yourself within the onItemSelect
handler to update the property with new id's and use onItemDeselect
handler to clear selection. This overwrites the default behaviour of selecting one item on click.
An array specifying keys in the items
and groups
objects. Defaults to
1{ 2 groupIdKey: 'id', 3 groupTitleKey: 'title', 4 groupRightTitleKey: 'rightTitle', 5 itemIdKey: 'id', 6 itemTitleKey: 'title', // key for item div content 7 itemDivTitleKey: 'title', // key for item div title (<div title="text"/>) 8 itemGroupKey: 'group', 9 itemTimeStartKey: 'start_time', 10 itemTimeEndKey: 'end_time', 11}
Additional class names as a string for the root Timeline element.
Width of the sidebar in pixels. If set to 0
, the sidebar is not rendered. Defaults to 150
.
Everything passed here will be displayed above the left sidebar. Use this to display small filters or so. Defaults to null
.
Width of the right sidebar in pixels. If set to 0
, the right sidebar is not rendered. Defaults to 0
.
Everything passed here will be displayed above the right sidebar. Use this to display small filters or so. Defaults to null
.
Snapping unit when dragging items. Defaults to 15 * 60 * 1000
or 15min. When so, the items will snap to 15min intervals when dragging.
The minimum width, in pixels, of a timeline entry when it's possible to resize. If not reached, you must zoom in to resize more. Default to 20
.
Height of one line in the calendar in pixels. Default 30
What percentage of the height of the line is taken by the item? Default 0.65
Smallest time the calendar can zoom to in milliseconds. Default 60 * 60 * 1000
(1 hour)
notes: please note than second won't show up unless you change this to 60 * 1000
Largest time the calendar can zoom to in milliseconds. Default 5 * 365.24 * 86400 * 1000
(5 years)
How many pixels we can drag the background for it to be counted as a click on the background. Default 3
Can items be dragged around? Can be overridden in the items
array. Defaults to true
Can items be moved between groups? Can be overridden in the items
array. Defaults to true
Can items be resized? Can be overridden in the items
array. Accepted values: false
, "left"
, "right"
, "both"
. Defaults to "right"
. If you pass true
, it will be treated as "right"
to not break compatibility with versions 0.9 and below.
Append a special .rct-drag-right
handle to the elements and only resize if dragged from there. Defaults to false
Stack items under each other, so there is no visual overlap when times collide. Can be overridden in the groups
array. Defaults to false
. Requires millisecond or Moment
timestamps, not native JavaScript Date
objects.
Zoom in when scrolling the mouse up/down. Defaults to false
Normally tapping (touching) an item selects it. If this is set to true, a tap will have the same effect, as selecting with the first click and then clicking again to open and send the onItemClick event. Defaults to false
.
With what step to display different units. E.g. 15
for minute
means only minutes 0, 15, 30 and 45 will be shown.
Default:
1{ 2 second: 1, 3 minute: 1, 4 hour: 1, 5 day: 1, 6 month: 1, 7 year: 1 8}
Ref callback that gets a DOM reference to the scroll body element. Can be useful to programmatically scroll.
Called when an item is moving or resizing. Returns an object with the following properties:
property | type | description |
---|---|---|
eventType | string | retuns either move or resize |
itemId | number | ID of the item being moved or resized |
time | number | UNIX timestamp in milliseconds |
edge | string | on resize , returns a value of either left or right |
newGroupOrder | number | on move , index position of the new group that the item is moving to |
Callback when an item is moved. Returns 1) the item's ID, 2) the new start time and 3) the index of the new group in the groups
array.
Callback when an item is resized. Returns 1) the item's ID, 2) the new start or end time of the item 3) The edge that was dragged (left
or right
)
Called when an item is selected. This is sent on the first click on an item. time
is the time that corresponds to where you click/select on the item in the timeline.
Called when deselecting an item. Used to clear controlled selected prop.
Called when an item is clicked. Note: the item must be selected before it's clicked... except if it's a touch event and itemTouchSendsClick
is enabled. time
is the time that corresponds to where you click on the item in the timeline.
Called when an item was double clicked. time
is the time that corresponds to where you double click on the item in the timeline.
Called when the item is clicked by the right button of the mouse. time
is the time that corresponds to where you context click on the item in the timeline. Note: If this property is set the default context menu doesn't appear.
Called when an empty spot on the canvas was clicked. Get the group ID and the time as arguments. For example open a "new item" window after this.
Called when an empty spot on the canvas was double clicked. Get the group ID and the time as arguments.
Called when the canvas is clicked by the right button of the mouse. Note: If this property is set the default context menu doesn't appear
Called when the timeline is zoomed, either via mouse/pinch zoom or clicking header to change timeline units
This function is called when an item is being moved or resized. It's up to this function to return a new version of change
, when the proposed move would violate business logic.
The argument action
is one of move
or resize
.
The argument resizeEdge
is when resizing one of left
or right
.
The argument time
describes the proposed new time for either the start time of the item (for move) or the start or end time (for resize).
The function must return a new unix timestamp in milliseconds... or just time
if the proposed new time doesn't interfere with business logic.
For example, to prevent moving of items into the past, but to keep them at 15min intervals, use this code:
1function (action, item, time, resizeEdge) { 2 if (time < new Date().getTime()) { 3 var newTime = Math.ceil(new Date().getTime() / (15*60*1000)) * (15*60*1000); 4 return newTime; 5 } 6 7 return time 8}
A function that's called when the user tries to scroll. Call the passed updateScrollCanvas(start, end)
with the updated visibleTimeStart and visibleTimeEnd (as unix timestamps in milliseconds) to change the scroll behavior, for example to limit scrolling.
Here is an example that limits the timeline to only show dates starting 6 months from now and ending in 6 months.
1// this limits the timeline to -6 months ... +6 months
2const minTime = moment().add(-6, 'months').valueOf()
3const maxTime = moment().add(6, 'months').valueOf()
4
5function (visibleTimeStart, visibleTimeEnd, updateScrollCanvas) {
6 if (visibleTimeStart < minTime && visibleTimeEnd > maxTime) {
7 updateScrollCanvas(minTime, maxTime)
8 } else if (visibleTimeStart < minTime) {
9 updateScrollCanvas(minTime, minTime + (visibleTimeEnd - visibleTimeStart))
10 } else if (visibleTimeEnd > maxTime) {
11 updateScrollCanvas(maxTime - (visibleTimeEnd - visibleTimeStart), maxTime)
12 } else {
13 updateScrollCanvas(visibleTimeStart, visibleTimeEnd)
14 }
15}
Called when the bounds in the calendar's canvas change. Use it for example to load new data to display. (see "Behind the scenes" below). canvasTimeStart
and canvasTimeEnd
are unix timestamps in milliseconds.
Render prop function used to render a customized item. The function provides multiple parameters that can be used to render each item.
Parameters provided to the function has two types: context params which have the state of the item and timeline, and prop getters functions
item
has the item we passed as a prop to the calendar.
timelineContext
property | type | description |
---|---|---|
timelineWidth | number | returns the full width of the timeline. |
visibleTimeStart | number | returns the exact start of view port of the calendar |
visibleTimeEnd | number | returns the exact end of view port of the calendar. |
canvasTimeStart | number | denotes the start time in ms of the canvas timeline |
canvasTimeEnd | number | denotes the end time in ms of the canvas timeline |
itemContext
property | type | description |
---|---|---|
dimensions | object | returns the dimensions of the item which includes collisionLeft , collisionWidth , height , isDragging , left , order , originalLeft , stack , top , and width |
useResizeHandle | boolean | returns the prop useResizeHandle from calendar root component |
title | string | returns title to render in content element. |
canMove | boolean | returns if the item is movable. |
canResizeLeft | boolean | returns if the item can resize from the left |
canResizeRight | boolean | returns if the item can resize from the right. |
selected | boolean | returns if the item is selected. |
dragging | boolean | returns if the item is being dragged |
dragStart | object | returns x and y of the start dragging point of the item. |
dragTime | number | current drag time. |
dragGroupDelta | number | returns number of groups the item moved. if negative, moving was to top. If positive, moving was to down |
resizing | boolean | returns if the item is being resized. |
resizeEdge | left , right | the side from which the component is being resized form |
resizeStart | number | returns the x value from where the component start moving |
resizeTime | number | current resize time |
width | boolean | returns the width of the item (same as in dimensions) |
These functions are used to apply props to the elements that you render. This gives you maximum flexibility to render what, when, and wherever you like.
Rather than applying props on the element yourself and to avoid your props being overridden (or overriding the props returned). You can pass an object to the prop getters to avoid any problems. This object will only accept some properties that our component manage so the component make sure to combine them correctly.
property | type | description |
---|---|---|
getItemProps | function(props={}) | returns the props you should apply to the root item element. |
getResizeProps | function(props={}) | returns two sets of props to apply on the left and right elements as resizing elements if you have useResizeHandle prop set to true |
getItemProps
returns the props you should apply to the root item element. The returned props are:
** the given styles will only override the styles that are not a requirement for positioning the item. Other styles like color
, radius
and others
These properties can be overriden using the prop argument with properties:
getResizeProps
returns the props you should apply to the left and right resize handlers only if useResizeHandle
set to true. The returned object has the props for the left element under property left
and the props to be applied to the right element under right
:
These properties can be override using the prop argument with properties:
example
1let items = [ 2 { 3 id: 1, 4 group: 1, 5 title: 'Title', 6 tip: 'additional information', 7 color: 'rgb(158, 14, 206)', 8 selectedBgColor: 'rgba(225, 166, 244, 1)', 9 bgColor : 'rgba(225, 166, 244, 0.6)', 10 ... 11 } 12] 13 14itemRenderer: ({ 15 item, 16 itemContext, 17 getItemProps, 18 getResizeProps 19}) => { 20 const { left: leftResizeProps, right: rightResizeProps } = getResizeProps() 21 return ( 22 <div {...getItemProps(item.itemProps)}> 23 {itemContext.useResizeHandle ? <div {...leftResizeProps} /> : ''} 24 25 <div 26 className="rct-item-content" 27 style={{ maxHeight: `${itemContext.dimensions.height}` }} 28 > 29 {itemContext.title} 30 </div> 31 32 {itemContext.useResizeHandle ? <div {...rightResizeProps} /> : ''} 33 </div> 34 )} 35 36}
React component that will be used to render the content of groups in the
sidebar. Will be passed the group
and isRightSidebar
as props.
1let groups = [ 2 { 3 id: 1, 4 title: 'Title', 5 tip: 'additional information' 6 } 7] 8 9groupRenderer = ({ group }) => { 10 return ( 11 <div className="custom-group"> 12 <span className="title">{group.title}</span> 13 <p className="tip">{group.tip}</p> 14 </div> 15 ) 16}
The component automatically detects when the window has been resized. Optionally you can also detect when the component's DOM element has been resized.
To do this, pass a resizeDetector
. Since bundling it by default would add ~18kb of minimized JS, you need to opt in to this like so:
1import containerResizeDetector from 'react-calendar-timeline/lib/resize-detector/container' 2 3<Timeline resizeDetector={containerResizeDetector} ... />
This function is called when the vertical line is rendered. start
and end
are unix timestamps in milliseconds for the current column. The function should return an array of strings containing the classNames which should be applied to the column. This makes it possible to visually highlight e.g. public holidays or office hours.
An example could look like (see: demo/vertical-classes):
1verticalLineClassNamesForTime = (timeStart, timeEnd) => { 2 const currentTimeStart = moment(timeStart) 3 const currentTimeEnd = moment(timeEnd) 4 5 for (let holiday of holidays) { 6 if ( 7 holiday.isSame(currentTimeStart, 'day') && 8 holiday.isSame(currentTimeEnd, 'day') 9 ) { 10 return ['holiday'] 11 } 12 } 13}
Be aware that this function should be as optimized for performance as possible as it will be called on each render of the timeline (i.e. when the canvas is reset, when zooming, etc)
This function is called when the horizontal line is rendered. group
is the group which will be rendered into the current row. The function should return an array of strings containing the classNames which should be applied to the row. This makes it possible to visually highlight categories or important items.
An example could look like:
1horizontalLineClassNamesForGroup={(group) => group.root ? ["row-root"] : []}
Timeline markers are markers that are overlayed on the canvas at specific datepoints.
Markers can be placed in the Timeline by declaring them as children
of the Timeline
component:
1import Timeline, { 2 TimelineMarkers, 3 CustomMarker, 4 TodayMarker, 5 CursorMarker 6} from 'react-calendar-timeline' 7 8<Timeline> 9 <TimelineMarkers> 10 <TodayMarker /> 11 <CustomMarker date={today} /> 12 <CustomMarker date={tomorrow}> 13 {/* custom renderer for this marker */} 14 {({ styles, date }) => { 15 const customStyles = { 16 ...styles, 17 backgroundColor: 'deeppink', 18 width: '4px' 19 } 20 return <div style={customStyles} onClick={someCustomHandler} /> 21 }} 22 </CustomMarker> 23 <CursorMarker /> 24 </TimelineMarkers> 25</Timeline>
Each marker allows for passing in a custom renderer via a function as a child component. This allows the user to render whatever they want (event handlers, custom styling, etc). This custom renderer receives an object with two properties:
styles: {position: 'absolute', top: 0, bottom: 0, left: number}
This object must be passed to the root component's style
prop in order to be rendered properly. Note that you can merge this object with any other properties.
date: number
Date in unix timestamp of this marker. This can be used to change how your marker is rendered (or if its rendered at all)
Wrapper for timeline markers that you want rendered.
Marker that is placed on the current date/time.
interval: number | default: 10000
How often the TodayMarker refreshes. Value represents milliseconds.
children: function({styles: object, date: number}) => JSX.Element
Custom renderer for this marker. Ensure that you always pass styles
to the root component's style
prop as this object contains positioning of the marker.
1// custom interval 2const twoSeconds = 2000 3 4<TodayMarker interval={twoSeconds} /> 5 6//custom renderer 7 8<TodayMarker> 9 {({ styles, date }) => 10 // date is value of current date. Use this to render special styles for the marker 11 // or any other custom logic based on date: 12 // e.g. styles = {...styles, backgroundColor: isDateInAfternoon(date) ? 'red' : 'limegreen'} 13 <div style={styles} /> 14 } 15</TodayMarker>
Marker that is placed on the current date/time.
date: number | required
Where to place the marker on the timeline. date
value is unix timestamp.
children: function({styles: object, date: number}) => JSX.Element
Custom renderer for this marker. Ensure that you always pass styles
to the root component's style
prop as this object contains positioning of the marker.
1const today = Date.now() 2<CustomMarker date={today} /> 3 4//custom renderer 5<CustomMarker date={today}> 6 {({ styles, date }) => <div style={styles} />} 7</CustomMarker> 8 9// multiple CustomMarkers 10const markerDates = [ 11 {date: today, id: 1,}, 12 {date: tomorrow, id: 2,}, 13 {date: nextFriday, id: 3,}, 14] 15 16<TimelineMarkers> 17 {markerDates.map(marker => <CustomMarker key={marker.date} date={marker.date}/> )} 18</TimelineMarkers>
Marker that is displayed when hovering over the timeline and matches where your cursor is.
children: function({styles: object, date: number}) => JSX.Element
Custom renderer for this marker. Ensure that you always pass styles
to the root component's style
prop as this object contains positioning of the marker.
1// render default marker for Cursor 2<CursorMarker /> 3 4//custom renderer 5<CursorMarker> 6 {({ styles, date }) => 7 // date is value of current date. Use this to render special styles for the marker 8 // or any other custom logic based on date: 9 // e.g. styles = {...styles, backgroundColor: isDateInAfternoon(date) ? 'red' : 'limegreen'} 10 <div style={styles} /> 11 } 12</CursorMarker>
Timeline headers are the section above the timeline which consist of two main parts: First, the calender header which is a scrolable div containing the dates of the calendar called DateHeader
. Second, is the headers for the sidebars, called SidebarHeader
, the left one and optionally the right one.
For the default case, two DateHeader
s are rendered above the timeline, one primary
and secondary
. The secondary has the same date unit as the timeline and a primary
which has a unit larger than the timeline unit by one.
For the SidebarHeader
s an empty SidebarHeader
will be render for the left and optionally an empty right sidebar header if rightSidebarWith
exists.
To provide any custom headers for DateHeader
or SidebarHeader
. You need to provide basic usage to provide any custom headers. These Custom headers should be always included inside TimelineHeaders
component in the component's children.
1import Timeline, { 2 TimelineHeaders, 3 SidebarHeader, 4 DateHeader 5} from 'react-calendar-timeline' 6 7<Timeline> 8 <TimelineHeaders> 9 <SidebarHeader> 10 {({ getRootProps }) => { 11 return <div {...getRootProps()}>Left</div> 12 }} 13 </SidebarHeader> 14 <DateHeader unit="primaryHeader" /> 15 <DateHeader /> 16 </TimelineHeaders> 17<Timeline>
Custom headers are implemented through a set of component with mostly function as a child component pattern, designed to give the user the most control on how to render the headers.
TimelineHeader
Is the core component wrapper component for custom headers
Prop | type | description |
---|---|---|
style | object | applied to the root component of headers |
className | string | applied to the root component of the headers |
calendarHeaderStyle | object | applied to the root component of the calendar headers -scrolable div- DateHeader and CustomHeader ) |
calendarHeaderClassName | string | applied to the root component of the calendar headers -scrolable div- DateHeader and CustomHeader ) |
headerRef | function | used to get the ref of the header element |
SidebarHeader
Responsible for rendering the headers above the left and right sidebars.
Prop | type | description |
---|---|---|
variant | left (default), right | renders above the left or right sidebar |
children | Function | function as a child component to render the header |
headerData | any | Contextual data to be passed to the item renderer as a data prop |
a Function provides multiple parameters that can be used to render the sidebar headers
Rather than applying props on the element yourself and to avoid your props being overridden (or overriding the props returned). You can pass an object to the prop getters to avoid any problems. This object will only accept some properties that our component manage so the component make sure to combine them correctly.
property | type | description |
---|---|---|
getRootProps | function(props={}) | returns the props you should apply to the root div element. |
data | any | Contextual data passed by headerData prop |
getRootProps
The returned props are:
These properties can be override using the prop argument with properties:
1import Timeline, { 2 TimelineHeaders, 3 SidebarHeader, 4 DateHeader 5} from 'react-calendar-timeline' 6 7<Timeline> 8 <TimelineHeaders> 9 <SidebarHeader> 10 {({ getRootProps }) => { 11 return <div {...getRootProps()}>Left</div> 12 }} 13 </SidebarHeader> 14 <SidebarHeader variant="right" headerData={{someData: 'extra'}}> 15 {({ getRootProps, data }) => { 16 return <div {...getRootProps()}>Right {data.someData}</div> 17 }} 18 </SidebarHeader> 19 <DateHeader unit="primaryHeader" /> 20 <DateHeader /> 21 </TimelineHeaders> 22<Timeline>
Note : the Child function renderer can be a component or a function for convenience
DateHeader
Responsible for rendering the headers above calendar part of the timeline. Consists of time intervals dividing the headers in columns.
Prop | type | description |
---|---|---|
style | object | applied to the root of the header |
className | string | applied to the root of the header |
unit | second , minute , hour , day , week , month , year or primaryHeader | intervals between columns |
labelFormat | Function or string | controls the how to format the interval label |
intervalRenderer | Function | render prop to render each interval in the header |
headerData | any | Contextual data to be passed to the item renderer as a data prop |
height | number default (30) | height of the header in pixels |
Note: passing primaryHeader
to unit the header will act as the main header with interval unit larger than timeline unit by 1
intervals are decided through the prop: unit
. By default, the unit of the intervals will be the same the timeline.
If primaryHeader
is passed to unit, it will override the unit with a unit a unit larger by 1 of the timeline unit.
If unit
is set, the unit of the header will be the unit passed though the prop and can be any unit of time
from momentjs
.
To format each interval label you can use 2 types of props to format which are:
string
: if a string was passed it will be passed to startTime
method format
which is a momentjs
object .
Function
: This is the more powerful method and offers the most control over what is rendered. The returned string
will be rendered inside the interval
1 type Unit = `second` | `minute` | `hour` | `day` | `month` | `year` 2([startTime, endTime] : [Moment, Moment], unit: Unit, labelWidth: number, formatOptions: LabelFormat = defaultFormat ) => string
by default we provide a responsive format for the dates based on the label width. it follows the following rules:
The long
, mediumLong
, medium
and short
will be be decided through the labelWidth
value according to where it lays upon the following scale:
|-----`short`-----50px-----`medium`-----100px-----`mediumLong`-----150px--------`long`-----
1// default format object 2const format : LabelFormat = { 3year: { 4 long: 'YYYY', 5 mediumLong: 'YYYY', 6 medium: 'YYYY', 7 short: 'YY' 8}, 9month: { 10 long: 'MMMM YYYY', 11 mediumLong: 'MMMM', 12 medium: 'MMMM', 13 short: 'MM/YY' 14}, 15week: { 16 long: 'w', 17 mediumLong: 'w', 18 medium: 'w', 19 short: 'w' 20}, 21day: { 22 long: 'dddd, LL', 23 mediumLong: 'dddd, LL', 24 medium: 'dd D', 25 short: 'D' 26}, 27hour: { 28 long: 'dddd, LL, HH:00', 29 mediumLong: 'L, HH:00', 30 medium: 'HH:00', 31 short: 'HH' 32}, 33minute: { 34 long: 'HH:mm', 35 mediumLong: 'HH:mm', 36 medium: 'HH:mm', 37 short: 'mm', 38}, 39second: { 40 "long": 'mm:ss', 41 mediumLong: 'mm:ss', 42 medium: 'mm:ss', 43 "short": 'ss' 44} 45}
Note: this is only an implementation of the function param. You can do this on your own easily
Render prop function used to render a customized interval. The function provides multiple parameters that can be used to render each interval.
Paramters provided to the function has two types: context params which have the state of the item and timeline, and prop getters functions
Note : the renderProp can be a component or a function for convenience
An object contains the following properties:
property | type | description |
---|---|---|
interval | object : {startTime, endTime, labelWidth, left} | an object containing data related to the interval |
intervalText | string | the string returned from labelFormat prop |
Rather than applying props on the element yourself and to avoid your props being overridden (or overriding the props returned). You can pass an object to the prop getters to avoid any problems. This object will only accept some properties that our component manage so the component make sure to combine them correctly.
property | type | description |
---|---|---|
getIntervalProps | function(props={}) | returns the props you should apply to the root div element. |
getIntervalProps
The returned props are:
These properties can be extended using the prop argument with properties:
showPeriod callback
data passed through headerData
1import Timeline, { 2 TimelineHeaders, 3 SidebarHeader, 4 DateHeader 5} from 'react-calendar-timeline' 6 7<Timeline> 8 <TimelineHeaders> 9 <SidebarHeader> 10 {({ getRootProps }) => { 11 return <div {...getRootProps()}>Left</div> 12 }} 13 </SidebarHeader> 14 <DateHeader unit="primaryHeader" /> 15 <DateHeader /> 16 <DateHeader 17 unit="day" 18 labelFormat="MM/DD" 19 style={{ height: 50 }} 20 data={{someData: 'example'}} 21 intervalRenderer={({ getIntervalProps, intervalContext, data }) => { 22 return <div {...getIntervalProps()}> 23 {intervalContext.intervalText} 24 {data.example} 25 </div> 26 }} 27 /> 28 </TimelineHeaders> 29</Timeline>
CustomHeader
Responsible for rendering the headers above calendar part of the timeline. This is the base component for DateHeader
and offers more control with less features.
Prop | type | description |
---|---|---|
unit | second , minute , hour , day , week , month , year (default timelineUnit ) | intervals |
children | Function | function as a child component to render the header |
headerData | any | Contextual data to be passed to the item renderer as a data prop |
height | number default (30) | height of the header in pixels |
The unit of the header will be the unit passed though the prop and can be any unit of time
from momentjs
. The default value for unit is timelineUnit
Function as a child component to render the header
Paramters provided to the function has three types: context params which have the state of the item and timeline, prop getters functions and helper functions.
Note : the Child function renderer can be a component or a function for convenience
({
timelineContext: {
timelineWidth,
visibleTimeStart,
visibleTimeEnd,
canvasTimeStart,
canvasTimeEnd
},
headerContext: {
unit,
intervals: this.state.intervals
},
getRootProps: this.getRootProps,
getIntervalProps: this.getIntervalProps,
showPeriod,
//contextual data passed through headerData
data,
})=> React.Node
An object contains context for timeline
and header
:
property | type | description |
---|---|---|
timelineWidth | number | width of timeline |
visibleTimeStart | number | unix milliseconds of start visible time |
visibleTimeEnd | number | unix milliseconds of end visible time |
canvasTimeStart | number | unix milliseconds of start buffer time |
canvasTimeEnd | number | unix milliseconds of end buffer time |
property | type | description |
---|---|---|
intervals | array | an array with all intervals |
unit | string | unit passed or timelineUnit |
** interval
: [startTime: Moment, endTime: Moment]
Rather than applying props on the element yourself and to avoid your props being overridden (or overriding the props returned). You can pass an object to the prop getters to avoid any problems. This object will only accept some properties that our component manage so the component make sure to combine them correctly.
property | type | description |
---|---|---|
getRootProps | function(props={}) | returns the props you should apply to the root div element. |
getIntervalProps | function(props={}) | returns the props you should apply to the interval div element. |
getIntervalProps
The returned props are:
These properties can be extended using the prop argument with properties:
showPeriod callback
property | type | description |
---|---|---|
showPeriod | function(props={}) | returns the props you should apply to the root div element. |
pass through the headerData
prop content
1import Timeline, { 2 TimelineHeaders, 3 SidebarHeader, 4 DateHeader 5} from 'react-calendar-timeline' 6 7<Timeline> 8 <TimelineHeaders> 9 <SidebarHeader> 10 {({ getRootProps }) => { 11 return <div {...getRootProps()}>Left</div> 12 }} 13 </SidebarHeader> 14 <DateHeader unit="primaryHeader" /> 15 <DateHeader /> 16 <CustomHeader height={50} headerData={{someData: 'data'}} unit="year"> 17 {({ 18 headerContext: { intervals }, 19 getRootProps, 20 getIntervalProps, 21 showPeriod, 22 data, 23 }) => { 24 return ( 25 <div {...getRootProps()}> 26 {intervals.map(interval => { 27 const intervalStyle = { 28 lineHeight: '30px', 29 textAlign: 'center', 30 borderLeft: '1px solid black', 31 cursor: 'pointer', 32 backgroundColor: 'Turquoise', 33 color: 'white' 34 } 35 return ( 36 <div 37 onClick={() => { 38 showPeriod(interval.startTime, interval.endTime) 39 }} 40 {...getIntervalProps({ 41 interval, 42 style: intervalStyle 43 })} 44 > 45 <div className="sticky"> 46 {interval.startTime.format('YYYY')} 47 </div> 48 </div> 49 ) 50 })} 51 </div> 52 ) 53 }} 54 </CustomHeader> 55 </TimelineHeaders> 56</Timeline>
You need to include the Timeline.css
file, either via static file reference or webpack stylesheet bundling. The file is located at lib/Timeline.css
Now you can use item renderer for rendering items with different colors itemRenderer. Please refer to examples for a sandbox example
The library supports right sidebar.
To use it, you need to add a props to the <Timeline />
component:
1rightSidebarWidth={150}
And add rightTitle
prop to the groups objects:
1{ 2 id: 1, 3 title: 'group 1', 4 rightTitle: 'additional info about group 1' 5}
If you are using Custom Headers then you need to add SidebarHeader
component under TimelineHeader
with variant right
you need to add sticky to the header like this example.
These module bundlers don't use the transpiled (ES5) code of this module. They load the original ES2015+ source. Thus your babel configuration needs to match ours. We recommend adding the stage-0
preset to your .babelrc
to make sure everything works as intended.
If that's too experimental, then the minimum you need is to add is the transform-class-properties
plugin that's in stage-2 and possibly the transform-object-rest-spread
plugin from stage-3. However in this case it's easier to make sure you have at least stage-2
enabled.
See issue 51 for more details.
Alternatively you may import the transpiled version of the timeline like this:
1// import Timeline from 'react-calendar-timeline' // ESnext version 2import Timeline from 'react-calendar-timeline/lib' // ES5 version
However doing so you lose on some of the features of webpack 2 and will potentially get a slightly larger bundle.
create-react-app
It's the same issue as above. See issue 134 for details and options.
This is useful when using the plugins (that you pass as children to the component). Override the CSS to change:
The timeline is built with speed, usability and extensibility in mind.
Speed: The calendar itself is actually a 3x wide scrolling canvas of the screen. All scroll events left and right happen naturally, like scrolling any website. When the timeline has scrolled enough (50% of the invisible surface on one side), we change the "position:absolute;left:{num}px;" variables of each of the visible items and scroll the canvas back. When this happens, the onBoundsChange
prop is called.
This results in a visually endless scrolling canvas with optimal performance.
Extensibility and usability: While some parameters (onTimeChange
, moveResizeValidator
) might be hard to configure, these are design decisions to make it as extensible as possible. If you have recipes for common tasks regarding those parameters, send a PR to add them to this doc.
Note: 3x can be controlled by changing the buffer
To interact and navigate within the timeline there are the following options for the user:
shift + mousewheel = move timeline left/right
alt + mousewheel = zoom in/out
ctrl + mousewheel = zoom in/out 10× faster
meta + mousewheel = zoom in/out 3x faster (win or cmd + mousewheel)
Plus there is a handling for pinch-in and pinch-out zoom gestures (two touch points).
The pinch gesture on a trackpad (not a touch device) works in Chrome and Firefox (v55+) because these browsers map the gesture to ctrl + mousewheel
.
If you like to improve React Calendar Timeline fork the repo and get started by running the following:
1$ git clone https://github.com/namespace-ee/react-calendar-timeline.git react-calendar-timeline 2$ cd react-calendar-timeline 3$ yarn 4$ yarn start
Check http://0.0.0.0:8888/ in your browser and have fun!
Please run npm run lint
before you send a pull request. npm run test
runs the jest tests.
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
0 existing vulnerabilities detected
Reason
license file detected
Details
Reason
8 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 6
Reason
Found 2/4 approved changesets -- score normalized to 5
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Score
Last Scanned on 2024-11-18
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More