From 1db8cfc2ac99368f461070e21586ae7240086965 Mon Sep 17 00:00:00 2001 From: Olivier Tassinari Date: Tue, 15 Sep 2015 22:44:19 +0100 Subject: [PATCH] [DatePicker] add proporty needed for Intl --- .../pages/components/date-picker.jsx | 21 ++++ src/date-picker/calendar-toolbar.jsx | 13 +- src/date-picker/calendar.jsx | 10 ++ src/date-picker/date-display.jsx | 8 +- src/date-picker/date-picker-dialog.jsx | 24 +++- src/date-picker/date-picker.jsx | 9 ++ src/utils/date-time.js | 119 ++---------------- 7 files changed, 88 insertions(+), 116 deletions(-) diff --git a/docs/src/app/components/pages/components/date-picker.jsx b/docs/src/app/components/pages/components/date-picker.jsx index ea8ff269571d3a..abf7f4384d233a 100644 --- a/docs/src/app/components/pages/components/date-picker.jsx +++ b/docs/src/app/components/pages/components/date-picker.jsx @@ -29,6 +29,27 @@ export default class DatePickerPage extends React.Component { { name: 'Props', infoArray: [ + { + name: 'DateTimeFormat', + type: 'func', + header: 'default: custom one that only support en-US locale', + desc: 'Constructor for time formatting. Follow this specificaction: ' + + 'ECMAScript Internationalization API 1.0 (ECMA-402).', + }, + { + name: 'locale', + type: 'string', + header: 'default: en-US', + desc: 'Locale used for formating date. If you are not using the default value, ' + + 'you have to provide a DateTimeFormat that support it. You can use Intl.DateTimeFormat' + + ' if it\'s supported by your environment. https://github.com/andyearnshaw/Intl.js is a good polyfill.', + }, + { + name: 'wording', + type: 'object', + header: 'default: {ok: \'OK\', cancel: \'Cancel\' }', + desc: 'Wording used inside the button of the dialog.', + }, { name: 'autoOk', type: 'bool', diff --git a/src/date-picker/calendar-toolbar.jsx b/src/date-picker/calendar-toolbar.jsx index 4c7edaec797342..4c77da739a1b3b 100644 --- a/src/date-picker/calendar-toolbar.jsx +++ b/src/date-picker/calendar-toolbar.jsx @@ -1,5 +1,4 @@ const React = require('react'); -const DateTime = require('../utils/date-time'); const IconButton = require('../icon-button'); const Toolbar = require('../toolbar/toolbar'); const ToolbarGroup = require('../toolbar/toolbar-group'); @@ -44,6 +43,8 @@ const CalendarToolbar = React.createClass({ }, propTypes: { + DateTimeFormat: React.PropTypes.func.isRequired, + locale: React.PropTypes.string.isRequired, displayDate: React.PropTypes.object.isRequired, nextMonth: React.PropTypes.bool, onMonthChange: React.PropTypes.func, @@ -81,10 +82,16 @@ const CalendarToolbar = React.createClass({ }, render() { - const dateTimeFormated = new DateTime.DateTimeFormat('en-US', { + const { + DateTimeFormat, + locale, + displayDate, + } = this.props + + const dateTimeFormated = new DateTimeFormat(locale, { month: 'long', year: 'numeric', - }).format(this.props.displayDate); + }).format(displayDate); const nextButtonIcon = this.state.muiTheme.isRtl ? : ; const prevButtonIcon = this.state.muiTheme.isRtl ? : ; diff --git a/src/date-picker/calendar.jsx b/src/date-picker/calendar.jsx index 7288ae25b1a6e6..f554ac4176a271 100644 --- a/src/date-picker/calendar.jsx +++ b/src/date-picker/calendar.jsx @@ -34,6 +34,8 @@ const Calendar = React.createClass({ }, propTypes: { + DateTimeFormat: React.PropTypes.func.isRequired, + locale: React.PropTypes.string.isRequired, disableYearSelection: React.PropTypes.bool, initialDate: React.PropTypes.object, isActive: React.PropTypes.bool, @@ -133,10 +135,16 @@ const Calendar = React.createClass({ }; const weekTitleDayStyle = this.prepareStyles(styles.weekTitleDay); + const { + DateTimeFormat, + locale, + } = this.props; return ( , @@ -123,7 +141,7 @@ const DatePickerDialog = React.createClass({ actions.push(