@cripty2001/utils 0.0.114 → 0.0.116

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.
@@ -12,7 +12,7 @@ export type FormComponentPropsInput = {
12
12
  });
13
13
  export type FormComponentProps<T extends Record<string, string>> = {
14
14
  inputs: FormComponentPropsInput[];
15
- onSubmit: (values: T) => void;
15
+ onSubmit?: (values: T) => void;
16
16
  submitLabel: string;
17
17
  value: T;
18
18
  setValue: React.Dispatch<React.SetStateAction<T>>;
@@ -32,5 +32,6 @@ function FormComponent(props) {
32
32
  default:
33
33
  return (0, jsx_runtime_1.jsx)("div", { style: { color: '#ef4444', backgroundColor: 'white' }, children: "Unknown input type" });
34
34
  }
35
- })()), (0, jsx_runtime_1.jsx)(button_1.default, { className: variants.default.button, title: props.submitLabel, onClick: () => props.onSubmit(props.value) })] }));
35
+ })()), props.onSubmit &&
36
+ (0, jsx_runtime_1.jsx)(button_1.default, { className: variants.default.button, title: props.submitLabel, onClick: () => props.onSubmit?.(props.value) })] }));
36
37
  }
@@ -1,12 +1,15 @@
1
+ import { LucideIcon } from "lucide-react";
1
2
  export type InputComponentPropsVariantsItem = {
2
3
  input: string;
3
4
  label: string;
5
+ wrapper: string;
4
6
  };
5
7
  export type InputComponentPropsVariants = Record<string, InputComponentPropsVariantsItem> & {
6
8
  default: InputComponentPropsVariantsItem;
7
9
  };
8
10
  export type InputComponentProps<V extends InputComponentPropsVariants> = {
9
11
  label?: string;
12
+ icon?: React.ReactElement<LucideIcon>;
10
13
  value: string;
11
14
  setValue: (value: string) => void;
12
15
  required?: boolean;
@@ -11,21 +11,22 @@ function InputComponent(props) {
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
13
  (0, jsx_runtime_1.jsx)("label", { className: baseClassName.label, children: props.label }), props.copy &&
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
- value: props.value,
16
- setValue: (v) => {
17
- try {
18
- if (props.required && v === "")
19
- throw new Error("Required field is empty");
20
- props.validate?.(v);
21
- props.setValue(v);
22
- setError(null);
23
- }
24
- catch (e) {
25
- setError(e.message);
26
- }
27
- },
28
- className: baseClassName.input
29
- }) }), error &&
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.jsxs)("div", { style: { position: 'relative' }, className: baseClassName.wrapper, children: [props.icon &&
15
+ (0, jsx_runtime_1.jsx)("div", { style: { position: 'absolute', left: '0.5rem', top: '0.5rem' }, children: props.icon }), (0, jsx_runtime_1.jsx)("div", { style: { paddingLeft: props.icon ? '2rem' : '0.5rem' }, children: props.children({
16
+ value: props.value,
17
+ setValue: (v) => {
18
+ try {
19
+ if (props.required && v === "")
20
+ throw new Error("Required field is empty");
21
+ props.validate?.(v);
22
+ props.setValue(v);
23
+ setError(null);
24
+ }
25
+ catch (e) {
26
+ setError(e.message);
27
+ }
28
+ },
29
+ className: baseClassName.input
30
+ }) })] }), error &&
30
31
  (0, jsx_runtime_1.jsx)("div", { style: { color: '#ef4444', fontSize: '0.75rem' }, children: error })] }));
31
32
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cripty2001/utils",
3
- "version": "0.0.114",
3
+ "version": "0.0.116",
4
4
  "description": "Internal Set of utils. If you need them use them, otherwise go to the next package ;)",
5
5
  "homepage": "https://github.com/cripty2001/utils#readme",
6
6
  "bugs": {