Skip to content

Commit 7475cd2

Browse files
daltonesMaja Wichrowska
authored andcommitted
Expose DayOfWeekShape propType
1 parent b65541c commit 7475cd2

File tree

9 files changed

+24
-12
lines changed

9 files changed

+24
-12
lines changed

constants.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,5 @@ module.exports = {
1515

1616
DAY_SIZE: 39,
1717
BLOCKED_MODIFIER: 'blocked',
18+
WEEKDAYS: [0, 1, 2, 3, 4, 5, 6],
1819
};

src/components/CalendarMonth.jsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import isSameDay from '../utils/isSameDay';
1818
import toISODateString from '../utils/toISODateString';
1919

2020
import ScrollableOrientationShape from '../shapes/ScrollableOrientationShape';
21+
import DayOfWeekShape from '../shapes/DayOfWeekShape';
2122

2223
import {
2324
HORIZONTAL_ORIENTATION,
@@ -38,7 +39,7 @@ const propTypes = forbidExtraProps({
3839
onDayMouseLeave: PropTypes.func,
3940
renderMonth: PropTypes.func,
4041
renderDay: PropTypes.func,
41-
firstDayOfWeek: PropTypes.oneOf([0, 1, 2, 3, 4, 5, 6]),
42+
firstDayOfWeek: DayOfWeekShape,
4243

4344
focusedDate: momentPropTypes.momentObj, // indicates focusable day
4445
isFocused: PropTypes.bool, // indicates whether or not to move focus to focusable day
@@ -78,7 +79,7 @@ export default class CalendarMonth extends React.Component {
7879
weeks: getCalendarMonthWeeks(
7980
props.month,
8081
props.enableOutsideDays,
81-
props.firstDayOfWeek === null ? moment.localeData().firstDayOfWeek() : props.firstDayOfWeek,
82+
props.firstDayOfWeek == null ? moment.localeData().firstDayOfWeek() : props.firstDayOfWeek,
8283
),
8384
};
8485
}
@@ -92,7 +93,7 @@ export default class CalendarMonth extends React.Component {
9293
weeks: getCalendarMonthWeeks(
9394
month,
9495
enableOutsideDays,
95-
firstDayOfWeek === null ? moment.localeData().firstDayOfWeek() : firstDayOfWeek,
96+
firstDayOfWeek == null ? moment.localeData().firstDayOfWeek() : firstDayOfWeek,
9697
),
9798
});
9899
}

src/components/CalendarMonthGrid.jsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import toISOMonthString from '../utils/toISOMonthString';
1919
import isAfterDay from '../utils/isAfterDay';
2020

2121
import ScrollableOrientationShape from '../shapes/ScrollableOrientationShape';
22+
import DayOfWeekShape from '../shapes/DayOfWeekShape';
2223

