Skip to content

Commit

Permalink
Fixed #706 - Header and Footer templates for Calendar component
Browse files Browse the repository at this point in the history
  • Loading branch information
cagataycivici committed Jan 9, 2019
1 parent d36f314 commit 144145f
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 4 deletions.
6 changes: 2 additions & 4 deletions src/components/calendar/Calendar.css
Original file line number Diff line number Diff line change
Expand Up @@ -144,10 +144,8 @@
cursor: pointer;
}

.p-datepicker .p-datepicker-buttonbar {
border-left: 0 none;
border-right: 0 none;
border-bottom: 0 none;
.p-datepicker .p-datepicker-buttonbar,
.p-datepicker .p-datepicker-footer {
padding: .5em;
}

Expand Down
2 changes: 2 additions & 0 deletions src/components/calendar/Calendar.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ interface CalendarProps {
tooltipOptions?: TooltipOptions;
yearRange?: string;
dateTemplate?(dateMeta:DateMetaData): React.ReactNode;
headerTemplate?(): React.ReactNode;
footerTemplate?(): React.ReactNode;
onFocus?(event: Event): void;
onBlur?(event: Event): void;
onInput?(event: Event): void;
Expand Down
23 changes: 23 additions & 0 deletions src/components/calendar/Calendar.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ export class Calendar extends Component {
tooltip: null,
tooltipOptions: null,
dateTemplate: null,
headerTemplate: null,
footerTemplate: null,
onFocus: null,
onBlur: null,
onInput: null,
Expand Down Expand Up @@ -137,6 +139,8 @@ export class Calendar extends Component {
tooltip: PropTypes.string,
tooltipOptions: PropTypes.object,
dateTemplate: PropTypes.func,
headerTemplate: PropTypes.func,
footerTemplate: PropTypes.func,
onFocus: PropTypes.func,
onBlur: PropTypes.func,
onInput: PropTypes.func,
Expand Down Expand Up @@ -1660,10 +1664,12 @@ export class Calendar extends Component {
const forwardNavigator = (this.props.numberOfMonths === 1) || (index === this.props.numberOfMonths -1) ? this.renderForwardNavigator(): null;
const title = this.renderTitle(monthMetaData);
const dateViewGrid = this.renderDateViewGrid(monthMetaData, weekDays);
const header = this.props.headerTemplate ? this.props.headerTemplate() : null;

return (
<div key={monthMetaData.month} className="p-datepicker-group">
<div className="p-datepicker-header">
{header}
{backwardNavigator}
{forwardNavigator}
{title}
Expand Down Expand Up @@ -1913,6 +1919,21 @@ export class Calendar extends Component {
return null;
}
}

renderFooter() {
if (this.props.footerTemplate) {
const content = this.props.footerTemplate();

return (
<div className="p-datepicker-footer">
{content}
</div>
)
}
else {
return null;
}
}

render() {
const className = classNames('p-calendar', this.props.className, {
Expand All @@ -1935,6 +1956,7 @@ export class Calendar extends Component {
const datePicker = this.renderDatePicker();
const timePicker = this.renderTimePicker();
const buttonBar = this.renderButtonBar();
const footer = this.renderFooter();

return (
<span ref={(el) => this.container = el} id={this.props.id} className={className} style={this.props.style}>
Expand All @@ -1945,6 +1967,7 @@ export class Calendar extends Component {
{datePicker}
{timePicker}
{buttonBar}
{footer}
</CalendarPanel>
</span>
);
Expand Down
9 changes: 9 additions & 0 deletions src/showcase/calendar/CalendarDemo.js
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,15 @@ dateTemplate(date) {
}
}
`}
</CodeHighlight>

<h3>Header and Footer</h3>
<p><i>headerTemplate</i> and <i>footerTemplate</i> properties are available to place custom content at these sections.</p>
<CodeHighlight className="language-jsx">
{`
<Calendar value={this.state.date} onChange={(e) => this.setState({date: e.value})} headerTemplate={<Button label="Custom Button" />} footerTemplate={<div>Footer Content</div>} />
`}
</CodeHighlight>

Expand Down

0 comments on commit 144145f

Please sign in to comment.