@gravity-ui/dynamic-forms 4.14.0 → 4.14.1
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/build/cjs/lib/kit/components/Inputs/DateInput/DateInput.js +7 -3
- package/build/cjs/lib/kit/components/Views/DateView/DateView.js +10 -8
- package/build/esm/lib/core/types/specs.d.ts +1 -0
- package/build/esm/lib/kit/components/Inputs/DateInput/DateInput.d.ts +1 -1
- package/build/esm/lib/kit/components/Inputs/DateInput/DateInput.js +8 -4
- package/build/esm/lib/kit/components/Views/DateView/DateView.js +10 -8
- package/package.json +3 -3
|
@@ -6,11 +6,12 @@ const react_1 = tslib_1.__importStar(require("react"));
|
|
|
6
6
|
const date_components_1 = require("@gravity-ui/date-components");
|
|
7
7
|
const date_utils_1 = require("@gravity-ui/date-utils");
|
|
8
8
|
const utils_1 = require("../../../utils");
|
|
9
|
-
exports.DEFAULT_DATE_FORMAT = 'DD
|
|
9
|
+
exports.DEFAULT_DATE_FORMAT = 'DD.MM.YYYY HH:mm';
|
|
10
10
|
const b = (0, utils_1.block)('date-input');
|
|
11
11
|
const DateInput = ({ name, input, spec, inputProps, }) => {
|
|
12
12
|
const { value, onChange, onBlur, onFocus } = input;
|
|
13
13
|
const dateInput = spec.viewSpec.dateInput;
|
|
14
|
+
const timeZone = (dateInput === null || dateInput === void 0 ? void 0 : dateInput.timeZone) && (0, date_utils_1.isValidTimeZone)(dateInput.timeZone) ? dateInput.timeZone : undefined;
|
|
14
15
|
const outputFormat = dateInput === null || dateInput === void 0 ? void 0 : dateInput.outputFormat;
|
|
15
16
|
const onUpdate = (0, react_1.useCallback)((date) => {
|
|
16
17
|
if (!date) {
|
|
@@ -42,8 +43,11 @@ const DateInput = ({ name, input, spec, inputProps, }) => {
|
|
|
42
43
|
}
|
|
43
44
|
}, [outputFormat]);
|
|
44
45
|
const props = Object.assign(Object.assign({ hasClear: true, format: (dateInput === null || dateInput === void 0 ? void 0 : dateInput.printFormat) || exports.DEFAULT_DATE_FORMAT }, inputProps), { onBlur: onBlur, onFocus: onFocus, value: value
|
|
45
|
-
? (0, date_utils_1.dateTimeParse)(value.seconds ? value.seconds * 1000 : value
|
|
46
|
-
|
|
46
|
+
? (0, date_utils_1.dateTimeParse)(value.seconds ? value.seconds * 1000 : value, {
|
|
47
|
+
format: dateInput === null || dateInput === void 0 ? void 0 : dateInput.outputFormat,
|
|
48
|
+
timeZone,
|
|
49
|
+
}) || null
|
|
50
|
+
: null, onUpdate, disabled: spec.viewSpec.disabled, placeholder: spec.viewSpec.placeholder, timeZone });
|
|
47
51
|
return react_1.default.createElement(date_components_1.DatePicker, Object.assign({ className: b(), "data-qa": name }, props));
|
|
48
52
|
};
|
|
49
53
|
exports.DateInput = DateInput;
|
|
@@ -7,15 +7,17 @@ const components_1 = require("../../../components");
|
|
|
7
7
|
const date_utils_1 = require("@gravity-ui/date-utils");
|
|
8
8
|
const isObject_1 = tslib_1.__importDefault(require("lodash/isObject"));
|
|
9
9
|
const DateView = (_a) => {
|
|
10
|
-
var _b, _c, _d;
|
|
11
10
|
var { value, spec } = _a, restProps = tslib_1.__rest(_a, ["value", "spec"]);
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
if (formatedValue
|
|
18
|
-
|
|
11
|
+
const { printFormat = components_1.DEFAULT_DATE_FORMAT, outputFormat, timeZone, } = spec.viewSpec.dateInput || {};
|
|
12
|
+
let formatedValue = value;
|
|
13
|
+
if ((0, isObject_1.default)(value) && value.seconds) {
|
|
14
|
+
formatedValue = Number(value.seconds) * 1000;
|
|
15
|
+
}
|
|
16
|
+
if (formatedValue) {
|
|
17
|
+
const date = (0, date_utils_1.dateTimeParse)(formatedValue, { format: outputFormat, timeZone });
|
|
18
|
+
if (date) {
|
|
19
|
+
formatedValue = date.format(printFormat);
|
|
20
|
+
}
|
|
19
21
|
}
|
|
20
22
|
return react_1.default.createElement(components_1.BaseView, Object.assign({ spec: spec, value: String(formatedValue) }, restProps));
|
|
21
23
|
};
|
|
@@ -2,7 +2,7 @@ import React from 'react';
|
|
|
2
2
|
import { DatePickerProps } from '@gravity-ui/date-components';
|
|
3
3
|
import { StringInputProps } from '../../../../core';
|
|
4
4
|
import './DateInput.css';
|
|
5
|
-
export declare const DEFAULT_DATE_FORMAT = "DD
|
|
5
|
+
export declare const DEFAULT_DATE_FORMAT = "DD.MM.YYYY HH:mm";
|
|
6
6
|
export interface DateProps extends Omit<DatePickerProps, 'value' | 'disabled' | 'placeholder' | 'qa'> {
|
|
7
7
|
}
|
|
8
8
|
export declare const DateInput: React.FC<StringInputProps<DateProps>>;
|
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
import React, { useCallback } from 'react';
|
|
2
2
|
import { DatePicker } from '@gravity-ui/date-components';
|
|
3
|
-
import { dateTimeParse } from '@gravity-ui/date-utils';
|
|
3
|
+
import { dateTimeParse, isValidTimeZone } from '@gravity-ui/date-utils';
|
|
4
4
|
import { block } from '../../../utils';
|
|
5
5
|
import './DateInput.css';
|
|
6
|
-
export const DEFAULT_DATE_FORMAT = 'DD
|
|
6
|
+
export const DEFAULT_DATE_FORMAT = 'DD.MM.YYYY HH:mm';
|
|
7
7
|
const b = block('date-input');
|
|
8
8
|
export const DateInput = ({ name, input, spec, inputProps, }) => {
|
|
9
9
|
const { value, onChange, onBlur, onFocus } = input;
|
|
10
10
|
const dateInput = spec.viewSpec.dateInput;
|
|
11
|
+
const timeZone = (dateInput === null || dateInput === void 0 ? void 0 : dateInput.timeZone) && isValidTimeZone(dateInput.timeZone) ? dateInput.timeZone : undefined;
|
|
11
12
|
const outputFormat = dateInput === null || dateInput === void 0 ? void 0 : dateInput.outputFormat;
|
|
12
13
|
const onUpdate = useCallback((date) => {
|
|
13
14
|
if (!date) {
|
|
@@ -39,8 +40,11 @@ export const DateInput = ({ name, input, spec, inputProps, }) => {
|
|
|
39
40
|
}
|
|
40
41
|
}, [outputFormat]);
|
|
41
42
|
const props = Object.assign(Object.assign({ hasClear: true, format: (dateInput === null || dateInput === void 0 ? void 0 : dateInput.printFormat) || DEFAULT_DATE_FORMAT }, inputProps), { onBlur: onBlur, onFocus: onFocus, value: value
|
|
42
|
-
? dateTimeParse(value.seconds ? value.seconds * 1000 : value
|
|
43
|
-
|
|
43
|
+
? dateTimeParse(value.seconds ? value.seconds * 1000 : value, {
|
|
44
|
+
format: dateInput === null || dateInput === void 0 ? void 0 : dateInput.outputFormat,
|
|
45
|
+
timeZone,
|
|
46
|
+
}) || null
|
|
47
|
+
: null, onUpdate, disabled: spec.viewSpec.disabled, placeholder: spec.viewSpec.placeholder, timeZone });
|
|
44
48
|
return React.createElement(DatePicker, Object.assign({ className: b(), "data-qa": name }, props));
|
|
45
49
|
};
|
|
46
50
|
export default DateInput;
|
|
@@ -4,15 +4,17 @@ import { BaseView, DEFAULT_DATE_FORMAT } from '../../../components';
|
|
|
4
4
|
import { dateTimeParse } from '@gravity-ui/date-utils';
|
|
5
5
|
import isObject from 'lodash/isObject';
|
|
6
6
|
export const DateView = (_a) => {
|
|
7
|
-
var _b, _c, _d;
|
|
8
7
|
var { value, spec } = _a, restProps = __rest(_a, ["value", "spec"]);
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
if (formatedValue
|
|
15
|
-
|
|
8
|
+
const { printFormat = DEFAULT_DATE_FORMAT, outputFormat, timeZone, } = spec.viewSpec.dateInput || {};
|
|
9
|
+
let formatedValue = value;
|
|
10
|
+
if (isObject(value) && value.seconds) {
|
|
11
|
+
formatedValue = Number(value.seconds) * 1000;
|
|
12
|
+
}
|
|
13
|
+
if (formatedValue) {
|
|
14
|
+
const date = dateTimeParse(formatedValue, { format: outputFormat, timeZone });
|
|
15
|
+
if (date) {
|
|
16
|
+
formatedValue = date.format(printFormat);
|
|
17
|
+
}
|
|
16
18
|
}
|
|
17
19
|
return React.createElement(BaseView, Object.assign({ spec: spec, value: String(formatedValue) }, restProps));
|
|
18
20
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gravity-ui/dynamic-forms",
|
|
3
|
-
"version": "4.14.
|
|
3
|
+
"version": "4.14.1",
|
|
4
4
|
"description": "",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"main": "build/cjs/index.js",
|
|
@@ -46,8 +46,8 @@
|
|
|
46
46
|
"dependencies": {
|
|
47
47
|
"@bem-react/classname": "^1.6.0",
|
|
48
48
|
"@gravity-ui/components": "^3.0.0",
|
|
49
|
-
"@gravity-ui/date-components": "^2.
|
|
50
|
-
"@gravity-ui/date-utils": "^2.
|
|
49
|
+
"@gravity-ui/date-components": "^2.10.3",
|
|
50
|
+
"@gravity-ui/date-utils": "^2.5.5",
|
|
51
51
|
"@gravity-ui/i18n": "^1.2.0",
|
|
52
52
|
"@gravity-ui/icons": "^2.8.1",
|
|
53
53
|
"lodash": "^4.17.20"
|