Skip to content

Commit d52693d

Browse files
authored
fix: added localized text shape to calendar (#494)
* added description for caledar, edited propertydefault for arrays, edited property table so localized text call is not duplicated * added days and months as individual strings instead of array for API ease * updated localized text proptype names and made method to input month names * added suffix to propName in propertyTable to include object descriptions * changed prop description to include shape
1 parent 981fef3 commit d52693d

File tree

2 files changed

+103
-7
lines changed

2 files changed

+103
-7
lines changed

src/Calendar/Calendar.js

Lines changed: 102 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import classnames from 'classnames';
2+
import CustomPropTypes from '../utils/CustomPropTypes/CustomPropTypes';
23
import PropTypes from 'prop-types';
34
import React, { Component } from 'react';
45

@@ -110,7 +111,7 @@ class Calendar extends Component {
110111

111112
changeMonth = (month) => {
112113
let date = this.state.currentDateDisplayed;
113-
let months = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'];
114+
let months = this.getMonths();
114115
date.setMonth(months.indexOf(month));
115116
// reset date to first of month
116117
date.setDate(1);
@@ -156,7 +157,7 @@ class Calendar extends Component {
156157
}
157158

158159
generateMonths = (monthProps) => {
159-
let months = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'];
160+
let months = this.getMonths();
160161
let listOfMonths = months.map(element => {
161162
let shortenedNameMonth = '';
162163
if (element.length > 3) {
@@ -337,7 +338,8 @@ class Calendar extends Component {
337338
}
338339

339340
disableWeekday = (date, weekDays) => {
340-
let daysName = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'];
341+
const { day1Sun, day2Mon, day3Tues, day4Wed, day5Thurs, day6Fri, day7Sat } = this.props.localizedText;
342+
let daysName = [day1Sun, day2Mon, day3Tues, day4Wed, day5Thurs, day6Fri, day7Sat];
341343

342344
if (typeof weekDays === 'undefined') {
343345
return false;
@@ -382,8 +384,17 @@ class Calendar extends Component {
382384
this.props.onChange(dates);
383385
}
384386

387+
getMonths = () => {
388+
const { month01Jan, month02Feb, month03Mar, month04Apr, month05May, month06Jun, month07Jul,
389+
month08Aug, month09Sep, month10Oct, month11Nov, month12Dec } = this.props.localizedText;
390+
let months = [month01Jan, month02Feb, month03Mar, month04Apr, month05May, month06Jun, month07Jul,
391+
month08Aug, month09Sep, month10Oct, month11Nov, month12Dec];
392+
393+
return months;
394+
}
395+
385396
generateNavigation = () => {
386-
let months = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'];
397+
let months = this.getMonths();
387398

388399
return (
389400
<header className='fd-calendar__header'>
@@ -416,7 +427,8 @@ class Calendar extends Component {
416427

417428
generateWeekdays = () => {
418429
let weekDays = [];
419-
let daysName = ['S', 'M', 'T', 'W', 'T', 'F', 'S'];
430+
const { dayChar1Sun, dayChar2Mon, dayChar3Tues, dayChar4Wed, dayChar5Thurs, dayChar6Fri, dayChar7Sat } = this.props.localizedText;
431+
let daysName = [dayChar1Sun, dayChar2Mon, dayChar3Tues, dayChar4Wed, dayChar5Thurs, dayChar6Fri, dayChar7Sat];
420432

421433
for (let index = 0; index < 7; index++) {
422434
weekDays.push(
@@ -524,6 +536,7 @@ class Calendar extends Component {
524536
disabledDates,
525537
customDate,
526538
className,
539+
localizedText,
527540
monthListProps,
528541
yearListProps,
529542
tableProps,
@@ -563,7 +576,34 @@ Calendar.basePropTypes = {
563576

564577
Calendar.propTypes = {
565578
...Calendar.basePropTypes,
566-
579+
localizedText: CustomPropTypes.i18n({
580+
day1Sun: PropTypes.string,
581+
day2Mon: PropTypes.string,
582+
day3Tues: PropTypes.string,
583+
day4Wed: PropTypes.string,
584+
day5Thurs: PropTypes.string,
585+
day6Fri: PropTypes.string,
586+
day7Sat: PropTypes.string,
587+
dayChar1Sun: PropTypes.string,
588+
dayChar2Mon: PropTypes.string,
589+
dayChar3Tues: PropTypes.string,
590+
dayChar4Wed: PropTypes.string,
591+
dayChar5Thurs: PropTypes.string,
592+
dayChar6Fri: PropTypes.string,
593+
dayChar7Sat: PropTypes.string,
594+
month01Jan: PropTypes.string,
595+
month02Feb: PropTypes.string,
596+
month03Mar: PropTypes.string,
597+
month04Apr: PropTypes.string,
598+
month05May: PropTypes.string,
599+
month06Jun: PropTypes.string,
600+
month07Jul: PropTypes.string,
601+
month08Aug: PropTypes.string,
602+
month09Sep: PropTypes.string,
603+
month10Oct: PropTypes.string,
604+
month11Nov: PropTypes.string,
605+
month12Dec: PropTypes.string
606+
}),
567607
monthListProps: PropTypes.object,
568608
tableBodyProps: PropTypes.object,
569609
tableHeaderProps: PropTypes.object,
@@ -573,6 +613,34 @@ Calendar.propTypes = {
573613
};
574614

575615
Calendar.defaultProps = {
616+
localizedText: {
617+
day1Sun: 'Sunday',
618+
day2Mon: 'Monday',
619+
day3Tues: 'Tuesday',
620+
day4Wed: 'Wednesday',
621+
day5Thurs: 'Thursday',
622+
day6Fri: 'Friday',
623+
day7Sat: 'Saturday',
624+
dayChar1Sun: 'S',
625+
dayChar2Mon: 'M',
626+
dayChar3Tues: 'T',
627+
dayChar4Wed: 'W',
628+
dayChar5Thurs: 'T',
629+
dayChar6Fri: 'F',
630+
dayChar7Sat: 'S',
631+
month01Jan: 'January',
632+
month02Feb: 'February',
633+
month03Mar: 'March',
634+
month04Apr: 'April',
635+
month05May: 'May',
636+
month06Jun: 'June',
637+
month07Jul: 'July',
638+
month08Aug: 'August',
639+
month09Sep: 'September',
640+
month10Oct: 'October',
641+
month11Nov: 'November',
642+
month12Dec: 'December'
643+
},
576644
onChange: () => { }
577645
};
578646

@@ -585,6 +653,34 @@ Calendar.propDescriptions = {
585653
disablePastDates: 'Set to **true** to disable dates before today\'s date.',
586654
disableWeekday: 'Disables dates that match a weekday.',
587655
disableWeekends: 'Set to **true** to disables dates that match a weekend.',
656+
localizedTextShape: {
657+
day1Sun: 'Full name for Sunday.',
658+
day2Mon: 'Full name for Monday.',
659+
day3Tues: 'Full name for Tuesday.',
660+
day4Wed: 'Full name for Wednesday.',
661+
day5Thurs: 'Full name for Thursday.',
662+
day6Fri: 'Full name for Friday.',
663+
day7Sat: 'Full name for Saturday.',
664+
dayChar1Sun: 'Single character for Sunday.',
665+
dayChar2Mon: 'Single character for Monday.',
666+
dayChar3Tues: 'Single character for Tuesday.',
667+
dayChar4Wed: 'Single character for Wednesday.',
668+
dayChar5Thurs: 'Single character for Thursday.',
669+
dayChar6Fri: 'Single character for Friday.',
670+
dayChar7Sat: 'Single character for Saturday.',
671+
month01Jan: 'Full name for January.',
672+
month02Feb: 'Full name for February.',
673+
month03Mar: 'Full name for March.',
674+
month04Apr: 'Full name for April.',
675+
month05May: 'Full name for May.',
676+
month06Jun: 'Full name for June.',
677+
month07Jul: 'Full name for July.',
678+
month08Aug: 'Full name for August.',
679+
month09Sep: 'Full name for September.',
680+
month10Oct: 'Full name for Octobor.',
681+
month11Nov: 'Full name for November.',
682+
month12Dec: 'Full name for December'
683+
},
588684
monthListProps: 'Additional props to be spread to the month\'s `<ul>` element.',
589685
tableBodyProps: 'Additional props to be spread to the `<tbody>` element.',
590686
tableHeaderProps: 'Additional props to be spread to the `<thead>` element.',

src/_playground/documentation/Properties/_PropertyTable.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ const PropertyTable = ({ title, propTypes, defaultProps, propDescriptions }) =>
6565
return (<PropertyShape
6666
defaultProps={defaultProps[shape]}
6767
key={i}
68-
propDescriptions={mergedPropDescriptions[shape]}
68+
propDescriptions={mergedPropDescriptions[`${shape}Shape`]}
6969
propTypes={propTypes[shape].typeChecker}
7070
title={shapeName} />);
7171
})}

0 commit comments

Comments
 (0)