From ce0d56bcec61dfb604eb2edc99726a813687ad1d Mon Sep 17 00:00:00 2001 From: Bogdan Chadkin Date: Thu, 17 Jan 2019 17:03:28 +0300 Subject: [PATCH] feat: remove propTypes in production (#1180) This saves ~7kB --- .babelrc | 3 ++ .size-snapshot.json | 12 +++--- package.json | 1 + src/Agenda.js | 34 +++++++-------- src/BackgroundCells.js | 42 +++++++++---------- src/Calendar.js | 6 ++- src/DateContentRow.js | 81 ++++++++++++++++++------------------ src/Day.js | 8 ++-- src/DayColumn.js | 80 +++++++++++++++++------------------ src/EventCell.js | 38 ++++++++--------- src/EventEndingRow.js | 26 +++++++----- src/EventRow.js | 22 ++++++---- src/Month.js | 87 +++++++++++++++++++------------------- src/Popup.js | 44 ++++++++++---------- src/TimeGrid.js | 94 +++++++++++++++++++++--------------------- src/TimeGridHeader.js | 54 ++++++++++++------------ src/TimeGutter.js | 24 +++++------ src/TimeSlotGroup.js | 16 +++---- src/Toolbar.js | 23 ++++++----- src/Week.js | 12 +++--- src/WorkWeek.js | 12 +++--- yarn.lock | 5 +++ 22 files changed, 371 insertions(+), 353 deletions(-) diff --git a/.babelrc b/.babelrc index d08766d52..7a0f098c6 100644 --- a/.babelrc +++ b/.babelrc @@ -1,5 +1,8 @@ { "presets": ["jason"], + plugins: [ + ['transform-react-remove-prop-types', { mode: 'wrap' }], + ], "env": { "esm": { "presets": [ diff --git a/.size-snapshot.json b/.size-snapshot.json index cde87a8dd..d5fd570f0 100644 --- a/.size-snapshot.json +++ b/.size-snapshot.json @@ -1,12 +1,12 @@ { "./dist/react-big-calendar.js": { - "bundled": 470107, - "minified": 152579, - "gzipped": 42233 + "bundled": 469894, + "minified": 152522, + "gzipped": 42174 }, "./dist/react-big-calendar.min.js": { - "bundled": 439313, - "minified": 142681, - "gzipped": 39554 + "bundled": 412865, + "minified": 135555, + "gzipped": 38300 } } diff --git a/package.json b/package.json index 51dc1a5ba..dc8ff698a 100644 --- a/package.json +++ b/package.json @@ -72,6 +72,7 @@ "babel-core": "^7.0.0-bridge.0", "babel-eslint": "^10.0.1", "babel-jest": "^23.6.0", + "babel-plugin-transform-react-remove-prop-types": "^0.4.22", "babel-preset-jason": "^6.0.1", "bootstrap": "^3.3.5", "component-metadata-loader": "^4.0.0", diff --git a/src/Agenda.js b/src/Agenda.js index 04dbb4e1a..f185eec92 100644 --- a/src/Agenda.js +++ b/src/Agenda.js @@ -10,23 +10,6 @@ import { inRange } from './utils/eventLevels' import { isSelected } from './utils/selection' class Agenda extends React.Component { - static propTypes = { - events: PropTypes.array, - date: PropTypes.instanceOf(Date), - length: PropTypes.number.isRequired, - - selected: PropTypes.object, - - accessors: PropTypes.object.isRequired, - components: PropTypes.object.isRequired, - getters: PropTypes.object.isRequired, - localizer: PropTypes.object.isRequired, - } - - static defaultProps = { - length: 30, - } - componentDidMount() { this._adjustHeader() } @@ -200,6 +183,23 @@ class Agenda extends React.Component { } } +Agenda.propTypes = { + events: PropTypes.array, + date: PropTypes.instanceOf(Date), + length: PropTypes.number.isRequired, + + selected: PropTypes.object, + + accessors: PropTypes.object.isRequired, + components: PropTypes.object.isRequired, + getters: PropTypes.object.isRequired, + localizer: PropTypes.object.isRequired, +} + +Agenda.defaultProps = { + length: 30, +} + Agenda.range = (start, { length = Agenda.defaultProps.length }) => { let end = dates.add(start, length, 'day') return { start, end } diff --git a/src/BackgroundCells.js b/src/BackgroundCells.js index ecc6af5e2..62dab92e2 100644 --- a/src/BackgroundCells.js +++ b/src/BackgroundCells.js @@ -9,27 +9,6 @@ import { dateCellSelection, getSlotAtX, pointInBox } from './utils/selection' import Selection, { getBoundsForNode, isEvent } from './Selection' class BackgroundCells extends React.Component { - static propTypes = { - date: PropTypes.instanceOf(Date), - getNow: PropTypes.func.isRequired, - - getters: PropTypes.object.isRequired, - components: PropTypes.object.isRequired, - - container: PropTypes.func, - dayPropGetter: PropTypes.func, - selectable: PropTypes.oneOf([true, false, 'ignoreEvents']), - longPressThreshold: PropTypes.number, - - onSelectSlot: PropTypes.func.isRequired, - onSelectEnd: PropTypes.func, - onSelectStart: PropTypes.func, - - range: PropTypes.arrayOf(PropTypes.instanceOf(Date)), - rtl: PropTypes.bool, - type: PropTypes.string, - } - constructor(props, context) { super(props, context) @@ -185,4 +164,25 @@ class BackgroundCells extends React.Component { } } +BackgroundCells.propTypes = { + date: PropTypes.instanceOf(Date), + getNow: PropTypes.func.isRequired, + + getters: PropTypes.object.isRequired, + components: PropTypes.object.isRequired, + + container: PropTypes.func, + dayPropGetter: PropTypes.func, + selectable: PropTypes.oneOf([true, false, 'ignoreEvents']), + longPressThreshold: PropTypes.number, + + onSelectSlot: PropTypes.func.isRequired, + onSelectEnd: PropTypes.func, + onSelectStart: PropTypes.func, + + range: PropTypes.arrayOf(PropTypes.instanceOf(Date)), + rtl: PropTypes.bool, + type: PropTypes.string, +} + export default BackgroundCells diff --git a/src/Calendar.js b/src/Calendar.js index 999c8f8be..72c7110e3 100644 --- a/src/Calendar.js +++ b/src/Calendar.js @@ -952,7 +952,11 @@ class Calendar extends React.Component { } let views = this.getViews() - this.handleRangeChange(this.props.date || this.props.getNow(), views[view], view) + this.handleRangeChange( + this.props.date || this.props.getNow(), + views[view], + view + ) } handleSelectEvent = (...args) => { diff --git a/src/DateContentRow.js b/src/DateContentRow.js index 95d028e23..d5577f231 100644 --- a/src/DateContentRow.js +++ b/src/DateContentRow.js @@ -11,46 +11,6 @@ import EventRow from './EventRow' import EventEndingRow from './EventEndingRow' import * as DateSlotMetrics from './utils/DateSlotMetrics' -const propTypes = { - date: PropTypes.instanceOf(Date), - events: PropTypes.array.isRequired, - range: PropTypes.array.isRequired, - - rtl: PropTypes.bool, - resourceId: PropTypes.any, - renderForMeasure: PropTypes.bool, - renderHeader: PropTypes.func, - - container: PropTypes.func, - selected: PropTypes.object, - selectable: PropTypes.oneOf([true, false, 'ignoreEvents']), - longPressThreshold: PropTypes.number, - - onShowMore: PropTypes.func, - onSelectSlot: PropTypes.func, - onSelect: PropTypes.func, - onSelectEnd: PropTypes.func, - onSelectStart: PropTypes.func, - onDoubleClick: PropTypes.func, - dayPropGetter: PropTypes.func, - - getNow: PropTypes.func.isRequired, - isAllDay: PropTypes.bool, - - accessors: PropTypes.object.isRequired, - components: PropTypes.object.isRequired, - getters: PropTypes.object.isRequired, - localizer: PropTypes.object.isRequired, - - minRows: PropTypes.number.isRequired, - maxRows: PropTypes.number.isRequired, -} - -const defaultProps = { - minRows: 0, - maxRows: Infinity, -} - class DateContentRow extends React.Component { constructor(...args) { super(...args) @@ -218,7 +178,44 @@ class DateContentRow extends React.Component { } } -DateContentRow.propTypes = propTypes -DateContentRow.defaultProps = defaultProps +DateContentRow.propTypes = { + date: PropTypes.instanceOf(Date), + events: PropTypes.array.isRequired, + range: PropTypes.array.isRequired, + + rtl: PropTypes.bool, + resourceId: PropTypes.any, + renderForMeasure: PropTypes.bool, + renderHeader: PropTypes.func, + + container: PropTypes.func, + selected: PropTypes.object, + selectable: PropTypes.oneOf([true, false, 'ignoreEvents']), + longPressThreshold: PropTypes.number, + + onShowMore: PropTypes.func, + onSelectSlot: PropTypes.func, + onSelect: PropTypes.func, + onSelectEnd: PropTypes.func, + onSelectStart: PropTypes.func, + onDoubleClick: PropTypes.func, + dayPropGetter: PropTypes.func, + + getNow: PropTypes.func.isRequired, + isAllDay: PropTypes.bool, + + accessors: PropTypes.object.isRequired, + components: PropTypes.object.isRequired, + getters: PropTypes.object.isRequired, + localizer: PropTypes.object.isRequired, + + minRows: PropTypes.number.isRequired, + maxRows: PropTypes.number.isRequired, +} + +DateContentRow.defaultProps = { + minRows: 0, + maxRows: Infinity, +} export default DateContentRow diff --git a/src/Day.js b/src/Day.js index 26ee9e209..8176973e5 100644 --- a/src/Day.js +++ b/src/Day.js @@ -6,10 +6,6 @@ import { navigate } from './utils/constants' import TimeGrid from './TimeGrid' class Day extends React.Component { - static propTypes = { - date: PropTypes.instanceOf(Date).isRequired, - } - render() { let { date, ...props } = this.props let range = Day.range(date) @@ -18,6 +14,10 @@ class Day extends React.Component { } } +Day.propTypes = { + date: PropTypes.instanceOf(Date).isRequired, +} + Day.range = date => { return [dates.startOf(date, 'day')] } diff --git a/src/DayColumn.js b/src/DayColumn.js index 3a675297b..8771f3ceb 100644 --- a/src/DayColumn.js +++ b/src/DayColumn.js @@ -14,46 +14,6 @@ import TimeSlotGroup from './TimeSlotGroup' import TimeGridEvent from './TimeGridEvent' class DayColumn extends React.Component { - static propTypes = { - events: PropTypes.array.isRequired, - step: PropTypes.number.isRequired, - date: PropTypes.instanceOf(Date).isRequired, - min: PropTypes.instanceOf(Date).isRequired, - max: PropTypes.instanceOf(Date).isRequired, - getNow: PropTypes.func.isRequired, - isNow: PropTypes.bool, - - rtl: PropTypes.bool, - - accessors: PropTypes.object.isRequired, - components: PropTypes.object.isRequired, - getters: PropTypes.object.isRequired, - localizer: PropTypes.object.isRequired, - - showMultiDayTimes: PropTypes.bool, - culture: PropTypes.string, - timeslots: PropTypes.number, - - selected: PropTypes.object, - selectable: PropTypes.oneOf([true, false, 'ignoreEvents']), - eventOffset: PropTypes.number, - longPressThreshold: PropTypes.number, - - onSelecting: PropTypes.func, - onSelectSlot: PropTypes.func.isRequired, - onSelectEvent: PropTypes.func.isRequired, - onDoubleClickEvent: PropTypes.func.isRequired, - - className: PropTypes.string, - dragThroughEvents: PropTypes.bool, - resource: PropTypes.any, - } - - static defaultProps = { - dragThroughEvents: true, - timeslots: 2, - } - state = { selecting: false, timeIndicatorPosition: null } constructor(...args) { @@ -390,4 +350,44 @@ class DayColumn extends React.Component { } } +DayColumn.propTypes = { + events: PropTypes.array.isRequired, + step: PropTypes.number.isRequired, + date: PropTypes.instanceOf(Date).isRequired, + min: PropTypes.instanceOf(Date).isRequired, + max: PropTypes.instanceOf(Date).isRequired, + getNow: PropTypes.func.isRequired, + isNow: PropTypes.bool, + + rtl: PropTypes.bool, + + accessors: PropTypes.object.isRequired, + components: PropTypes.object.isRequired, + getters: PropTypes.object.isRequired, + localizer: PropTypes.object.isRequired, + + showMultiDayTimes: PropTypes.bool, + culture: PropTypes.string, + timeslots: PropTypes.number, + + selected: PropTypes.object, + selectable: PropTypes.oneOf([true, false, 'ignoreEvents']), + eventOffset: PropTypes.number, + longPressThreshold: PropTypes.number, + + onSelecting: PropTypes.func, + onSelectSlot: PropTypes.func.isRequired, + onSelectEvent: PropTypes.func.isRequired, + onDoubleClickEvent: PropTypes.func.isRequired, + + className: PropTypes.string, + dragThroughEvents: PropTypes.bool, + resource: PropTypes.any, +} + +DayColumn.defaultProps = { + dragThroughEvents: true, + timeslots: 2, +} + export default DayColumn diff --git a/src/EventCell.js b/src/EventCell.js index 1ea0b7589..513be0353 100644 --- a/src/EventCell.js +++ b/src/EventCell.js @@ -3,25 +3,6 @@ import React from 'react' import cn from 'classnames' import dates from './utils/dates' -let propTypes = { - event: PropTypes.object.isRequired, - slotStart: PropTypes.instanceOf(Date), - slotEnd: PropTypes.instanceOf(Date), - - selected: PropTypes.bool, - isAllDay: PropTypes.bool, - continuesPrior: PropTypes.bool, - continuesAfter: PropTypes.bool, - - accessors: PropTypes.object.isRequired, - components: PropTypes.object.isRequired, - getters: PropTypes.object.isRequired, - localizer: PropTypes.object, - - onSelect: PropTypes.func, - onDoubleClick: PropTypes.func, -} - class EventCell extends React.Component { render() { let { @@ -89,6 +70,23 @@ class EventCell extends React.Component { } } -EventCell.propTypes = propTypes +EventCell.propTypes = { + event: PropTypes.object.isRequired, + slotStart: PropTypes.instanceOf(Date), + slotEnd: PropTypes.instanceOf(Date), + + selected: PropTypes.bool, + isAllDay: PropTypes.bool, + continuesPrior: PropTypes.bool, + continuesAfter: PropTypes.bool, + + accessors: PropTypes.object.isRequired, + components: PropTypes.object.isRequired, + getters: PropTypes.object.isRequired, + localizer: PropTypes.object, + + onSelect: PropTypes.func, + onDoubleClick: PropTypes.func, +} export default EventCell diff --git a/src/EventEndingRow.js b/src/EventEndingRow.js index 16e47c6b7..798d3c4c7 100644 --- a/src/EventEndingRow.js +++ b/src/EventEndingRow.js @@ -9,18 +9,11 @@ let eventsInSlot = (segments, slot) => segments.filter(seg => isSegmentInSlot(seg, slot)).length class EventEndingRow extends React.Component { - static propTypes = { - segments: PropTypes.array, - slots: PropTypes.number, - onShowMore: PropTypes.func, - ...EventRowMixin.propTypes, - } - static defaultProps = { - ...EventRowMixin.defaultProps, - } - render() { - let { segments, slotMetrics: { slots } } = this.props + let { + segments, + slotMetrics: { slots }, + } = this.props let rowSegments = eventLevels(segments).levels[0] let current = 1, @@ -104,4 +97,15 @@ class EventEndingRow extends React.Component { } } +EventEndingRow.propTypes = { + segments: PropTypes.array, + slots: PropTypes.number, + onShowMore: PropTypes.func, + ...EventRowMixin.propTypes, +} + +EventEndingRow.defaultProps = { + ...EventRowMixin.defaultProps, +} + export default EventEndingRow diff --git a/src/EventRow.js b/src/EventRow.js index f1e98a13b..772c48dff 100644 --- a/src/EventRow.js +++ b/src/EventRow.js @@ -4,15 +4,12 @@ import React from 'react' import EventRowMixin from './EventRowMixin' class EventRow extends React.Component { - static propTypes = { - segments: PropTypes.array, - ...EventRowMixin.propTypes, - } - static defaultProps = { - ...EventRowMixin.defaultProps, - } render() { - let { segments, slotMetrics: { slots }, className } = this.props + let { + segments, + slotMetrics: { slots }, + className, + } = this.props let lastEnd = 1 @@ -37,4 +34,13 @@ class EventRow extends React.Component { } } +EventRow.propTypes = { + segments: PropTypes.array, + ...EventRowMixin.propTypes, +} + +EventRow.defaultProps = { + ...EventRowMixin.defaultProps, +} + export default EventRow diff --git a/src/Month.js b/src/Month.js index b3cb07b82..58e2eab1d 100644 --- a/src/Month.js +++ b/src/Month.js @@ -22,52 +22,7 @@ import { inRange, sortEvents } from './utils/eventLevels' let eventsForWeek = (evts, start, end, accessors) => evts.filter(e => inRange(e, start, end, accessors)) -let propTypes = { - events: PropTypes.array.isRequired, - date: PropTypes.instanceOf(Date), - - min: PropTypes.instanceOf(Date), - max: PropTypes.instanceOf(Date), - - step: PropTypes.number, - getNow: PropTypes.func.isRequired, - - scrollToTime: PropTypes.instanceOf(Date), - rtl: PropTypes.bool, - width: PropTypes.number, - - accessors: PropTypes.object.isRequired, - components: PropTypes.object.isRequired, - getters: PropTypes.object.isRequired, - localizer: PropTypes.object.isRequired, - - selected: PropTypes.object, - selectable: PropTypes.oneOf([true, false, 'ignoreEvents']), - longPressThreshold: PropTypes.number, - - onNavigate: PropTypes.func, - onSelectSlot: PropTypes.func, - onSelectEvent: PropTypes.func, - onDoubleClickEvent: PropTypes.func, - onShowMore: PropTypes.func, - onDrillDown: PropTypes.func, - getDrilldownView: PropTypes.func.isRequired, - - popup: PropTypes.bool, - - popupOffset: PropTypes.oneOfType([ - PropTypes.number, - PropTypes.shape({ - x: PropTypes.number, - y: PropTypes.number, - }), - ]), -} - class MonthView extends React.Component { - static displayName = 'MonthView' - static propTypes = propTypes - constructor(...args) { super(...args) @@ -327,6 +282,48 @@ class MonthView extends React.Component { } } +MonthView.propTypes = { + events: PropTypes.array.isRequired, + date: PropTypes.instanceOf(Date), + + min: PropTypes.instanceOf(Date), + max: PropTypes.instanceOf(Date), + + step: PropTypes.number, + getNow: PropTypes.func.isRequired, + + scrollToTime: PropTypes.instanceOf(Date), + rtl: PropTypes.bool, + width: PropTypes.number, + + accessors: PropTypes.object.isRequired, + components: PropTypes.object.isRequired, + getters: PropTypes.object.isRequired, + localizer: PropTypes.object.isRequired, + + selected: PropTypes.object, + selectable: PropTypes.oneOf([true, false, 'ignoreEvents']), + longPressThreshold: PropTypes.number, + + onNavigate: PropTypes.func, + onSelectSlot: PropTypes.func, + onSelectEvent: PropTypes.func, + onDoubleClickEvent: PropTypes.func, + onShowMore: PropTypes.func, + onDrillDown: PropTypes.func, + getDrilldownView: PropTypes.func.isRequired, + + popup: PropTypes.bool, + + popupOffset: PropTypes.oneOfType([ + PropTypes.number, + PropTypes.shape({ + x: PropTypes.number, + y: PropTypes.number, + }), + ]), +} + MonthView.range = (date, { localizer }) => { let start = dates.firstVisibleDay(date, localizer) let end = dates.lastVisibleDay(date, localizer) diff --git a/src/Popup.js b/src/Popup.js index b3f3979b6..abf455148 100644 --- a/src/Popup.js +++ b/src/Popup.js @@ -8,28 +8,6 @@ import dates from './utils/dates' import EventCell from './EventCell' import { isSelected } from './utils/selection' -const propTypes = { - position: PropTypes.object, - popupOffset: PropTypes.oneOfType([ - PropTypes.number, - PropTypes.shape({ - x: PropTypes.number, - y: PropTypes.number, - }), - ]), - events: PropTypes.array, - selected: PropTypes.object, - - accessors: PropTypes.object.isRequired, - components: PropTypes.object.isRequired, - getters: PropTypes.object.isRequired, - localizer: PropTypes.object.isRequired, - onSelect: PropTypes.func, - onDoubleClick: PropTypes.func, - slotStart: PropTypes.instanceOf(Date), - slotEnd: PropTypes.number, -} - class Popup extends React.Component { componentDidMount() { let { popupOffset = 5 } = this.props, @@ -100,6 +78,26 @@ class Popup extends React.Component { } } -Popup.propTypes = propTypes +Popup.propTypes = { + position: PropTypes.object, + popupOffset: PropTypes.oneOfType([ + PropTypes.number, + PropTypes.shape({ + x: PropTypes.number, + y: PropTypes.number, + }), + ]), + events: PropTypes.array, + selected: PropTypes.object, + + accessors: PropTypes.object.isRequired, + components: PropTypes.object.isRequired, + getters: PropTypes.object.isRequired, + localizer: PropTypes.object.isRequired, + onSelect: PropTypes.func, + onDoubleClick: PropTypes.func, + slotStart: PropTypes.instanceOf(Date), + slotEnd: PropTypes.number, +} export default Popup diff --git a/src/TimeGrid.js b/src/TimeGrid.js index c3ba681d3..c96c87e5a 100644 --- a/src/TimeGrid.js +++ b/src/TimeGrid.js @@ -16,50 +16,6 @@ import { inRange, sortEvents } from './utils/eventLevels' import Resources from './utils/Resources' export default class TimeGrid extends Component { - static propTypes = { - events: PropTypes.array.isRequired, - resources: PropTypes.array, - - step: PropTypes.number, - timeslots: PropTypes.number, - range: PropTypes.arrayOf(PropTypes.instanceOf(Date)), - min: PropTypes.instanceOf(Date), - max: PropTypes.instanceOf(Date), - getNow: PropTypes.func.isRequired, - - scrollToTime: PropTypes.instanceOf(Date), - showMultiDayTimes: PropTypes.bool, - - rtl: PropTypes.bool, - width: PropTypes.number, - - accessors: PropTypes.object.isRequired, - components: PropTypes.object.isRequired, - getters: PropTypes.object.isRequired, - localizer: PropTypes.object.isRequired, - - selected: PropTypes.object, - selectable: PropTypes.oneOf([true, false, 'ignoreEvents']), - longPressThreshold: PropTypes.number, - - onNavigate: PropTypes.func, - onSelectSlot: PropTypes.func, - onSelectEnd: PropTypes.func, - onSelectStart: PropTypes.func, - onSelectEvent: PropTypes.func, - onDoubleClickEvent: PropTypes.func, - onDrillDown: PropTypes.func, - getDrilldownView: PropTypes.func.isRequired, - } - - static defaultProps = { - step: 30, - timeslots: 2, - min: dates.startOf(new Date(), 'day'), - max: dates.endOf(new Date(), 'day'), - scrollToTime: dates.startOf(new Date(), 'day'), - } - constructor(props) { super(props) @@ -94,7 +50,7 @@ export default class TimeGrid extends Component { raf.cancel(this.rafHandle) this.rafHandle = raf(this.checkOverflow) } - + componentWillUnmount() { window.removeEventListener('resize', this.handleResize) @@ -327,5 +283,51 @@ export default class TimeGrid extends Component { } } - memoizedResources = memoize((resources, accessors) => Resources(resources, accessors)) + memoizedResources = memoize((resources, accessors) => + Resources(resources, accessors) + ) +} + +TimeGrid.propTypes = { + events: PropTypes.array.isRequired, + resources: PropTypes.array, + + step: PropTypes.number, + timeslots: PropTypes.number, + range: PropTypes.arrayOf(PropTypes.instanceOf(Date)), + min: PropTypes.instanceOf(Date), + max: PropTypes.instanceOf(Date), + getNow: PropTypes.func.isRequired, + + scrollToTime: PropTypes.instanceOf(Date), + showMultiDayTimes: PropTypes.bool, + + rtl: PropTypes.bool, + width: PropTypes.number, + + accessors: PropTypes.object.isRequired, + components: PropTypes.object.isRequired, + getters: PropTypes.object.isRequired, + localizer: PropTypes.object.isRequired, + + selected: PropTypes.object, + selectable: PropTypes.oneOf([true, false, 'ignoreEvents']), + longPressThreshold: PropTypes.number, + + onNavigate: PropTypes.func, + onSelectSlot: PropTypes.func, + onSelectEnd: PropTypes.func, + onSelectStart: PropTypes.func, + onSelectEvent: PropTypes.func, + onDoubleClickEvent: PropTypes.func, + onDrillDown: PropTypes.func, + getDrilldownView: PropTypes.func.isRequired, +} + +TimeGrid.defaultProps = { + step: 30, + timeslots: 2, + min: dates.startOf(new Date(), 'day'), + max: dates.endOf(new Date(), 'day'), + scrollToTime: dates.startOf(new Date(), 'day'), } diff --git a/src/TimeGridHeader.js b/src/TimeGridHeader.js index 1562473eb..f06b86714 100644 --- a/src/TimeGridHeader.js +++ b/src/TimeGridHeader.js @@ -9,33 +9,6 @@ import Header from './Header' import { notify } from './utils/helpers' class TimeGridHeader extends React.Component { - static propTypes = { - range: PropTypes.array.isRequired, - events: PropTypes.array.isRequired, - resources: PropTypes.object, - getNow: PropTypes.func.isRequired, - isOverflowing: PropTypes.bool, - - rtl: PropTypes.bool, - width: PropTypes.number, - - localizer: PropTypes.object.isRequired, - accessors: PropTypes.object.isRequired, - components: PropTypes.object.isRequired, - getters: PropTypes.object.isRequired, - - selected: PropTypes.object, - selectable: PropTypes.oneOf([true, false, 'ignoreEvents']), - longPressThreshold: PropTypes.number, - - onSelectSlot: PropTypes.func, - onSelectEvent: PropTypes.func, - onDoubleClickEvent: PropTypes.func, - onDrillDown: PropTypes.func, - getDrilldownView: PropTypes.func.isRequired, - scrollRef: PropTypes.any, - } - handleHeaderClick = (date, view, e) => { e.preventDefault() notify(this.props.onDrillDown, [date, view]) @@ -209,4 +182,31 @@ class TimeGridHeader extends React.Component { } } +TimeGridHeader.propTypes = { + range: PropTypes.array.isRequired, + events: PropTypes.array.isRequired, + resources: PropTypes.object, + getNow: PropTypes.func.isRequired, + isOverflowing: PropTypes.bool, + + rtl: PropTypes.bool, + width: PropTypes.number, + + localizer: PropTypes.object.isRequired, + accessors: PropTypes.object.isRequired, + components: PropTypes.object.isRequired, + getters: PropTypes.object.isRequired, + + selected: PropTypes.object, + selectable: PropTypes.oneOf([true, false, 'ignoreEvents']), + longPressThreshold: PropTypes.number, + + onSelectSlot: PropTypes.func, + onSelectEvent: PropTypes.func, + onDoubleClickEvent: PropTypes.func, + onDrillDown: PropTypes.func, + getDrilldownView: PropTypes.func.isRequired, + scrollRef: PropTypes.any, +} + export default TimeGridHeader diff --git a/src/TimeGutter.js b/src/TimeGutter.js index 3824e0471..6d833bfc6 100644 --- a/src/TimeGutter.js +++ b/src/TimeGutter.js @@ -6,18 +6,6 @@ import * as TimeSlotUtils from './utils/TimeSlots' import TimeSlotGroup from './TimeSlotGroup' export default class TimeGutter extends Component { - static propTypes = { - min: PropTypes.instanceOf(Date).isRequired, - max: PropTypes.instanceOf(Date).isRequired, - timeslots: PropTypes.number.isRequired, - step: PropTypes.number.isRequired, - getNow: PropTypes.func.isRequired, - components: PropTypes.object.isRequired, - - localizer: PropTypes.object.isRequired, - resource: PropTypes.string, - } - constructor(...args) { super(...args) @@ -67,3 +55,15 @@ export default class TimeGutter extends Component { ) } } + +TimeGutter.propTypes = { + min: PropTypes.instanceOf(Date).isRequired, + max: PropTypes.instanceOf(Date).isRequired, + timeslots: PropTypes.number.isRequired, + step: PropTypes.number.isRequired, + getNow: PropTypes.func.isRequired, + components: PropTypes.object.isRequired, + + localizer: PropTypes.object.isRequired, + resource: PropTypes.string, +} diff --git a/src/TimeSlotGroup.js b/src/TimeSlotGroup.js index ab964b57a..a3f6e1d89 100644 --- a/src/TimeSlotGroup.js +++ b/src/TimeSlotGroup.js @@ -5,14 +5,6 @@ import React, { Component } from 'react' import BackgroundWrapper from './BackgroundWrapper' export default class TimeSlotGroup extends Component { - static propTypes = { - renderSlot: PropTypes.func, - group: PropTypes.array.isRequired, - resource: PropTypes.any, - components: PropTypes.object, - getters: PropTypes.object, - } - render() { const { renderSlot, @@ -41,3 +33,11 @@ export default class TimeSlotGroup extends Component { ) } } + +TimeSlotGroup.propTypes = { + renderSlot: PropTypes.func, + group: PropTypes.array.isRequired, + resource: PropTypes.any, + components: PropTypes.object, + getters: PropTypes.object, +} diff --git a/src/Toolbar.js b/src/Toolbar.js index 0fe370413..7a1ebf1ca 100644 --- a/src/Toolbar.js +++ b/src/Toolbar.js @@ -4,17 +4,11 @@ import cn from 'classnames' import { navigate } from './utils/constants' class Toolbar extends React.Component { - static propTypes = { - view: PropTypes.string.isRequired, - views: PropTypes.arrayOf(PropTypes.string).isRequired, - label: PropTypes.node.isRequired, - localizer: PropTypes.object, - onNavigate: PropTypes.func.isRequired, - onView: PropTypes.func.isRequired, - } - render() { - let { localizer: { messages }, label } = this.props + let { + localizer: { messages }, + label, + } = this.props return (
@@ -73,4 +67,13 @@ class Toolbar extends React.Component { } } +Toolbar.propTypes = { + view: PropTypes.string.isRequired, + views: PropTypes.arrayOf(PropTypes.string).isRequired, + label: PropTypes.node.isRequired, + localizer: PropTypes.object, + onNavigate: PropTypes.func.isRequired, + onView: PropTypes.func.isRequired, +} + export default Toolbar diff --git a/src/Week.js b/src/Week.js index 7e8a1508d..3d5202608 100644 --- a/src/Week.js +++ b/src/Week.js @@ -5,12 +5,6 @@ import { navigate } from './utils/constants' import TimeGrid from './TimeGrid' class Week extends React.Component { - static propTypes = { - date: PropTypes.instanceOf(Date).isRequired, - } - - static defaultProps = TimeGrid.defaultProps - render() { let { date, ...props } = this.props let range = Week.range(date, this.props) @@ -19,6 +13,12 @@ class Week extends React.Component { } } +Week.propTypes = { + date: PropTypes.instanceOf(Date).isRequired, +} + +Week.defaultProps = TimeGrid.defaultProps + Week.navigate = (date, action) => { switch (action) { case navigate.PREVIOUS: diff --git a/src/WorkWeek.js b/src/WorkWeek.js index 3db982dce..83a60741e 100644 --- a/src/WorkWeek.js +++ b/src/WorkWeek.js @@ -11,12 +11,6 @@ function workWeekRange(date, options) { } class WorkWeek extends React.Component { - static propTypes = { - date: PropTypes.instanceOf(Date).isRequired, - } - - static defaultProps = TimeGrid.defaultProps - render() { let { date, ...props } = this.props let range = workWeekRange(date, this.props) @@ -25,6 +19,12 @@ class WorkWeek extends React.Component { } } +WorkWeek.propTypes = { + date: PropTypes.instanceOf(Date).isRequired, +} + +WorkWeek.defaultProps = TimeGrid.defaultProps + WorkWeek.range = workWeekRange WorkWeek.navigate = Week.navigate diff --git a/yarn.lock b/yarn.lock index 6471a1655..f36cbad31 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2571,6 +2571,11 @@ babel-plugin-transform-react-jsx@^6.24.1: babel-plugin-syntax-jsx "^6.8.0" babel-runtime "^6.22.0" +babel-plugin-transform-react-remove-prop-types@^0.4.22: + version "0.4.22" + resolved "https://registry.yarnpkg.com/babel-plugin-transform-react-remove-prop-types/-/babel-plugin-transform-react-remove-prop-types-0.4.22.tgz#209f08958e17a003f524298efeb39e7ed74c6070" + integrity sha512-X0qLmmQ0LKGTaBTEzQkCNYr6XbjiPgA+wWux4qo5fYi8+zhcyo552KOMy/UI8jA5M2u66HlLCQ7DRxhxl6YYZQ== + babel-plugin-transform-regenerator@^6.22.0, babel-plugin-transform-regenerator@^6.26.0: version "6.26.0" resolved "https://registry.yarnpkg.com/babel-plugin-transform-regenerator/-/babel-plugin-transform-regenerator-6.26.0.tgz#e0703696fbde27f0a3efcacf8b4dca2f7b3a8f2f"