@uxf/form 10.0.0-beta.40 → 10.0.0-beta.46
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/date-range-picker-input/date-range-picker-input.d.ts +11 -0
- package/date-range-picker-input/date-range-picker-input.js +104 -0
- package/date-range-picker-input/date-range-picker-input.stories.d.ts +8 -0
- package/date-range-picker-input/date-range-picker-input.stories.js +24 -0
- package/date-range-picker-input/index.d.ts +1 -0
- package/date-range-picker-input/index.js +17 -0
- package/package.json +2 -2
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { DateRangePickerInputProps as UIDateRangePickerInputProps } from "@uxf/ui/date-range-picker-input";
|
|
2
|
+
import React from "react";
|
|
3
|
+
import { FieldValues, UseControllerProps } from "react-hook-form";
|
|
4
|
+
export type DateRangePickerInputProps<FormData extends FieldValues> = UseControllerProps<FormData> & Omit<UIDateRangePickerInputProps, "isInvalid" | "max" | "min" | "pattern" | "step" | "name" | "onChange" | "value"> & {
|
|
5
|
+
onChange?: UIDateRangePickerInputProps["onChange"];
|
|
6
|
+
requiredMessage?: string;
|
|
7
|
+
};
|
|
8
|
+
export declare function DateRangePickerInput<FormData extends FieldValues>(props: DateRangePickerInputProps<FormData>): React.JSX.Element;
|
|
9
|
+
export declare namespace DateRangePickerInput {
|
|
10
|
+
var displayName: string;
|
|
11
|
+
}
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
26
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
|
+
};
|
|
28
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
+
exports.DateRangePickerInput = void 0;
|
|
30
|
+
const date_range_picker_input_1 = require("@uxf/ui/date-range-picker-input");
|
|
31
|
+
const dayjs_1 = __importStar(require("dayjs"));
|
|
32
|
+
const react_1 = __importDefault(require("react"));
|
|
33
|
+
const react_hook_form_1 = require("react-hook-form");
|
|
34
|
+
const customParseFormat_1 = __importDefault(require("dayjs/plugin/customParseFormat"));
|
|
35
|
+
const date_range_picker_input_2 = require("@uxf/ui/date-range-picker-input/date-range-picker-input");
|
|
36
|
+
(0, dayjs_1.extend)(customParseFormat_1.default);
|
|
37
|
+
const OUTPUT_DATE_FORMAT = "YYYY-MM-DD";
|
|
38
|
+
function DateRangePickerInput(props) {
|
|
39
|
+
var _a, _b, _c, _d, _e, _f;
|
|
40
|
+
const { field, fieldState } = (0, react_hook_form_1.useController)({
|
|
41
|
+
control: props.control,
|
|
42
|
+
defaultValue: props.defaultValue,
|
|
43
|
+
name: props.name,
|
|
44
|
+
rules: {
|
|
45
|
+
required: props.isRequired ? props.requiredMessage || "Toto pole je povinné" : undefined,
|
|
46
|
+
...((_a = props.rules) !== null && _a !== void 0 ? _a : {}),
|
|
47
|
+
validate: {
|
|
48
|
+
validDate: (value) => {
|
|
49
|
+
if (!value) {
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
const { from, to } = (0, date_range_picker_input_2.splitValueToRange)(value);
|
|
53
|
+
const fromIsValid = (0, dayjs_1.default)(from, date_range_picker_input_2.ALLOWED_DATE_FORMAT, true).isValid();
|
|
54
|
+
const toIsValid = (0, dayjs_1.default)(to, date_range_picker_input_2.ALLOWED_DATE_FORMAT, true).isValid();
|
|
55
|
+
if (!fromIsValid || !toIsValid) {
|
|
56
|
+
return "Rozsah musí být ve formátu D. M. YYYY. - D. M. YYYY.";
|
|
57
|
+
}
|
|
58
|
+
if ((0, dayjs_1.default)(from).isAfter((0, dayjs_1.default)(to), "day")) {
|
|
59
|
+
return "Koncové datum nemůže předcházet počátečnímu datu.";
|
|
60
|
+
}
|
|
61
|
+
},
|
|
62
|
+
...(typeof ((_b = props.rules) === null || _b === void 0 ? void 0 : _b.validate) === "function"
|
|
63
|
+
? { custom: props.rules.validate }
|
|
64
|
+
: (_d = (_c = props.rules) === null || _c === void 0 ? void 0 : _c.validate) !== null && _d !== void 0 ? _d : {}),
|
|
65
|
+
},
|
|
66
|
+
},
|
|
67
|
+
shouldUnregister: props.shouldUnregister,
|
|
68
|
+
});
|
|
69
|
+
const onBlur = (event) => {
|
|
70
|
+
var _a;
|
|
71
|
+
field.onBlur();
|
|
72
|
+
(_a = props.onBlur) === null || _a === void 0 ? void 0 : _a.call(props, event);
|
|
73
|
+
};
|
|
74
|
+
const onChange = (value, event) => {
|
|
75
|
+
var _a;
|
|
76
|
+
if (value) {
|
|
77
|
+
const { from, to } = (0, date_range_picker_input_2.splitValueToRange)(value);
|
|
78
|
+
const fromIsValid = (0, dayjs_1.default)(from, date_range_picker_input_2.ALLOWED_DATE_FORMAT, true).isValid();
|
|
79
|
+
const toIsValid = (0, dayjs_1.default)(to, date_range_picker_input_2.ALLOWED_DATE_FORMAT, true).isValid();
|
|
80
|
+
if (fromIsValid || toIsValid) {
|
|
81
|
+
field.onChange((fromIsValid ? (0, dayjs_1.default)(from, date_range_picker_input_2.ALLOWED_DATE_FORMAT, true).format(OUTPUT_DATE_FORMAT) : from) +
|
|
82
|
+
date_range_picker_input_2.SEPARATOR +
|
|
83
|
+
(toIsValid ? (0, dayjs_1.default)(to, date_range_picker_input_2.ALLOWED_DATE_FORMAT, true).format(OUTPUT_DATE_FORMAT) : to));
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
else {
|
|
87
|
+
field.onChange(value);
|
|
88
|
+
}
|
|
89
|
+
(_a = props.onChange) === null || _a === void 0 ? void 0 : _a.call(props, value, event);
|
|
90
|
+
};
|
|
91
|
+
const { from: fieldFrom, to: fieldTo } = (0, date_range_picker_input_2.splitValueToRange)(field.value);
|
|
92
|
+
const parsedFrom = (0, dayjs_1.default)(fieldFrom, date_range_picker_input_2.ALLOWED_DATE_FORMAT, true);
|
|
93
|
+
const parsedTo = (0, dayjs_1.default)(fieldTo, date_range_picker_input_2.ALLOWED_DATE_FORMAT, true);
|
|
94
|
+
const value = field.value
|
|
95
|
+
? parsedFrom.isValid() || parsedTo.isValid()
|
|
96
|
+
? (parsedFrom.isValid() ? parsedFrom.format(date_range_picker_input_2.DISPLAY_DATE_FORMAT) : fieldFrom) +
|
|
97
|
+
date_range_picker_input_2.SEPARATOR +
|
|
98
|
+
(parsedTo.isValid() ? parsedTo.format(date_range_picker_input_2.DISPLAY_DATE_FORMAT) : fieldTo)
|
|
99
|
+
: field.value
|
|
100
|
+
: null;
|
|
101
|
+
return (react_1.default.createElement(date_range_picker_input_1.DateRangePickerInput, { className: props.className, form: props.form, helperText: (_f = (_e = fieldState.error) === null || _e === void 0 ? void 0 : _e.message) !== null && _f !== void 0 ? _f : props.helperText, hiddenLabel: props.hiddenLabel, id: props.id, isClearable: props.isClearable, isDisabled: props.isDisabled, isInvalid: !!fieldState.error, isReadOnly: props.isReadOnly, isRequired: props.isRequired, label: props.label, leftAddon: props.leftAddon, leftElement: props.leftElement, name: field.name, numberOfMonths: props.numberOfMonths, onBlur: onBlur, onChange: onChange, onFocus: props.onFocus, placeholder: props.placeholder, popoverPlacement: props.popoverPlacement, popoverStrategy: props.popoverStrategy, ref: field.ref, rightAddon: props.rightAddon, rightElement: props.rightElement, size: props.size, triggerElement: props.triggerElement, value: value, variant: props.variant }));
|
|
102
|
+
}
|
|
103
|
+
exports.DateRangePickerInput = DateRangePickerInput;
|
|
104
|
+
DateRangePickerInput.displayName = "UxfFormDateRangePickerInput";
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { DateRangePickerInput } from "./date-range-picker-input";
|
|
3
|
+
declare const _default: {
|
|
4
|
+
title: string;
|
|
5
|
+
component: typeof DateRangePickerInput;
|
|
6
|
+
};
|
|
7
|
+
export default _default;
|
|
8
|
+
export declare function Default(): React.JSX.Element;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.Default = void 0;
|
|
7
|
+
const react_1 = __importDefault(require("react"));
|
|
8
|
+
const date_range_picker_input_1 = require("./date-range-picker-input");
|
|
9
|
+
const button_1 = require("@uxf/ui/button");
|
|
10
|
+
const storybook_form_1 = require("../storybook/storybook-form");
|
|
11
|
+
exports.default = {
|
|
12
|
+
title: "Form/DateRangePickerInput",
|
|
13
|
+
component: date_range_picker_input_1.DateRangePickerInput,
|
|
14
|
+
};
|
|
15
|
+
function Default() {
|
|
16
|
+
const storyFormDatePickers = (control) => (react_1.default.createElement("div", { className: "space-y-4" },
|
|
17
|
+
react_1.default.createElement(date_range_picker_input_1.DateRangePickerInput, { label: "Default date range picker", name: "default", control: control, isClearable: true, isRequired: true }),
|
|
18
|
+
react_1.default.createElement(date_range_picker_input_1.DateRangePickerInput, { label: "Date range picker with two months", name: "twomonths", numberOfMonths: 2, control: control, isClearable: true, isRequired: true }),
|
|
19
|
+
react_1.default.createElement(button_1.Button, { type: "submit" }, "Submit")));
|
|
20
|
+
return (react_1.default.createElement(storybook_form_1.StorybookForm, null, ({ control }) => (react_1.default.createElement("div", { className: "flex flex-col lg:flex-row" },
|
|
21
|
+
react_1.default.createElement("div", { className: "light space-y-2 p-20 lg:w-1/2" }, storyFormDatePickers(control)),
|
|
22
|
+
react_1.default.createElement("div", { className: "dark space-y-2 bg-gray-900 p-20 text-white lg:w-1/2" }, storyFormDatePickers(control))))));
|
|
23
|
+
}
|
|
24
|
+
exports.Default = Default;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./date-range-picker-input";
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./date-range-picker-input"), exports);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@uxf/form",
|
|
3
|
-
"version": "10.0.0-beta.
|
|
3
|
+
"version": "10.0.0-beta.46",
|
|
4
4
|
"description": "",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
"author": "UX Fans s.r.o",
|
|
13
13
|
"license": "MIT",
|
|
14
14
|
"dependencies": {
|
|
15
|
-
"@uxf/ui": "10.0.0-beta.
|
|
15
|
+
"@uxf/ui": "10.0.0-beta.46",
|
|
16
16
|
"react-hook-form": "7.44.3",
|
|
17
17
|
"coordinate-parser": "1.0.7"
|
|
18
18
|
}
|