Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,20 @@ class App extends Component {
console.log(date);
this.setState({ date: date, selectedDate: formatDate(date) });
}}
localizedMonths={ // default is the english options
0: 'January',
1: 'February',
2: 'March',
3: 'April',
4: 'May',
5: 'June',
6: 'July',
7: 'August',
8: 'September',
9: 'October',
10: 'November',
11: 'December'
}
ids={ // optional
{
year: 'select-year',
Expand Down Expand Up @@ -198,6 +212,20 @@ class App extends Component {
this.setState({ month });
console.log(month);
}}
localizedMonths={ // default is the english options
0: 'January',
1: 'February',
2: 'March',
3: 'April',
4: 'May',
5: 'June',
6: 'July',
7: 'August',
8: 'September',
9: 'October',
10: 'November',
11: 'December'
}
id={'month'}
name={'month'}
classes={'classes'}
Expand Down
11 changes: 7 additions & 4 deletions src/date-dropdown.component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ interface IProps {
onDayChange?: Function;
onYearChange?: Function;
onDateChange?: Function;
localizedMonths?: Object;
ids?: {
year?: string;
month?: string;
Expand Down Expand Up @@ -143,8 +144,10 @@ export class DropdownDate extends React.Component<IProps, IState> {
}

generateMonthOptions() {
const { classes, options, defaultValues } = this.props;
const { classes, options, defaultValues, localizedMonths } = this.props;
const { startMonth, endMonth, startYear, endYear, selectedYear } = this.state;
let localizedMonthOptions = (localizedMonths && Object.entries(localizedMonths).length > 0) ? localizedMonths : monthByNumber;

let months = [];

if (selectedYear === startYear && selectedYear === endYear) {
Expand All @@ -158,21 +161,21 @@ export class DropdownDate extends React.Component<IProps, IState> {
for (let i = startMonth; i <= 11; i++) {
months.push({
value: i,
month: monthByNumber[i]
month: localizedMonthOptions[i]
});
}
} else if (selectedYear === endYear) {
for (let i = 0; i <= endMonth; i++) {
months.push({
value: i,
month: monthByNumber[i]
month: localizedMonthOptions[i]
});
}
} else {
for (let i = 0; i <= 11; i++) {
months.push({
value: i,
month: monthByNumber[i]
month: localizedMonthOptions[i]
});
}
}
Expand Down
6 changes: 4 additions & 2 deletions src/month-picker.component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ interface IProps {
name?: string;
classes?: string;
optionClasses?: string;
localizedMonths?: Object;
}

interface IState {
Expand All @@ -25,10 +26,11 @@ interface IState {
export class MonthPicker extends React.Component<IProps, IState> {

renderMonthOptions = () => {
const { endYearGiven, year, numeric, caps, short, optionClasses, defaultValue } = this.props;
const { endYearGiven, year, numeric, caps, short, optionClasses, defaultValue, localizedMonths } = this.props;
const today = new Date();
let months = [];
let month = 11;
let localizedMonthOptions = (localizedMonths && Object.entries(localizedMonths).length > 0) ? localizedMonths : monthByNumber;
if (!endYearGiven) {
if (year && parseInt(year.toString()) === today.getFullYear()) {
month = today.getMonth();
Expand All @@ -40,7 +42,7 @@ export class MonthPicker extends React.Component<IProps, IState> {
}
} else {
for (let i = 0; i <= month; ++i) {
months.push(monthByNumber[i]);
months.push(localizedMonthOptions[i]);
}
if (caps) {
months = months.map((month) => { return month.toUpperCase(); });
Expand Down