Skip to content

Commit f36dbf3

Browse files
committed
Move propTypes to static properties
1 parent 9f5f318 commit f36dbf3

File tree

2 files changed

+130
-130
lines changed

2 files changed

+130
-130
lines changed

src/DateTimeInput.jsx

Lines changed: 38 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,45 @@ function renderCustomInputs(placeholder, elementFunctions, allowMultipleInstance
151151

152152
const formatNumber = getNumberFormatter({ useGrouping: false });
153153

154+
const isValue = PropTypes.oneOfType([PropTypes.string, PropTypes.instanceOf(Date)]);
155+
154156
export default class DateTimeInput extends PureComponent {
157+
static defaultProps = {
158+
maxDetail: 'minute',
159+
name: 'datetime',
160+
};
161+
162+
static propTypes = {
163+
amPmAriaLabel: PropTypes.string,
164+
autoFocus: PropTypes.bool,
165+
className: PropTypes.string.isRequired,
166+
dayAriaLabel: PropTypes.string,
167+
dayPlaceholder: PropTypes.string,
168+
disabled: PropTypes.bool,
169+
format: PropTypes.string,
170+
hourAriaLabel: PropTypes.string,
171+
hourPlaceholder: PropTypes.string,
172+
isWidgetOpen: PropTypes.bool,
173+
locale: PropTypes.string,
174+
maxDate: isMaxDate,
175+
maxDetail: PropTypes.oneOf(allViews),
176+
minDate: isMinDate,
177+
minuteAriaLabel: PropTypes.string,
178+
minutePlaceholder: PropTypes.string,
179+
monthAriaLabel: PropTypes.string,
180+
monthPlaceholder: PropTypes.string,
181+
name: PropTypes.string,
182+
nativeInputAriaLabel: PropTypes.string,
183+
onChange: PropTypes.func,
184+
required: PropTypes.bool,
185+
secondAriaLabel: PropTypes.string,
186+
secondPlaceholder: PropTypes.string,
187+
showLeadingZeros: PropTypes.bool,
188+
value: PropTypes.oneOfType([isValue, PropTypes.arrayOf(isValue)]),
189+
yearAriaLabel: PropTypes.string,
190+
yearPlaceholder: PropTypes.string,
191+
};
192+
155193
static getDerivedStateFromProps(nextProps, prevState) {
156194
const { minDate, maxDate } = nextProps;
157195

@@ -846,41 +884,3 @@ export default class DateTimeInput extends PureComponent {
846884
);
847885
}
848886
}
849-
850-
DateTimeInput.defaultProps = {
851-
maxDetail: 'minute',
852-
name: 'datetime',
853-
};
854-
855-
const isValue = PropTypes.oneOfType([PropTypes.string, PropTypes.instanceOf(Date)]);
856-
857-
DateTimeInput.propTypes = {
858-
amPmAriaLabel: PropTypes.string,
859-
autoFocus: PropTypes.bool,
860-
className: PropTypes.string.isRequired,
861-
dayAriaLabel: PropTypes.string,
862-
dayPlaceholder: PropTypes.string,
863-
disabled: PropTypes.bool,
864-
format: PropTypes.string,
865-
hourAriaLabel: PropTypes.string,
866-
hourPlaceholder: PropTypes.string,
867-
isWidgetOpen: PropTypes.bool,
868-
locale: PropTypes.string,
869-
maxDate: isMaxDate,
870-
maxDetail: PropTypes.oneOf(allViews),
871-
minDate: isMinDate,
872-
minuteAriaLabel: PropTypes.string,
873-
minutePlaceholder: PropTypes.string,
874-
monthAriaLabel: PropTypes.string,
875-
monthPlaceholder: PropTypes.string,
876-
name: PropTypes.string,
877-
nativeInputAriaLabel: PropTypes.string,
878-
onChange: PropTypes.func,
879-
required: PropTypes.bool,
880-
secondAriaLabel: PropTypes.string,
881-
secondPlaceholder: PropTypes.string,
882-
showLeadingZeros: PropTypes.bool,
883-
value: PropTypes.oneOfType([isValue, PropTypes.arrayOf(isValue)]),
884-
yearAriaLabel: PropTypes.string,
885-
yearPlaceholder: PropTypes.string,
886-
};

src/DateTimePicker.jsx

Lines changed: 92 additions & 92 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,99 @@ const allViews = ['hour', 'minute', 'second'];
1616
const baseClassName = 'react-datetime-picker';
1717
const outsideActionEvents = ['mousedown', 'focusin', 'touchstart'];
1818

19+
const iconProps = {
20+
xmlns: 'http://www.w3.org/2000/svg',
21+
width: 19,
22+
height: 19,
23+
viewBox: '0 0 19 19',
24+
stroke: 'black',
25+
strokeWidth: 2,
26+
};
27+
28+
const CalendarIcon = (
29+
<svg
30+
{...iconProps}
31+
className={`${baseClassName}__calendar-button__icon ${baseClassName}__button__icon`}
32+
>
33+
<rect fill="none" height="15" width="15" x="2" y="2" />
34+
<line x1="6" x2="6" y1="0" y2="4" />
35+
<line x1="13" x2="13" y1="0" y2="4" />
36+
</svg>
37+
);
38+
39+
const ClearIcon = (
40+
<svg
41+
{...iconProps}
42+
className={`${baseClassName}__clear-button__icon ${baseClassName}__button__icon`}
43+
>
44+
<line x1="4" x2="15" y1="4" y2="15" />
45+
<line x1="15" x2="4" y1="4" y2="15" />
46+
</svg>
47+
);
48+
49+
const isValue = PropTypes.oneOfType([PropTypes.string, PropTypes.instanceOf(Date)]);
50+
1951
export default class DateTimePicker extends PureComponent {
52+
static defaultProps = {
53+
calendarIcon: CalendarIcon,
54+
clearIcon: ClearIcon,
55+
closeWidgets: true,
56+
isCalendarOpen: null,
57+
isClockOpen: null,
58+
maxDetail: 'minute',
59+
openWidgetsOnFocus: true,
60+
};
61+
62+
static propTypes = {
63+
amPmAriaLabel: PropTypes.string,
64+
autoFocus: PropTypes.bool,
65+
calendarAriaLabel: PropTypes.string,
66+
calendarClassName: PropTypes.oneOfType([PropTypes.string, PropTypes.arrayOf(PropTypes.string)]),
67+
calendarIcon: PropTypes.oneOfType([PropTypes.node, PropTypes.func]),
68+
className: PropTypes.oneOfType([PropTypes.string, PropTypes.arrayOf(PropTypes.string)]),
69+
clearAriaLabel: PropTypes.string,
70+
clearIcon: PropTypes.oneOfType([PropTypes.node, PropTypes.func]),
71+
clockClassName: PropTypes.oneOfType([PropTypes.string, PropTypes.arrayOf(PropTypes.string)]),
72+
closeWidgets: PropTypes.bool,
73+
'data-testid': PropTypes.string,
74+
dayAriaLabel: PropTypes.string,
75+
dayPlaceholder: PropTypes.string,
76+
disableCalendar: PropTypes.bool,
77+
disableClock: PropTypes.bool,
78+
disabled: PropTypes.bool,
79+
format: PropTypes.string,
80+
hourAriaLabel: PropTypes.string,
81+
hourPlaceholder: PropTypes.string,
82+
id: PropTypes.string,
83+
isCalendarOpen: PropTypes.bool,
84+
isClockOpen: PropTypes.bool,
85+
locale: PropTypes.string,
86+
maxDate: isMaxDate,
87+
maxDetail: PropTypes.oneOf(allViews),
88+
minDate: isMinDate,
89+
minuteAriaLabel: PropTypes.string,
90+
minutePlaceholder: PropTypes.string,
91+
monthAriaLabel: PropTypes.string,
92+
monthPlaceholder: PropTypes.string,
93+
name: PropTypes.string,
94+
nativeInputAriaLabel: PropTypes.string,
95+
onCalendarClose: PropTypes.func,
96+
onCalendarOpen: PropTypes.func,
97+
onChange: PropTypes.func,
98+
onClockClose: PropTypes.func,
99+
onClockOpen: PropTypes.func,
100+
onFocus: PropTypes.func,
101+
openWidgetsOnFocus: PropTypes.bool,
102+
portalContainer: PropTypes.object,
103+
required: PropTypes.bool,
104+
secondAriaLabel: PropTypes.string,
105+
secondPlaceholder: PropTypes.string,
106+
showLeadingZeros: PropTypes.bool,
107+
value: PropTypes.oneOfType([isValue, PropTypes.arrayOf(isValue)]),
108+
yearAriaLabel: PropTypes.string,
109+
yearPlaceholder: PropTypes.string,
110+
};
111+
20112
static getDerivedStateFromProps(nextProps, prevState) {
21113
const nextState = {};
22114

@@ -475,95 +567,3 @@ export default class DateTimePicker extends PureComponent {
475567
);
476568
}
477569
}
478-
479-
const iconProps = {
480-
xmlns: 'http://www.w3.org/2000/svg',
481-
width: 19,
482-
height: 19,
483-
viewBox: '0 0 19 19',
484-
stroke: 'black',
485-
strokeWidth: 2,
486-
};
487-
488-
const CalendarIcon = (
489-
<svg
490-
{...iconProps}
491-
className={`${baseClassName}__calendar-button__icon ${baseClassName}__button__icon`}
492-
>
493-
<rect fill="none" height="15" width="15" x="2" y="2" />
494-
<line x1="6" x2="6" y1="0" y2="4" />
495-
<line x1="13" x2="13" y1="0" y2="4" />
496-
</svg>
497-
);
498-
499-
const ClearIcon = (
500-
<svg
501-
{...iconProps}
502-
className={`${baseClassName}__clear-button__icon ${baseClassName}__button__icon`}
503-
>
504-
<line x1="4" x2="15" y1="4" y2="15" />
505-
<line x1="15" x2="4" y1="4" y2="15" />
506-
</svg>
507-
);
508-
509-
DateTimePicker.defaultProps = {
510-
calendarIcon: CalendarIcon,
511-
clearIcon: ClearIcon,
512-
closeWidgets: true,
513-
isCalendarOpen: null,
514-
isClockOpen: null,
515-
maxDetail: 'minute',
516-
openWidgetsOnFocus: true,
517-
};
518-
519-
const isValue = PropTypes.oneOfType([PropTypes.string, PropTypes.instanceOf(Date)]);
520-
521-
DateTimePicker.propTypes = {
522-
amPmAriaLabel: PropTypes.string,
523-
autoFocus: PropTypes.bool,
524-
calendarAriaLabel: PropTypes.string,
525-
calendarClassName: PropTypes.oneOfType([PropTypes.string, PropTypes.arrayOf(PropTypes.string)]),
526-
calendarIcon: PropTypes.oneOfType([PropTypes.node, PropTypes.func]),
527-
className: PropTypes.oneOfType([PropTypes.string, PropTypes.arrayOf(PropTypes.string)]),
528-
clearAriaLabel: PropTypes.string,
529-
clearIcon: PropTypes.oneOfType([PropTypes.node, PropTypes.func]),
530-
clockClassName: PropTypes.oneOfType([PropTypes.string, PropTypes.arrayOf(PropTypes.string)]),
531-
closeWidgets: PropTypes.bool,
532-
'data-testid': PropTypes.string,
533-
dayAriaLabel: PropTypes.string,
534-
dayPlaceholder: PropTypes.string,
535-
disableCalendar: PropTypes.bool,
536-
disableClock: PropTypes.bool,
537-
disabled: PropTypes.bool,
538-
format: PropTypes.string,
539-
hourAriaLabel: PropTypes.string,
540-
hourPlaceholder: PropTypes.string,
541-
id: PropTypes.string,
542-
isCalendarOpen: PropTypes.bool,
543-
isClockOpen: PropTypes.bool,
544-
locale: PropTypes.string,
545-
maxDate: isMaxDate,
546-
maxDetail: PropTypes.oneOf(allViews),
547-
minDate: isMinDate,
548-
minuteAriaLabel: PropTypes.string,
549-
minutePlaceholder: PropTypes.string,
550-
monthAriaLabel: PropTypes.string,
551-
monthPlaceholder: PropTypes.string,
552-
name: PropTypes.string,
553-
nativeInputAriaLabel: PropTypes.string,
554-
onCalendarClose: PropTypes.func,
555-
onCalendarOpen: PropTypes.func,
556-
onChange: PropTypes.func,
557-
onClockClose: PropTypes.func,
558-
onClockOpen: PropTypes.func,
559-
onFocus: PropTypes.func,
560-
openWidgetsOnFocus: PropTypes.bool,
561-
portalContainer: PropTypes.object,
562-
required: PropTypes.bool,
563-
secondAriaLabel: PropTypes.string,
564-
secondPlaceholder: PropTypes.string,
565-
showLeadingZeros: PropTypes.bool,
566-
value: PropTypes.oneOfType([isValue, PropTypes.arrayOf(isValue)]),
567-
yearAriaLabel: PropTypes.string,
568-
yearPlaceholder: PropTypes.string,
569-
};

0 commit comments

Comments
 (0)