@kirana-ui/solid 0.0.0 → 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 +1 -1
- 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 +219 -6
- 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 -7
- package/index.js +0 -5
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { memo as _$memo } from "solid-js/web";
|
|
2
|
+
import { mergeProps as _$mergeProps } from "solid-js/web";
|
|
3
|
+
import { createComponent as _$createComponent } from "solid-js/web";
|
|
4
|
+
import { 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 [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/server/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
|
+
};
|
|
@@ -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/server/field.js
ADDED
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { createComponent as _$createComponent } from "solid-js/web";
|
|
2
|
+
import { mergeProps as _$mergeProps } from "solid-js/web";
|
|
3
|
+
import { createField } from "@kirana-ui/core/field";
|
|
4
|
+
import { Show, createUniqueId, onCleanup, onMount, splitProps, useContext } from "solid-js";
|
|
5
|
+
import { FieldContext } from "./field-context.js";
|
|
6
|
+
import { FieldsetContext } from "./fieldset.js";
|
|
7
|
+
import { FormContext } from "./form.js";
|
|
8
|
+
import { Part, controller, fromSignal, toSignal } from "./runtime.js";
|
|
9
|
+
function useField() {
|
|
10
|
+
const made = useContext(FieldContext);
|
|
11
|
+
if (!made) throw new Error("A Field part must be inside <Field.Root>");
|
|
12
|
+
return made;
|
|
13
|
+
}
|
|
14
|
+
function Root(props) {
|
|
15
|
+
const [local, rest] = splitProps(props, ["name", "disabled", "invalid", "validate", "validationMode", "validationDebounceTime", "id"]);
|
|
16
|
+
const generated = createUniqueId();
|
|
17
|
+
const around = {
|
|
18
|
+
form: useContext(FormContext),
|
|
19
|
+
fieldset: useContext(FieldsetContext)
|
|
20
|
+
};
|
|
21
|
+
const made = controller(source => createField(source, around), () => ({
|
|
22
|
+
...local,
|
|
23
|
+
id: local.id ?? generated,
|
|
24
|
+
validate: value => local.validate?.(value) ?? null
|
|
25
|
+
}));
|
|
26
|
+
return _$createComponent(FieldContext.Provider, {
|
|
27
|
+
value: made,
|
|
28
|
+
get children() {
|
|
29
|
+
return _$createComponent(Part, _$mergeProps({
|
|
30
|
+
get part() {
|
|
31
|
+
return made.root;
|
|
32
|
+
},
|
|
33
|
+
tag: "div"
|
|
34
|
+
}, rest));
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* What is wrong, or its children in its place. In the page while it applies. `match` is one of
|
|
40
|
+
* the browser's findings (`"valueMissing"`) to show for only that, or `true` to show always.
|
|
41
|
+
*/
|
|
42
|
+
function FieldError(props) {
|
|
43
|
+
const [local, rest] = splitProps(props, ["match", "children"]);
|
|
44
|
+
const options = toSignal(() => ({
|
|
45
|
+
match: local.match
|
|
46
|
+
}));
|
|
47
|
+
const error = useField().error(() => options.get().match);
|
|
48
|
+
onMount(() => onCleanup(error.mount()));
|
|
49
|
+
const mounted = fromSignal(error.mounted);
|
|
50
|
+
const text = fromSignal(error.text);
|
|
51
|
+
return _$createComponent(Show, {
|
|
52
|
+
get when() {
|
|
53
|
+
return mounted();
|
|
54
|
+
},
|
|
55
|
+
get children() {
|
|
56
|
+
return _$createComponent(Part, _$mergeProps({
|
|
57
|
+
get part() {
|
|
58
|
+
return error.part;
|
|
59
|
+
},
|
|
60
|
+
tag: "div"
|
|
61
|
+
}, rest, {
|
|
62
|
+
get children() {
|
|
63
|
+
return local.children ?? text();
|
|
64
|
+
}
|
|
65
|
+
}));
|
|
66
|
+
}
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
/** Draws nothing itself: its child, a function, is given the field's validity. */
|
|
70
|
+
function Validity(props) {
|
|
71
|
+
return props.children(fromSignal(useField().validity));
|
|
72
|
+
}
|
|
73
|
+
const part = (key, tag) => props => _$createComponent(Part, _$mergeProps({
|
|
74
|
+
get part() {
|
|
75
|
+
return useField()[key];
|
|
76
|
+
},
|
|
77
|
+
tag: tag
|
|
78
|
+
}, props));
|
|
79
|
+
export const Field = {
|
|
80
|
+
Root,
|
|
81
|
+
Label: part("label", "label"),
|
|
82
|
+
/** An `<input>`; `as="textarea"` or `as="select"` for another. */
|
|
83
|
+
Control: part("control", "input"),
|
|
84
|
+
Description: part("description", "p"),
|
|
85
|
+
Error: FieldError,
|
|
86
|
+
Validity
|
|
87
|
+
};
|
|
@@ -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/server/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
|
+
}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { mergeProps as _$mergeProps } from "solid-js/web";
|
|
2
|
+
import { createComponent as _$createComponent } from "solid-js/web";
|
|
3
|
+
import { createContext, createUniqueId, useContext } from "solid-js";
|
|
4
|
+
import { positioned } from "./popover.js";
|
|
5
|
+
import { Part, Portal as BodyPortal, controller } from "./runtime.js";
|
|
6
|
+
/** The parts of a popup the pointer opens: a tooltip's, a hover card's. */
|
|
7
|
+
export function hoverPopup(name, create, triggerTag) {
|
|
8
|
+
const Context = createContext();
|
|
9
|
+
function use() {
|
|
10
|
+
const made = useContext(Context);
|
|
11
|
+
if (!made) throw new Error(`A ${name} part must be inside <${name}.Root>`);
|
|
12
|
+
return made;
|
|
13
|
+
}
|
|
14
|
+
function Root(props) {
|
|
15
|
+
const generated = createUniqueId();
|
|
16
|
+
const made = controller(create, () => ({
|
|
17
|
+
id: props.id ?? generated,
|
|
18
|
+
open: props.open,
|
|
19
|
+
defaultOpen: props.defaultOpen,
|
|
20
|
+
delay: props.delay,
|
|
21
|
+
closeDelay: props.closeDelay,
|
|
22
|
+
disabled: props.disabled,
|
|
23
|
+
onOpenChange: (open, details) => props.onOpenChange?.(open, details)
|
|
24
|
+
}));
|
|
25
|
+
return _$createComponent(Context.Provider, {
|
|
26
|
+
value: made,
|
|
27
|
+
get children() {
|
|
28
|
+
return props.children;
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
const Portal = props => _$createComponent(BodyPortal, {
|
|
33
|
+
get mounted() {
|
|
34
|
+
return use().mounted;
|
|
35
|
+
},
|
|
36
|
+
get children() {
|
|
37
|
+
return props.children;
|
|
38
|
+
}
|
|
39
|
+
});
|
|
40
|
+
function Positioner(props) {
|
|
41
|
+
const made = use();
|
|
42
|
+
return _$createComponent(Part, _$mergeProps({
|
|
43
|
+
get part() {
|
|
44
|
+
return made.positioner;
|
|
45
|
+
},
|
|
46
|
+
tag: "div"
|
|
47
|
+
}, () => positioned(props, made.positioning)));
|
|
48
|
+
}
|
|
49
|
+
const part = (key, tag) => props => _$createComponent(Part, _$mergeProps({
|
|
50
|
+
get part() {
|
|
51
|
+
return use()[key];
|
|
52
|
+
},
|
|
53
|
+
tag: tag
|
|
54
|
+
}, props));
|
|
55
|
+
return {
|
|
56
|
+
Root,
|
|
57
|
+
Portal,
|
|
58
|
+
Positioner,
|
|
59
|
+
Trigger: part("trigger", triggerTag),
|
|
60
|
+
Popup: part("popup", "div"),
|
|
61
|
+
Arrow: part("arrow", "div")
|
|
62
|
+
};
|
|
63
|
+
}
|
package/server/index.js
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
export { Accordion } from "./accordion.js";
|
|
2
|
+
export { Checkbox } from "./checkbox.js";
|
|
3
|
+
export { Collapsible } from "./collapsible.js";
|
|
4
|
+
export { AlertDialog, Dialog } from "./dialog.js";
|
|
5
|
+
export { HoverCard } from "./hover-card.js";
|
|
6
|
+
export { Popover } from "./popover.js";
|
|
7
|
+
export { RadioGroup } from "./radio-group.js";
|
|
8
|
+
export { Select } from "./select.js";
|
|
9
|
+
export { Switch } from "./switch.js";
|
|
10
|
+
export { Tabs } from "./tabs.js";
|
|
11
|
+
export { Tooltip } from "./tooltip.js";
|
|
12
|
+
export { Avatar } from "./avatar.js";
|
|
13
|
+
export { Button } from "./button.js";
|
|
14
|
+
export { Meter } from "./meter.js";
|
|
15
|
+
export { Progress } from "./progress.js";
|
|
16
|
+
export { Separator } from "./separator.js";
|
|
17
|
+
export { Toggle } from "./toggle.js";
|
|
18
|
+
export { Slider } from "./slider.js";
|
|
19
|
+
export { Field } from "./field.js";
|
|
20
|
+
export { Fieldset } from "./fieldset.js";
|
|
21
|
+
export { Form } from "./form.js";
|
|
22
|
+
export { DirectionProvider, useDirection } from "./direction.js";
|
package/server/meter.js
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
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
|
+
function usePopover() {
|
|
9
|
+
const made = useContext(Context);
|
|
10
|
+
if (!made) throw new Error("A Popover part must be inside <Popover.Root>");
|
|
11
|
+
return made;
|
|
12
|
+
}
|
|
13
|
+
function Root(props) {
|
|
14
|
+
const generated = createUniqueId();
|
|
15
|
+
const made = controller(createPopover, () => ({
|
|
16
|
+
id: props.id ?? generated,
|
|
17
|
+
open: props.open,
|
|
18
|
+
defaultOpen: props.defaultOpen,
|
|
19
|
+
onOpenChange: (open, details) => props.onOpenChange?.(open, details)
|
|
20
|
+
}));
|
|
21
|
+
return _$createComponent(Context.Provider, {
|
|
22
|
+
value: made,
|
|
23
|
+
get children() {
|
|
24
|
+
return props.children;
|
|
25
|
+
}
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
const Portal = props => _$createComponent(BodyPortal, {
|
|
29
|
+
get mounted() {
|
|
30
|
+
return usePopover().mounted;
|
|
31
|
+
},
|
|
32
|
+
get children() {
|
|
33
|
+
return props.children;
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
/** A positioner's own props, written where its placement reads them, before its element attaches. */
|
|
37
|
+
export function positioned(props, positioning) {
|
|
38
|
+
const [local, rest] = splitProps(props, ["side", "align", "sideOffset", "alignOffset", "collisionPadding"]);
|
|
39
|
+
createComputed(() => positioning.set(defined({
|
|
40
|
+
...local
|
|
41
|
+
})));
|
|
42
|
+
return rest;
|
|
43
|
+
}
|
|
44
|
+
function Positioner(props) {
|
|
45
|
+
const made = usePopover();
|
|
46
|
+
return _$createComponent(Part, _$mergeProps({
|
|
47
|
+
get part() {
|
|
48
|
+
return made.positioner;
|
|
49
|
+
},
|
|
50
|
+
tag: "div"
|
|
51
|
+
}, () => positioned(props, made.positioning)));
|
|
52
|
+
}
|
|
53
|
+
const part = (name, tag) => props => _$createComponent(Part, _$mergeProps({
|
|
54
|
+
get part() {
|
|
55
|
+
return usePopover()[name];
|
|
56
|
+
},
|
|
57
|
+
tag: tag
|
|
58
|
+
}, props));
|
|
59
|
+
export const Popover = {
|
|
60
|
+
Root,
|
|
61
|
+
Portal,
|
|
62
|
+
Positioner,
|
|
63
|
+
Trigger: part("trigger", "button"),
|
|
64
|
+
Popup: part("popup", "div"),
|
|
65
|
+
Title: part("title", "h2"),
|
|
66
|
+
Description: part("description", "p"),
|
|
67
|
+
Close: part("close", "button")
|
|
68
|
+
};
|
|
@@ -0,0 +1,100 @@
|
|
|
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", "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
|
+
onValueChange: (value, details) => local.onValueChange?.(value, details)
|
|
33
|
+
}));
|
|
34
|
+
return _$createComponent(Context.Provider, {
|
|
35
|
+
value: made,
|
|
36
|
+
get children() {
|
|
37
|
+
return _$createComponent(Part, _$mergeProps({
|
|
38
|
+
get part() {
|
|
39
|
+
return made.root;
|
|
40
|
+
},
|
|
41
|
+
tag: "div"
|
|
42
|
+
}, rest));
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
function Item(props) {
|
|
47
|
+
const [local, rest] = splitProps(props, ["value", "disabled", "children"]);
|
|
48
|
+
// An item is its value for as long as it is in the page.
|
|
49
|
+
const value = untrack(() => local.value);
|
|
50
|
+
const options = toSignal(() => ({
|
|
51
|
+
disabled: local.disabled
|
|
52
|
+
}));
|
|
53
|
+
const read = () => defined(options.get());
|
|
54
|
+
const group = useRadioGroup();
|
|
55
|
+
return _$createComponent(ItemContext.Provider, {
|
|
56
|
+
value: value,
|
|
57
|
+
get children() {
|
|
58
|
+
return _$createComponent(Part, _$mergeProps({
|
|
59
|
+
get part() {
|
|
60
|
+
return group.item(value, read);
|
|
61
|
+
},
|
|
62
|
+
tag: "span"
|
|
63
|
+
}, rest, {
|
|
64
|
+
get children() {
|
|
65
|
+
return [local.children, _$createComponent(Part, {
|
|
66
|
+
get part() {
|
|
67
|
+
return group.itemInput(value, read);
|
|
68
|
+
},
|
|
69
|
+
tag: "input"
|
|
70
|
+
})];
|
|
71
|
+
}
|
|
72
|
+
}));
|
|
73
|
+
}
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
/** `keepMounted` keeps the mark in the page while its item is not the chosen one. */
|
|
77
|
+
function Indicator(props) {
|
|
78
|
+
const [local, rest] = splitProps(props, ["keepMounted"]);
|
|
79
|
+
const indicator = useRadioGroup().indicator(useContext(ItemContext));
|
|
80
|
+
onMount(() => onCleanup(indicator.mount()));
|
|
81
|
+
const mounted = fromSignal(indicator.mounted);
|
|
82
|
+
return _$createComponent(Show, {
|
|
83
|
+
get when() {
|
|
84
|
+
return mounted() || local.keepMounted;
|
|
85
|
+
},
|
|
86
|
+
get children() {
|
|
87
|
+
return _$createComponent(Part, _$mergeProps({
|
|
88
|
+
get part() {
|
|
89
|
+
return indicator.part;
|
|
90
|
+
},
|
|
91
|
+
tag: "span"
|
|
92
|
+
}, rest));
|
|
93
|
+
}
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
export const RadioGroup = {
|
|
97
|
+
Root,
|
|
98
|
+
Item,
|
|
99
|
+
Indicator
|
|
100
|
+
};
|