Skip to content

Commit

Permalink
Introduce renderWeekHeader prop
Browse files Browse the repository at this point in the history
  • Loading branch information
Joachim Seminck committed Aug 23, 2017
1 parent 46bf99b commit 494117b
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 2 deletions.
14 changes: 12 additions & 2 deletions src/components/DayPicker.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ const propTypes = forbidExtraProps({
onNextMonthClick: PropTypes.func,
onMultiplyScrollableMonths: PropTypes.func, // VERTICAL_SCROLLABLE daypickers only

// week header props
renderWeekHeaderDay: PropTypes.func,

// month props
renderMonth: PropTypes.func,

Expand Down Expand Up @@ -105,6 +108,9 @@ export const defaultProps = {
onNextMonthClick() {},
onMultiplyScrollableMonths() {},

// week header props
renderWeekHeaderDay: null,

// month props
renderMonth: null,

Expand Down Expand Up @@ -668,7 +674,7 @@ export default class DayPicker extends React.Component {
}

renderWeekHeader(index) {
const { daySize, orientation } = this.props;
const { daySize, orientation, renderWeekHeaderDay } = this.props;
const { calendarMonthWidth } = this.state;
const verticalScrollable = orientation === VERTICAL_SCROLLABLE;
const horizontalStyle = {
Expand All @@ -692,9 +698,13 @@ export default class DayPicker extends React.Component {

const header = [];
for (let i = 0; i < 7; i += 1) {
const day = (i + firstDayOfWeek) % 7;

header.push(
<li key={i} style={{ width: daySize }}>
<small>{moment().day((i + firstDayOfWeek) % 7).format('dd')}</small>
{ renderWeekHeaderDay ? renderWeekHeaderDay(day) : (
<small>{moment().day(day).format('dd')}</small>
) }
</li>,
);
}
Expand Down
4 changes: 4 additions & 0 deletions src/components/DayPickerRangeController.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ const propTypes = forbidExtraProps({

// DayPicker props
renderMonth: PropTypes.func,
renderWeekHeaderDay: PropTypes.func,
enableOutsideDays: PropTypes.bool,
numberOfMonths: PropTypes.number,
orientation: ScrollableOrientationShape,
Expand Down Expand Up @@ -99,6 +100,7 @@ const defaultProps = {

// DayPicker props
renderMonth: null,
renderWeekHeaderDay: null,
enableOutsideDays: false,
numberOfMonths: 1,
orientation: HORIZONTAL_ORIENTATION,
Expand Down Expand Up @@ -822,6 +824,7 @@ export default class DayPickerRangeController extends React.Component {
orientation,
monthFormat,
renderMonth,
renderWeekHeaderDay,
navPrev,
navNext,
onOutsideClick,
Expand Down Expand Up @@ -856,6 +859,7 @@ export default class DayPickerRangeController extends React.Component {
onMultiplyScrollableMonths={this.onMultiplyScrollableMonths}
monthFormat={monthFormat}
renderMonth={renderMonth}
renderWeekHeaderDay={renderWeekHeaderDay}
withPortal={withPortal}
hidden={!focusedInput}
initialVisibleMonth={() => currentMonth}
Expand Down
4 changes: 4 additions & 0 deletions src/components/DayPickerSingleDateController.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ const propTypes = forbidExtraProps({

// DayPicker props
renderMonth: PropTypes.func,
renderWeekHeaderDay: PropTypes.func,
enableOutsideDays: PropTypes.bool,
numberOfMonths: PropTypes.number,
orientation: ScrollableOrientationShape,
Expand Down Expand Up @@ -92,6 +93,7 @@ const defaultProps = {

// DayPicker props
renderMonth: null,
renderWeekHeaderDay: null,
enableOutsideDays: false,
numberOfMonths: 1,
orientation: HORIZONTAL_ORIENTATION,
Expand Down Expand Up @@ -553,6 +555,7 @@ export default class DayPickerSingleDateController extends React.Component {
orientation,
monthFormat,
renderMonth,
renderWeekHeaderDay,
navPrev,
navNext,
withPortal,
Expand Down Expand Up @@ -594,6 +597,7 @@ export default class DayPickerSingleDateController extends React.Component {
navPrev={navPrev}
navNext={navNext}
renderMonth={renderMonth}
renderWeekHeaderDay={renderWeekHeaderDay}
renderDay={renderDay}
renderCalendarInfo={renderCalendarInfo}
isFocused={isFocused}
Expand Down
6 changes: 6 additions & 0 deletions stories/DayPicker.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import React from 'react';
import moment from 'moment';
import { storiesOf } from '@storybook/react';
import DayPicker from '../src/components/DayPicker';

Expand Down Expand Up @@ -95,6 +96,11 @@ storiesOf('DayPicker', module)
renderDay={day => (day.day() % 6 === 5 ? '😻' : day.format('D'))}
/>
))
.addWithInfo('with custom week headers', () => (
<DayPicker
renderWeekHeaderDay={day => <b>{moment().day(day).format('ddd')}</b>}
/>
))
.addWithInfo('vertical with fixed-width container', () => (
<div style={{ width: '400px' }}>
<DayPicker
Expand Down

0 comments on commit 494117b

Please sign in to comment.