Skip to content

Commit 9cac256

Browse files
committed
Build entry points
These three files are used as entry points into the project, and we expect people to be importing them directly so they are at the top level for convenience. Because of this, they have not been getting run through Babel like the rest of the code here, so they were using older syntax. In this commit, I am moving these files into the src directory so they will be built into lib like the rest of the code here. In their place at the top level, I am creating some very light shims that simply bring in the built version of the module and re-export it if necessary. This gives us a couple of advantages. First, it makes more of our code consistent. Second, it makes it possible to produce two different kinds of builds, one for CommonJS consumers and another for ES modules consumers.
1 parent a865f5b commit 9cac256

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+87
-115
lines changed

constants.js

+2-25
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,2 @@
1-
module.exports = {
2-
DISPLAY_FORMAT: 'L',
3-
ISO_FORMAT: 'YYYY-MM-DD',
4-
ISO_MONTH_FORMAT: 'YYYY-MM',
5-
6-
START_DATE: 'startDate',
7-
END_DATE: 'endDate',
8-
9-
HORIZONTAL_ORIENTATION: 'horizontal',
10-
VERTICAL_ORIENTATION: 'vertical',
11-
VERTICAL_SCROLLABLE: 'verticalScrollable',
12-
13-
ICON_BEFORE_POSITION: 'before',
14-
ICON_AFTER_POSITION: 'after',
15-
16-
ANCHOR_LEFT: 'left',
17-
ANCHOR_RIGHT: 'right',
18-
19-
OPEN_DOWN: 'down',
20-
OPEN_UP: 'up',
21-
22-
DAY_SIZE: 39,
23-
BLOCKED_MODIFIER: 'blocked',
24-
WEEKDAYS: [0, 1, 2, 3, 4, 5, 6],
25-
};
1+
// eslint-disable-next-line import/no-unresolved
2+
module.exports = require('./lib/constants');

index.js

+2-51
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,2 @@
1-
var DateRangePicker = require('./lib/components/DateRangePicker').default;
2-
var DateRangePickerInput = require('./lib/components/DateRangePickerInput').default;
3-
var DateRangePickerInputController = require('./lib/components/DateRangePickerInputController').default;
4-
var SingleDatePicker = require('./lib/components/SingleDatePicker').default;
5-
var SingleDatePickerInput = require('./lib/components/SingleDatePickerInput').default;
6-
var DayPicker = require('./lib/components/DayPicker').default;
7-
var DayPickerRangeController = require('./lib/components/DayPickerRangeController').default;
8-
var DayPickerSingleDateController = require('./lib/components/DayPickerSingleDateController').default;
9-
var CalendarMonthGrid = require('./lib/components/CalendarMonthGrid').default;
10-
var CalendarMonth = require('./lib/components/CalendarMonth').default;
11-
var CalendarDay = require('./lib/components/CalendarDay').default;
12-
13-
var DateRangePickerShape = require('./lib/shapes/DateRangePickerShape').default;
14-
var SingleDatePickerShape = require('./lib/shapes/SingleDatePickerShape').default;
15-
16-
var isInclusivelyAfterDay = require('./lib/utils/isInclusivelyAfterDay').default;
17-
var isInclusivelyBeforeDay = require('./lib/utils/isInclusivelyBeforeDay').default;
18-
var isNextDay = require('./lib/utils/isNextDay').default;
19-
var isSameDay = require('./lib/utils/isSameDay').default;
20-
21-
var toISODateString = require('./lib/utils/toISODateString').default;
22-
var toLocalizedDateString = require('./lib/utils/toLocalizedDateString').default;
23-
var toMomentObject = require('./lib/utils/toMomentObject').default;
24-
25-
26-
module.exports = {
27-
DateRangePicker: DateRangePicker,
28-
SingleDatePicker: SingleDatePicker,
29-
30-
DateRangePickerInputController: DateRangePickerInputController,
31-
DateRangePickerInput: DateRangePickerInput,
32-
SingleDatePickerInput: SingleDatePickerInput,
33-
DayPicker: DayPicker,
34-
DayPickerRangeController: DayPickerRangeController,
35-
DayPickerSingleDateController: DayPickerSingleDateController,
36-
CalendarMonthGrid: CalendarMonthGrid,
37-
CalendarMonth: CalendarMonth,
38-
CalendarDay: CalendarDay,
39-
40-
DateRangePickerShape: DateRangePickerShape,
41-
SingleDatePickerShape: SingleDatePickerShape,
42-
43-
isInclusivelyAfterDay: isInclusivelyAfterDay,
44-
isInclusivelyBeforeDay: isInclusivelyBeforeDay,
45-
isNextDay: isNextDay,
46-
isSameDay: isSameDay,
47-
48-
toISODateString: toISODateString,
49-
toLocalizedDateString: toLocalizedDateString,
50-
toMomentObject: toMomentObject,
51-
};
1+
// eslint-disable-next-line import/no-unresolved
2+
module.exports = require('./lib');

