@uxf/form 1.0.0-beta.22 → 1.0.0-beta.23
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/package.json +3 -4
- package/storybook/form-data-printer.d.ts +6 -0
- package/storybook/form-data-printer.jsx +11 -0
- package/storybook/form.d.ts +7 -0
- package/storybook/form.jsx +15 -0
- package/text-input/index.d.ts +1 -0
- package/text-input/index.js +17 -0
- package/text-input/text-input.d.ts +5 -0
- package/text-input/text-input.jsx +19 -0
- package/text-input/text-input.stories.d.ts +8 -0
- package/text-input/text-input.stories.jsx +22 -0
package/package.json
CHANGED
|
@@ -1,15 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@uxf/form",
|
|
3
|
-
"version": "1.0.0-beta.
|
|
3
|
+
"version": "1.0.0-beta.23",
|
|
4
4
|
"description": "",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
7
7
|
},
|
|
8
8
|
"scripts": {
|
|
9
|
-
"build": "npm run
|
|
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
13
|
"author": "",
|
|
15
14
|
"license": "MIT",
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.FormDataPrinter = void 0;
|
|
4
|
+
const react_hook_form_1 = require("react-hook-form");
|
|
5
|
+
function FormDataPrinter(props) {
|
|
6
|
+
const data = (0, react_hook_form_1.useWatch)({ control: props.control });
|
|
7
|
+
return (<pre className="bg-gray-100 p-2 text-sm">
|
|
8
|
+
{JSON.stringify(data, null, " ")}
|
|
9
|
+
</pre>);
|
|
10
|
+
}
|
|
11
|
+
exports.FormDataPrinter = FormDataPrinter;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Form = void 0;
|
|
4
|
+
const react_hook_form_1 = require("react-hook-form");
|
|
5
|
+
const form_data_printer_1 = require("./form-data-printer");
|
|
6
|
+
function Form(props) {
|
|
7
|
+
const form = (0, react_hook_form_1.useForm)();
|
|
8
|
+
return (<form onSubmit={form.handleSubmit(console.log)}>
|
|
9
|
+
{props.children(form)}
|
|
10
|
+
<div className="mt-4">
|
|
11
|
+
<form_data_printer_1.FormDataPrinter control={form.control}/>
|
|
12
|
+
</div>
|
|
13
|
+
</form>);
|
|
14
|
+
}
|
|
15
|
+
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,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TextInput = void 0;
|
|
4
|
+
const text_input_1 = require("@uxf/ui/text-input");
|
|
5
|
+
const react_hook_form_1 = require("react-hook-form");
|
|
6
|
+
function TextInput(props) {
|
|
7
|
+
var _a, _b;
|
|
8
|
+
const { field, fieldState } = (0, react_hook_form_1.useController)({
|
|
9
|
+
control: props.control,
|
|
10
|
+
name: props.name,
|
|
11
|
+
});
|
|
12
|
+
const onBlur = (event) => {
|
|
13
|
+
var _a;
|
|
14
|
+
field.onBlur();
|
|
15
|
+
(_a = props.onBlur) === null || _a === void 0 ? void 0 : _a.call(props, event);
|
|
16
|
+
};
|
|
17
|
+
return (<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}/>);
|
|
18
|
+
}
|
|
19
|
+
exports.TextInput = TextInput;
|
|
@@ -0,0 +1,22 @@
|
|
|
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 (<form_1.Form>
|
|
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
|
+
}
|
|
22
|
+
exports.Default = Default;
|