Skip to content

Commit 336acee

Browse files
committed
release v2.6.1
1 parent 3c373ee commit 336acee

36 files changed

+436
-295
lines changed

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.6.0",
3+
"version": "2.6.1",
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: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/Calendar.js

Lines changed: 14 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ var React = require('react'),
1313
Year = require('./Year'),
1414
Decade = require('./Decade'),
1515
Century = require('./Century'),
16+
localizers = require('./util/configuration').locale,
1617
CustomPropTypes = require('./util/propTypes'),
1718
createUncontrolledWidget = require('uncontrollable'),
1819
SlideTransition = require('./SlideTransition'),
@@ -52,6 +53,10 @@ var MULTIPLIER = (_MULTIPLIER = {}, _MULTIPLIER[views.YEAR] = 1, _MULTIPLIER[vie
5253

5354
var VIEW_FORMATS = (_VIEW_FORMATS = {}, _VIEW_FORMATS[views.MONTH] = 'dateFormat', _VIEW_FORMATS[views.YEAR] = 'monthFormat', _VIEW_FORMATS[views.DECADE] = 'yearFormat', _VIEW_FORMATS[views.CENTURY] = 'decadeFormat', _VIEW_FORMATS);
5455

56+
var format = function format(props, f) {
57+
return props[f + 'Format'] || localizers.date.formats[f];
58+
};
59+
5560
var propTypes = {
5661

5762
onChange: React.PropTypes.func,
@@ -77,15 +82,15 @@ var propTypes = {
7782

7883
footer: React.PropTypes.bool,
7984

80-
headerFormat: CustomPropTypes.localeFormat,
81-
footerFormat: CustomPropTypes.localeFormat,
85+
headerFormat: CustomPropTypes.dateFormat,
86+
footerFormat: CustomPropTypes.dateFormat,
8287

83-
dayFormat: CustomPropTypes.localeFormat,
84-
dateFormat: CustomPropTypes.localeFormat,
85-
monthFormat: CustomPropTypes.localeFormat,
86-
yearFormat: CustomPropTypes.localeFormat,
87-
decadeFormat: CustomPropTypes.localeFormat,
88-
centuryFormat: CustomPropTypes.localeFormat,
88+
dayFormat: CustomPropTypes.dateFormat,
89+
dateFormat: CustomPropTypes.dateFormat,
90+
monthFormat: CustomPropTypes.dateFormat,
91+
yearFormat: CustomPropTypes.dateFormat,
92+
decadeFormat: CustomPropTypes.dateFormat,
93+
centuryFormat: CustomPropTypes.dateFormat,
8994

9095
messages: React.PropTypes.shape({
9196
moveBack: React.PropTypes.string,
@@ -123,22 +128,6 @@ var Calendar = React.createClass({
123128
tabIndex: '0',
124129
footer: false,
125130

126-
headerFormat: dates.formats.MONTH_YEAR,
127-
footerFormat: dates.formats.FOOTER,
128-
129-
dayFormat: dates.shortDay,
130-
dateFormat: dates.formats.DAY_OF_MONTH,
131-
monthFormat: dates.formats.MONTH_NAME_ABRV,
132-
yearFormat: dates.formats.YEAR,
133-
134-
decadeFormat: function decadeFormat(dt, culture) {
135-
return '' + dates.format(dt, dates.formats.YEAR, culture) + ' - ' + dates.format(dates.endOf(dt, 'decade'), dates.formats.YEAR, culture);
136-
},
137-
138-
centuryFormat: function centuryFormat(dt, culture) {
139-
return '' + dates.format(dt, dates.formats.YEAR, culture) + ' - ' + dates.format(dates.endOf(dt, 'century'), dates.formats.YEAR, culture);
140-
},
141-
142131
messages: msgs({})
143132
};
144133
},
@@ -346,7 +335,7 @@ var Calendar = React.createClass({
346335
var view = this.state.view;
347336
var dt = this.state.currentDate;
348337

349-
if (view === 'month') return dates.format(dt, props.headerFormat, culture);else if (view === 'year') return dates.format(dt, props.yearFormat, culture);else if (view === 'decade') return dates.format(dates.startOf(dt, 'decade'), props.decadeFormat, culture);else if (view === 'century') return dates.format(dates.startOf(dt, 'century'), props.centuryFormat, culture);
338+
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(dates.startOf(dt, 'decade'), format(props, 'decade'), culture);else if (view === 'century') return localizers.date.format(dates.startOf(dt, 'century'), format(props, 'century'), culture);
350339
},
351340

352341
inRangeValue: function inRangeValue(_value) {
@@ -377,22 +366,6 @@ function msgs(msgs) {
377366
moveForward: 'navigate forward' }, msgs);
378367
}
379368

380-
function formats(obj) {
381-
return babelHelpers._extends({
382-
headerFormat: dates.formats.MONTH_YEAR,
383-
dateFormat: dates.formats.DAY_OF_MONTH,
384-
monthFormat: dates.formats.MONTH_NAME_ABRV,
385-
yearFormat: dates.formats.YEAR,
386-
387-
decadeFormat: function decadeFormat(dt, culture) {
388-
return '' + dates.format(dt, dates.formats.YEAR, culture) + ' - ' + dates.format(dates.endOf(dt, 'decade'), dates.formats.YEAR, culture);
389-
},
390-
391-
centuryFormat: function centuryFormat(dt, culture) {
392-
return '' + dates.format(dt, dates.formats.YEAR, culture) + ' - ' + dates.format(dates.endOf(dt, 'century'), dates.formats.YEAR, culture);
393-
} }, obj);
394-
}
395-
396369
module.exports = createUncontrolledWidget(Calendar, { value: 'onChange' });
397370

398371
module.exports.BaseCalendar = Calendar;

lib/Century.js

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,16 @@ var babelHelpers = require('./util/babelHelpers.js');
55
var React = require('react'),
66
cx = require('classnames'),
77
dates = require('./util/dates'),
8+
localizers = require('./util/configuration').locale,
89
directions = require('./util/constants').directions,
910
Btn = require('./WidgetButton'),
1011
_ = require('./util/_'),
1112
CustomPropTypes = require('./util/propTypes'); //omit
1213

14+
var format = function format(props) {
15+
return props.decadeFormat || localizers.date.formats.decade;
16+
};
17+
1318
module.exports = React.createClass({
1419

1520
displayName: 'CenturyView',
@@ -24,7 +29,7 @@ module.exports = React.createClass({
2429

2530
onChange: React.PropTypes.func.isRequired,
2631

27-
decadeFormat: CustomPropTypes.localeFormat.isRequired
32+
decadeFormat: CustomPropTypes.dateFormat
2833
},
2934

3035
render: function render() {
@@ -81,7 +86,7 @@ module.exports = React.createClass({
8186
'rw-state-selected': selected,
8287
'rw-now': currentDecade
8388
}) },
84-
dates.format(dates.startOf(date, 'decade'), _this.props.decadeFormat, _this.props.culture)
89+
localizers.date.format(dates.startOf(date, 'decade'), format(_this.props), _this.props.culture)
8590
)
8691
);
8792
})
@@ -90,10 +95,6 @@ module.exports = React.createClass({
9095

9196
});
9297

93-
function label(date, format, culture) {
94-
return dates.format(dates.startOf(date, 'decade'), format, culture) + ' - ' + dates.format(dates.endOf(date, 'decade'), format, culture);
95-
}
96-
9798
function inRangeDate(decade, min, max) {
9899
return dates.max(dates.min(decade, max), min);
99100
}

lib/DateInput.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,16 @@ var React = require('react'),
66
cx = require('classnames'),
77
dates = require('./util/dates'),
88
compat = require('./util/compat'),
9+
localizers = require('./util/configuration').locale,
910
CustomPropTypes = require('./util/propTypes');
1011

1112
module.exports = React.createClass({
1213

1314
displayName: 'DatePickerInput',
1415

1516
propTypes: {
16-
format: CustomPropTypes.localeFormat,
17+
format: CustomPropTypes.dateFormat.isRequired,
18+
editFormat: CustomPropTypes.dateFormat,
1719
parse: React.PropTypes.func.isRequired,
1820

1921
value: React.PropTypes.instanceOf(Date),
@@ -88,7 +90,7 @@ function isValid(d) {
8890
function formatDate(date, format, culture) {
8991
var val = '';
9092

91-
if (date instanceof Date && isValid(date)) val = dates.format(date, format, culture);
93+
if (date instanceof Date && isValid(date)) val = localizers.date.format(date, format, culture);
9294

9395
return val;
9496
}

lib/DateTimePicker.js

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ var React = require('react'),
1111

1212
,
1313
dates = require('./util/dates'),
14+
localizers = require('./util/configuration').locale,
1415
views = require('./util/constants').calendarViews,
1516
popups = require('./util/constants').datePopups,
1617
Popup = require('./Popup'),
@@ -41,8 +42,9 @@ var propTypes = babelHelpers._extends({}, compat.type(Calendar).propTypes, {
4142

4243
culture: React.PropTypes.string,
4344

44-
format: CustomPropTypes.localeFormat,
45-
editFormat: CustomPropTypes.localeFormat,
45+
format: CustomPropTypes.dateFormat,
46+
timeFormat: CustomPropTypes.dateFormat,
47+
editFormat: CustomPropTypes.dateFormat,
4648

4749
calendar: React.PropTypes.bool,
4850
time: React.PropTypes.bool,
@@ -210,6 +212,7 @@ var DateTimePicker = React.createClass({
210212
optID: timeOptID,
211213
'aria-hidden': !this.props.open,
212214
value: value,
215+
format: this.props.timeFormat,
213216
step: this.props.step,
214217
min: this.props.min,
215218
max: this.props.max,
@@ -363,13 +366,13 @@ function getFormat(props) {
363366
var cal = props[popups.CALENDAR] != null ? props.calendar : true,
364367
time = props[popups.TIME] != null ? props.time : true;
365368

366-
return props.format ? props.format : cal && time || !cal && !time ? 'f' : cal ? 'd' : 't';
369+
return props.format ? props.format : cal && time || !cal && !time ? localizers.date.formats['default'] : localizers.date.formats[cal ? 'date' : 'time'];
367370
}
368371

369372
function formatDate(date, format, culture) {
370373
var val = '';
371374

372-
if (date instanceof Date && !isNaN(date.getTime())) val = dates.format(date, format, culture);
375+
if (date instanceof Date && !isNaN(date.getTime())) val = localizers.date.format(date, format, culture);
373376

374377
return val;
375378
}
@@ -378,7 +381,7 @@ function formatsParser(formats, culture, str) {
378381
var date;
379382

380383
for (var i = 0; i < formats.length; i++) {
381-
date = dates.parse(str, formats[i], culture);
384+
date = localizers.date.parse(str, formats[i], culture);
382385
if (date) return date;
383386
}
384387
return null;

lib/Decade.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,14 @@ var React = require('react'),
66
_ = require('./util/_'),
77
cx = require('classnames'),
88
dates = require('./util/dates'),
9+
localizers = require('./util/configuration').locale,
910
CustomPropTypes = require('./util/propTypes'),
1011
Btn = require('./WidgetButton');
1112

13+
var format = function format(props) {
14+
return props.yearFormat || localizers.date.formats.year;
15+
};
16+
1217
module.exports = React.createClass({
1318

1419
displayName: 'DecadeView',
@@ -24,7 +29,7 @@ module.exports = React.createClass({
2429
max: React.PropTypes.instanceOf(Date),
2530
onChange: React.PropTypes.func.isRequired,
2631

27-
yearFormat: CustomPropTypes.localeFormat.isRequired
32+
yearFormat: CustomPropTypes.dateFormat
2833

2934
},
3035

@@ -80,7 +85,7 @@ module.exports = React.createClass({
8085
'rw-state-selected': selected,
8186
'rw-now': currentYear
8287
}) },
83-
dates.format(date, _this.props.yearFormat, _this.props.culture)
88+
localizers.date.format(date, format(_this.props), _this.props.culture)
8489
)
8590
);
8691
})
@@ -96,7 +101,7 @@ function getDecadeYears(_date) {
96101
var days = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12],
97102
date = dates.add(dates.startOf(_date, 'decade'), -2, 'year');
98103

99-
return days.map(function (i) {
104+
return days.map(function () {
100105
return date = dates.add(date, 1, 'year');
101106
});
102107
}

lib/DropdownList.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,7 @@ var DropdownList = React.createClass({
249249
key = e.key,
250250
alt = e.altKey,
251251
list = this.refs.list,
252+
filtering = this.props.filter,
252253
focusedItem = this.state.focusedItem,
253254
selectedItem = this.state.selectedItem,
254255
isOpen = this.props.open,
@@ -264,7 +265,7 @@ var DropdownList = React.createClass({
264265
e.preventDefault();
265266
} else if (key === 'Escape' && isOpen) {
266267
closeWithFocus();
267-
} else if ((key === 'Enter' || key === ' ') && isOpen) {
268+
} else if ((key === 'Enter' || key === ' ' && !filtering) && isOpen) {
268269
change(this.state.focusedItem, true);
269270
} else if (key === 'ArrowDown') {
270271
if (alt) this.open();else if (isOpen) this.setState({ focusedItem: list.next(focusedItem) });else change(list.next(selectedItem));

lib/Footer.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,20 @@
22

33
var React = require('react'),
44
Btn = require('./WidgetButton'),
5-
dates = require('./util/dates');
5+
dates = require('./util/dates'),
6+
localizers = require('./util/configuration').locale;
7+
8+
var format = function format(props) {
9+
return props.format || localizers.date.formats.footer;
10+
};
611

712
module.exports = React.createClass({
813

914
displayName: 'Footer',
1015

1116
render: function render() {
1217
var now = this.props.value,
13-
formatted = dates.format(now, this.props.format, this.props.culture);
18+
formatted = localizers.date.format(now, format(this.props), this.props.culture);
1419

1520
return React.createElement(
1621
'div',

lib/Month.js

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,18 @@ var babelHelpers = require('./util/babelHelpers.js');
55
var React = require('react'),
66
cx = require('classnames'),
77
dates = require('./util/dates'),
8+
localizers = require('./util/configuration').locale,
89
CustomPropTypes = require('./util/propTypes'),
910
_ = require('./util/_'),
1011
Btn = require('./WidgetButton');
1112

13+
var dayFormat = function dayFormat(props) {
14+
return props.dayFormat || localizers.date.formats.weekday;
15+
},
16+
dateFormat = function dateFormat(props) {
17+
return props.dateFormat || localizers.date.formats.dayOfMonth;
18+
};
19+
1220
module.exports = React.createClass({
1321

1422
displayName: 'MonthView',
@@ -22,8 +30,8 @@ module.exports = React.createClass({
2230
min: React.PropTypes.instanceOf(Date),
2331
max: React.PropTypes.instanceOf(Date),
2432

25-
dayFormat: CustomPropTypes.localeFormat.isRequired,
26-
dateFormat: CustomPropTypes.localeFormat.isRequired,
33+
dayFormat: CustomPropTypes.dateFormat,
34+
dateFormat: CustomPropTypes.dateFormat,
2735

2836
onChange: React.PropTypes.func.isRequired },
2937

@@ -44,7 +52,7 @@ module.exports = React.createClass({
4452
React.createElement(
4553
'tr',
4654
null,
47-
this._headers(props.dayFormat, props.culture)
55+
this._headers(dayFormat(this.props), props.culture)
4856
)
4957
),
5058
React.createElement(
@@ -90,7 +98,7 @@ module.exports = React.createClass({
9098
'rw-now': today
9199
}),
92100
id: focused ? id : undefined },
93-
dates.format(day, _this.props.dateFormat, _this.props.culture)
101+
localizers.date.format(day, dateFormat(_this.props), _this.props.culture)
94102
)
95103
);
96104
})
@@ -102,7 +110,7 @@ module.exports = React.createClass({
102110
return React.createElement(
103111
'th',
104112
{ key: 'header_' + day },
105-
dates.format(day, format, culture)
113+
localizers.date.format(day, format, culture)
106114
);
107115
});
108116
}

0 commit comments

Comments
 (0)