initialize.js

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,2 @@
11
// eslint-disable-next-line import/no-unresolved
2-
const registerCSSInterfaceWithDefaultTheme = require('./lib/utils/registerCSSInterfaceWithDefaultTheme.js').default;
3-
4-
registerCSSInterfaceWithDefaultTheme();
2+
require('./lib/initialize');

src/components/CalendarDay.jsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import { CalendarDayPhrases } from '../defaultPhrases';
1010
import getPhrasePropTypes from '../utils/getPhrasePropTypes';
1111
import getPhrase from '../utils/getPhrase';
1212

13-
import { BLOCKED_MODIFIER, DAY_SIZE } from '../../constants';
13+
import { BLOCKED_MODIFIER, DAY_SIZE } from '../constants';
1414

1515
const propTypes = forbidExtraProps({
1616
...withStylesPropTypes,

src/components/CalendarMonth.jsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ import {
2626
VERTICAL_ORIENTATION,
2727
VERTICAL_SCROLLABLE,
2828
DAY_SIZE,
29-
} from '../../constants';
29+
} from '../constants';
3030

3131
const propTypes = forbidExtraProps({
3232
...withStylesPropTypes,

src/components/CalendarMonthGrid.jsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ import {
2626
VERTICAL_ORIENTATION,
2727
VERTICAL_SCROLLABLE,
2828
DAY_SIZE,
29-
} from '../../constants';
29+
} from '../constants';
3030

3131
const propTypes = forbidExtraProps({
3232
...withStylesPropTypes,

src/components/DateInput.jsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import throttle from 'lodash/throttle';
66
import isTouchDevice from 'is-touch-device';
77

88
import openDirectionShape from '../shapes/OpenDirectionShape';
9-
import { OPEN_DOWN, OPEN_UP } from '../../constants';
9+
import { OPEN_DOWN, OPEN_UP } from '../constants';
1010

1111
const propTypes = forbidExtraProps({
1212
...withStylesPropTypes,

src/components/DateRangePicker.jsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ import {
3232
OPEN_UP,
3333
DAY_SIZE,
3434
ICON_BEFORE_POSITION,
35-
} from '../../constants';
35+
} from '../constants';
3636

3737
const propTypes = forbidExtraProps({
3838
...withStylesPropTypes,

src/components/DateRangePickerInput.jsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import {
2121
ICON_BEFORE_POSITION,
2222
ICON_AFTER_POSITION,
2323
OPEN_DOWN,
24-
} from '../../constants';
24+
} from '../constants';
2525

2626
const propTypes = forbidExtraProps({
2727
...withStylesPropTypes,

src/components/DateRangePickerInputController.jsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import toLocalizedDateString from '../utils/toLocalizedDateString';
1919
import isInclusivelyAfterDay from '../utils/isInclusivelyAfterDay';
2020
import isBeforeDay from '../utils/isBeforeDay';
2121

22-
import { START_DATE, END_DATE, ICON_BEFORE_POSITION, OPEN_DOWN } from '../../constants';
22+
import { START_DATE, END_DATE, ICON_BEFORE_POSITION, OPEN_DOWN } from '../constants';
2323

2424
const propTypes = forbidExtraProps({
2525
startDate: momentPropTypes.momentObj,

src/components/DayPicker.jsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ import {
3232
VERTICAL_ORIENTATION,
3333
VERTICAL_SCROLLABLE,
3434
DAY_SIZE,
35-
} from '../../constants';
35+
} from '../constants';
3636

3737
const MONTH_PADDING = 23;
3838
const DAY_PICKER_PADDING = 9;

src/components/DayPickerNavigation.jsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import ScrollableOrientationShape from '../shapes/ScrollableOrientationShape';
1515
import {
1616
HORIZONTAL_ORIENTATION,
1717
VERTICAL_SCROLLABLE,
18-
} from '../../constants';
18+
} from '../constants';
1919

2020
const propTypes = forbidExtraProps({
2121
...withStylesPropTypes,

src/components/DayPickerRangeController.jsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ import {
3131
HORIZONTAL_ORIENTATION,
3232
VERTICAL_SCROLLABLE,
3333
DAY_SIZE,
34-
} from '../../constants';
34+
} from '../constants';
3535

3636
import DayPicker from './DayPicker';
3737

src/components/DayPickerSingleDateController.jsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import {
2525
HORIZONTAL_ORIENTATION,
2626
VERTICAL_SCROLLABLE,
2727
DAY_SIZE,
28-
} from '../../constants';
28+
} from '../constants';
2929

3030
import DayPicker from './DayPicker';
3131
import OutsideClickHandler from './OutsideClickHandler';

src/components/SingleDatePicker.jsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ import {
3030
OPEN_UP,
3131
DAY_SIZE,
3232
ICON_BEFORE_POSITION,
33-
} from '../../constants';
33+
} from '../constants';
3434

3535
const propTypes = forbidExtraProps({
3636
...withStylesPropTypes,

src/components/SingleDatePickerInput.jsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import CloseButton from './CloseButton';
1313
import CalendarIcon from './CalendarIcon';
1414

1515
import openDirectionShape from '../shapes/OpenDirectionShape';
16-
import { ICON_BEFORE_POSITION, ICON_AFTER_POSITION, OPEN_DOWN } from '../../constants';
16+
import { ICON_BEFORE_POSITION, ICON_AFTER_POSITION, OPEN_DOWN } from '../constants';
1717

1818
const propTypes = forbidExtraProps({
1919
...withStylesPropTypes,

src/constants.js

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
export const DISPLAY_FORMAT = 'L';
2+
export const ISO_FORMAT = 'YYYY-MM-DD';
3+
export const ISO_MONTH_FORMAT = 'YYYY-MM';
4+
5+
export const START_DATE = 'startDate';
6+
export const END_DATE = 'endDate';
7+
8+
export const HORIZONTAL_ORIENTATION = 'horizontal';
9+
export const VERTICAL_ORIENTATION = 'vertical';
10+
export const VERTICAL_SCROLLABLE = 'verticalScrollable';
11+
12+
export const ICON_BEFORE_POSITION = 'before';
13+
export const ICON_AFTER_POSITION = 'after';
14+
15+
export const ANCHOR_LEFT = 'left';
16+
export const ANCHOR_RIGHT = 'right';
17+
18+
export const OPEN_DOWN = 'down';
19+
export const OPEN_UP = 'up';
20+
21+
export const DAY_SIZE = 39;
22+
export const BLOCKED_MODIFIER = 'blocked';
23+
export const WEEKDAYS = [0, 1, 2, 3, 4, 5, 6];

src/index.js

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
export { default as CalendarDay } from './components/CalendarDay';
2+
export { default as CalendarMonth } from './components/CalendarMonth';
3+
export { default as CalendarMonthGrid } from './components/CalendarMonthGrid';
4+
export { default as DateRangePicker } from './components/DateRangePicker';
5+
export { default as DateRangePickerInput } from './components/DateRangePickerInput';
6+
export { default as DateRangePickerInputController } from './components/DateRangePickerInputController';
7+
export { default as DateRangePickerShape } from './shapes/DateRangePickerShape';
8+
export { default as DayPicker } from './components/DayPicker';
9+
export { default as DayPickerRangeController } from './components/DayPickerRangeController';
10+
export { default as DayPickerSingleDateController } from './components/DayPickerSingleDateController';
11+
export { default as SingleDatePicker } from './components/SingleDatePicker';
12+
export { default as SingleDatePickerInput } from './components/SingleDatePickerInput';
13+
export { default as SingleDatePickerShape } from './shapes/SingleDatePickerShape';
14+
export { default as isInclusivelyAfterDay } from './utils/isInclusivelyAfterDay';
15+
export { default as isInclusivelyBeforeDay } from './utils/isInclusivelyBeforeDay';
16+
export { default as isNextDay } from './utils/isNextDay';
17+
export { default as isSameDay } from './utils/isSameDay';
18+
export { default as toISODateString } from './utils/toISODateString';
19+
export { default as toLocalizedDateString } from './utils/toLocalizedDateString';
20+
export { default as toMomentObject } from './utils/toMomentObject';

src/initialize.js

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import registerCSSInterfaceWithDefaultTheme from './utils/registerCSSInterfaceWithDefaultTheme';
2+
3+
registerCSSInterfaceWithDefaultTheme();

src/shapes/AnchorDirectionShape.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@ import PropTypes from 'prop-types';
33
import {
44
ANCHOR_LEFT,
55
ANCHOR_RIGHT,
6-
} from '../../constants';
6+
} from '../constants';
77

88
export default PropTypes.oneOf([ANCHOR_LEFT, ANCHOR_RIGHT]);

src/shapes/DayOfWeekShape.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import PropTypes from 'prop-types';
22

3-
import { WEEKDAYS } from '../../constants';
3+
import { WEEKDAYS } from '../constants';
44

55
export default PropTypes.oneOf(WEEKDAYS);

src/shapes/FocusedInputShape.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@ import PropTypes from 'prop-types';
33
import {
44
START_DATE,
55
END_DATE,
6-
} from '../../constants';
6+
} from '../constants';
77

88
export default PropTypes.oneOf([START_DATE, END_DATE]);

src/shapes/IconPositionShape.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@ import PropTypes from 'prop-types';
33
import {
44
ICON_BEFORE_POSITION,
55
ICON_AFTER_POSITION,
6-
} from '../../constants';
6+
} from '../constants';
77

88
export default PropTypes.oneOf([ICON_BEFORE_POSITION, ICON_AFTER_POSITION]);

src/shapes/OpenDirectionShape.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@ import PropTypes from 'prop-types';
33
import {
44
OPEN_DOWN,
55
OPEN_UP,
6-
} from '../../constants';
6+
} from '../constants';
77

88
export default PropTypes.oneOf([OPEN_DOWN, OPEN_UP]);

src/shapes/OrientationShape.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@ import PropTypes from 'prop-types';
33
import {
44
HORIZONTAL_ORIENTATION,
55
VERTICAL_ORIENTATION,
6-
} from '../../constants';
6+
} from '../constants';
77

88
export default PropTypes.oneOf([HORIZONTAL_ORIENTATION, VERTICAL_ORIENTATION]);

src/shapes/ScrollableOrientationShape.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import {
44
HORIZONTAL_ORIENTATION,
55
VERTICAL_ORIENTATION,
66
VERTICAL_SCROLLABLE,
7-
} from '../../constants';
7+
} from '../constants';
88

99
export default PropTypes.oneOf([
1010
HORIZONTAL_ORIENTATION,

src/utils/getCalendarMonthWeeks.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import moment from 'moment';
22

3-
import { WEEKDAYS } from '../../constants';
3+
import { WEEKDAYS } from '../constants';
44

55
export default function getCalendarMonthWeeks(
66
month,

src/utils/getResponsiveContainerStyles.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { ANCHOR_LEFT } from '../../constants';
1+
import { ANCHOR_LEFT } from '../constants';
22

33
export default function getResponsiveContainerStyles(
44
anchorDirection,

src/utils/toISODateString.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import moment from 'moment';
22

33
import toMomentObject from './toMomentObject';
44

5-
import { ISO_FORMAT } from '../../constants';
5+
import { ISO_FORMAT } from '../constants';
66

77
export default function toISODateString(date, currentFormat) {
88
const dateObj = moment.isMoment(date) ? date : toMomentObject(date, currentFormat);

src/utils/toISOMonthString.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import moment from 'moment';
22

33
import toMomentObject from './toMomentObject';
44

5-
import { ISO_MONTH_FORMAT } from '../../constants';
5+
import { ISO_MONTH_FORMAT } from '../constants';
66

77
export default function toISOMonthString(date, currentFormat) {
88
const dateObj = moment.isMoment(date) ? date : toMomentObject(date, currentFormat);

src/utils/toLocalizedDateString.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import moment from 'moment';
22

33
import toMomentObject from './toMomentObject';
44

5-
import { DISPLAY_FORMAT } from '../../constants';
5+
import { DISPLAY_FORMAT } from '../constants';
66

77
export default function toLocalizedDateString(date, currentFormat) {
88
const dateObj = moment.isMoment(date) ? date : toMomentObject(date, currentFormat);

src/utils/toMomentObject.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import moment from 'moment';
22

3-
import { DISPLAY_FORMAT, ISO_FORMAT } from '../../constants';
3+
import { DISPLAY_FORMAT, ISO_FORMAT } from '../constants';
44

55
export default function toMomentObject(dateString, customFormat) {
66
const dateFormats = customFormat ?

test/components/CalendarDay_spec.jsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import sinon from 'sinon-sandbox';
44
import { shallow } from 'enzyme';
55
import moment from 'moment';
66

7-
import { BLOCKED_MODIFIER } from '../../constants';
7+
import { BLOCKED_MODIFIER } from '../../src/constants';
88
import CalendarDay, { PureCalendarDay } from '../../src/components/CalendarDay';
99

1010
describe('CalendarDay', () => {

test/components/DateRangePickerInputController_spec.jsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import isSameDay from '../../src/utils/isSameDay';
1414
import {
1515
START_DATE,
1616
END_DATE,
17-
} from '../../constants';
17+
} from '../../src/constants';
1818

1919
// Set to noon to mimic how days in the picker are configured internally
2020
const today = moment().startOf('day').hours(12);

test/components/DateRangePicker_spec.jsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import DayPickerRangeController from '../../src/components/DayPickerRangeControl
1313
import {
1414
HORIZONTAL_ORIENTATION,
1515
START_DATE,
16-
} from '../../constants';
16+
} from '../../src/constants';
1717

1818
const requiredProps = {
1919
onDatesChange: () => {},

test/components/DayPickerNavigation_spec.jsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { shallow } from 'enzyme';
66
import DayPickerNavigation from '../../src/components/DayPickerNavigation';
77
import {
88
VERTICAL_SCROLLABLE,
9-
} from '../../constants';
9+
} from '../../src/constants';
1010

1111
describe('DayPickerNavigation', () => {
1212
describe('#render', () => {

0 commit comments

Comments
 (0)