@uxf/form 1.0.0-beta.23 β 1.0.0-beta.26
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/combobox/combobox.d.ts +5 -0
- package/combobox/combobox.jsx +21 -0
- package/combobox/combobox.stories.d.ts +8 -0
- package/combobox/combobox.stories.jsx +26 -0
- package/combobox/index.d.ts +1 -0
- package/combobox/index.js +17 -0
- package/package.json +2 -2
- package/select/index.d.ts +1 -0
- package/select/index.js +17 -0
- package/select/select.d.ts +5 -0
- package/select/select.jsx +21 -0
- package/select/select.stories.d.ts +8 -0
- package/select/select.stories.jsx +26 -0
- package/storybook/form-data-printer.jsx +1 -3
- package/storybook/form.jsx +8 -6
- package/text-input/text-input.stories.jsx +5 -5
- package/textarea/index.d.ts +1 -0
- package/textarea/index.js +17 -0
- package/textarea/textarea.d.ts +5 -0
- package/textarea/textarea.jsx +28 -0
- package/textarea/textarea.stories.d.ts +8 -0
- package/textarea/textarea.stories.jsx +21 -0
|
@@ -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,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Combobox = void 0;
|
|
4
|
+
const combobox_1 = require("@uxf/ui/combobox");
|
|
5
|
+
const react_hook_form_1 = require("react-hook-form");
|
|
6
|
+
function Combobox(props) {
|
|
7
|
+
var _a;
|
|
8
|
+
const { field, fieldState } = (0, react_hook_form_1.useController)({
|
|
9
|
+
control: props.control,
|
|
10
|
+
name: props.name,
|
|
11
|
+
defaultValue: props.defaultValue,
|
|
12
|
+
shouldUnregister: props.shouldUnregister,
|
|
13
|
+
});
|
|
14
|
+
const onBlur = (event) => {
|
|
15
|
+
var _a;
|
|
16
|
+
field.onBlur();
|
|
17
|
+
(_a = props.onBlur) === null || _a === void 0 ? void 0 : _a.call(props, event);
|
|
18
|
+
};
|
|
19
|
+
return (<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}/>);
|
|
20
|
+
}
|
|
21
|
+
exports.Combobox = Combobox;
|
|
@@ -0,0 +1,26 @@
|
|
|
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 (<form_1.Form>
|
|
21
|
+
{({ control }) => (<div className="space-y-4">
|
|
22
|
+
<combobox_1.Combobox label="Combobox form" name="combobox" control={control} placeholder="placeholder" options={options} id="form-combobox"/>
|
|
23
|
+
</div>)}
|
|
24
|
+
</form_1.Form>);
|
|
25
|
+
}
|
|
26
|
+
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,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@uxf/form",
|
|
3
|
-
"version": "1.0.0-beta.
|
|
3
|
+
"version": "1.0.0-beta.26",
|
|
4
4
|
"description": "",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
"compile": "tsc -P tsconfig.json",
|
|
11
11
|
"typecheck": "tsc --noEmit --skipLibCheck"
|
|
12
12
|
},
|
|
13
|
-
"author": "",
|
|
13
|
+
"author": "UX Fans s.r.o",
|
|
14
14
|
"license": "MIT",
|
|
15
15
|
"dependencies": {
|
|
16
16
|
"@uxf/ui": "*",
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./select";
|
package/select/index.js
ADDED
|
@@ -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,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Select = void 0;
|
|
4
|
+
const select_1 = require("@uxf/ui/select");
|
|
5
|
+
const react_hook_form_1 = require("react-hook-form");
|
|
6
|
+
function Select(props) {
|
|
7
|
+
var _a;
|
|
8
|
+
const { field, fieldState } = (0, react_hook_form_1.useController)({
|
|
9
|
+
control: props.control,
|
|
10
|
+
name: props.name,
|
|
11
|
+
defaultValue: props.defaultValue,
|
|
12
|
+
shouldUnregister: props.shouldUnregister,
|
|
13
|
+
});
|
|
14
|
+
const onBlur = (event) => {
|
|
15
|
+
var _a;
|
|
16
|
+
field.onBlur();
|
|
17
|
+
(_a = props.onBlur) === null || _a === void 0 ? void 0 : _a.call(props, event);
|
|
18
|
+
};
|
|
19
|
+
return (<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}/>);
|
|
20
|
+
}
|
|
21
|
+
exports.Select = Select;
|
|
@@ -0,0 +1,26 @@
|
|
|
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 (<form_1.Form>
|
|
21
|
+
{({ control }) => (<div className="space-y-4">
|
|
22
|
+
<select_1.Select label="Select form" name="select" control={control} placeholder="placeholder" options={options} id="form-select"/>
|
|
23
|
+
</div>)}
|
|
24
|
+
</form_1.Form>);
|
|
25
|
+
}
|
|
26
|
+
exports.Default = Default;
|
|
@@ -4,8 +4,6 @@ exports.FormDataPrinter = void 0;
|
|
|
4
4
|
const react_hook_form_1 = require("react-hook-form");
|
|
5
5
|
function FormDataPrinter(props) {
|
|
6
6
|
const data = (0, react_hook_form_1.useWatch)({ control: props.control });
|
|
7
|
-
return
|
|
8
|
-
{JSON.stringify(data, null, " ")}
|
|
9
|
-
</pre>);
|
|
7
|
+
return <pre className="bg-gray-100 p-2 text-sm">{JSON.stringify(data, null, " ")}</pre>;
|
|
10
8
|
}
|
|
11
9
|
exports.FormDataPrinter = FormDataPrinter;
|
package/storybook/form.jsx
CHANGED
|
@@ -5,11 +5,13 @@ const react_hook_form_1 = require("react-hook-form");
|
|
|
5
5
|
const form_data_printer_1 = require("./form-data-printer");
|
|
6
6
|
function Form(props) {
|
|
7
7
|
const form = (0, react_hook_form_1.useForm)();
|
|
8
|
-
return (
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
8
|
+
return (
|
|
9
|
+
// eslint-disable-next-line no-console
|
|
10
|
+
<form onSubmit={form.handleSubmit(console.log)}>
|
|
11
|
+
{props.children(form)}
|
|
12
|
+
<div className="mt-4">
|
|
13
|
+
<form_data_printer_1.FormDataPrinter control={form.control}/>
|
|
14
|
+
</div>
|
|
15
|
+
</form>);
|
|
14
16
|
}
|
|
15
17
|
exports.Form = Form;
|
|
@@ -13,10 +13,10 @@ exports.default = {
|
|
|
13
13
|
};
|
|
14
14
|
function Default() {
|
|
15
15
|
return (<form_1.Form>
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
16
|
+
{({ control }) => (<div className="space-y-4">
|
|
17
|
+
<text_input_1.TextInput label="Basic text input" name="textFieldBasic" control={control}/>
|
|
18
|
+
<text_input_1.TextInput label="Full text input" name="textFieldFull" control={control} leftAddon="https://" rightAddon=".uxf.cz" leftElement="π·" rightElement="π" helperText="Helper text" placeholder="placeholder"/>
|
|
19
|
+
</div>)}
|
|
20
|
+
</form_1.Form>);
|
|
21
21
|
}
|
|
22
22
|
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,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Textarea = void 0;
|
|
4
|
+
const textarea_1 = require("@uxf/ui/textarea");
|
|
5
|
+
const react_hook_form_1 = require("react-hook-form");
|
|
6
|
+
const react_1 = require("react");
|
|
7
|
+
function Textarea(props) {
|
|
8
|
+
var _a;
|
|
9
|
+
const { control, rules = {}, shouldUnregister, autoComplete, className, disabled, disableAutoHeight, form, label, maxLength, minLength, onBlur, onFocus, placeholder, readOnly, required, rows, style, name, } = props;
|
|
10
|
+
const { field, fieldState } = (0, react_hook_form_1.useController)({
|
|
11
|
+
control,
|
|
12
|
+
name,
|
|
13
|
+
rules: {
|
|
14
|
+
required: required ? "Toto pole je povinnΓ©" : undefined,
|
|
15
|
+
...rules,
|
|
16
|
+
},
|
|
17
|
+
shouldUnregister,
|
|
18
|
+
});
|
|
19
|
+
const _onBlur = (0, react_1.useCallback)((e) => {
|
|
20
|
+
field.onBlur();
|
|
21
|
+
if (onBlur) {
|
|
22
|
+
onBlur(e);
|
|
23
|
+
}
|
|
24
|
+
}, [field, onBlur]);
|
|
25
|
+
const inputId = `${form ? form + "__" : ""}${name}`;
|
|
26
|
+
return (<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}/>);
|
|
27
|
+
}
|
|
28
|
+
exports.Textarea = Textarea;
|
|
@@ -0,0 +1,21 @@
|
|
|
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 (<form_1.Form>
|
|
16
|
+
{({ control }) => (<div className="space-y-4">
|
|
17
|
+
<textarea_1.Textarea label="Textarea" name="textarea" control={control} placeholder="placeholder" form="form-textarea"/>
|
|
18
|
+
</div>)}
|
|
19
|
+
</form_1.Form>);
|
|
20
|
+
}
|
|
21
|
+
exports.Default = Default;
|