@@ -5,6 +5,7 @@ import CustomHeader from './CustomHeader'
55import { getNextUnit } from '../utility/calendar'
66import { defaultHeaderFormats } from '../default-config'
77import Interval from './Interval'
8+ import memoize from 'memoize-one'
89
910class DateHeader extends React . Component {
1011 static propTypes = {
@@ -31,14 +32,14 @@ class DateHeader extends React.Component {
3132 return this . props . timelineUnit
3233 }
3334
34- getRootStyle = ( ) => {
35+ getRootStyle = memoize ( style => {
3536 return {
3637 height : 30 ,
37- ...this . props . style
38+ ...style
3839 }
39- }
40+ } )
4041
41- getLabelFormat ( interval , unit , labelWidth ) {
42+ getLabelFormat = ( interval , unit , labelWidth ) => {
4243 const { labelFormat } = this . props
4344 if ( typeof labelFormat === 'string' ) {
4445 const startTime = interval [ 0 ]
@@ -50,50 +51,43 @@ class DateHeader extends React.Component {
5051 }
5152 }
5253
54+ getHeaderData = memoize (
55+ (
56+ intervalRenderer ,
57+ style ,
58+ className ,
59+ getLabelFormat ,
60+ unitProp ,
61+ headerData
62+ ) => {
63+ return {
64+ intervalRenderer,
65+ style,
66+ className,
67+ getLabelFormat,
68+ unitProp,
69+ headerData
70+ }
71+ }
72+ )
73+
5374 render ( ) {
5475 const unit = this . getHeaderUnit ( )
5576 const { headerData, height } = this . props
5677 return (
57- < CustomHeader unit = { unit } height = { height } headerData = { headerData } >
58- { ( {
59- headerContext : { intervals } ,
60- getRootProps,
61- getIntervalProps,
62- showPeriod,
63- data
64- } ) => {
65- const unit = this . getHeaderUnit ( )
66-
67- return (
68- < div
69- data-testid = { `dateHeader` }
70- className = { this . props . className }
71- { ...getRootProps ( { style : this . getRootStyle ( ) } ) }
72- >
73- { intervals . map ( interval => {
74- const intervalText = this . getLabelFormat (
75- [ interval . startTime , interval . endTime ] ,
76- unit ,
77- interval . labelWidth
78- )
79- return (
80- < Interval
81- key = { `label-${ interval . startTime . valueOf ( ) } ` }
82- unit = { unit }
83- interval = { interval }
84- showPeriod = { showPeriod }
85- intervalText = { intervalText }
86- primaryHeader = { this . props . unit === 'primaryHeader' }
87- getIntervalProps = { getIntervalProps }
88- intervalRenderer = { this . props . intervalRenderer }
89- headerData = { data }
90- />
91- )
92- } ) }
93- </ div >
94- )
95- } }
96- </ CustomHeader >
78+ < CustomHeader
79+ unit = { unit }
80+ height = { height }
81+ headerData = { this . getHeaderData (
82+ this . props . intervalRenderer ,
83+ this . getRootStyle ( this . props . style ) ,
84+ this . props . className ,
85+ this . getLabelFormat ,
86+ this . props . unit ,
87+ this . props . headerData
88+ ) }
89+ children = { Header }
90+ />
9791 )
9892 }
9993}
@@ -116,6 +110,7 @@ class DateHeaderWrapper extends React.Component {
116110 static defaultProps = {
117111 labelFormat : formatLabel
118112 }
113+
119114 render ( ) {
120115 const {
121116 unit,
@@ -148,6 +143,50 @@ class DateHeaderWrapper extends React.Component {
148143 }
149144}
150145
146+ function Header ( {
147+ headerContext : { intervals, unit } ,
148+ getRootProps,
149+ getIntervalProps,
150+ showPeriod,
151+ data : {
152+ style,
153+ intervalRenderer,
154+ className,
155+ getLabelFormat,
156+ unitProp,
157+ ...restData
158+ }
159+ } ) {
160+ return (
161+ < div
162+ data-testid = { `dateHeader` }
163+ className = { className }
164+ { ...getRootProps ( { style } ) }
165+ >
166+ { intervals . map ( interval => {
167+ const intervalText = getLabelFormat (
168+ [ interval . startTime , interval . endTime ] ,
169+ unit ,
170+ interval . labelWidth
171+ )
172+ return (
173+ < Interval
174+ key = { `label-${ interval . startTime . valueOf ( ) } ` }
175+ unit = { unit }
176+ interval = { interval }
177+ showPeriod = { showPeriod }
178+ intervalText = { intervalText }
179+ primaryHeader = { unitProp === 'primaryHeader' }
180+ getIntervalProps = { getIntervalProps }
181+ intervalRenderer = { intervalRenderer }
182+ headerData = { restData }
183+ />
184+ )
185+ } ) }
186+ </ div >
187+ )
188+ }
189+
151190function formatLabel (
152191 [ timeStart , timeEnd ] ,
153192 unit ,
0 commit comments