Skip to content

Commit 66a17ac

Browse files
committed
Move propTypes to static properties
1 parent 281563f commit 66a17ac

File tree

2 files changed

+113
-113
lines changed

2 files changed

+113
-113
lines changed

src/DateInput.jsx

Lines changed: 33 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,40 @@ function renderCustomInputs(placeholder, elementFunctions, allowMultipleInstance
149149
}, []);
150150
}
151151

152+
const isValue = PropTypes.oneOfType([PropTypes.string, PropTypes.instanceOf(Date)]);
153+
152154
export default class DateInput extends PureComponent {
155+
static defaultProps = {
156+
maxDetail: 'month',
157+
name: 'date',
158+
returnValue: 'start',
159+
};
160+
161+
static propTypes = {
162+
autoFocus: PropTypes.bool,
163+
className: PropTypes.string.isRequired,
164+
dayAriaLabel: PropTypes.string,
165+
dayPlaceholder: PropTypes.string,
166+
disabled: PropTypes.bool,
167+
format: PropTypes.string,
168+
isCalendarOpen: PropTypes.bool,
169+
locale: PropTypes.string,
170+
maxDate: isMaxDate,
171+
maxDetail: PropTypes.oneOf(allViews),
172+
minDate: isMinDate,
173+
monthAriaLabel: PropTypes.string,
174+
monthPlaceholder: PropTypes.string,
175+
name: PropTypes.string,
176+
nativeInputAriaLabel: PropTypes.string,
177+
onChange: PropTypes.func,
178+
required: PropTypes.bool,
179+
returnValue: PropTypes.oneOf(['start', 'end', 'range']),
180+
showLeadingZeros: PropTypes.bool,
181+
value: PropTypes.oneOfType([isValue, PropTypes.arrayOf(isValue)]),
182+
yearAriaLabel: PropTypes.string,
183+
yearPlaceholder: PropTypes.string,
184+
};
185+
153186
static getDerivedStateFromProps(nextProps, prevState) {
154187
const { minDate, maxDate, maxDetail } = nextProps;
155188

@@ -613,36 +646,3 @@ export default class DateInput extends PureComponent {
613646
);
614647
}
615648
}
616-
617-
DateInput.defaultProps = {
618-
maxDetail: 'month',
619-
name: 'date',
620-
returnValue: 'start',
621-
};
622-
623-
const isValue = PropTypes.oneOfType([PropTypes.string, PropTypes.instanceOf(Date)]);
624-
625-
DateInput.propTypes = {
626-
autoFocus: PropTypes.bool,
627-
className: PropTypes.string.isRequired,
628-
dayAriaLabel: PropTypes.string,
629-
dayPlaceholder: PropTypes.string,
630-
disabled: PropTypes.bool,
631-
format: PropTypes.string,
632-
isCalendarOpen: PropTypes.bool,
633-
locale: PropTypes.string,
634-
maxDate: isMaxDate,
635-
maxDetail: PropTypes.oneOf(allViews),
636-
minDate: isMinDate,
637-
monthAriaLabel: PropTypes.string,
638-
monthPlaceholder: PropTypes.string,
639-
name: PropTypes.string,
640-
nativeInputAriaLabel: PropTypes.string,
641-
onChange: PropTypes.func,
642-
required: PropTypes.bool,
643-
returnValue: PropTypes.oneOf(['start', 'end', 'range']),
644-
showLeadingZeros: PropTypes.bool,
645-
value: PropTypes.oneOfType([isValue, PropTypes.arrayOf(isValue)]),
646-
yearAriaLabel: PropTypes.string,
647-
yearPlaceholder: PropTypes.string,
648-
};

src/DatePicker.jsx

Lines changed: 80 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,87 @@ const baseClassName = 'react-date-picker';
1414
const outsideActionEvents = ['mousedown', 'focusin', 'touchstart'];
1515
const allViews = ['century', 'decade', 'year', 'month'];
1616

