@cripty2001/utils 0.0.107 → 0.0.109

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.
@@ -1,8 +1,9 @@
1
1
  import { InputComponentPropsVariants } from "./input";
2
- export type FormComponentPropsInput = {
2
+ export type FormComponentPropsInput<V extends InputComponentPropsVariants> = {
3
3
  label: string;
4
4
  required: boolean;
5
5
  key: string;
6
+ variant: keyof V;
6
7
  } & ({
7
8
  type: "text" | "email" | "password" | "tel";
8
9
  } | {
@@ -10,7 +11,7 @@ export type FormComponentPropsInput = {
10
11
  options: string[];
11
12
  });
12
13
  export type FormComponentProps<T extends Record<string, string>, V extends InputComponentPropsVariants> = {
13
- inputs: FormComponentPropsInput[];
14
+ inputs: FormComponentPropsInput<V>[];
14
15
  onSubmit: (values: T) => void;
15
16
  submitLabel: string;
16
17
  value: T;
@@ -19,9 +19,9 @@ function FormComponent(props) {
19
19
  case "email":
20
20
  case "password":
21
21
  case "tel":
22
- return (0, jsx_runtime_1.jsx)(input_1.default, { label: input.label, value: value, setValue: setValue, variant: "form", variants: props.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 })) });
22
+ return (0, jsx_runtime_1.jsx)(input_1.default, { label: input.label, value: value, setValue: setValue, variant: input.variant, variants: props.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
23
  case "select":
24
- return (0, jsx_runtime_1.jsx)(input_1.default, { label: input.label, value: value, setValue: setValue, variant: "form", variants: props.variants, required: input.required, validate: (v) => {
24
+ return (0, jsx_runtime_1.jsx)(input_1.default, { label: input.label, value: value, setValue: setValue, variant: input.variant, variants: props.variants, required: input.required, validate: (v) => {
25
25
  if (!input.options.includes(v))
26
26
  throw new Error("Invalid option");
27
27
  }, 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))) })) });
@@ -1,5 +1,9 @@
1
- export type InputComponentPropsVariants = Record<string, string> & {
2
- default: string;
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;
@@ -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", { style: { display: 'block', marginBottom: '0.25rem', fontSize: '0.875rem', fontWeight: 500, color: '#374151' }, children: props.label }), props.copy &&
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cripty2001/utils",
3
- "version": "0.0.107",
3
+ "version": "0.0.109",
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": {