envoc-form 5.0.8 → 5.0.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3079 -1068
- package/es/DatePicker/DatePickerGroup.d.ts +1 -1
- package/es/DatePicker/DatePickerGroup.js +4 -3
- package/es/DateTimePicker/DateTimePickerGroup.d.ts +12 -0
- package/es/DateTimePicker/DateTimePickerGroup.js +87 -0
- package/es/DateTimePicker/DateTimePickerHelper.d.ts +3 -0
- package/es/DateTimePicker/DateTimePickerHelper.js +1 -0
- package/es/DateTimePicker/StringDateTimePickerGroup.d.ts +9 -0
- package/es/DateTimePicker/StringDateTimePickerGroup.js +53 -0
- package/es/Input/InputGroup.d.ts +1 -1
- package/es/Input/InputGroup.js +2 -2
- package/es/index.d.ts +4 -0
- package/es/index.js +3 -0
- package/lib/DatePicker/DatePickerGroup.d.ts +1 -1
- package/lib/DatePicker/DatePickerGroup.js +4 -3
- package/lib/DateTimePicker/DateTimePickerGroup.d.ts +12 -0
- package/lib/DateTimePicker/DateTimePickerGroup.js +93 -0
- package/lib/DateTimePicker/DateTimePickerHelper.d.ts +3 -0
- package/lib/DateTimePicker/DateTimePickerHelper.js +2 -0
- package/lib/DateTimePicker/StringDateTimePickerGroup.d.ts +9 -0
- package/lib/DateTimePicker/StringDateTimePickerGroup.js +59 -0
- package/lib/Input/InputGroup.d.ts +1 -1
- package/lib/Input/InputGroup.js +2 -2
- package/lib/index.d.ts +4 -0
- package/lib/index.js +6 -1
- package/package.json +4 -3
- package/src/DatePicker/DatePickerGroup.tsx +6 -0
- package/src/DateTimePicker/DateTimePicker.test.tsx +243 -0
- package/src/DateTimePicker/DateTimePickerGroup.tsx +116 -0
- package/src/DateTimePicker/DateTimePickerHelper.ts +4 -0
- package/src/DateTimePicker/StringDateTimePickerGroup.tsx +61 -0
- package/src/DateTimePicker/__snapshots__/DateTimePicker.test.tsx.snap +217 -0
- package/src/Input/InputGroup.tsx +3 -0
- package/src/__Tests__/FormTestBase.tsx +1 -0
- package/src/index.ts +7 -0
@@ -0,0 +1,243 @@
|
|
1
|
+
import React from 'react';
|
2
|
+
import { render } from '@testing-library/react';
|
3
|
+
import StringDateTimePickerGroup from './StringDateTimePickerGroup';
|
4
|
+
import FormTestBase, { PersonDto } from '../__Tests__/FormTestBase';
|
5
|
+
|
6
|
+
//hack so the datetimepicker internals don't complain about this not existing in the context of jest
|
7
|
+
HTMLCanvasElement.prototype.getContext = () => null;
|
8
|
+
|
9
|
+
describe('StringDateTimePickerGroup', () => {
|
10
|
+
it('renders without crashing', () => {
|
11
|
+
render(
|
12
|
+
<FormTestBase>
|
13
|
+
{({ Field }) => (
|
14
|
+
<Field
|
15
|
+
name="createdDateTime"
|
16
|
+
Component={StringDateTimePickerGroup}
|
17
|
+
label="Created Date Time"
|
18
|
+
monthPlaceholder="mm"
|
19
|
+
dayPlaceholder="dd"
|
20
|
+
yearPlaceholder="yyyy"
|
21
|
+
disableClock
|
22
|
+
maxDate={new Date('9/23/2023')}
|
23
|
+
minDate={new Date('6/22/2022')}
|
24
|
+
/>
|
25
|
+
)}
|
26
|
+
</FormTestBase>
|
27
|
+
);
|
28
|
+
});
|
29
|
+
|
30
|
+
it('has matching snapshot', () => {
|
31
|
+
const renderResult = render(
|
32
|
+
<FormTestBase>
|
33
|
+
{({ Field }) => (
|
34
|
+
<Field
|
35
|
+
name="createdDateTime"
|
36
|
+
Component={StringDateTimePickerGroup}
|
37
|
+
label="Created Date Time"
|
38
|
+
monthPlaceholder="mm"
|
39
|
+
dayPlaceholder="dd"
|
40
|
+
yearPlaceholder="yyyy"
|
41
|
+
disableClock
|
42
|
+
maxDate={new Date('9/23/2023')}
|
43
|
+
minDate={new Date('6/22/2022')}
|
44
|
+
/>
|
45
|
+
)}
|
46
|
+
</FormTestBase>
|
47
|
+
);
|
48
|
+
expect(renderResult.asFragment()).toMatchSnapshot();
|
49
|
+
});
|
50
|
+
|
51
|
+
it('does not render with initial date-only string and throws exception', () => {
|
52
|
+
const dateOnlyString = '2024-09-04';
|
53
|
+
const personDtoWithDateOnlyString: PersonDto = {
|
54
|
+
createdDateTime: dateOnlyString,
|
55
|
+
};
|
56
|
+
|
57
|
+
try {
|
58
|
+
render(
|
59
|
+
<FormTestBase initialValues={personDtoWithDateOnlyString}>
|
60
|
+
{({ Field }) => (
|
61
|
+
<Field
|
62
|
+
name="createdDateTime"
|
63
|
+
Component={StringDateTimePickerGroup}
|
64
|
+
label="Created Date Time"
|
65
|
+
monthPlaceholder="mm"
|
66
|
+
dayPlaceholder="dd"
|
67
|
+
yearPlaceholder="yyyy"
|
68
|
+
disableClock
|
69
|
+
/>
|
70
|
+
)}
|
71
|
+
</FormTestBase>
|
72
|
+
);
|
73
|
+
|
74
|
+
fail('Expected an exception to be thrown for date-only string');
|
75
|
+
} catch (error: any) {
|
76
|
+
// Assert that the error message matches the expected message
|
77
|
+
expect(error.message).toEqual(
|
78
|
+
`Invalid "date time" value of ${dateOnlyString} provided to DateTimePickerGroup component. Please provide ISO 8601 string that includes the time zone designator. Sample strings: 2022-09-24T:08:54:12+00:00, 2022-09-24T:08:54:12Z, 2022-09-24T:08:54:12.123-05:00`
|
79
|
+
);
|
80
|
+
}
|
81
|
+
});
|
82
|
+
|
83
|
+
it('renders with ISO UTC date time string taking browser timezone into account', () => {
|
84
|
+
const isoUTCDateTimeString = '2024-04-09T21:00:24.670Z';
|
85
|
+
const personDtoWithDateTimeString: PersonDto = {
|
86
|
+
createdDateTime: isoUTCDateTimeString,
|
87
|
+
};
|
88
|
+
|
89
|
+
render(
|
90
|
+
<FormTestBase initialValues={personDtoWithDateTimeString}>
|
91
|
+
{({ Field }) => (
|
92
|
+
<Field
|
93
|
+
name="createdDateTime"
|
94
|
+
Component={StringDateTimePickerGroup}
|
95
|
+
label="Created Date Time"
|
96
|
+
monthPlaceholder="mm"
|
97
|
+
dayPlaceholder="dd"
|
98
|
+
yearPlaceholder="yyyy"
|
99
|
+
disableClock
|
100
|
+
/>
|
101
|
+
)}
|
102
|
+
</FormTestBase>
|
103
|
+
);
|
104
|
+
|
105
|
+
const dateTimePickerInputComponent = document.querySelector(
|
106
|
+
'input[name="datetime"][type="datetime-local"]'
|
107
|
+
);
|
108
|
+
const utcDate = new Date(isoUTCDateTimeString);
|
109
|
+
const localDateTimeString =
|
110
|
+
convertToDateTimePickerComponentValueString(utcDate);
|
111
|
+
|
112
|
+
// Assert that no exception is thrown during rendering
|
113
|
+
expect(true).toBe(true);
|
114
|
+
// Assert the value of the component
|
115
|
+
expect(dateTimePickerInputComponent).toHaveValue(localDateTimeString);
|
116
|
+
});
|
117
|
+
|
118
|
+
it('does not render with invalid datetime ISO string and throws exception', () => {
|
119
|
+
const invalidISODateTimeString = '2024-04-11T01:00:00.000-5:00';
|
120
|
+
const personDtoWithDateOnlyString: PersonDto = {
|
121
|
+
createdDateTime: invalidISODateTimeString,
|
122
|
+
};
|
123
|
+
|
124
|
+
try {
|
125
|
+
render(
|
126
|
+
<FormTestBase initialValues={personDtoWithDateOnlyString}>
|
127
|
+
{({ Field }) => (
|
128
|
+
<Field
|
129
|
+
name="createdDateTime"
|
130
|
+
Component={StringDateTimePickerGroup}
|
131
|
+
label="Created Date Time"
|
132
|
+
monthPlaceholder="mm"
|
133
|
+
dayPlaceholder="dd"
|
134
|
+
yearPlaceholder="yyyy"
|
135
|
+
disableClock
|
136
|
+
/>
|
137
|
+
)}
|
138
|
+
</FormTestBase>
|
139
|
+
);
|
140
|
+
|
141
|
+
fail('Expected an exception to be thrown for invalid datetime string');
|
142
|
+
} catch (error: any) {
|
143
|
+
// Assert that the error message matches the expected message
|
144
|
+
expect(error.message).toEqual(
|
145
|
+
`Invalid "date time" value of ${invalidISODateTimeString} provided to DateTimePickerGroup component. Please provide ISO 8601 string that includes the time zone designator. Sample strings: 2022-09-24T:08:54:12+00:00, 2022-09-24T:08:54:12Z, 2022-09-24T:08:54:12.123-05:00`
|
146
|
+
);
|
147
|
+
}
|
148
|
+
});
|
149
|
+
|
150
|
+
it('renders with ISO date time string with different offset than browser taking browser timezone into account', () => {
|
151
|
+
const isoDateTimeString = '2024-04-09T21:00:24.670-01:00';
|
152
|
+
const personDtoWithDateTimeString: PersonDto = {
|
153
|
+
createdDateTime: isoDateTimeString,
|
154
|
+
};
|
155
|
+
|
156
|
+
render(
|
157
|
+
<FormTestBase initialValues={personDtoWithDateTimeString}>
|
158
|
+
{({ Field }) => (
|
159
|
+
<Field
|
160
|
+
name="createdDateTime"
|
161
|
+
Component={StringDateTimePickerGroup}
|
162
|
+
label="Created Date Time"
|
163
|
+
monthPlaceholder="mm"
|
164
|
+
dayPlaceholder="dd"
|
165
|
+
yearPlaceholder="yyyy"
|
166
|
+
disableClock
|
167
|
+
/>
|
168
|
+
)}
|
169
|
+
</FormTestBase>
|
170
|
+
);
|
171
|
+
|
172
|
+
const dateTimePickerInputComponent = document.querySelector(
|
173
|
+
'input[name="datetime"][type="datetime-local"]'
|
174
|
+
);
|
175
|
+
const utcDate = new Date(isoDateTimeString);
|
176
|
+
const localDateTimeString =
|
177
|
+
convertToDateTimePickerComponentValueString(utcDate);
|
178
|
+
|
179
|
+
// Assert that no exception is thrown during rendering
|
180
|
+
expect(true).toBe(true);
|
181
|
+
// Assert the value of the component
|
182
|
+
expect(dateTimePickerInputComponent).toHaveValue(localDateTimeString);
|
183
|
+
});
|
184
|
+
|
185
|
+
it('renders with ISO date time string with same offset as the browser taking browser timezone into account', () => {
|
186
|
+
const isoDateTimeString = '2024-04-09T21:00:24.670-05:00';
|
187
|
+
const personDtoWithDateTimeString: PersonDto = {
|
188
|
+
createdDateTime: isoDateTimeString,
|
189
|
+
};
|
190
|
+
|
191
|
+
render(
|
192
|
+
<FormTestBase initialValues={personDtoWithDateTimeString}>
|
193
|
+
{({ Field }) => (
|
194
|
+
<Field
|
195
|
+
name="createdDateTime"
|
196
|
+
Component={StringDateTimePickerGroup}
|
197
|
+
label="Created Date Time"
|
198
|
+
monthPlaceholder="mm"
|
199
|
+
dayPlaceholder="dd"
|
200
|
+
yearPlaceholder="yyyy"
|
201
|
+
disableClock
|
202
|
+
/>
|
203
|
+
)}
|
204
|
+
</FormTestBase>
|
205
|
+
);
|
206
|
+
|
207
|
+
const dateTimePickerInputComponent = document.querySelector(
|
208
|
+
'input[name="datetime"][type="datetime-local"]'
|
209
|
+
);
|
210
|
+
const utcDate = new Date(isoDateTimeString);
|
211
|
+
const localDateTimeString =
|
212
|
+
convertToDateTimePickerComponentValueString(utcDate);
|
213
|
+
|
214
|
+
// Assert that no exception is thrown during rendering
|
215
|
+
expect(true).toBe(true);
|
216
|
+
// Assert the value of the component
|
217
|
+
expect(dateTimePickerInputComponent).toHaveValue(localDateTimeString);
|
218
|
+
});
|
219
|
+
});
|
220
|
+
|
221
|
+
function convertToDateTimePickerComponentValueString(date: Date): string {
|
222
|
+
// Format the date in the required format using `intl.DateTimeFormat`
|
223
|
+
const year = new Intl.DateTimeFormat('en', { year: 'numeric' })
|
224
|
+
.format(date)
|
225
|
+
.padStart(4, '0');
|
226
|
+
|
227
|
+
const month = new Intl.DateTimeFormat('en', { month: '2-digit' }).format(
|
228
|
+
date
|
229
|
+
);
|
230
|
+
|
231
|
+
const day = new Intl.DateTimeFormat('en', { day: '2-digit' }).format(date);
|
232
|
+
|
233
|
+
const hour = new Intl.DateTimeFormat('en', {
|
234
|
+
hour: '2-digit',
|
235
|
+
hourCycle: 'h23',
|
236
|
+
}).format(date);
|
237
|
+
|
238
|
+
const minute = new Intl.DateTimeFormat('en', { minute: '2-digit' })
|
239
|
+
.format(date)
|
240
|
+
.padStart(2, '0');
|
241
|
+
|
242
|
+
return `${year}-${month}-${day}T${hour}:${minute}`;
|
243
|
+
}
|
@@ -0,0 +1,116 @@
|
|
1
|
+
import { useEffect, useState } from 'react';
|
2
|
+
import { DateTimePicker, DateTimePickerProps } from 'react-datetime-picker';
|
3
|
+
import { clsx } from 'clsx';
|
4
|
+
import parseISO from 'date-fns/parseISO';
|
5
|
+
import { InjectedFieldProps } from '../Field/InjectedFieldProps';
|
6
|
+
import { FormDefaults } from '../FormDefaults';
|
7
|
+
import Group, { GroupProps } from '../Group';
|
8
|
+
|
9
|
+
// Represents a single date/date string, or null
|
10
|
+
type DateTimePickerValuePiece = Date | string | null;
|
11
|
+
// Represents either a single date/date string, a pair of dates/date strings for a range, or null
|
12
|
+
type DateTimePickerValue =
|
13
|
+
| DateTimePickerValuePiece
|
14
|
+
| [DateTimePickerValuePiece, DateTimePickerValuePiece];
|
15
|
+
|
16
|
+
export interface DateTimePickerGroupProps<T>
|
17
|
+
extends InjectedFieldProps<T | undefined | null>,
|
18
|
+
Omit<
|
19
|
+
DateTimePickerProps,
|
20
|
+
keyof InjectedFieldProps<T> | 'name' | 'value' | 'className'
|
21
|
+
>,
|
22
|
+
Omit<GroupProps, keyof InjectedFieldProps<T> | 'children'> {
|
23
|
+
convert: (date: Date) => T;
|
24
|
+
}
|
25
|
+
|
26
|
+
/**
|
27
|
+
* Field for inputting date and time. Uses `<Group/>` and `<DateTimePicker/>`.
|
28
|
+
*
|
29
|
+
* Uses [react-datetime-picker](https://www.npmjs.com/package/react-datetime-picker)
|
30
|
+
*/
|
31
|
+
export default function DateTimePickerGroup<T>({
|
32
|
+
input,
|
33
|
+
meta,
|
34
|
+
label,
|
35
|
+
helpText,
|
36
|
+
className,
|
37
|
+
required,
|
38
|
+
disabled,
|
39
|
+
convert,
|
40
|
+
...rest
|
41
|
+
}: DateTimePickerGroupProps<T>) {
|
42
|
+
const [displayDateTime, setDisplayDateTime] = useState<Date | null>(null);
|
43
|
+
|
44
|
+
useEffect(() => {
|
45
|
+
const inputValue = input.value;
|
46
|
+
if (!inputValue) {
|
47
|
+
setDisplayDateTime(null);
|
48
|
+
} else if (typeof inputValue === 'string') {
|
49
|
+
const parsedDateTime = convertISODateTimeStringToDate(inputValue);
|
50
|
+
setDisplayDateTime(parsedDateTime);
|
51
|
+
} else if (inputValue instanceof Date) {
|
52
|
+
setDisplayDateTime(inputValue);
|
53
|
+
}
|
54
|
+
}, [setDisplayDateTime, input.value]);
|
55
|
+
|
56
|
+
return (
|
57
|
+
<Group
|
58
|
+
input={input}
|
59
|
+
meta={meta}
|
60
|
+
label={label}
|
61
|
+
helpText={helpText}
|
62
|
+
className={clsx(
|
63
|
+
className,
|
64
|
+
FormDefaults.cssClassPrefix + 'date-time-picker'
|
65
|
+
)}
|
66
|
+
required={required}
|
67
|
+
disabled={disabled}>
|
68
|
+
<DateTimePicker
|
69
|
+
{...rest}
|
70
|
+
className={clsx(
|
71
|
+
FormDefaults.cssClassPrefix + 'date-time-picker',
|
72
|
+
className
|
73
|
+
)}
|
74
|
+
value={displayDateTime}
|
75
|
+
onChange={handleChange}
|
76
|
+
/>
|
77
|
+
</Group>
|
78
|
+
);
|
79
|
+
|
80
|
+
function handleChange(newDateTime: DateTimePickerValue) {
|
81
|
+
const { onChange } = input;
|
82
|
+
if (onChange === null) {
|
83
|
+
return;
|
84
|
+
}
|
85
|
+
|
86
|
+
if (!newDateTime) {
|
87
|
+
onChange(undefined);
|
88
|
+
setDisplayDateTime(null);
|
89
|
+
return;
|
90
|
+
} else if (typeof newDateTime === 'string') {
|
91
|
+
const parsedDateTime = parseISO(newDateTime);
|
92
|
+
setDisplayDateTime(parsedDateTime);
|
93
|
+
onChange(convert(parsedDateTime));
|
94
|
+
} else if (newDateTime instanceof Date) {
|
95
|
+
setDisplayDateTime(newDateTime);
|
96
|
+
onChange(convert(newDateTime));
|
97
|
+
}
|
98
|
+
}
|
99
|
+
}
|
100
|
+
|
101
|
+
function convertISODateTimeStringToDate(isoDateTimeString: string) {
|
102
|
+
const isoDateTimeRegex =
|
103
|
+
/^(\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(\.\d+)?)([+-]\d{2}:\d{2}|Z)?$/;
|
104
|
+
const isValidIsoDateTimeString = isoDateTimeRegex.test(isoDateTimeString);
|
105
|
+
if (isValidIsoDateTimeString) {
|
106
|
+
return new Date(isoDateTimeString);
|
107
|
+
}
|
108
|
+
|
109
|
+
const errorMessage = `Invalid "date time" value of ${isoDateTimeString} provided to DateTimePickerGroup component. Please provide ISO 8601 string that includes the time zone designator. Sample strings: 2022-09-24T:08:54:12+00:00, 2022-09-24T:08:54:12Z, 2022-09-24T:08:54:12.123-05:00`;
|
110
|
+
if (process.env.NODE_ENV !== 'production') {
|
111
|
+
throw new Error(errorMessage);
|
112
|
+
} else {
|
113
|
+
console.error(errorMessage);
|
114
|
+
}
|
115
|
+
return null;
|
116
|
+
}
|
@@ -0,0 +1,61 @@
|
|
1
|
+
import DateTimePickerGroup from './DateTimePickerGroup';
|
2
|
+
import { DateTimePickerHelper } from './DateTimePickerHelper';
|
3
|
+
|
4
|
+
export interface StringDateTimePickerGroupProps
|
5
|
+
extends DateTimePickerHelper<string | undefined | null> {}
|
6
|
+
|
7
|
+
/**
|
8
|
+
* Date Time picker input that consumes JS Date object and outputs as a date time offset string in ISO format `YYYY-MM-DDTHH:mm:ss.sss±hh:mm`.
|
9
|
+
*
|
10
|
+
* Default display to the user is in `MM/DD/YYYY HH:mm:ss AM/PM` format.
|
11
|
+
*/
|
12
|
+
export default function StringDateTimePickerGroup(
|
13
|
+
props: StringDateTimePickerGroupProps
|
14
|
+
) {
|
15
|
+
return <DateTimePickerGroup {...props} convert={convertToISOString} />;
|
16
|
+
}
|
17
|
+
|
18
|
+
function convertToISOString(date: Date): string {
|
19
|
+
// Get the offset in minutes
|
20
|
+
const offsetMinutes = date.getTimezoneOffset();
|
21
|
+
|
22
|
+
// Calculate the offset in hours and minutes
|
23
|
+
const offsetHours = Math.floor(Math.abs(offsetMinutes) / 60);
|
24
|
+
const offsetMinutesPart = Math.abs(offsetMinutes) % 60;
|
25
|
+
|
26
|
+
// Format the offset in the required format (+/-hh:mm)
|
27
|
+
const offsetString =
|
28
|
+
(offsetMinutes >= 0 ? '-' : '+') +
|
29
|
+
String(offsetHours).padStart(2, '0') +
|
30
|
+
':' +
|
31
|
+
String(offsetMinutesPart).padStart(2, '0');
|
32
|
+
|
33
|
+
// Format the date in the required format using `intl.DateTimeFormat`
|
34
|
+
const year = new Intl.DateTimeFormat('en', { year: 'numeric' })
|
35
|
+
.format(date)
|
36
|
+
.padStart(4, '0');
|
37
|
+
|
38
|
+
const month = new Intl.DateTimeFormat('en', { month: '2-digit' }).format(
|
39
|
+
date
|
40
|
+
);
|
41
|
+
|
42
|
+
const day = new Intl.DateTimeFormat('en', { day: '2-digit' }).format(date);
|
43
|
+
|
44
|
+
const hour = new Intl.DateTimeFormat('en', {
|
45
|
+
hour: '2-digit',
|
46
|
+
hourCycle: 'h23',
|
47
|
+
}).format(date);
|
48
|
+
|
49
|
+
const minute = new Intl.DateTimeFormat('en', { minute: '2-digit' })
|
50
|
+
.format(date)
|
51
|
+
.padStart(2, '0');
|
52
|
+
|
53
|
+
const second = new Intl.DateTimeFormat('en', {
|
54
|
+
second: '2-digit',
|
55
|
+
fractionalSecondDigits: 3,
|
56
|
+
})
|
57
|
+
.format(date)
|
58
|
+
.padStart(6, '0');
|
59
|
+
|
60
|
+
return `${year}-${month}-${day}T${hour}:${minute}:${second}${offsetString}`;
|
61
|
+
}
|
@@ -0,0 +1,217 @@
|
|
1
|
+
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
2
|
+
|
3
|
+
exports[`StringDateTimePickerGroup has matching snapshot 1`] = `
|
4
|
+
<DocumentFragment>
|
5
|
+
<form
|
6
|
+
action="#"
|
7
|
+
class="envoc-form-form"
|
8
|
+
>
|
9
|
+
<div
|
10
|
+
class="envoc-form-date-time-picker envoc-form-group"
|
11
|
+
>
|
12
|
+
<div
|
13
|
+
id="createddatetime-error-scroll-target"
|
14
|
+
style="display: none;"
|
15
|
+
/>
|
16
|
+
<label
|
17
|
+
for="createdDateTime"
|
18
|
+
>
|
19
|
+
Created Date Time
|
20
|
+
</label>
|
21
|
+
<div
|
22
|
+
class="react-datetime-picker react-datetime-picker--closed react-datetime-picker--enabled envoc-form-date-time-picker"
|
23
|
+
id="createdDateTime"
|
24
|
+
>
|
25
|
+
<div
|
26
|
+
class="react-datetime-picker__wrapper"
|
27
|
+
>
|
28
|
+
<div
|
29
|
+
class="react-datetime-picker__inputGroup"
|
30
|
+
>
|
31
|
+
<input
|
32
|
+
hidden=""
|
33
|
+
max="2023-09-23T00:00"
|
34
|
+
min="2022-06-22T00:00"
|
35
|
+
name="datetime"
|
36
|
+
step="60"
|
37
|
+
style="visibility: hidden; position: absolute; z-index: -999;"
|
38
|
+
type="datetime-local"
|
39
|
+
value=""
|
40
|
+
/>
|
41
|
+
<input
|
42
|
+
autocomplete="off"
|
43
|
+
class="react-datetime-picker__inputGroup__input react-datetime-picker__inputGroup__month"
|
44
|
+
data-input="true"
|
45
|
+
inputmode="numeric"
|
46
|
+
max="12"
|
47
|
+
min="1"
|
48
|
+
name="month"
|
49
|
+
placeholder="mm"
|
50
|
+
type="number"
|
51
|
+
value=""
|
52
|
+
/>
|
53
|
+
<span
|
54
|
+
class="react-datetime-picker__inputGroup__divider"
|
55
|
+
>
|
56
|
+
/
|
57
|
+
</span>
|
58
|
+
<input
|
59
|
+
autocomplete="off"
|
60
|
+
class="react-datetime-picker__inputGroup__input react-datetime-picker__inputGroup__day"
|
61
|
+
data-input="true"
|
62
|
+
inputmode="numeric"
|
63
|
+
max="31"
|
64
|
+
min="1"
|
65
|
+
name="day"
|
66
|
+
placeholder="dd"
|
67
|
+
type="number"
|
68
|
+
value=""
|
69
|
+
/>
|
70
|
+
<span
|
71
|
+
class="react-datetime-picker__inputGroup__divider"
|
72
|
+
>
|
73
|
+
/
|
74
|
+
</span>
|
75
|
+
<input
|
76
|
+
autocomplete="off"
|
77
|
+
class="react-datetime-picker__inputGroup__input react-datetime-picker__inputGroup__year"
|
78
|
+
data-input="true"
|
79
|
+
inputmode="numeric"
|
80
|
+
max="2023"
|
81
|
+
min="2022"
|
82
|
+
name="year"
|
83
|
+
placeholder="yyyy"
|
84
|
+
step="1"
|
85
|
+
type="number"
|
86
|
+
value=""
|
87
|
+
/>
|
88
|
+
<span
|
89
|
+
class="react-datetime-picker__inputGroup__divider"
|
90
|
+
>
|
91
|
+
|
92
|
+
</span>
|
93
|
+
<input
|
94
|
+
autocomplete="off"
|
95
|
+
class="react-datetime-picker__inputGroup__input react-datetime-picker__inputGroup__hour"
|
96
|
+
data-input="true"
|
97
|
+
inputmode="numeric"
|
98
|
+
max="12"
|
99
|
+
min="1"
|
100
|
+
name="hour12"
|
101
|
+
placeholder="--"
|
102
|
+
type="number"
|
103
|
+
value=""
|
104
|
+
/>
|
105
|
+
<span
|
106
|
+
class="react-datetime-picker__inputGroup__divider"
|
107
|
+
>
|
108
|
+
:
|
109
|
+
</span>
|
110
|
+
<input
|
111
|
+
autocomplete="off"
|
112
|
+
class="react-datetime-picker__inputGroup__input react-datetime-picker__inputGroup__minute"
|
113
|
+
data-input="true"
|
114
|
+
inputmode="numeric"
|
115
|
+
max="59"
|
116
|
+
min="0"
|
117
|
+
name="minute"
|
118
|
+
placeholder="--"
|
119
|
+
type="number"
|
120
|
+
value=""
|
121
|
+
/>
|
122
|
+
<span
|
123
|
+
class="react-datetime-picker__inputGroup__divider"
|
124
|
+
>
|
125
|
+
|
126
|
+
</span>
|
127
|
+
<select
|
128
|
+
class="react-datetime-picker__inputGroup__input react-datetime-picker__inputGroup__amPm"
|
129
|
+
data-input="true"
|
130
|
+
data-select="true"
|
131
|
+
name="amPm"
|
132
|
+
>
|
133
|
+
<option
|
134
|
+
value=""
|
135
|
+
>
|
136
|
+
--
|
137
|
+
</option>
|
138
|
+
<option
|
139
|
+
value="am"
|
140
|
+
>
|
141
|
+
AM
|
142
|
+
</option>
|
143
|
+
<option
|
144
|
+
value="pm"
|
145
|
+
>
|
146
|
+
PM
|
147
|
+
</option>
|
148
|
+
</select>
|
149
|
+
</div>
|
150
|
+
<button
|
151
|
+
class="react-datetime-picker__clear-button react-datetime-picker__button"
|
152
|
+
type="button"
|
153
|
+
>
|
154
|
+
<svg
|
155
|
+
class="react-datetime-picker__clear-button__icon react-datetime-picker__button__icon"
|
156
|
+
height="19"
|
157
|
+
stroke="black"
|
158
|
+
stroke-width="2"
|
159
|
+
viewBox="0 0 19 19"
|
160
|
+
width="19"
|
161
|
+
xmlns="http://www.w3.org/2000/svg"
|
162
|
+
>
|
163
|
+
<line
|
164
|
+
x1="4"
|
165
|
+
x2="15"
|
166
|
+
y1="4"
|
167
|
+
y2="15"
|
168
|
+
/>
|
169
|
+
<line
|
170
|
+
x1="15"
|
171
|
+
x2="4"
|
172
|
+
y1="4"
|
173
|
+
y2="15"
|
174
|
+
/>
|
175
|
+
</svg>
|
176
|
+
</button>
|
177
|
+
<button
|
178
|
+
aria-expanded="false"
|
179
|
+
class="react-datetime-picker__calendar-button react-datetime-picker__button"
|
180
|
+
type="button"
|
181
|
+
>
|
182
|
+
<svg
|
183
|
+
class="react-datetime-picker__calendar-button__icon react-datetime-picker__button__icon"
|
184
|
+
height="19"
|
185
|
+
stroke="black"
|
186
|
+
stroke-width="2"
|
187
|
+
viewBox="0 0 19 19"
|
188
|
+
width="19"
|
189
|
+
xmlns="http://www.w3.org/2000/svg"
|
190
|
+
>
|
191
|
+
<rect
|
192
|
+
fill="none"
|
193
|
+
height="15"
|
194
|
+
width="15"
|
195
|
+
x="2"
|
196
|
+
y="2"
|
197
|
+
/>
|
198
|
+
<line
|
199
|
+
x1="6"
|
200
|
+
x2="6"
|
201
|
+
y1="0"
|
202
|
+
y2="4"
|
203
|
+
/>
|
204
|
+
<line
|
205
|
+
x1="13"
|
206
|
+
x2="13"
|
207
|
+
y1="0"
|
208
|
+
y2="4"
|
209
|
+
/>
|
210
|
+
</svg>
|
211
|
+
</button>
|
212
|
+
</div>
|
213
|
+
</div>
|
214
|
+
</div>
|
215
|
+
</form>
|
216
|
+
</DocumentFragment>
|
217
|
+
`;
|
package/src/Input/InputGroup.tsx
CHANGED
@@ -32,6 +32,7 @@ function InputGroup<TValue>(
|
|
32
32
|
onChange,
|
33
33
|
value,
|
34
34
|
icon,
|
35
|
+
type,
|
35
36
|
...rest
|
36
37
|
}: InputGroupProps<TValue>,
|
37
38
|
ref: LegacyRef<HTMLInputElement>
|
@@ -55,6 +56,8 @@ function InputGroup<TValue>(
|
|
55
56
|
onChange={onChange}
|
56
57
|
ref={ref}
|
57
58
|
className={clsx(className, FormDefaults.cssClassPrefix + 'input-group')}
|
59
|
+
disabled={disabled}
|
60
|
+
type={disabled ? 'text' : type}
|
58
61
|
/>
|
59
62
|
</Group>
|
60
63
|
);
|
package/src/index.ts
CHANGED
@@ -27,6 +27,13 @@ export type { StringDatePickerGroupProps } from './DatePicker/StringDatePickerGr
|
|
27
27
|
export { default as StringDateOnlyPickerGroup } from './DatePicker/StringDateOnlyPickerGroup';
|
28
28
|
export type { StringDateOnlyPickerGroupProps } from './DatePicker/StringDateOnlyPickerGroup';
|
29
29
|
|
30
|
+
// DateTime
|
31
|
+
export { default as DateTimePickerGroup } from './DateTimePicker/DateTimePickerGroup';
|
32
|
+
export type { DateTimePickerGroupProps } from './DateTimePicker/DateTimePickerGroup';
|
33
|
+
|
34
|
+
export { default as StringDateTimePickerGroup } from './DateTimePicker/StringDateTimePickerGroup';
|
35
|
+
export type { StringDateTimePickerGroupProps } from './DateTimePicker/StringDateTimePickerGroup';
|
36
|
+
|
30
37
|
// Field
|
31
38
|
export { default as Field } from './Field/Field';
|
32
39
|
export type { FieldProps } from './Field/Field';
|