@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/src/menu.jsx
ADDED
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
import { defined, within } from "@kirana-ui/core";
|
|
2
|
+
import { createMenu } from "@kirana-ui/core/menu";
|
|
3
|
+
import { Show, createContext, createUniqueId, splitProps, untrack, useContext } from "solid-js";
|
|
4
|
+
import { DirectionContext } from "./direction-context.js";
|
|
5
|
+
import { MenubarContext } from "./menubar-context.js";
|
|
6
|
+
import { positioned } from "./popover.jsx";
|
|
7
|
+
import { Part, Portal as BodyPortal, controller, fromSignal, toSignal } from "./runtime.jsx";
|
|
8
|
+
const Context = createContext();
|
|
9
|
+
const GroupContext = createContext(null);
|
|
10
|
+
const CheckboxContext = createContext();
|
|
11
|
+
const RadioGroupContext = createContext();
|
|
12
|
+
const RadioItemContext = createContext();
|
|
13
|
+
function useMenu() {
|
|
14
|
+
const made = useContext(Context);
|
|
15
|
+
if (!made)
|
|
16
|
+
throw new Error("A Menu part must be inside <Menu.Root>");
|
|
17
|
+
return made;
|
|
18
|
+
}
|
|
19
|
+
function inside(found, parent) {
|
|
20
|
+
if (!found)
|
|
21
|
+
throw new Error(`A Menu part must be inside <Menu.${parent}>`);
|
|
22
|
+
return found;
|
|
23
|
+
}
|
|
24
|
+
function make(props, kind) {
|
|
25
|
+
const generated = createUniqueId();
|
|
26
|
+
const direction = useContext(DirectionContext);
|
|
27
|
+
const parent = kind === "submenu" ? useMenu() : undefined;
|
|
28
|
+
const menubar = kind === "menu" ? (useContext(MenubarContext) ?? undefined) : undefined;
|
|
29
|
+
const around = { parent, direction, menubar, context: kind === "context" };
|
|
30
|
+
const made = controller(within(createMenu, around), () => ({
|
|
31
|
+
id: props.id ?? generated,
|
|
32
|
+
open: props.open,
|
|
33
|
+
defaultOpen: props.defaultOpen,
|
|
34
|
+
disabled: props.disabled,
|
|
35
|
+
loop: props.loop,
|
|
36
|
+
modal: props.modal,
|
|
37
|
+
onOpenChange: (open, details) => props.onOpenChange?.(open, details),
|
|
38
|
+
}));
|
|
39
|
+
return (<Context.Provider value={made}>
|
|
40
|
+
{/* A group around a submenu is not a group of the submenu's own items; nor is a menu
|
|
41
|
+
written inside a bar's menu one of the bar's. */}
|
|
42
|
+
<MenubarContext.Provider value={null}>
|
|
43
|
+
<GroupContext.Provider value={null}>{props.children}</GroupContext.Provider>
|
|
44
|
+
</MenubarContext.Provider>
|
|
45
|
+
</Context.Provider>);
|
|
46
|
+
}
|
|
47
|
+
const Root = (props) => make(props, "menu");
|
|
48
|
+
/** A menu for an area of the page, opened at the pointer. Its trigger is the area. */
|
|
49
|
+
const ContextRoot = (props) => make(props, "context");
|
|
50
|
+
/** A menu that one of this menu's items opens. Its trigger is `<Menu.SubmenuTrigger>`. */
|
|
51
|
+
const SubmenuRoot = (props) => make(props, "submenu");
|
|
52
|
+
const Portal = (props) => (<BodyPortal mounted={useMenu().mounted}>{props.children}</BodyPortal>);
|
|
53
|
+
function Positioner(props) {
|
|
54
|
+
const made = useMenu();
|
|
55
|
+
return <Part part={made.positioner} tag="div" {...positioned(props, made.positioning)}/>;
|
|
56
|
+
}
|
|
57
|
+
const ITEM = ["disabled", "label", "closeOnClick"];
|
|
58
|
+
function Item(props) {
|
|
59
|
+
const [local, rest] = splitProps(props, ITEM);
|
|
60
|
+
const options = toSignal(() => ({ ...local }));
|
|
61
|
+
const part = useMenu().item(() => defined(options.get()));
|
|
62
|
+
return <Part part={part} tag="div" {...rest}/>;
|
|
63
|
+
}
|
|
64
|
+
/** An item that is a link: `href` and the rest go to its `<a>`. */
|
|
65
|
+
function LinkItem(props) {
|
|
66
|
+
const [local, rest] = splitProps(props, ITEM);
|
|
67
|
+
const options = toSignal(() => ({ ...local }));
|
|
68
|
+
const part = useMenu().item(() => defined(options.get()));
|
|
69
|
+
return <Part part={part} tag="a" {...rest}/>;
|
|
70
|
+
}
|
|
71
|
+
function Group(props) {
|
|
72
|
+
const [local, rest] = splitProps(props, ["id"]);
|
|
73
|
+
const generated = createUniqueId();
|
|
74
|
+
const group = useMenu().group(untrack(() => local.id) ?? generated);
|
|
75
|
+
return (<GroupContext.Provider value={group}>
|
|
76
|
+
<Part part={group.root} tag="div" {...rest}/>
|
|
77
|
+
</GroupContext.Provider>);
|
|
78
|
+
}
|
|
79
|
+
/** Names the group it is in. With no group around it, it is plain text. */
|
|
80
|
+
const GroupLabel = (props) => (<Part part={useContext(GroupContext)?.label ?? useMenu().label} tag="div" {...props}/>);
|
|
81
|
+
function CheckboxItem(props) {
|
|
82
|
+
const [local, rest] = splitProps(props, [...ITEM, "checked", "defaultChecked", "onCheckedChange"]);
|
|
83
|
+
const item = controller(useMenu().checkboxItem, () => ({
|
|
84
|
+
checked: local.checked,
|
|
85
|
+
defaultChecked: local.defaultChecked,
|
|
86
|
+
disabled: local.disabled,
|
|
87
|
+
label: local.label,
|
|
88
|
+
closeOnClick: local.closeOnClick,
|
|
89
|
+
onCheckedChange: (checked, details) => local.onCheckedChange?.(checked, details),
|
|
90
|
+
}));
|
|
91
|
+
return (<CheckboxContext.Provider value={item}>
|
|
92
|
+
<Part part={item.part} tag="div" {...rest}/>
|
|
93
|
+
</CheckboxContext.Provider>);
|
|
94
|
+
}
|
|
95
|
+
function CheckboxItemIndicator(props) {
|
|
96
|
+
const [local, rest] = splitProps(props, ["keepMounted"]);
|
|
97
|
+
const item = inside(useContext(CheckboxContext), "CheckboxItem");
|
|
98
|
+
const checked = fromSignal(item.checked);
|
|
99
|
+
return (<Show when={checked() || local.keepMounted}>
|
|
100
|
+
<Part part={item.indicator} tag="span" {...rest}/>
|
|
101
|
+
</Show>);
|
|
102
|
+
}
|
|
103
|
+
function RadioGroup(props) {
|
|
104
|
+
const [local, rest] = splitProps(props, ["value", "defaultValue", "onValueChange", "disabled"]);
|
|
105
|
+
const group = controller((useMenu().radioGroup), () => ({
|
|
106
|
+
value: local.value,
|
|
107
|
+
defaultValue: local.defaultValue,
|
|
108
|
+
disabled: local.disabled,
|
|
109
|
+
onValueChange: (value, details) => local.onValueChange?.(value, details),
|
|
110
|
+
}));
|
|
111
|
+
return (<RadioGroupContext.Provider value={group}>
|
|
112
|
+
<Part part={group.root} tag="div" {...rest}/>
|
|
113
|
+
</RadioGroupContext.Provider>);
|
|
114
|
+
}
|
|
115
|
+
function RadioItem(props) {
|
|
116
|
+
const [local, rest] = splitProps(props, [...ITEM, "value"]);
|
|
117
|
+
// An item is its value for as long as it is in the page.
|
|
118
|
+
const value = untrack(() => local.value);
|
|
119
|
+
const options = toSignal(() => ({
|
|
120
|
+
disabled: local.disabled,
|
|
121
|
+
label: local.label,
|
|
122
|
+
closeOnClick: local.closeOnClick,
|
|
123
|
+
}));
|
|
124
|
+
const part = inside(useContext(RadioGroupContext), "RadioGroup").item(value, () => defined(options.get()));
|
|
125
|
+
return (<RadioItemContext.Provider value={value}>
|
|
126
|
+
<Part part={part} tag="div" {...rest}/>
|
|
127
|
+
</RadioItemContext.Provider>);
|
|
128
|
+
}
|
|
129
|
+
function RadioItemIndicator(props) {
|
|
130
|
+
const [local, rest] = splitProps(props, ["keepMounted"]);
|
|
131
|
+
const group = inside(useContext(RadioGroupContext), "RadioGroup");
|
|
132
|
+
const value = useContext(RadioItemContext);
|
|
133
|
+
const checked = fromSignal(group.checked(value));
|
|
134
|
+
return (<Show when={checked() || local.keepMounted}>
|
|
135
|
+
<Part part={group.indicator(value)} tag="span" {...rest}/>
|
|
136
|
+
</Show>);
|
|
137
|
+
}
|
|
138
|
+
const part = (name, tag) => (props) => <Part part={useMenu()[name]} tag={tag} {...props}/>;
|
|
139
|
+
export const Menu = {
|
|
140
|
+
Root,
|
|
141
|
+
Portal,
|
|
142
|
+
Positioner,
|
|
143
|
+
Trigger: part("trigger", "button"),
|
|
144
|
+
Popup: part("popup", "div"),
|
|
145
|
+
Arrow: part("arrow", "div"),
|
|
146
|
+
Item,
|
|
147
|
+
LinkItem,
|
|
148
|
+
Group,
|
|
149
|
+
GroupLabel,
|
|
150
|
+
Separator: part("separator", "div"),
|
|
151
|
+
CheckboxItem,
|
|
152
|
+
CheckboxItemIndicator,
|
|
153
|
+
RadioGroup,
|
|
154
|
+
RadioItem,
|
|
155
|
+
RadioItemIndicator,
|
|
156
|
+
SubmenuRoot,
|
|
157
|
+
SubmenuTrigger: part("trigger", "div"),
|
|
158
|
+
};
|
|
159
|
+
export const ContextMenu = {
|
|
160
|
+
...Menu,
|
|
161
|
+
Root: ContextRoot,
|
|
162
|
+
/** The area a secondary press, or a long press on a touch screen, opens the menu in. */
|
|
163
|
+
Trigger: part("area", "div"),
|
|
164
|
+
};
|
package/src/menubar.jsx
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { within } from "@kirana-ui/core";
|
|
2
|
+
import { createMenubar } from "@kirana-ui/core/menubar";
|
|
3
|
+
import { createUniqueId, splitProps, useContext } from "solid-js";
|
|
4
|
+
import { DirectionContext } from "./direction-context.js";
|
|
5
|
+
import { MenubarContext } from "./menubar-context.js";
|
|
6
|
+
import { Part, controller } from "./runtime.jsx";
|
|
7
|
+
/** A row of menus that work as one. Each `<Menu.Root>` inside it is one of its items. */
|
|
8
|
+
export function Menubar(props) {
|
|
9
|
+
const [local, rest] = splitProps(props, ["loop", "disabled", "orientation", "id"]);
|
|
10
|
+
const generated = createUniqueId();
|
|
11
|
+
const direction = useContext(DirectionContext);
|
|
12
|
+
const made = controller(within(createMenubar, { direction }), () => ({
|
|
13
|
+
id: local.id ?? generated,
|
|
14
|
+
loop: local.loop,
|
|
15
|
+
disabled: local.disabled,
|
|
16
|
+
orientation: local.orientation,
|
|
17
|
+
}));
|
|
18
|
+
return (<MenubarContext.Provider value={made}>
|
|
19
|
+
<Part part={made.root} tag="div" {...rest}/>
|
|
20
|
+
</MenubarContext.Provider>);
|
|
21
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { createMessageScroller } from "@kirana-ui/core/message-scroller";
|
|
2
|
+
import { createContext, createUniqueId, splitProps, useContext } from "solid-js";
|
|
3
|
+
import { Part, controller } from "./runtime.jsx";
|
|
4
|
+
const Context = createContext();
|
|
5
|
+
function useScroller() {
|
|
6
|
+
const made = useContext(Context);
|
|
7
|
+
if (!made)
|
|
8
|
+
throw new Error("A MessageScroller part must be inside <MessageScroller.Root>");
|
|
9
|
+
return made;
|
|
10
|
+
}
|
|
11
|
+
function Root(props) {
|
|
12
|
+
const [local, rest] = splitProps(props, ["initial", "threshold", "onAtBottomChange", "id"]);
|
|
13
|
+
const generated = createUniqueId();
|
|
14
|
+
const made = controller(createMessageScroller, () => ({
|
|
15
|
+
id: local.id ?? generated,
|
|
16
|
+
initial: local.initial,
|
|
17
|
+
threshold: local.threshold,
|
|
18
|
+
onAtBottomChange: (atBottom, details) => local.onAtBottomChange?.(atBottom, details),
|
|
19
|
+
}));
|
|
20
|
+
return (<Context.Provider value={made}>
|
|
21
|
+
<Part part={made.root} tag="div" {...rest}/>
|
|
22
|
+
</Context.Provider>);
|
|
23
|
+
}
|
|
24
|
+
const Viewport = (props) => (<Part part={useScroller().viewport} tag="div" {...props}/>);
|
|
25
|
+
const Content = (props) => (<Part part={useScroller().content} tag="div" {...props}/>);
|
|
26
|
+
const Button = (props) => (<Part part={useScroller().button} tag="button" {...props}/>);
|
|
27
|
+
export const MessageScroller = { Root, Viewport, Content, Button };
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import { defined, within } from "@kirana-ui/core";
|
|
2
|
+
import { createNavigationMenu } from "@kirana-ui/core/navigation-menu";
|
|
3
|
+
import { Show, createContext, createUniqueId, onCleanup, onMount, splitProps, untrack, useContext, } from "solid-js";
|
|
4
|
+
import { DirectionContext } from "./direction-context.js";
|
|
5
|
+
import { positioned } from "./popover.jsx";
|
|
6
|
+
import { Into, Part, Portal as BodyPortal, controller, fromSignal, toSignal } from "./runtime.jsx";
|
|
7
|
+
const Context = createContext();
|
|
8
|
+
const ItemContext = createContext();
|
|
9
|
+
function useNavigation() {
|
|
10
|
+
const made = useContext(Context);
|
|
11
|
+
if (!made)
|
|
12
|
+
throw new Error("A NavigationMenu part must be inside <NavigationMenu.Root>");
|
|
13
|
+
return made;
|
|
14
|
+
}
|
|
15
|
+
function useItem() {
|
|
16
|
+
const item = useContext(ItemContext);
|
|
17
|
+
if (!item)
|
|
18
|
+
throw new Error("A NavigationMenu part must be inside <NavigationMenu.Item>");
|
|
19
|
+
return item;
|
|
20
|
+
}
|
|
21
|
+
function Root(props) {
|
|
22
|
+
const [local, rest] = splitProps(props, [
|
|
23
|
+
"value",
|
|
24
|
+
"defaultValue",
|
|
25
|
+
"onValueChange",
|
|
26
|
+
"delay",
|
|
27
|
+
"closeDelay",
|
|
28
|
+
"orientation",
|
|
29
|
+
"id",
|
|
30
|
+
]);
|
|
31
|
+
const generated = createUniqueId();
|
|
32
|
+
const direction = useContext(DirectionContext);
|
|
33
|
+
const made = controller(within(createNavigationMenu, { direction }), () => ({
|
|
34
|
+
id: local.id ?? generated,
|
|
35
|
+
value: local.value,
|
|
36
|
+
defaultValue: local.defaultValue,
|
|
37
|
+
delay: local.delay,
|
|
38
|
+
closeDelay: local.closeDelay,
|
|
39
|
+
orientation: local.orientation,
|
|
40
|
+
onValueChange: (value, details) => local.onValueChange?.(value, details),
|
|
41
|
+
}));
|
|
42
|
+
return (<Context.Provider value={made}>
|
|
43
|
+
<Part part={made.root} tag="nav" {...rest}/>
|
|
44
|
+
</Context.Provider>);
|
|
45
|
+
}
|
|
46
|
+
/** `value` tells this item from the others; an item that is only a link needs none. */
|
|
47
|
+
function Item(props) {
|
|
48
|
+
const value = untrack(() => props.value);
|
|
49
|
+
if (value === undefined)
|
|
50
|
+
return <li>{props.children}</li>;
|
|
51
|
+
const item = useNavigation().item(value);
|
|
52
|
+
onMount(() => onCleanup(item.mount()));
|
|
53
|
+
return (<ItemContext.Provider value={item}>
|
|
54
|
+
<li>{props.children}</li>
|
|
55
|
+
</ItemContext.Provider>);
|
|
56
|
+
}
|
|
57
|
+
/** An item's content: drawn in `<NavigationMenu.Viewport>`, while it is shown. */
|
|
58
|
+
function Content(props) {
|
|
59
|
+
const item = useItem();
|
|
60
|
+
const mounted = fromSignal(item.mounted);
|
|
61
|
+
const viewport = fromSignal(useNavigation().viewportElement);
|
|
62
|
+
return (<Show when={mounted() ? viewport() : undefined}>
|
|
63
|
+
{(target) => (<Into target={target()}>
|
|
64
|
+
<Part part={item.content} tag="div" {...props}/>
|
|
65
|
+
</Into>)}
|
|
66
|
+
</Show>);
|
|
67
|
+
}
|
|
68
|
+
function Link(props) {
|
|
69
|
+
const [local, rest] = splitProps(props, ["active", "closeOnClick"]);
|
|
70
|
+
const options = toSignal(() => ({ ...local }));
|
|
71
|
+
const part = useNavigation().link(() => defined(options.get()));
|
|
72
|
+
return <Part part={part} tag="a" {...rest}/>;
|
|
73
|
+
}
|
|
74
|
+
const Portal = (props) => (<BodyPortal mounted={useNavigation().mounted}>{props.children}</BodyPortal>);
|
|
75
|
+
function Positioner(props) {
|
|
76
|
+
const made = useNavigation();
|
|
77
|
+
return <Part part={made.positioner} tag="div" {...positioned(props, made.positioning)}/>;
|
|
78
|
+
}
|
|
79
|
+
const part = (name, tag) => (props) => <Part part={useNavigation()[name]} tag={tag} {...props}/>;
|
|
80
|
+
const itemPart = (name, tag) => (props) => (<Part part={useItem()[name]} tag={tag} {...props}/>);
|
|
81
|
+
export const NavigationMenu = {
|
|
82
|
+
Root,
|
|
83
|
+
List: part("list", "ul"),
|
|
84
|
+
Item,
|
|
85
|
+
Trigger: itemPart("trigger", "button"),
|
|
86
|
+
Icon: itemPart("icon", "span"),
|
|
87
|
+
Content,
|
|
88
|
+
Link,
|
|
89
|
+
Portal,
|
|
90
|
+
Positioner,
|
|
91
|
+
Popup: part("popup", "div"),
|
|
92
|
+
Viewport: part("viewport", "div"),
|
|
93
|
+
Arrow: part("arrow", "div"),
|
|
94
|
+
Backdrop: part("backdrop", "div"),
|
|
95
|
+
};
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { within } from "@kirana-ui/core";
|
|
2
|
+
import { createNumberField } from "@kirana-ui/core/number-field";
|
|
3
|
+
import { Show, createContext, createUniqueId, splitProps, useContext } from "solid-js";
|
|
4
|
+
import { FieldContext } from "./field-context.js";
|
|
5
|
+
import { Part, controller, fromSignal } from "./runtime.jsx";
|
|
6
|
+
const Context = createContext();
|
|
7
|
+
function useNumberField() {
|
|
8
|
+
const made = useContext(Context);
|
|
9
|
+
if (!made)
|
|
10
|
+
throw new Error("A NumberField part must be inside <NumberField.Root>");
|
|
11
|
+
return made;
|
|
12
|
+
}
|
|
13
|
+
function Root(props) {
|
|
14
|
+
const [local, rest] = splitProps(props, [
|
|
15
|
+
"value",
|
|
16
|
+
"defaultValue",
|
|
17
|
+
"onValueChange",
|
|
18
|
+
"onValueCommitted",
|
|
19
|
+
"min",
|
|
20
|
+
"max",
|
|
21
|
+
"step",
|
|
22
|
+
"smallStep",
|
|
23
|
+
"largeStep",
|
|
24
|
+
"snapOnStep",
|
|
25
|
+
"allowWheelScrub",
|
|
26
|
+
"format",
|
|
27
|
+
"locale",
|
|
28
|
+
"disabled",
|
|
29
|
+
"readOnly",
|
|
30
|
+
"required",
|
|
31
|
+
"name",
|
|
32
|
+
"form",
|
|
33
|
+
"id",
|
|
34
|
+
"children",
|
|
35
|
+
]);
|
|
36
|
+
const generated = createUniqueId();
|
|
37
|
+
const made = controller(within(createNumberField, { field: useContext(FieldContext) }), () => ({
|
|
38
|
+
id: local.id ?? generated,
|
|
39
|
+
value: local.value,
|
|
40
|
+
defaultValue: local.defaultValue,
|
|
41
|
+
min: local.min,
|
|
42
|
+
max: local.max,
|
|
43
|
+
step: local.step,
|
|
44
|
+
smallStep: local.smallStep,
|
|
45
|
+
largeStep: local.largeStep,
|
|
46
|
+
snapOnStep: local.snapOnStep,
|
|
47
|
+
allowWheelScrub: local.allowWheelScrub,
|
|
48
|
+
format: local.format,
|
|
49
|
+
locale: local.locale,
|
|
50
|
+
disabled: local.disabled,
|
|
51
|
+
readOnly: local.readOnly,
|
|
52
|
+
required: local.required,
|
|
53
|
+
name: local.name,
|
|
54
|
+
form: local.form,
|
|
55
|
+
onValueChange: (value, details) => local.onValueChange?.(value, details),
|
|
56
|
+
onValueCommitted: (value, details) => local.onValueCommitted?.(value, details),
|
|
57
|
+
}));
|
|
58
|
+
const named = fromSignal(made.named);
|
|
59
|
+
return (<Context.Provider value={made}>
|
|
60
|
+
<Part part={made.root} tag="div" {...rest}>
|
|
61
|
+
{local.children}
|
|
62
|
+
<Show when={named()}>
|
|
63
|
+
<Part part={made.hidden} tag="input"/>
|
|
64
|
+
</Show>
|
|
65
|
+
</Part>
|
|
66
|
+
</Context.Provider>);
|
|
67
|
+
}
|
|
68
|
+
const part = (name, tag) => (props) => <Part part={useNumberField()[name]} tag={tag} {...props}/>;
|
|
69
|
+
export const NumberField = {
|
|
70
|
+
Root,
|
|
71
|
+
Group: part("group", "div"),
|
|
72
|
+
Input: part("input", "input"),
|
|
73
|
+
Increment: part("increment", "button"),
|
|
74
|
+
Decrement: part("decrement", "button"),
|
|
75
|
+
};
|
package/src/otp.jsx
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { createOtp } from "@kirana-ui/core/otp";
|
|
2
|
+
import { Show, createContext, createUniqueId, splitProps, untrack, useContext } from "solid-js";
|
|
3
|
+
import { Part, controller, fromSignal } from "./runtime.jsx";
|
|
4
|
+
const Context = createContext();
|
|
5
|
+
const SlotContext = createContext();
|
|
6
|
+
function useOtp() {
|
|
7
|
+
const made = useContext(Context);
|
|
8
|
+
if (!made)
|
|
9
|
+
throw new Error("An Otp part must be inside <Otp.Root>");
|
|
10
|
+
return made;
|
|
11
|
+
}
|
|
12
|
+
function Root(props) {
|
|
13
|
+
const [local, rest] = splitProps(props, [
|
|
14
|
+
"length",
|
|
15
|
+
"value",
|
|
16
|
+
"defaultValue",
|
|
17
|
+
"onValueChange",
|
|
18
|
+
"onComplete",
|
|
19
|
+
"mode",
|
|
20
|
+
"disabled",
|
|
21
|
+
"name",
|
|
22
|
+
"form",
|
|
23
|
+
"id",
|
|
24
|
+
]);
|
|
25
|
+
const generated = createUniqueId();
|
|
26
|
+
const made = controller(createOtp, () => ({
|
|
27
|
+
id: local.id ?? generated,
|
|
28
|
+
length: local.length,
|
|
29
|
+
value: local.value,
|
|
30
|
+
defaultValue: local.defaultValue,
|
|
31
|
+
mode: local.mode,
|
|
32
|
+
disabled: local.disabled,
|
|
33
|
+
name: local.name,
|
|
34
|
+
form: local.form,
|
|
35
|
+
onValueChange: (value, details) => local.onValueChange?.(value, details),
|
|
36
|
+
onComplete: (value) => local.onComplete?.(value),
|
|
37
|
+
}));
|
|
38
|
+
return (<Context.Provider value={made}>
|
|
39
|
+
<Part part={made.root} tag="div" {...rest}/>
|
|
40
|
+
</Context.Provider>);
|
|
41
|
+
}
|
|
42
|
+
/** One cell: it shows its character, then whatever it is given (a caret). */
|
|
43
|
+
function Slot(props) {
|
|
44
|
+
const [local, rest] = splitProps(props, ["index", "children"]);
|
|
45
|
+
const slot = useOtp().slot(untrack(() => local.index));
|
|
46
|
+
const char = fromSignal(slot.char);
|
|
47
|
+
return (<SlotContext.Provider value={slot}>
|
|
48
|
+
<Part part={slot.part} tag="div" {...rest}>
|
|
49
|
+
{char()}
|
|
50
|
+
{local.children}
|
|
51
|
+
</Part>
|
|
52
|
+
</SlotContext.Provider>);
|
|
53
|
+
}
|
|
54
|
+
/** Drawn in its cell while the cell is the active one and empty. */
|
|
55
|
+
function Caret(props) {
|
|
56
|
+
const made = useOtp();
|
|
57
|
+
const slot = useContext(SlotContext);
|
|
58
|
+
if (!slot)
|
|
59
|
+
throw new Error("An Otp.Caret must be inside <Otp.Slot>");
|
|
60
|
+
const shown = fromSignal(slot.caret);
|
|
61
|
+
return (<Show when={shown()}>
|
|
62
|
+
<Part part={made.caretPart} tag="div" {...props}/>
|
|
63
|
+
</Show>);
|
|
64
|
+
}
|
|
65
|
+
const part = (name, tag) => (props) => (<Part part={useOtp()[name]} tag={tag} {...props}/>);
|
|
66
|
+
export const Otp = {
|
|
67
|
+
Root,
|
|
68
|
+
Input: part("input", "input"),
|
|
69
|
+
Group: part("group", "div"),
|
|
70
|
+
Slot,
|
|
71
|
+
Separator: part("separator", "div"),
|
|
72
|
+
Caret,
|
|
73
|
+
};
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { createPagination } from "@kirana-ui/core/pagination";
|
|
2
|
+
import { For, createContext, createUniqueId, splitProps, useContext } from "solid-js";
|
|
3
|
+
import { Part, controller, fromSignal } from "./runtime.jsx";
|
|
4
|
+
const Context = createContext();
|
|
5
|
+
function usePagination() {
|
|
6
|
+
const made = useContext(Context);
|
|
7
|
+
if (!made)
|
|
8
|
+
throw new Error("A Pagination part must be inside <Pagination.Root>");
|
|
9
|
+
return made;
|
|
10
|
+
}
|
|
11
|
+
function Root(props) {
|
|
12
|
+
const [local, rest] = splitProps(props, [
|
|
13
|
+
"page",
|
|
14
|
+
"defaultPage",
|
|
15
|
+
"onPageChange",
|
|
16
|
+
"count",
|
|
17
|
+
"pageSize",
|
|
18
|
+
"siblingCount",
|
|
19
|
+
"boundaryCount",
|
|
20
|
+
"disabled",
|
|
21
|
+
"id",
|
|
22
|
+
]);
|
|
23
|
+
const generated = createUniqueId();
|
|
24
|
+
const made = controller(createPagination, () => ({
|
|
25
|
+
id: local.id ?? generated,
|
|
26
|
+
page: local.page,
|
|
27
|
+
defaultPage: local.defaultPage,
|
|
28
|
+
count: local.count,
|
|
29
|
+
pageSize: local.pageSize,
|
|
30
|
+
siblingCount: local.siblingCount,
|
|
31
|
+
boundaryCount: local.boundaryCount,
|
|
32
|
+
disabled: local.disabled,
|
|
33
|
+
onPageChange: (page, details) => local.onPageChange?.(page, details),
|
|
34
|
+
}));
|
|
35
|
+
return (<Context.Provider value={made}>
|
|
36
|
+
<Part part={made.root} tag="nav" {...rest}/>
|
|
37
|
+
</Context.Provider>);
|
|
38
|
+
}
|
|
39
|
+
/** Draws its child once for each piece of the row: a page, or the mark for pages left out. */
|
|
40
|
+
function Items(props) {
|
|
41
|
+
const entries = fromSignal(usePagination().entries);
|
|
42
|
+
// By key: a page that stays in the row keeps its element.
|
|
43
|
+
const keys = () => entries().map((each) => each.key);
|
|
44
|
+
const of = (key) => entries().find((each) => each.key === key);
|
|
45
|
+
return <For each={keys()}>{(key) => props.children(of(key))}</For>;
|
|
46
|
+
}
|
|
47
|
+
function Item(props) {
|
|
48
|
+
const [local, rest] = splitProps(props, ["page"]);
|
|
49
|
+
const made = usePagination();
|
|
50
|
+
return <Part part={made.item(local.page)} tag="button" {...rest}/>;
|
|
51
|
+
}
|
|
52
|
+
const part = (name, tag) => (props) => (<Part part={usePagination()[name]} tag={tag} {...props}/>);
|
|
53
|
+
export const Pagination = {
|
|
54
|
+
Root,
|
|
55
|
+
Items,
|
|
56
|
+
Item,
|
|
57
|
+
Ellipsis: part("ellipsis", "span"),
|
|
58
|
+
Previous: part("previous", "button"),
|
|
59
|
+
Next: part("next", "button"),
|
|
60
|
+
};
|
package/src/popover.jsx
CHANGED
|
@@ -3,6 +3,8 @@ import { createPopover } from "@kirana-ui/core/popover";
|
|
|
3
3
|
import { createComputed, createContext, createUniqueId, splitProps, useContext } from "solid-js";
|
|
4
4
|
import { Part, Portal as BodyPortal, controller } from "./runtime.jsx";
|
|
5
5
|
const Context = createContext();
|
|
6
|
+
/** For a component made of this one's parts: a date picker. */
|
|
7
|
+
export { Context as PopoverContext };
|
|
6
8
|
function usePopover() {
|
|
7
9
|
const made = useContext(Context);
|
|
8
10
|
if (!made)
|
package/src/qr-code.jsx
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { createQrCode } from "@kirana-ui/core/qr-code";
|
|
2
|
+
import { createContext, createUniqueId, splitProps, useContext } from "solid-js";
|
|
3
|
+
import { Part, controller } from "./runtime.jsx";
|
|
4
|
+
const Context = createContext();
|
|
5
|
+
function useQrCode() {
|
|
6
|
+
const made = useContext(Context);
|
|
7
|
+
if (!made)
|
|
8
|
+
throw new Error("A QrCode part must be inside <QrCode.Root>");
|
|
9
|
+
return made;
|
|
10
|
+
}
|
|
11
|
+
function Root(props) {
|
|
12
|
+
const [local, rest] = splitProps(props, ["value", "correction", "id"]);
|
|
13
|
+
const generated = createUniqueId();
|
|
14
|
+
const made = controller(createQrCode, () => ({
|
|
15
|
+
id: local.id ?? generated,
|
|
16
|
+
value: local.value,
|
|
17
|
+
correction: local.correction,
|
|
18
|
+
}));
|
|
19
|
+
return (<Context.Provider value={made}>
|
|
20
|
+
<Part part={made.root} tag="div" {...rest}/>
|
|
21
|
+
</Context.Provider>);
|
|
22
|
+
}
|
|
23
|
+
const Frame = (props) => <Part part={useQrCode().frame} tag="svg" {...props}/>;
|
|
24
|
+
const Pattern = (props) => (<Part part={useQrCode().pattern} tag="path" {...props}/>);
|
|
25
|
+
export const QrCode = { Root, Frame, Pattern };
|
package/src/radio-group.jsx
CHANGED
|
@@ -21,6 +21,7 @@ function Root(props) {
|
|
|
21
21
|
"readOnly",
|
|
22
22
|
"required",
|
|
23
23
|
"name",
|
|
24
|
+
"form",
|
|
24
25
|
"id",
|
|
25
26
|
]);
|
|
26
27
|
const generated = createUniqueId();
|
|
@@ -33,6 +34,7 @@ function Root(props) {
|
|
|
33
34
|
readOnly: local.readOnly,
|
|
34
35
|
required: local.required,
|
|
35
36
|
name: local.name,
|
|
37
|
+
form: local.form,
|
|
36
38
|
onValueChange: (value, details) => local.onValueChange?.(value, details),
|
|
37
39
|
}));
|
|
38
40
|
return (<Context.Provider value={made}>
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { defined, within } from "@kirana-ui/core";
|
|
2
|
+
import { createResizable } from "@kirana-ui/core/resizable";
|
|
3
|
+
import { createContext, createUniqueId, splitProps, useContext } from "solid-js";
|
|
4
|
+
import { DirectionContext } from "./direction-context.js";
|
|
5
|
+
import { Part, controller, toSignal } from "./runtime.jsx";
|
|
6
|
+
const Context = createContext();
|
|
7
|
+
function useResizable() {
|
|
8
|
+
const made = useContext(Context);
|
|
9
|
+
if (!made)
|
|
10
|
+
throw new Error("A Resizable part must be inside <Resizable.Group>");
|
|
11
|
+
return made;
|
|
12
|
+
}
|
|
13
|
+
function Group(props) {
|
|
14
|
+
const [local, rest] = splitProps(props, [
|
|
15
|
+
"orientation",
|
|
16
|
+
"onSizesChange",
|
|
17
|
+
"keyboardStep",
|
|
18
|
+
"disabled",
|
|
19
|
+
"id",
|
|
20
|
+
]);
|
|
21
|
+
const generated = createUniqueId();
|
|
22
|
+
const direction = useContext(DirectionContext);
|
|
23
|
+
const made = controller(within(createResizable, { direction }), () => ({
|
|
24
|
+
id: local.id ?? generated,
|
|
25
|
+
orientation: local.orientation,
|
|
26
|
+
keyboardStep: local.keyboardStep,
|
|
27
|
+
disabled: local.disabled,
|
|
28
|
+
onSizesChange: (sizes, details) => local.onSizesChange?.(sizes, details),
|
|
29
|
+
}));
|
|
30
|
+
return (<Context.Provider value={made}>
|
|
31
|
+
<Part part={made.group} tag="div" {...rest}/>
|
|
32
|
+
</Context.Provider>);
|
|
33
|
+
}
|
|
34
|
+
function Panel(props) {
|
|
35
|
+
const [local, rest] = splitProps(props, ["defaultSize", "minSize", "maxSize"]);
|
|
36
|
+
const options = toSignal(() => ({ ...local }));
|
|
37
|
+
const part = useResizable().panel(() => defined(options.get()));
|
|
38
|
+
return <Part part={part} tag="div" {...rest}/>;
|
|
39
|
+
}
|
|
40
|
+
function Handle(props) {
|
|
41
|
+
const [local, rest] = splitProps(props, ["disabled"]);
|
|
42
|
+
const options = toSignal(() => ({ disabled: local.disabled }));
|
|
43
|
+
const part = useResizable().handle(() => defined(options.get()));
|
|
44
|
+
return <Part part={part} tag="div" {...rest}/>;
|
|
45
|
+
}
|
|
46
|
+
export const Resizable = { Group, Panel, Handle };
|
package/src/runtime.jsx
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { mergeProps, sameProps, signal } from "@kirana-ui/core";
|
|
2
|
-
import { Show, createComputed, createMemo, createSignal, getOwner, onCleanup, onMount, runWithOwner, splitProps, untrack, } from "solid-js";
|
|
2
|
+
import { Show, children, createComputed, createContext, createRenderEffect, createMemo, createSignal, getOwner, onCleanup, onMount, runWithOwner, splitProps, untrack, useContext, } from "solid-js";
|
|
3
3
|
import { Dynamic, Portal as SolidPortal, isServer } from "solid-js/web";
|
|
4
4
|
/** A core signal as a Solid accessor: tracked by whatever calls it. */
|
|
5
5
|
export function fromSignal(source) {
|
|
@@ -77,11 +77,42 @@ export function Part(props) {
|
|
|
77
77
|
{(render) => render()(merged)}
|
|
78
78
|
</Show>);
|
|
79
79
|
}
|
|
80
|
+
/**
|
|
81
|
+
* Its children as children of `target`, an element drawn elsewhere: with no element of its own
|
|
82
|
+
* around them (Solid's `Portal` adds one), so the page is the same as on the other adapters.
|
|
83
|
+
*/
|
|
84
|
+
export function Into(props) {
|
|
85
|
+
const resolved = children(() => props.children);
|
|
86
|
+
// Before any mount work of the children: their elements are in the page by then.
|
|
87
|
+
createRenderEffect(() => {
|
|
88
|
+
const target = props.target;
|
|
89
|
+
const nodes = resolved.toArray().filter((each) => each instanceof Node);
|
|
90
|
+
for (const node of nodes)
|
|
91
|
+
target.appendChild(node);
|
|
92
|
+
onCleanup(() => {
|
|
93
|
+
for (const node of nodes)
|
|
94
|
+
if (node.parentNode === target)
|
|
95
|
+
target.removeChild(node);
|
|
96
|
+
});
|
|
97
|
+
});
|
|
98
|
+
return null;
|
|
99
|
+
}
|
|
100
|
+
const PortalContainer = createContext();
|
|
101
|
+
/**
|
|
102
|
+
* Says where every popup inside it is drawn, the popups those open included: an element of
|
|
103
|
+
* the page (a shadow root's host, a full-screen element) in place of `<body>`.
|
|
104
|
+
*/
|
|
105
|
+
export function PortalProvider(props) {
|
|
106
|
+
return (<PortalContainer.Provider value={() => props.container}>
|
|
107
|
+
{props.children}
|
|
108
|
+
</PortalContainer.Provider>);
|
|
109
|
+
}
|
|
80
110
|
/** Its children in a container at the end of the page, while `mounted`. */
|
|
81
111
|
export function Portal(props) {
|
|
82
112
|
const shown = fromSignal(untrack(() => props.mounted));
|
|
113
|
+
const container = useContext(PortalContainer);
|
|
83
114
|
return (<Show when={shown()}>
|
|
84
|
-
<SolidPortal ref={(
|
|
115
|
+
<SolidPortal mount={container?.() ?? undefined} ref={(outlet) => outlet.setAttribute("data-kirana-portal", "")}>
|
|
85
116
|
{props.children}
|
|
86
117
|
</SolidPortal>
|
|
87
118
|
</Show>);
|