-
-
Notifications
You must be signed in to change notification settings - Fork 69
/
Copy pathTest.tsx
136 lines (126 loc) · 4.81 KB
/
Test.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
import { useRef, useState } from 'react';
import DateTimePicker from 'react-datetime-picker';
import 'react-datetime-picker/dist/DateTimePicker.css';
import 'react-calendar/dist/Calendar.css';
import 'react-clock/dist/Clock.css';
import ValidityOptions from './ValidityOptions.js';
import MaxDetailOptions from './MaxDetailOptions.js';
import LocaleOptions from './LocaleOptions.js';
import ValueOptions from './ValueOptions.js';
import ViewOptions from './ViewOptions.js';
import './Test.css';
import type { Detail, LooseValue } from './shared/types.js';
const now = new Date();
const ariaLabelProps = {
amPmAriaLabel: 'Select AM/PM',
calendarAriaLabel: 'Toggle calendar',
clearAriaLabel: 'Clear value',
dayAriaLabel: 'Day',
hourAriaLabel: 'Hour',
minuteAriaLabel: 'Minute',
monthAriaLabel: 'Month',
nativeInputAriaLabel: 'Date and time',
secondAriaLabel: 'Second',
yearAriaLabel: 'Year',
};
const placeholderProps = {
dayPlaceholder: 'dd',
hourPlaceholder: 'hh',
minutePlaceholder: 'mm',
monthPlaceholder: 'mm',
secondPlaceholder: 'ss',
yearPlaceholder: 'yyyy',
};
const nineteenNinetyFive = new Date(1995, now.getUTCMonth() + 1, 15, 12);
const fifteenthOfNextMonth = new Date(now.getUTCFullYear(), now.getUTCMonth() + 1, 15, 12);
export default function Test() {
const portalContainer = useRef<HTMLDivElement>(null);
const [disabled, setDisabled] = useState(false);
const [locale, setLocale] = useState<string>();
const [maxDate, setMaxDate] = useState<Date | undefined>(fifteenthOfNextMonth);
const [maxDetail, setMaxDetail] = useState<Detail>('minute');
const [minDate, setMinDate] = useState<Date | undefined>(nineteenNinetyFive);
const [renderInPortal, setRenderInPortal] = useState(false);
const [required, setRequired] = useState(true);
const [showLeadingZeros, setShowLeadingZeros] = useState(true);
const [showNeighboringMonth, setShowNeighboringMonth] = useState(false);
const [showWeekNumbers, setShowWeekNumbers] = useState(false);
const [value, setValue] = useState<LooseValue>(now);
return (
<div className="Test">
<header>
<h1>react-datetime-picker test page</h1>
</header>
<div className="Test__container">
<aside className="Test__container__options">
<MaxDetailOptions maxDetail={maxDetail} setMaxDetail={setMaxDetail} />
<ValidityOptions
maxDate={maxDate}
minDate={minDate}
required={required}
setMaxDate={setMaxDate}
setMinDate={setMinDate}
setRequired={setRequired}
/>
<LocaleOptions locale={locale} setLocale={setLocale} />
<ValueOptions setValue={setValue} value={value} />
<ViewOptions
disabled={disabled}
renderInPortal={renderInPortal}
setDisabled={setDisabled}
setRenderInPortal={setRenderInPortal}
setShowLeadingZeros={setShowLeadingZeros}
setShowNeighboringMonth={setShowNeighboringMonth}
setShowWeekNumbers={setShowWeekNumbers}
showLeadingZeros={showLeadingZeros}
showNeighboringMonth={showNeighboringMonth}
showWeekNumbers={showWeekNumbers}
/>
</aside>
<main className="Test__container__content">
<form
onSubmit={(event) => {
event.preventDefault();
console.warn('DateTimePicker triggered submitting the form.');
console.log(event);
}}
>
<DateTimePicker
{...ariaLabelProps}
{...placeholderProps}
calendarProps={{
className: 'myCustomCalendarClassName',
showNeighboringMonth,
showWeekNumbers,
}}
className="myCustomTimePickerClassName"
clockProps={{ className: 'myCustomClockClassName' }}
data-testid="myCustomDateTimePicker"
disabled={disabled}
locale={locale}
maxDate={maxDate}
maxDetail={maxDetail}
minDate={minDate}
name="myCustomName"
onCalendarClose={() => console.log('Calendar closed')}
onCalendarOpen={() => console.log('Calendar opened')}
onChange={setValue}
onClockClose={() => console.log('Clock closed')}
onClockOpen={() => console.log('Clock opened')}
portalContainer={renderInPortal ? portalContainer.current : undefined}
required={required}
showLeadingZeros={showLeadingZeros}
value={value}
/>
<div ref={portalContainer} />
<br />
<br />
<button id="submit" type="submit">
Submit
</button>
</form>
</main>
</div>
</div>
);
}