Skip to content

Commit

Permalink
Add an example of using locales without a global variable
Browse files Browse the repository at this point in the history
  • Loading branch information
whatisaphone committed Mar 11, 2019
1 parent 90400b5 commit 92b08b6
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 0 deletions.
5 changes: 5 additions & 0 deletions docs-site/src/example_components.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import CustomDayClassNames from "./examples/custom_day_class_names";
import PlaceholderText from "./examples/placeholder_text";
import SpecificDateRange from "./examples/specific_date_range";
import Locale from "./examples/locale";
import LocaleWithoutGlobalVariable from "./examples/locale_without_global_variable";
import ExcludeDates from "./examples/exclude_dates";
import HighlightDates from "./examples/highlight_dates";
import HighlightDatesRanges from "./examples/highlight_dates_with_ranges";
Expand Down Expand Up @@ -125,6 +126,10 @@ export default class exampleComponents extends React.Component {
title: "Locale",
component: <Locale />
},
{
title: "Locale without global variables",
component: <LocaleWithoutGlobalVariable />
},
{
title: "Exclude dates",
component: <ExcludeDates />
Expand Down
57 changes: 57 additions & 0 deletions docs-site/src/examples/locale_without_global_variable.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import React from "react";
import DatePicker, { registerLocale } from "react-datepicker";
import fi from "date-fns/locale/fi";

export default class LocaleWithoutGlobalVariable extends React.Component {
state = {
startDate: null
};

handleChange = date => {
this.setState({
startDate: date
});
};

render() {
return (
<div className="row">
<pre className="column example__code">
<code className="jsx">
{
"// Note: Make sure to npm install the right version of date-fns as"
}
<br />
{
"// specified in packaged.json. The default one may not be compatiable"
}
<br />
{"// npm install --save date-fns@version"}
<br />
{"import DatePicker from 'react-datepicker';"}
<br />
{"import fi from 'date-fns/locale/fi';"}
<br />
<br />
{"<DatePicker"}
<br />
{" selected={this.state.startDate}"}
<br />
{" onChange={this.handleChange}"}
<br />
<strong>{" locale={fi}"}</strong>
<br />
{"/>"}
</code>
</pre>
<div className="column">
<DatePicker
selected={this.state.startDate}
onChange={this.handleChange}
locale={fi}
/>
</div>
</div>
);
}
}

0 comments on commit 92b08b6

Please sign in to comment.