@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
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { createComponent as _$createComponent } from "solid-js/web";
|
|
2
|
+
import { mergeProps as _$mergeProps } from "solid-js/web";
|
|
3
|
+
import { createPagination } from "@kirana-ui/core/pagination";
|
|
4
|
+
import { For, createContext, createUniqueId, splitProps, useContext } from "solid-js";
|
|
5
|
+
import { Part, controller, fromSignal } from "./runtime.js";
|
|
6
|
+
const Context = createContext();
|
|
7
|
+
function usePagination() {
|
|
8
|
+
const made = useContext(Context);
|
|
9
|
+
if (!made) throw new Error("A Pagination part must be inside <Pagination.Root>");
|
|
10
|
+
return made;
|
|
11
|
+
}
|
|
12
|
+
function Root(props) {
|
|
13
|
+
const [local, rest] = splitProps(props, ["page", "defaultPage", "onPageChange", "count", "pageSize", "siblingCount", "boundaryCount", "disabled", "id"]);
|
|
14
|
+
const generated = createUniqueId();
|
|
15
|
+
const made = controller(createPagination, () => ({
|
|
16
|
+
id: local.id ?? generated,
|
|
17
|
+
page: local.page,
|
|
18
|
+
defaultPage: local.defaultPage,
|
|
19
|
+
count: local.count,
|
|
20
|
+
pageSize: local.pageSize,
|
|
21
|
+
siblingCount: local.siblingCount,
|
|
22
|
+
boundaryCount: local.boundaryCount,
|
|
23
|
+
disabled: local.disabled,
|
|
24
|
+
onPageChange: (page, details) => local.onPageChange?.(page, 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: "nav"
|
|
34
|
+
}, rest));
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
/** Draws its child once for each piece of the row: a page, or the mark for pages left out. */
|
|
39
|
+
function Items(props) {
|
|
40
|
+
const entries = fromSignal(usePagination().entries);
|
|
41
|
+
// By key: a page that stays in the row keeps its element.
|
|
42
|
+
const keys = () => entries().map(each => each.key);
|
|
43
|
+
const of = key => entries().find(each => each.key === key);
|
|
44
|
+
return _$createComponent(For, {
|
|
45
|
+
get each() {
|
|
46
|
+
return keys();
|
|
47
|
+
},
|
|
48
|
+
children: key => props.children(of(key))
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
function Item(props) {
|
|
52
|
+
const [local, rest] = splitProps(props, ["page"]);
|
|
53
|
+
const made = usePagination();
|
|
54
|
+
return _$createComponent(Part, _$mergeProps({
|
|
55
|
+
get part() {
|
|
56
|
+
return made.item(local.page);
|
|
57
|
+
},
|
|
58
|
+
tag: "button"
|
|
59
|
+
}, rest));
|
|
60
|
+
}
|
|
61
|
+
const part = (name, tag) => props => _$createComponent(Part, _$mergeProps({
|
|
62
|
+
get part() {
|
|
63
|
+
return usePagination()[name];
|
|
64
|
+
},
|
|
65
|
+
tag: tag
|
|
66
|
+
}, props));
|
|
67
|
+
export const Pagination = {
|
|
68
|
+
Root,
|
|
69
|
+
Items,
|
|
70
|
+
Item,
|
|
71
|
+
Ellipsis: part("ellipsis", "span"),
|
|
72
|
+
Previous: part("previous", "button"),
|
|
73
|
+
Next: part("next", "button")
|
|
74
|
+
};
|
package/dom/popover.js
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { mergeProps as _$mergeProps } from "solid-js/web";
|
|
2
|
+
import { createComponent as _$createComponent } from "solid-js/web";
|
|
3
|
+
import { defined } from "@kirana-ui/core";
|
|
4
|
+
import { createPopover } from "@kirana-ui/core/popover";
|
|
5
|
+
import { createComputed, createContext, createUniqueId, splitProps, useContext } from "solid-js";
|
|
6
|
+
import { Part, Portal as BodyPortal, controller } from "./runtime.js";
|
|
7
|
+
const Context = createContext();
|
|
8
|
+
/** For a component made of this one's parts: a date picker. */
|
|
9
|
+
export { Context as PopoverContext };
|
|
10
|
+
function usePopover() {
|
|
11
|
+
const made = useContext(Context);
|
|
12
|
+
if (!made) throw new Error("A Popover part must be inside <Popover.Root>");
|
|
13
|
+
return made;
|
|
14
|
+
}
|
|
15
|
+
function Root(props) {
|
|
16
|
+
const generated = createUniqueId();
|
|
17
|
+
const made = controller(createPopover, () => ({
|
|
18
|
+
id: props.id ?? generated,
|
|
19
|
+
open: props.open,
|
|
20
|
+
defaultOpen: props.defaultOpen,
|
|
21
|
+
onOpenChange: (open, details) => props.onOpenChange?.(open, details)
|
|
22
|
+
}));
|
|
23
|
+
return _$createComponent(Context.Provider, {
|
|
24
|
+
value: made,
|
|
25
|
+
get children() {
|
|
26
|
+
return props.children;
|
|
27
|
+
}
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
const Portal = props => _$createComponent(BodyPortal, {
|
|
31
|
+
get mounted() {
|
|
32
|
+
return usePopover().mounted;
|
|
33
|
+
},
|
|
34
|
+
get children() {
|
|
35
|
+
return props.children;
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
/** A positioner's own props, written where its placement reads them, before its element attaches. */
|
|
39
|
+
export function positioned(props, positioning) {
|
|
40
|
+
const [local, rest] = splitProps(props, ["side", "align", "sideOffset", "alignOffset", "collisionPadding"]);
|
|
41
|
+
createComputed(() => positioning.set(defined({
|
|
42
|
+
...local
|
|
43
|
+
})));
|
|
44
|
+
return rest;
|
|
45
|
+
}
|
|
46
|
+
function Positioner(props) {
|
|
47
|
+
const made = usePopover();
|
|
48
|
+
return _$createComponent(Part, _$mergeProps({
|
|
49
|
+
get part() {
|
|
50
|
+
return made.positioner;
|
|
51
|
+
},
|
|
52
|
+
tag: "div"
|
|
53
|
+
}, () => positioned(props, made.positioning)));
|
|
54
|
+
}
|
|
55
|
+
const part = (name, tag) => props => _$createComponent(Part, _$mergeProps({
|
|
56
|
+
get part() {
|
|
57
|
+
return usePopover()[name];
|
|
58
|
+
},
|
|
59
|
+
tag: tag
|
|
60
|
+
}, props));
|
|
61
|
+
export const Popover = {
|
|
62
|
+
Root,
|
|
63
|
+
Portal,
|
|
64
|
+
Positioner,
|
|
65
|
+
Trigger: part("trigger", "button"),
|
|
66
|
+
Popup: part("popup", "div"),
|
|
67
|
+
Title: part("title", "h2"),
|
|
68
|
+
Description: part("description", "p"),
|
|
69
|
+
Close: part("close", "button")
|
|
70
|
+
};
|
package/dom/progress.js
ADDED
package/dom/qr-code.js
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { createComponent as _$createComponent } from "solid-js/web";
|
|
2
|
+
import { mergeProps as _$mergeProps } from "solid-js/web";
|
|
3
|
+
import { createQrCode } from "@kirana-ui/core/qr-code";
|
|
4
|
+
import { createContext, createUniqueId, splitProps, useContext } from "solid-js";
|
|
5
|
+
import { Part, controller } from "./runtime.js";
|
|
6
|
+
const Context = createContext();
|
|
7
|
+
function useQrCode() {
|
|
8
|
+
const made = useContext(Context);
|
|
9
|
+
if (!made) throw new Error("A QrCode part must be inside <QrCode.Root>");
|
|
10
|
+
return made;
|
|
11
|
+
}
|
|
12
|
+
function Root(props) {
|
|
13
|
+
const [local, rest] = splitProps(props, ["value", "correction", "id"]);
|
|
14
|
+
const generated = createUniqueId();
|
|
15
|
+
const made = controller(createQrCode, () => ({
|
|
16
|
+
id: local.id ?? generated,
|
|
17
|
+
value: local.value,
|
|
18
|
+
correction: local.correction
|
|
19
|
+
}));
|
|
20
|
+
return _$createComponent(Context.Provider, {
|
|
21
|
+
value: made,
|
|
22
|
+
get children() {
|
|
23
|
+
return _$createComponent(Part, _$mergeProps({
|
|
24
|
+
get part() {
|
|
25
|
+
return made.root;
|
|
26
|
+
},
|
|
27
|
+
tag: "div"
|
|
28
|
+
}, rest));
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
const Frame = props => _$createComponent(Part, _$mergeProps({
|
|
33
|
+
get part() {
|
|
34
|
+
return useQrCode().frame;
|
|
35
|
+
},
|
|
36
|
+
tag: "svg"
|
|
37
|
+
}, props));
|
|
38
|
+
const Pattern = props => _$createComponent(Part, _$mergeProps({
|
|
39
|
+
get part() {
|
|
40
|
+
return useQrCode().pattern;
|
|
41
|
+
},
|
|
42
|
+
tag: "path"
|
|
43
|
+
}, props));
|
|
44
|
+
export const QrCode = {
|
|
45
|
+
Root,
|
|
46
|
+
Frame,
|
|
47
|
+
Pattern
|
|
48
|
+
};
|
|
@@ -0,0 +1,101 @@
|
|
|
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 { defined, within } from "@kirana-ui/core";
|
|
5
|
+
import { createRadioGroup } from "@kirana-ui/core/radio-group";
|
|
6
|
+
import { Show, createContext, createUniqueId, onCleanup, onMount, splitProps, untrack, useContext } from "solid-js";
|
|
7
|
+
import { DirectionContext } from "./direction-context.js";
|
|
8
|
+
import { FieldContext } from "./field-context.js";
|
|
9
|
+
import { Part, controller, fromSignal, toSignal } from "./runtime.js";
|
|
10
|
+
const Context = createContext();
|
|
11
|
+
const ItemContext = createContext();
|
|
12
|
+
function useRadioGroup() {
|
|
13
|
+
const made = useContext(Context);
|
|
14
|
+
if (!made) throw new Error("A RadioGroup part must be inside <RadioGroup.Root>");
|
|
15
|
+
return made;
|
|
16
|
+
}
|
|
17
|
+
function Root(props) {
|
|
18
|
+
const [local, rest] = splitProps(props, ["value", "defaultValue", "onValueChange", "disabled", "readOnly", "required", "name", "form", "id"]);
|
|
19
|
+
const generated = createUniqueId();
|
|
20
|
+
const field = useContext(FieldContext);
|
|
21
|
+
const made = controller(within(createRadioGroup, {
|
|
22
|
+
field,
|
|
23
|
+
direction: useContext(DirectionContext)
|
|
24
|
+
}), () => ({
|
|
25
|
+
id: local.id ?? generated,
|
|
26
|
+
value: local.value,
|
|
27
|
+
defaultValue: local.defaultValue,
|
|
28
|
+
disabled: local.disabled,
|
|
29
|
+
readOnly: local.readOnly,
|
|
30
|
+
required: local.required,
|
|
31
|
+
name: local.name,
|
|
32
|
+
form: local.form,
|
|
33
|
+
onValueChange: (value, details) => local.onValueChange?.(value, details)
|
|
34
|
+
}));
|
|
35
|
+
return _$createComponent(Context.Provider, {
|
|
36
|
+
value: made,
|
|
37
|
+
get children() {
|
|
38
|
+
return _$createComponent(Part, _$mergeProps({
|
|
39
|
+
get part() {
|
|
40
|
+
return made.root;
|
|
41
|
+
},
|
|
42
|
+
tag: "div"
|
|
43
|
+
}, rest));
|
|
44
|
+
}
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
function Item(props) {
|
|
48
|
+
const [local, rest] = splitProps(props, ["value", "disabled", "children"]);
|
|
49
|
+
// An item is its value for as long as it is in the page.
|
|
50
|
+
const value = untrack(() => local.value);
|
|
51
|
+
const options = toSignal(() => ({
|
|
52
|
+
disabled: local.disabled
|
|
53
|
+
}));
|
|
54
|
+
const read = () => defined(options.get());
|
|
55
|
+
const group = useRadioGroup();
|
|
56
|
+
return _$createComponent(ItemContext.Provider, {
|
|
57
|
+
value: value,
|
|
58
|
+
get children() {
|
|
59
|
+
return _$createComponent(Part, _$mergeProps({
|
|
60
|
+
get part() {
|
|
61
|
+
return group.item(value, read);
|
|
62
|
+
},
|
|
63
|
+
tag: "span"
|
|
64
|
+
}, rest, {
|
|
65
|
+
get children() {
|
|
66
|
+
return [_$memo(() => local.children), _$createComponent(Part, {
|
|
67
|
+
get part() {
|
|
68
|
+
return group.itemInput(value, read);
|
|
69
|
+
},
|
|
70
|
+
tag: "input"
|
|
71
|
+
})];
|
|
72
|
+
}
|
|
73
|
+
}));
|
|
74
|
+
}
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
/** `keepMounted` keeps the mark in the page while its item is not the chosen one. */
|
|
78
|
+
function Indicator(props) {
|
|
79
|
+
const [local, rest] = splitProps(props, ["keepMounted"]);
|
|
80
|
+
const indicator = useRadioGroup().indicator(useContext(ItemContext));
|
|
81
|
+
onMount(() => onCleanup(indicator.mount()));
|
|
82
|
+
const mounted = fromSignal(indicator.mounted);
|
|
83
|
+
return _$createComponent(Show, {
|
|
84
|
+
get when() {
|
|
85
|
+
return mounted() || local.keepMounted;
|
|
86
|
+
},
|
|
87
|
+
get children() {
|
|
88
|
+
return _$createComponent(Part, _$mergeProps({
|
|
89
|
+
get part() {
|
|
90
|
+
return indicator.part;
|
|
91
|
+
},
|
|
92
|
+
tag: "span"
|
|
93
|
+
}, rest));
|
|
94
|
+
}
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
export const RadioGroup = {
|
|
98
|
+
Root,
|
|
99
|
+
Item,
|
|
100
|
+
Indicator
|
|
101
|
+
};
|
package/dom/resizable.js
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { createComponent as _$createComponent } from "solid-js/web";
|
|
2
|
+
import { mergeProps as _$mergeProps } from "solid-js/web";
|
|
3
|
+
import { defined, within } from "@kirana-ui/core";
|
|
4
|
+
import { createResizable } from "@kirana-ui/core/resizable";
|
|
5
|
+
import { createContext, createUniqueId, splitProps, useContext } from "solid-js";
|
|
6
|
+
import { DirectionContext } from "./direction-context.js";
|
|
7
|
+
import { Part, controller, toSignal } from "./runtime.js";
|
|
8
|
+
const Context = createContext();
|
|
9
|
+
function useResizable() {
|
|
10
|
+
const made = useContext(Context);
|
|
11
|
+
if (!made) throw new Error("A Resizable part must be inside <Resizable.Group>");
|
|
12
|
+
return made;
|
|
13
|
+
}
|
|
14
|
+
function Group(props) {
|
|
15
|
+
const [local, rest] = splitProps(props, ["orientation", "onSizesChange", "keyboardStep", "disabled", "id"]);
|
|
16
|
+
const generated = createUniqueId();
|
|
17
|
+
const direction = useContext(DirectionContext);
|
|
18
|
+
const made = controller(within(createResizable, {
|
|
19
|
+
direction
|
|
20
|
+
}), () => ({
|
|
21
|
+
id: local.id ?? generated,
|
|
22
|
+
orientation: local.orientation,
|
|
23
|
+
keyboardStep: local.keyboardStep,
|
|
24
|
+
disabled: local.disabled,
|
|
25
|
+
onSizesChange: (sizes, details) => local.onSizesChange?.(sizes, details)
|
|
26
|
+
}));
|
|
27
|
+
return _$createComponent(Context.Provider, {
|
|
28
|
+
value: made,
|
|
29
|
+
get children() {
|
|
30
|
+
return _$createComponent(Part, _$mergeProps({
|
|
31
|
+
get part() {
|
|
32
|
+
return made.group;
|
|
33
|
+
},
|
|
34
|
+
tag: "div"
|
|
35
|
+
}, rest));
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
function Panel(props) {
|
|
40
|
+
const [local, rest] = splitProps(props, ["defaultSize", "minSize", "maxSize"]);
|
|
41
|
+
const options = toSignal(() => ({
|
|
42
|
+
...local
|
|
43
|
+
}));
|
|
44
|
+
const part = useResizable().panel(() => defined(options.get()));
|
|
45
|
+
return _$createComponent(Part, _$mergeProps({
|
|
46
|
+
part: part,
|
|
47
|
+
tag: "div"
|
|
48
|
+
}, rest));
|
|
49
|
+
}
|
|
50
|
+
function Handle(props) {
|
|
51
|
+
const [local, rest] = splitProps(props, ["disabled"]);
|
|
52
|
+
const options = toSignal(() => ({
|
|
53
|
+
disabled: local.disabled
|
|
54
|
+
}));
|
|
55
|
+
const part = useResizable().handle(() => defined(options.get()));
|
|
56
|
+
return _$createComponent(Part, _$mergeProps({
|
|
57
|
+
part: part,
|
|
58
|
+
tag: "div"
|
|
59
|
+
}, rest));
|
|
60
|
+
}
|
|
61
|
+
export const Resizable = {
|
|
62
|
+
Group,
|
|
63
|
+
Panel,
|
|
64
|
+
Handle
|
|
65
|
+
};
|
package/dom/runtime.js
ADDED
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
import { mergeProps as _$mergeProps } from "solid-js/web";
|
|
2
|
+
import { memo as _$memo } from "solid-js/web";
|
|
3
|
+
import { createComponent as _$createComponent } from "solid-js/web";
|
|
4
|
+
import { mergeProps, sameProps, signal } from "@kirana-ui/core";
|
|
5
|
+
import { Show, children, createComputed, createContext, createRenderEffect, createMemo, createSignal, getOwner, onCleanup, onMount, runWithOwner, splitProps, untrack, useContext } from "solid-js";
|
|
6
|
+
import { Dynamic, Portal as SolidPortal, isServer } from "solid-js/web";
|
|
7
|
+
/** A core signal as a Solid accessor: tracked by whatever calls it. */
|
|
8
|
+
export function fromSignal(source) {
|
|
9
|
+
const [read, write] = createSignal(source.peek(), {
|
|
10
|
+
equals: false
|
|
11
|
+
});
|
|
12
|
+
if (!isServer) onCleanup(source.subscribe(() => write(() => source.peek())));
|
|
13
|
+
return read;
|
|
14
|
+
}
|
|
15
|
+
/** A core signal that follows Solid state: the core hears a changed prop before anything renders. */
|
|
16
|
+
export function toSignal(read) {
|
|
17
|
+
const source = signal(untrack(read), sameProps);
|
|
18
|
+
createComputed(() => source.set(read()));
|
|
19
|
+
return source;
|
|
20
|
+
}
|
|
21
|
+
/** A component's controller, made once, following its props. */
|
|
22
|
+
export function controller(create, read) {
|
|
23
|
+
const made = create(toSignal(read));
|
|
24
|
+
onMount(() => onCleanup(made.mount()));
|
|
25
|
+
return made;
|
|
26
|
+
}
|
|
27
|
+
// HTML's boolean attributes, which Solid sets as properties: a part's `""` means "present".
|
|
28
|
+
const BOOLEAN = new Set(["hidden", "disabled", "inert", "required", "readonly", "multiple", "checked", "novalidate"]);
|
|
29
|
+
function toSolid(props) {
|
|
30
|
+
const out = {};
|
|
31
|
+
for (const key in props) {
|
|
32
|
+
const value = props[key];
|
|
33
|
+
// Solid's `onFocus` and `onBlur` do not bubble; the core's are the ones that do.
|
|
34
|
+
if (key === "onFocus") out.onFocusIn = value;else if (key === "onBlur") out.onFocusOut = value;else out[key] = BOOLEAN.has(key) ? value === "" || value === true : value;
|
|
35
|
+
}
|
|
36
|
+
return out;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* A part's element (or the caller's, through `render`), with the caller's props merged under the
|
|
40
|
+
* part's and the part's DOM work attached once the element is in the page.
|
|
41
|
+
*/
|
|
42
|
+
export function Part(props) {
|
|
43
|
+
const [local, caller] = splitProps(props, ["part", "tag", "as", "render", "children"]);
|
|
44
|
+
const own = fromSignal(untrack(() => local.part).props);
|
|
45
|
+
// Solid hands over an element before it is in the page: the part's DOM work (focus, measures,
|
|
46
|
+
// the starting style) waits for the mount that follows. It belongs to this component, not to
|
|
47
|
+
// the effect that spreads the props (which hands the ref over again, and is torn down, each time
|
|
48
|
+
// they change): attached once per element, detached when the component goes.
|
|
49
|
+
const owner = getOwner();
|
|
50
|
+
let attached;
|
|
51
|
+
const attach = element => {
|
|
52
|
+
if (element === attached) return;
|
|
53
|
+
attached = element;
|
|
54
|
+
const part = untrack(() => local.part);
|
|
55
|
+
runWithOwner(owner, () => onMount(() => onCleanup(part.attach(element))));
|
|
56
|
+
};
|
|
57
|
+
const merged = createMemo(() => {
|
|
58
|
+
const theirs = {};
|
|
59
|
+
for (const key of Object.keys(caller)) theirs[key] = caller[key];
|
|
60
|
+
return {
|
|
61
|
+
...mergeProps(theirs, toSolid(own())),
|
|
62
|
+
ref: attach
|
|
63
|
+
};
|
|
64
|
+
});
|
|
65
|
+
return _$createComponent(Show, {
|
|
66
|
+
get when() {
|
|
67
|
+
return local.render;
|
|
68
|
+
},
|
|
69
|
+
get fallback() {
|
|
70
|
+
return _$createComponent(Dynamic, _$mergeProps({
|
|
71
|
+
get component() {
|
|
72
|
+
return local.as ?? local.tag;
|
|
73
|
+
}
|
|
74
|
+
}, merged, {
|
|
75
|
+
get children() {
|
|
76
|
+
return local.children;
|
|
77
|
+
}
|
|
78
|
+
}));
|
|
79
|
+
},
|
|
80
|
+
children: render => render()(merged)
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Its children as children of `target`, an element drawn elsewhere: with no element of its own
|
|
85
|
+
* around them (Solid's `Portal` adds one), so the page is the same as on the other adapters.
|
|
86
|
+
*/
|
|
87
|
+
export function Into(props) {
|
|
88
|
+
const resolved = children(() => props.children);
|
|
89
|
+
// Before any mount work of the children: their elements are in the page by then.
|
|
90
|
+
createRenderEffect(() => {
|
|
91
|
+
const target = props.target;
|
|
92
|
+
const nodes = resolved.toArray().filter(each => each instanceof Node);
|
|
93
|
+
for (const node of nodes) target.appendChild(node);
|
|
94
|
+
onCleanup(() => {
|
|
95
|
+
for (const node of nodes) if (node.parentNode === target) 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 _$createComponent(PortalContainer.Provider, {
|
|
107
|
+
value: () => props.container,
|
|
108
|
+
get children() {
|
|
109
|
+
return props.children;
|
|
110
|
+
}
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
/** Its children in a container at the end of the page, while `mounted`. */
|
|
114
|
+
export function Portal(props) {
|
|
115
|
+
const shown = fromSignal(untrack(() => props.mounted));
|
|
116
|
+
const container = useContext(PortalContainer);
|
|
117
|
+
return _$createComponent(Show, {
|
|
118
|
+
get when() {
|
|
119
|
+
return shown();
|
|
120
|
+
},
|
|
121
|
+
get children() {
|
|
122
|
+
return _$createComponent(SolidPortal, {
|
|
123
|
+
get mount() {
|
|
124
|
+
return container?.() ?? undefined;
|
|
125
|
+
},
|
|
126
|
+
ref: outlet => outlet.setAttribute("data-kirana-portal", ""),
|
|
127
|
+
get children() {
|
|
128
|
+
return props.children;
|
|
129
|
+
}
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
});
|
|
133
|
+
}
|
|
@@ -0,0 +1,99 @@
|
|
|
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 { within } from "@kirana-ui/core";
|
|
5
|
+
import { createScrollArea } from "@kirana-ui/core/scroll-area";
|
|
6
|
+
import { Show, createContext, splitProps, untrack, useContext } from "solid-js";
|
|
7
|
+
import { DirectionContext } from "./direction-context.js";
|
|
8
|
+
import { Part, controller, fromSignal } from "./runtime.js";
|
|
9
|
+
const Context = createContext();
|
|
10
|
+
const ScrollbarContext = createContext();
|
|
11
|
+
function useScrollArea() {
|
|
12
|
+
const made = useContext(Context);
|
|
13
|
+
if (!made) throw new Error("A ScrollArea part must be inside <ScrollArea.Root>");
|
|
14
|
+
return made;
|
|
15
|
+
}
|
|
16
|
+
function Root(props) {
|
|
17
|
+
const direction = useContext(DirectionContext);
|
|
18
|
+
const made = controller(within(createScrollArea, {
|
|
19
|
+
direction
|
|
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
|
+
}, props));
|
|
30
|
+
}
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
/** `orientation` is which way it scrolls (`vertical` by default). */
|
|
34
|
+
function Scrollbar(props) {
|
|
35
|
+
const [local, rest] = splitProps(props, ["orientation", "keepMounted"]);
|
|
36
|
+
const bar = useScrollArea().scrollbar(untrack(() => local.orientation) ?? "vertical");
|
|
37
|
+
const shown = fromSignal(bar.shown);
|
|
38
|
+
return _$createComponent(ScrollbarContext.Provider, {
|
|
39
|
+
value: bar,
|
|
40
|
+
get children() {
|
|
41
|
+
return _$createComponent(Show, {
|
|
42
|
+
get when() {
|
|
43
|
+
return shown() || local.keepMounted;
|
|
44
|
+
},
|
|
45
|
+
get children() {
|
|
46
|
+
return _$createComponent(Part, _$mergeProps({
|
|
47
|
+
get part() {
|
|
48
|
+
return bar.part;
|
|
49
|
+
},
|
|
50
|
+
tag: "div"
|
|
51
|
+
}, rest));
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
function Thumb(props) {
|
|
58
|
+
const bar = useContext(ScrollbarContext);
|
|
59
|
+
if (!bar) throw new Error("A ScrollArea.Thumb must be inside <ScrollArea.Scrollbar>");
|
|
60
|
+
return _$createComponent(Part, _$mergeProps({
|
|
61
|
+
get part() {
|
|
62
|
+
return bar.thumb;
|
|
63
|
+
},
|
|
64
|
+
tag: "div"
|
|
65
|
+
}, props));
|
|
66
|
+
}
|
|
67
|
+
function Corner(props) {
|
|
68
|
+
const {
|
|
69
|
+
corner
|
|
70
|
+
} = useScrollArea();
|
|
71
|
+
const shown = fromSignal(corner.shown);
|
|
72
|
+
return _$createComponent(Show, {
|
|
73
|
+
get when() {
|
|
74
|
+
return shown();
|
|
75
|
+
},
|
|
76
|
+
get children() {
|
|
77
|
+
return _$createComponent(Part, _$mergeProps({
|
|
78
|
+
get part() {
|
|
79
|
+
return corner.part;
|
|
80
|
+
},
|
|
81
|
+
tag: "div"
|
|
82
|
+
}, props));
|
|
83
|
+
}
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
const part = name => props => _$createComponent(Part, _$mergeProps({
|
|
87
|
+
get part() {
|
|
88
|
+
return useScrollArea()[name];
|
|
89
|
+
},
|
|
90
|
+
tag: "div"
|
|
91
|
+
}, props));
|
|
92
|
+
export const ScrollArea = {
|
|
93
|
+
Root,
|
|
94
|
+
Viewport: part("viewport"),
|
|
95
|
+
Content: part("content"),
|
|
96
|
+
Scrollbar,
|
|
97
|
+
Thumb,
|
|
98
|
+
Corner
|
|
99
|
+
};
|