@kirana-ui/solid 0.0.0 → 0.1.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/LICENSE +1 -1
- package/dom/accordion.js +106 -0
- package/dom/alert-dialog.js +2 -0
- package/dom/autocomplete.js +2 -0
- package/dom/autosize.js +19 -0
- package/dom/avatar.js +68 -0
- package/dom/button.js +18 -0
- package/dom/calendar.js +141 -0
- package/dom/carousel.js +83 -0
- package/dom/checkbox.js +77 -0
- package/dom/collapsible.js +64 -0
- package/dom/combobox.js +281 -0
- package/dom/command.js +129 -0
- package/dom/context-menu.js +2 -0
- package/dom/date-field.js +86 -0
- package/dom/date-picker.js +103 -0
- package/dom/dialog.js +101 -0
- package/dom/direction-context.js +3 -0
- package/dom/direction.js +27 -0
- package/dom/drawer.js +2 -0
- package/dom/field-context.js +3 -0
- package/dom/field.js +88 -0
- package/dom/fieldset.js +41 -0
- package/dom/form.js +29 -0
- package/dom/hover-card.js +3 -0
- package/dom/hover-popup.js +78 -0
- package/dom/index.js +47 -0
- package/dom/input.js +26 -0
- package/dom/label.js +18 -0
- package/dom/listbox.js +114 -0
- package/dom/menu.js +261 -0
- package/dom/menubar-context.js +3 -0
- package/dom/menubar.js +33 -0
- package/dom/message-scroller.js +56 -0
- package/dom/meter.js +3 -0
- package/dom/navigation-menu.js +150 -0
- package/dom/number-field.js +82 -0
- package/dom/otp.js +95 -0
- package/dom/pagination.js +74 -0
- package/dom/popover.js +70 -0
- package/dom/progress.js +3 -0
- package/dom/qr-code.js +48 -0
- package/dom/radio-group.js +101 -0
- package/dom/resizable.js +65 -0
- package/dom/runtime.js +133 -0
- package/dom/scroll-area.js +99 -0
- package/dom/select.js +213 -0
- package/dom/separator.js +17 -0
- package/dom/slider.js +93 -0
- package/dom/switch.js +63 -0
- package/dom/tabs.js +97 -0
- package/dom/toast.js +113 -0
- package/dom/toggle-group.js +37 -0
- package/dom/toggle.js +28 -0
- package/dom/toolbar-context.js +5 -0
- package/dom/toolbar.js +71 -0
- package/dom/tooltip.js +3 -0
- package/dom/value-bar.js +62 -0
- package/llms.txt +1838 -0
- package/package.json +437 -6
- package/server/accordion.js +106 -0
- package/server/alert-dialog.js +2 -0
- package/server/autocomplete.js +2 -0
- package/server/autosize.js +19 -0
- package/server/avatar.js +68 -0
- package/server/button.js +18 -0
- package/server/calendar.js +140 -0
- package/server/carousel.js +83 -0
- package/server/checkbox.js +77 -0
- package/server/collapsible.js +64 -0
- package/server/combobox.js +281 -0
- package/server/command.js +129 -0
- package/server/context-menu.js +2 -0
- package/server/date-field.js +86 -0
- package/server/date-picker.js +103 -0
- package/server/dialog.js +101 -0
- package/server/direction-context.js +3 -0
- package/server/direction.js +27 -0
- package/server/drawer.js +2 -0
- package/server/field-context.js +3 -0
- package/server/field.js +87 -0
- package/server/fieldset.js +41 -0
- package/server/form.js +29 -0
- package/server/hover-card.js +3 -0
- package/server/hover-popup.js +78 -0
- package/server/index.js +47 -0
- package/server/input.js +26 -0
- package/server/label.js +18 -0
- package/server/listbox.js +114 -0
- package/server/menu.js +261 -0
- package/server/menubar-context.js +3 -0
- package/server/menubar.js +33 -0
- package/server/message-scroller.js +56 -0
- package/server/meter.js +3 -0
- package/server/navigation-menu.js +144 -0
- package/server/number-field.js +81 -0
- package/server/otp.js +94 -0
- package/server/pagination.js +74 -0
- package/server/popover.js +70 -0
- package/server/progress.js +3 -0
- package/server/qr-code.js +48 -0
- package/server/radio-group.js +101 -0
- package/server/resizable.js +65 -0
- package/server/runtime.js +132 -0
- package/server/scroll-area.js +99 -0
- package/server/select.js +213 -0
- package/server/separator.js +17 -0
- package/server/slider.js +92 -0
- package/server/switch.js +62 -0
- package/server/tabs.js +97 -0
- package/server/toast.js +113 -0
- package/server/toggle-group.js +37 -0
- package/server/toggle.js +28 -0
- package/server/toolbar-context.js +5 -0
- package/server/toolbar.js +71 -0
- package/server/tooltip.js +3 -0
- package/server/value-bar.js +61 -0
- package/src/accordion.jsx +68 -0
- package/src/alert-dialog.js +2 -0
- package/src/autocomplete.jsx +2 -0
- package/src/autosize.jsx +8 -0
- package/src/avatar.jsx +35 -0
- package/src/button.jsx +9 -0
- package/src/calendar.jsx +104 -0
- package/src/carousel.jsx +51 -0
- package/src/checkbox.jsx +59 -0
- package/src/collapsible.jsx +35 -0
- package/src/combobox.jsx +179 -0
- package/src/command.jsx +81 -0
- package/src/context-menu.js +2 -0
- package/src/date-field.jsx +67 -0
- package/src/date-picker.jsx +72 -0
- package/src/dialog.jsx +67 -0
- package/src/direction-context.js +3 -0
- package/src/direction.jsx +17 -0
- package/src/drawer.js +2 -0
- package/src/field-context.js +3 -0
- package/src/field.jsx +64 -0
- package/src/fieldset.jsx +24 -0
- package/src/form.jsx +26 -0
- package/src/hover-card.jsx +3 -0
- package/src/hover-popup.jsx +48 -0
- package/src/index.js +47 -0
- package/src/input.jsx +17 -0
- package/src/label.jsx +9 -0
- package/src/listbox.jsx +81 -0
- package/src/menu.jsx +164 -0
- package/src/menubar-context.js +3 -0
- package/src/menubar.jsx +21 -0
- package/src/message-scroller.jsx +27 -0
- package/src/meter.jsx +3 -0
- package/src/navigation-menu.jsx +95 -0
- package/src/number-field.jsx +75 -0
- package/src/otp.jsx +73 -0
- package/src/pagination.jsx +60 -0
- package/src/popover.jsx +51 -0
- package/src/progress.jsx +3 -0
- package/src/qr-code.jsx +25 -0
- package/src/radio-group.jsx +68 -0
- package/src/resizable.jsx +46 -0
- package/src/runtime.jsx +119 -0
- package/src/scroll-area.jsx +53 -0
- package/src/select.jsx +129 -0
- package/src/separator.jsx +8 -0
- package/src/slider.jsx +76 -0
- package/src/switch.jsx +49 -0
- package/src/tabs.jsx +58 -0
- package/src/toast.jsx +58 -0
- package/src/toggle-group.jsx +32 -0
- package/src/toggle.jsx +24 -0
- package/src/toolbar-context.js +5 -0
- package/src/toolbar.jsx +43 -0
- package/src/tooltip.jsx +3 -0
- package/src/value-bar.jsx +45 -0
- package/types/accordion.d.ts +30 -0
- package/types/alert-dialog.d.ts +1 -0
- package/types/autocomplete.d.ts +1 -0
- package/types/autosize.d.ts +8 -0
- package/types/avatar.d.ts +15 -0
- package/types/button.d.ts +9 -0
- package/types/calendar.d.ts +40 -0
- package/types/carousel.d.ts +26 -0
- package/types/checkbox.d.ts +26 -0
- package/types/collapsible.d.ts +21 -0
- package/types/combobox.d.ts +106 -0
- package/types/command.d.ts +45 -0
- package/types/context-menu.d.ts +1 -0
- package/types/date-field.d.ts +23 -0
- package/types/date-picker.d.ts +49 -0
- package/types/dialog.d.ts +61 -0
- package/types/direction-context.d.ts +3 -0
- package/types/direction.d.ts +14 -0
- package/types/drawer.d.ts +1 -0
- package/types/field-context.d.ts +3 -0
- package/types/field.d.ts +28 -0
- package/types/fieldset.d.ts +14 -0
- package/types/form.d.ts +7 -0
- package/types/hover-card.d.ts +13 -0
- package/types/hover-popup.d.ts +29 -0
- package/types/index.d.ts +50 -0
- package/types/input.d.ts +12 -0
- package/types/label.d.ts +4 -0
- package/types/listbox.d.ts +38 -0
- package/types/menu.d.ts +91 -0
- package/types/menubar-context.d.ts +3 -0
- package/types/menubar.d.ts +10 -0
- package/types/message-scroller.d.ts +16 -0
- package/types/meter.d.ts +9 -0
- package/types/navigation-menu.d.ts +44 -0
- package/types/number-field.d.ts +15 -0
- package/types/otp.d.ts +32 -0
- package/types/pagination.d.ts +23 -0
- package/types/popover.d.ts +31 -0
- package/types/progress.d.ts +9 -0
- package/types/qr-code.d.ts +14 -0
- package/types/radio-group.d.ts +29 -0
- package/types/resizable.d.ts +24 -0
- package/types/runtime.d.ts +49 -0
- package/types/scroll-area.d.ts +20 -0
- package/types/select.d.ts +74 -0
- package/types/separator.d.ts +6 -0
- package/types/slider.d.ts +24 -0
- package/types/switch.d.ts +21 -0
- package/types/tabs.d.ts +32 -0
- package/types/toast.d.ts +33 -0
- package/types/toggle-group.d.ts +14 -0
- package/types/toggle.d.ts +12 -0
- package/types/toolbar-context.d.ts +6 -0
- package/types/toolbar.d.ts +23 -0
- package/types/tooltip.d.ts +13 -0
- package/types/value-bar.d.ts +17 -0
- package/README.md +0 -7
- package/index.js +0 -5
package/dom/combobox.js
ADDED
|
@@ -0,0 +1,281 @@
|
|
|
1
|
+
import { mergeProps as _$mergeProps } from "solid-js/web";
|
|
2
|
+
import { createComponent as _$createComponent } from "solid-js/web";
|
|
3
|
+
import { memo as _$memo } from "solid-js/web";
|
|
4
|
+
import { within } from "@kirana-ui/core";
|
|
5
|
+
import { createAutocomplete } from "@kirana-ui/core/autocomplete";
|
|
6
|
+
import { createCombobox } from "@kirana-ui/core/combobox";
|
|
7
|
+
import { Show, createContext, createUniqueId, splitProps, untrack, useContext } from "solid-js";
|
|
8
|
+
import { FieldContext } from "./field-context.js";
|
|
9
|
+
import { positioned } from "./popover.js";
|
|
10
|
+
import { Part, Portal as BodyPortal, controller, fromSignal, toSignal } from "./runtime.js";
|
|
11
|
+
const Context = createContext();
|
|
12
|
+
const ItemContext = createContext();
|
|
13
|
+
function useCombobox() {
|
|
14
|
+
const made = useContext(Context);
|
|
15
|
+
if (!made) throw new Error("A Combobox part must be inside <Combobox.Root>");
|
|
16
|
+
return made;
|
|
17
|
+
}
|
|
18
|
+
function Root(props) {
|
|
19
|
+
const generated = createUniqueId();
|
|
20
|
+
const field = useContext(FieldContext);
|
|
21
|
+
const made = controller(within(createCombobox, {
|
|
22
|
+
field
|
|
23
|
+
}), () => ({
|
|
24
|
+
id: props.id ?? generated,
|
|
25
|
+
value: props.value,
|
|
26
|
+
defaultValue: props.defaultValue,
|
|
27
|
+
inputValue: props.inputValue,
|
|
28
|
+
defaultInputValue: props.defaultInputValue,
|
|
29
|
+
open: props.open,
|
|
30
|
+
defaultOpen: props.defaultOpen,
|
|
31
|
+
disabled: props.disabled,
|
|
32
|
+
required: props.required,
|
|
33
|
+
multiple: props.multiple,
|
|
34
|
+
values: props.values,
|
|
35
|
+
defaultValues: props.defaultValues,
|
|
36
|
+
onValuesChange: (values, details) => props.onValuesChange?.(values, details),
|
|
37
|
+
inline: props.inline,
|
|
38
|
+
virtualized: props.virtualized,
|
|
39
|
+
name: props.name,
|
|
40
|
+
form: props.form,
|
|
41
|
+
items: props.items,
|
|
42
|
+
filter: props.filter,
|
|
43
|
+
onValueChange: (value, details) => props.onValueChange?.(value, details),
|
|
44
|
+
onInputValueChange: (value, details) => props.onInputValueChange?.(value, details),
|
|
45
|
+
onOpenChange: (open, details) => props.onOpenChange?.(open, details)
|
|
46
|
+
}));
|
|
47
|
+
const named = fromSignal(made.named);
|
|
48
|
+
return _$createComponent(Context.Provider, {
|
|
49
|
+
value: made,
|
|
50
|
+
get children() {
|
|
51
|
+
return [_$memo(() => props.children), _$createComponent(Show, {
|
|
52
|
+
get when() {
|
|
53
|
+
return named();
|
|
54
|
+
},
|
|
55
|
+
get children() {
|
|
56
|
+
return _$createComponent(Part, {
|
|
57
|
+
get part() {
|
|
58
|
+
return made.hidden;
|
|
59
|
+
},
|
|
60
|
+
tag: "input"
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
})];
|
|
64
|
+
}
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
const Portal = props => _$createComponent(BodyPortal, {
|
|
68
|
+
get mounted() {
|
|
69
|
+
return useCombobox().mounted;
|
|
70
|
+
},
|
|
71
|
+
get children() {
|
|
72
|
+
return props.children;
|
|
73
|
+
}
|
|
74
|
+
});
|
|
75
|
+
function Positioner(props) {
|
|
76
|
+
const made = useCombobox();
|
|
77
|
+
return _$createComponent(Part, _$mergeProps({
|
|
78
|
+
get part() {
|
|
79
|
+
return made.positioner;
|
|
80
|
+
},
|
|
81
|
+
tag: "div"
|
|
82
|
+
}, () => positioned(props, made.positioning)));
|
|
83
|
+
}
|
|
84
|
+
/** `label` is what is filtered and what the input shows; the item's text when left out. */
|
|
85
|
+
function Item(props) {
|
|
86
|
+
const [local, rest] = splitProps(props, ["value", "disabled", "label", "id", "index"]);
|
|
87
|
+
// An item is its value for as long as it is in the page.
|
|
88
|
+
const value = untrack(() => local.value);
|
|
89
|
+
const generated = createUniqueId();
|
|
90
|
+
const options = toSignal(() => ({
|
|
91
|
+
disabled: local.disabled,
|
|
92
|
+
label: local.label,
|
|
93
|
+
index: local.index,
|
|
94
|
+
id: local.id ?? generated
|
|
95
|
+
}));
|
|
96
|
+
const part = useCombobox().item(value, () => options.get(), useContext(GroupContext));
|
|
97
|
+
return _$createComponent(ItemContext.Provider, {
|
|
98
|
+
value: value,
|
|
99
|
+
get children() {
|
|
100
|
+
return _$createComponent(Part, _$mergeProps({
|
|
101
|
+
part: part,
|
|
102
|
+
tag: "div"
|
|
103
|
+
}, rest));
|
|
104
|
+
}
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
function ItemIndicator(props) {
|
|
108
|
+
const [local, rest] = splitProps(props, ["keepMounted"]);
|
|
109
|
+
const made = useCombobox();
|
|
110
|
+
const value = useContext(ItemContext);
|
|
111
|
+
const selected = fromSignal(made.selected(value));
|
|
112
|
+
return _$createComponent(Show, {
|
|
113
|
+
get when() {
|
|
114
|
+
return selected() || local.keepMounted;
|
|
115
|
+
},
|
|
116
|
+
get children() {
|
|
117
|
+
return _$createComponent(Part, _$mergeProps({
|
|
118
|
+
get part() {
|
|
119
|
+
return made.itemIndicator(value);
|
|
120
|
+
},
|
|
121
|
+
tag: "span"
|
|
122
|
+
}, rest));
|
|
123
|
+
}
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
/** A button that empties the input and the value. Drawn while there is something to clear. */
|
|
127
|
+
function Clear(props) {
|
|
128
|
+
const [local, rest] = splitProps(props, ["keepMounted"]);
|
|
129
|
+
const made = useCombobox();
|
|
130
|
+
const clearable = fromSignal(made.clearable);
|
|
131
|
+
return _$createComponent(Show, {
|
|
132
|
+
get when() {
|
|
133
|
+
return clearable() || local.keepMounted;
|
|
134
|
+
},
|
|
135
|
+
get children() {
|
|
136
|
+
return _$createComponent(Part, _$mergeProps({
|
|
137
|
+
get part() {
|
|
138
|
+
return made.clear;
|
|
139
|
+
},
|
|
140
|
+
tag: "button"
|
|
141
|
+
}, rest));
|
|
142
|
+
}
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
const ChipContext = createContext();
|
|
146
|
+
/** With `multiple`: one chosen value. Its `value` is what its remove button takes away. */
|
|
147
|
+
function Chip(props) {
|
|
148
|
+
const [local, rest] = splitProps(props, ["value"]);
|
|
149
|
+
// A chip is its value for as long as it is in the page.
|
|
150
|
+
const value = untrack(() => local.value);
|
|
151
|
+
return _$createComponent(ChipContext.Provider, {
|
|
152
|
+
value: value,
|
|
153
|
+
get children() {
|
|
154
|
+
return _$createComponent(Part, _$mergeProps({
|
|
155
|
+
get part() {
|
|
156
|
+
return useCombobox().chip(value);
|
|
157
|
+
},
|
|
158
|
+
tag: "span"
|
|
159
|
+
}, rest));
|
|
160
|
+
}
|
|
161
|
+
});
|
|
162
|
+
}
|
|
163
|
+
const ChipRemove = props => _$createComponent(Part, _$mergeProps({
|
|
164
|
+
get part() {
|
|
165
|
+
return useCombobox().chipRemove(useContext(ChipContext));
|
|
166
|
+
},
|
|
167
|
+
tag: "button"
|
|
168
|
+
}, props));
|
|
169
|
+
/** Drawn while no item is shown for what was typed. */
|
|
170
|
+
function Empty(props) {
|
|
171
|
+
const made = useCombobox();
|
|
172
|
+
const empty = fromSignal(made.empty);
|
|
173
|
+
return _$createComponent(Show, {
|
|
174
|
+
get when() {
|
|
175
|
+
return empty();
|
|
176
|
+
},
|
|
177
|
+
get children() {
|
|
178
|
+
return _$createComponent(Part, _$mergeProps({
|
|
179
|
+
get part() {
|
|
180
|
+
return made.emptyPart;
|
|
181
|
+
},
|
|
182
|
+
tag: "div"
|
|
183
|
+
}, props));
|
|
184
|
+
}
|
|
185
|
+
});
|
|
186
|
+
}
|
|
187
|
+
const GroupContext = createContext();
|
|
188
|
+
/** Items that belong together, named by their `GroupLabel`. Hidden while none is shown. */
|
|
189
|
+
function Group(props) {
|
|
190
|
+
const [local, rest] = splitProps(props, ["id"]);
|
|
191
|
+
const generated = createUniqueId();
|
|
192
|
+
const group = useCombobox().group(untrack(() => local.id) ?? generated);
|
|
193
|
+
return _$createComponent(GroupContext.Provider, {
|
|
194
|
+
value: group,
|
|
195
|
+
get children() {
|
|
196
|
+
return _$createComponent(Part, _$mergeProps({
|
|
197
|
+
get part() {
|
|
198
|
+
return group.root;
|
|
199
|
+
},
|
|
200
|
+
tag: "div"
|
|
201
|
+
}, rest));
|
|
202
|
+
}
|
|
203
|
+
});
|
|
204
|
+
}
|
|
205
|
+
/** Names the group it is in. With no group around it, it is plain text. */
|
|
206
|
+
const GroupLabel = props => _$createComponent(Part, _$mergeProps({
|
|
207
|
+
get part() {
|
|
208
|
+
return useContext(GroupContext)?.label ?? useCombobox().groupLabel;
|
|
209
|
+
},
|
|
210
|
+
tag: "div"
|
|
211
|
+
}, props));
|
|
212
|
+
const part = (name, tag) => props => _$createComponent(Part, _$mergeProps({
|
|
213
|
+
get part() {
|
|
214
|
+
return useCombobox()[name];
|
|
215
|
+
},
|
|
216
|
+
tag: tag
|
|
217
|
+
}, props));
|
|
218
|
+
/** A combobox whose text is the value: the list only suggests. */
|
|
219
|
+
function AutocompleteRoot(props) {
|
|
220
|
+
const generated = createUniqueId();
|
|
221
|
+
const field = useContext(FieldContext);
|
|
222
|
+
const made = controller(within(createAutocomplete, {
|
|
223
|
+
field
|
|
224
|
+
}), () => ({
|
|
225
|
+
id: props.id ?? generated,
|
|
226
|
+
value: props.value,
|
|
227
|
+
defaultValue: props.defaultValue,
|
|
228
|
+
open: props.open,
|
|
229
|
+
defaultOpen: props.defaultOpen,
|
|
230
|
+
mode: props.mode,
|
|
231
|
+
filter: props.filter,
|
|
232
|
+
openOnInputClick: props.openOnInputClick,
|
|
233
|
+
disabled: props.disabled,
|
|
234
|
+
required: props.required,
|
|
235
|
+
name: props.name,
|
|
236
|
+
form: props.form,
|
|
237
|
+
virtualized: props.virtualized,
|
|
238
|
+
onValueChange: (value, details) => props.onValueChange?.(value, details),
|
|
239
|
+
onOpenChange: (open, details) => props.onOpenChange?.(open, details)
|
|
240
|
+
}));
|
|
241
|
+
return _$createComponent(Context.Provider, {
|
|
242
|
+
value: made,
|
|
243
|
+
get children() {
|
|
244
|
+
return props.children;
|
|
245
|
+
}
|
|
246
|
+
});
|
|
247
|
+
}
|
|
248
|
+
export const Combobox = {
|
|
249
|
+
Root,
|
|
250
|
+
Input: part("input", "input"),
|
|
251
|
+
Trigger: part("trigger", "button"),
|
|
252
|
+
Clear,
|
|
253
|
+
/** With `multiple`: what holds the chips and the input. */
|
|
254
|
+
Chips: part("chips", "div"),
|
|
255
|
+
Chip,
|
|
256
|
+
ChipRemove,
|
|
257
|
+
Portal,
|
|
258
|
+
Positioner,
|
|
259
|
+
Popup: part("popup", "div"),
|
|
260
|
+
Group,
|
|
261
|
+
GroupLabel,
|
|
262
|
+
/** A line between groups. */
|
|
263
|
+
Separator: part("separator", "div"),
|
|
264
|
+
Item,
|
|
265
|
+
ItemIndicator,
|
|
266
|
+
Empty
|
|
267
|
+
};
|
|
268
|
+
export const Autocomplete = {
|
|
269
|
+
Root: AutocompleteRoot,
|
|
270
|
+
Input: Combobox.Input,
|
|
271
|
+
Trigger: Combobox.Trigger,
|
|
272
|
+
Clear: Combobox.Clear,
|
|
273
|
+
Portal: Combobox.Portal,
|
|
274
|
+
Positioner: Combobox.Positioner,
|
|
275
|
+
Popup: Combobox.Popup,
|
|
276
|
+
Group: Combobox.Group,
|
|
277
|
+
GroupLabel: Combobox.GroupLabel,
|
|
278
|
+
Separator: Combobox.Separator,
|
|
279
|
+
Item: Combobox.Item,
|
|
280
|
+
Empty: Combobox.Empty
|
|
281
|
+
};
|
package/dom/command.js
ADDED
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
import { createComponent as _$createComponent } from "solid-js/web";
|
|
2
|
+
import { mergeProps as _$mergeProps } from "solid-js/web";
|
|
3
|
+
import { createCommand } from "@kirana-ui/core/command";
|
|
4
|
+
import { Show, createContext, createUniqueId, splitProps, untrack, useContext } from "solid-js";
|
|
5
|
+
import { Part, controller, fromSignal, toSignal } from "./runtime.js";
|
|
6
|
+
const Context = createContext();
|
|
7
|
+
const GroupContext = createContext();
|
|
8
|
+
function useCommand() {
|
|
9
|
+
const made = useContext(Context);
|
|
10
|
+
if (!made) throw new Error("A Command part must be inside <Command.Root>");
|
|
11
|
+
return made;
|
|
12
|
+
}
|
|
13
|
+
function Root(props) {
|
|
14
|
+
const [local, rest] = splitProps(props, ["inputValue", "defaultInputValue", "onInputValueChange", "onSelect", "filter", "loop", "disabled", "id"]);
|
|
15
|
+
const generated = createUniqueId();
|
|
16
|
+
const made = controller(createCommand, () => ({
|
|
17
|
+
id: local.id ?? generated,
|
|
18
|
+
inputValue: local.inputValue,
|
|
19
|
+
defaultInputValue: local.defaultInputValue,
|
|
20
|
+
filter: local.filter,
|
|
21
|
+
loop: local.loop,
|
|
22
|
+
disabled: local.disabled,
|
|
23
|
+
onInputValueChange: (value, details) => local.onInputValueChange?.(value, details),
|
|
24
|
+
onSelect: (value, details) => local.onSelect?.(value, details)
|
|
25
|
+
}));
|
|
26
|
+
return _$createComponent(Context.Provider, {
|
|
27
|
+
value: made,
|
|
28
|
+
get children() {
|
|
29
|
+
return _$createComponent(Part, _$mergeProps({
|
|
30
|
+
get part() {
|
|
31
|
+
return made.root;
|
|
32
|
+
},
|
|
33
|
+
tag: "div"
|
|
34
|
+
}, rest));
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
const Input = props => _$createComponent(Part, _$mergeProps({
|
|
39
|
+
get part() {
|
|
40
|
+
return useCommand().input;
|
|
41
|
+
},
|
|
42
|
+
tag: "input"
|
|
43
|
+
}, props));
|
|
44
|
+
const List = props => _$createComponent(Part, _$mergeProps({
|
|
45
|
+
get part() {
|
|
46
|
+
return useCommand().list;
|
|
47
|
+
},
|
|
48
|
+
tag: "div"
|
|
49
|
+
}, props));
|
|
50
|
+
/** Drawn while no item is shown for what was typed. */
|
|
51
|
+
function Empty(props) {
|
|
52
|
+
const made = useCommand();
|
|
53
|
+
const empty = fromSignal(made.empty);
|
|
54
|
+
return _$createComponent(Show, {
|
|
55
|
+
get when() {
|
|
56
|
+
return empty();
|
|
57
|
+
},
|
|
58
|
+
get children() {
|
|
59
|
+
return _$createComponent(Part, _$mergeProps({
|
|
60
|
+
get part() {
|
|
61
|
+
return made.emptyPart;
|
|
62
|
+
},
|
|
63
|
+
tag: "div"
|
|
64
|
+
}, props));
|
|
65
|
+
}
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
/** Items under a `<Command.GroupHeading>`. Hidden while none of them is shown. */
|
|
69
|
+
function Group(props) {
|
|
70
|
+
const [local, rest] = splitProps(props, ["id"]);
|
|
71
|
+
const generated = createUniqueId();
|
|
72
|
+
const group = useCommand().group(untrack(() => local.id) ?? generated);
|
|
73
|
+
return _$createComponent(GroupContext.Provider, {
|
|
74
|
+
value: group,
|
|
75
|
+
get children() {
|
|
76
|
+
return _$createComponent(Part, _$mergeProps({
|
|
77
|
+
get part() {
|
|
78
|
+
return group.part;
|
|
79
|
+
},
|
|
80
|
+
tag: "div"
|
|
81
|
+
}, rest));
|
|
82
|
+
}
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
function GroupHeading(props) {
|
|
86
|
+
const part = useContext(GroupContext)?.heading ?? useCommand().heading;
|
|
87
|
+
return _$createComponent(Part, _$mergeProps({
|
|
88
|
+
part: part,
|
|
89
|
+
tag: "div"
|
|
90
|
+
}, props));
|
|
91
|
+
}
|
|
92
|
+
/** `label` is what is filtered, the item's text when left out; `keywords` are other words for it. */
|
|
93
|
+
function Item(props) {
|
|
94
|
+
const [local, rest] = splitProps(props, ["value", "disabled", "label", "keywords", "id"]);
|
|
95
|
+
const generated = createUniqueId();
|
|
96
|
+
const options = toSignal(() => ({
|
|
97
|
+
disabled: local.disabled,
|
|
98
|
+
label: local.label,
|
|
99
|
+
keywords: local.keywords,
|
|
100
|
+
id: local.id ?? generated
|
|
101
|
+
}));
|
|
102
|
+
const part = useCommand().item(untrack(() => local.value), () => options.get(), useContext(GroupContext));
|
|
103
|
+
return _$createComponent(Part, _$mergeProps({
|
|
104
|
+
part: part,
|
|
105
|
+
tag: "div"
|
|
106
|
+
}, rest));
|
|
107
|
+
}
|
|
108
|
+
/** A line between groups: gone while something is typed, unless `alwaysRender`. */
|
|
109
|
+
function Separator(props) {
|
|
110
|
+
const [local, rest] = splitProps(props, ["alwaysRender"]);
|
|
111
|
+
const options = toSignal(() => ({
|
|
112
|
+
alwaysRender: local.alwaysRender
|
|
113
|
+
}));
|
|
114
|
+
const part = useCommand().separator(() => options.get().alwaysRender);
|
|
115
|
+
return _$createComponent(Part, _$mergeProps({
|
|
116
|
+
part: part,
|
|
117
|
+
tag: "div"
|
|
118
|
+
}, rest));
|
|
119
|
+
}
|
|
120
|
+
export const Command = {
|
|
121
|
+
Root,
|
|
122
|
+
Input,
|
|
123
|
+
List,
|
|
124
|
+
Empty,
|
|
125
|
+
Group,
|
|
126
|
+
GroupHeading,
|
|
127
|
+
Item,
|
|
128
|
+
Separator
|
|
129
|
+
};
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import { createComponent as _$createComponent } from "solid-js/web";
|
|
2
|
+
import { mergeProps as _$mergeProps } from "solid-js/web";
|
|
3
|
+
import { within } from "@kirana-ui/core";
|
|
4
|
+
import { createDateField } from "@kirana-ui/core/date-field";
|
|
5
|
+
import { For, createContext, createUniqueId, splitProps, useContext } from "solid-js";
|
|
6
|
+
import { DirectionContext } from "./direction-context.js";
|
|
7
|
+
import { Part, controller, fromSignal } from "./runtime.js";
|
|
8
|
+
const Context = createContext();
|
|
9
|
+
/** For a component made of this one's parts: a date picker. */
|
|
10
|
+
export { Context as DateFieldContext };
|
|
11
|
+
function useDateField() {
|
|
12
|
+
const made = useContext(Context);
|
|
13
|
+
if (!made) throw new Error("A DateField part must be inside <DateField.Root>");
|
|
14
|
+
return made;
|
|
15
|
+
}
|
|
16
|
+
function Root(props) {
|
|
17
|
+
const [local, rest] = splitProps(props, ["value", "defaultValue", "onValueChange", "locale", "min", "max", "placeholders", "disabled", "readOnly", "required", "name", "form", "id"]);
|
|
18
|
+
const generated = createUniqueId();
|
|
19
|
+
const direction = useContext(DirectionContext);
|
|
20
|
+
const made = controller(within(createDateField, {
|
|
21
|
+
direction
|
|
22
|
+
}), () => ({
|
|
23
|
+
id: local.id ?? generated,
|
|
24
|
+
value: local.value,
|
|
25
|
+
defaultValue: local.defaultValue,
|
|
26
|
+
locale: local.locale,
|
|
27
|
+
min: local.min,
|
|
28
|
+
max: local.max,
|
|
29
|
+
placeholders: local.placeholders,
|
|
30
|
+
disabled: local.disabled,
|
|
31
|
+
readOnly: local.readOnly,
|
|
32
|
+
required: local.required,
|
|
33
|
+
name: local.name,
|
|
34
|
+
form: local.form,
|
|
35
|
+
onValueChange: (value, details) => local.onValueChange?.(value, details)
|
|
36
|
+
}));
|
|
37
|
+
return _$createComponent(Context.Provider, {
|
|
38
|
+
value: made,
|
|
39
|
+
get children() {
|
|
40
|
+
return _$createComponent(Part, _$mergeProps({
|
|
41
|
+
get part() {
|
|
42
|
+
return made.root;
|
|
43
|
+
},
|
|
44
|
+
tag: "div"
|
|
45
|
+
}, rest));
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
/** Draws its child once for each piece of the date, in the locale's order. */
|
|
50
|
+
function Segments(props) {
|
|
51
|
+
const segments = fromSignal(useDateField().segments);
|
|
52
|
+
return _$createComponent(For, {
|
|
53
|
+
get each() {
|
|
54
|
+
return segments();
|
|
55
|
+
},
|
|
56
|
+
children: segment => props.children(segment)
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
/** One piece: a part that is typed, or what stands between two. It writes its own text. */
|
|
60
|
+
function Segment(props) {
|
|
61
|
+
const [local, rest] = splitProps(props, ["segment"]);
|
|
62
|
+
const made = useDateField().segment(local.segment);
|
|
63
|
+
const shown = fromSignal(made.text);
|
|
64
|
+
return _$createComponent(Part, _$mergeProps({
|
|
65
|
+
get part() {
|
|
66
|
+
return made.part;
|
|
67
|
+
},
|
|
68
|
+
tag: "span"
|
|
69
|
+
}, rest, {
|
|
70
|
+
get children() {
|
|
71
|
+
return shown();
|
|
72
|
+
}
|
|
73
|
+
}));
|
|
74
|
+
}
|
|
75
|
+
const Input = props => _$createComponent(Part, _$mergeProps({
|
|
76
|
+
get part() {
|
|
77
|
+
return useDateField().input;
|
|
78
|
+
},
|
|
79
|
+
tag: "input"
|
|
80
|
+
}, props));
|
|
81
|
+
export const DateField = {
|
|
82
|
+
Root,
|
|
83
|
+
Segments,
|
|
84
|
+
Segment,
|
|
85
|
+
Input
|
|
86
|
+
};
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import { mergeProps as _$mergeProps } from "solid-js/web";
|
|
2
|
+
import { createComponent as _$createComponent } from "solid-js/web";
|
|
3
|
+
import { within } from "@kirana-ui/core";
|
|
4
|
+
import { createDatePicker } from "@kirana-ui/core/date-picker";
|
|
5
|
+
import { createContext, createUniqueId, useContext } from "solid-js";
|
|
6
|
+
import { Calendar, CalendarContext } from "./calendar.js";
|
|
7
|
+
import { DateField, DateFieldContext } from "./date-field.js";
|
|
8
|
+
import { DirectionContext } from "./direction-context.js";
|
|
9
|
+
import { Popover, PopoverContext } from "./popover.js";
|
|
10
|
+
import { Part, controller } from "./runtime.js";
|
|
11
|
+
const Context = createContext();
|
|
12
|
+
function useDatePicker() {
|
|
13
|
+
const made = useContext(Context);
|
|
14
|
+
if (!made) throw new Error("A DatePicker part must be inside <DatePicker.Root>");
|
|
15
|
+
return made;
|
|
16
|
+
}
|
|
17
|
+
/** A date field, and a calendar in a popover, with one value between them. It draws nothing. */
|
|
18
|
+
function Root(props) {
|
|
19
|
+
const generated = createUniqueId();
|
|
20
|
+
const made = controller(within(createDatePicker, {
|
|
21
|
+
direction: useContext(DirectionContext)
|
|
22
|
+
}), () => ({
|
|
23
|
+
id: props.id ?? generated,
|
|
24
|
+
value: props.value,
|
|
25
|
+
defaultValue: props.defaultValue,
|
|
26
|
+
open: props.open,
|
|
27
|
+
defaultOpen: props.defaultOpen,
|
|
28
|
+
locale: props.locale,
|
|
29
|
+
min: props.min,
|
|
30
|
+
max: props.max,
|
|
31
|
+
isDateUnavailable: props.isDateUnavailable,
|
|
32
|
+
calendarSystem: props.calendarSystem,
|
|
33
|
+
fixedWeeks: props.fixedWeeks,
|
|
34
|
+
placeholders: props.placeholders,
|
|
35
|
+
disabled: props.disabled,
|
|
36
|
+
readOnly: props.readOnly,
|
|
37
|
+
required: props.required,
|
|
38
|
+
name: props.name,
|
|
39
|
+
form: props.form,
|
|
40
|
+
onValueChange: (value, details) => props.onValueChange?.(value, details),
|
|
41
|
+
onOpenChange: (open, details) => props.onOpenChange?.(open, details)
|
|
42
|
+
}));
|
|
43
|
+
return _$createComponent(Context.Provider, {
|
|
44
|
+
value: made,
|
|
45
|
+
get children() {
|
|
46
|
+
return _$createComponent(DateFieldContext.Provider, {
|
|
47
|
+
get value() {
|
|
48
|
+
return made.field;
|
|
49
|
+
},
|
|
50
|
+
get children() {
|
|
51
|
+
return _$createComponent(PopoverContext.Provider, {
|
|
52
|
+
get value() {
|
|
53
|
+
return made.popover;
|
|
54
|
+
},
|
|
55
|
+
get children() {
|
|
56
|
+
return _$createComponent(CalendarContext.Provider, {
|
|
57
|
+
get value() {
|
|
58
|
+
return made.calendar;
|
|
59
|
+
},
|
|
60
|
+
get children() {
|
|
61
|
+
return props.children;
|
|
62
|
+
}
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
export const DatePicker = {
|
|
72
|
+
Root,
|
|
73
|
+
/** The typed date: what holds its segments and its hidden input. */
|
|
74
|
+
Field: props => _$createComponent(Part, _$mergeProps({
|
|
75
|
+
get part() {
|
|
76
|
+
return useDatePicker().field.root;
|
|
77
|
+
},
|
|
78
|
+
tag: "div"
|
|
79
|
+
}, props)),
|
|
80
|
+
Segments: DateField.Segments,
|
|
81
|
+
Segment: DateField.Segment,
|
|
82
|
+
Input: DateField.Input,
|
|
83
|
+
Trigger: Popover.Trigger,
|
|
84
|
+
Portal: Popover.Portal,
|
|
85
|
+
Positioner: Popover.Positioner,
|
|
86
|
+
Popup: Popover.Popup,
|
|
87
|
+
/** The calendar: what holds its heading, its buttons and its grid. */
|
|
88
|
+
Calendar: props => _$createComponent(Part, _$mergeProps({
|
|
89
|
+
get part() {
|
|
90
|
+
return useDatePicker().calendar.root;
|
|
91
|
+
},
|
|
92
|
+
tag: "div"
|
|
93
|
+
}, props)),
|
|
94
|
+
Heading: Calendar.Heading,
|
|
95
|
+
Previous: Calendar.Previous,
|
|
96
|
+
Next: Calendar.Next,
|
|
97
|
+
Grid: Calendar.Grid,
|
|
98
|
+
Weekdays: Calendar.Weekdays,
|
|
99
|
+
HeadCell: Calendar.HeadCell,
|
|
100
|
+
Weeks: Calendar.Weeks,
|
|
101
|
+
Cell: Calendar.Cell,
|
|
102
|
+
Day: Calendar.Day
|
|
103
|
+
};
|
package/dom/dialog.js
ADDED
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import { mergeProps as _$mergeProps } from "solid-js/web";
|
|
2
|
+
import { createComponent as _$createComponent } from "solid-js/web";
|
|
3
|
+
import { createAlertDialog } from "@kirana-ui/core/alert-dialog";
|
|
4
|
+
import { createDialog } from "@kirana-ui/core/dialog";
|
|
5
|
+
import { createDrawer } from "@kirana-ui/core/drawer";
|
|
6
|
+
import { createContext, createUniqueId, useContext } from "solid-js";
|
|
7
|
+
import { Part, Portal as BodyPortal, controller } from "./runtime.js";
|
|
8
|
+
const Context = createContext();
|
|
9
|
+
function useDialog() {
|
|
10
|
+
const made = useContext(Context);
|
|
11
|
+
if (!made) throw new Error("A Dialog part must be inside <Dialog.Root>");
|
|
12
|
+
return made;
|
|
13
|
+
}
|
|
14
|
+
function Root(props) {
|
|
15
|
+
const generated = createUniqueId();
|
|
16
|
+
const made = controller(createDialog, () => ({
|
|
17
|
+
id: props.id ?? generated,
|
|
18
|
+
open: props.open,
|
|
19
|
+
defaultOpen: props.defaultOpen,
|
|
20
|
+
modal: props.modal,
|
|
21
|
+
dismissible: props.dismissible,
|
|
22
|
+
onOpenChange: (open, details) => props.onOpenChange?.(open, details)
|
|
23
|
+
}));
|
|
24
|
+
return _$createComponent(Context.Provider, {
|
|
25
|
+
value: made,
|
|
26
|
+
get children() {
|
|
27
|
+
return props.children;
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
const Portal = props => _$createComponent(BodyPortal, {
|
|
32
|
+
get mounted() {
|
|
33
|
+
return useDialog().mounted;
|
|
34
|
+
},
|
|
35
|
+
get children() {
|
|
36
|
+
return props.children;
|
|
37
|
+
}
|
|
38
|
+
});
|
|
39
|
+
const part = (name, tag) => props => _$createComponent(Part, _$mergeProps({
|
|
40
|
+
get part() {
|
|
41
|
+
return useDialog()[name];
|
|
42
|
+
},
|
|
43
|
+
tag: tag
|
|
44
|
+
}, props));
|
|
45
|
+
function AlertRoot(props) {
|
|
46
|
+
const generated = createUniqueId();
|
|
47
|
+
const made = controller(createAlertDialog, () => ({
|
|
48
|
+
id: props.id ?? generated,
|
|
49
|
+
open: props.open,
|
|
50
|
+
defaultOpen: props.defaultOpen,
|
|
51
|
+
onOpenChange: (open, details) => props.onOpenChange?.(open, details)
|
|
52
|
+
}));
|
|
53
|
+
return _$createComponent(Context.Provider, {
|
|
54
|
+
value: made,
|
|
55
|
+
get children() {
|
|
56
|
+
return props.children;
|
|
57
|
+
}
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
export const Dialog = {
|
|
61
|
+
Root,
|
|
62
|
+
Portal,
|
|
63
|
+
Trigger: part("trigger", "button"),
|
|
64
|
+
Backdrop: part("backdrop", "div"),
|
|
65
|
+
Popup: part("popup", "div"),
|
|
66
|
+
Title: part("title", "h2"),
|
|
67
|
+
Description: part("description", "p"),
|
|
68
|
+
Close: part("close", "button")
|
|
69
|
+
};
|
|
70
|
+
/** A dialog that asks for an answer: a press outside it does not close it. Its parts are a dialog's. */
|
|
71
|
+
export const AlertDialog = {
|
|
72
|
+
...Dialog,
|
|
73
|
+
Root: AlertRoot
|
|
74
|
+
};
|
|
75
|
+
function DrawerRoot(props) {
|
|
76
|
+
const generated = createUniqueId();
|
|
77
|
+
const made = controller(createDrawer, () => ({
|
|
78
|
+
id: props.id ?? generated,
|
|
79
|
+
open: props.open,
|
|
80
|
+
defaultOpen: props.defaultOpen,
|
|
81
|
+
modal: props.modal,
|
|
82
|
+
dismissible: props.dismissible,
|
|
83
|
+
swipeDirection: props.swipeDirection,
|
|
84
|
+
snapPoints: props.snapPoints,
|
|
85
|
+
snapPoint: props.snapPoint,
|
|
86
|
+
defaultSnapPoint: props.defaultSnapPoint,
|
|
87
|
+
onSnapPointChange: (snapPoint, details) => props.onSnapPointChange?.(snapPoint, details),
|
|
88
|
+
onOpenChange: (open, details) => props.onOpenChange?.(open, details)
|
|
89
|
+
}));
|
|
90
|
+
return _$createComponent(Context.Provider, {
|
|
91
|
+
value: made,
|
|
92
|
+
get children() {
|
|
93
|
+
return props.children;
|
|
94
|
+
}
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
/** A dialog that comes from an edge and is dragged back to it. Its parts are a dialog's. */
|
|
98
|
+
export const Drawer = {
|
|
99
|
+
...Dialog,
|
|
100
|
+
Root: DrawerRoot
|
|
101
|
+
};
|