Skip to content

Commit 3c1b266

Browse files
committed
2.8.1
1 parent 098ddbe commit 3c1b266

39 files changed

Lines changed: 1762 additions & 1217 deletions

bower.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-widgets",
3-
"version": "2.7.4",
3+
"version": "2.8.0",
44
"main": "dist/react-widgets.js",
55
"description": "A set of input widgets for React",
66
"homepage": "http://jquense.github.io/react-widgets/docs",

dist/react-widgets.js

Lines changed: 5 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/Calendar.js

Lines changed: 98 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,10 @@ var _util_2 = babelHelpers.interopRequireDefault(_util_);
7272

7373
//values, omit
7474

75+
var _utilWidgetHelpers = require('./util/widgetHelpers');
76+
77+
var _utilInteraction = require('./util/interaction');
78+
7579
var dir = _utilConstants2['default'].directions,
7680
values = function values(obj) {
7781
return Object.keys(obj).map(function (k) {
@@ -109,6 +113,9 @@ var format = function format(props, f) {
109113

110114
var propTypes = {
111115

116+
disabled: _utilPropTypes2['default'].disabled,
117+
readOnly: _utilPropTypes2['default'].readOnly,
118+
112119
onChange: _react2['default'].PropTypes.func,
113120
value: _react2['default'].PropTypes.instanceOf(Date),
114121

@@ -124,10 +131,6 @@ var propTypes = {
124131
if (VIEW_OPTIONS.indexOf(props[propname]) < VIEW_OPTIONS.indexOf(props.initialView)) return new Error(('The `' + propname + '` prop: `' + props[propname] + '` cannot be \'lower\' than the `initialView`\n prop. This creates a range that cannot be rendered.').replace(/\n\t/g, ''));
125132
},
126133

127-
disabled: _react2['default'].PropTypes.oneOfType([_react2['default'].PropTypes.bool, _react2['default'].PropTypes.oneOf(['disabled'])]),
128-
129-
readOnly: _react2['default'].PropTypes.oneOfType([_react2['default'].PropTypes.bool, _react2['default'].PropTypes.oneOf(['readOnly'])]),
130-
131134
culture: _react2['default'].PropTypes.string,
132135

133136
footer: _react2['default'].PropTypes.bool,
@@ -149,25 +152,35 @@ var propTypes = {
149152
})
150153
};
151154

152-
var Calendar = _react2['default'].createClass({
153-
154-
displayName: 'Calendar',
155-
156-
mixins: [require('./mixins/WidgetMixin'), require('./mixins/TimeoutMixin'), require('./mixins/PureRenderMixin'), require('./mixins/RtlParentContextMixin'), require('./mixins/AriaDescendantMixin')()],
157-
158-
propTypes: propTypes,
159-
160-
getInitialState: function getInitialState() {
155+
var Calendar = _react2['default'].createClass(babelHelpers.createDecoratedObject([{
156+
key: 'displayName',
157+
initializer: function initializer() {
158+
return 'Calendar';
159+
}
160+
}, {
161+
key: 'mixins',
162+
initializer: function initializer() {
163+
return [require('./mixins/TimeoutMixin'), require('./mixins/PureRenderMixin'), require('./mixins/RtlParentContextMixin'), require('./mixins/AriaDescendantMixin')()];
164+
}
165+
}, {
166+
key: 'propTypes',
167+
initializer: function initializer() {
168+
return propTypes;
169+
}
170+
}, {
171+
key: 'getInitialState',
172+
value: function getInitialState() {
161173
var value = this.inRangeValue(this.props.value);
162174

163175
return {
164176
selectedIndex: 0,
165177
view: this.props.initialView || 'month',
166178
currentDate: value ? new Date(value) : this.inRangeValue(new Date())
167179
};
168-
},
169-
170-
getDefaultProps: function getDefaultProps() {
180+
}
181+
}, {
182+
key: 'getDefaultProps',
183+
value: function getDefaultProps() {
171184
return {
172185

173186
value: null,
@@ -183,9 +196,10 @@ var Calendar = _react2['default'].createClass({
183196
ariaActiveDescendantKey: 'calendar',
184197
messages: msgs({})
185198
};
186-
},
187-
188-
componentWillReceiveProps: function componentWillReceiveProps(nextProps) {
199+
}
200+
}, {
201+
key: 'componentWillReceiveProps',
202+
value: function componentWillReceiveProps(nextProps) {
189203
var bottom = VIEW_OPTIONS.indexOf(nextProps.initialView),
190204
top = VIEW_OPTIONS.indexOf(nextProps.finalView),
191205
current = VIEW_OPTIONS.indexOf(this.state.view),
@@ -198,9 +212,10 @@ var Calendar = _react2['default'].createClass({
198212
if (!_utilDates2['default'].eq(val, dateOrNull(this.props.value), VIEW_UNIT[view])) this.setState({
199213
currentDate: val ? new Date(val) : new Date()
200214
});
201-
},
202-
203-
render: function render() {
215+
}
216+
}, {
217+
key: 'render',
218+
value: function render() {
204219
var _this = this;
205220

206221
var _props = this.props;
@@ -229,8 +244,8 @@ var Calendar = _react2['default'].createClass({
229244

230245
unit = unit === 'day' ? 'date' : unit;
231246

232-
var viewID = this._id('_calendar'),
233-
labelID = this._id('_calendar_label'),
247+
var viewID = _utilWidgetHelpers.instanceId(this, '_calendar'),
248+
labelID = _utilWidgetHelpers.instanceId(this, '_calendar_label'),
234249
key = view + '_' + _utilDates2['default'][view](currentDate);
235250

236251
var elementProps = _util_2['default'].omit(this.props, Object.keys(propTypes)),
@@ -247,7 +262,7 @@ var Calendar = _react2['default'].createClass({
247262
onKeyDown: this._keyDown,
248263
onFocus: this._focus.bind(null, true),
249264
onBlur: this._focus.bind(null, false),
250-
className: (0, _classnames2['default'])(className, 'rw-calendar', 'rw-widget', {
265+
className: _classnames2['default'](className, 'rw-calendar', 'rw-widget', {
251266
'rw-state-focus': focused,
252267
'rw-state-disabled': disabled,
253268
'rw-state-readonly': readOnly,
@@ -284,7 +299,7 @@ var Calendar = _react2['default'].createClass({
284299
today: todaysDate,
285300
value: value,
286301
focused: currentDate,
287-
onChange: this._maybeHandle(this.change),
302+
onChange: this.change,
288303
onKeyDown: this._keyDown,
289304
ariaActiveDescendantKey: 'calendarView'
290305
}))
@@ -295,12 +310,14 @@ var Calendar = _react2['default'].createClass({
295310
culture: culture,
296311
disabled: disabled || todayNotInRange,
297312
readOnly: readOnly,
298-
onClick: this._maybeHandle(this.select)
313+
onClick: this.select
299314
})
300315
);
301-
},
302-
303-
navigate: _util_2['default'].ifNotDisabled(function (direction, date) {
316+
}
317+
}, {
318+
key: 'navigate',
319+
decorators: [_utilInteraction.widgetEditable],
320+
value: function navigate(direction, date) {
304321
var view = this.state.view,
305322
slideDir = direction === dir.LEFT || direction === dir.UP ? 'right' : 'left';
306323

@@ -311,7 +328,7 @@ var Calendar = _react2['default'].createClass({
311328
if (direction === dir.UP) view = NEXT_VIEW[view] || view;
312329

313330
if (this.isValidView(view) && _utilDates2['default'].inRange(date, this.props.min, this.props.max, view)) {
314-
this.notify('onNavigate', [date, slideDir, view]);
331+
_utilWidgetHelpers.notify(this.props.onNavigate, [date, slideDir, view]);
315332
this.focus(true);
316333

317334
this.setState({
@@ -320,41 +337,50 @@ var Calendar = _react2['default'].createClass({
320337
view: view
321338
});
322339
}
323-
}),
324-
325-
focus: function focus() {
340+
}
341+
}, {
342+
key: 'focus',
343+
value: function focus() {
326344
if (+this.props.tabIndex > -1) _utilCompat2['default'].findDOMNode(this).focus();
327-
},
328345

329-
_focus: _util_2['default'].ifNotDisabled(true, function (focused, e) {
346+
//console.log(document.activeElement)
347+
}
348+
}, {
349+
key: '_focus',
350+
decorators: [_utilInteraction.widgetEnabled],
351+
value: function _focus(focused, e) {
330352
var _this2 = this;
331353

332354
if (+this.props.tabIndex === -1) return;
333355

334356
this.setTimeout('focus', function () {
335357
if (focused !== _this2.state.focused) {
336-
_this2.notify(focused ? 'onFocus' : 'onBlur', e);
358+
_utilWidgetHelpers.notify(_this2.props[focused ? 'onFocus' : 'onBlur'], e);
337359
_this2.setState({ focused: focused });
338360
}
339361
});
340-
}),
341-
342-
change: function change(date) {
362+
}
363+
}, {
364+
key: 'change',
365+
decorators: [_utilInteraction.widgetEditable],
366+
value: function change(date) {
343367
if (this.state.view === this.props.initialView) {
344-
this.notify('onChange', date);
368+
_utilWidgetHelpers.notify(this.props.onChange, date);
345369
this.focus();
346370
return;
347371
}
348372

349373
this.navigate(dir.DOWN, date);
350-
},
351-
352-
select: function select(date) {
374+
}
375+
}, {
376+
key: 'select',
377+
decorators: [_utilInteraction.widgetEditable],
378+
value: function select(date) {
353379
var view = this.props.initialView,
354380
slideDir = view !== this.state.view || _utilDates2['default'].gt(date, this.state.currentDate) ? 'left' // move down to a the view
355381
: 'right';
356382

357-
this.notify('onChange', date);
383+
_utilWidgetHelpers.notify(this.props.onChange, date);
358384

359385
if (this.isValidView(view) && _utilDates2['default'].inRange(date, this.props.min, this.props.max, view)) {
360386
this.focus();
@@ -365,18 +391,21 @@ var Calendar = _react2['default'].createClass({
365391
view: view
366392
});
367393
}
368-
},
369-
370-
nextDate: function nextDate(direction) {
394+
}
395+
}, {
396+
key: 'nextDate',
397+
value: function nextDate(direction) {
371398
var method = direction === dir.LEFT ? 'subtract' : 'add',
372399
view = this.state.view,
373400
unit = view === views.MONTH ? view : views.YEAR,
374401
multi = MULTIPLIER[view] || 1;
375402

376403
return _utilDates2['default'][method](this.state.currentDate, 1 * multi, unit);
377-
},
378-
379-
_keyDown: _util_2['default'].ifNotDisabled(function (e) {
404+
}
405+
}, {
406+
key: '_keyDown',
407+
decorators: [_utilInteraction.widgetEditable],
408+
value: function _keyDown(e) {
380409
var ctrl = e.ctrlKey,
381410
key = e.key,
382411
direction = ARROWS_TO_DIRECTION[key],
@@ -407,35 +436,38 @@ var Calendar = _react2['default'].createClass({
407436
}
408437
}
409438

410-
this.notify('onKeyDown', [e]);
411-
}),
412-
413-
_label: function _label() {
439+
_utilWidgetHelpers.notify(this.props.onKeyDown, [e]);
440+
}
441+
}, {
442+
key: '_label',
443+
value: function _label() {
414444
var _props2 = this.props;
415445
var culture = _props2.culture;
416446
var props = babelHelpers.objectWithoutProperties(_props2, ['culture']);
417447
var view = this.state.view;
418448
var dt = this.state.currentDate;
419449

420450
if (view === 'month') return localizers.date.format(dt, format(props, 'header'), culture);else if (view === 'year') return localizers.date.format(dt, format(props, 'year'), culture);else if (view === 'decade') return localizers.date.format(_utilDates2['default'].startOf(dt, 'decade'), format(props, 'decade'), culture);else if (view === 'century') return localizers.date.format(_utilDates2['default'].startOf(dt, 'century'), format(props, 'century'), culture);
421-
},
422-
423-
inRangeValue: function inRangeValue(_value) {
451+
}
452+
}, {
453+
key: 'inRangeValue',
454+
value: function inRangeValue(_value) {
424455
var value = dateOrNull(_value);
425456

426457
if (value === null) return value;
427458

428459
return _utilDates2['default'].max(_utilDates2['default'].min(value, this.props.max), this.props.min);
429-
},
430-
431-
isValidView: function isValidView(next) {
460+
}
461+
}, {
462+
key: 'isValidView',
463+
value: function isValidView(next) {
432464
var bottom = VIEW_OPTIONS.indexOf(this.props.initialView),
433465
top = VIEW_OPTIONS.indexOf(this.props.finalView),
434466
current = VIEW_OPTIONS.indexOf(next);
435467

436468
return current >= bottom && current <= top;
437469
}
438-
});
470+
}]));
439471

440472
function dateOrNull(dt) {
441473
if (dt && !isNaN(dt.getTime())) return dt;
@@ -445,13 +477,13 @@ function dateOrNull(dt) {
445477
function msgs(msgs) {
446478
return babelHelpers._extends({
447479
moveBack: 'navigate back',
448-
moveForward: 'navigate forward' }, msgs);
480+
moveForward: 'navigate forward'
481+
}, msgs);
449482
}
450483

451-
var UncontrolledCalendar = (0, _uncontrollable2['default'])(Calendar, { value: 'onChange' });
484+
var UncontrolledCalendar = _uncontrollable2['default'](Calendar, { value: 'onChange' });
452485

453486
UncontrolledCalendar.BaseCalendar = Calendar;
454487

455488
exports['default'] = UncontrolledCalendar;
456-
module.exports = exports['default'];
457-
//console.log(document.activeElement)
489+
module.exports = exports['default'];

0 commit comments

Comments
 (0)