@uxf/ui 1.0.0-beta.163 → 1.0.0-beta.164
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.
|
@@ -37,35 +37,38 @@ const icon_1 = require("../icon");
|
|
|
37
37
|
exports.ALLOWED_DATE_FORMAT = ["D. M. YYYY", "DD. MM. YYYY", "D.M.YYYY", "DD.MM.YYYY"];
|
|
38
38
|
exports.DISPLAY_DATE_FORMAT = "D. M. YYYY";
|
|
39
39
|
exports.OUTPUT_DATE_FORMAT = "YYYY-MM-DD";
|
|
40
|
+
function getValue(value) {
|
|
41
|
+
const parsedValue = (0, dayjs_1.default)(value, exports.OUTPUT_DATE_FORMAT, true);
|
|
42
|
+
if (value && parsedValue.isValid()) {
|
|
43
|
+
return parsedValue.format(exports.DISPLAY_DATE_FORMAT);
|
|
44
|
+
}
|
|
45
|
+
return value !== null && value !== void 0 ? value : "";
|
|
46
|
+
}
|
|
47
|
+
function getSelectedDate(value) {
|
|
48
|
+
const parsedValue = (0, dayjs_1.default)(value, exports.OUTPUT_DATE_FORMAT, true);
|
|
49
|
+
if (value && parsedValue.isValid()) {
|
|
50
|
+
return parsedValue.toDate();
|
|
51
|
+
}
|
|
52
|
+
return null;
|
|
53
|
+
}
|
|
40
54
|
exports.DatePickerInput = (0, react_1.forwardRef)((props, ref) => {
|
|
41
55
|
var _a;
|
|
42
56
|
const onChange = props.onChange;
|
|
43
|
-
const [inputValue, setInputValue] = (0, react_1.useState)(() => {
|
|
44
|
-
var _a;
|
|
45
|
-
const parsedDate = (0, dayjs_1.default)(props.value, exports.OUTPUT_DATE_FORMAT, true);
|
|
46
|
-
if (props.value && parsedDate.isValid()) {
|
|
47
|
-
return parsedDate.format(exports.DISPLAY_DATE_FORMAT);
|
|
48
|
-
}
|
|
49
|
-
return (_a = props.value) !== null && _a !== void 0 ? _a : "";
|
|
50
|
-
});
|
|
51
57
|
const onInputChange = (0, react_1.useCallback)((value) => {
|
|
52
58
|
const parsedValue = (0, dayjs_1.default)(value, exports.ALLOWED_DATE_FORMAT, true);
|
|
53
59
|
if (value !== "" && parsedValue.isValid()) {
|
|
54
60
|
onChange(parsedValue.format(exports.OUTPUT_DATE_FORMAT));
|
|
55
|
-
setInputValue(parsedValue.format(exports.DISPLAY_DATE_FORMAT));
|
|
56
61
|
}
|
|
57
62
|
else {
|
|
58
63
|
onChange(value === "" ? null : value);
|
|
59
|
-
setInputValue(value);
|
|
60
64
|
}
|
|
61
65
|
}, [onChange]);
|
|
62
66
|
const onDatePickerChange = (0, react_1.useCallback)((value) => {
|
|
63
67
|
const parsedValue = (0, dayjs_1.default)(value);
|
|
64
68
|
onChange(parsedValue.format(exports.OUTPUT_DATE_FORMAT));
|
|
65
|
-
setInputValue(parsedValue.format(exports.DISPLAY_DATE_FORMAT));
|
|
66
69
|
}, [onChange]);
|
|
67
|
-
const
|
|
68
|
-
const selectedDate = props.value
|
|
69
|
-
return (react_1.default.createElement(_input_with_popover_1._InputWithPopover, { ...props, onChange: onInputChange, placeholder: props.placeholder || "Vyberte datum...", ref: ref, value:
|
|
70
|
+
const value = getValue(props.value);
|
|
71
|
+
const selectedDate = getSelectedDate(props.value);
|
|
72
|
+
return (react_1.default.createElement(_input_with_popover_1._InputWithPopover, { ...props, onChange: onInputChange, placeholder: props.placeholder || "Vyberte datum...", ref: ref, value: value, triggerElement: (_a = props.triggerElement) !== null && _a !== void 0 ? _a : react_1.default.createElement(icon_1.Icon, { name: "calendar", size: 20 }) }, ({ close }) => (react_1.default.createElement(date_picker_provider_1.DatePickerProvider, { closePopoverHandler: close, onChange: onDatePickerChange, selectedDate: selectedDate }))));
|
|
70
73
|
});
|
|
71
74
|
exports.DatePickerInput.displayName = "UxfUiDatePickerInput";
|
package/package.json
CHANGED
|
@@ -37,41 +37,42 @@ const icon_1 = require("../icon");
|
|
|
37
37
|
exports.ALLOWED_TIME_FORMAT = ["HH:mm", "H:mm"];
|
|
38
38
|
exports.DISPLAY_TIME_FORMAT = "H:mm";
|
|
39
39
|
exports.OUTPUT_TIME_FORMAT = "HH:mm:ss";
|
|
40
|
+
function getValue(value) {
|
|
41
|
+
const parsedValue = (0, dayjs_1.default)(value, exports.OUTPUT_TIME_FORMAT, true);
|
|
42
|
+
if (value && parsedValue.isValid()) {
|
|
43
|
+
return parsedValue.format(exports.DISPLAY_TIME_FORMAT);
|
|
44
|
+
}
|
|
45
|
+
return value !== null && value !== void 0 ? value : "";
|
|
46
|
+
}
|
|
47
|
+
function getSelectedTime(value) {
|
|
48
|
+
const parsedValue = (0, dayjs_1.default)(value, exports.OUTPUT_TIME_FORMAT, true);
|
|
49
|
+
if (value && parsedValue.isValid()) {
|
|
50
|
+
return {
|
|
51
|
+
hour: parsedValue.hour(),
|
|
52
|
+
minute: parsedValue.minute(),
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
return null;
|
|
56
|
+
}
|
|
40
57
|
exports.TimePickerInput = (0, react_1.forwardRef)((props, ref) => {
|
|
41
58
|
var _a;
|
|
42
59
|
const onChange = props.onChange;
|
|
43
|
-
const [inputValue, setInputValue] = (0, react_1.useState)(() => {
|
|
44
|
-
var _a;
|
|
45
|
-
const parsedDate = (0, dayjs_1.default)(props.value, exports.OUTPUT_TIME_FORMAT, true);
|
|
46
|
-
if (props.value && parsedDate.isValid()) {
|
|
47
|
-
return parsedDate.format(exports.DISPLAY_TIME_FORMAT);
|
|
48
|
-
}
|
|
49
|
-
return (_a = props.value) !== null && _a !== void 0 ? _a : "";
|
|
50
|
-
});
|
|
51
60
|
const onInputChange = (0, react_1.useCallback)((value) => {
|
|
52
61
|
const parsedValue = (0, dayjs_1.default)(value, exports.ALLOWED_TIME_FORMAT, true);
|
|
53
62
|
if (value !== "" && parsedValue.isValid()) {
|
|
54
63
|
onChange(parsedValue.format(exports.OUTPUT_TIME_FORMAT));
|
|
55
|
-
setInputValue(parsedValue.format(exports.DISPLAY_TIME_FORMAT));
|
|
56
64
|
}
|
|
57
65
|
else {
|
|
58
66
|
onChange(value === "" ? null : value);
|
|
59
|
-
setInputValue(value);
|
|
60
67
|
}
|
|
61
68
|
}, [onChange]);
|
|
62
69
|
const onTimePickerChange = (0, react_1.useCallback)((value) => {
|
|
63
|
-
var _a
|
|
70
|
+
var _a;
|
|
64
71
|
const parsedValue = value ? (0, dayjs_1.default)().hour(value.hour).minute(value.minute).second(0) : null;
|
|
65
72
|
onChange((_a = parsedValue === null || parsedValue === void 0 ? void 0 : parsedValue.format(exports.OUTPUT_TIME_FORMAT)) !== null && _a !== void 0 ? _a : null);
|
|
66
|
-
setInputValue((_b = parsedValue === null || parsedValue === void 0 ? void 0 : parsedValue.format(exports.DISPLAY_TIME_FORMAT)) !== null && _b !== void 0 ? _b : "");
|
|
67
73
|
}, [onChange]);
|
|
68
|
-
const
|
|
69
|
-
const selectedTime = props.value
|
|
70
|
-
|
|
71
|
-
hour: parsedTime.hour(),
|
|
72
|
-
minute: parsedTime.minute(),
|
|
73
|
-
}
|
|
74
|
-
: null;
|
|
75
|
-
return (react_1.default.createElement(_input_with_popover_1._InputWithPopover, { ...props, onChange: onInputChange, placeholder: props.placeholder || "Vyberte čas...", ref: ref, value: inputValue, triggerElement: (_a = props.triggerElement) !== null && _a !== void 0 ? _a : react_1.default.createElement(icon_1.Icon, { name: "clock", size: 20 }) }, ({ close }) => (react_1.default.createElement(time_picker_1.TimePicker, { closePopoverHandler: close, onChange: onTimePickerChange, selectedTime: selectedTime }))));
|
|
74
|
+
const value = getValue(props.value);
|
|
75
|
+
const selectedTime = getSelectedTime(props.value);
|
|
76
|
+
return (react_1.default.createElement(_input_with_popover_1._InputWithPopover, { ...props, onChange: onInputChange, placeholder: props.placeholder || "Vyberte čas...", ref: ref, value: value, triggerElement: (_a = props.triggerElement) !== null && _a !== void 0 ? _a : react_1.default.createElement(icon_1.Icon, { name: "clock", size: 20 }) }, ({ close }) => (react_1.default.createElement(time_picker_1.TimePicker, { closePopoverHandler: close, onChange: onTimePickerChange, selectedTime: selectedTime }))));
|
|
76
77
|
});
|
|
77
78
|
exports.TimePickerInput.displayName = "UxfUiTimePickerInput";
|