@cripty2001/utils 0.0.108 → 0.0.110
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/dist/react-ui/form.d.ts
CHANGED
|
@@ -1,21 +1,23 @@
|
|
|
1
|
+
import { TypeofRecord } from "..";
|
|
1
2
|
import { InputComponentPropsVariants } from "./input";
|
|
2
|
-
export type FormComponentPropsInput
|
|
3
|
+
export type FormComponentPropsInput = {
|
|
3
4
|
label: string;
|
|
4
5
|
required: boolean;
|
|
5
6
|
key: string;
|
|
6
|
-
variant: keyof V;
|
|
7
7
|
} & ({
|
|
8
8
|
type: "text" | "email" | "password" | "tel";
|
|
9
9
|
} | {
|
|
10
10
|
type: "select";
|
|
11
11
|
options: string[];
|
|
12
12
|
});
|
|
13
|
-
export type FormComponentProps<T extends Record<string, string
|
|
14
|
-
inputs: FormComponentPropsInput
|
|
13
|
+
export type FormComponentProps<T extends Record<string, string>> = {
|
|
14
|
+
inputs: FormComponentPropsInput[];
|
|
15
15
|
onSubmit: (values: T) => void;
|
|
16
16
|
submitLabel: string;
|
|
17
17
|
value: T;
|
|
18
18
|
setValue: React.Dispatch<React.SetStateAction<T>>;
|
|
19
|
-
|
|
19
|
+
variant: TypeofRecord<InputComponentPropsVariants> & {
|
|
20
|
+
button: string;
|
|
21
|
+
};
|
|
20
22
|
};
|
|
21
|
-
export default function FormComponent<T extends Record<string, string
|
|
23
|
+
export default function FormComponent<T extends Record<string, string>>(props: FormComponentProps<T>): import("react/jsx-runtime").JSX.Element;
|
package/dist/react-ui/form.js
CHANGED
|
@@ -5,9 +5,13 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.default = FormComponent;
|
|
7
7
|
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
8
|
+
const react_1 = require("react");
|
|
8
9
|
const button_1 = __importDefault(require("./button"));
|
|
9
10
|
const input_1 = __importDefault(require("./input"));
|
|
10
11
|
function FormComponent(props) {
|
|
12
|
+
const variants = (0, react_1.useMemo)(() => ({
|
|
13
|
+
default: props.variant
|
|
14
|
+
}), [props.variant]);
|
|
11
15
|
return ((0, jsx_runtime_1.jsxs)("div", { style: { display: 'flex', flexDirection: 'column', gap: '1rem' }, children: [props.inputs.map(input => (() => {
|
|
12
16
|
const value = props.value[input.key];
|
|
13
17
|
const setValue = (v) => props.setValue(prev => ({
|
|
@@ -19,14 +23,14 @@ function FormComponent(props) {
|
|
|
19
23
|
case "email":
|
|
20
24
|
case "password":
|
|
21
25
|
case "tel":
|
|
22
|
-
return (0, jsx_runtime_1.jsx)(input_1.default, { label: input.label, value: value, setValue: setValue, variant:
|
|
26
|
+
return (0, jsx_runtime_1.jsx)(input_1.default, { label: input.label, value: value, setValue: setValue, variant: "default", variants: variants, children: ({ value, setValue, className }) => ((0, jsx_runtime_1.jsx)("input", { type: input.type, value: value, onChange: (e) => setValue(e.target.value), required: input.required, className: className, placeholder: input.label })) });
|
|
23
27
|
case "select":
|
|
24
|
-
return (0, jsx_runtime_1.jsx)(input_1.default, { label: input.label, value: value, setValue: setValue, variant:
|
|
28
|
+
return (0, jsx_runtime_1.jsx)(input_1.default, { label: input.label, value: value, setValue: setValue, variant: "default", variants: variants, required: input.required, validate: (v) => {
|
|
25
29
|
if (!input.options.includes(v))
|
|
26
30
|
throw new Error("Invalid option");
|
|
27
31
|
}, children: ({ value, setValue, className }) => ((0, jsx_runtime_1.jsx)("select", { value: value, onChange: (e) => setValue(e.target.value), required: input.required, className: className, children: input.options.map(option => ((0, jsx_runtime_1.jsx)("option", { value: option, children: option }, option))) })) });
|
|
28
32
|
default:
|
|
29
33
|
return (0, jsx_runtime_1.jsx)("div", { style: { color: '#ef4444', backgroundColor: 'white' }, children: "Unknown input type" });
|
|
30
34
|
}
|
|
31
|
-
})()), (0, jsx_runtime_1.jsx)(button_1.default, { title: props.submitLabel, onClick: () => props.onSubmit(props.value) })] }));
|
|
35
|
+
})()), (0, jsx_runtime_1.jsx)(button_1.default, { className: variants.default.button, title: props.submitLabel, onClick: () => props.onSubmit(props.value) })] }));
|
|
32
36
|
}
|
package/dist/react-ui/input.d.ts
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
|
-
export type
|
|
2
|
-
|
|
1
|
+
export type InputComponentPropsVariantsItem = {
|
|
2
|
+
input: string;
|
|
3
|
+
label: string;
|
|
4
|
+
};
|
|
5
|
+
export type InputComponentPropsVariants = Record<string, InputComponentPropsVariantsItem> & {
|
|
6
|
+
default: InputComponentPropsVariantsItem;
|
|
3
7
|
};
|
|
4
8
|
export type InputComponentProps<V extends InputComponentPropsVariants> = {
|
|
5
9
|
label?: string;
|
package/dist/react-ui/input.js
CHANGED
|
@@ -10,7 +10,7 @@ function InputComponent(props) {
|
|
|
10
10
|
const baseClassName = props.variants[variant ?? "default"];
|
|
11
11
|
const [error, setError] = (0, react_1.useState)(null);
|
|
12
12
|
return ((0, jsx_runtime_1.jsxs)("div", { style: { display: 'flex', flexDirection: 'column', gap: '0.5rem' }, children: [(0, jsx_runtime_1.jsxs)("div", { style: { display: 'flex', flexDirection: 'row', justifyContent: 'space-between', alignItems: 'center', gap: '0.5rem' }, children: [props.label &&
|
|
13
|
-
(0, jsx_runtime_1.jsx)("label", {
|
|
13
|
+
(0, jsx_runtime_1.jsx)("label", { className: baseClassName.label, children: props.label }), props.copy &&
|
|
14
14
|
(0, jsx_runtime_1.jsx)(lucide_react_1.CopyIcon, { style: { width: '1rem', height: '1rem', cursor: 'pointer' }, onClick: () => (0, index_1.copyToClipboard)(props.value) })] }), (0, jsx_runtime_1.jsx)("div", { style: { position: 'relative' }, children: props.children({
|
|
15
15
|
value: props.value,
|
|
16
16
|
setValue: (v) => {
|
|
@@ -25,7 +25,7 @@ function InputComponent(props) {
|
|
|
25
25
|
setError(e.message);
|
|
26
26
|
}
|
|
27
27
|
},
|
|
28
|
-
className: baseClassName
|
|
28
|
+
className: baseClassName.input
|
|
29
29
|
}) }), error &&
|
|
30
30
|
(0, jsx_runtime_1.jsx)("div", { style: { color: '#ef4444', fontSize: '0.75rem' }, children: error })] }));
|
|
31
31
|
}
|
package/package.json
CHANGED