@manafishrov/ui 1.2.13 → 1.3.1
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/components/DatePicker.d.ts +1 -1
- package/dist/components/DatePicker.js +5 -5
- package/dist/components/DatePicker.js.map +1 -1
- package/dist/components/Field.d.ts +1 -1
- package/dist/components/Field.js +1 -1
- package/dist/components/Field.js.map +1 -1
- package/dist/components/MenuCombobox.d.ts +1 -1
- package/dist/components/MenuCombobox.js.map +1 -1
- package/dist/components/MenuComboboxList.d.ts +10 -10
- package/dist/components/MenuComboboxList.js.map +1 -1
- package/dist/components/form/AutoSubmit.d.ts +5 -0
- package/dist/components/form/AutoSubmit.js +21 -0
- package/dist/components/form/AutoSubmit.js.map +1 -0
- package/dist/components/form/Form.d.ts +99 -84
- package/dist/components/form/Form.js +62 -40
- package/dist/components/form/Form.js.map +1 -1
- package/dist/components/form/index.d.ts +1 -0
- package/dist/components/form/index.js +30 -27
- package/dist/components/form/index.js.map +1 -1
- package/package.json +1 -1
- package/src/components/DatePicker.tsx +1 -1
- package/src/components/Field.tsx +1 -1
- package/src/components/MenuCombobox.tsx +6 -6
- package/src/components/MenuComboboxList.tsx +54 -20
- package/src/components/form/AutoSubmit.tsx +38 -0
- package/src/components/form/Form.tsx +29 -1
- package/src/components/form/index.ts +1 -0
|
@@ -13,36 +13,60 @@ import {
|
|
|
13
13
|
MenuComboboxShortcut,
|
|
14
14
|
} from '@/components/MenuCombobox';
|
|
15
15
|
|
|
16
|
-
export type
|
|
17
|
-
|
|
16
|
+
export type MenuComboboxItemData = {
|
|
17
|
+
value: string;
|
|
18
|
+
label: string;
|
|
19
|
+
disabled?: boolean;
|
|
20
|
+
shortcut?: string;
|
|
21
|
+
};
|
|
22
|
+
export type MenuComboboxCheckboxItemData = {
|
|
18
23
|
type: 'checkbox';
|
|
19
24
|
value: string;
|
|
20
25
|
label: string;
|
|
21
26
|
checked?: boolean;
|
|
22
27
|
disabled?: boolean;
|
|
23
28
|
};
|
|
24
|
-
export type
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
29
|
+
export type MenuComboboxRadioItemData = {
|
|
30
|
+
type: 'radio';
|
|
31
|
+
value: string;
|
|
32
|
+
label: string;
|
|
33
|
+
disabled?: boolean;
|
|
34
|
+
};
|
|
35
|
+
export type MenuComboboxRadioItemGroupData = {
|
|
36
|
+
type: 'radio-group';
|
|
37
|
+
value: string;
|
|
38
|
+
items: MenuComboboxRadioItemData[];
|
|
39
|
+
};
|
|
40
|
+
export type MenuComboboxSeparatorData = { type: 'separator' };
|
|
41
|
+
export type MenuComboboxItemGroupData = {
|
|
28
42
|
label: string;
|
|
29
|
-
items: (
|
|
43
|
+
items: (
|
|
44
|
+
| MenuComboboxItemData
|
|
45
|
+
| MenuComboboxCheckboxItemData
|
|
46
|
+
| MenuComboboxRadioItemGroupData
|
|
47
|
+
| MenuComboboxSeparatorData
|
|
48
|
+
)[];
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
export type MenuComboboxListProps = {
|
|
52
|
+
items: MenuComboboxItemData[];
|
|
53
|
+
searchValue?: string;
|
|
54
|
+
class?: string;
|
|
30
55
|
};
|
|
31
|
-
export type MenuComboboxListProps = { items: MenuItemData[]; searchValue?: string; class?: string };
|
|
32
56
|
export type MenuComboboxGroupedListProps = {
|
|
33
|
-
groups:
|
|
57
|
+
groups: MenuComboboxItemGroupData[];
|
|
34
58
|
searchValue?: string;
|
|
35
59
|
class?: string;
|
|
36
60
|
};
|
|
37
61
|
|
|
38
62
|
const hasShortcut = (shortcut?: string): boolean => typeof shortcut === 'string' && shortcut !== '';
|
|
39
63
|
const matchesSearch = (
|
|
40
|
-
item:
|
|
64
|
+
item: MenuComboboxItemData | MenuComboboxCheckboxItemData | MenuComboboxRadioItemData,
|
|
41
65
|
search: string,
|
|
42
66
|
): boolean =>
|
|
43
67
|
item.label.toLowerCase().includes(search) || item.value.toLowerCase().includes(search);
|
|
44
68
|
|
|
45
|
-
const renderRadioItems = (items:
|
|
69
|
+
const renderRadioItems = (items: MenuComboboxRadioItemData[]): JSXElement => (
|
|
46
70
|
<For each={items}>
|
|
47
71
|
{(radioItem) => (
|
|
48
72
|
<MenuComboboxRadioItem value={radioItem.value} disabled={radioItem.disabled}>
|
|
@@ -53,7 +77,11 @@ const renderRadioItems = (items: MenuRadioItemData[]): JSXElement => (
|
|
|
53
77
|
);
|
|
54
78
|
|
|
55
79
|
const renderGroupedItem = (
|
|
56
|
-
item:
|
|
80
|
+
item:
|
|
81
|
+
| MenuComboboxItemData
|
|
82
|
+
| MenuComboboxCheckboxItemData
|
|
83
|
+
| MenuComboboxRadioItemGroupData
|
|
84
|
+
| MenuComboboxSeparatorData,
|
|
57
85
|
): JSXElement => {
|
|
58
86
|
if (!('type' in item)) {
|
|
59
87
|
return (
|
|
@@ -88,13 +116,17 @@ const renderGroupedItem = (
|
|
|
88
116
|
};
|
|
89
117
|
|
|
90
118
|
type GroupFilterResult =
|
|
91
|
-
|
|
|
92
|
-
|
|
|
93
|
-
|
|
|
94
|
-
|
|
|
119
|
+
| MenuComboboxItemData
|
|
120
|
+
| MenuComboboxCheckboxItemData
|
|
121
|
+
| MenuComboboxRadioItemGroupData
|
|
122
|
+
| MenuComboboxSeparatorData;
|
|
95
123
|
|
|
96
124
|
const filterGroupItem = (
|
|
97
|
-
item:
|
|
125
|
+
item:
|
|
126
|
+
| MenuComboboxItemData
|
|
127
|
+
| MenuComboboxCheckboxItemData
|
|
128
|
+
| MenuComboboxRadioItemGroupData
|
|
129
|
+
| MenuComboboxSeparatorData,
|
|
98
130
|
search: string,
|
|
99
131
|
): GroupFilterResult[] => {
|
|
100
132
|
if (!('type' in item)) {
|
|
@@ -110,11 +142,13 @@ const filterGroupItem = (
|
|
|
110
142
|
return filteredRadioItems.length > 0 ? [{ ...item, items: filteredRadioItems }] : [];
|
|
111
143
|
};
|
|
112
144
|
|
|
113
|
-
const GroupItems: Component<{ items:
|
|
145
|
+
const GroupItems: Component<{ items: MenuComboboxItemGroupData['items'] }> = (props) => (
|
|
114
146
|
<For each={props.items}>{(item) => renderGroupedItem(item)}</For>
|
|
115
147
|
);
|
|
116
148
|
|
|
117
|
-
const GroupSection: Component<{ group:
|
|
149
|
+
const GroupSection: Component<{ group: MenuComboboxItemGroupData; showSeparator: boolean }> = (
|
|
150
|
+
props,
|
|
151
|
+
) => (
|
|
118
152
|
<>
|
|
119
153
|
{props.showSeparator && <MenuComboboxSeparator />}
|
|
120
154
|
<MenuComboboxItemGroup>
|
|
@@ -169,7 +203,7 @@ export const MenuComboboxGroupedList: Component<MenuComboboxGroupedListProps> =
|
|
|
169
203
|
}
|
|
170
204
|
return false;
|
|
171
205
|
})
|
|
172
|
-
.filter((group): group is
|
|
206
|
+
.filter((group): group is MenuComboboxItemGroupData => group !== false);
|
|
173
207
|
});
|
|
174
208
|
|
|
175
209
|
const emptyProps = (): { searchValue: string } | Record<string, never> =>
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { createEffect, onCleanup, type Component } from 'solid-js';
|
|
2
|
+
|
|
3
|
+
import { useFormContext } from './context';
|
|
4
|
+
|
|
5
|
+
const DEFAULT_DEBOUNCE_MS = 300;
|
|
6
|
+
|
|
7
|
+
export type AutoSubmitProps = {
|
|
8
|
+
debounce?: number;
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
export const AutoSubmit: Component<AutoSubmitProps> = (props) => {
|
|
12
|
+
const form = useFormContext();
|
|
13
|
+
const values = form.useStore((state) => state.values);
|
|
14
|
+
const isTouched = form.useStore((state) => state.isTouched);
|
|
15
|
+
|
|
16
|
+
createEffect(() => {
|
|
17
|
+
values();
|
|
18
|
+
|
|
19
|
+
if (!isTouched()) {
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
const debounceTimer = setTimeout(
|
|
24
|
+
() => {
|
|
25
|
+
form.handleSubmit().catch((error: unknown) => {
|
|
26
|
+
throw error;
|
|
27
|
+
});
|
|
28
|
+
},
|
|
29
|
+
Math.max(0, props.debounce ?? DEFAULT_DEBOUNCE_MS),
|
|
30
|
+
);
|
|
31
|
+
|
|
32
|
+
onCleanup(() => {
|
|
33
|
+
clearTimeout(debounceTimer);
|
|
34
|
+
});
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
return <></>;
|
|
38
|
+
};
|
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
import { createFormHook } from '@tanstack/solid-form';
|
|
2
|
+
import { splitProps, type Component, type ComponentProps } from 'solid-js';
|
|
3
|
+
import { cn } from 'tailwind-variants';
|
|
2
4
|
|
|
5
|
+
import { AutoSubmit } from './AutoSubmit';
|
|
3
6
|
import { CheckboxField } from './CheckboxField';
|
|
4
7
|
import { ComboboxField } from './ComboboxField';
|
|
5
|
-
import { formContext,
|
|
8
|
+
import { fieldContext, formContext, useFormContext } from './context';
|
|
6
9
|
import { DatePickerField } from './DatePickerField';
|
|
7
10
|
import { NumberInputField } from './NumberInputField';
|
|
8
11
|
import { PasswordInputField } from './PasswordInputField';
|
|
@@ -16,6 +19,29 @@ import { TagsInputField } from './TagsInputField';
|
|
|
16
19
|
import { TextareaField } from './TextareaField';
|
|
17
20
|
import { TextInputField } from './TextInputField';
|
|
18
21
|
|
|
22
|
+
export type FormProps = Omit<ComponentProps<'form'>, 'onSubmit'>;
|
|
23
|
+
|
|
24
|
+
export const Form: Component<FormProps> = (props) => {
|
|
25
|
+
const form = useFormContext();
|
|
26
|
+
const [local, formProps] = splitProps(props, ['children', 'class']);
|
|
27
|
+
|
|
28
|
+
return (
|
|
29
|
+
<form
|
|
30
|
+
class={cn('space-y-6 relative', local.class)}
|
|
31
|
+
onSubmit={(submitEvent) => {
|
|
32
|
+
submitEvent.preventDefault();
|
|
33
|
+
submitEvent.stopPropagation();
|
|
34
|
+
form.handleSubmit().catch((error: unknown) => {
|
|
35
|
+
throw error;
|
|
36
|
+
});
|
|
37
|
+
}}
|
|
38
|
+
{...formProps}
|
|
39
|
+
>
|
|
40
|
+
{local.children}
|
|
41
|
+
</form>
|
|
42
|
+
);
|
|
43
|
+
};
|
|
44
|
+
|
|
19
45
|
export const { useAppForm, withForm, withFieldGroup } = createFormHook({
|
|
20
46
|
formContext,
|
|
21
47
|
fieldContext,
|
|
@@ -35,6 +61,8 @@ export const { useAppForm, withForm, withFieldGroup } = createFormHook({
|
|
|
35
61
|
TextareaField,
|
|
36
62
|
},
|
|
37
63
|
formComponents: {
|
|
64
|
+
AutoSubmit,
|
|
65
|
+
Form,
|
|
38
66
|
SubmitButton,
|
|
39
67
|
},
|
|
40
68
|
});
|