Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extract ViewNavigation component #727

Merged
merged 1 commit into from
Sep 21, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 9 additions & 11 deletions src/datetime/DaysView.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import React from 'react';
import ViewNavigation from './ViewNavigation';

export default class DaysView extends React.Component {
static defaultProps = {
Expand Down Expand Up @@ -30,17 +31,14 @@ export default class DaysView extends React.Component {

renderNavigation( date, locale ) {
return (
<tr>
<th className="rdtPrev" onClick={ () => this.props.navigate( -1, 'months' ) }>
<span></span>
</th>
<th className="rdtSwitch" onClick={ () => this.props.showView( 'months' ) } colSpan={5} data-value={ this.props.viewDate.month() }>
{ locale.months( date ) + ' ' + date.year() }
</th>
<th className="rdtNext" onClick={ () => this.props.navigate( 1, 'months' ) }>
<span></span>
</th>
</tr>
<ViewNavigation
onClickPrev={ () => this.props.navigate( -1, 'months' ) }
onClickSwitch={ () => this.props.showView( 'months' ) }
onClickNext={ () => this.props.navigate( 1, 'months' ) }
switchContent={ locale.months( date ) + ' ' + date.year() }
switchColSpan={5}
switchProps={ { 'data-value': this.props.viewDate.month() } }
/>
);
}

Expand Down
23 changes: 10 additions & 13 deletions src/datetime/MonthsView.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import React from 'react';
import ViewNavigation from './ViewNavigation';

export default class MonthsView extends React.Component {
render() {
return (
<div className="rdtMonths">
<table>
<thead>
{ this.renderHeader() }
{ this.renderNavigation() }
</thead>
</table>
<table>
Expand All @@ -18,21 +19,17 @@ export default class MonthsView extends React.Component {
);
}

renderHeader() {
renderNavigation() {
let year = this.props.viewDate.year();
arqex marked this conversation as resolved.
Show resolved Hide resolved

return (
<tr>
<th className="rdtPrev" onClick={ () => this.props.navigate( -1, 'years' ) }>
<span></span>
</th>
<th className="rdtSwitch" onClick={ () => this.props.showView( 'years' ) } colSpan="2" data-value={ year } >
{ year }
</th>
<th className="rdtNext" onClick={ () => this.props.navigate( 1, 'years' ) }>
<span></span>
</th>
</tr>
<ViewNavigation
onClickPrev={ () => this.props.navigate( -1, 'years' ) }
onClickSwitch={ () => this.props.showView( 'years' ) }
onClickNext={ () => this.props.navigate( 1, 'years' ) }
switchContent={ year }
switchColSpan="2"
/>
);
}

Expand Down
17 changes: 17 additions & 0 deletions src/datetime/ViewNavigation.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import React from 'react';

export default function ViewNavigation( { onClickPrev, onClickSwitch, onClickNext, switchContent, switchColSpan, switchProps } ) {
return (
<tr>
<th className="rdtPrev" onClick={ onClickPrev }>
<span></span>
</th>
<th className="rdtSwitch" colSpan={ switchColSpan } onClick={ onClickSwitch } {...switchProps}>
{ switchContent }
</th>
<th className="rdtNext" onClick={ onClickNext }>
<span></span>
</th>
</tr>
);
}
22 changes: 9 additions & 13 deletions src/datetime/YearsView.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import React from 'react';
import ViewNavigation from './ViewNavigation';

export default class YearsView extends React.Component {
render() {
Expand All @@ -8,7 +9,7 @@ export default class YearsView extends React.Component {
<div className="rdtYears">
<table>
<thead>
{ this.renderHeader( viewYear ) }
{ this.renderNavigation( viewYear ) }
</thead>
</table>
<table>
Expand All @@ -20,19 +21,14 @@ export default class YearsView extends React.Component {
);
}

renderHeader( viewYear ) {
renderNavigation( viewYear ) {
return (
<tr>
<th className="rdtPrev" onClick={ () => this.props.navigate( -10, 'years' ) }>
<span></span>
</th>
<th className="rdtSwitch" onClick={ () => this.props.showView( 'years' ) }>
{ `${viewYear}-${viewYear + 9}` }
</th>
<th className="rdtNext" onClick={ () => this.props.navigate( 10, 'years' ) }>
<span></span>
</th>
</tr>
<ViewNavigation
onClickPrev={ () => this.props.navigate( -10, 'years' ) }
onClickSwitch={ () => this.props.showView( 'years' ) }
onClickNext={ () => this.props.navigate( 10, 'years' ) }
switchContent={ `${viewYear}-${viewYear + 9}` }
/>
);
}

Expand Down