Skip to content

Commit

Permalink
[DatePicker] add example with fr
Browse files Browse the repository at this point in the history
  • Loading branch information
oliviertassinari committed Oct 23, 2015
1 parent 1db8cfc commit 9c59bba
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 12 deletions.
17 changes: 12 additions & 5 deletions docs/src/app/components/pages/components/date-picker.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,23 +32,23 @@ export default class DatePickerPage extends React.Component {
{
name: 'DateTimeFormat',
type: 'func',
header: 'default: custom one that only support en-US locale',
header: 'default: custom function defined inside utils/date-time.js that only supports 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' +
desc: 'Locale used for formatting date. If you are not using the default value, ' +
'you have to provide a DateTimeFormat that supports 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',
name: 'wordings',
type: 'object',
header: 'default: {ok: \'OK\', cancel: \'Cancel\' }',
desc: 'Wording used inside the button of the dialog.',
desc: 'Wordings used inside the button of the dialog.',
},
{
name: 'autoOk',
Expand Down Expand Up @@ -216,6 +216,13 @@ export default class DatePickerPage extends React.Component {
maxDate={this.state.maxDate}
showYearSelector={this.state.showYearSelector} />

<DatePicker
hintText="fr version"
DateTimeFormat={Intl.DateTimeFormat}
// Intl is defined by the browser see http://caniuse.com/#search=intl
wordings={{ok: 'OK', cancel: 'Annuler'}}
locale="fr" />

<div style={optionsStyle}>
<TextField
floatingLabelText="Min Date"
Expand Down
7 changes: 7 additions & 0 deletions docs/src/app/components/raw-code/date-picker-code.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,10 @@
minDate={this.state.minDate}
maxDate={this.state.maxDate}
showYearSelector={this.state.showYearSelector} />

<DatePicker
hintText="fr version"
// Intl is defined by the browser see http://caniuse.com/#search=intl
DateTimeFormat={Intl.DateTimeFormat}
wordings={{ok: 'OK', cancel: 'Annuler'}}
locale="fr" />
4 changes: 2 additions & 2 deletions src/date-picker/calendar-toolbar.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ const CalendarToolbar = React.createClass({
displayDate,
} = this.props

const dateTimeFormated = new DateTimeFormat(locale, {
const dateTimeFormatted = new DateTimeFormat(locale, {
month: 'long',
year: 'numeric',
}).format(displayDate);
Expand All @@ -101,7 +101,7 @@ const CalendarToolbar = React.createClass({
<SlideInTransitionGroup
style={styles.title}
direction={this.state.transitionDirection}>
<div key={dateTimeFormated}>{dateTimeFormated}</div>
<div key={dateTimeFormatted}>{dateTimeFormatted}</div>
</SlideInTransitionGroup>

<ToolbarGroup key={0} float="left">
Expand Down
6 changes: 3 additions & 3 deletions src/date-picker/date-display.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ const DateDisplay = React.createClass({
const year = this.props.selectedDate.getFullYear();
const styles = this.getStyles();

const dateTimeFormated = new DateTimeFormat(locale, {
const dateTimeFormatted = new DateTimeFormat(locale, {
month: 'short',
weekday: 'short',
day: '2-digit',
Expand All @@ -152,10 +152,10 @@ const DateDisplay = React.createClass({
style={styles.monthDay.root}
direction={this.state.transitionDirection}>
<div
key={dateTimeFormated}
key={dateTimeFormatted}
style={styles.monthDay.title}
onTouchTap={this._handleMonthDayClick}>
{dateTimeFormated}
{dateTimeFormatted}
</div>
</SlideInTransitionGroup>
</div>
Expand Down
2 changes: 0 additions & 2 deletions src/utils/date-time.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ const monthLongList = ['January', 'February', 'March', 'April', 'May', 'June',
'July', 'August', 'September', 'October', 'November', 'December'];

function DateTimeFormat(locale, options) {
this.options = options;

if (process.env.NODE_ENV !== 'production' && locale !== 'en-US') {
console.warn('Wrong usage of DateTimeFormat. The ' + locale +' locale is not supported.');
}
Expand Down
21 changes: 21 additions & 0 deletions test/date-picker/calendar-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import Calendar from 'date-picker/calendar';
import CalendarToolbar from 'date-picker/calendar-toolbar';
import IconButton from 'icon-button';
import injectTheme from '../fixtures/inject-theme';
import DateTime from 'utils/date-time';

const TestUtils = React.addons.TestUtils;

Expand All @@ -25,6 +26,8 @@ describe(`Calendar`, () => {
let render = TestUtils.renderIntoDocument(
<ThemedCalendar
initialDate={initialDate}
DateTimeFormat={DateTime.DateTimeFormat}
locale="en-US"
maxDate={maxDate}
/>
);
Expand All @@ -42,6 +45,8 @@ describe(`Calendar`, () => {
let render = TestUtils.renderIntoDocument(
<ThemedCalendar
initialDate={initialDate}
DateTimeFormat={DateTime.DateTimeFormat}
locale="en-US"
maxDate={maxDate} />
);
let renderedCalendarToolbar =
Expand All @@ -58,6 +63,8 @@ describe(`Calendar`, () => {
let render = TestUtils.renderIntoDocument(
<ThemedCalendar
initialDate={initialDate}
DateTimeFormat={DateTime.DateTimeFormat}
locale="en-US"
maxDate={maxDate} />
);

Expand All @@ -74,6 +81,8 @@ describe(`Calendar`, () => {
let render = TestUtils.renderIntoDocument(
<ThemedCalendar
initialDate={initialDate}
DateTimeFormat={DateTime.DateTimeFormat}
locale="en-US"
maxDate={maxDate} />
);
let prevMonthButton = ReactDOM.findDOMNode(
Expand All @@ -94,6 +103,8 @@ describe(`Calendar`, () => {
let render = TestUtils.renderIntoDocument(
<ThemedCalendar
initialDate={initialDate}
DateTimeFormat={DateTime.DateTimeFormat}
locale="en-US"
maxDate={maxDate} />
);
let nextMonthButton = ReactDOM.findDOMNode(
Expand All @@ -115,6 +126,8 @@ describe(`Calendar`, () => {
let render = TestUtils.renderIntoDocument(
<ThemedCalendar
initialDate={initialDate}
DateTimeFormat={DateTime.DateTimeFormat}
locale="en-US"
minDate={minDate}
/>
);
Expand All @@ -131,6 +144,8 @@ describe(`Calendar`, () => {
let render = TestUtils.renderIntoDocument(
<ThemedCalendar
initialDate={initialDate}
DateTimeFormat={DateTime.DateTimeFormat}
locale="en-US"
minDate={minDate}
/>
);
Expand All @@ -147,6 +162,8 @@ describe(`Calendar`, () => {
let render = TestUtils.renderIntoDocument(
<ThemedCalendar
initialDate={initialDate}
DateTimeFormat={DateTime.DateTimeFormat}
locale="en-US"
minDate={minDate}
/>
);
Expand All @@ -162,6 +179,8 @@ describe(`Calendar`, () => {
let render = TestUtils.renderIntoDocument(
<ThemedCalendar
initialDate={initialDate}
DateTimeFormat={DateTime.DateTimeFormat}
locale="en-US"
minDate={minDate}
/>
);
Expand All @@ -181,6 +200,8 @@ describe(`Calendar`, () => {
let render = TestUtils.renderIntoDocument(
<ThemedCalendar
initialDate={initialDate}
DateTimeFormat={DateTime.DateTimeFormat}
locale="en-US"
minDate={minDate}
/>
);
Expand Down

0 comments on commit 9c59bba

Please sign in to comment.