Skip to content

Commit b66e624

Browse files
committed
Fix hypeserver#627 and eslint suggestions
1 parent 624c6a1 commit b66e624

File tree

11 files changed

+115
-127
lines changed

11 files changed

+115
-127
lines changed

src/accessibility/index.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
import PropTypes from 'prop-types';
22

33
export const ariaLabelsShape = PropTypes.shape({
4-
dateInput: PropTypes.objectOf(
5-
PropTypes.shape({ startDate: PropTypes.string, endDate: PropTypes.string })
6-
),
4+
dateInput: PropTypes.objectOf(PropTypes.shape({ startDate: PropTypes.string, endDate: PropTypes.string })),
75
monthPicker: PropTypes.string,
86
yearPicker: PropTypes.string,
97
prevButton: PropTypes.string,

src/components/Calendar/index.js

Lines changed: 43 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,30 @@
1-
import React, { PureComponent } from 'react';
2-
import PropTypes from 'prop-types';
3-
import { rangeShape } from '../DayCell';
4-
import Month from '../Month';
5-
import DateInput from '../DateInput';
6-
import { calcFocusDate, generateStyles, getMonthDisplayRange } from '../../utils';
71
import classnames from 'classnames';
8-
import ReactList from 'react-list';
9-
import { shallowEqualObjects } from 'shallow-equal';
102
import * as dateFns from 'date-fns';
113
import { enUS as defaultLocale } from 'date-fns/locale/en-US';
12-
import coreStyles from '../../styles';
4+
import PropTypes from 'prop-types';
5+
import React, { PureComponent } from 'react';
6+
import ReactList from 'react-list';
7+
import { shallowEqualObjects } from 'shallow-equal';
138
import { ariaLabelsShape } from '../../accessibility';
9+
import coreStyles from '../../styles';
10+
import { calcFocusDate, generateStyles, getMonthDisplayRange, restrictMinMaxDate } from '../../utils';
11+
import DateInput from '../DateInput';
12+
import { rangeShape } from '../DayCell';
13+
import Month from '../Month';
1414

1515
class Calendar extends PureComponent {
1616
constructor(props, context) {
1717
super(props, context);
1818
this.dateOptions = { locale: props.locale };
19-
if (props.weekStartsOn !== undefined) this.dateOptions.weekStartsOn = props.weekStartsOn;
19+
if (props.weekStartsOn !== undefined) {
20+
this.dateOptions.weekStartsOn = props.weekStartsOn;
21+
}
2022
this.styles = generateStyles([coreStyles, props.classNames]);
2123
this.listSizeCache = {};
2224
this.isFirstRender = true;
25+
const ranges = restrictMinMaxDate(props.ranges, props.minDate, props.maxDate);
2326
this.state = {
27+
ranges,
2428
monthNames: this.getMonthNames(),
2529
focusedDate: calcFocusDate(null, props),
2630
drag: {
@@ -70,11 +74,7 @@ class Calendar extends PureComponent {
7074
this.setState({ focusedDate: date });
7175
return;
7276
}
73-
const targetMonthIndex = dateFns.differenceInCalendarMonths(
74-
date,
75-
props.minDate,
76-
this.dateOptions
77-
);
77+
const targetMonthIndex = dateFns.differenceInCalendarMonths(date, props.minDate, this.dateOptions);
7878
const visibleMonths = this.list.getVisibleRange();
7979
if (preventUnnecessary && visibleMonths.includes(targetMonthIndex)) return;
8080
this.isFirstRender = true;
@@ -120,13 +120,9 @@ class Calendar extends PureComponent {
120120
this.updateShownDate(this.props);
121121
}
122122

123-
if (
124-
prevProps.locale !== this.props.locale ||
125-
prevProps.weekStartsOn !== this.props.weekStartsOn
126-
) {
123+
if (prevProps.locale !== this.props.locale || prevProps.weekStartsOn !== this.props.weekStartsOn) {
127124
this.dateOptions = { locale: this.props.locale };
128-
if (this.props.weekStartsOn !== undefined)
129-
this.dateOptions.weekStartsOn = this.props.weekStartsOn;
125+
if (this.props.weekStartsOn !== undefined) this.dateOptions.weekStartsOn = this.props.weekStartsOn;
130126
this.setState({
131127
monthNames: this.getMonthNames(),
132128
});
@@ -182,7 +178,8 @@ class Calendar extends PureComponent {
182178
type="button"
183179
className={classnames(styles.nextPrevButton, styles.prevButton)}
184180
onClick={() => changeShownDate(-1, 'monthOffset')}
185-
aria-label={ariaLabels.prevButton}>
181+
aria-label={ariaLabels.prevButton}
182+
>
186183
<i />
187184
</button>
188185
) : null}
@@ -192,7 +189,8 @@ class Calendar extends PureComponent {
192189
<select
193190
value={focusedDate.getMonth()}
194191
onChange={e => changeShownDate(e.target.value, 'setMonth')}
195-
aria-label={ariaLabels.monthPicker}>
192+
aria-label={ariaLabels.monthPicker}
193+
>
196194
{this.state.monthNames.map((monthName, i) => (
197195
<option key={i} value={i}>
198196
{monthName}
@@ -205,17 +203,16 @@ class Calendar extends PureComponent {
205203
<select
206204
value={focusedDate.getFullYear()}
207205
onChange={e => changeShownDate(e.target.value, 'setYear')}
208-
aria-label={ariaLabels.yearPicker}>
209-
{new Array(upperYearLimit - lowerYearLimit + 1)
210-
.fill(upperYearLimit)
211-
.map((val, i) => {
212-
const year = val - i;
213-
return (
214-
<option key={year} value={year}>
215-
{year}
216-
</option>
217-
);
218-
})}
206+
aria-label={ariaLabels.yearPicker}
207+
>
208+
{new Array(upperYearLimit - lowerYearLimit + 1).fill(upperYearLimit).map((val, i) => {
209+
const year = val - i;
210+
return (
211+
<option key={year} value={year}>
212+
{year}
213+
</option>
214+
);
215+
})}
219216
</select>
220217
</span>
221218
</span>
@@ -229,7 +226,8 @@ class Calendar extends PureComponent {
229226
type="button"
230227
className={classnames(styles.nextPrevButton, styles.nextButton)}
231228
onClick={() => changeShownDate(+1, 'monthOffset')}
232-
aria-label={ariaLabels.nextButton}>
229+
aria-label={ariaLabels.nextButton}
230+
>
233231
<i />
234232
</button>
235233
) : null}
@@ -257,28 +255,24 @@ class Calendar extends PureComponent {
257255
const {
258256
focusedRange,
259257
color,
260-
ranges,
261258
rangeColors,
262259
dateDisplayFormat,
263260
editableDateInputs,
264261
startDatePlaceholder,
265262
endDatePlaceholder,
266263
ariaLabels,
267264
} = this.props;
265+
const { ranges } = this.state;
268266

269267
const defaultColor = rangeColors[focusedRange[0]] || color;
270268
const styles = this.styles;
271269

272270
return (
273271
<div className={styles.dateDisplayWrapper}>
274272
{ranges.map((range, i) => {
275-
if (range.showDateDisplay === false || (range.disabled && !range.showDateDisplay))
276-
return null;
273+
if (range.showDateDisplay === false || (range.disabled && !range.showDateDisplay)) return null;
277274
return (
278-
<div
279-
className={styles.dateDisplay}
280-
key={i}
281-
style={{ color: range.color || defaultColor }}>
275+
<div className={styles.dateDisplay} key={i} style={{ color: range.color || defaultColor }}>
282276
<DateInput
283277
className={classnames(styles.dateDisplayItem, {
284278
[styles.dateDisplayItemActive]: focusedRange[0] === i && focusedRange[1] === 0,
@@ -403,7 +397,7 @@ class Calendar extends PureComponent {
403397
const isVertical = direction === 'vertical';
404398
const monthAndYearRenderer = navigatorRenderer || this.renderMonthAndYear;
405399

406-
const ranges = this.props.ranges.map((range, i) => ({
400+
const ranges = this.state.ranges.map((range, i) => ({
407401
...range,
408402
color: range.color || rangeColors[i] || color,
409403
}));
@@ -413,7 +407,8 @@ class Calendar extends PureComponent {
413407
onMouseUp={() => this.setState({ drag: { status: false, range: {} } })}
414408
onMouseLeave={() => {
415409
this.setState({ drag: { status: false, range: {} } });
416-
}}>
410+
}}
411+
>
417412
{showDateDisplay && this.renderDateDisplay()}
418413
{monthAndYearRenderer(focusedDate, this.changeShownDate, this.props)}
419414
{scroll.enabled ? (
@@ -429,7 +424,8 @@ class Calendar extends PureComponent {
429424
width: scrollArea.calendarWidth + 11,
430425
height: scrollArea.calendarHeight + 11,
431426
}}
432-
onScroll={this.handleScroll}>
427+
onScroll={this.handleScroll}
428+
>
433429
<ReactList
434430
length={dateFns.differenceInCalendarMonths(
435431
dateFns.endOfMonth(maxDate),
@@ -478,7 +474,8 @@ class Calendar extends PureComponent {
478474
className={classnames(
479475
this.styles.months,
480476
isVertical ? this.styles.monthsVertical : this.styles.monthsHorizontal
481-
)}>
477+
)}
478+
>
482479
{new Array(this.props.months).fill(null).map((_, i) => {
483480
let monthStep = dateFns.addMonths(this.state.focusedDate, i);
484481
if (this.props.calendarFocus === 'backwards') {

src/components/DateRange/index.js

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,28 @@
1-
import React, { Component } from 'react';
1+
import classnames from 'classnames';
22
import PropTypes from 'prop-types';
3+
import React, { Component } from 'react';
4+
import coreStyles from '../../styles';
5+
import { calcNewSelection, findNextRangeIndex, generateStyles, restrictMinMaxDate } from '../../utils';
36
import Calendar from '../Calendar';
47
import { rangeShape } from '../DayCell';
5-
import { calcNewSelection, findNextRangeIndex, generateStyles } from '../../utils';
6-
import classnames from 'classnames';
7-
import coreStyles from '../../styles';
88

99
class DateRange extends Component {
1010
constructor(props, context) {
1111
super(props, context);
12+
const ranges = restrictMinMaxDate(props.ranges, props.minDate, props.maxDate);
1213
this.state = {
13-
focusedRange: props.initialFocusedRange || [findNextRangeIndex(props.ranges), 0],
14+
ranges,
15+
focusedRange: props.initialFocusedRange || [findNextRangeIndex(ranges), 0],
1416
preview: null,
1517
};
1618
this.styles = generateStyles([coreStyles, props.classNames]);
1719
}
1820
calcNewSelection = (value, isSingleValue = true) => {
1921
const focusedRange = this.props.focusedRange || this.state.focusedRange;
20-
const {
21-
ranges,
22-
onChange,
23-
maxDate,
24-
moveRangeOnFirstSelection,
25-
retainEndDateOnFirstSelection,
26-
disabledDates,
27-
} = this.props;
22+
const { onChange, maxDate, moveRangeOnFirstSelection, retainEndDateOnFirstSelection, disabledDates } =
23+
this.props;
24+
const { ranges } = this.state;
25+
2826
return calcNewSelection(
2927
value,
3028
isSingleValue,
@@ -38,6 +36,7 @@ class DateRange extends Component {
3836
);
3937
};
4038
setSelection = (value, isSingleValue) => {
39+
console.log('uma setSelection', value);
4140
const { onChange, ranges, onRangeFocusChange } = this.props;
4241
const focusedRange = this.props.focusedRange || this.state.focusedRange;
4342
const focusedRangeIndex = focusedRange[0];

src/components/DateRangePicker/README.md

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ const [state, setState] = useState([
1616

1717
<DateRangePicker
1818
onChange={item => setState([item.selection])}
19-
showSelectionPreview={true}
2019
moveRangeOnFirstSelection={false}
2120
months={2}
2221
ranges={state}
@@ -40,7 +39,6 @@ const [state, setState] = useState([
4039

4140
<DateRangePicker
4241
onChange={item => setState([item.selection])}
43-
showSelectionPreview={true}
4442
moveRangeOnFirstSelection={false}
4543
months={2}
4644
ranges={state}
@@ -132,7 +130,6 @@ const [state, setState] = useState({
132130

133131
<DateRangePicker
134132
onChange={item => setState({ ...state, ...item })}
135-
showSelectionPreview={true}
136133
moveRangeOnFirstSelection={false}
137134
months={2}
138135
ranges={[state.selection1, state.selection2]}
@@ -197,7 +194,6 @@ function customDayContent(day) {
197194

198195
<DateRangePicker
199196
onChange={item => setState({ ...state, ...item })}
200-
showSelectionPreview={true}
201197
moveRangeOnFirstSelection={false}
202198
months={2}
203199
ranges={[state.selection1, state.selection2]}

src/components/DateRangePicker/index.js

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,18 @@
1-
import React, { Component } from 'react';
1+
import classnames from 'classnames';
22
import PropTypes from 'prop-types';
3+
import React, { Component } from 'react';
4+
import coreStyles from '../../styles';
5+
import { findNextRangeIndex, generateStyles, restrictMinMaxDate } from '../../utils';
36
import DateRange from '../DateRange';
47
import DefinedRange from '../DefinedRange';
5-
import { findNextRangeIndex, generateStyles } from '../../utils';
6-
import classnames from 'classnames';
7-
import coreStyles from '../../styles';
88

99
class DateRangePicker extends Component {
1010
constructor(props) {
1111
super(props);
12+
const ranges = restrictMinMaxDate(props.ranges, props.minDate, props.maxDate);
1213
this.state = {
13-
focusedRange: [findNextRangeIndex(props.ranges), 0],
14+
ranges,
15+
focusedRange: [findNextRangeIndex(ranges), 0],
1416
};
1517
this.styles = generateStyles([coreStyles, props.classNames]);
1618
}
@@ -33,6 +35,7 @@ class DateRangePicker extends Component {
3335
onRangeFocusChange={focusedRange => this.setState({ focusedRange })}
3436
focusedRange={focusedRange}
3537
{...this.props}
38+
ranges={this.state.ranges}
3639
ref={t => (this.dateRange = t)}
3740
className={undefined}
3841
/>

src/components/DayCell/index.js

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
/* eslint-disable no-fallthrough */
2-
import React, { Component } from 'react';
3-
import PropTypes from 'prop-types';
42
import classnames from 'classnames';
53
import * as dateFns from 'date-fns';
4+
import PropTypes from 'prop-types';
5+
import React, { Component } from 'react';
66

77
class DayCell extends Component {
88
constructor(props, context) {
@@ -88,8 +88,7 @@ class DayCell extends Component {
8888
const startDate = preview.startDate ? dateFns.endOfDay(preview.startDate) : null;
8989
const endDate = preview.endDate ? dateFns.startOfDay(preview.endDate) : null;
9090
const isInRange =
91-
(!startDate || dateFns.isAfter(day, startDate)) &&
92-
(!endDate || dateFns.isBefore(day, endDate));
91+
(!startDate || dateFns.isAfter(day, startDate)) && (!endDate || dateFns.isBefore(day, endDate));
9392
const isStartEdge = !isInRange && dateFns.isSameDay(day, startDate);
9493
const isEndEdge = !isInRange && dateFns.isSameDay(day, endDate);
9594
return (
@@ -107,9 +106,7 @@ class DayCell extends Component {
107106
const { styles, ranges, day } = this.props;
108107
if (this.props.displayMode === 'date') {
109108
let isSelected = dateFns.isSameDay(this.props.day, this.props.date);
110-
return isSelected ? (
111-
<span className={styles.selected} style={{ color: this.props.color }} />
112-
) : null;
109+
return isSelected ? <span className={styles.selected} style={{ color: this.props.color }} /> : null;
113110
}
114111

115112
const inRanges = ranges.reduce((result, range) => {
@@ -121,8 +118,7 @@ class DayCell extends Component {
121118
startDate = startDate ? dateFns.endOfDay(startDate) : null;
122119
endDate = endDate ? dateFns.startOfDay(endDate) : null;
123120
const isInRange =
124-
(!startDate || dateFns.isAfter(day, startDate)) &&
125-
(!endDate || dateFns.isBefore(day, endDate));
121+
(!startDate || dateFns.isAfter(day, startDate)) && (!endDate || dateFns.isBefore(day, endDate));
126122
const isStartEdge = !isInRange && dateFns.isSameDay(day, startDate);
127123
const isEndEdge = !isInRange && dateFns.isSameDay(day, endDate);
128124
if (isInRange || isStartEdge || isEndEdge) {
@@ -168,7 +164,8 @@ class DayCell extends Component {
168164
onKeyUp={this.handleKeyEvent}
169165
className={this.getClassNames(this.props.styles)}
170166
{...(this.props.disabled || this.props.isPassive ? { tabIndex: -1 } : {})}
171-
style={{ color: this.props.color }}>
167+
style={{ color: this.props.color }}
168+
>
172169
{this.renderSelectionPlaceholders()}
173170
{this.renderPreviewPlaceholder()}
174171
<span className={this.props.styles.dayNumber}>

0 commit comments

Comments
 (0)