@data-driven-forms/carbon-component-mapper 3.12.2 → 3.13.0
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/esm/time-picker/time-picker.js +9 -150
- package/esm/time-picker-base/index.js +2 -0
- package/esm/time-picker-base/time-picker-base.js +100 -0
- package/esm/time-picker-date/index.js +2 -0
- package/esm/time-picker-date/time-picker-date.js +129 -0
- package/esm/time-picker-string/index.js +2 -0
- package/esm/time-picker-string/time-picker-string.js +88 -0
- package/index.d.ts +6 -0
- package/package.json +1 -1
- package/time-picker/time-picker.d.ts +5 -13
- package/time-picker/time-picker.js +9 -162
- package/time-picker-base/index.d.ts +2 -0
- package/time-picker-base/index.js +32 -0
- package/time-picker-base/package.json +1 -0
- package/time-picker-base/time-picker-base.d.ts +29 -0
- package/time-picker-base/time-picker-base.js +116 -0
- package/time-picker-date/index.d.ts +2 -0
- package/time-picker-date/index.js +32 -0
- package/time-picker-date/package.json +1 -0
- package/time-picker-date/time-picker-date.d.ts +21 -0
- package/time-picker-date/time-picker-date.js +153 -0
- package/time-picker-string/index.d.ts +2 -0
- package/time-picker-string/index.js +32 -0
- package/time-picker-string/package.json +1 -0
- package/time-picker-string/time-picker-string.d.ts +21 -0
- package/time-picker-string/time-picker-string.js +112 -0
|
@@ -1,159 +1,18 @@
|
|
|
1
|
-
import _extends from "@babel/runtime/helpers/extends";
|
|
2
|
-
import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
|
|
3
1
|
import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
|
|
4
|
-
var _excluded = ["
|
|
5
|
-
|
|
6
|
-
import React, { useState, useEffect, useRef } from 'react';
|
|
2
|
+
var _excluded = ["useStringFormat"];
|
|
3
|
+
import React from 'react';
|
|
7
4
|
import PropTypes from 'prop-types';
|
|
8
|
-
import
|
|
9
|
-
import
|
|
10
|
-
import TimePickerSelect from "carbon-components-react/es/components/TimePickerSelect/TimePickerSelect.js";
|
|
11
|
-
import SelectItem from "carbon-components-react/es/components/SelectItem/SelectItem.js";
|
|
12
|
-
import prepareProps from '../prepare-props';
|
|
13
|
-
import HelperTextBlock from '../helper-text-block/helper-text-block';
|
|
5
|
+
import TimePickerString from '../time-picker-string/time-picker-string';
|
|
6
|
+
import TimePickerDate from '../time-picker-date';
|
|
14
7
|
|
|
15
|
-
var TimePicker = function TimePicker(
|
|
16
|
-
var
|
|
8
|
+
var TimePicker = function TimePicker(_ref) {
|
|
9
|
+
var useStringFormat = _ref.useStringFormat,
|
|
10
|
+
props = _objectWithoutProperties(_ref, _excluded);
|
|
17
11
|
|
|
18
|
-
|
|
19
|
-
input = _useFieldApi.input,
|
|
20
|
-
meta = _useFieldApi.meta,
|
|
21
|
-
twelveHoursFormat = _useFieldApi.twelveHoursFormat,
|
|
22
|
-
timezones = _useFieldApi.timezones,
|
|
23
|
-
validateOnMount = _useFieldApi.validateOnMount,
|
|
24
|
-
helperText = _useFieldApi.helperText,
|
|
25
|
-
WrapperProps = _useFieldApi.WrapperProps,
|
|
26
|
-
rest = _objectWithoutProperties(_useFieldApi, _excluded);
|
|
27
|
-
|
|
28
|
-
var _useState = useState(timezones ? (_timezones$ = timezones[0]) === null || _timezones$ === void 0 ? void 0 : _timezones$.value : ''),
|
|
29
|
-
_useState2 = _slicedToArray(_useState, 2),
|
|
30
|
-
timezone = _useState2[0],
|
|
31
|
-
selectTimezone = _useState2[1];
|
|
32
|
-
|
|
33
|
-
var _useState3 = useState('AM'),
|
|
34
|
-
_useState4 = _slicedToArray(_useState3, 2),
|
|
35
|
-
format = _useState4[0],
|
|
36
|
-
selectFormat = _useState4[1];
|
|
37
|
-
|
|
38
|
-
var isMounted = useRef(false);
|
|
39
|
-
var invalid = (meta.touched || validateOnMount) && (meta.error || meta.submitError);
|
|
40
|
-
var warnText = (meta.touched || validateOnMount) && meta.warning;
|
|
41
|
-
var finalValue = input.value;
|
|
42
|
-
|
|
43
|
-
if (input.value instanceof Date) {
|
|
44
|
-
var _timezones$find;
|
|
45
|
-
|
|
46
|
-
var _input$value$toLocale = input.value.toLocaleTimeString('en-us', {
|
|
47
|
-
hour12: !!twelveHoursFormat,
|
|
48
|
-
timeZone: timezones === null || timezones === void 0 ? void 0 : (_timezones$find = timezones.find(function (_ref) {
|
|
49
|
-
var value = _ref.value;
|
|
50
|
-
return value === timezone;
|
|
51
|
-
})) === null || _timezones$find === void 0 ? void 0 : _timezones$find.showAs
|
|
52
|
-
}).split(':'),
|
|
53
|
-
_input$value$toLocale2 = _slicedToArray(_input$value$toLocale, 2),
|
|
54
|
-
_input$value$toLocale3 = _input$value$toLocale2[0],
|
|
55
|
-
hours = _input$value$toLocale3 === void 0 ? '00' : _input$value$toLocale3,
|
|
56
|
-
_input$value$toLocale4 = _input$value$toLocale2[1],
|
|
57
|
-
minutes = _input$value$toLocale4 === void 0 ? '00' : _input$value$toLocale4;
|
|
58
|
-
|
|
59
|
-
finalValue = "".concat(String(hours).padStart(2, '0'), ":").concat(String(minutes).padStart(2, '0'));
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
var enhnancedOnBlur = function enhnancedOnBlur() {
|
|
63
|
-
var _finalValue;
|
|
64
|
-
|
|
65
|
-
var _ref2 = ((_finalValue = finalValue) === null || _finalValue === void 0 ? void 0 : _finalValue.split(':')) || [],
|
|
66
|
-
_ref3 = _slicedToArray(_ref2, 2),
|
|
67
|
-
_ref3$ = _ref3[0],
|
|
68
|
-
hours = _ref3$ === void 0 ? '00' : _ref3$,
|
|
69
|
-
_ref3$2 = _ref3[1],
|
|
70
|
-
minutes = _ref3$2 === void 0 ? '00' : _ref3$2;
|
|
71
|
-
|
|
72
|
-
if (!hours || isNaN(hours)) {
|
|
73
|
-
hours = '00';
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
if (!minutes || isNaN(minutes)) {
|
|
77
|
-
minutes = '00';
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
if (twelveHoursFormat) {
|
|
81
|
-
hours = hours % 12;
|
|
82
|
-
|
|
83
|
-
if (format === 'PM') {
|
|
84
|
-
hours = hours + 12;
|
|
85
|
-
}
|
|
86
|
-
} else {
|
|
87
|
-
hours = hours % 24;
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
minutes = minutes % 59;
|
|
91
|
-
var enhancedValue = new Date("Jan 1 2000 ".concat(hours, ":").concat(minutes, ":00 ").concat(timezone));
|
|
92
|
-
input.onChange(enhancedValue);
|
|
93
|
-
input.onBlur();
|
|
94
|
-
};
|
|
95
|
-
|
|
96
|
-
useEffect(function () {
|
|
97
|
-
if (isMounted.current === true) {
|
|
98
|
-
enhnancedOnBlur();
|
|
99
|
-
} else {
|
|
100
|
-
isMounted.current = true;
|
|
101
|
-
}
|
|
102
|
-
}, [timezone, format]);
|
|
103
|
-
return /*#__PURE__*/React.createElement("div", WrapperProps, /*#__PURE__*/React.createElement(CarbonTimePicker, _extends({}, input, {
|
|
104
|
-
value: finalValue,
|
|
105
|
-
onBlur: enhnancedOnBlur,
|
|
106
|
-
key: input.name,
|
|
107
|
-
id: input.name,
|
|
108
|
-
invalid: Boolean(invalid),
|
|
109
|
-
invalidText: invalid || ''
|
|
110
|
-
}, rest), twelveHoursFormat && /*#__PURE__*/React.createElement(TimePickerSelect, {
|
|
111
|
-
labelText: "Period",
|
|
112
|
-
id: "".concat(rest.id || input.name, "-12h"),
|
|
113
|
-
onChange: function onChange(_ref4) {
|
|
114
|
-
var value = _ref4.target.value;
|
|
115
|
-
return selectFormat(value);
|
|
116
|
-
}
|
|
117
|
-
}, /*#__PURE__*/React.createElement(SelectItem, {
|
|
118
|
-
value: "AM",
|
|
119
|
-
text: "AM"
|
|
120
|
-
}), /*#__PURE__*/React.createElement(SelectItem, {
|
|
121
|
-
value: "PM",
|
|
122
|
-
text: "PM"
|
|
123
|
-
})), timezones && /*#__PURE__*/React.createElement(TimePickerSelect, {
|
|
124
|
-
labelText: "Timezone",
|
|
125
|
-
id: "".concat(rest.id || input.name, "-timezones"),
|
|
126
|
-
onChange: function onChange(_ref5) {
|
|
127
|
-
var value = _ref5.target.value;
|
|
128
|
-
return selectTimezone(value);
|
|
129
|
-
}
|
|
130
|
-
}, timezones.map(function (_ref6) {
|
|
131
|
-
var showAs = _ref6.showAs,
|
|
132
|
-
tz = _objectWithoutProperties(_ref6, _excluded2);
|
|
133
|
-
|
|
134
|
-
return /*#__PURE__*/React.createElement(SelectItem, _extends({
|
|
135
|
-
key: tz.value,
|
|
136
|
-
text: tz.label
|
|
137
|
-
}, tz));
|
|
138
|
-
}))), /*#__PURE__*/React.createElement(HelperTextBlock, {
|
|
139
|
-
helperText: !invalid && helperText,
|
|
140
|
-
warnText: warnText
|
|
141
|
-
}));
|
|
12
|
+
return useStringFormat ? /*#__PURE__*/React.createElement(TimePickerString, props) : /*#__PURE__*/React.createElement(TimePickerDate, props);
|
|
142
13
|
};
|
|
143
14
|
|
|
144
15
|
TimePicker.propTypes = {
|
|
145
|
-
|
|
146
|
-
isReadOnly: PropTypes.bool,
|
|
147
|
-
isRequired: PropTypes.bool,
|
|
148
|
-
label: PropTypes.node,
|
|
149
|
-
labelText: PropTypes.node,
|
|
150
|
-
description: PropTypes.node,
|
|
151
|
-
twelveHoursFormat: PropTypes.bool,
|
|
152
|
-
timezones: PropTypes.arrayOf(PropTypes.shape({
|
|
153
|
-
value: PropTypes.string.isRequired,
|
|
154
|
-
label: PropTypes.node.isRequired,
|
|
155
|
-
showAs: PropTypes.string.isRequired
|
|
156
|
-
})),
|
|
157
|
-
WrapperProps: PropTypes.object
|
|
16
|
+
useStringFormat: PropTypes.bool
|
|
158
17
|
};
|
|
159
18
|
export default TimePicker;
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import _extends from "@babel/runtime/helpers/extends";
|
|
2
|
+
import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
|
|
3
|
+
var _excluded = ["WrapperProps", "input", "enhnancedOnBlur", "enhancedOnChange", "finalValue", "invalid", "twelveHoursFormat", "timezones", "helperText", "warnText", "selectFormat", "selectTimezone"],
|
|
4
|
+
_excluded2 = ["showAs"];
|
|
5
|
+
import React from 'react';
|
|
6
|
+
import PropTypes from 'prop-types';
|
|
7
|
+
import CarbonTimePicker from "carbon-components-react/es/components/TimePicker/TimePicker.js";
|
|
8
|
+
import TimePickerSelect from "carbon-components-react/es/components/TimePickerSelect/TimePickerSelect.js";
|
|
9
|
+
import SelectItem from "carbon-components-react/es/components/SelectItem/SelectItem.js";
|
|
10
|
+
import HelperTextBlock from '../helper-text-block/helper-text-block';
|
|
11
|
+
|
|
12
|
+
var TimePickerBase = function TimePickerBase(_ref) {
|
|
13
|
+
var WrapperProps = _ref.WrapperProps,
|
|
14
|
+
input = _ref.input,
|
|
15
|
+
enhnancedOnBlur = _ref.enhnancedOnBlur,
|
|
16
|
+
enhancedOnChange = _ref.enhancedOnChange,
|
|
17
|
+
finalValue = _ref.finalValue,
|
|
18
|
+
invalid = _ref.invalid,
|
|
19
|
+
twelveHoursFormat = _ref.twelveHoursFormat,
|
|
20
|
+
timezones = _ref.timezones,
|
|
21
|
+
helperText = _ref.helperText,
|
|
22
|
+
warnText = _ref.warnText,
|
|
23
|
+
selectFormat = _ref.selectFormat,
|
|
24
|
+
selectTimezone = _ref.selectTimezone,
|
|
25
|
+
rest = _objectWithoutProperties(_ref, _excluded);
|
|
26
|
+
|
|
27
|
+
return /*#__PURE__*/React.createElement("div", WrapperProps, /*#__PURE__*/React.createElement(CarbonTimePicker, _extends({}, input, enhnancedOnBlur && {
|
|
28
|
+
onBlur: enhnancedOnBlur
|
|
29
|
+
}, enhancedOnChange && {
|
|
30
|
+
onChange: function onChange(e) {
|
|
31
|
+
return enhancedOnChange(e.target.value);
|
|
32
|
+
}
|
|
33
|
+
}, {
|
|
34
|
+
onBlur: enhnancedOnBlur,
|
|
35
|
+
value: finalValue,
|
|
36
|
+
key: input.name,
|
|
37
|
+
id: input.name,
|
|
38
|
+
invalid: Boolean(invalid),
|
|
39
|
+
invalidText: invalid || ''
|
|
40
|
+
}, rest), twelveHoursFormat && /*#__PURE__*/React.createElement(TimePickerSelect, {
|
|
41
|
+
labelText: "Period",
|
|
42
|
+
id: "".concat(rest.id || input.name, "-12h"),
|
|
43
|
+
onChange: function onChange(_ref2) {
|
|
44
|
+
var value = _ref2.target.value;
|
|
45
|
+
return selectFormat(value);
|
|
46
|
+
}
|
|
47
|
+
}, /*#__PURE__*/React.createElement(SelectItem, {
|
|
48
|
+
value: "AM",
|
|
49
|
+
text: "AM"
|
|
50
|
+
}), /*#__PURE__*/React.createElement(SelectItem, {
|
|
51
|
+
value: "PM",
|
|
52
|
+
text: "PM"
|
|
53
|
+
})), timezones && /*#__PURE__*/React.createElement(TimePickerSelect, {
|
|
54
|
+
labelText: "Timezone",
|
|
55
|
+
id: "".concat(rest.id || input.name, "-timezones"),
|
|
56
|
+
onChange: function onChange(_ref3) {
|
|
57
|
+
var value = _ref3.target.value;
|
|
58
|
+
return selectTimezone(value);
|
|
59
|
+
}
|
|
60
|
+
}, timezones.map(function (_ref4) {
|
|
61
|
+
var showAs = _ref4.showAs,
|
|
62
|
+
tz = _objectWithoutProperties(_ref4, _excluded2);
|
|
63
|
+
|
|
64
|
+
return /*#__PURE__*/React.createElement(SelectItem, _extends({
|
|
65
|
+
key: tz.value,
|
|
66
|
+
text: tz.label
|
|
67
|
+
}, tz));
|
|
68
|
+
}))), /*#__PURE__*/React.createElement(HelperTextBlock, {
|
|
69
|
+
helperText: !invalid && helperText,
|
|
70
|
+
warnText: warnText
|
|
71
|
+
}));
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
TimePickerBase.propTypes = {
|
|
75
|
+
isDisabled: PropTypes.bool,
|
|
76
|
+
isReadOnly: PropTypes.bool,
|
|
77
|
+
isRequired: PropTypes.bool,
|
|
78
|
+
label: PropTypes.node,
|
|
79
|
+
labelText: PropTypes.node,
|
|
80
|
+
description: PropTypes.node,
|
|
81
|
+
twelveHoursFormat: PropTypes.bool,
|
|
82
|
+
timezones: PropTypes.arrayOf(PropTypes.shape({
|
|
83
|
+
value: PropTypes.string.isRequired,
|
|
84
|
+
label: PropTypes.node.isRequired,
|
|
85
|
+
showAs: PropTypes.string
|
|
86
|
+
})),
|
|
87
|
+
WrapperProps: PropTypes.object,
|
|
88
|
+
input: PropTypes.shape({
|
|
89
|
+
name: PropTypes.string
|
|
90
|
+
}).isRequired,
|
|
91
|
+
enhnancedOnBlur: PropTypes.func,
|
|
92
|
+
enhancedOnChange: PropTypes.func,
|
|
93
|
+
finalValue: PropTypes.any,
|
|
94
|
+
invalid: PropTypes.node,
|
|
95
|
+
helperText: PropTypes.node,
|
|
96
|
+
warnText: PropTypes.node,
|
|
97
|
+
selectFormat: PropTypes.func.isRequired,
|
|
98
|
+
selectTimezone: PropTypes.func.isRequired
|
|
99
|
+
};
|
|
100
|
+
export default TimePickerBase;
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
import _extends from "@babel/runtime/helpers/extends";
|
|
2
|
+
import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
|
|
3
|
+
import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
|
|
4
|
+
var _excluded = ["input", "meta", "twelveHoursFormat", "timezones", "validateOnMount", "helperText", "WrapperProps"];
|
|
5
|
+
import React, { useState, useEffect, useRef } from 'react';
|
|
6
|
+
import PropTypes from 'prop-types';
|
|
7
|
+
import useFieldApi from "@data-driven-forms/react-form-renderer/use-field-api";
|
|
8
|
+
import prepareProps from '../prepare-props';
|
|
9
|
+
import TimePickerBase from '../time-picker-base';
|
|
10
|
+
|
|
11
|
+
var TimePickerDate = function TimePickerDate(props) {
|
|
12
|
+
var _timezones$;
|
|
13
|
+
|
|
14
|
+
var _useFieldApi = useFieldApi(prepareProps(props)),
|
|
15
|
+
input = _useFieldApi.input,
|
|
16
|
+
meta = _useFieldApi.meta,
|
|
17
|
+
twelveHoursFormat = _useFieldApi.twelveHoursFormat,
|
|
18
|
+
timezones = _useFieldApi.timezones,
|
|
19
|
+
validateOnMount = _useFieldApi.validateOnMount,
|
|
20
|
+
helperText = _useFieldApi.helperText,
|
|
21
|
+
WrapperProps = _useFieldApi.WrapperProps,
|
|
22
|
+
rest = _objectWithoutProperties(_useFieldApi, _excluded);
|
|
23
|
+
|
|
24
|
+
var _useState = useState(timezones ? (_timezones$ = timezones[0]) === null || _timezones$ === void 0 ? void 0 : _timezones$.value : ''),
|
|
25
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
26
|
+
timezone = _useState2[0],
|
|
27
|
+
selectTimezone = _useState2[1];
|
|
28
|
+
|
|
29
|
+
var _useState3 = useState('AM'),
|
|
30
|
+
_useState4 = _slicedToArray(_useState3, 2),
|
|
31
|
+
format = _useState4[0],
|
|
32
|
+
selectFormat = _useState4[1];
|
|
33
|
+
|
|
34
|
+
var isMounted = useRef(false);
|
|
35
|
+
var invalid = (meta.touched || validateOnMount) && (meta.error || meta.submitError);
|
|
36
|
+
var warnText = (meta.touched || validateOnMount) && meta.warning;
|
|
37
|
+
var finalValue = input.value;
|
|
38
|
+
|
|
39
|
+
if (input.value instanceof Date) {
|
|
40
|
+
var _timezones$find;
|
|
41
|
+
|
|
42
|
+
var _input$value$toLocale = input.value.toLocaleTimeString('en-us', {
|
|
43
|
+
hour12: !!twelveHoursFormat,
|
|
44
|
+
timeZone: timezones === null || timezones === void 0 ? void 0 : (_timezones$find = timezones.find(function (_ref) {
|
|
45
|
+
var value = _ref.value;
|
|
46
|
+
return value === timezone;
|
|
47
|
+
})) === null || _timezones$find === void 0 ? void 0 : _timezones$find.showAs
|
|
48
|
+
}).split(':'),
|
|
49
|
+
_input$value$toLocale2 = _slicedToArray(_input$value$toLocale, 2),
|
|
50
|
+
_input$value$toLocale3 = _input$value$toLocale2[0],
|
|
51
|
+
hours = _input$value$toLocale3 === void 0 ? '00' : _input$value$toLocale3,
|
|
52
|
+
_input$value$toLocale4 = _input$value$toLocale2[1],
|
|
53
|
+
minutes = _input$value$toLocale4 === void 0 ? '00' : _input$value$toLocale4;
|
|
54
|
+
|
|
55
|
+
finalValue = "".concat(String(hours).padStart(2, '0'), ":").concat(String(minutes).padStart(2, '0'));
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
var enhnancedOnBlur = function enhnancedOnBlur() {
|
|
59
|
+
var _finalValue;
|
|
60
|
+
|
|
61
|
+
var _ref2 = ((_finalValue = finalValue) === null || _finalValue === void 0 ? void 0 : _finalValue.split(':')) || [],
|
|
62
|
+
_ref3 = _slicedToArray(_ref2, 2),
|
|
63
|
+
_ref3$ = _ref3[0],
|
|
64
|
+
hours = _ref3$ === void 0 ? '00' : _ref3$,
|
|
65
|
+
_ref3$2 = _ref3[1],
|
|
66
|
+
minutes = _ref3$2 === void 0 ? '00' : _ref3$2;
|
|
67
|
+
|
|
68
|
+
if (!hours || isNaN(hours)) {
|
|
69
|
+
hours = '00';
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
if (!minutes || isNaN(minutes)) {
|
|
73
|
+
minutes = '00';
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
if (twelveHoursFormat) {
|
|
77
|
+
hours = hours % 12;
|
|
78
|
+
|
|
79
|
+
if (format === 'PM') {
|
|
80
|
+
hours = hours + 12;
|
|
81
|
+
}
|
|
82
|
+
} else {
|
|
83
|
+
hours = hours % 24;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
minutes = minutes % 59;
|
|
87
|
+
var enhancedValue = new Date("Jan 1 2000 ".concat(hours, ":").concat(minutes, ":00 ").concat(timezone));
|
|
88
|
+
input.onChange(enhancedValue);
|
|
89
|
+
input.onBlur();
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
useEffect(function () {
|
|
93
|
+
if (isMounted.current === true) {
|
|
94
|
+
enhnancedOnBlur();
|
|
95
|
+
} else {
|
|
96
|
+
isMounted.current = true;
|
|
97
|
+
}
|
|
98
|
+
}, [timezone, format]);
|
|
99
|
+
return /*#__PURE__*/React.createElement(TimePickerBase, _extends({
|
|
100
|
+
WrapperProps: WrapperProps,
|
|
101
|
+
input: input,
|
|
102
|
+
enhnancedOnBlur: enhnancedOnBlur,
|
|
103
|
+
finalValue: finalValue,
|
|
104
|
+
invalid: invalid,
|
|
105
|
+
twelveHoursFormat: twelveHoursFormat,
|
|
106
|
+
timezones: timezones,
|
|
107
|
+
helperText: helperText,
|
|
108
|
+
warnText: warnText,
|
|
109
|
+
selectFormat: selectFormat,
|
|
110
|
+
selectTimezone: selectTimezone
|
|
111
|
+
}, rest));
|
|
112
|
+
};
|
|
113
|
+
|
|
114
|
+
TimePickerDate.propTypes = {
|
|
115
|
+
isDisabled: PropTypes.bool,
|
|
116
|
+
isReadOnly: PropTypes.bool,
|
|
117
|
+
isRequired: PropTypes.bool,
|
|
118
|
+
label: PropTypes.node,
|
|
119
|
+
labelText: PropTypes.node,
|
|
120
|
+
description: PropTypes.node,
|
|
121
|
+
twelveHoursFormat: PropTypes.bool,
|
|
122
|
+
timezones: PropTypes.arrayOf(PropTypes.shape({
|
|
123
|
+
value: PropTypes.string.isRequired,
|
|
124
|
+
label: PropTypes.node.isRequired,
|
|
125
|
+
showAs: PropTypes.string
|
|
126
|
+
})),
|
|
127
|
+
WrapperProps: PropTypes.object
|
|
128
|
+
};
|
|
129
|
+
export default TimePickerDate;
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import _extends from "@babel/runtime/helpers/extends";
|
|
2
|
+
import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
|
|
3
|
+
import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
|
|
4
|
+
var _excluded = ["input", "meta", "twelveHoursFormat", "timezones", "validateOnMount", "helperText", "WrapperProps", "useStringFormat"];
|
|
5
|
+
import React, { useState, useEffect, useRef } from 'react';
|
|
6
|
+
import PropTypes from 'prop-types';
|
|
7
|
+
import useFieldApi from "@data-driven-forms/react-form-renderer/use-field-api";
|
|
8
|
+
import prepareProps from '../prepare-props';
|
|
9
|
+
import TimePickerBase from '../time-picker-base';
|
|
10
|
+
|
|
11
|
+
var TimePickerString = function TimePickerString(props) {
|
|
12
|
+
var _useFieldApi = useFieldApi(prepareProps(props)),
|
|
13
|
+
input = _useFieldApi.input,
|
|
14
|
+
meta = _useFieldApi.meta,
|
|
15
|
+
twelveHoursFormat = _useFieldApi.twelveHoursFormat,
|
|
16
|
+
timezones = _useFieldApi.timezones,
|
|
17
|
+
validateOnMount = _useFieldApi.validateOnMount,
|
|
18
|
+
helperText = _useFieldApi.helperText,
|
|
19
|
+
WrapperProps = _useFieldApi.WrapperProps,
|
|
20
|
+
useStringFormat = _useFieldApi.useStringFormat,
|
|
21
|
+
rest = _objectWithoutProperties(_useFieldApi, _excluded);
|
|
22
|
+
|
|
23
|
+
var _useState = useState(function () {
|
|
24
|
+
var _input$value$match, _timezones$;
|
|
25
|
+
|
|
26
|
+
return timezones ? ((_input$value$match = input.value.match(/ \w+$/)) === null || _input$value$match === void 0 ? void 0 : _input$value$match[0].trim()) || ((_timezones$ = timezones[0]) === null || _timezones$ === void 0 ? void 0 : _timezones$.value) : '';
|
|
27
|
+
}),
|
|
28
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
29
|
+
timezone = _useState2[0],
|
|
30
|
+
selectTimezone = _useState2[1];
|
|
31
|
+
|
|
32
|
+
var _useState3 = useState(function () {
|
|
33
|
+
var _input$value$match2;
|
|
34
|
+
|
|
35
|
+
return ((_input$value$match2 = input.value.match(/ \w+ /)) === null || _input$value$match2 === void 0 ? void 0 : _input$value$match2[0].trim()) || 'AM';
|
|
36
|
+
}),
|
|
37
|
+
_useState4 = _slicedToArray(_useState3, 2),
|
|
38
|
+
format = _useState4[0],
|
|
39
|
+
selectFormat = _useState4[1];
|
|
40
|
+
|
|
41
|
+
var isMounted = useRef(false);
|
|
42
|
+
var invalid = (meta.touched || validateOnMount) && (meta.error || meta.submitError);
|
|
43
|
+
var warnText = (meta.touched || validateOnMount) && meta.warning;
|
|
44
|
+
var finalValue = input.value.replace(/ .*/, '');
|
|
45
|
+
|
|
46
|
+
var enhancedOnChange = function enhancedOnChange(value) {
|
|
47
|
+
return input.onChange("".concat(value, " ").concat(twelveHoursFormat ? format : '', " ").concat(timezones ? timezone : '').replace(/ {2}/, ' ').trim());
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
useEffect(function () {
|
|
51
|
+
if (isMounted.current === true) {
|
|
52
|
+
enhancedOnChange(finalValue);
|
|
53
|
+
} else {
|
|
54
|
+
isMounted.current = true;
|
|
55
|
+
}
|
|
56
|
+
}, [timezone, format]);
|
|
57
|
+
return /*#__PURE__*/React.createElement(TimePickerBase, _extends({
|
|
58
|
+
WrapperProps: WrapperProps,
|
|
59
|
+
input: input,
|
|
60
|
+
enhancedOnChange: enhancedOnChange,
|
|
61
|
+
finalValue: finalValue,
|
|
62
|
+
invalid: invalid,
|
|
63
|
+
twelveHoursFormat: twelveHoursFormat,
|
|
64
|
+
timezones: timezones,
|
|
65
|
+
helperText: helperText,
|
|
66
|
+
warnText: warnText,
|
|
67
|
+
selectFormat: selectFormat,
|
|
68
|
+
selectTimezone: selectTimezone
|
|
69
|
+
}, rest));
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
TimePickerString.propTypes = {
|
|
73
|
+
isDisabled: PropTypes.bool,
|
|
74
|
+
isReadOnly: PropTypes.bool,
|
|
75
|
+
isRequired: PropTypes.bool,
|
|
76
|
+
label: PropTypes.node,
|
|
77
|
+
labelText: PropTypes.node,
|
|
78
|
+
description: PropTypes.node,
|
|
79
|
+
twelveHoursFormat: PropTypes.bool,
|
|
80
|
+
timezones: PropTypes.arrayOf(PropTypes.shape({
|
|
81
|
+
value: PropTypes.string.isRequired,
|
|
82
|
+
label: PropTypes.node.isRequired,
|
|
83
|
+
showAs: PropTypes.string
|
|
84
|
+
})),
|
|
85
|
+
WrapperProps: PropTypes.object,
|
|
86
|
+
useStringFormat: PropTypes.bool
|
|
87
|
+
};
|
|
88
|
+
export default TimePickerString;
|
package/index.d.ts
CHANGED
|
@@ -36,6 +36,12 @@ export { default as TextField } from './text-field';
|
|
|
36
36
|
export * from './text-field';
|
|
37
37
|
export { default as Textarea } from './textarea';
|
|
38
38
|
export * from './textarea';
|
|
39
|
+
export { default as TimePickerBase } from './time-picker-base';
|
|
40
|
+
export * from './time-picker-base';
|
|
41
|
+
export { default as TimePickerDate } from './time-picker-date';
|
|
42
|
+
export * from './time-picker-date';
|
|
43
|
+
export { default as TimePickerString } from './time-picker-string';
|
|
44
|
+
export * from './time-picker-string';
|
|
39
45
|
export { default as TimePicker } from './time-picker';
|
|
40
46
|
export * from './time-picker';
|
|
41
47
|
export { default as WithDescription } from './with-description';
|
package/package.json
CHANGED
|
@@ -1,21 +1,13 @@
|
|
|
1
|
-
import { ReactNode } from "react";
|
|
2
1
|
import { UseFieldApiComponentConfig, AnyObject } from "@data-driven-forms/react-form-renderer";
|
|
3
2
|
|
|
4
|
-
import {
|
|
3
|
+
import { TimePickerDateProps } from "../time-picker-date";
|
|
4
|
+
import { TimePickerStringProps } from "../time-picker-string";
|
|
5
5
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
export interface Timezone extends SelectItemProps {
|
|
9
|
-
value: string;
|
|
10
|
-
label?: string;
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
interface InternalTimePickerProps extends CarbonTimePickerProps {
|
|
14
|
-
twelveHoursFormat?: boolean;
|
|
15
|
-
timezones?: Timezone[];
|
|
6
|
+
interface InternalTimePickerProps extends AnyObject{
|
|
7
|
+
useStringFormat?: boolean;
|
|
16
8
|
}
|
|
17
9
|
|
|
18
|
-
export type TimePickerProps = InternalTimePickerProps &
|
|
10
|
+
export type TimePickerProps = InternalTimePickerProps & TimePickerDateProps & TimePickerStringProps & UseFieldApiComponentConfig;
|
|
19
11
|
|
|
20
12
|
declare const TimePicker: React.ComponentType<TimePickerProps>;
|
|
21
13
|
|