17+
const iconProps = {
18+
xmlns: 'http://www.w3.org/2000/svg',
19+
width: 19,
20+
height: 19,
21+
viewBox: '0 0 19 19',
22+
stroke: 'black',
23+
strokeWidth: 2,
24+
};
25+
26+
const CalendarIcon = (
27+
<svg
28+
{...iconProps}
29+
className={`${baseClassName}__calendar-button__icon ${baseClassName}__button__icon`}
30+
>
31+
<rect fill="none" height="15" width="15" x="2" y="2" />
32+
<line x1="6" x2="6" y1="0" y2="4" />
33+
<line x1="13" x2="13" y1="0" y2="4" />
34+
</svg>
35+
);
36+
37+
const ClearIcon = (
38+
<svg
39+
{...iconProps}
40+
className={`${baseClassName}__clear-button__icon ${baseClassName}__button__icon`}
41+
>
42+
<line x1="4" x2="15" y1="4" y2="15" />
43+
<line x1="15" x2="4" y1="4" y2="15" />
44+
</svg>
45+
);
46+
47+
const isValue = PropTypes.oneOfType([PropTypes.string, PropTypes.instanceOf(Date)]);
48+
1749
export default class DatePicker extends PureComponent {
50+
static defaultProps = {
51+
calendarIcon: CalendarIcon,
52+
clearIcon: ClearIcon,
53+
closeCalendar: true,
54+
isOpen: null,
55+
openCalendarOnFocus: true,
56+
returnValue: 'start',
57+
};
58+
59+
static propTypes = {
60+
autoFocus: PropTypes.bool,
61+
calendarAriaLabel: PropTypes.string,
62+
calendarClassName: PropTypes.oneOfType([PropTypes.string, PropTypes.arrayOf(PropTypes.string)]),
63+
calendarIcon: PropTypes.oneOfType([PropTypes.node, PropTypes.func]),
64+
className: PropTypes.oneOfType([PropTypes.string, PropTypes.arrayOf(PropTypes.string)]),
65+
clearAriaLabel: PropTypes.string,
66+
clearIcon: PropTypes.oneOfType([PropTypes.node, PropTypes.func]),
67+
closeCalendar: PropTypes.bool,
68+
'data-testid': PropTypes.string,
69+
dayAriaLabel: PropTypes.string,
70+
dayPlaceholder: PropTypes.string,
71+
disableCalendar: PropTypes.bool,
72+
disabled: PropTypes.bool,
73+
format: PropTypes.string,
74+
id: PropTypes.string,
75+
isOpen: PropTypes.bool,
76+
locale: PropTypes.string,
77+
maxDate: isMaxDate,
78+
maxDetail: PropTypes.oneOf(allViews),
79+
minDate: isMinDate,
80+
monthAriaLabel: PropTypes.string,
81+
monthPlaceholder: PropTypes.string,
82+
name: PropTypes.string,
83+
nativeInputAriaLabel: PropTypes.string,
84+
onCalendarClose: PropTypes.func,
85+
onCalendarOpen: PropTypes.func,
86+
onChange: PropTypes.func,
87+
onFocus: PropTypes.func,
88+
openCalendarOnFocus: PropTypes.bool,
89+
portalContainer: PropTypes.object,
90+
required: PropTypes.bool,
91+
returnValue: PropTypes.oneOf(['start', 'end', 'range']),
92+
showLeadingZeros: PropTypes.bool,
93+
value: PropTypes.oneOfType([isValue, PropTypes.arrayOf(isValue)]),
94+
yearAriaLabel: PropTypes.string,
95+
yearPlaceholder: PropTypes.string,
96+
};
97+
1898
static getDerivedStateFromProps(nextProps, prevState) {
1999
if (nextProps.isOpen !== prevState.isOpenProps) {
20100
return {
@@ -314,83 +394,3 @@ export default class DatePicker extends PureComponent {
314394
);
315395
}
316396
}
317-
318-
const iconProps = {
319-
xmlns: 'http://www.w3.org/2000/svg',
320-
width: 19,
321-
height: 19,
322-
viewBox: '0 0 19 19',
323-
stroke: 'black',
324-
strokeWidth: 2,
325-
};
326-
327-
const CalendarIcon = (
328-
<svg
329-
{...iconProps}
330-
className={`${baseClassName}__calendar-button__icon ${baseClassName}__button__icon`}
331-
>
332-
<rect fill="none" height="15" width="15" x="2" y="2" />
333-
<line x1="6" x2="6" y1="0" y2="4" />
334-
<line x1="13" x2="13" y1="0" y2="4" />
335-
</svg>
336-
);
337-
338-
const ClearIcon = (
339-
<svg
340-
{...iconProps}
341-
className={`${baseClassName}__clear-button__icon ${baseClassName}__button__icon`}
342-
>
343-
<line x1="4" x2="15" y1="4" y2="15" />
344-
<line x1="15" x2="4" y1="4" y2="15" />
345-
</svg>
346-
);
347-
348-
DatePicker.defaultProps = {
349-
calendarIcon: CalendarIcon,
350-
clearIcon: ClearIcon,
351-
closeCalendar: true,
352-
isOpen: null,
353-
openCalendarOnFocus: true,
354-
returnValue: 'start',
355-
};
356-
357-
const isValue = PropTypes.oneOfType([PropTypes.string, PropTypes.instanceOf(Date)]);
358-
359-
DatePicker.propTypes = {
360-
autoFocus: PropTypes.bool,
361-
calendarAriaLabel: PropTypes.string,
362-
calendarClassName: PropTypes.oneOfType([PropTypes.string, PropTypes.arrayOf(PropTypes.string)]),
363-
calendarIcon: PropTypes.oneOfType([PropTypes.node, PropTypes.func]),
364-
className: PropTypes.oneOfType([PropTypes.string, PropTypes.arrayOf(PropTypes.string)]),
365-
clearAriaLabel: PropTypes.string,
366-
clearIcon: PropTypes.oneOfType([PropTypes.node, PropTypes.func]),
367-
closeCalendar: PropTypes.bool,
368-
'data-testid': PropTypes.string,
369-
dayAriaLabel: PropTypes.string,
370-
dayPlaceholder: PropTypes.string,
371-
disableCalendar: PropTypes.bool,
372-
disabled: PropTypes.bool,
373-
format: PropTypes.string,
374-
id: PropTypes.string,
375-
isOpen: PropTypes.bool,
376-
locale: PropTypes.string,
377-
maxDate: isMaxDate,
378-
maxDetail: PropTypes.oneOf(allViews),
379-
minDate: isMinDate,
380-
monthAriaLabel: PropTypes.string,
381-
monthPlaceholder: PropTypes.string,
382-
name: PropTypes.string,
383-
nativeInputAriaLabel: PropTypes.string,
384-
onCalendarClose: PropTypes.func,
385-
onCalendarOpen: PropTypes.func,
386-
onChange: PropTypes.func,
387-
onFocus: PropTypes.func,
388-
openCalendarOnFocus: PropTypes.bool,
389-
portalContainer: PropTypes.object,
390-
required: PropTypes.bool,
391-
returnValue: PropTypes.oneOf(['start', 'end', 'range']),
392-
showLeadingZeros: PropTypes.bool,
393-
value: PropTypes.oneOfType([isValue, PropTypes.arrayOf(isValue)]),
394-
yearAriaLabel: PropTypes.string,
395-
yearPlaceholder: PropTypes.string,
396-
};

0 commit comments

Comments
 (0)