-
-
Notifications
You must be signed in to change notification settings - Fork 732
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #226 from gpbl/spread-locale-utils
New props for localization
- Loading branch information
Showing
20 changed files
with
292 additions
and
86 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
# Utilities | ||
|
||
* [DateUtils](DateUtils.md) – contain some date functions useful to setup modifiers. | ||
* [LocaleUtils](LocaleUtils.md) - set of functions used to localize the component, usually [overridden](LocalizationCustom.md) by implementers. | ||
* [LocaleUtils](LocaleUtils.md) - set of functions used to localize the component, usually [overridden](LocalizationAdvanced.md) by implementers. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,48 +1,26 @@ | ||
import React from 'react'; | ||
import DayPicker from '../../../src'; | ||
|
||
// Use a custom util to format the calendar values according to the | ||
// selected locale. This one is based on moment.js | ||
import MomentLocaleUtils from 'react-day-picker/moment'; | ||
const MONTHS = ['Gennaio', 'Febbraio', 'Marzo', 'Aprile', 'Maggio', | ||
'Giugno', 'Luglio', 'Agosto', 'Settembre', 'Ottobre', 'Novembre', | ||
'Dicembre']; | ||
|
||
// Make sure moment.js has the required locale data | ||
import 'moment/locale/ja'; | ||
import 'moment/locale/ar'; | ||
import 'moment/locale/it'; | ||
const WEEKDAYS_LONG = ['Domenica', 'Lunedì', 'Martedì', | ||
'Mercoledì', 'Giovedì', 'Venerdì', 'Sabato']; | ||
|
||
import '../../../src/style.css'; | ||
const WEEKDAYS_SHORT = ['Do', 'Lu', 'Ma', 'Me', 'Gi', 'Ve', 'Sa']; | ||
|
||
export default class Localized extends React.Component { | ||
constructor(props) { | ||
super(props); | ||
this.switchLocale = this.switchLocale.bind(this); | ||
} | ||
state = { | ||
locale: 'en', | ||
}; | ||
switchLocale(e) { | ||
const locale = e.target.value || 'en'; | ||
this.setState({ locale }); | ||
} | ||
render() { | ||
const { locale } = this.state; | ||
return ( | ||
<div> | ||
<p> | ||
<select onChange={ this.switchLocale }> | ||
<option value="en">English</option> | ||
<option value="it">Italian</option> | ||
<option value="ja">Japanese</option> | ||
<option value="ar">Arabic</option> | ||
</select> | ||
</p> | ||
<DayPicker | ||
dir={ locale === 'ar' ? 'rtl' : 'ltr' } | ||
locale={ locale } | ||
localeUtils={ MomentLocaleUtils } | ||
modifiers={ { sunday: day => day.getDay() === 0 } } | ||
/> | ||
</div> | ||
); | ||
} | ||
export default function Localized() { | ||
return ( | ||
<div> | ||
<DayPicker | ||
locale="it" | ||
months={ MONTHS } | ||
weekdaysLong={ WEEKDAYS_LONG } | ||
weekdaysShort={ WEEKDAYS_SHORT } | ||
firstDayOfWeek={ 1 } | ||
modifiers={ { sunday: day => day.getDay() === 0 } } | ||
/> | ||
</div> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import React from 'react'; | ||
import DayPicker from '../../../src'; | ||
|
||
// Use a custom util to format the calendar values according to the | ||
// selected locale. This one is based on moment.js | ||
import MomentLocaleUtils from 'react-day-picker/moment'; | ||
|
||
// Make sure moment.js has the required locale data | ||
import 'moment/locale/ja'; | ||
import 'moment/locale/ar'; | ||
import 'moment/locale/it'; | ||
|
||
import '../../../src/style.css'; | ||
|
||
export default class LocalizedMoment extends React.Component { | ||
constructor(props) { | ||
super(props); | ||
this.switchLocale = this.switchLocale.bind(this); | ||
} | ||
state = { | ||
locale: 'en', | ||
}; | ||
switchLocale(e) { | ||
const locale = e.target.value || 'en'; | ||
this.setState({ locale }); | ||
} | ||
render() { | ||
const { locale } = this.state; | ||
return ( | ||
<div> | ||
<p> | ||
<select onChange={ this.switchLocale }> | ||
<option value="en">English</option> | ||
<option value="it">Italian</option> | ||
<option value="ja">Japanese</option> | ||
<option value="ar">Arabic</option> | ||
</select> | ||
</p> | ||
<DayPicker | ||
dir={ locale === 'ar' ? 'rtl' : 'ltr' } | ||
locale={ locale } | ||
localeUtils={ MomentLocaleUtils } | ||
modifiers={ { sunday: day => day.getDay() === 0 } } | ||
/> | ||
</div> | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -206,3 +206,8 @@ select { | |
margin-bottom: 2em; | ||
display: inline-block; | ||
} | ||
|
||
.Example-Code { | ||
max-width: 800px; | ||
margin: 0 auto; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.