Skip to content

Commit

Permalink
Merge pull request #402 from andresgutgon/feature/custom-date-header
Browse files Browse the repository at this point in the history
Adding optional custom DateHeader component for month view
  • Loading branch information
jquense authored May 24, 2017
2 parents 4170e6e + 1d33fcf commit 04f1fc7
Show file tree
Hide file tree
Showing 7 changed files with 63 additions and 12 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,6 @@ node_modules

# Webstorm ide files
.idea

# Mac OS X
.DS_Store
6 changes: 5 additions & 1 deletion src/BackgroundCells.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,11 @@ class BackgroundCells extends React.Component {
{range.map((date, index) => {
let selected = selecting && index >= startIdx && index <= endIdx;
return (
<Wrapper key={index} value={date}>
<Wrapper
key={index}
value={date}
range={range}
>
<div
style={segStyle(1, range.length)}
className={cn(
Expand Down
7 changes: 7 additions & 0 deletions src/BackgroundWrapper.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
import React from 'react';
import PropTypes from 'prop-types';

class BackgroundWrapper extends React.Component {
render() {
return this.props.children;
}
}

BackgroundWrapper.propTypes = {
children: PropTypes.element,
value: PropTypes.instanceOf(Date),
range: PropTypes.arrayOf(PropTypes.instanceOf(Date))
}

export default BackgroundWrapper;
2 changes: 1 addition & 1 deletion src/Calendar.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,6 @@ class Calendar extends React.Component {
* ```
*/
onSelecting: PropTypes.func,

/**
* The selected event, if any.
*/
Expand Down Expand Up @@ -420,6 +419,7 @@ class Calendar extends React.Component {
}),
month: PropTypes.shape({
header: elementType,
dateHeader: elementType,
event: elementType
})
}),
Expand Down
24 changes: 24 additions & 0 deletions src/DateHeader.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import PropTypes from 'prop-types';
import React from 'react'

const DateHeader = ({ label, drillDownView, onDrillDown }) => {
if (!drillDownView) {
return (<span>{label}</span>)
}

return (
<a href="#" onClick={onDrillDown}>
{label}
</a>
)
}

DateHeader.propTypes = {
label: PropTypes.node,
date: PropTypes.instanceOf(Date),
drillDownView: PropTypes.string,
onDrillDown: PropTypes.func,
isOffRange: PropTypes.bool
}

export default DateHeader
18 changes: 8 additions & 10 deletions src/Month.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import Popup from './Popup'
import Overlay from 'react-overlays/lib/Overlay'
import DateContentRow from './DateContentRow'
import Header from './Header'
import DateHeader from './DateHeader'

import { accessor, dateFormat } from './utils/propTypes'
import { segStyle, inRange, sortEvents } from './utils/eventLevels'
Expand Down Expand Up @@ -205,6 +206,7 @@ class MonthView extends React.Component {
let isCurrent = dates.eq(date, currentDate, 'day')
let drilldownView = getDrilldownView(date)
let label = localizer.format(date, dateFormat, culture)
let DateHeaderComponent = this.props.components.dateHeader || DateHeader

return (
<div
Expand All @@ -215,16 +217,12 @@ class MonthView extends React.Component {
isCurrent && 'rbc-current'
)}
>
{drilldownView
? <a
href="#"
onClick={e => this.handleHeadingClick(date, drilldownView, e)}
>
{label}
</a>
: <span>
{label}
</span>}
<DateHeaderComponent
label={label}
date={date}
drilldownView={drilldownView}
isOffRange={isOffRange}
onDrillDown={e => this.handleHeadingClick(date, drilldownView, e)} />
</div>
)
}
Expand Down
15 changes: 15 additions & 0 deletions stories/Calendar.js
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,21 @@ storiesOf('module.Calendar.week', module)
</div>
)
})
.add('add custom date header', () => {
return (
<div style={{height: 600}}>
<Calendar
defaultView={Calendar.Views.MONTH}
events={events}
components={{
month: {
dateHeader: ({ label }) => <span>{label} - Custom date header</span>
}
}}
/>
</div>
)
})
.add('no duration', () => {
return (
<div style={{height: 600}}>
Expand Down

0 comments on commit 04f1fc7

Please sign in to comment.