@solidpb/ui-kit 0.5.1 → 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;
|
package/dist/components/Form.jsx
CHANGED
|
@@ -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
|
-
|
|
21
|
+
props.setData((prev) => ({ ...prev, [key]: value }));
|
|
24
22
|
};
|
|
25
23
|
const getValue = (key) => {
|
|
26
|
-
return
|
|
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?.(
|
|
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
|
-
|
|
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;
|
|
@@ -22,7 +22,7 @@ const tabContent = tv({
|
|
|
22
22
|
base: "card bg-base-100 border-base-300 p-3 w-full",
|
|
23
23
|
});
|
|
24
24
|
export const Tabs = (props) => {
|
|
25
|
-
return (<KTabs class={tabs({ size: props.size, class: props.class })} defaultValue={props.defaultTab}>
|
|
25
|
+
return (<KTabs class={tabs({ size: props.size, class: props.class })} defaultValue={props.defaultTab} value={props.value} onChange={props.onTabChange}>
|
|
26
26
|
{props.children}
|
|
27
27
|
</KTabs>);
|
|
28
28
|
};
|