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 adding a custom CSS class to the DateRangePicker #147

Merged
merged 1 commit into from
Aug 9, 2016
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
7 changes: 5 additions & 2 deletions src/DateRangePicker.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ const DateRangePicker = React.createClass({
propTypes: {
bemBlock: React.PropTypes.string,
bemNamespace: React.PropTypes.string,
className: React.PropTypes.string,
dateStates: React.PropTypes.array, // an array of date ranges and their states
defaultState: React.PropTypes.string,
disableNavigation: React.PropTypes.bool,
Expand Down Expand Up @@ -62,6 +63,7 @@ const DateRangePicker = React.createClass({
return {
bemNamespace: null,
bemBlock: 'DateRangePicker',
className: '',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

numberOfCalendars: 1,
firstOfWeek: 0,
disableNavigation: false,
Expand Down Expand Up @@ -496,12 +498,13 @@ const DateRangePicker = React.createClass({
},

render: function() {
let {paginationArrowComponent: PaginationArrowComponent, numberOfCalendars, stateDefinitions, selectedLabel, showLegend, helpMessage} = this.props;
let {paginationArrowComponent: PaginationArrowComponent, className, numberOfCalendars, stateDefinitions, selectedLabel, showLegend, helpMessage} = this.props;

let calendars = Immutable.Range(0, numberOfCalendars).map(this.renderCalendar);
className = this.cx({element: null}) + ' ' + className;

return (
<div className={this.cx({element: null})}>
<div className={className.trim()}>
Copy link
Member

@AlanFoster AlanFoster Jul 13, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What are your thoughts on -

<div className={`$this.cx({element: null}) ${className}`}>

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There will be a trailing space if no className is given, but this is not really a problem.
Another idea... What are your thoughts on this? 😉

let combinedClassName = [ this.cx({element: null}), className ].join(' ').trim()
<div className={combinedClassName}>

<PaginationArrowComponent direction="previous" onTrigger={this.moveBack} disabled={!this.canMoveBack()} />
{calendars.toJS()}
<PaginationArrowComponent direction="next" onTrigger={this.moveForward} disabled={!this.canMoveForward()} />
Expand Down
7 changes: 7 additions & 0 deletions src/tests/DateRangePicker.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,13 @@ describe('The DateRangePicker component', function () {
expect(this.renderedComponent.props.className).toBe('DateRangePicker');
});

it('uses the supplied CSS class', function () {
this.useShallowRenderer({
className: 'foo-bar',
});
expect(this.renderedComponent.props.className).toBe('DateRangePicker foo-bar');
});

describe('contains PaginationArrow components', function () {

it('2 of them', function () {
Expand Down