@kirana-ui/solid 0.0.0-stage → 0.1.0
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 +21 -0
- package/dom/accordion.js +106 -0
- package/dom/alert-dialog.js +2 -0
- package/dom/avatar.js +68 -0
- package/dom/button.js +18 -0
- package/dom/checkbox.js +76 -0
- package/dom/collapsible.js +64 -0
- package/dom/dialog.js +73 -0
- package/dom/direction-context.js +3 -0
- package/dom/direction.js +27 -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 +63 -0
- package/dom/index.js +22 -0
- package/dom/meter.js +3 -0
- package/dom/popover.js +68 -0
- package/dom/progress.js +3 -0
- package/dom/radio-group.js +100 -0
- package/dom/runtime.js +99 -0
- package/dom/select.js +149 -0
- package/dom/separator.js +17 -0
- package/dom/slider.js +93 -0
- package/dom/switch.js +62 -0
- package/dom/tabs.js +97 -0
- package/dom/toggle.js +20 -0
- package/dom/tooltip.js +3 -0
- package/dom/value-bar.js +62 -0
- package/package.json +229 -4
- package/server/accordion.js +106 -0
- package/server/alert-dialog.js +2 -0
- package/server/avatar.js +68 -0
- package/server/button.js +18 -0
- package/server/checkbox.js +76 -0
- package/server/collapsible.js +64 -0
- package/server/dialog.js +73 -0
- package/server/direction-context.js +3 -0
- package/server/direction.js +27 -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 +63 -0
- package/server/index.js +22 -0
- package/server/meter.js +3 -0
- package/server/popover.js +68 -0
- package/server/progress.js +3 -0
- package/server/radio-group.js +100 -0
- package/server/runtime.js +98 -0
- package/server/select.js +149 -0
- package/server/separator.js +17 -0
- package/server/slider.js +92 -0
- package/server/switch.js +61 -0
- package/server/tabs.js +97 -0
- package/server/toggle.js +20 -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/avatar.jsx +35 -0
- package/src/button.jsx +9 -0
- package/src/checkbox.jsx +57 -0
- package/src/collapsible.jsx +35 -0
- package/src/dialog.jsx +47 -0
- package/src/direction-context.js +3 -0
- package/src/direction.jsx +17 -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 +40 -0
- package/src/index.js +22 -0
- package/src/meter.jsx +3 -0
- package/src/popover.jsx +49 -0
- package/src/progress.jsx +3 -0
- package/src/radio-group.jsx +66 -0
- package/src/runtime.jsx +88 -0
- package/src/select.jsx +85 -0
- package/src/separator.jsx +8 -0
- package/src/slider.jsx +74 -0
- package/src/switch.jsx +47 -0
- package/src/tabs.jsx +58 -0
- package/src/toggle.jsx +18 -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/avatar.d.ts +15 -0
- package/types/button.d.ts +9 -0
- package/types/checkbox.d.ts +25 -0
- package/types/collapsible.d.ts +21 -0
- package/types/dialog.d.ts +40 -0
- package/types/direction-context.d.ts +3 -0
- package/types/direction.d.ts +14 -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 +10 -0
- package/types/hover-popup.d.ts +26 -0
- package/types/index.d.ts +24 -0
- package/types/meter.d.ts +9 -0
- package/types/popover.d.ts +28 -0
- package/types/progress.d.ts +9 -0
- package/types/radio-group.d.ts +28 -0
- package/types/runtime.d.ts +31 -0
- package/types/select.d.ts +50 -0
- package/types/separator.d.ts +6 -0
- package/types/slider.d.ts +24 -0
- package/types/switch.d.ts +20 -0
- package/types/tabs.d.ts +32 -0
- package/types/toggle.d.ts +10 -0
- package/types/tooltip.d.ts +10 -0
- package/types/value-bar.d.ts +17 -0
- package/README.md +0 -3
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Kirana authors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/dom/accordion.js
ADDED
|
@@ -0,0 +1,106 @@
|
|
|
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 { createAccordion } from "@kirana-ui/core/accordion";
|
|
6
|
+
import { Show, createContext, createUniqueId, onCleanup, onMount, splitProps, untrack, useContext } from "solid-js";
|
|
7
|
+
import { DirectionContext } from "./direction-context.js";
|
|
8
|
+
import { Part, controller, fromSignal, toSignal } from "./runtime.js";
|
|
9
|
+
const Context = createContext();
|
|
10
|
+
const ItemContext = createContext();
|
|
11
|
+
function useAccordion() {
|
|
12
|
+
const made = useContext(Context);
|
|
13
|
+
if (!made) throw new Error("An Accordion part must be inside <Accordion.Root>");
|
|
14
|
+
return made;
|
|
15
|
+
}
|
|
16
|
+
function useItem() {
|
|
17
|
+
const item = useContext(ItemContext);
|
|
18
|
+
if (!item) throw new Error("An Accordion part must be inside <Accordion.Item>");
|
|
19
|
+
return item;
|
|
20
|
+
}
|
|
21
|
+
function Root(props) {
|
|
22
|
+
const [local, rest] = splitProps(props, ["value", "defaultValue", "onValueChange", "multiple", "disabled", "orientation", "loop", "id"]);
|
|
23
|
+
const generated = createUniqueId();
|
|
24
|
+
const direction = useContext(DirectionContext);
|
|
25
|
+
const made = controller(within(createAccordion, {
|
|
26
|
+
direction
|
|
27
|
+
}), () => ({
|
|
28
|
+
id: local.id ?? generated,
|
|
29
|
+
value: local.value,
|
|
30
|
+
defaultValue: local.defaultValue,
|
|
31
|
+
multiple: local.multiple,
|
|
32
|
+
disabled: local.disabled,
|
|
33
|
+
orientation: local.orientation,
|
|
34
|
+
loop: local.loop,
|
|
35
|
+
onValueChange: (value, details) => local.onValueChange?.(value, details)
|
|
36
|
+
}));
|
|
37
|
+
return _$createComponent(Context.Provider, {
|
|
38
|
+
value: made,
|
|
39
|
+
get children() {
|
|
40
|
+
return _$createComponent(Part, _$mergeProps({
|
|
41
|
+
get part() {
|
|
42
|
+
return made.root;
|
|
43
|
+
},
|
|
44
|
+
tag: "div"
|
|
45
|
+
}, rest));
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
function Item(props) {
|
|
50
|
+
const [local, rest] = splitProps(props, ["value", "disabled"]);
|
|
51
|
+
const options = toSignal(() => ({
|
|
52
|
+
disabled: local.disabled
|
|
53
|
+
}));
|
|
54
|
+
// An item is its value for as long as it is in the page.
|
|
55
|
+
const item = useAccordion().item(untrack(() => local.value), () => defined(options.get()));
|
|
56
|
+
onMount(() => onCleanup(item.mount()));
|
|
57
|
+
return _$createComponent(ItemContext.Provider, {
|
|
58
|
+
value: item,
|
|
59
|
+
get children() {
|
|
60
|
+
return _$createComponent(Part, _$mergeProps({
|
|
61
|
+
get part() {
|
|
62
|
+
return item.root;
|
|
63
|
+
},
|
|
64
|
+
tag: "div"
|
|
65
|
+
}, rest));
|
|
66
|
+
}
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
const Header = props => _$createComponent(Part, _$mergeProps({
|
|
70
|
+
get part() {
|
|
71
|
+
return useItem().header;
|
|
72
|
+
},
|
|
73
|
+
tag: "h3"
|
|
74
|
+
}, props));
|
|
75
|
+
const Trigger = props => _$createComponent(Part, _$mergeProps({
|
|
76
|
+
get part() {
|
|
77
|
+
return useItem().trigger;
|
|
78
|
+
},
|
|
79
|
+
tag: "button"
|
|
80
|
+
}, props));
|
|
81
|
+
/** `keepMounted` keeps the closed panel in the page, `hidden`. */
|
|
82
|
+
function Panel(props) {
|
|
83
|
+
const [local, rest] = splitProps(props, ["keepMounted"]);
|
|
84
|
+
const item = useItem();
|
|
85
|
+
const mounted = fromSignal(item.mounted);
|
|
86
|
+
return _$createComponent(Show, {
|
|
87
|
+
get when() {
|
|
88
|
+
return mounted() || local.keepMounted;
|
|
89
|
+
},
|
|
90
|
+
get children() {
|
|
91
|
+
return _$createComponent(Part, _$mergeProps({
|
|
92
|
+
get part() {
|
|
93
|
+
return item.panel;
|
|
94
|
+
},
|
|
95
|
+
tag: "div"
|
|
96
|
+
}, rest));
|
|
97
|
+
}
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
export const Accordion = {
|
|
101
|
+
Root,
|
|
102
|
+
Item,
|
|
103
|
+
Header,
|
|
104
|
+
Trigger,
|
|
105
|
+
Panel
|
|
106
|
+
};
|
package/dom/avatar.js
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { createComponent as _$createComponent } from "solid-js/web";
|
|
2
|
+
import { mergeProps as _$mergeProps } from "solid-js/web";
|
|
3
|
+
import { createAvatar } from "@kirana-ui/core/avatar";
|
|
4
|
+
import { Show, createComputed, createContext, splitProps, useContext } from "solid-js";
|
|
5
|
+
import { Part, controller, fromSignal } from "./runtime.js";
|
|
6
|
+
const Context = createContext();
|
|
7
|
+
function useAvatar() {
|
|
8
|
+
const made = useContext(Context);
|
|
9
|
+
if (!made) throw new Error("An Avatar part must be inside <Avatar.Root>");
|
|
10
|
+
return made;
|
|
11
|
+
}
|
|
12
|
+
function Root(props) {
|
|
13
|
+
const made = controller(createAvatar, () => ({}));
|
|
14
|
+
return _$createComponent(Context.Provider, {
|
|
15
|
+
value: made,
|
|
16
|
+
get children() {
|
|
17
|
+
return _$createComponent(Part, _$mergeProps({
|
|
18
|
+
get part() {
|
|
19
|
+
return made.root;
|
|
20
|
+
},
|
|
21
|
+
tag: "span"
|
|
22
|
+
}, props));
|
|
23
|
+
}
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
/** The picture: in the page once `src` has loaded. */
|
|
27
|
+
function Image(props) {
|
|
28
|
+
const [local, rest] = splitProps(props, ["src"]);
|
|
29
|
+
const made = useAvatar();
|
|
30
|
+
createComputed(() => made.source.set(local.src));
|
|
31
|
+
const status = fromSignal(made.status);
|
|
32
|
+
return _$createComponent(Show, {
|
|
33
|
+
get when() {
|
|
34
|
+
return status() === "loaded";
|
|
35
|
+
},
|
|
36
|
+
get children() {
|
|
37
|
+
return _$createComponent(Part, _$mergeProps({
|
|
38
|
+
get part() {
|
|
39
|
+
return made.image;
|
|
40
|
+
},
|
|
41
|
+
tag: "img"
|
|
42
|
+
}, rest));
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
/** What shows until the picture has loaded, or when it cannot. */
|
|
47
|
+
function Fallback(props) {
|
|
48
|
+
const made = useAvatar();
|
|
49
|
+
const status = fromSignal(made.status);
|
|
50
|
+
return _$createComponent(Show, {
|
|
51
|
+
get when() {
|
|
52
|
+
return status() !== "loaded";
|
|
53
|
+
},
|
|
54
|
+
get children() {
|
|
55
|
+
return _$createComponent(Part, _$mergeProps({
|
|
56
|
+
get part() {
|
|
57
|
+
return made.fallback;
|
|
58
|
+
},
|
|
59
|
+
tag: "span"
|
|
60
|
+
}, props));
|
|
61
|
+
}
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
export const Avatar = {
|
|
65
|
+
Root,
|
|
66
|
+
Image,
|
|
67
|
+
Fallback
|
|
68
|
+
};
|
package/dom/button.js
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { createComponent as _$createComponent } from "solid-js/web";
|
|
2
|
+
import { mergeProps as _$mergeProps } from "solid-js/web";
|
|
3
|
+
import { createButton } from "@kirana-ui/core/button";
|
|
4
|
+
import { splitProps } from "solid-js";
|
|
5
|
+
import { Part, controller } from "./runtime.js";
|
|
6
|
+
/** A `<button>`, or with `as` and `nativeButton={false}` another element that acts as one. */
|
|
7
|
+
export function Button(props) {
|
|
8
|
+
const [local, rest] = splitProps(props, ["disabled", "focusableWhenDisabled", "nativeButton"]);
|
|
9
|
+
const made = controller(createButton, () => ({
|
|
10
|
+
...local
|
|
11
|
+
}));
|
|
12
|
+
return _$createComponent(Part, _$mergeProps({
|
|
13
|
+
get part() {
|
|
14
|
+
return made.root;
|
|
15
|
+
},
|
|
16
|
+
tag: "button"
|
|
17
|
+
}, rest));
|
|
18
|
+
}
|
package/dom/checkbox.js
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
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 { createCheckbox } from "@kirana-ui/core/checkbox";
|
|
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 useCheckbox() {
|
|
11
|
+
const made = useContext(Context);
|
|
12
|
+
if (!made) throw new Error("A Checkbox part must be inside <Checkbox.Root>");
|
|
13
|
+
return made;
|
|
14
|
+
}
|
|
15
|
+
function Root(props) {
|
|
16
|
+
const [local, rest] = splitProps(props, ["checked", "defaultChecked", "onCheckedChange", "indeterminate", "disabled", "readOnly", "required", "name", "value", "id", "children"]);
|
|
17
|
+
const generated = createUniqueId();
|
|
18
|
+
const field = useContext(FieldContext);
|
|
19
|
+
const made = controller(within(createCheckbox, {
|
|
20
|
+
field
|
|
21
|
+
}), () => ({
|
|
22
|
+
id: local.id ?? generated,
|
|
23
|
+
checked: local.checked,
|
|
24
|
+
defaultChecked: local.defaultChecked,
|
|
25
|
+
indeterminate: local.indeterminate,
|
|
26
|
+
disabled: local.disabled,
|
|
27
|
+
readOnly: local.readOnly,
|
|
28
|
+
required: local.required,
|
|
29
|
+
name: local.name,
|
|
30
|
+
value: local.value,
|
|
31
|
+
onCheckedChange: (checked, details) => local.onCheckedChange?.(checked, details)
|
|
32
|
+
}));
|
|
33
|
+
return _$createComponent(Context.Provider, {
|
|
34
|
+
value: made,
|
|
35
|
+
get children() {
|
|
36
|
+
return _$createComponent(Part, _$mergeProps({
|
|
37
|
+
get part() {
|
|
38
|
+
return made.root;
|
|
39
|
+
},
|
|
40
|
+
tag: "span"
|
|
41
|
+
}, rest, {
|
|
42
|
+
get children() {
|
|
43
|
+
return [_$memo(() => local.children), _$createComponent(Part, {
|
|
44
|
+
get part() {
|
|
45
|
+
return made.input;
|
|
46
|
+
},
|
|
47
|
+
tag: "input"
|
|
48
|
+
})];
|
|
49
|
+
}
|
|
50
|
+
}));
|
|
51
|
+
}
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
/** `keepMounted` keeps the mark in the page while the box is unchecked. */
|
|
55
|
+
function Indicator(props) {
|
|
56
|
+
const [local, rest] = splitProps(props, ["keepMounted"]);
|
|
57
|
+
const made = useCheckbox();
|
|
58
|
+
const mounted = fromSignal(made.indicatorMounted);
|
|
59
|
+
return _$createComponent(Show, {
|
|
60
|
+
get when() {
|
|
61
|
+
return mounted() || local.keepMounted;
|
|
62
|
+
},
|
|
63
|
+
get children() {
|
|
64
|
+
return _$createComponent(Part, _$mergeProps({
|
|
65
|
+
get part() {
|
|
66
|
+
return made.indicator;
|
|
67
|
+
},
|
|
68
|
+
tag: "span"
|
|
69
|
+
}, rest));
|
|
70
|
+
}
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
export const Checkbox = {
|
|
74
|
+
Root,
|
|
75
|
+
Indicator
|
|
76
|
+
};
|
|
@@ -0,0 +1,64 @@
|
|
|
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 { createCollapsible } from "@kirana-ui/core/collapsible";
|
|
5
|
+
import { Show, createContext, createUniqueId, splitProps, useContext } from "solid-js";
|
|
6
|
+
import { Part, controller, fromSignal } from "./runtime.js";
|
|
7
|
+
const Context = createContext();
|
|
8
|
+
function useCollapsible() {
|
|
9
|
+
const made = useContext(Context);
|
|
10
|
+
if (!made) throw new Error("A Collapsible part must be inside <Collapsible.Root>");
|
|
11
|
+
return made;
|
|
12
|
+
}
|
|
13
|
+
function Root(props) {
|
|
14
|
+
const [local, rest] = splitProps(props, ["open", "defaultOpen", "onOpenChange", "disabled", "id"]);
|
|
15
|
+
const generated = createUniqueId();
|
|
16
|
+
const made = controller(createCollapsible, () => ({
|
|
17
|
+
id: local.id ?? generated,
|
|
18
|
+
open: local.open,
|
|
19
|
+
defaultOpen: local.defaultOpen,
|
|
20
|
+
disabled: local.disabled,
|
|
21
|
+
onOpenChange: (open, details) => local.onOpenChange?.(open, details)
|
|
22
|
+
}));
|
|
23
|
+
return _$createComponent(Context.Provider, {
|
|
24
|
+
value: made,
|
|
25
|
+
get children() {
|
|
26
|
+
return _$createComponent(Part, _$mergeProps({
|
|
27
|
+
get part() {
|
|
28
|
+
return made.root;
|
|
29
|
+
},
|
|
30
|
+
tag: "div"
|
|
31
|
+
}, rest));
|
|
32
|
+
}
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
const Trigger = props => _$createComponent(Part, _$mergeProps({
|
|
36
|
+
get part() {
|
|
37
|
+
return useCollapsible().trigger;
|
|
38
|
+
},
|
|
39
|
+
tag: "button"
|
|
40
|
+
}, props));
|
|
41
|
+
/** `keepMounted` keeps the closed panel in the page, `hidden`. */
|
|
42
|
+
function Panel(props) {
|
|
43
|
+
const [local, rest] = splitProps(props, ["keepMounted"]);
|
|
44
|
+
const made = useCollapsible();
|
|
45
|
+
const mounted = fromSignal(made.mounted);
|
|
46
|
+
return _$createComponent(Show, {
|
|
47
|
+
get when() {
|
|
48
|
+
return mounted() || local.keepMounted;
|
|
49
|
+
},
|
|
50
|
+
get children() {
|
|
51
|
+
return _$createComponent(Part, _$mergeProps({
|
|
52
|
+
get part() {
|
|
53
|
+
return made.panel;
|
|
54
|
+
},
|
|
55
|
+
tag: "div"
|
|
56
|
+
}, rest));
|
|
57
|
+
}
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
export const Collapsible = {
|
|
61
|
+
Root,
|
|
62
|
+
Trigger,
|
|
63
|
+
Panel
|
|
64
|
+
};
|
package/dom/dialog.js
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { mergeProps as _$mergeProps } from "solid-js/web";
|
|
2
|
+
import { createComponent as _$createComponent } from "solid-js/web";
|
|
3
|
+
import { createAlertDialog } from "@kirana-ui/core/alert-dialog";
|
|
4
|
+
import { createDialog } from "@kirana-ui/core/dialog";
|
|
5
|
+
import { createContext, createUniqueId, useContext } from "solid-js";
|
|
6
|
+
import { Part, Portal as BodyPortal, controller } from "./runtime.js";
|
|
7
|
+
const Context = createContext();
|
|
8
|
+
function useDialog() {
|
|
9
|
+
const made = useContext(Context);
|
|
10
|
+
if (!made) throw new Error("A Dialog part must be inside <Dialog.Root>");
|
|
11
|
+
return made;
|
|
12
|
+
}
|
|
13
|
+
function Root(props) {
|
|
14
|
+
const generated = createUniqueId();
|
|
15
|
+
const made = controller(createDialog, () => ({
|
|
16
|
+
id: props.id ?? generated,
|
|
17
|
+
open: props.open,
|
|
18
|
+
defaultOpen: props.defaultOpen,
|
|
19
|
+
modal: props.modal,
|
|
20
|
+
dismissible: props.dismissible,
|
|
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 useDialog().mounted;
|
|
33
|
+
},
|
|
34
|
+
get children() {
|
|
35
|
+
return props.children;
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
const part = (name, tag) => props => _$createComponent(Part, _$mergeProps({
|
|
39
|
+
get part() {
|
|
40
|
+
return useDialog()[name];
|
|
41
|
+
},
|
|
42
|
+
tag: tag
|
|
43
|
+
}, props));
|
|
44
|
+
function AlertRoot(props) {
|
|
45
|
+
const generated = createUniqueId();
|
|
46
|
+
const made = controller(createAlertDialog, () => ({
|
|
47
|
+
id: props.id ?? generated,
|
|
48
|
+
open: props.open,
|
|
49
|
+
defaultOpen: props.defaultOpen,
|
|
50
|
+
onOpenChange: (open, details) => props.onOpenChange?.(open, details)
|
|
51
|
+
}));
|
|
52
|
+
return _$createComponent(Context.Provider, {
|
|
53
|
+
value: made,
|
|
54
|
+
get children() {
|
|
55
|
+
return props.children;
|
|
56
|
+
}
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
export const Dialog = {
|
|
60
|
+
Root,
|
|
61
|
+
Portal,
|
|
62
|
+
Trigger: part("trigger", "button"),
|
|
63
|
+
Backdrop: part("backdrop", "div"),
|
|
64
|
+
Popup: part("popup", "div"),
|
|
65
|
+
Title: part("title", "h2"),
|
|
66
|
+
Description: part("description", "p"),
|
|
67
|
+
Close: part("close", "button")
|
|
68
|
+
};
|
|
69
|
+
/** A dialog that asks for an answer: a press outside it does not close it. Its parts are a dialog's. */
|
|
70
|
+
export const AlertDialog = {
|
|
71
|
+
...Dialog,
|
|
72
|
+
Root: AlertRoot
|
|
73
|
+
};
|
package/dom/direction.js
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { createComponent as _$createComponent } from "solid-js/web";
|
|
2
|
+
import { signal } from "@kirana-ui/core";
|
|
3
|
+
import { createDirection } from "@kirana-ui/core/direction";
|
|
4
|
+
import { useContext } from "solid-js";
|
|
5
|
+
import { DirectionContext } from "./direction-context.js";
|
|
6
|
+
import { controller, fromSignal } from "./runtime.js";
|
|
7
|
+
/**
|
|
8
|
+
* States the reading direction for the components inside. It draws nothing: set the page's own
|
|
9
|
+
* `dir` attribute with it.
|
|
10
|
+
*/
|
|
11
|
+
export function DirectionProvider(props) {
|
|
12
|
+
const made = controller(createDirection, () => ({
|
|
13
|
+
direction: props.direction
|
|
14
|
+
}));
|
|
15
|
+
return _$createComponent(DirectionContext.Provider, {
|
|
16
|
+
get value() {
|
|
17
|
+
return made.direction;
|
|
18
|
+
},
|
|
19
|
+
get children() {
|
|
20
|
+
return props.children;
|
|
21
|
+
}
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
/** The direction the nearest provider states; `ltr` outside one. */
|
|
25
|
+
export function useDirection() {
|
|
26
|
+
return fromSignal(useContext(DirectionContext) ?? signal("ltr"));
|
|
27
|
+
}
|
package/dom/field.js
ADDED
|
@@ -0,0 +1,88 @@
|
|
|
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 { createField } from "@kirana-ui/core/field";
|
|
5
|
+
import { Show, createUniqueId, onCleanup, onMount, splitProps, useContext } from "solid-js";
|
|
6
|
+
import { FieldContext } from "./field-context.js";
|
|
7
|
+
import { FieldsetContext } from "./fieldset.js";
|
|
8
|
+
import { FormContext } from "./form.js";
|
|
9
|
+
import { Part, controller, fromSignal, toSignal } from "./runtime.js";
|
|
10
|
+
function useField() {
|
|
11
|
+
const made = useContext(FieldContext);
|
|
12
|
+
if (!made) throw new Error("A Field part must be inside <Field.Root>");
|
|
13
|
+
return made;
|
|
14
|
+
}
|
|
15
|
+
function Root(props) {
|
|
16
|
+
const [local, rest] = splitProps(props, ["name", "disabled", "invalid", "validate", "validationMode", "validationDebounceTime", "id"]);
|
|
17
|
+
const generated = createUniqueId();
|
|
18
|
+
const around = {
|
|
19
|
+
form: useContext(FormContext),
|
|
20
|
+
fieldset: useContext(FieldsetContext)
|
|
21
|
+
};
|
|
22
|
+
const made = controller(source => createField(source, around), () => ({
|
|
23
|
+
...local,
|
|
24
|
+
id: local.id ?? generated,
|
|
25
|
+
validate: value => local.validate?.(value) ?? null
|
|
26
|
+
}));
|
|
27
|
+
return _$createComponent(FieldContext.Provider, {
|
|
28
|
+
value: made,
|
|
29
|
+
get children() {
|
|
30
|
+
return _$createComponent(Part, _$mergeProps({
|
|
31
|
+
get part() {
|
|
32
|
+
return made.root;
|
|
33
|
+
},
|
|
34
|
+
tag: "div"
|
|
35
|
+
}, rest));
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* What is wrong, or its children in its place. In the page while it applies. `match` is one of
|
|
41
|
+
* the browser's findings (`"valueMissing"`) to show for only that, or `true` to show always.
|
|
42
|
+
*/
|
|
43
|
+
function FieldError(props) {
|
|
44
|
+
const [local, rest] = splitProps(props, ["match", "children"]);
|
|
45
|
+
const options = toSignal(() => ({
|
|
46
|
+
match: local.match
|
|
47
|
+
}));
|
|
48
|
+
const error = useField().error(() => options.get().match);
|
|
49
|
+
onMount(() => onCleanup(error.mount()));
|
|
50
|
+
const mounted = fromSignal(error.mounted);
|
|
51
|
+
const text = fromSignal(error.text);
|
|
52
|
+
return _$createComponent(Show, {
|
|
53
|
+
get when() {
|
|
54
|
+
return mounted();
|
|
55
|
+
},
|
|
56
|
+
get children() {
|
|
57
|
+
return _$createComponent(Part, _$mergeProps({
|
|
58
|
+
get part() {
|
|
59
|
+
return error.part;
|
|
60
|
+
},
|
|
61
|
+
tag: "div"
|
|
62
|
+
}, rest, {
|
|
63
|
+
get children() {
|
|
64
|
+
return local.children ?? text();
|
|
65
|
+
}
|
|
66
|
+
}));
|
|
67
|
+
}
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
/** Draws nothing itself: its child, a function, is given the field's validity. */
|
|
71
|
+
function Validity(props) {
|
|
72
|
+
return props.children(fromSignal(useField().validity));
|
|
73
|
+
}
|
|
74
|
+
const part = (key, tag) => props => _$createComponent(Part, _$mergeProps({
|
|
75
|
+
get part() {
|
|
76
|
+
return useField()[key];
|
|
77
|
+
},
|
|
78
|
+
tag: tag
|
|
79
|
+
}, props));
|
|
80
|
+
export const Field = {
|
|
81
|
+
Root,
|
|
82
|
+
Label: part("label", "label"),
|
|
83
|
+
/** An `<input>`; `as="textarea"` or `as="select"` for another. */
|
|
84
|
+
Control: part("control", "input"),
|
|
85
|
+
Description: part("description", "p"),
|
|
86
|
+
Error: FieldError,
|
|
87
|
+
Validity
|
|
88
|
+
};
|
package/dom/fieldset.js
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { createComponent as _$createComponent } from "solid-js/web";
|
|
2
|
+
import { mergeProps as _$mergeProps } from "solid-js/web";
|
|
3
|
+
import { createFieldset } from "@kirana-ui/core/fieldset";
|
|
4
|
+
import { createContext, createUniqueId, splitProps, useContext } from "solid-js";
|
|
5
|
+
import { Part, controller } from "./runtime.js";
|
|
6
|
+
/** The fieldset a field is in, if it is in one. */
|
|
7
|
+
export const FieldsetContext = createContext();
|
|
8
|
+
function useFieldset() {
|
|
9
|
+
const made = useContext(FieldsetContext);
|
|
10
|
+
if (!made) throw new Error("A Fieldset part must be inside <Fieldset.Root>");
|
|
11
|
+
return made;
|
|
12
|
+
}
|
|
13
|
+
function Root(props) {
|
|
14
|
+
const [local, rest] = splitProps(props, ["disabled", "id"]);
|
|
15
|
+
const generated = createUniqueId();
|
|
16
|
+
const made = controller(createFieldset, () => ({
|
|
17
|
+
id: local.id ?? generated,
|
|
18
|
+
disabled: local.disabled
|
|
19
|
+
}));
|
|
20
|
+
return _$createComponent(FieldsetContext.Provider, {
|
|
21
|
+
value: made,
|
|
22
|
+
get children() {
|
|
23
|
+
return _$createComponent(Part, _$mergeProps({
|
|
24
|
+
get part() {
|
|
25
|
+
return made.root;
|
|
26
|
+
},
|
|
27
|
+
tag: "fieldset"
|
|
28
|
+
}, rest));
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
const Legend = props => _$createComponent(Part, _$mergeProps({
|
|
33
|
+
get part() {
|
|
34
|
+
return useFieldset().legend;
|
|
35
|
+
},
|
|
36
|
+
tag: "div"
|
|
37
|
+
}, props));
|
|
38
|
+
export const Fieldset = {
|
|
39
|
+
Root,
|
|
40
|
+
Legend
|
|
41
|
+
};
|
package/dom/form.js
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { createComponent as _$createComponent } from "solid-js/web";
|
|
2
|
+
import { mergeProps as _$mergeProps } from "solid-js/web";
|
|
3
|
+
import { createForm } from "@kirana-ui/core/form";
|
|
4
|
+
import { createContext, splitProps } from "solid-js";
|
|
5
|
+
import { Part, controller } from "./runtime.js";
|
|
6
|
+
/** The form a field is in, if it is in one. */
|
|
7
|
+
export const FormContext = createContext();
|
|
8
|
+
/** A `<form>` whose fields say what is wrong; `onFormSubmit` takes the values once all are valid. */
|
|
9
|
+
export function Form(props) {
|
|
10
|
+
const [local, rest] = splitProps(props, ["errors", "onClearErrors", "onFormSubmit", "validationMode"]);
|
|
11
|
+
const made = controller(createForm, () => ({
|
|
12
|
+
errors: local.errors,
|
|
13
|
+
validationMode: local.validationMode,
|
|
14
|
+
// Only when the caller takes the values: without it the form submits as a form does.
|
|
15
|
+
onFormSubmit: local.onFormSubmit ? (values, details) => local.onFormSubmit?.(values, details) : undefined,
|
|
16
|
+
onClearErrors: errors => local.onClearErrors?.(errors)
|
|
17
|
+
}));
|
|
18
|
+
return _$createComponent(FormContext.Provider, {
|
|
19
|
+
value: made,
|
|
20
|
+
get children() {
|
|
21
|
+
return _$createComponent(Part, _$mergeProps({
|
|
22
|
+
get part() {
|
|
23
|
+
return made.root;
|
|
24
|
+
},
|
|
25
|
+
tag: "form"
|
|
26
|
+
}, rest));
|
|
27
|
+
}
|
|
28
|
+
});
|
|
29
|
+
}
|