@contentful/field-editor-date 2.0.14 → 2.0.15
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.
|
@@ -77,13 +77,13 @@ function parseRawInput(raw) {
|
|
|
77
77
|
}
|
|
78
78
|
const getDefaultTime = ()=>(0, _datefns.parse)('12:00 AM', 'hh:mm a', REF_DATE);
|
|
79
79
|
const formatToString = (uses12hClock, value)=>(0, _datefns.format)(value, uses12hClock ? 'hh:mm a' : 'HH:mm');
|
|
80
|
-
const TimepickerInput = ({ disabled, uses12hClock, time = '
|
|
80
|
+
const TimepickerInput = ({ disabled, uses12hClock, time = '00:00', ampm = 'AM', onChange })=>{
|
|
81
81
|
const [selectedTime, setSelectedTime] = (0, _react.useState)(()=>{
|
|
82
82
|
return formatToString(uses12hClock, getDefaultTime());
|
|
83
83
|
});
|
|
84
84
|
(0, _react.useEffect)(()=>{
|
|
85
85
|
const parsed = uses12hClock ? (0, _datefns.parse)(`${time} ${ampm}`, 'hh:mm a', REF_DATE) : (0, _datefns.parse)(time, 'HH:mm', REF_DATE);
|
|
86
|
-
setSelectedTime(formatToString(uses12hClock, parsed));
|
|
86
|
+
setSelectedTime(formatToString(uses12hClock, (0, _datefns.isValid)(parsed) ? parsed : getDefaultTime()));
|
|
87
87
|
}, [
|
|
88
88
|
time,
|
|
89
89
|
ampm,
|
|
@@ -68,6 +68,22 @@ describe('TimepickerInput', ()=>{
|
|
|
68
68
|
}));
|
|
69
69
|
expect(getByTestId('time-input')).toHaveValue('00:00');
|
|
70
70
|
});
|
|
71
|
+
it('defaults to 00:00 in 24h mode when no time prop is provided', ()=>{
|
|
72
|
+
const { getByTestId } = (0, _react1.render)(/*#__PURE__*/ _react.createElement(_TimepickerInput.TimepickerInput, {
|
|
73
|
+
disabled: false,
|
|
74
|
+
uses12hClock: false,
|
|
75
|
+
onChange: jest.fn()
|
|
76
|
+
}));
|
|
77
|
+
expect(getByTestId('time-input')).toHaveValue('00:00');
|
|
78
|
+
});
|
|
79
|
+
it('defaults to 12:00 AM in 12h mode when no time prop is provided', ()=>{
|
|
80
|
+
const { getByTestId } = (0, _react1.render)(/*#__PURE__*/ _react.createElement(_TimepickerInput.TimepickerInput, {
|
|
81
|
+
disabled: false,
|
|
82
|
+
uses12hClock: true,
|
|
83
|
+
onChange: jest.fn()
|
|
84
|
+
}));
|
|
85
|
+
expect(getByTestId('time-input')).toHaveValue('12:00 AM');
|
|
86
|
+
});
|
|
71
87
|
it('renders late-night hours (e.g. 23:00) in 24h mode without crashing', ()=>{
|
|
72
88
|
const { getByTestId } = (0, _react1.render)(/*#__PURE__*/ _react.createElement(_TimepickerInput.TimepickerInput, {
|
|
73
89
|
disabled: false,
|
|
@@ -26,13 +26,13 @@ function parseRawInput(raw) {
|
|
|
26
26
|
}
|
|
27
27
|
const getDefaultTime = ()=>parse('12:00 AM', 'hh:mm a', REF_DATE);
|
|
28
28
|
const formatToString = (uses12hClock, value)=>format(value, uses12hClock ? 'hh:mm a' : 'HH:mm');
|
|
29
|
-
export const TimepickerInput = ({ disabled, uses12hClock, time = '
|
|
29
|
+
export const TimepickerInput = ({ disabled, uses12hClock, time = '00:00', ampm = 'AM', onChange })=>{
|
|
30
30
|
const [selectedTime, setSelectedTime] = useState(()=>{
|
|
31
31
|
return formatToString(uses12hClock, getDefaultTime());
|
|
32
32
|
});
|
|
33
33
|
useEffect(()=>{
|
|
34
34
|
const parsed = uses12hClock ? parse(`${time} ${ampm}`, 'hh:mm a', REF_DATE) : parse(time, 'HH:mm', REF_DATE);
|
|
35
|
-
setSelectedTime(formatToString(uses12hClock, parsed));
|
|
35
|
+
setSelectedTime(formatToString(uses12hClock, isValid(parsed) ? parsed : getDefaultTime()));
|
|
36
36
|
}, [
|
|
37
37
|
time,
|
|
38
38
|
ampm,
|
|
@@ -18,6 +18,22 @@ describe('TimepickerInput', ()=>{
|
|
|
18
18
|
}));
|
|
19
19
|
expect(getByTestId('time-input')).toHaveValue('00:00');
|
|
20
20
|
});
|
|
21
|
+
it('defaults to 00:00 in 24h mode when no time prop is provided', ()=>{
|
|
22
|
+
const { getByTestId } = render(/*#__PURE__*/ React.createElement(TimepickerInput, {
|
|
23
|
+
disabled: false,
|
|
24
|
+
uses12hClock: false,
|
|
25
|
+
onChange: jest.fn()
|
|
26
|
+
}));
|
|
27
|
+
expect(getByTestId('time-input')).toHaveValue('00:00');
|
|
28
|
+
});
|
|
29
|
+
it('defaults to 12:00 AM in 12h mode when no time prop is provided', ()=>{
|
|
30
|
+
const { getByTestId } = render(/*#__PURE__*/ React.createElement(TimepickerInput, {
|
|
31
|
+
disabled: false,
|
|
32
|
+
uses12hClock: true,
|
|
33
|
+
onChange: jest.fn()
|
|
34
|
+
}));
|
|
35
|
+
expect(getByTestId('time-input')).toHaveValue('12:00 AM');
|
|
36
|
+
});
|
|
21
37
|
it('renders late-night hours (e.g. 23:00) in 24h mode without crashing', ()=>{
|
|
22
38
|
const { getByTestId } = render(/*#__PURE__*/ React.createElement(TimepickerInput, {
|
|
23
39
|
disabled: false,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@contentful/field-editor-date",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.15",
|
|
4
4
|
"main": "dist/cjs/index.js",
|
|
5
5
|
"module": "dist/esm/index.js",
|
|
6
6
|
"types": "dist/types/index.d.ts",
|
|
@@ -39,7 +39,7 @@
|
|
|
39
39
|
"dependencies": {
|
|
40
40
|
"@contentful/f36-components": "^6.7.1",
|
|
41
41
|
"@contentful/f36-tokens": "^6.1.2",
|
|
42
|
-
"@contentful/field-editor-shared": "^4.1.
|
|
42
|
+
"@contentful/field-editor-shared": "^4.1.1",
|
|
43
43
|
"@emotion/css": "^11.13.5",
|
|
44
44
|
"date-fns": "^2.30.0"
|
|
45
45
|
},
|
|
@@ -57,5 +57,5 @@
|
|
|
57
57
|
"publishConfig": {
|
|
58
58
|
"registry": "https://npm.pkg.github.com/"
|
|
59
59
|
},
|
|
60
|
-
"gitHead": "
|
|
60
|
+
"gitHead": "1c60463b77d379bd0d88409fed04fb0bdea3677c"
|
|
61
61
|
}
|