Skip to content

Commit

Permalink
Merge pull request #37 from onefinestay/proptypes-and-linting
Browse files Browse the repository at this point in the history
fix the lints
  • Loading branch information
jkimbo committed May 18, 2015
2 parents 47972c8 + 41ae9c3 commit 69a717f
Show file tree
Hide file tree
Showing 22 changed files with 186 additions and 59 deletions.
20 changes: 6 additions & 14 deletions dist/DateRangePicker.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ var _utilsBemMixin = require('./utils/BemMixin');

var _utilsBemMixin2 = _interopRequireDefault(_utilsBemMixin);

var _utilsCustomPropTypes = require('./utils/CustomPropTypes');

var _utilsCustomPropTypes2 = _interopRequireDefault(_utilsCustomPropTypes);

var _Legend = require('./Legend');

var _Legend2 = _interopRequireDefault(_Legend);
Expand Down Expand Up @@ -85,18 +89,7 @@ var DateRangePicker = _reactAddons2['default'].createClass({
selectionType: _reactAddons2['default'].PropTypes.oneOf(['single', 'range']),
showLegend: _reactAddons2['default'].PropTypes.bool,
stateDefinitions: _reactAddons2['default'].PropTypes.object,
value: function value(props, propName) {
var val = props[propName];

if (!val) {
return null;
} else if (_momentRange2['default'].isMoment(val)) {
return null;
} else if (val.start && val.end && _momentRange2['default'].isMoment(val.start) && _momentRange2['default'].isMoment(val.end)) {
return null;
}
return new Error('Value must be a moment or a moment range');
}
value: _utilsCustomPropTypes2['default'].momentOrMomentRange
},

getDefaultProps: function getDefaultProps() {
Expand Down Expand Up @@ -301,7 +294,7 @@ var DateRangePicker = _reactAddons2['default'].createClass({
}
},

onUnHighlightDate: function onUnHighlightDate(date) {
onUnHighlightDate: function onUnHighlightDate() {
this.setState({
highlightedDate: null
});
Expand Down Expand Up @@ -508,7 +501,6 @@ var DateRangePicker = _reactAddons2['default'].createClass({
var hideSelection = _state2.hideSelection;
var highlightedDate = _state2.highlightedDate;
var highlightedRange = _state2.highlightedRange;
var highlightStartDate = _state2.highlightStartDate;

var monthDate = this.getMonthDate();
var year = monthDate.year();
Expand Down
4 changes: 0 additions & 4 deletions dist/calendar/CalendarDate.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,6 @@ var _reactAddons = require('react/addons');

var _reactAddons2 = _interopRequireDefault(_reactAddons);

var _momentRange = require('moment-range');

var _momentRange2 = _interopRequireDefault(_momentRange);

var _immutable = require('immutable');

var _immutable2 = _interopRequireDefault(_immutable);
Expand Down
5 changes: 5 additions & 0 deletions dist/calendar/CalendarDatePeriod.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ var CalendarDatePeriod = _reactAddons2['default'].createClass({

mixins: [_utilsBemMixin2['default'], _utilsPureRenderMixin2['default']],

propTypes: {
color: _reactAddons2['default'].PropTypes.string,
period: _reactAddons2['default'].PropTypes.string
},

render: function render() {
var _props = this.props;
var color = _props.color;
Expand Down
4 changes: 4 additions & 0 deletions dist/calendar/CalendarHighlight.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ var CalendarHighlight = _reactAddons2['default'].createClass({

mixins: [_utilsBemMixin2['default'], _utilsPureRenderMixin2['default']],

propTypes: {
modifier: _reactAddons2['default'].PropTypes.string
},

render: function render() {
var modifier = this.props.modifier;

Expand Down
18 changes: 16 additions & 2 deletions dist/calendar/CalendarMonth.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ var _utilsBemMixin = require('../utils/BemMixin');

var _utilsBemMixin2 = _interopRequireDefault(_utilsBemMixin);

var _utilsCustomPropTypes = require('../utils/CustomPropTypes');

var _utilsCustomPropTypes2 = _interopRequireDefault(_utilsCustomPropTypes);

var _utilsIsMomentRange = require('../utils/isMomentRange');

var _utilsIsMomentRange2 = _interopRequireDefault(_utilsIsMomentRange);
Expand All @@ -50,6 +54,16 @@ var CalendarMonth = _reactAddons2['default'].createClass({

mixins: [_utilsBemMixin2['default'], _utilsPureRenderMixin2['default']],

propTypes: {
dateComponent: _reactAddons2['default'].PropTypes.func,
enabledRange: _utilsCustomPropTypes2['default'].momentRange,
firstOfWeek: _reactAddons2['default'].PropTypes.oneOf([0, 1, 2, 3, 4, 5, 6]),
hideSelection: _reactAddons2['default'].PropTypes.bool,
highlightedDate: _reactAddons2['default'].PropTypes.object,
highlightedRange: _reactAddons2['default'].PropTypes.object,
value: _utilsCustomPropTypes2['default'].momentOrMomentRange
},

renderDay: function renderDay(date, i) {
var _props = this.props;
var CalendarDate = _props.dateComponent;
Expand Down Expand Up @@ -137,11 +151,11 @@ var CalendarMonth = _reactAddons2['default'].createClass({
var enabledRange = this.props.enabledRange;

if (year < enabledRange.start.year()) {
return;
return null;
}

if (year > enabledRange.end.year()) {
return;
return null;
}

return _reactAddons2['default'].createElement(
Expand Down
5 changes: 5 additions & 0 deletions dist/calendar/CalendarSelection.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ var CalendarSelection = _reactAddons2['default'].createClass({

mixins: [_utilsBemMixin2['default'], _utilsPureRenderMixin2['default']],

propTypes: {
modifier: _reactAddons2['default'].PropTypes.string,
pending: _reactAddons2['default'].PropTypes.bool.isRequired
},

render: function render() {
var _props = this.props;
var modifier = _props.modifier;
Expand Down
3 changes: 2 additions & 1 deletion dist/utils/BemMixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@ var BemMixin = {
var opts = {
namespace: this.getBemNamespace(),
element: this.constructor.displayName,
block: this.getBemBlock() };
block: this.getBemBlock()
};

_extends(opts, options);
return _bemCx2['default'](opts);
Expand Down
42 changes: 42 additions & 0 deletions dist/utils/CustomPropTypes.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
'use strict';

Object.defineProperty(exports, '__esModule', {
value: true
});

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }

var _momentRange = require('moment-range');

var _momentRange2 = _interopRequireDefault(_momentRange);

var _isMomentRange = require('./isMomentRange');

var _isMomentRange2 = _interopRequireDefault(_isMomentRange);

exports['default'] = {
momentOrMomentRange: function momentOrMomentRange(props, propName) {
var val = props[propName];

if (!val) {
return null;
} else if (_momentRange2['default'].isMoment(val)) {
return null;
} else if (_isMomentRange2['default'](val)) {
return null;
}
return new Error('Value must be a moment or a moment range');
},

momentRange: function momentRange(props, propName) {
var val = props[propName];

if (!val) {
return null;
} else if (_isMomentRange2['default'](val)) {
return null;
}
return new Error('Value must be a moment range');
}
};
module.exports = exports['default'];
4 changes: 2 additions & 2 deletions dist/utils/bemCx.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ function bemCx() {
bemClasses.push(baseClassName);

if (states) {
if (typeof states == 'object') {
if (typeof states === 'object') {
states = Object.keys(states).filter(function (s) {
return states[s];
});
Expand All @@ -45,7 +45,7 @@ function bemCx() {
}

if (modifiers) {
if (typeof modifiers == 'object') {
if (typeof modifiers === 'object') {
modifiers = Object.keys(modifiers).filter(function (m) {
return modifiers[m];
});
Expand Down
9 changes: 8 additions & 1 deletion dist/utils/shallowEqual.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
'use strict';

Object.defineProperty(exports, '__esModule', {
value: true
});

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }

var _momentRange = require('moment-range');
Expand All @@ -19,6 +23,7 @@ function shallowEqual(objA, objB) {
return true;
}
var key;

// Test for A's keys different from B.
for (key in objA) {
if (objA.hasOwnProperty(key)) {
Expand All @@ -35,6 +40,7 @@ function shallowEqual(objA, objB) {
}
}
}

// Test for B's keys missing from A.
for (key in objB) {
if (objB.hasOwnProperty(key) && !objA.hasOwnProperty(key)) {
Expand All @@ -44,4 +50,5 @@ function shallowEqual(objA, objB) {
return true;
}

module.exports = shallowEqual;
exports['default'] = shallowEqual;
module.exports = exports['default'];
27 changes: 8 additions & 19 deletions src/DateRangePicker.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import Immutable from 'immutable';
import calendar from 'calendar';

import BemMixin from './utils/BemMixin';
import CustomPropTypes from './utils/CustomPropTypes';
import Legend from './Legend';

import CalendarMonth from './calendar/CalendarMonth';
Expand Down Expand Up @@ -50,18 +51,7 @@ const DateRangePicker = React.createClass({
selectionType: React.PropTypes.oneOf(['single', 'range']),
showLegend: React.PropTypes.bool,
stateDefinitions: React.PropTypes.object,
value(props, propName) {
let val = props[propName];

if (!val) {
return null;
} else if (moment.isMoment(val)) {
return null;
} else if (val.start && val.end && moment.isMoment(val.start) && moment.isMoment(val.end)) {
return null;
}
return new Error('Value must be a moment or a moment range');
}
value: CustomPropTypes.momentOrMomentRange
},

getDefaultProps() {
Expand Down Expand Up @@ -252,11 +242,11 @@ const DateRangePicker = React.createClass({
}
},

onUnHighlightDate(date) {
onUnHighlightDate() {
this.setState({
highlightedDate: null
});
},
},

onSelectDate(date) {
let {selectionType} = this.props;
Expand Down Expand Up @@ -298,7 +288,7 @@ const DateRangePicker = React.createClass({
this.highlightDate(date);
}
}
},
},

startRangeSelection(date) {
this.setState({
Expand Down Expand Up @@ -448,8 +438,7 @@ const DateRangePicker = React.createClass({
enabledRange,
hideSelection,
highlightedDate,
highlightedRange,
highlightStartDate
highlightedRange
} = this.state;

let monthDate = this.getMonthDate();
Expand All @@ -473,7 +462,7 @@ const DateRangePicker = React.createClass({
} else if (isMomentRange(value)) {
if (!monthRange.overlaps(value)) {
value = null;
}
}
}

if (!moment.isMoment(highlightedDate) || !monthRange.contains(highlightedDate)) {
Expand All @@ -482,7 +471,7 @@ const DateRangePicker = React.createClass({

if (!isMomentRange(highlightedRange) || !monthRange.overlaps(highlightedRange)) {
highlightedRange = null;
}
}

props = {
bemBlock,
Expand Down
4 changes: 2 additions & 2 deletions src/calendar/CalendarDate.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

import React from 'react/addons';

import moment from 'moment-range';
import Immutable from 'immutable';

import BemMixin from '../utils/BemMixin';
import CustomPropTypes from '../utils/CustomPropTypes';
import PureRenderMixin from '../utils/PureRenderMixin';
import lightenDarkenColor from '../utils/lightenDarkenColor';

Expand All @@ -18,7 +18,7 @@ const CalendarDate = React.createClass({
mixins: [BemMixin, PureRenderMixin],

propTypes: {
date: React.PropTypes.object.isRequired,
date: CustomPropTypes.moment,

firstOfMonth: React.PropTypes.object.isRequired,

Expand Down
7 changes: 6 additions & 1 deletion src/calendar/CalendarDatePeriod.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,18 @@ import PureRenderMixin from '../utils/PureRenderMixin';
const CalendarDatePeriod = React.createClass({
mixins: [BemMixin, PureRenderMixin],

propTypes: {
color: React.PropTypes.string,
period: React.PropTypes.string
},

render() {
let {color, period} = this.props;
let modifiers = {[period]: true};
let style;

if (color) {
style= {backgroundColor: color};
style = {backgroundColor: color};
}

return (
Expand Down
4 changes: 4 additions & 0 deletions src/calendar/CalendarHighlight.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ import PureRenderMixin from '../utils/PureRenderMixin';
const CalendarHighlight = React.createClass({
mixins: [BemMixin, PureRenderMixin],

propTypes: {
modifier: React.PropTypes.string
},

render() {
let {modifier} = this.props;
let modifiers = {[modifier]: true};
Expand Down
Loading

0 comments on commit 69a717f

Please sign in to comment.