2324
import {
2425
HORIZONTAL_ORIENTATION,
@@ -45,7 +46,7 @@ const propTypes = forbidExtraProps({
4546
daySize: nonNegativeInteger,
4647
focusedDate: momentPropTypes.momentObj, // indicates focusable day
4748
isFocused: PropTypes.bool, // indicates whether or not to move focus to focusable day
48-
firstDayOfWeek: range(0, 7),
49+
firstDayOfWeek: DayOfWeekShape,
4950

5051
// i18n
5152
monthFormat: PropTypes.string,

src/components/DayPicker.jsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import getActiveElement from '../utils/getActiveElement';
2626
import isDayVisible from '../utils/isDayVisible';
2727

2828
import ScrollableOrientationShape from '../shapes/ScrollableOrientationShape';
29+
import DayOfWeekShape from '../shapes/DayOfWeekShape';
2930

3031
import {
3132
HORIZONTAL_ORIENTATION,
@@ -48,7 +49,7 @@ const propTypes = forbidExtraProps({
4849
onOutsideClick: PropTypes.func,
4950
hidden: PropTypes.bool,
5051
initialVisibleMonth: PropTypes.func,
51-
firstDayOfWeek: range(0, 7),
52+
firstDayOfWeek: DayOfWeekShape,
5253
renderCalendarInfo: PropTypes.func,
5354
hideKeyboardShortcutsPanel: PropTypes.bool,
5455
daySize: nonNegativeInteger,
@@ -685,7 +686,7 @@ export default class DayPicker extends React.Component {
685686
}
686687

687688
let { firstDayOfWeek } = this.props;
688-
if (firstDayOfWeek === null) {
689+
if (firstDayOfWeek == null) {
689690
firstDayOfWeek = moment.localeData().firstDayOfWeek();
690691
}
691692

src/components/DayPickerRangeController.jsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import toISOMonthString from '../utils/toISOMonthString';
2323

2424
import FocusedInputShape from '../shapes/FocusedInputShape';
2525
import ScrollableOrientationShape from '../shapes/ScrollableOrientationShape';
26+
import DayOfWeekShape from '../shapes/DayOfWeekShape';
2627

2728
import {
2829
START_DATE,
@@ -67,7 +68,7 @@ const propTypes = forbidExtraProps({
6768
onOutsideClick: PropTypes.func,
6869
renderDay: PropTypes.func,
6970
renderCalendarInfo: PropTypes.func,
70-
firstDayOfWeek: PropTypes.oneOf([0, 1, 2, 3, 4, 5, 6]),
71+
firstDayOfWeek: DayOfWeekShape,
7172

7273
// accessibility
7374
onBlur: PropTypes.func,

src/shapes/DateRangePickerShape.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
import PropTypes from 'prop-types';
22
import momentPropTypes from 'react-moment-proptypes';
3-
import { nonNegativeInteger, range } from 'airbnb-prop-types';
3+
import { nonNegativeInteger } from 'airbnb-prop-types';
44

55
import { DateRangePickerPhrases } from '../defaultPhrases';
66
import getPhrasePropTypes from '../utils/getPhrasePropTypes';
77

88
import FocusedInputShape from '../shapes/FocusedInputShape';
99
import OrientationShape from '../shapes/OrientationShape';
1010
import anchorDirectionShape from '../shapes/AnchorDirectionShape';
11+
import DayOfWeekShape from '../shapes/DayOfWeekShape';
1112

1213
export default {
1314
// required props for a functional interactive DateRangePicker
@@ -44,7 +45,7 @@ export default {
4445
withFullScreenPortal: PropTypes.bool,
4546
daySize: nonNegativeInteger,
4647
isRTL: PropTypes.bool,
47-
firstDayOfWeek: range(0, 7),
48+
firstDayOfWeek: DayOfWeekShape,
4849
initialVisibleMonth: PropTypes.func,
4950
numberOfMonths: PropTypes.number,
5051
keepOpenOnDateSelect: PropTypes.bool,

src/shapes/DayOfWeekShape.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import { PropTypes } from 'react';
2+
3+
import { WEEKDAYS } from '../../constants';
4+
5+
export default PropTypes.oneOf(WEEKDAYS);

src/shapes/SingleDatePickerShape.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
import PropTypes from 'prop-types';
22
import momentPropTypes from 'react-moment-proptypes';
3-
import { nonNegativeInteger, range } from 'airbnb-prop-types';
3+
import { nonNegativeInteger } from 'airbnb-prop-types';
44

55
import { SingleDatePickerPhrases } from '../defaultPhrases';
66
import getPhrasePropTypes from '../utils/getPhrasePropTypes';
77

88
import OrientationShape from '../shapes/OrientationShape';
99
import anchorDirectionShape from '../shapes/AnchorDirectionShape';
10+
import DayOfWeekShape from '../shapes/DayOfWeekShape';
1011

1112
export default {
1213
// required props for a functional interactive SingleDatePicker
@@ -36,7 +37,7 @@ export default {
3637
withPortal: PropTypes.bool,
3738
withFullScreenPortal: PropTypes.bool,
3839
initialVisibleMonth: PropTypes.func,
39-
firstDayOfWeek: range(0,7),
40+
firstDayOfWeek: DayOfWeekShape,
4041
numberOfMonths: PropTypes.number,
4142
keepOpenOnDateSelect: PropTypes.bool,
4243
reopenPickerOnClearDate: PropTypes.bool,

src/utils/getCalendarMonthWeeks.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import moment from 'moment';
22

3-
const WEEKDAYS = [0, 1, 2, 3, 4, 5, 6];
3+
import { WEEKDAYS } from '../../constants';
44

55
export default function getCalendarMonthWeeks(
66
month,

0 commit comments

Comments
 (0)