@kirana-ui/solid 0.1.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/dom/autocomplete.js +2 -0
- package/dom/autosize.js +19 -0
- package/dom/calendar.js +141 -0
- package/dom/carousel.js +83 -0
- package/dom/checkbox.js +2 -1
- 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 +28 -0
- package/dom/drawer.js +2 -0
- package/dom/hover-popup.js +17 -2
- package/dom/index.js +26 -1
- 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/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 +2 -0
- package/dom/qr-code.js +48 -0
- package/dom/radio-group.js +2 -1
- package/dom/resizable.js +65 -0
- package/dom/runtime.js +36 -2
- package/dom/scroll-area.js +99 -0
- package/dom/select.js +69 -5
- package/dom/slider.js +1 -1
- package/dom/switch.js +2 -1
- package/dom/toast.js +113 -0
- package/dom/toggle-group.js +37 -0
- package/dom/toggle.js +11 -3
- package/dom/toolbar-context.js +5 -0
- package/dom/toolbar.js +71 -0
- package/llms.txt +1838 -0
- package/package.json +220 -2
- package/server/autocomplete.js +2 -0
- package/server/autosize.js +19 -0
- package/server/calendar.js +140 -0
- package/server/carousel.js +83 -0
- package/server/checkbox.js +2 -1
- 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 +28 -0
- package/server/drawer.js +2 -0
- package/server/hover-popup.js +17 -2
- package/server/index.js +26 -1
- 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/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 +2 -0
- package/server/qr-code.js +48 -0
- package/server/radio-group.js +2 -1
- package/server/resizable.js +65 -0
- package/server/runtime.js +35 -1
- package/server/scroll-area.js +99 -0
- package/server/select.js +69 -5
- package/server/slider.js +1 -1
- package/server/switch.js +2 -1
- package/server/toast.js +113 -0
- package/server/toggle-group.js +37 -0
- package/server/toggle.js +11 -3
- package/server/toolbar-context.js +5 -0
- package/server/toolbar.js +71 -0
- package/src/autocomplete.jsx +2 -0
- package/src/autosize.jsx +8 -0
- package/src/calendar.jsx +104 -0
- package/src/carousel.jsx +51 -0
- package/src/checkbox.jsx +2 -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 +20 -0
- package/src/drawer.js +2 -0
- package/src/hover-popup.jsx +10 -2
- package/src/index.js +26 -1
- 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/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 +2 -0
- package/src/qr-code.jsx +25 -0
- package/src/radio-group.jsx +2 -0
- package/src/resizable.jsx +46 -0
- package/src/runtime.jsx +33 -2
- package/src/scroll-area.jsx +53 -0
- package/src/select.jsx +49 -5
- package/src/slider.jsx +2 -0
- package/src/switch.jsx +2 -0
- package/src/toast.jsx +58 -0
- package/src/toggle-group.jsx +32 -0
- package/src/toggle.jsx +8 -2
- package/src/toolbar-context.js +5 -0
- package/src/toolbar.jsx +43 -0
- package/types/autocomplete.d.ts +1 -0
- package/types/autosize.d.ts +8 -0
- package/types/calendar.d.ts +40 -0
- package/types/carousel.d.ts +26 -0
- package/types/checkbox.d.ts +1 -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 +21 -0
- package/types/drawer.d.ts +1 -0
- package/types/hover-card.d.ts +4 -1
- package/types/hover-popup.d.ts +4 -1
- package/types/index.d.ts +27 -1
- 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/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 +4 -1
- package/types/qr-code.d.ts +14 -0
- package/types/radio-group.d.ts +1 -0
- package/types/resizable.d.ts +24 -0
- package/types/runtime.d.ts +18 -0
- package/types/scroll-area.d.ts +20 -0
- package/types/select.d.ts +25 -1
- package/types/switch.d.ts +1 -0
- package/types/toast.d.ts +33 -0
- package/types/toggle-group.d.ts +14 -0
- package/types/toggle.d.ts +2 -0
- package/types/toolbar-context.d.ts +6 -0
- package/types/toolbar.d.ts +23 -0
- package/types/tooltip.d.ts +4 -1
package/dom/menu.js
ADDED
|
@@ -0,0 +1,261 @@
|
|
|
1
|
+
import { memo as _$memo } from "solid-js/web";
|
|
2
|
+
import { mergeProps as _$mergeProps } from "solid-js/web";
|
|
3
|
+
import { createComponent as _$createComponent } from "solid-js/web";
|
|
4
|
+
import { defined, within } from "@kirana-ui/core";
|
|
5
|
+
import { createMenu } from "@kirana-ui/core/menu";
|
|
6
|
+
import { Show, createContext, createUniqueId, splitProps, untrack, useContext } from "solid-js";
|
|
7
|
+
import { DirectionContext } from "./direction-context.js";
|
|
8
|
+
import { MenubarContext } from "./menubar-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 GroupContext = createContext(null);
|
|
13
|
+
const CheckboxContext = createContext();
|
|
14
|
+
const RadioGroupContext = createContext();
|
|
15
|
+
const RadioItemContext = createContext();
|
|
16
|
+
function useMenu() {
|
|
17
|
+
const made = useContext(Context);
|
|
18
|
+
if (!made) throw new Error("A Menu part must be inside <Menu.Root>");
|
|
19
|
+
return made;
|
|
20
|
+
}
|
|
21
|
+
function inside(found, parent) {
|
|
22
|
+
if (!found) throw new Error(`A Menu part must be inside <Menu.${parent}>`);
|
|
23
|
+
return found;
|
|
24
|
+
}
|
|
25
|
+
function make(props, kind) {
|
|
26
|
+
const generated = createUniqueId();
|
|
27
|
+
const direction = useContext(DirectionContext);
|
|
28
|
+
const parent = kind === "submenu" ? useMenu() : undefined;
|
|
29
|
+
const menubar = kind === "menu" ? useContext(MenubarContext) ?? undefined : undefined;
|
|
30
|
+
const around = {
|
|
31
|
+
parent,
|
|
32
|
+
direction,
|
|
33
|
+
menubar,
|
|
34
|
+
context: kind === "context"
|
|
35
|
+
};
|
|
36
|
+
const made = controller(within(createMenu, around), () => ({
|
|
37
|
+
id: props.id ?? generated,
|
|
38
|
+
open: props.open,
|
|
39
|
+
defaultOpen: props.defaultOpen,
|
|
40
|
+
disabled: props.disabled,
|
|
41
|
+
loop: props.loop,
|
|
42
|
+
modal: props.modal,
|
|
43
|
+
onOpenChange: (open, details) => props.onOpenChange?.(open, details)
|
|
44
|
+
}));
|
|
45
|
+
return _$createComponent(Context.Provider, {
|
|
46
|
+
value: made,
|
|
47
|
+
get children() {
|
|
48
|
+
return _$createComponent(MenubarContext.Provider, {
|
|
49
|
+
value: null,
|
|
50
|
+
get children() {
|
|
51
|
+
return _$createComponent(GroupContext.Provider, {
|
|
52
|
+
value: null,
|
|
53
|
+
get children() {
|
|
54
|
+
return props.children;
|
|
55
|
+
}
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
const Root = props => make(props, "menu");
|
|
63
|
+
/** A menu for an area of the page, opened at the pointer. Its trigger is the area. */
|
|
64
|
+
const ContextRoot = props => make(props, "context");
|
|
65
|
+
/** A menu that one of this menu's items opens. Its trigger is `<Menu.SubmenuTrigger>`. */
|
|
66
|
+
const SubmenuRoot = props => make(props, "submenu");
|
|
67
|
+
const Portal = props => _$createComponent(BodyPortal, {
|
|
68
|
+
get mounted() {
|
|
69
|
+
return useMenu().mounted;
|
|
70
|
+
},
|
|
71
|
+
get children() {
|
|
72
|
+
return props.children;
|
|
73
|
+
}
|
|
74
|
+
});
|
|
75
|
+
function Positioner(props) {
|
|
76
|
+
const made = useMenu();
|
|
77
|
+
return _$createComponent(Part, _$mergeProps({
|
|
78
|
+
get part() {
|
|
79
|
+
return made.positioner;
|
|
80
|
+
},
|
|
81
|
+
tag: "div"
|
|
82
|
+
}, () => positioned(props, made.positioning)));
|
|
83
|
+
}
|
|
84
|
+
const ITEM = ["disabled", "label", "closeOnClick"];
|
|
85
|
+
function Item(props) {
|
|
86
|
+
const [local, rest] = splitProps(props, ITEM);
|
|
87
|
+
const options = toSignal(() => ({
|
|
88
|
+
...local
|
|
89
|
+
}));
|
|
90
|
+
const part = useMenu().item(() => defined(options.get()));
|
|
91
|
+
return _$createComponent(Part, _$mergeProps({
|
|
92
|
+
part: part,
|
|
93
|
+
tag: "div"
|
|
94
|
+
}, rest));
|
|
95
|
+
}
|
|
96
|
+
/** An item that is a link: `href` and the rest go to its `<a>`. */
|
|
97
|
+
function LinkItem(props) {
|
|
98
|
+
const [local, rest] = splitProps(props, ITEM);
|
|
99
|
+
const options = toSignal(() => ({
|
|
100
|
+
...local
|
|
101
|
+
}));
|
|
102
|
+
const part = useMenu().item(() => defined(options.get()));
|
|
103
|
+
return _$createComponent(Part, _$mergeProps({
|
|
104
|
+
part: part,
|
|
105
|
+
tag: "a"
|
|
106
|
+
}, rest));
|
|
107
|
+
}
|
|
108
|
+
function Group(props) {
|
|
109
|
+
const [local, rest] = splitProps(props, ["id"]);
|
|
110
|
+
const generated = createUniqueId();
|
|
111
|
+
const group = useMenu().group(untrack(() => local.id) ?? generated);
|
|
112
|
+
return _$createComponent(GroupContext.Provider, {
|
|
113
|
+
value: group,
|
|
114
|
+
get children() {
|
|
115
|
+
return _$createComponent(Part, _$mergeProps({
|
|
116
|
+
get part() {
|
|
117
|
+
return group.root;
|
|
118
|
+
},
|
|
119
|
+
tag: "div"
|
|
120
|
+
}, rest));
|
|
121
|
+
}
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
/** Names the group it is in. With no group around it, it is plain text. */
|
|
125
|
+
const GroupLabel = props => _$createComponent(Part, _$mergeProps({
|
|
126
|
+
get part() {
|
|
127
|
+
return useContext(GroupContext)?.label ?? useMenu().label;
|
|
128
|
+
},
|
|
129
|
+
tag: "div"
|
|
130
|
+
}, props));
|
|
131
|
+
function CheckboxItem(props) {
|
|
132
|
+
const [local, rest] = splitProps(props, [...ITEM, "checked", "defaultChecked", "onCheckedChange"]);
|
|
133
|
+
const item = controller(useMenu().checkboxItem, () => ({
|
|
134
|
+
checked: local.checked,
|
|
135
|
+
defaultChecked: local.defaultChecked,
|
|
136
|
+
disabled: local.disabled,
|
|
137
|
+
label: local.label,
|
|
138
|
+
closeOnClick: local.closeOnClick,
|
|
139
|
+
onCheckedChange: (checked, details) => local.onCheckedChange?.(checked, details)
|
|
140
|
+
}));
|
|
141
|
+
return _$createComponent(CheckboxContext.Provider, {
|
|
142
|
+
value: item,
|
|
143
|
+
get children() {
|
|
144
|
+
return _$createComponent(Part, _$mergeProps({
|
|
145
|
+
get part() {
|
|
146
|
+
return item.part;
|
|
147
|
+
},
|
|
148
|
+
tag: "div"
|
|
149
|
+
}, rest));
|
|
150
|
+
}
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
function CheckboxItemIndicator(props) {
|
|
154
|
+
const [local, rest] = splitProps(props, ["keepMounted"]);
|
|
155
|
+
const item = inside(useContext(CheckboxContext), "CheckboxItem");
|
|
156
|
+
const checked = fromSignal(item.checked);
|
|
157
|
+
return _$createComponent(Show, {
|
|
158
|
+
get when() {
|
|
159
|
+
return checked() || local.keepMounted;
|
|
160
|
+
},
|
|
161
|
+
get children() {
|
|
162
|
+
return _$createComponent(Part, _$mergeProps({
|
|
163
|
+
get part() {
|
|
164
|
+
return item.indicator;
|
|
165
|
+
},
|
|
166
|
+
tag: "span"
|
|
167
|
+
}, rest));
|
|
168
|
+
}
|
|
169
|
+
});
|
|
170
|
+
}
|
|
171
|
+
function RadioGroup(props) {
|
|
172
|
+
const [local, rest] = splitProps(props, ["value", "defaultValue", "onValueChange", "disabled"]);
|
|
173
|
+
const group = controller(useMenu().radioGroup, () => ({
|
|
174
|
+
value: local.value,
|
|
175
|
+
defaultValue: local.defaultValue,
|
|
176
|
+
disabled: local.disabled,
|
|
177
|
+
onValueChange: (value, details) => local.onValueChange?.(value, details)
|
|
178
|
+
}));
|
|
179
|
+
return _$createComponent(RadioGroupContext.Provider, {
|
|
180
|
+
value: group,
|
|
181
|
+
get children() {
|
|
182
|
+
return _$createComponent(Part, _$mergeProps({
|
|
183
|
+
get part() {
|
|
184
|
+
return group.root;
|
|
185
|
+
},
|
|
186
|
+
tag: "div"
|
|
187
|
+
}, rest));
|
|
188
|
+
}
|
|
189
|
+
});
|
|
190
|
+
}
|
|
191
|
+
function RadioItem(props) {
|
|
192
|
+
const [local, rest] = splitProps(props, [...ITEM, "value"]);
|
|
193
|
+
// An item is its value for as long as it is in the page.
|
|
194
|
+
const value = untrack(() => local.value);
|
|
195
|
+
const options = toSignal(() => ({
|
|
196
|
+
disabled: local.disabled,
|
|
197
|
+
label: local.label,
|
|
198
|
+
closeOnClick: local.closeOnClick
|
|
199
|
+
}));
|
|
200
|
+
const part = inside(useContext(RadioGroupContext), "RadioGroup").item(value, () => defined(options.get()));
|
|
201
|
+
return _$createComponent(RadioItemContext.Provider, {
|
|
202
|
+
value: value,
|
|
203
|
+
get children() {
|
|
204
|
+
return _$createComponent(Part, _$mergeProps({
|
|
205
|
+
part: part,
|
|
206
|
+
tag: "div"
|
|
207
|
+
}, rest));
|
|
208
|
+
}
|
|
209
|
+
});
|
|
210
|
+
}
|
|
211
|
+
function RadioItemIndicator(props) {
|
|
212
|
+
const [local, rest] = splitProps(props, ["keepMounted"]);
|
|
213
|
+
const group = inside(useContext(RadioGroupContext), "RadioGroup");
|
|
214
|
+
const value = useContext(RadioItemContext);
|
|
215
|
+
const checked = fromSignal(group.checked(value));
|
|
216
|
+
return _$createComponent(Show, {
|
|
217
|
+
get when() {
|
|
218
|
+
return checked() || local.keepMounted;
|
|
219
|
+
},
|
|
220
|
+
get children() {
|
|
221
|
+
return _$createComponent(Part, _$mergeProps({
|
|
222
|
+
get part() {
|
|
223
|
+
return group.indicator(value);
|
|
224
|
+
},
|
|
225
|
+
tag: "span"
|
|
226
|
+
}, rest));
|
|
227
|
+
}
|
|
228
|
+
});
|
|
229
|
+
}
|
|
230
|
+
const part = (name, tag) => props => _$createComponent(Part, _$mergeProps({
|
|
231
|
+
get part() {
|
|
232
|
+
return useMenu()[name];
|
|
233
|
+
},
|
|
234
|
+
tag: tag
|
|
235
|
+
}, props));
|
|
236
|
+
export const Menu = {
|
|
237
|
+
Root,
|
|
238
|
+
Portal,
|
|
239
|
+
Positioner,
|
|
240
|
+
Trigger: part("trigger", "button"),
|
|
241
|
+
Popup: part("popup", "div"),
|
|
242
|
+
Arrow: part("arrow", "div"),
|
|
243
|
+
Item,
|
|
244
|
+
LinkItem,
|
|
245
|
+
Group,
|
|
246
|
+
GroupLabel,
|
|
247
|
+
Separator: part("separator", "div"),
|
|
248
|
+
CheckboxItem,
|
|
249
|
+
CheckboxItemIndicator,
|
|
250
|
+
RadioGroup,
|
|
251
|
+
RadioItem,
|
|
252
|
+
RadioItemIndicator,
|
|
253
|
+
SubmenuRoot,
|
|
254
|
+
SubmenuTrigger: part("trigger", "div")
|
|
255
|
+
};
|
|
256
|
+
export const ContextMenu = {
|
|
257
|
+
...Menu,
|
|
258
|
+
Root: ContextRoot,
|
|
259
|
+
/** The area a secondary press, or a long press on a touch screen, opens the menu in. */
|
|
260
|
+
Trigger: part("area", "div")
|
|
261
|
+
};
|
package/dom/menubar.js
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
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 { createMenubar } from "@kirana-ui/core/menubar";
|
|
5
|
+
import { createUniqueId, splitProps, useContext } from "solid-js";
|
|
6
|
+
import { DirectionContext } from "./direction-context.js";
|
|
7
|
+
import { MenubarContext } from "./menubar-context.js";
|
|
8
|
+
import { Part, controller } from "./runtime.js";
|
|
9
|
+
/** A row of menus that work as one. Each `<Menu.Root>` inside it is one of its items. */
|
|
10
|
+
export function Menubar(props) {
|
|
11
|
+
const [local, rest] = splitProps(props, ["loop", "disabled", "orientation", "id"]);
|
|
12
|
+
const generated = createUniqueId();
|
|
13
|
+
const direction = useContext(DirectionContext);
|
|
14
|
+
const made = controller(within(createMenubar, {
|
|
15
|
+
direction
|
|
16
|
+
}), () => ({
|
|
17
|
+
id: local.id ?? generated,
|
|
18
|
+
loop: local.loop,
|
|
19
|
+
disabled: local.disabled,
|
|
20
|
+
orientation: local.orientation
|
|
21
|
+
}));
|
|
22
|
+
return _$createComponent(MenubarContext.Provider, {
|
|
23
|
+
value: made,
|
|
24
|
+
get children() {
|
|
25
|
+
return _$createComponent(Part, _$mergeProps({
|
|
26
|
+
get part() {
|
|
27
|
+
return made.root;
|
|
28
|
+
},
|
|
29
|
+
tag: "div"
|
|
30
|
+
}, rest));
|
|
31
|
+
}
|
|
32
|
+
});
|
|
33
|
+
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { createComponent as _$createComponent } from "solid-js/web";
|
|
2
|
+
import { mergeProps as _$mergeProps } from "solid-js/web";
|
|
3
|
+
import { createMessageScroller } from "@kirana-ui/core/message-scroller";
|
|
4
|
+
import { createContext, createUniqueId, splitProps, useContext } from "solid-js";
|
|
5
|
+
import { Part, controller } from "./runtime.js";
|
|
6
|
+
const Context = createContext();
|
|
7
|
+
function useScroller() {
|
|
8
|
+
const made = useContext(Context);
|
|
9
|
+
if (!made) throw new Error("A MessageScroller part must be inside <MessageScroller.Root>");
|
|
10
|
+
return made;
|
|
11
|
+
}
|
|
12
|
+
function Root(props) {
|
|
13
|
+
const [local, rest] = splitProps(props, ["initial", "threshold", "onAtBottomChange", "id"]);
|
|
14
|
+
const generated = createUniqueId();
|
|
15
|
+
const made = controller(createMessageScroller, () => ({
|
|
16
|
+
id: local.id ?? generated,
|
|
17
|
+
initial: local.initial,
|
|
18
|
+
threshold: local.threshold,
|
|
19
|
+
onAtBottomChange: (atBottom, details) => local.onAtBottomChange?.(atBottom, details)
|
|
20
|
+
}));
|
|
21
|
+
return _$createComponent(Context.Provider, {
|
|
22
|
+
value: made,
|
|
23
|
+
get children() {
|
|
24
|
+
return _$createComponent(Part, _$mergeProps({
|
|
25
|
+
get part() {
|
|
26
|
+
return made.root;
|
|
27
|
+
},
|
|
28
|
+
tag: "div"
|
|
29
|
+
}, rest));
|
|
30
|
+
}
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
const Viewport = props => _$createComponent(Part, _$mergeProps({
|
|
34
|
+
get part() {
|
|
35
|
+
return useScroller().viewport;
|
|
36
|
+
},
|
|
37
|
+
tag: "div"
|
|
38
|
+
}, props));
|
|
39
|
+
const Content = props => _$createComponent(Part, _$mergeProps({
|
|
40
|
+
get part() {
|
|
41
|
+
return useScroller().content;
|
|
42
|
+
},
|
|
43
|
+
tag: "div"
|
|
44
|
+
}, props));
|
|
45
|
+
const Button = props => _$createComponent(Part, _$mergeProps({
|
|
46
|
+
get part() {
|
|
47
|
+
return useScroller().button;
|
|
48
|
+
},
|
|
49
|
+
tag: "button"
|
|
50
|
+
}, props));
|
|
51
|
+
export const MessageScroller = {
|
|
52
|
+
Root,
|
|
53
|
+
Viewport,
|
|
54
|
+
Content,
|
|
55
|
+
Button
|
|
56
|
+
};
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
import { template as _$template } from "solid-js/web";
|
|
2
|
+
import { memo as _$memo } from "solid-js/web";
|
|
3
|
+
import { getNextElement as _$getNextElement } from "solid-js/web";
|
|
4
|
+
import { insert as _$insert } from "solid-js/web";
|
|
5
|
+
import { createComponent as _$createComponent } from "solid-js/web";
|
|
6
|
+
import { mergeProps as _$mergeProps } from "solid-js/web";
|
|
7
|
+
var _tmpl$ = /*#__PURE__*/_$template(`<li>`);
|
|
8
|
+
import { defined, within } from "@kirana-ui/core";
|
|
9
|
+
import { createNavigationMenu } from "@kirana-ui/core/navigation-menu";
|
|
10
|
+
import { Show, createContext, createUniqueId, onCleanup, onMount, splitProps, untrack, useContext } from "solid-js";
|
|
11
|
+
import { DirectionContext } from "./direction-context.js";
|
|
12
|
+
import { positioned } from "./popover.js";
|
|
13
|
+
import { Into, Part, Portal as BodyPortal, controller, fromSignal, toSignal } from "./runtime.js";
|
|
14
|
+
const Context = createContext();
|
|
15
|
+
const ItemContext = createContext();
|
|
16
|
+
function useNavigation() {
|
|
17
|
+
const made = useContext(Context);
|
|
18
|
+
if (!made) throw new Error("A NavigationMenu part must be inside <NavigationMenu.Root>");
|
|
19
|
+
return made;
|
|
20
|
+
}
|
|
21
|
+
function useItem() {
|
|
22
|
+
const item = useContext(ItemContext);
|
|
23
|
+
if (!item) throw new Error("A NavigationMenu part must be inside <NavigationMenu.Item>");
|
|
24
|
+
return item;
|
|
25
|
+
}
|
|
26
|
+
function Root(props) {
|
|
27
|
+
const [local, rest] = splitProps(props, ["value", "defaultValue", "onValueChange", "delay", "closeDelay", "orientation", "id"]);
|
|
28
|
+
const generated = createUniqueId();
|
|
29
|
+
const direction = useContext(DirectionContext);
|
|
30
|
+
const made = controller(within(createNavigationMenu, {
|
|
31
|
+
direction
|
|
32
|
+
}), () => ({
|
|
33
|
+
id: local.id ?? generated,
|
|
34
|
+
value: local.value,
|
|
35
|
+
defaultValue: local.defaultValue,
|
|
36
|
+
delay: local.delay,
|
|
37
|
+
closeDelay: local.closeDelay,
|
|
38
|
+
orientation: local.orientation,
|
|
39
|
+
onValueChange: (value, details) => local.onValueChange?.(value, details)
|
|
40
|
+
}));
|
|
41
|
+
return _$createComponent(Context.Provider, {
|
|
42
|
+
value: made,
|
|
43
|
+
get children() {
|
|
44
|
+
return _$createComponent(Part, _$mergeProps({
|
|
45
|
+
get part() {
|
|
46
|
+
return made.root;
|
|
47
|
+
},
|
|
48
|
+
tag: "nav"
|
|
49
|
+
}, rest));
|
|
50
|
+
}
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
/** `value` tells this item from the others; an item that is only a link needs none. */
|
|
54
|
+
function Item(props) {
|
|
55
|
+
const value = untrack(() => props.value);
|
|
56
|
+
if (value === undefined) return (() => {
|
|
57
|
+
var _el$ = _$getNextElement(_tmpl$);
|
|
58
|
+
_$insert(_el$, () => props.children);
|
|
59
|
+
return _el$;
|
|
60
|
+
})();
|
|
61
|
+
const item = useNavigation().item(value);
|
|
62
|
+
onMount(() => onCleanup(item.mount()));
|
|
63
|
+
return _$createComponent(ItemContext.Provider, {
|
|
64
|
+
value: item,
|
|
65
|
+
get children() {
|
|
66
|
+
var _el$2 = _$getNextElement(_tmpl$);
|
|
67
|
+
_$insert(_el$2, () => props.children);
|
|
68
|
+
return _el$2;
|
|
69
|
+
}
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
/** An item's content: drawn in `<NavigationMenu.Viewport>`, while it is shown. */
|
|
73
|
+
function Content(props) {
|
|
74
|
+
const item = useItem();
|
|
75
|
+
const mounted = fromSignal(item.mounted);
|
|
76
|
+
const viewport = fromSignal(useNavigation().viewportElement);
|
|
77
|
+
return _$createComponent(Show, {
|
|
78
|
+
get when() {
|
|
79
|
+
return _$memo(() => !!mounted())() ? viewport() : undefined;
|
|
80
|
+
},
|
|
81
|
+
children: target => _$createComponent(Into, {
|
|
82
|
+
get target() {
|
|
83
|
+
return target();
|
|
84
|
+
},
|
|
85
|
+
get children() {
|
|
86
|
+
return _$createComponent(Part, _$mergeProps({
|
|
87
|
+
get part() {
|
|
88
|
+
return item.content;
|
|
89
|
+
},
|
|
90
|
+
tag: "div"
|
|
91
|
+
}, props));
|
|
92
|
+
}
|
|
93
|
+
})
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
function Link(props) {
|
|
97
|
+
const [local, rest] = splitProps(props, ["active", "closeOnClick"]);
|
|
98
|
+
const options = toSignal(() => ({
|
|
99
|
+
...local
|
|
100
|
+
}));
|
|
101
|
+
const part = useNavigation().link(() => defined(options.get()));
|
|
102
|
+
return _$createComponent(Part, _$mergeProps({
|
|
103
|
+
part: part,
|
|
104
|
+
tag: "a"
|
|
105
|
+
}, rest));
|
|
106
|
+
}
|
|
107
|
+
const Portal = props => _$createComponent(BodyPortal, {
|
|
108
|
+
get mounted() {
|
|
109
|
+
return useNavigation().mounted;
|
|
110
|
+
},
|
|
111
|
+
get children() {
|
|
112
|
+
return props.children;
|
|
113
|
+
}
|
|
114
|
+
});
|
|
115
|
+
function Positioner(props) {
|
|
116
|
+
const made = useNavigation();
|
|
117
|
+
return _$createComponent(Part, _$mergeProps({
|
|
118
|
+
get part() {
|
|
119
|
+
return made.positioner;
|
|
120
|
+
},
|
|
121
|
+
tag: "div"
|
|
122
|
+
}, () => positioned(props, made.positioning)));
|
|
123
|
+
}
|
|
124
|
+
const part = (name, tag) => props => _$createComponent(Part, _$mergeProps({
|
|
125
|
+
get part() {
|
|
126
|
+
return useNavigation()[name];
|
|
127
|
+
},
|
|
128
|
+
tag: tag
|
|
129
|
+
}, props));
|
|
130
|
+
const itemPart = (name, tag) => props => _$createComponent(Part, _$mergeProps({
|
|
131
|
+
get part() {
|
|
132
|
+
return useItem()[name];
|
|
133
|
+
},
|
|
134
|
+
tag: tag
|
|
135
|
+
}, props));
|
|
136
|
+
export const NavigationMenu = {
|
|
137
|
+
Root,
|
|
138
|
+
List: part("list", "ul"),
|
|
139
|
+
Item,
|
|
140
|
+
Trigger: itemPart("trigger", "button"),
|
|
141
|
+
Icon: itemPart("icon", "span"),
|
|
142
|
+
Content,
|
|
143
|
+
Link,
|
|
144
|
+
Portal,
|
|
145
|
+
Positioner,
|
|
146
|
+
Popup: part("popup", "div"),
|
|
147
|
+
Viewport: part("viewport", "div"),
|
|
148
|
+
Arrow: part("arrow", "div"),
|
|
149
|
+
Backdrop: part("backdrop", "div")
|
|
150
|
+
};
|
|
@@ -0,0 +1,82 @@
|
|
|
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 { createNumberField } from "@kirana-ui/core/number-field";
|
|
6
|
+
import { Show, createContext, createUniqueId, splitProps, useContext } from "solid-js";
|
|
7
|
+
import { FieldContext } from "./field-context.js";
|
|
8
|
+
import { Part, controller, fromSignal } from "./runtime.js";
|
|
9
|
+
const Context = createContext();
|
|
10
|
+
function useNumberField() {
|
|
11
|
+
const made = useContext(Context);
|
|
12
|
+
if (!made) throw new Error("A NumberField part must be inside <NumberField.Root>");
|
|
13
|
+
return made;
|
|
14
|
+
}
|
|
15
|
+
function Root(props) {
|
|
16
|
+
const [local, rest] = splitProps(props, ["value", "defaultValue", "onValueChange", "onValueCommitted", "min", "max", "step", "smallStep", "largeStep", "snapOnStep", "allowWheelScrub", "format", "locale", "disabled", "readOnly", "required", "name", "form", "id", "children"]);
|
|
17
|
+
const generated = createUniqueId();
|
|
18
|
+
const made = controller(within(createNumberField, {
|
|
19
|
+
field: useContext(FieldContext)
|
|
20
|
+
}), () => ({
|
|
21
|
+
id: local.id ?? generated,
|
|
22
|
+
value: local.value,
|
|
23
|
+
defaultValue: local.defaultValue,
|
|
24
|
+
min: local.min,
|
|
25
|
+
max: local.max,
|
|
26
|
+
step: local.step,
|
|
27
|
+
smallStep: local.smallStep,
|
|
28
|
+
largeStep: local.largeStep,
|
|
29
|
+
snapOnStep: local.snapOnStep,
|
|
30
|
+
allowWheelScrub: local.allowWheelScrub,
|
|
31
|
+
format: local.format,
|
|
32
|
+
locale: local.locale,
|
|
33
|
+
disabled: local.disabled,
|
|
34
|
+
readOnly: local.readOnly,
|
|
35
|
+
required: local.required,
|
|
36
|
+
name: local.name,
|
|
37
|
+
form: local.form,
|
|
38
|
+
onValueChange: (value, details) => local.onValueChange?.(value, details),
|
|
39
|
+
onValueCommitted: (value, details) => local.onValueCommitted?.(value, details)
|
|
40
|
+
}));
|
|
41
|
+
const named = fromSignal(made.named);
|
|
42
|
+
return _$createComponent(Context.Provider, {
|
|
43
|
+
value: made,
|
|
44
|
+
get children() {
|
|
45
|
+
return _$createComponent(Part, _$mergeProps({
|
|
46
|
+
get part() {
|
|
47
|
+
return made.root;
|
|
48
|
+
},
|
|
49
|
+
tag: "div"
|
|
50
|
+
}, rest, {
|
|
51
|
+
get children() {
|
|
52
|
+
return [_$memo(() => local.children), _$createComponent(Show, {
|
|
53
|
+
get when() {
|
|
54
|
+
return named();
|
|
55
|
+
},
|
|
56
|
+
get children() {
|
|
57
|
+
return _$createComponent(Part, {
|
|
58
|
+
get part() {
|
|
59
|
+
return made.hidden;
|
|
60
|
+
},
|
|
61
|
+
tag: "input"
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
})];
|
|
65
|
+
}
|
|
66
|
+
}));
|
|
67
|
+
}
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
const part = (name, tag) => props => _$createComponent(Part, _$mergeProps({
|
|
71
|
+
get part() {
|
|
72
|
+
return useNumberField()[name];
|
|
73
|
+
},
|
|
74
|
+
tag: tag
|
|
75
|
+
}, props));
|
|
76
|
+
export const NumberField = {
|
|
77
|
+
Root,
|
|
78
|
+
Group: part("group", "div"),
|
|
79
|
+
Input: part("input", "input"),
|
|
80
|
+
Increment: part("increment", "button"),
|
|
81
|
+
Decrement: part("decrement", "button")
|
|
82
|
+
};
|
package/dom/otp.js
ADDED
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import { memo as _$memo } from "solid-js/web";
|
|
2
|
+
import { createComponent as _$createComponent } from "solid-js/web";
|
|
3
|
+
import { mergeProps as _$mergeProps } from "solid-js/web";
|
|
4
|
+
import { createOtp } from "@kirana-ui/core/otp";
|
|
5
|
+
import { Show, createContext, createUniqueId, splitProps, untrack, useContext } from "solid-js";
|
|
6
|
+
import { Part, controller, fromSignal } from "./runtime.js";
|
|
7
|
+
const Context = createContext();
|
|
8
|
+
const SlotContext = createContext();
|
|
9
|
+
function useOtp() {
|
|
10
|
+
const made = useContext(Context);
|
|
11
|
+
if (!made) throw new Error("An Otp part must be inside <Otp.Root>");
|
|
12
|
+
return made;
|
|
13
|
+
}
|
|
14
|
+
function Root(props) {
|
|
15
|
+
const [local, rest] = splitProps(props, ["length", "value", "defaultValue", "onValueChange", "onComplete", "mode", "disabled", "name", "form", "id"]);
|
|
16
|
+
const generated = createUniqueId();
|
|
17
|
+
const made = controller(createOtp, () => ({
|
|
18
|
+
id: local.id ?? generated,
|
|
19
|
+
length: local.length,
|
|
20
|
+
value: local.value,
|
|
21
|
+
defaultValue: local.defaultValue,
|
|
22
|
+
mode: local.mode,
|
|
23
|
+
disabled: local.disabled,
|
|
24
|
+
name: local.name,
|
|
25
|
+
form: local.form,
|
|
26
|
+
onValueChange: (value, details) => local.onValueChange?.(value, details),
|
|
27
|
+
onComplete: value => local.onComplete?.(value)
|
|
28
|
+
}));
|
|
29
|
+
return _$createComponent(Context.Provider, {
|
|
30
|
+
value: made,
|
|
31
|
+
get children() {
|
|
32
|
+
return _$createComponent(Part, _$mergeProps({
|
|
33
|
+
get part() {
|
|
34
|
+
return made.root;
|
|
35
|
+
},
|
|
36
|
+
tag: "div"
|
|
37
|
+
}, rest));
|
|
38
|
+
}
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
/** One cell: it shows its character, then whatever it is given (a caret). */
|
|
42
|
+
function Slot(props) {
|
|
43
|
+
const [local, rest] = splitProps(props, ["index", "children"]);
|
|
44
|
+
const slot = useOtp().slot(untrack(() => local.index));
|
|
45
|
+
const char = fromSignal(slot.char);
|
|
46
|
+
return _$createComponent(SlotContext.Provider, {
|
|
47
|
+
value: slot,
|
|
48
|
+
get children() {
|
|
49
|
+
return _$createComponent(Part, _$mergeProps({
|
|
50
|
+
get part() {
|
|
51
|
+
return slot.part;
|
|
52
|
+
},
|
|
53
|
+
tag: "div"
|
|
54
|
+
}, rest, {
|
|
55
|
+
get children() {
|
|
56
|
+
return [_$memo(() => char()), _$memo(() => local.children)];
|
|
57
|
+
}
|
|
58
|
+
}));
|
|
59
|
+
}
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
/** Drawn in its cell while the cell is the active one and empty. */
|
|
63
|
+
function Caret(props) {
|
|
64
|
+
const made = useOtp();
|
|
65
|
+
const slot = useContext(SlotContext);
|
|
66
|
+
if (!slot) throw new Error("An Otp.Caret must be inside <Otp.Slot>");
|
|
67
|
+
const shown = fromSignal(slot.caret);
|
|
68
|
+
return _$createComponent(Show, {
|
|
69
|
+
get when() {
|
|
70
|
+
return shown();
|
|
71
|
+
},
|
|
72
|
+
get children() {
|
|
73
|
+
return _$createComponent(Part, _$mergeProps({
|
|
74
|
+
get part() {
|
|
75
|
+
return made.caretPart;
|
|
76
|
+
},
|
|
77
|
+
tag: "div"
|
|
78
|
+
}, props));
|
|
79
|
+
}
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
const part = (name, tag) => props => _$createComponent(Part, _$mergeProps({
|
|
83
|
+
get part() {
|
|
84
|
+
return useOtp()[name];
|
|
85
|
+
},
|
|
86
|
+
tag: tag
|
|
87
|
+
}, props));
|
|
88
|
+
export const Otp = {
|
|
89
|
+
Root,
|
|
90
|
+
Input: part("input", "input"),
|
|
91
|
+
Group: part("group", "div"),
|
|
92
|
+
Slot,
|
|
93
|
+
Separator: part("separator", "div"),
|
|
94
|
+
Caret
|
|
95
|
+
};
|