@uxf/form 1.0.0-beta.22 → 1.0.0-beta.27

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.
@@ -0,0 +1,5 @@
1
+ /// <reference types="react" />
2
+ import { ComboboxProps as UIComboboxProps } from "@uxf/ui/combobox";
3
+ import { FieldValues, UseControllerProps } from "react-hook-form";
4
+ export declare type ComboProps<FormData extends FieldValues> = UseControllerProps<FormData> & Omit<UIComboboxProps, "defaultValue" | "invalid" | "name" | "onChange" | "value">;
5
+ export declare function Combobox<FormData extends Record<string, any>>(props: ComboProps<FormData>): JSX.Element;
@@ -0,0 +1,25 @@
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.Combobox = void 0;
7
+ const combobox_1 = require("@uxf/ui/combobox");
8
+ const react_hook_form_1 = require("react-hook-form");
9
+ const react_1 = __importDefault(require("react"));
10
+ function Combobox(props) {
11
+ var _a;
12
+ const { field, fieldState } = (0, react_hook_form_1.useController)({
13
+ control: props.control,
14
+ name: props.name,
15
+ defaultValue: props.defaultValue,
16
+ shouldUnregister: props.shouldUnregister,
17
+ });
18
+ const onBlur = (event) => {
19
+ var _a;
20
+ field.onBlur();
21
+ (_a = props.onBlur) === null || _a === void 0 ? void 0 : _a.call(props, event);
22
+ };
23
+ return (react_1.default.createElement(combobox_1.Combobox, { id: props.id, name: props.name, value: field.value, onChange: (value) => field.onChange(value === null || value === void 0 ? void 0 : value.id), onFocus: props.onFocus, onBlur: onBlur, placeholder: props.placeholder, className: props.className, label: props.label, options: props.options, disabled: props.options.length === 0 || props.disabled, error: (_a = fieldState.error) === null || _a === void 0 ? void 0 : _a.message, invalid: fieldState.invalid, ref: field.ref, required: props.required, readOnly: props.readOnly }));
24
+ }
25
+ exports.Combobox = Combobox;
@@ -0,0 +1,8 @@
1
+ /// <reference types="react" />
2
+ import { Combobox } from "./combobox";
3
+ declare const _default: {
4
+ title: string;
5
+ component: typeof Combobox;
6
+ };
7
+ export default _default;
8
+ export declare function Default(): JSX.Element;
@@ -0,0 +1,23 @@
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 combobox_1 = require("./combobox");
9
+ const form_1 = require("../storybook/form");
10
+ exports.default = {
11
+ title: "Form/Combobox",
12
+ component: combobox_1.Combobox,
13
+ };
14
+ const options = [
15
+ { id: "one", label: "Option one" },
16
+ { id: "two", label: "Option two" },
17
+ { id: "three", label: "Option three" },
18
+ ];
19
+ function Default() {
20
+ return (react_1.default.createElement(form_1.Form, null, ({ control }) => (react_1.default.createElement("div", { className: "space-y-4" },
21
+ react_1.default.createElement(combobox_1.Combobox, { label: "Combobox form", name: "combobox", control: control, placeholder: "placeholder", options: options, id: "form-combobox" })))));
22
+ }
23
+ exports.Default = Default;
@@ -0,0 +1 @@
1
+ export * from "./combobox";
@@ -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("./combobox"), exports);
package/package.json CHANGED
@@ -1,17 +1,16 @@
1
1
  {
2
2
  "name": "@uxf/form",
3
- "version": "1.0.0-beta.22",
3
+ "version": "1.0.0-beta.27",
4
4
  "description": "",
5
5
  "publishConfig": {
6
6
  "access": "public"
7
7
  },
8
8
  "scripts": {
9
- "build": "npm run-script compile",
9
+ "build": "npm run compile",
10
10
  "compile": "tsc -P tsconfig.json",
11
- "typecheck": "tsc --noEmit --skipLibCheck",
12
- "prepublish": "npm run-script build"
11
+ "typecheck": "tsc --noEmit --skipLibCheck"
13
12
  },
14
- "author": "",
13
+ "author": "UX Fans s.r.o",
15
14
  "license": "MIT",
16
15
  "dependencies": {
17
16
  "@uxf/ui": "*",
@@ -0,0 +1 @@
1
+ export * from "./select";
@@ -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("./select"), exports);
@@ -0,0 +1,5 @@
1
+ /// <reference types="react" />
2
+ import { SelectProps as UISelectProps } from "@uxf/ui/select";
3
+ import { FieldValues, UseControllerProps } from "react-hook-form";
4
+ export declare type SelectProps<FormData extends FieldValues> = UseControllerProps<FormData> & Omit<UISelectProps, "defaultValue" | "invalid" | "name" | "onChange" | "value">;
5
+ export declare function Select<FormData extends Record<string, any>>(props: SelectProps<FormData>): JSX.Element;
@@ -0,0 +1,25 @@
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.Select = void 0;
7
+ const select_1 = require("@uxf/ui/select");
8
+ const react_hook_form_1 = require("react-hook-form");
9
+ const react_1 = __importDefault(require("react"));
10
+ function Select(props) {
11
+ var _a;
12
+ const { field, fieldState } = (0, react_hook_form_1.useController)({
13
+ control: props.control,
14
+ name: props.name,
15
+ defaultValue: props.defaultValue,
16
+ shouldUnregister: props.shouldUnregister,
17
+ });
18
+ const onBlur = (event) => {
19
+ var _a;
20
+ field.onBlur();
21
+ (_a = props.onBlur) === null || _a === void 0 ? void 0 : _a.call(props, event);
22
+ };
23
+ return (react_1.default.createElement(select_1.Select, { id: props.id, name: props.name, value: field.value, onChange: (value) => field.onChange(value === null || value === void 0 ? void 0 : value.id), onFocus: props.onFocus, onBlur: onBlur, placeholder: props.placeholder, className: props.className, label: props.label, options: props.options, disabled: props.options.length === 0 || props.disabled, error: (_a = fieldState.error) === null || _a === void 0 ? void 0 : _a.message, invalid: fieldState.invalid, ref: field.ref, required: props.required, readOnly: props.readOnly }));
24
+ }
25
+ exports.Select = Select;
@@ -0,0 +1,8 @@
1
+ /// <reference types="react" />
2
+ import { Select } from "./select";
3
+ declare const _default: {
4
+ title: string;
5
+ component: typeof Select;
6
+ };
7
+ export default _default;
8
+ export declare function Default(): JSX.Element;
@@ -0,0 +1,23 @@
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 select_1 = require("./select");
9
+ const form_1 = require("../storybook/form");
10
+ exports.default = {
11
+ title: "Form/Select",
12
+ component: select_1.Select,
13
+ };
14
+ const options = [
15
+ { id: "one", label: "Option one" },
16
+ { id: "two", label: "Option two" },
17
+ { id: "three", label: "Option three" },
18
+ ];
19
+ function Default() {
20
+ return (react_1.default.createElement(form_1.Form, null, ({ control }) => (react_1.default.createElement("div", { className: "space-y-4" },
21
+ react_1.default.createElement(select_1.Select, { label: "Select form", name: "select", control: control, placeholder: "placeholder", options: options, id: "form-select" })))));
22
+ }
23
+ exports.Default = Default;
@@ -0,0 +1,6 @@
1
+ /// <reference types="react" />
2
+ interface FormDataPrinterProps {
3
+ control: any;
4
+ }
5
+ export declare function FormDataPrinter(props: FormDataPrinterProps): JSX.Element;
6
+ export {};
@@ -0,0 +1,13 @@
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.FormDataPrinter = void 0;
7
+ const react_hook_form_1 = require("react-hook-form");
8
+ const react_1 = __importDefault(require("react"));
9
+ function FormDataPrinter(props) {
10
+ const data = (0, react_hook_form_1.useWatch)({ control: props.control });
11
+ return react_1.default.createElement("pre", { className: "bg-gray-100 p-2 text-sm" }, JSON.stringify(data, null, " "));
12
+ }
13
+ exports.FormDataPrinter = FormDataPrinter;
@@ -0,0 +1,7 @@
1
+ import { UseFormReturn } from "react-hook-form";
2
+ import { ReactNode } from "react";
3
+ interface FormProps {
4
+ children: (form: UseFormReturn) => ReactNode;
5
+ }
6
+ export declare function Form(props: FormProps): JSX.Element;
7
+ export {};
@@ -0,0 +1,19 @@
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.Form = void 0;
7
+ const react_hook_form_1 = require("react-hook-form");
8
+ const react_1 = __importDefault(require("react"));
9
+ const form_data_printer_1 = require("./form-data-printer");
10
+ function Form(props) {
11
+ const form = (0, react_hook_form_1.useForm)();
12
+ return (
13
+ // eslint-disable-next-line no-console
14
+ react_1.default.createElement("form", { onSubmit: form.handleSubmit(console.log) },
15
+ props.children(form),
16
+ react_1.default.createElement("div", { className: "mt-4" },
17
+ react_1.default.createElement(form_data_printer_1.FormDataPrinter, { control: form.control }))));
18
+ }
19
+ exports.Form = Form;
@@ -0,0 +1 @@
1
+ export * from "./text-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("./text-input"), exports);
@@ -0,0 +1,5 @@
1
+ /// <reference types="react" />
2
+ import { TextInputProps as UITextInputProps } from "@uxf/ui/text-input";
3
+ import { FieldValues, UseControllerProps } from "react-hook-form";
4
+ export declare type TextInputProps<FormData extends FieldValues> = UseControllerProps<FormData> & Omit<UITextInputProps, "value" | "onChange">;
5
+ export declare function TextInput<FormData extends Record<string, any>>(props: TextInputProps<FormData>): JSX.Element;
@@ -0,0 +1,23 @@
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.TextInput = void 0;
7
+ const text_input_1 = require("@uxf/ui/text-input");
8
+ const react_hook_form_1 = require("react-hook-form");
9
+ const react_1 = __importDefault(require("react"));
10
+ function TextInput(props) {
11
+ var _a, _b;
12
+ const { field, fieldState } = (0, react_hook_form_1.useController)({
13
+ control: props.control,
14
+ name: props.name,
15
+ });
16
+ const onBlur = (event) => {
17
+ var _a;
18
+ field.onBlur();
19
+ (_a = props.onBlur) === null || _a === void 0 ? void 0 : _a.call(props, event);
20
+ };
21
+ return (react_1.default.createElement(text_input_1.TextInput, { id: props.id, name: props.name, value: field.value, onChange: field.onChange, onFocus: props.onFocus, onBlur: onBlur, isRequired: props.isRequired, isReadOnly: props.isReadOnly, isDisabled: props.isDisabled, isInvalid: !!fieldState.error, helperText: (_b = (_a = fieldState.error) === null || _a === void 0 ? void 0 : _a.message) !== null && _b !== void 0 ? _b : props.helperText, placeholder: props.placeholder, leftElement: props.leftElement, rightElement: props.rightElement, variant: props.variant, size: props.size, className: props.className, label: props.label, form: props.form, inputMode: props.inputMode, leftAddon: props.leftAddon, rightAddon: props.rightAddon, autoComplete: props.autoComplete, enterKeyHint: props.enterKeyHint }));
22
+ }
23
+ exports.TextInput = TextInput;
@@ -0,0 +1,8 @@
1
+ /// <reference types="react" />
2
+ import { TextInput } from "./text-input";
3
+ declare const _default: {
4
+ title: string;
5
+ component: typeof TextInput;
6
+ };
7
+ export default _default;
8
+ export declare function Default(): JSX.Element;
@@ -0,0 +1,19 @@
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 text_input_1 = require("./text-input");
9
+ const form_1 = require("../storybook/form");
10
+ exports.default = {
11
+ title: "Form/TextInput",
12
+ component: text_input_1.TextInput,
13
+ };
14
+ function Default() {
15
+ return (react_1.default.createElement(form_1.Form, null, ({ control }) => (react_1.default.createElement("div", { className: "space-y-4" },
16
+ react_1.default.createElement(text_input_1.TextInput, { label: "Basic text input", name: "textFieldBasic", control: control }),
17
+ react_1.default.createElement(text_input_1.TextInput, { label: "Full text input", name: "textFieldFull", control: control, leftAddon: "https://", rightAddon: ".uxf.cz", leftElement: "\uD83C\uDF37", rightElement: "\uD83D\uDD14", helperText: "Helper text", placeholder: "placeholder" })))));
18
+ }
19
+ exports.Default = Default;
@@ -0,0 +1 @@
1
+ export * from "./textarea";
@@ -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("./textarea"), exports);
@@ -0,0 +1,5 @@
1
+ /// <reference types="react" />
2
+ import { TextareaProps as UITextareaProps } from "@uxf/ui/textarea";
3
+ import { FieldValues, UseControllerProps } from "react-hook-form";
4
+ export declare type TextareaProps<FormData extends FieldValues> = UseControllerProps<FormData> & Omit<UITextareaProps, "id" | "invalid" | "name" | "onChange" | "value">;
5
+ export declare function Textarea<FormData extends Record<string, any>>(props: TextareaProps<FormData>): JSX.Element;
@@ -0,0 +1,51 @@
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.Textarea = void 0;
27
+ const textarea_1 = require("@uxf/ui/textarea");
28
+ const react_hook_form_1 = require("react-hook-form");
29
+ const react_1 = __importStar(require("react"));
30
+ function Textarea(props) {
31
+ var _a;
32
+ const { control, rules = {}, shouldUnregister, autoComplete, className, disabled, disableAutoHeight, form, label, maxLength, minLength, onBlur, onFocus, placeholder, readOnly, required, rows, style, name, } = props;
33
+ const { field, fieldState } = (0, react_hook_form_1.useController)({
34
+ control,
35
+ name,
36
+ rules: {
37
+ required: required ? "Toto pole je povinné" : undefined,
38
+ ...rules,
39
+ },
40
+ shouldUnregister,
41
+ });
42
+ const _onBlur = (0, react_1.useCallback)((e) => {
43
+ field.onBlur();
44
+ if (onBlur) {
45
+ onBlur(e);
46
+ }
47
+ }, [field, onBlur]);
48
+ const inputId = `${form ? form + "__" : ""}${name}`;
49
+ return (react_1.default.createElement(textarea_1.Textarea, { error: (_a = fieldState.error) === null || _a === void 0 ? void 0 : _a.message, form: form, id: inputId, invalid: fieldState.invalid, name: field.name, onBlur: _onBlur, onChange: field.onChange, ref: field.ref, required: required, value: field.value || "", autoComplete: autoComplete, className: className, disabled: disabled, disableAutoHeight: disableAutoHeight, label: label, maxLength: maxLength, minLength: minLength, onFocus: onFocus, placeholder: placeholder, readOnly: readOnly, rows: rows, style: style }));
50
+ }
51
+ exports.Textarea = Textarea;
@@ -0,0 +1,8 @@
1
+ /// <reference types="react" />
2
+ import { Textarea } from "./textarea";
3
+ declare const _default: {
4
+ title: string;
5
+ component: typeof Textarea;
6
+ };
7
+ export default _default;
8
+ export declare function Default(): JSX.Element;
@@ -0,0 +1,18 @@
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 textarea_1 = require("./textarea");
9
+ const form_1 = require("../storybook/form");
10
+ exports.default = {
11
+ title: "Form/Textarea",
12
+ component: textarea_1.Textarea,
13
+ };
14
+ function Default() {
15
+ return (react_1.default.createElement(form_1.Form, null, ({ control }) => (react_1.default.createElement("div", { className: "space-y-4" },
16
+ react_1.default.createElement(textarea_1.Textarea, { label: "Textarea", name: "textarea", control: control, placeholder: "placeholder", form: "form-textarea" })))));
17
+ }
18
+ exports.Default = Default;