@uxf/form 10.5.0 → 10.6.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.
@@ -35,23 +35,24 @@ const react_hook_form_1 = require("react-hook-form");
35
35
  const form_id_context_1 = require("../form-id-context");
36
36
  (0, dayjs_1.extend)(customParseFormat_1.default);
37
37
  function DatePickerInput(props) {
38
- var _a, _b, _c, _d, _e, _f, _g;
38
+ var _a, _b, _c, _d, _e, _f, _g, _h;
39
39
  const formId = (0, form_id_context_1.useFormIdContext)();
40
40
  const id = (_a = props.id) !== null && _a !== void 0 ? _a : `${formId}__${props.name}`;
41
+ const displayDateFormat = (_b = props.displayDateFormat) !== null && _b !== void 0 ? _b : date_picker_input_1.DISPLAY_DATE_FORMAT;
41
42
  const { field, fieldState } = (0, react_hook_form_1.useController)({
42
43
  control: props.control,
43
44
  defaultValue: props.defaultValue,
44
45
  name: props.name,
45
46
  rules: {
46
47
  required: props.isRequired ? props.requiredMessage || "Toto pole je povinné" : undefined,
47
- ...((_b = props.rules) !== null && _b !== void 0 ? _b : {}),
48
+ ...((_c = props.rules) !== null && _c !== void 0 ? _c : {}),
48
49
  validate: {
49
50
  validDate: (value) => {
50
51
  if (!value) {
51
52
  return;
52
53
  }
53
54
  if (!(0, dayjs_1.default)(value, date_picker_input_1.OUTPUT_DATE_FORMAT, true).isValid()) {
54
- return `Datum musí být ve formátu ${date_picker_input_1.DISPLAY_DATE_FORMAT}.`;
55
+ return `Datum musí být ve formátu ${displayDateFormat}.`;
55
56
  }
56
57
  },
57
58
  validDateRange: (value) => {
@@ -59,15 +60,15 @@ function DatePickerInput(props) {
59
60
  return;
60
61
  }
61
62
  if (props.minDate && (0, dayjs_1.default)(value, date_picker_input_1.OUTPUT_DATE_FORMAT, true).isBefore(props.minDate)) {
62
- return `Minimální datum, který je možné zadat, je: ${(0, dayjs_1.default)(props.minDate).format(date_picker_input_1.DISPLAY_DATE_FORMAT)}`;
63
+ return `Minimální datum, který je možné zadat, je: ${(0, dayjs_1.default)(props.minDate).format(displayDateFormat)}`;
63
64
  }
64
65
  if (props.maxDate && (0, dayjs_1.default)(value, date_picker_input_1.OUTPUT_DATE_FORMAT, true).isAfter(props.maxDate)) {
65
- return `Maximální datum, který je možné zadat, je: ${(0, dayjs_1.default)(props.maxDate).format(date_picker_input_1.DISPLAY_DATE_FORMAT)}`;
66
+ return `Maximální datum, který je možné zadat, je: ${(0, dayjs_1.default)(props.maxDate).format(displayDateFormat)}`;
66
67
  }
67
68
  },
68
- ...(typeof ((_c = props.rules) === null || _c === void 0 ? void 0 : _c.validate) === "function"
69
+ ...(typeof ((_d = props.rules) === null || _d === void 0 ? void 0 : _d.validate) === "function"
69
70
  ? { custom: props.rules.validate }
70
- : (_e = (_d = props.rules) === null || _d === void 0 ? void 0 : _d.validate) !== null && _e !== void 0 ? _e : {}),
71
+ : (_f = (_e = props.rules) === null || _e === void 0 ? void 0 : _e.validate) !== null && _f !== void 0 ? _f : {}),
71
72
  },
72
73
  },
73
74
  shouldUnregister: props.shouldUnregister,
@@ -82,7 +83,7 @@ function DatePickerInput(props) {
82
83
  field.onChange(value);
83
84
  (_a = props.onChange) === null || _a === void 0 ? void 0 : _a.call(props, value, event);
84
85
  };
85
- return (react_1.default.createElement(date_picker_input_1.DatePickerInput, { autoFocus: props.autoFocus, bottomContent: props.bottomContent, className: props.className, form: props.form, helperText: (_g = (_f = fieldState.error) === null || _f === void 0 ? void 0 : _f.message) !== null && _g !== void 0 ? _g : props.helperText, hiddenLabel: props.hiddenLabel, id: 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, maxDate: props.maxDate, minDate: props.minDate, name: field.name, 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, unavailableDates: props.unavailableDates, value: field.value, variant: props.variant }));
86
+ return (react_1.default.createElement(date_picker_input_1.DatePickerInput, { allowedDateFormats: props.allowedDateFormats, autoFocus: props.autoFocus, bottomContent: props.bottomContent, className: props.className, displayDateFormat: props.displayDateFormat, form: props.form, helperText: (_h = (_g = fieldState.error) === null || _g === void 0 ? void 0 : _g.message) !== null && _h !== void 0 ? _h : props.helperText, hiddenLabel: props.hiddenLabel, id: 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, maxDate: props.maxDate, minDate: props.minDate, name: field.name, 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, unavailableDates: props.unavailableDates, value: field.value, variant: props.variant }));
86
87
  }
87
88
  exports.DatePickerInput = DatePickerInput;
88
89
  DatePickerInput.displayName = "UxfFormDatePickerInput";
@@ -18,6 +18,7 @@ function Default() {
18
18
  react_1.default.createElement(date_picker_input_1.DatePickerInput, { control: control, isClearable: true, isRequired: true, label: "Default date picker", name: "default" }),
19
19
  react_1.default.createElement(date_picker_input_1.DatePickerInput, { control: control, isClearable: true, isRequired: true, label: "Default date picker with default value", name: "withDefaultValue" }),
20
20
  react_1.default.createElement(date_picker_input_1.DatePickerInput, { control: control, isClearable: true, isRequired: true, minDate: "2023-06-10", maxDate: "2023-06-20", label: "Date picker with input validation", name: "withMinMaxValidation", placeholder: "" }),
21
+ react_1.default.createElement(date_picker_input_1.DatePickerInput, { allowedDateFormats: ["MM/DD/YYYY", "M/D/YYYY"], control: control, displayDateFormat: "MM/DD/YYYY", id: "date-custom-format", isClearable: true, label: "Datum s vlastn\u00EDm form\u00E1tem (US)", name: "date" }),
21
22
  react_1.default.createElement(button_1.Button, { type: "submit" }, "Submit")));
22
23
  return (react_1.default.createElement(storybook_form_1.StorybookForm, { defaultValues: {
23
24
  withDefaultValue: (0, dayjs_1.default)("2023-10-20T14:32:10.511").format("YYYY-MM-DD"),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@uxf/form",
3
- "version": "10.5.0",
3
+ "version": "10.6.0",
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.5.0",
15
+ "@uxf/ui": "10.6.0",
16
16
  "coordinate-parser": "1.0.7",
17
17
  "dayjs": "1.11.10",
18
18
  "react-hook-form": "7.47.0"