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

Allow the client to pass through a label for the selected range #19

Merged
merged 1 commit into from
Apr 21, 2015
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
5 changes: 4 additions & 1 deletion dist/DateRangePicker.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ var DateRangePicker = React.createClass({
maximumDate: React.PropTypes.instanceOf(Date),
selectionType: React.PropTypes.oneOf(["single", "range"]),
stateDefinitions: React.PropTypes.object,
selectedLabel: React.PropTypes.string,
dateStates: React.PropTypes.array, // an array of date ranges and their states
defaultState: React.PropTypes.string,
initialFromValue: React.PropTypes.bool,
Expand Down Expand Up @@ -89,6 +90,7 @@ var DateRangePicker = React.createClass({
label: null
}
},
selectedLabel: "Your selected dates",
defaultState: "__default",
dateStates: [],
showLegend: false,
Expand Down Expand Up @@ -395,6 +397,7 @@ var DateRangePicker = React.createClass({
var PaginationArrow = this.props.paginationArrowComponent;
var numberOfCalendars = this.props.numberOfCalendars;
var stateDefinitions = this.props.stateDefinitions;
var selectedLabel = this.props.selectedLabel;
var showLegend = this.props.showLegend;


Expand All @@ -406,7 +409,7 @@ var DateRangePicker = React.createClass({
React.createElement(PaginationArrow, { direction: "previous", onMouseEnter: this.moveBackIfSelecting, onClick: this.moveBack, disabled: !this.canMoveBack() }),
calendars.toJS(),
React.createElement(PaginationArrow, { direction: "next", onMouseEnter: this.moveForwardIfSelecting, onClick: this.moveForward, disabled: !this.canMoveForward() }),
showLegend ? React.createElement(Legend, { stateDefinitions: stateDefinitions }) : null
showLegend ? React.createElement(Legend, { stateDefinitions: stateDefinitions, selectedLabel: selectedLabel }) : null
);
}
});
Expand Down
3 changes: 2 additions & 1 deletion dist/Legend.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ var Legend = React.createClass({
mixins: [BemMixin, PureRenderMixin],

render: function render() {
var selectedLabel = this.props.selectedLabel;
var stateDefinitions = this.props.stateDefinitions;
var block = this.getBemBlock();
var namespace = this.getBemNamespace();
Expand Down Expand Up @@ -55,7 +56,7 @@ var Legend = React.createClass({
React.createElement(
"span",
{ className: this.cx({ element: "LegendItemLabel" }) },
"Your selected dates"
selectedLabel
)
),
items
Expand Down
6 changes: 4 additions & 2 deletions src/DateRangePicker.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ var DateRangePicker = React.createClass({
maximumDate: React.PropTypes.instanceOf(Date),
selectionType: React.PropTypes.oneOf(['single', 'range']),
stateDefinitions: React.PropTypes.object,
selectedLabel: React.PropTypes.string,
dateStates: React.PropTypes.array, // an array of date ranges and their states
defaultState: React.PropTypes.string,
initialFromValue: React.PropTypes.bool,
Expand Down Expand Up @@ -80,6 +81,7 @@ var DateRangePicker = React.createClass({
label: null
}
},
selectedLabel: "Your selected dates",
defaultState: '__default',
dateStates: [],
showLegend: false,
Expand Down Expand Up @@ -378,7 +380,7 @@ var DateRangePicker = React.createClass({
},

render: function() {
var {paginationArrowComponent: PaginationArrow, numberOfCalendars, stateDefinitions, showLegend} = this.props;
var {paginationArrowComponent: PaginationArrow, numberOfCalendars, stateDefinitions, selectedLabel, showLegend} = this.props;

var calendars = Immutable.Range(0, numberOfCalendars).map(this.renderCalendar);

Expand All @@ -387,7 +389,7 @@ var DateRangePicker = React.createClass({
<PaginationArrow direction="previous" onMouseEnter={this.moveBackIfSelecting} onClick={this.moveBack} disabled={!this.canMoveBack()} />
{calendars.toJS()}
<PaginationArrow direction="next" onMouseEnter={this.moveForwardIfSelecting} onClick={this.moveForward} disabled={!this.canMoveForward()} />
{showLegend ? <Legend stateDefinitions={stateDefinitions} /> : null}
{showLegend ? <Legend stateDefinitions={stateDefinitions} selectedLabel={selectedLabel} /> : null}
</div>
);
}
Expand Down
4 changes: 2 additions & 2 deletions src/Legend.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ var Legend = React.createClass({
mixins: [BemMixin, PureRenderMixin],

render() {
var {stateDefinitions} = this.props;
var {selectedLabel, stateDefinitions} = this.props;
var block = this.getBemBlock();
var namespace = this.getBemNamespace();
var items = [];
Expand All @@ -39,7 +39,7 @@ var Legend = React.createClass({
<ul className={this.cx()}>
<li className={this.cx({element: 'LegendItem'})}>
<span className={this.cx({element: 'LegendItemColor', modifiers: {'selection': true}})} />
<span className={this.cx({element: 'LegendItemLabel'})}>Your selected dates</span>
<span className={this.cx({element: 'LegendItemLabel'})}>{selectedLabel}</span>
</li>
{items}
</ul>
Expand Down