@uxf/form 11.15.3 → 11.16.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/components.d.ts CHANGED
@@ -13,6 +13,7 @@ import * as gpsInputStories from "./gps-input/gps-input.stories";
13
13
  import * as multiComboboxStories from "./multi-combobox/multi-combobox.stories";
14
14
  import * as multiSelectStories from "./multi-select/multi-select.stories";
15
15
  import * as numberInputStories from "./number-input/number-input.stories";
16
+ import * as passwordInputStories from "./password-input/password-input.stories";
16
17
  import * as radioGroupStories from "./radio-group/radio-group.stories";
17
18
  import * as selectStories from "./select/select.stories";
18
19
  import * as textInputStories from "./text-input/text-input.stories";
@@ -80,6 +81,10 @@ export declare const components: {
80
81
  readonly title: "NumberInput";
81
82
  readonly stories: typeof numberInputStories;
82
83
  };
84
+ readonly "password-input": {
85
+ readonly title: "PasswordInput";
86
+ readonly stories: typeof passwordInputStories;
87
+ };
83
88
  readonly "radio-group": {
84
89
  readonly title: "RadioGroup";
85
90
  readonly stories: typeof radioGroupStories;
package/components.js CHANGED
@@ -40,6 +40,7 @@ const gpsInputStories = __importStar(require("./gps-input/gps-input.stories"));
40
40
  const multiComboboxStories = __importStar(require("./multi-combobox/multi-combobox.stories"));
41
41
  const multiSelectStories = __importStar(require("./multi-select/multi-select.stories"));
42
42
  const numberInputStories = __importStar(require("./number-input/number-input.stories"));
43
+ const passwordInputStories = __importStar(require("./password-input/password-input.stories"));
43
44
  const radioGroupStories = __importStar(require("./radio-group/radio-group.stories"));
44
45
  const selectStories = __importStar(require("./select/select.stories"));
45
46
  const textInputStories = __importStar(require("./text-input/text-input.stories"));
@@ -107,6 +108,10 @@ exports.components = {
107
108
  title: "NumberInput",
108
109
  stories: numberInputStories
109
110
  },
111
+ "password-input": {
112
+ title: "PasswordInput",
113
+ stories: passwordInputStories
114
+ },
110
115
  "radio-group": {
111
116
  title: "RadioGroup",
112
117
  stories: radioGroupStories
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@uxf/form",
3
- "version": "11.15.3",
3
+ "version": "11.16.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": "11.15.3",
15
+ "@uxf/ui": "11.16.0",
16
16
  "coordinate-parser": "1.0.7",
17
17
  "dayjs": "1.11.10",
18
18
  "react-hook-form": "7.51.0"
@@ -0,0 +1 @@
1
+ # PasswordInput
@@ -0,0 +1 @@
1
+ export * from "./password-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("./password-input"), exports);
@@ -0,0 +1,14 @@
1
+ import { TextInputProps as UITextInputProps } from "@uxf/ui/text-input";
2
+ import { FormControlProps } from "@uxf/ui/types";
3
+ import React, { ReactNode } from "react";
4
+ import { FieldValues, UseControllerProps } from "react-hook-form";
5
+ export type PasswordInputProps<FormData extends FieldValues> = UseControllerProps<FormData> & Omit<UITextInputProps, "isInvalid" | "max" | "min" | "name" | "onChange" | "value" | "type"> & {
6
+ minLengthMessage?: string;
7
+ onChange?: FormControlProps<string | null>["onChange"];
8
+ renderVisibilitySetter?: (isVisible: boolean, onToggle: () => void) => ReactNode;
9
+ requiredMessage?: string;
10
+ };
11
+ export declare function PasswordInput<FormData extends FieldValues>(props: PasswordInputProps<FormData>): React.JSX.Element;
12
+ export declare namespace PasswordInput {
13
+ var displayName: string;
14
+ }
@@ -0,0 +1,93 @@
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
+ Object.defineProperty(exports, "__esModule", { value: true });
26
+ exports.PasswordInput = void 0;
27
+ const useOnUnmount_1 = require("@uxf/core/hooks/useOnUnmount");
28
+ const composeRefs_1 = require("@uxf/core/utils/composeRefs");
29
+ const is_nil_1 = require("@uxf/core/utils/is-nil");
30
+ const button_1 = require("@uxf/ui/button");
31
+ const icon_1 = require("@uxf/ui/icon");
32
+ const text_input_1 = require("@uxf/ui/text-input");
33
+ const react_1 = __importStar(require("react"));
34
+ const react_hook_form_1 = require("react-hook-form");
35
+ const form_id_context_1 = require("../form-id-context");
36
+ function usePasswordVisibility() {
37
+ const inputRef = (0, react_1.useRef)(null);
38
+ const [isVisible, setIsVisible] = (0, react_1.useState)(false);
39
+ const timer = (0, react_1.useRef)();
40
+ const visibilityChangeHandler = () => {
41
+ if ((0, is_nil_1.isNil)(inputRef.current)) {
42
+ return;
43
+ }
44
+ setIsVisible((prev) => !prev);
45
+ timer.current = window.setTimeout(() => {
46
+ if ((0, is_nil_1.isNil)(inputRef.current)) {
47
+ return;
48
+ }
49
+ const newCursorPosition = inputRef.current.value.length;
50
+ inputRef.current.selectionStart = newCursorPosition;
51
+ inputRef.current.selectionEnd = newCursorPosition;
52
+ }, 0);
53
+ };
54
+ (0, useOnUnmount_1.useOnUnmount)(() => clearTimeout(timer.current));
55
+ return { isVisible, inputRef, onToggle: visibilityChangeHandler };
56
+ }
57
+ function PasswordInput(props) {
58
+ var _a, _b, _c, _d, _e, _f, _g;
59
+ const formId = (0, form_id_context_1.useFormIdContext)();
60
+ const id = (_a = props.id) !== null && _a !== void 0 ? _a : `${formId}__${props.name}`;
61
+ const { field, fieldState } = (0, react_hook_form_1.useController)({
62
+ control: props.control,
63
+ defaultValue: props.defaultValue,
64
+ name: props.name,
65
+ shouldUnregister: props.shouldUnregister,
66
+ rules: {
67
+ minLength: props.minLength
68
+ ? {
69
+ value: Number(props.minLength),
70
+ message: props.minLengthMessage || `Heslo musí být nejméně ${props.minLength} znaků dlouhé.`,
71
+ }
72
+ : undefined,
73
+ required: props.isRequired ? props.requiredMessage || "Toto pole je povinné" : undefined,
74
+ ...((_b = props.rules) !== null && _b !== void 0 ? _b : {}),
75
+ },
76
+ });
77
+ const passwordVisibility = usePasswordVisibility();
78
+ const inputRef = (0, composeRefs_1.composeRefs)(field.ref, passwordVisibility.inputRef);
79
+ const onBlur = (event) => {
80
+ var _a;
81
+ field.onBlur();
82
+ (_a = props.onBlur) === null || _a === void 0 ? void 0 : _a.call(props, event);
83
+ };
84
+ const onChange = (value, event) => {
85
+ var _a;
86
+ field.onChange(value);
87
+ (_a = props.onChange) === null || _a === void 0 ? void 0 : _a.call(props, value, event);
88
+ };
89
+ return (react_1.default.createElement(text_input_1.TextInput, { autoComplete: props.autoComplete, autoFocus: props.autoFocus, className: props.className, enterKeyHint: props.enterKeyHint, form: props.form, helperText: (_d = (_c = fieldState.error) === null || _c === void 0 ? void 0 : _c.message) !== null && _d !== void 0 ? _d : props.helperText, hiddenLabel: props.hiddenLabel, id: id, inputMode: props.inputMode, isDisabled: props.isDisabled, isFocused: props.isFocused, isInvalid: !!fieldState.error, isReadOnly: props.isReadOnly, isRequired: props.isRequired, label: props.label, leftAddon: props.leftAddon, leftElement: props.leftElement, maxLength: props.maxLength, minLength: props.minLength, name: field.name, onBlur: onBlur, onChange: onChange, onFocus: props.onFocus, onKeyDown: props.onKeyDown, pattern: props.pattern, placeholder: props.placeholder, ref: inputRef, rightAddon: props.rightAddon, rightElement: (_f = (_e = props.renderVisibilitySetter) === null || _e === void 0 ? void 0 : _e.call(props, passwordVisibility.isVisible, passwordVisibility.onToggle)) !== null && _f !== void 0 ? _f : (react_1.default.createElement(button_1.Button, { onClick: passwordVisibility.onToggle, size: "xs", variant: "text" },
90
+ react_1.default.createElement(icon_1.Icon, { size: 20, name: passwordVisibility.isVisible ? "eye" : "eye-slash" }))), size: props.size, style: props.style, type: passwordVisibility.isVisible ? "text" : "password", value: (_g = field.value) !== null && _g !== void 0 ? _g : "", variant: props.variant }));
91
+ }
92
+ exports.PasswordInput = PasswordInput;
93
+ PasswordInput.displayName = "UxfFormPasswordInput";
@@ -0,0 +1,8 @@
1
+ import React from "react";
2
+ import { PasswordInput } from "./password-input";
3
+ declare const _default: {
4
+ title: string;
5
+ component: typeof PasswordInput;
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 button_1 = require("@uxf/ui/button");
8
+ const react_1 = __importDefault(require("react"));
9
+ const storybook_form_1 = require("../storybook/storybook-form");
10
+ const password_input_1 = require("./password-input");
11
+ exports.default = {
12
+ title: "Form/PasswordInput",
13
+ component: password_input_1.PasswordInput,
14
+ };
15
+ function Default() {
16
+ const storyFormPasswordInputs = (control) => (react_1.default.createElement("div", { className: "mb-4 space-y-4 p-4" },
17
+ react_1.default.createElement(password_input_1.PasswordInput, { control: control, label: "Default input", name: "default" }),
18
+ react_1.default.createElement(password_input_1.PasswordInput, { control: control, label: "Min length 8", minLength: 12, name: "minLength", isRequired: true }),
19
+ react_1.default.createElement(password_input_1.PasswordInput, { control: control, label: "Required input", name: "required", isRequired: true }),
20
+ react_1.default.createElement(button_1.Button, { type: "submit" }, "Submit")));
21
+ return (react_1.default.createElement(storybook_form_1.StorybookForm, null, ({ control }) => (react_1.default.createElement("div", { className: "flex flex-col lg:flex-row" },
22
+ react_1.default.createElement("div", { className: "space-y-2 p-20 lg:w-1/2" }, storyFormPasswordInputs(control))))));
23
+ }
24
+ exports.Default = Default;
package/readmes.d.ts CHANGED
@@ -16,6 +16,7 @@ export declare const readmes: {
16
16
  readonly "multi-combobox": typeof avatarFileInputReadme;
17
17
  readonly "multi-select": typeof avatarFileInputReadme;
18
18
  readonly "number-input": typeof avatarFileInputReadme;
19
+ readonly "password-input": typeof avatarFileInputReadme;
19
20
  readonly "radio-group": typeof avatarFileInputReadme;
20
21
  readonly select: typeof avatarFileInputReadme;
21
22
  readonly "text-input": typeof avatarFileInputReadme;
package/readmes.js CHANGED
@@ -20,12 +20,13 @@ const README_md_12 = __importDefault(require("./gps-input/README.md"));
20
20
  const README_md_13 = __importDefault(require("./multi-combobox/README.md"));
21
21
  const README_md_14 = __importDefault(require("./multi-select/README.md"));
22
22
  const README_md_15 = __importDefault(require("./number-input/README.md"));
23
- const README_md_16 = __importDefault(require("./radio-group/README.md"));
24
- const README_md_17 = __importDefault(require("./select/README.md"));
25
- const README_md_18 = __importDefault(require("./text-input/README.md"));
26
- const README_md_19 = __importDefault(require("./textarea/README.md"));
27
- const README_md_20 = __importDefault(require("./time-picker-input/README.md"));
28
- const README_md_21 = __importDefault(require("./toggle/README.md"));
23
+ const README_md_16 = __importDefault(require("./password-input/README.md"));
24
+ const README_md_17 = __importDefault(require("./radio-group/README.md"));
25
+ const README_md_18 = __importDefault(require("./select/README.md"));
26
+ const README_md_19 = __importDefault(require("./text-input/README.md"));
27
+ const README_md_20 = __importDefault(require("./textarea/README.md"));
28
+ const README_md_21 = __importDefault(require("./time-picker-input/README.md"));
29
+ const README_md_22 = __importDefault(require("./toggle/README.md"));
29
30
  exports.readmes = {
30
31
  "avatar-file-input": README_md_1.default,
31
32
  "checkbox-button": README_md_2.default,
@@ -42,10 +43,11 @@ exports.readmes = {
42
43
  "multi-combobox": README_md_13.default,
43
44
  "multi-select": README_md_14.default,
44
45
  "number-input": README_md_15.default,
45
- "radio-group": README_md_16.default,
46
- "select": README_md_17.default,
47
- "text-input": README_md_18.default,
48
- "textarea": README_md_19.default,
49
- "time-picker-input": README_md_20.default,
50
- "toggle": README_md_21.default,
46
+ "password-input": README_md_16.default,
47
+ "radio-group": README_md_17.default,
48
+ "select": README_md_18.default,
49
+ "text-input": README_md_19.default,
50
+ "textarea": README_md_20.default,
51
+ "time-picker-input": README_md_21.default,
52
+ "toggle": README_md_22.default,
51
53
  };