@solidpb/ui-kit 0.5.2 → 0.5.3

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,4 +1,4 @@
1
- import { JSXElement } from "solid-js";
1
+ import { JSXElement, Setter } from "solid-js";
2
2
  import { type SwitchProps } from "./Switch";
3
3
  import { type SelectProps } from "./Select";
4
4
  import { type InputRootProps } from "./Input";
@@ -11,6 +11,7 @@ import { type FileInputProps } from "./FileInput";
11
11
  import { RelationPickerProps } from "./RelationPicker";
12
12
  export interface FormProps<T> {
13
13
  data: Partial<T>;
14
+ setData: Setter<Partial<T>>;
14
15
  title?: string;
15
16
  onSave?: (values: Partial<T>) => Promise<void>;
16
17
  onCancel?: () => void;
@@ -1,5 +1,4 @@
1
1
  import { splitProps } from "solid-js";
2
- import { createStore } from "solid-js/store";
3
2
  import { tv } from "tailwind-variants";
4
3
  import { InternalFormContext, useInternalFormContext } from "./formContext";
5
4
  import { Switch } from "./Switch";
@@ -18,17 +17,16 @@ const formClass = tv({
18
17
  });
19
18
  export function createForm() {
20
19
  const Form = (props) => {
21
- const [values, setValues] = createStore({ ...props.data });
22
20
  const setValue = (key, value) => {
23
- setValues(key, value);
21
+ props.setData((prev) => ({ ...prev, [key]: value }));
24
22
  };
25
23
  const getValue = (key) => {
26
- return values[key];
24
+ return props.data[key];
27
25
  };
28
26
  const contextValue = { setValue, getValue };
29
27
  const handleSubmit = (e) => {
30
28
  e.preventDefault();
31
- props.onSave?.(values);
29
+ props.onSave?.(props.data);
32
30
  };
33
31
  return (<InternalFormContext.Provider value={contextValue}>
34
32
  <form onSubmit={handleSubmit} class={formClass({ class: props.class })}>
@@ -94,18 +92,7 @@ export function createForm() {
94
92
  return (<Slider {...props} value={form.getValue(props.field)} onChange={(v) => form.setValue(props.field, v)}/>);
95
93
  };
96
94
  const RelationField = (props) => {
97
- const form = useInternalFormContext();
98
- const [local, others] = splitProps(props, ["onChange"]);
99
- const handleChange = (val) => {
100
- if (props.multi) {
101
- form.setValue(props.field, (Array.isArray(val) ? val.map((v) => v.id) : []));
102
- }
103
- else {
104
- form.setValue(props.field, (val?.id || null));
105
- }
106
- local.onChange?.(val);
107
- };
108
- return <RelationPicker {...others} onChange={handleChange}/>;
95
+ return <RelationPicker {...props}/>;
109
96
  };
110
97
  Form.TextField = TextField;
111
98
  Form.NumberField = NumberField;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@solidpb/ui-kit",
3
- "version": "0.5.2",
3
+ "version": "0.5.3",
4
4
  "type": "module",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.js",